diff --git a/libgui/GuiFrame.py b/libgui/GuiFrame.py index 288e7dd..bb61d8e 100644 --- a/libgui/GuiFrame.py +++ b/libgui/GuiFrame.py @@ -53,18 +53,22 @@ class GuiFrame(wx.Frame): self.SetIcon(icon) # }}} - # {{{ loadAccels(self, accels) - def loadAccels(self, accels): + # {{{ loadAccels(self, menus, toolBars) + def loadAccels(self, menus, toolBars): + def loadAccels_(accels): + nonlocal accelTableEntries + for accel in accels: + if (not accel in [NID_MENU_SEP, NID_TOOLBAR_HSEP]) \ + and (accel.attrDict["accel"] != None): + accelTableEntries += [wx.AcceleratorEntry()] + if accel.attrDict["id"] == None: + accel.attrDict["id"] = self.lastId; self.lastId += 1; + accelTableEntries[-1].Set(*accel.attrDict["accel"], accel.attrDict["id"]) + accel.attrDict["accelEntry"] = accelTableEntries[-1] + self.itemsById[accel.attrDict["id"]] = accel + self.Bind(wx.EVT_MENU, self.onMenu, id=accel.attrDict["id"]) accelTableEntries = [] - for accel in accels: - if accel.attrDict["accel"] != None: - accelTableEntries += [wx.AcceleratorEntry()] - if accel.attrDict["id"] == None: - accel.attrDict["id"] = self.lastId; self.lastId += 1; - accelTableEntries[-1].Set(*accel.attrDict["accel"], accel.attrDict["id"]) - accel.attrDict["accelEntry"] = accelTableEntries[-1] - self.itemsById[accel.attrDict["id"]] = accel - self.Bind(wx.EVT_MENU, self.onMenu, id=accel.attrDict["id"]) + [loadAccels_(menu[1:]) for menu in menus]; [loadAccels_(toolBar) for toolBar in toolBars]; self.SetAcceleratorTable(wx.AcceleratorTable(accelTableEntries)) # }}} # {{{ loadBitmap(self, basePathName, descr, size=(16, 16)) diff --git a/libroar/RoarCanvasCommands.py b/libroar/RoarCanvasCommands.py index 9b28392..a6040f4 100644 --- a/libroar/RoarCanvasCommands.py +++ b/libroar/RoarCanvasCommands.py @@ -87,12 +87,10 @@ class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCan # # __init__(self, parentCanvas, parentFrame): def __init__(self, parentCanvas, parentFrame): - accels, menus, toolBars = [], [], [] + menus, toolBars = [], [] self.canvasPathName, self.lastPanelState, self.parentCanvas, self.parentFrame = None, {}, parentCanvas, parentFrame for classObject in self.__class__.__bases__: classObject.__init__(self) - if len(self.accels): - accels += self.accels if len(self.menus): menus += self.menus if len(self.toolBars): @@ -118,6 +116,6 @@ class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCan self.canvasBrushSize(self.canvasBrushSize, 1, True), self.canvasBrushSize(self.canvasBrushSize, 0, False), self.canvasBrushSize(self.canvasBrushSize, 1, True), self.canvasBrushSize(self.canvasBrushSize, 1, False), NID_TOOLBAR_HSEP, self.canvasBrushSize(self.canvasBrushSize, 2, True), self.canvasBrushSize(self.canvasBrushSize, 2, False), ]) - self.accels, self.menus, self.toolBars = accels, menus, toolBars + self.menus, self.toolBars = menus, toolBars # vim:expandtab foldmethod=marker sw=4 ts=4 tw=0 diff --git a/libroar/RoarCanvasCommandsEdit.py b/libroar/RoarCanvasCommandsEdit.py index 622ce41..6fd0b6c 100644 --- a/libroar/RoarCanvasCommandsEdit.py +++ b/libroar/RoarCanvasCommandsEdit.py @@ -141,7 +141,6 @@ class RoarCanvasCommandsEdit(): # # __init__(self) def __init__(self): - self.accels = (self.canvasUndo, self.canvasRedo) self.menus = ( ("&Edit", self.canvasUndo, self.canvasRedo, NID_MENU_SEP, diff --git a/libroar/RoarCanvasCommandsFile.py b/libroar/RoarCanvasCommandsFile.py index 15c6716..7b7c6f0 100644 --- a/libroar/RoarCanvasCommandsFile.py +++ b/libroar/RoarCanvasCommandsFile.py @@ -220,7 +220,6 @@ class RoarCanvasCommandsFile(): # __init__(self) def __init__(self): self.imgurApiKey = ImgurApiKey.imgurApiKey if haveImgurApiKey else None - self.accels = (self.canvasExit, self.canvasNew, self.canvasOpen, self.canvasSave) self.menus = ( ("&File", self.canvasNew, self.canvasOpen, self.canvasSave, self.canvasSaveAs, NID_MENU_SEP, diff --git a/libroar/RoarCanvasCommandsHelp.py b/libroar/RoarCanvasCommandsHelp.py index 0a3b171..a7f266b 100644 --- a/libroar/RoarCanvasCommandsHelp.py +++ b/libroar/RoarCanvasCommandsHelp.py @@ -17,6 +17,6 @@ class RoarCanvasCommandsHelp(): # # __init__(self) def __init__(self): - self.accels, self.menus, self.toolBars = (), (("&Help", self.canvasAbout,),), () + self.menus, self.toolBars = (("&Help", self.canvasAbout,),), () # vim:expandtab foldmethod=marker sw=4 ts=4 tw=0 diff --git a/libroar/RoarCanvasCommandsTools.py b/libroar/RoarCanvasCommandsTools.py index cd7d0c0..fd4e038 100644 --- a/libroar/RoarCanvasCommandsTools.py +++ b/libroar/RoarCanvasCommandsTools.py @@ -41,7 +41,6 @@ class RoarCanvasCommandsTools(): # # __init__(self) def __init__(self): - self.accels = (self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4),) self.menus = ( ("&Tools", self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4), diff --git a/libroar/RoarClient.py b/libroar/RoarClient.py index d5e7a6d..8da6143 100644 --- a/libroar/RoarClient.py +++ b/libroar/RoarClient.py @@ -42,7 +42,7 @@ class RoarClient(GuiFrame): super().__init__(self._getIconPathName(), size, parent, title) self.canvas = Canvas(defaultCanvasSize) self.canvasPanel = RoarCanvasWindow(GuiCanvasWxBackend, self.canvas, defaultCellSize, RoarCanvasCommands, self.panelSkin, self, defaultCanvasPos, defaultCellSize, defaultCanvasSize) - self.loadAccels(self.canvasPanel.commands.accels) + self.loadAccels(self.canvasPanel.commands.menus, self.canvasPanel.commands.toolBars) self.loadMenus(self.canvasPanel.commands.menus) self._initToolBitmaps(self.canvasPanel.commands.toolBars) self.loadToolBars(self.canvasPanel.commands.toolBars)