MiRCART.py:MiRCARTCanvas.{parentFrame,__init__()}: added for MiRCARTFrame.onCanvasUpdate().

MiRCART.py:MiRCARTCanvas._processMapPatches(): call parentFrame.onCanvasUpdate() given updates.
MiRCART.py:MiRCARTCanvas.{re,un}do(): call parentFrame.onCanvasUpdate() given {re,un}do.
MiRCART.py:MiRCARTFrame.onCanvasUpdate(): {dis,en}able menuEdit{Re,Un}do on updates.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-05 18:21:38 +01:00
parent 813d49a3f2
commit 28ae8f04f8

View File

@ -48,6 +48,7 @@ mircColours = [
class MiRCARTCanvas(wx.Panel): class MiRCARTCanvas(wx.Panel):
"""XXX""" """XXX"""
parentFrame = None
canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None
canvasBitmap = canvasMap = canvasTools = None canvasBitmap = canvasMap = canvasTools = None
mircBg = mircFg = mircBrushes = mircPens = None mircBg = mircFg = mircBrushes = mircPens = None
@ -117,6 +118,8 @@ class MiRCARTCanvas(wx.Panel):
(atX + patch[0], atY + patch[1], patch[2], patch[3], " "))) (atX + patch[0], atY + patch[1], patch[2], patch[3], " ")))
self.canvasMap[atY + patch[1]][atX + patch[0]] = [patch[2], patch[3], " "]; self.canvasMap[atY + patch[1]][atX + patch[0]] = [patch[2], patch[3], " "];
self._drawPatch(patch, eventDc, tmpDc, atX, atY) self._drawPatch(patch, eventDc, tmpDc, atX, atY)
if len(mapPatch[3]):
self.parentFrame.onCanvasUpdate()
# }}} # }}}
# {{{ getBackgroundColour(): XXX # {{{ getBackgroundColour(): XXX
def getBackgroundColour(self): def getBackgroundColour(self):
@ -179,6 +182,7 @@ class MiRCARTCanvas(wx.Panel):
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC(); eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
tmpDc.SelectObject(self.canvasBitmap) tmpDc.SelectObject(self.canvasBitmap)
self._drawPatch(redoPatch, eventDc, tmpDc, 0, 0) self._drawPatch(redoPatch, eventDc, tmpDc, 0, 0)
self.parentFrame.onCanvasUpdate()
return True return True
else: else:
return False return False
@ -193,12 +197,14 @@ class MiRCARTCanvas(wx.Panel):
tmpDc.SelectObject(self.canvasBitmap) tmpDc.SelectObject(self.canvasBitmap)
self._drawPatch(undoPatch, eventDc, tmpDc, 0, 0) self._drawPatch(undoPatch, eventDc, tmpDc, 0, 0)
self.patchesUndoLevel += 1 self.patchesUndoLevel += 1
self.parentFrame.onCanvasUpdate()
return True return True
else: else:
return False return False
# }}} # }}}
# {{{ Initialisation method # {{{ Initialisation method
def __init__(self, parent, canvasPos, cellSize, canvasSize, canvasTools): def __init__(self, parent, parentFrame, canvasPos, cellSize, canvasSize, canvasTools):
self.parentFrame = parentFrame
canvasWinSize = (cellSize[0] * canvasSize[0], cellSize[1] * canvasSize[1]) canvasWinSize = (cellSize[0] * canvasSize[0], cellSize[1] * canvasSize[1])
super().__init__(parent, pos=canvasPos, size=canvasWinSize) super().__init__(parent, pos=canvasPos, size=canvasWinSize)
self.canvasPos = canvasPos; self.canvasSize = canvasSize; self.canvasWinSize = canvasWinSize; self.canvasPos = canvasPos; self.canvasSize = canvasSize; self.canvasWinSize = canvasWinSize;
@ -346,6 +352,17 @@ class MiRCARTFrame(wx.Frame):
def onAccelUndo(self, event): def onAccelUndo(self, event):
self.panelCanvas.undo() self.panelCanvas.undo()
# }}} # }}}
# {{{ onCanvasUpdate(): XXX
def onCanvasUpdate(self):
if self.panelCanvas.patchesUndo[self.panelCanvas.patchesUndoLevel] != None:
self.menuEditUndo.Enable(True)
else:
self.menuEditUndo.Enable(False)
if self.panelCanvas.patchesUndoLevel > 0:
self.menuEditRedo.Enable(True)
else:
self.menuEditRedo.Enable(False)
# }}}
# {{{ onEditCopy(): XXX # {{{ onEditCopy(): XXX
def onEditCopy(self, event): def onEditCopy(self, event):
pass pass
@ -433,6 +450,11 @@ class MiRCARTFrame(wx.Frame):
except IOError as error: except IOError as error:
wx.LogError("IOError {}".format(error)) wx.LogError("IOError {}".format(error))
# }}} # }}}
# {{{ onPaletteEvent(): XXX
def onPaletteEvent(self, leftDown, rightDown, numColour):
self.panelCanvas.onPaletteEvent(leftDown, rightDown, numColour)
self._updateStatusBar()
# }}}
# {{{ onToolsRect(): XXX # {{{ onToolsRect(): XXX
def onToolsRect(self, event): def onToolsRect(self, event):
pass pass
@ -445,18 +467,13 @@ class MiRCARTFrame(wx.Frame):
def onToolsLine(self, event): def onToolsLine(self, event):
pass pass
# }}} # }}}
# {{{ onPaletteEvent(): XXX
def onPaletteEvent(self, leftDown, rightDown, numColour):
self.panelCanvas.onPaletteEvent(leftDown, rightDown, numColour)
self._updateStatusBar()
# }}}
# {{{ Initialisation method # {{{ Initialisation method
def __init__(self, parent, appSize=(800, 600), canvasPos=(25, 25), cellSize=(7, 14), canvasSize=(80, 25)): def __init__(self, parent, appSize=(800, 600), canvasPos=(25, 25), cellSize=(7, 14), canvasSize=(80, 25)):
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize) super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
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, \
canvasPos=canvasPos, cellSize=cellSize, \ parentFrame=self, canvasPos=canvasPos, cellSize=cellSize, \
canvasSize=canvasSize, canvasTools=[MiRCARTToolRect]) canvasSize=canvasSize, canvasTools=[MiRCARTToolRect])
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)