MiRCART{Canvas{,Interface},Frame}.py: use dict() to cache canvas state in Frame.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-10 14:51:25 +01:00
parent 402e542137
commit 2254a0638b
3 changed files with 42 additions and 56 deletions

View File

@ -48,7 +48,7 @@ class MiRCARTCanvas(wx.Panel):
for patch in deltaPatches:
if self.canvasBackend.drawPatch(eventDc, patch):
self._commitPatch(patch)
self.parentFrame.onCanvasUpdate(newUndoLevel=self.canvasJournal.patchesUndoLevel)
self.parentFrame.onCanvasUpdate(undoLevel=self.canvasJournal.patchesUndoLevel)
# }}}
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
def _dispatchPatch(self, eventDc, isCursor, patch):
@ -98,10 +98,10 @@ class MiRCARTCanvas(wx.Panel):
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
self._dispatchPatch, eventDc)
if self._canvasDirty:
self.parentFrame.onCanvasUpdate(newCellPos=self.brushPos, \
newUndoLevel=self.canvasJournal.patchesUndoLevel)
self.parentFrame.onCanvasUpdate(cellPos=self.brushPos, \
undoLevel=self.canvasJournal.patchesUndoLevel)
if eventType == wx.wxEVT_MOTION:
self.parentFrame.onCanvasUpdate(newCellPos=mapPoint)
self.parentFrame.onCanvasUpdate(cellPos=mapPoint)
# }}}
# {{{ onPanelLeaveWindow(self, event): XXX
def onPanelLeaveWindow(self, event):
@ -151,7 +151,7 @@ class MiRCARTCanvas(wx.Panel):
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
self.parentFrame.onCanvasUpdate( \
newSize=self.canvasSize, newUndoLevel=-1)
size=self.canvasSize, undoLevel=-1)
# }}}
#
@ -164,7 +164,7 @@ class MiRCARTCanvas(wx.Panel):
self.canvasMap = None; self.canvasPos = canvasPos; self.canvasSize = canvasSize;
self.brushColours = [4, 1]; self.brushPos = [0, 0]; self.brushSize = [1, 1];
self.parentFrame.onCanvasUpdate( \
newBrushSize=self.brushSize, newColours=self.brushColours)
brushSize=self.brushSize, colours=self.brushColours)
self.canvasBackend = MiRCARTCanvasBackend(canvasSize, cellSize)
self.canvasJournal = MiRCARTCanvasJournal()
self.canvasExportStore = MiRCARTCanvasExportStore(parentCanvas=self)

View File

@ -69,7 +69,7 @@ class MiRCARTCanvasInterface():
self.parentCanvas.brushColours[0] = numColour
elif event.GetEventType() == wx.wxEVT_TOOL_RCLICKED:
self.parentCanvas.brushColours[1] = numColour
self.parentFrame.onCanvasUpdate(newColours=self.parentCanvas.brushColours)
self.parentFrame.onCanvasUpdate(colours=self.parentCanvas.brushColours)
# }}}
# {{{ canvasCopy(self, event): XXX
def canvasCopy(self, event):
@ -85,7 +85,7 @@ class MiRCARTCanvasInterface():
and self.parentCanvas.brushSize[1] > 1:
self.parentCanvas.brushSize = \
[a-1 for a in self.parentCanvas.brushSize]
self.parentFrame.onCanvasUpdate(newBrushSize=self.parentCanvas.brushSize)
self.parentFrame.onCanvasUpdate(brushSize=self.parentCanvas.brushSize)
# }}}
# {{{ canvasDecrCanvasHeight(self, event): XXX
def canvasDecrCanvasHeight(self, event):
@ -166,7 +166,7 @@ class MiRCARTCanvasInterface():
def canvasIncrBrush(self, event):
self.parentCanvas.brushSize = \
[a+1 for a in self.parentCanvas.brushSize]
self.parentFrame.onCanvasUpdate(newBrushSize=self.parentCanvas.brushSize)
self.parentFrame.onCanvasUpdate(brushSize=self.parentCanvas.brushSize)
# }}}
# {{{ canvasIncrCanvasHeight(self, event): XXX
def canvasIncrCanvasHeight(self, event):
@ -196,8 +196,7 @@ class MiRCARTCanvasInterface():
self.parentCanvas.canvasImportStore.importNew(newCanvasSize)
self.canvasPathName = None
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
self.parentFrame.onCanvasUpdate( \
newPathName="", newUndoLevel=-1)
self.parentFrame.onCanvasUpdate(pathName="", undoLevel=-1)
# }}}
# {{{ canvasOpen(self, event): XXX
def canvasOpen(self, event):
@ -220,7 +219,7 @@ class MiRCARTCanvasInterface():
self.parentCanvas.canvasImportStore.importIntoPanel()
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
self.parentFrame.onCanvasUpdate( \
newPathName=self.canvasPathName, newUndoLevel=-1)
pathName=self.canvasPathName, undoLevel=-1)
return True
# }}}
# {{{ canvasPaste(self, event): XXX
@ -261,22 +260,22 @@ class MiRCARTCanvasInterface():
# {{{ canvasToolCircle(self, event): XXX
def canvasToolCircle(self, event):
self.canvasTool = MiRCARTToolCircle(self.parentCanvas)
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasToolLine(self, event): XXX
def canvasToolLine(self, event):
self.canvasTool = MiRCARTToolLine(self.parentCanvas)
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasToolRect(self, event): XXX
def canvasToolRect(self, event):
self.canvasTool = MiRCARTToolRect(self.parentCanvas)
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasToolText(self, event): XXX
def canvasToolText(self, event):
self.canvasTool = MiRCARTToolText(self.parentCanvas)
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasUndo(self, event): XXX
def canvasUndo(self, event):

View File

@ -33,8 +33,7 @@ import os, wx
class MiRCARTFrame(MiRCARTGeneralFrame):
"""XXX"""
panelCanvas = None
lastBrushSize = lastCellPos = lastColours = lastPathName = lastSize = lastToolName = lastUndoLevel = None
panelCanvas = None; lastPanelState = {};
# {{{ Commands
# Id Type Id Labels Icon bitmap Accelerator [Initial state]
@ -159,55 +158,43 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
self.itemsById[eventId][7](self.panelCanvas.canvasInterface, event)
# }}}
# {{{ onCanvasUpdate(self, newBrushSize=None, newCellPos=None, newColours=None, newPathName=None, newSize=None, newToolName=None, newUndoLevel=None): XXX
def onCanvasUpdate(self, newBrushSize=None, newCellPos=None, newColours=None, newPathName=None, newSize=None, newToolName=None, newUndoLevel=None):
if newBrushSize != None:
self.lastBrushSize = newBrushSize
if newCellPos != None:
self.lastCellPos = newCellPos
if newColours != None:
self.lastColours = newColours
if newPathName != None:
self.lastPathName = newPathName
if newSize != None:
self.lastSize = newSize
if newToolName != None:
self.lastToolName = newToolName
if newUndoLevel != None:
self.lastUndoLevel = newUndoLevel
def onCanvasUpdate(self, **kwargs):
self.lastPanelState.update(kwargs)
textItems = []
if self.lastCellPos != None:
textItems.append("X: {:03d} Y: {:03d}".format( \
*self.lastCellPos))
if self.lastSize != None:
textItems.append("W: {:03d} H: {:03d}".format( \
*self.lastSize))
if self.lastBrushSize != None:
textItems.append("Brush: {:02d}x{:02d}".format( \
*self.lastBrushSize))
if self.lastColours != None:
textItems.append("FG: {:02d}, BG: {:02d}".format( \
*self.lastColours))
textItems.append("{} on {}".format( \
MiRCARTColours[self.lastColours[0]][4], \
MiRCARTColours[self.lastColours[1]][4]))
if self.lastPathName != None:
if self.lastPathName != "":
basePathName = os.path.basename(self.lastPathName)
if "cellPos" in self.lastPanelState:
textItems.append("X: {:03d} Y: {:03d}".format( \
*self.lastPanelState["cellPos"]))
if "size" in self.lastPanelState:
textItems.append("W: {:03d} H: {:03d}".format( \
*self.lastPanelState["size"]))
if "brushSize" in self.lastPanelState:
textItems.append("Brush: {:02d}x{:02d}".format( \
*self.lastPanelState["brushSize"]))
if "colours" in self.lastPanelState:
textItems.append("FG: {:02d}, BG: {:02d}".format( \
*self.lastPanelState["colours"]))
textItems.append("{} on {}".format( \
MiRCARTColours[self.lastPanelState["colours"][0]][4], \
MiRCARTColours[self.lastPanelState["colours"][1]][4]))
if "pathName" in self.lastPanelState:
if self.lastPanelState["pathName"] != "":
basePathName = os.path.basename(self.lastPanelState["pathName"])
textItems.append("Current file: {}".format(basePathName))
self.SetTitle("{} - MiRCART".format(basePathName))
else:
self.SetTitle("MiRCART")
if self.lastToolName != None:
textItems.append("Current tool: {}".format(self.lastToolName))
if "toolName" in self.lastPanelState:
textItems.append("Current tool: {}".format( \
self.lastPanelState["toolName"]))
self.statusBar.SetStatusText(" | ".join(textItems))
if self.lastUndoLevel != None:
if self.lastUndoLevel >= 0:
if "undoLevel" in self.lastPanelState:
if self.lastPanelState["undoLevel"] >= 0:
self.menuItemsById[self.CID_UNDO[0]].Enable(True)
self.toolBar.EnableTool(self.CID_UNDO[0], True)
else:
self.menuItemsById[self.CID_UNDO[0]].Enable(False)
self.toolBar.EnableTool(self.CID_UNDO[0], False)
if self.lastUndoLevel > 0:
if self.lastPanelState["undoLevel"] > 0:
self.menuItemsById[self.CID_REDO[0]].Enable(True)
self.toolBar.EnableTool(self.CID_REDO[0], True)
else: