Example #1
0
    def __init__(self):
        """
        Initialise utility, status/menu/tool bar, tabs, ctrl panel + bindings.
        """
        wx.Frame.__init__(self, None, title=_("Untitled") + u" - %s" % self.title)
        self.util = Utility(self)

        meta.find_transparent()  # important
        logger.info("Transparency supported: %s", meta.transparent)
        
        if meta.transparent:
            try:
                x = self.util.items.index(Highlighter)
            except ValueError:
                self.util.items.insert(1, Highlighter)

        self.can_paste = check_clipboard()
        self.process = None
        self.pid = None
        self.dialog = None
        self.convert_cancelled = False
        self.shape_viewer_open = False
        self.help = None
        self.hotkey_pressed = False  # for hotkey timer
        self.hotkey_timer = None
        self.tab_count = 1
        self.tab_total = 1
        self.current_tab = 0
        self.closed_tabs = []
        self.hotkeys = []

        style = (fnb.FNB_X_ON_TAB | fnb.FNB_NO_X_BUTTON | fnb.FNB_VC8 |
                 fnb.FNB_DROPDOWN_TABS_LIST | fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS |
                 fnb.FNB_NO_NAV_BUTTONS)

        self.control = ControlPanel(self)
        self.tabs = fnb.FlatNotebook(self, agwStyle=style)
        self.canvas = Canvas(self.tabs, self, (Config().default_width(), Config().default_height()))
        self.panel = SidePanel(self)

        self.thumbs = self.panel.thumbs
        self.notes = self.panel.notes
        self.tabs.AddPage(self.canvas, _("Sheet") + u" 1")

        box = wx.BoxSizer(wx.HORIZONTAL)  # position windows side-by-side
        box.Add(self.control, 0, wx.EXPAND)
        box.Add(self.tabs, 1, wx.EXPAND)
        box.Add(self.panel, 0, wx.EXPAND)
        self.SetSizer(box)
        self.SetSizeWH(800, 600)

        if os.name == "posix":
            self.canvas.SetFocus()  # makes EVT_CHAR_HOOK trigger
        if 'mac' != os.name:
            self.Maximize(True)

        self.paste_check_count = PASTE_CHECK_COUNT - 1
        wx.UpdateUIEvent.SetUpdateInterval(75)
        #wx.UpdateUIEvent.SetMode(wx.UPDATE_UI_PROCESS_SPECIFIED)

        self.SetIcon(icon.getIcon())
        self.SetExtraStyle(wx.WS_EX_PROCESS_UI_UPDATES)
        self.SetDropTarget(CanvasDropTarget())
        self.statusbar = self.CreateStatusBar()
        self._print = Print(self)

        self.filehistory = wx.FileHistory(8)
        self.config = wx.Config()
        self.load_history_file()
        self.filehistory.Load(self.config)

        self.menu = Menu(self)
        self.toolbar = self.CreateToolBar() 
        Toolbar.configure(self.toolbar, self.can_paste)
        self.SetMenuBar(self.menu.menu)
        self.set_menu_from_config()
        self.do_bindings()
        self.find_help()
        
        pub.sendMessage('thumbs.update_current')
        self.update_panels(True)
        wx.CallAfter(self.UpdateWindowUI)
Example #2
0
    def update_menus(self, event):
        """
        Enables/disables GUI menus and toolbar items.
        It uses a counter for the clipboard check as it can be too performance
        intense and cause segmentation faults
        """
        canvas = self.canvas
        if not canvas:
            return
        _id = event.GetId()

        if _id in [wx.ID_PASTE, ID_PASTE_NEW]:  # check this less frequently, possibly expensive
            self.paste_check_count += 1
            if self.paste_check_count == PASTE_CHECK_COUNT:
                self.can_paste = False

            if check_clipboard():
                self.can_paste = True
                self.paste_check_count = 0
                try:
                    self.menu.enable(ID_PASTE_NEW, self.can_paste)
                    self.menu.enable(wx.ID_PASTE, self.can_paste)
                except wx.PyDeadObjectError:
                    pass
            return

        if _id == ID_TRANSPARENT:
            if canvas.can_swap_transparency():
                if canvas.is_transparent():
                    event.Check(True)
                else:
                    event.Check(False)
                event.Enable(True)
            else:
                event.Enable(False)
            return

        do = False
        if _id == wx.ID_REDO and canvas.redo_list:
            do = True
        elif _id == wx.ID_UNDO and canvas.undo_list:
            do = True
        elif _id == ID_PREV and self.current_tab:
            do = True
        elif (_id == ID_NEXT and self.can_change_next_sheet()):
            do = True
        elif _id in [wx.ID_CLOSE, ID_CLOSE_ALL, ID_CLOSE_OTHERS] and self.tab_count > 1:
            do = True
        elif _id in [ID_UNDO_SHEET, ID_RECENTLY_CLOSED] and self.closed_tabs:
            do = True
        elif _id in [wx.ID_DELETE, ID_DESELECT, ID_FOREGROUND] and canvas.selected:
            do = True
        elif _id == ID_MOVE_UP and canvas.check_move(u"up"):
            do = True
        elif _id == ID_MOVE_DOWN and canvas.check_move(u"down"):
            do = True
        elif _id == ID_MOVE_TO_TOP and canvas.check_move(u"top"):
            do = True
        elif _id == ID_MOVE_TO_BOTTOM and canvas.check_move(u"bottom"):
            do = True
        elif _id in [ID_SWAP_COLOURS, ID_BACKGROUND] and canvas.can_swap_colours():
            do = True
        elif _id == wx.ID_COPY:
            if canvas:
                if canvas.copy:
                    do = True
        event.Enable(do)