MiRCARTGeneralFrame.py, MiRCARTFrame.py: cleanup.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-08 01:43:54 +01:00
parent 30f3688a2c
commit e7b7e05234
2 changed files with 48 additions and 42 deletions

View File

@ -25,7 +25,7 @@
from MiRCARTCanvas import MiRCARTCanvas, haveUrllib from MiRCARTCanvas import MiRCARTCanvas, haveUrllib
from MiRCARTColours import MiRCARTColours from MiRCARTColours import MiRCARTColours
from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \ 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 import os, wx
@ -110,6 +110,11 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
AID_EDIT = (0x500, TID_ACCELS, ( \ AID_EDIT = (0x500, TID_ACCELS, ( \
CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO)) 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) # {{{ _dialogSaveChanges(self)
def _dialogSaveChanges(self): def _dialogSaveChanges(self):

View File

@ -26,12 +26,13 @@ import os, wx
# #
# Types # Types
TID_COMMAND = (0x001) TID_ACCELS = (0x001)
TID_MENU = (0x002) TID_COMMAND = (0x002)
TID_NOTHING = (0x003) TID_LIST = (0x003)
TID_SELECT = (0x004) TID_MENU = (0x004)
TID_TOOLBAR = (0x005) TID_NOTHING = (0x005)
TID_ACCELS = (0x006) TID_SELECT = (0x006)
TID_TOOLBAR = (0x007)
class MiRCARTGeneralFrame(wx.Frame): class MiRCARTGeneralFrame(wx.Frame):
"""XXX""" """XXX"""
@ -48,8 +49,9 @@ class MiRCARTGeneralFrame(wx.Frame):
self.Bind(wx.EVT_MENU, handler, id=accelDescr[0]) self.Bind(wx.EVT_MENU, handler, id=accelDescr[0])
return accelTableEntries return accelTableEntries
# }}} # }}}
# {{{ _initMenus(self, menuBar, menusDescr, handler): XXX # {{{ _initMenus(self, menusDescr, handler): XXX
def _initMenus(self, menuBar, menusDescr, handler): def _initMenus(self, menusDescr, handler):
self.menuItemsById = {}; menuBar = wx.MenuBar();
for menuDescr in menusDescr: for menuDescr in menusDescr:
menuWindow = wx.Menu() menuWindow = wx.Menu()
for menuItem in menuDescr[4]: for menuItem in menuDescr[4]:
@ -68,28 +70,33 @@ class MiRCARTGeneralFrame(wx.Frame):
if len(menuItem) == 7: if len(menuItem) == 7:
menuItemWindow.Enable(menuItem[6]) menuItemWindow.Enable(menuItem[6])
menuBar.Append(menuWindow, menuDescr[3]) menuBar.Append(menuWindow, menuDescr[3])
return menuBar
# }}} # }}}
# {{{ _initToolBars(self, toolBar, toolBarsDescr, handler): XXX # {{{ _initToolBars(self, toolBarsDescr, handler): XXX
def _initToolBars(self, toolBar, toolBarsDescr, handler): def _initToolBars(self, toolBarsDescr, handler, panelSkin):
for toolBarDescr in toolBarsDescr: self.toolBarItemsById = {}
for toolBarItem in toolBarDescr[2]: self.toolBar = wx.ToolBar(panelSkin, -1, \
if toolBarItem == self.NID_TOOLBAR_SEP: style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER)
toolBar.AddSeparator() 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: else:
if toolBarItem[4] != None: toolBarItemIcon = wx.ArtProvider.GetBitmap( \
toolBarItemIcon = wx.ArtProvider.GetBitmap( \ wx.ART_HELP, wx.ART_TOOLBAR, (16,16))
toolBarItem[4], wx.ART_TOOLBAR, (16,16)) toolBarItemWindow = self.toolBar.AddTool( \
else: toolBarItem[0], toolBarItem[2], toolBarItemIcon)
toolBarItemIcon = wx.ArtProvider.GetBitmap( \ self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow
wx.ART_HELP, wx.ART_TOOLBAR, (16,16)) if len(toolBarItem) == 7 \
toolBarItemWindow = self.toolBar.AddTool( \ and toolBarItem[1] == TID_COMMAND:
toolBarItem[0], toolBarItem[2], toolBarItemIcon) toolBarItemWindow.Enable(toolBarItem[6])
self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow self.Bind(wx.EVT_TOOL, handler, toolBarItemWindow)
if len(toolBarItem) == 7 \ self.Bind(wx.EVT_TOOL_RCLICKED, handler, toolBarItemWindow)
and toolBarItem[1] == TID_COMMAND: self.toolBar.Realize(); self.toolBar.Fit();
toolBarItemWindow.Enable(toolBarItem[6])
self.Bind(wx.EVT_TOOL, handler, toolBarItemWindow)
self.Bind(wx.EVT_TOOL_RCLICKED, handler, toolBarItemWindow)
# }}} # }}}
# {{{ onClose(self, event): XXX # {{{ onClose(self, event): XXX
def onClose(self, event): def onClose(self, event):
@ -107,23 +114,17 @@ class MiRCARTGeneralFrame(wx.Frame):
panelSkin = wx.Panel(self, wx.ID_ANY) panelSkin = wx.Panel(self, wx.ID_ANY)
# Initialise menu bar, menus & menu items # Initialise menu bar, menus & menu items
self.menuItemsById = {}; menuBar = wx.MenuBar(); # Initialise toolbar & toolbar items
self._initMenus(menuBar, \ menuBar = self._initMenus(self.LID_MENUS[2], \
[self.MID_FILE, self.MID_EDIT, self.MID_TOOLS],
self.onFrameCommand) self.onFrameCommand)
self.SetMenuBar(menuBar) self.SetMenuBar(menuBar)
toolBar = self._initToolBars(self.LID_TOOLBARS[2], \
# Initialise toolbar & toolbar items self.onFrameCommand, panelSkin)
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();
# Initialise accelerators (hotkeys) # Initialise accelerators (hotkeys)
accelTable = wx.AcceleratorTable( \ accelTable = wx.AcceleratorTable( \
self._initAccelTable(self.AID_EDIT, self.onFrameCommand)) self._initAccelTable(self.LID_ACCELS[2], \
self.onFrameCommand))
self.SetAcceleratorTable(accelTable) self.SetAcceleratorTable(accelTable)
# Initialise status bar # Initialise status bar