From baa84ce859b03983f3069fbfffb1be52e85c9837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 8 Jan 2018 01:43:54 +0100 Subject: [PATCH] MiRCARTGeneralFrame.py, MiRCARTFrame.py: cleanup. --- MiRCARTFrame.py | 7 +++- MiRCARTGeneralFrame.py | 83 +++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/MiRCARTFrame.py b/MiRCARTFrame.py index 23b2e9c..06716d8 100644 --- a/MiRCARTFrame.py +++ b/MiRCARTFrame.py @@ -25,7 +25,7 @@ from MiRCARTCanvas import MiRCARTCanvas, haveUrllib from MiRCARTColours import MiRCARTColours from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \ - TID_COMMAND, TID_MENU, TID_NOTHING, TID_SELECT, TID_TOOLBAR, TID_ACCELS + TID_ACCELS, TID_COMMAND, TID_LIST, TID_MENU, TID_NOTHING, TID_SELECT, TID_TOOLBAR import os, wx @@ -110,6 +110,11 @@ class MiRCARTFrame(MiRCARTGeneralFrame): AID_EDIT = (0x500, TID_ACCELS, ( \ CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO)) # }}} + # {{{ Lists + LID_ACCELS = (0x600, TID_LIST, (AID_EDIT)) + LID_MENUS = (0x601, TID_LIST, (MID_FILE, MID_EDIT, MID_TOOLS)) + LID_TOOLBARS = (0x602, TID_LIST, (BID_TOOLBAR)) + # }}} # {{{ _dialogSaveChanges(self) def _dialogSaveChanges(self): diff --git a/MiRCARTGeneralFrame.py b/MiRCARTGeneralFrame.py index 798af47..0c127e0 100644 --- a/MiRCARTGeneralFrame.py +++ b/MiRCARTGeneralFrame.py @@ -26,12 +26,13 @@ import os, wx # # Types -TID_COMMAND = (0x001) -TID_MENU = (0x002) -TID_NOTHING = (0x003) -TID_SELECT = (0x004) -TID_TOOLBAR = (0x005) -TID_ACCELS = (0x006) +TID_ACCELS = (0x001) +TID_COMMAND = (0x002) +TID_LIST = (0x003) +TID_MENU = (0x004) +TID_NOTHING = (0x005) +TID_SELECT = (0x006) +TID_TOOLBAR = (0x007) class MiRCARTGeneralFrame(wx.Frame): """XXX""" @@ -48,8 +49,9 @@ class MiRCARTGeneralFrame(wx.Frame): self.Bind(wx.EVT_MENU, handler, id=accelDescr[0]) return accelTableEntries # }}} - # {{{ _initMenus(self, menuBar, menusDescr, handler): XXX - def _initMenus(self, menuBar, menusDescr, handler): + # {{{ _initMenus(self, menusDescr, handler): XXX + def _initMenus(self, menusDescr, handler): + self.menuItemsById = {}; menuBar = wx.MenuBar(); for menuDescr in menusDescr: menuWindow = wx.Menu() for menuItem in menuDescr[4]: @@ -68,28 +70,33 @@ class MiRCARTGeneralFrame(wx.Frame): if len(menuItem) == 7: menuItemWindow.Enable(menuItem[6]) menuBar.Append(menuWindow, menuDescr[3]) + return menuBar # }}} - # {{{ _initToolBars(self, toolBar, toolBarsDescr, handler): XXX - def _initToolBars(self, toolBar, toolBarsDescr, handler): - for toolBarDescr in toolBarsDescr: - for toolBarItem in toolBarDescr[2]: - if toolBarItem == self.NID_TOOLBAR_SEP: - toolBar.AddSeparator() + # {{{ _initToolBars(self, toolBarsDescr, handler): XXX + def _initToolBars(self, toolBarsDescr, handler, panelSkin): + self.toolBarItemsById = {} + self.toolBar = wx.ToolBar(panelSkin, -1, \ + style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER) + self.toolBar.SetToolBitmapSize((16,16)) + for toolBarItem in toolBarsDescr[2]: + if toolBarItem == self.NID_TOOLBAR_SEP: + self.toolBar.AddSeparator() + else: + if toolBarItem[4] != None: + toolBarItemIcon = wx.ArtProvider.GetBitmap( \ + toolBarItem[4], wx.ART_TOOLBAR, (16,16)) else: - if toolBarItem[4] != None: - toolBarItemIcon = wx.ArtProvider.GetBitmap( \ - toolBarItem[4], wx.ART_TOOLBAR, (16,16)) - else: - toolBarItemIcon = wx.ArtProvider.GetBitmap( \ - wx.ART_HELP, wx.ART_TOOLBAR, (16,16)) - toolBarItemWindow = self.toolBar.AddTool( \ - toolBarItem[0], toolBarItem[2], toolBarItemIcon) - self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow - if len(toolBarItem) == 7 \ - and toolBarItem[1] == TID_COMMAND: - toolBarItemWindow.Enable(toolBarItem[6]) - self.Bind(wx.EVT_TOOL, handler, toolBarItemWindow) - self.Bind(wx.EVT_TOOL_RCLICKED, handler, toolBarItemWindow) + toolBarItemIcon = wx.ArtProvider.GetBitmap( \ + wx.ART_HELP, wx.ART_TOOLBAR, (16,16)) + toolBarItemWindow = self.toolBar.AddTool( \ + toolBarItem[0], toolBarItem[2], toolBarItemIcon) + self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow + if len(toolBarItem) == 7 \ + and toolBarItem[1] == TID_COMMAND: + toolBarItemWindow.Enable(toolBarItem[6]) + self.Bind(wx.EVT_TOOL, handler, toolBarItemWindow) + self.Bind(wx.EVT_TOOL_RCLICKED, handler, toolBarItemWindow) + self.toolBar.Realize(); self.toolBar.Fit(); # }}} # {{{ onClose(self, event): XXX def onClose(self, event): @@ -107,23 +114,17 @@ class MiRCARTGeneralFrame(wx.Frame): panelSkin = wx.Panel(self, wx.ID_ANY) # Initialise menu bar, menus & menu items - self.menuItemsById = {}; menuBar = wx.MenuBar(); - self._initMenus(menuBar, \ - [self.MID_FILE, self.MID_EDIT, self.MID_TOOLS], + # Initialise toolbar & toolbar items + menuBar = self._initMenus(self.LID_MENUS[2], \ self.onFrameCommand) self.SetMenuBar(menuBar) - - # Initialise toolbar & toolbar items - self.toolBarItemsById = {} - self.toolBar = wx.ToolBar(panelSkin, -1, \ - style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER) - self.toolBar.SetToolBitmapSize((16,16)) - self._initToolBars(self.toolBar, [self.BID_TOOLBAR], self.onFrameCommand) - self.toolBar.Realize(); self.toolBar.Fit(); + toolBar = self._initToolBars(self.LID_TOOLBARS[2], \ + self.onFrameCommand, panelSkin) # Initialise accelerators (hotkeys) - accelTable = wx.AcceleratorTable( \ - self._initAccelTable(self.AID_EDIT, self.onFrameCommand)) + accelTable = wx.AcceleratorTable( \ + self._initAccelTable(self.LID_ACCELS[2], \ + self.onFrameCommand)) self.SetAcceleratorTable(accelTable) # Initialise status bar