"Fossies" - the Fresh Open Source Software Archive

Member "sk1-2.0rc4/src/sk1/parts/doctabs.py" (25 May 2019, 3319 Bytes) of package /linux/misc/sk1-2.0rc4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "doctabs.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0rc3_vs_2.0rc4.

    1 # -*- coding: utf-8 -*-
    2 #
    3 #  Copyright (C) 2018 by Igor E. Novikov
    4 #
    5 #  This program is free software: you can redistribute it and/or modify
    6 #  it under the terms of the GNU General Public License as published by
    7 #  the Free Software Foundation, either version 3 of the License, or
    8 #  (at your option) any later version.
    9 #
   10 #  This program is distributed in the hope that it will be useful,
   11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 #  GNU General Public License for more details.
   14 #
   15 #  You should have received a copy of the GNU General Public License
   16 #  along with this program.  If not, see <https://www.gnu.org/licenses/>.
   17 
   18 import wal
   19 
   20 from sk1 import events, config
   21 from sk1.pwidgets import ContextMenu
   22 from sk1.resources import pdids
   23 
   24 ITEMS = [wal.ID_CLOSE, pdids.ID_CLOSE_OTHERS, wal.ID_CLOSE_ALL, None,
   25          wal.ID_NEW, wal.ID_OPEN, None,
   26          wal.ID_SAVE, wal.ID_SAVEAS, pdids.ID_SAVE_SEL,
   27          pdids.ID_SAVEALL, None, pdids.ID_IMPORT, pdids.ID_EXPORT,
   28          None, wal.ID_PRINT, None, wal.ID_PROPERTIES]
   29 
   30 
   31 class DocTabPanel(wal.HTabPanel):
   32     app = None
   33     ctx_menu = None
   34 
   35     def __init__(self, app, parent, draw_top=True):
   36         self.app = app
   37         wal.HTabPanel.__init__(self, parent, draw_top=draw_top,
   38                                painter_index=config.tab_style)
   39         self.ctx_menu = ContextMenu(app, self, ITEMS)
   40         self.set_drop_target(wal.FileDropHandler(self, self.drop_file))
   41         events.connect(events.CONFIG_MODIFIED, self.check_config)
   42 
   43     def check_config(self, *args):
   44         if args[0] == 'tab_style':
   45             self.set_painter(config.tab_style)
   46             self.refresh()
   47 
   48     def double_click(self):
   49         self.app.actions[wal.ID_NEW]()
   50 
   51     def add_new_tab(self, doc):
   52         return wal.HTabPanel.add_new_tab(self, DocTab(self, doc))
   53 
   54     def remove_tab(self, doc):
   55         wal.HTabPanel.remove_tab(self, self.find_doctab(doc))
   56 
   57     def set_active(self, doc):
   58         wal.HTabPanel.set_active(self, self.find_doctab(doc))
   59 
   60     def change_tab_index(self, index, tab):
   61         doc = tab.doc
   62         self.app.docs.remove(doc)
   63         self.app.docs.insert(index, doc)
   64         wal.HTabPanel.change_tab_index(self, index, tab)
   65 
   66     def show_context_menu(self):
   67         self.popup_menu(self.ctx_menu)
   68 
   69     def find_doctab(self, doc):
   70         for tab in self.tabs:
   71             if doc == tab.doc:
   72                 return tab
   73 
   74     def drop_file(self, x, y, filename):
   75         self.app.open(filename)
   76 
   77 
   78 class DocTab(wal.HTab):
   79     doc = None
   80 
   81     def __init__(self, parent, doc, active=True):
   82         self.doc = doc
   83         self.text = self.doc.doc_name
   84         wal.HTab.__init__(self, parent, active)
   85 
   86     def set_title(self, title):
   87         self.saved = self.doc.saved
   88         wal.HTab.set_title(self, self.doc.doc_name)
   89 
   90     def close(self):
   91         self.mouse_leaved_tab()
   92         self.parent.refresh()
   93         self.doc.app.close(self.doc)
   94 
   95     def mouse_left_down(self, point):
   96         if wal.HTab.mouse_left_down(self, point):
   97             if not self.active:
   98                 self.doc.app.set_current_doc(self.doc)
   99 
  100     def mouse_right_down(self):
  101         if not self.active:
  102             self.doc.app.set_current_doc(self.doc)
  103         self.parent.show_context_menu()