libgui/GuiFrame.py:loadAccels(): obtain from {menu,Toolbar}s[].

libroar/RoarCanvasCommands{,Edit,File,Help,Tools}.py: remove self.accels[].
libroar/RoarClient.py: updated.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-10 12:28:26 +02:00
parent df41c40b80
commit 988e6199c0
7 changed files with 19 additions and 20 deletions

View File

@ -53,11 +53,13 @@ class GuiFrame(wx.Frame):
self.SetIcon(icon)
# }}}
# {{{ loadAccels(self, accels)
def loadAccels(self, accels):
accelTableEntries = []
# {{{ loadAccels(self, menus, toolBars)
def loadAccels(self, menus, toolBars):
def loadAccels_(accels):
nonlocal accelTableEntries
for accel in accels:
if accel.attrDict["accel"] != None:
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;
@ -65,6 +67,8 @@ class GuiFrame(wx.Frame):
accel.attrDict["accelEntry"] = accelTableEntries[-1]
self.itemsById[accel.attrDict["id"]] = accel
self.Bind(wx.EVT_MENU, self.onMenu, id=accel.attrDict["id"])
accelTableEntries = []
[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))

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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),

View File

@ -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)