MiRCART.py:MiRCARTFrame.accel{UndoId,Table}: added.

MiRCART.py:MiRCARTFrame.onAccelUndo(): call self.panelCanvas.undo().
MiRCART.py:MiRCARTFrame.__init__(): create self.menuFileUndo w/ wx.ID_UNDO.
MiRCART.py:MiRCARTFrame.__init__(): bind ^Z accelerator to self.onAccelUndo().
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-05 01:59:04 +01:00
parent 423f923b4e
commit 8b6d7ab445

View File

@ -299,7 +299,7 @@ class MiRCARTFrame(wx.Frame):
"""XXX""" """XXX"""
menuFile = menuFileUndo = menuFileSaveAs = menuFileExit = menuBar = None menuFile = menuFileUndo = menuFileSaveAs = menuFileExit = menuBar = None
panelSkin = panelCanvas = panelPalette = None panelSkin = panelCanvas = panelPalette = None
statusBar = None accelUndoId = accelTable = statusBar = None
# {{{ _updateStatusBar(): XXX # {{{ _updateStatusBar(): XXX
def _updateStatusBar(self): def _updateStatusBar(self):
@ -310,6 +310,10 @@ class MiRCARTFrame(wx.Frame):
text += " " + str(self.panelCanvas.getBackgroundColour()) text += " " + str(self.panelCanvas.getBackgroundColour())
self.statusBar.SetStatusText(text) self.statusBar.SetStatusText(text)
# }}} # }}}
# {{{ onAccelUndo(): XXX
def onAccelUndo(self, event):
self.panelCanvas.undo()
# }}}
# {{{ onFileUndo(): XXX # {{{ onFileUndo(): XXX
def onFileUndo(self, event): def onFileUndo(self, event):
self.panelCanvas.undo() self.panelCanvas.undo()
@ -355,11 +359,12 @@ class MiRCARTFrame(wx.Frame):
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize) super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
self.menuFile = wx.Menu() self.menuFile = wx.Menu()
self.menuFileUndo = self.menuFile.Append(wx.ID_SAVE, "&Undo", "Undo") self.menuFileUndo = self.menuFile.Append(wx.ID_UNDO, "&Undo", "Undo")
self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...") self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...")
self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit") self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit")
self.menuBar = wx.MenuBar() self.menuBar = wx.MenuBar()
self.menuBar.Append(self.menuFile, "&File") self.menuBar.Append(self.menuFile, "&File")
self.SetMenuBar(self.menuBar)
self.panelSkin = wx.Panel(self, wx.ID_ANY) self.panelSkin = wx.Panel(self, wx.ID_ANY)
self.panelCanvas = MiRCARTCanvas(self.panelSkin, \ self.panelCanvas = MiRCARTCanvas(self.panelSkin, \
@ -368,13 +373,18 @@ class MiRCARTFrame(wx.Frame):
self.panelPalette = MiRCARTPalette(self.panelSkin, \ self.panelPalette = MiRCARTPalette(self.panelSkin, \
(25, (canvasSize[1] + 3) * cellSize[1]), cellSize, self.onPaletteEvent) (25, (canvasSize[1] + 3) * cellSize[1]), cellSize, self.onPaletteEvent)
self.accelUndoId = wx.NewId()
self.accelTable = wx.AcceleratorTable([( \
wx.ACCEL_CTRL, ord('Z'), self.accelUndoId)])
self.SetAcceleratorTable(self.accelTable)
self.statusBar = self.CreateStatusBar() self.statusBar = self.CreateStatusBar()
self._updateStatusBar() self._updateStatusBar()
self.SetFocus()
self.Bind(wx.EVT_MENU, self.onAccelUndo, id=self.accelUndoId)
self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit) self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit)
self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs) self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs)
self.Bind(wx.EVT_MENU, self.onFileUndo, self.menuFileUndo) self.Bind(wx.EVT_MENU, self.onFileUndo, self.menuFileUndo)
self.SetMenuBar(self.menuBar)
self.Show(True) self.Show(True)
# }}} # }}}