mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 15:26:37 +00:00
MiRCART{Canvas{,Interface},Frame}.py: use dict() to cache canvas state in Frame.
This commit is contained in:
parent
402e542137
commit
2254a0638b
@ -48,7 +48,7 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
for patch in deltaPatches:
|
for patch in deltaPatches:
|
||||||
if self.canvasBackend.drawPatch(eventDc, patch):
|
if self.canvasBackend.drawPatch(eventDc, patch):
|
||||||
self._commitPatch(patch)
|
self._commitPatch(patch)
|
||||||
self.parentFrame.onCanvasUpdate(newUndoLevel=self.canvasJournal.patchesUndoLevel)
|
self.parentFrame.onCanvasUpdate(undoLevel=self.canvasJournal.patchesUndoLevel)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
|
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
|
||||||
def _dispatchPatch(self, eventDc, isCursor, patch):
|
def _dispatchPatch(self, eventDc, isCursor, patch):
|
||||||
@ -98,10 +98,10 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
|
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
|
||||||
self._dispatchPatch, eventDc)
|
self._dispatchPatch, eventDc)
|
||||||
if self._canvasDirty:
|
if self._canvasDirty:
|
||||||
self.parentFrame.onCanvasUpdate(newCellPos=self.brushPos, \
|
self.parentFrame.onCanvasUpdate(cellPos=self.brushPos, \
|
||||||
newUndoLevel=self.canvasJournal.patchesUndoLevel)
|
undoLevel=self.canvasJournal.patchesUndoLevel)
|
||||||
if eventType == wx.wxEVT_MOTION:
|
if eventType == wx.wxEVT_MOTION:
|
||||||
self.parentFrame.onCanvasUpdate(newCellPos=mapPoint)
|
self.parentFrame.onCanvasUpdate(cellPos=mapPoint)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onPanelLeaveWindow(self, event): XXX
|
# {{{ onPanelLeaveWindow(self, event): XXX
|
||||||
def onPanelLeaveWindow(self, event):
|
def onPanelLeaveWindow(self, event):
|
||||||
@ -151,7 +151,7 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
|
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
|
||||||
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
|
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
|
||||||
self.parentFrame.onCanvasUpdate( \
|
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.canvasMap = None; self.canvasPos = canvasPos; self.canvasSize = canvasSize;
|
||||||
self.brushColours = [4, 1]; self.brushPos = [0, 0]; self.brushSize = [1, 1];
|
self.brushColours = [4, 1]; self.brushPos = [0, 0]; self.brushSize = [1, 1];
|
||||||
self.parentFrame.onCanvasUpdate( \
|
self.parentFrame.onCanvasUpdate( \
|
||||||
newBrushSize=self.brushSize, newColours=self.brushColours)
|
brushSize=self.brushSize, colours=self.brushColours)
|
||||||
self.canvasBackend = MiRCARTCanvasBackend(canvasSize, cellSize)
|
self.canvasBackend = MiRCARTCanvasBackend(canvasSize, cellSize)
|
||||||
self.canvasJournal = MiRCARTCanvasJournal()
|
self.canvasJournal = MiRCARTCanvasJournal()
|
||||||
self.canvasExportStore = MiRCARTCanvasExportStore(parentCanvas=self)
|
self.canvasExportStore = MiRCARTCanvasExportStore(parentCanvas=self)
|
||||||
|
@ -69,7 +69,7 @@ class MiRCARTCanvasInterface():
|
|||||||
self.parentCanvas.brushColours[0] = numColour
|
self.parentCanvas.brushColours[0] = numColour
|
||||||
elif event.GetEventType() == wx.wxEVT_TOOL_RCLICKED:
|
elif event.GetEventType() == wx.wxEVT_TOOL_RCLICKED:
|
||||||
self.parentCanvas.brushColours[1] = numColour
|
self.parentCanvas.brushColours[1] = numColour
|
||||||
self.parentFrame.onCanvasUpdate(newColours=self.parentCanvas.brushColours)
|
self.parentFrame.onCanvasUpdate(colours=self.parentCanvas.brushColours)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasCopy(self, event): XXX
|
# {{{ canvasCopy(self, event): XXX
|
||||||
def canvasCopy(self, event):
|
def canvasCopy(self, event):
|
||||||
@ -85,7 +85,7 @@ class MiRCARTCanvasInterface():
|
|||||||
and self.parentCanvas.brushSize[1] > 1:
|
and self.parentCanvas.brushSize[1] > 1:
|
||||||
self.parentCanvas.brushSize = \
|
self.parentCanvas.brushSize = \
|
||||||
[a-1 for a in 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
|
# {{{ canvasDecrCanvasHeight(self, event): XXX
|
||||||
def canvasDecrCanvasHeight(self, event):
|
def canvasDecrCanvasHeight(self, event):
|
||||||
@ -166,7 +166,7 @@ class MiRCARTCanvasInterface():
|
|||||||
def canvasIncrBrush(self, event):
|
def canvasIncrBrush(self, event):
|
||||||
self.parentCanvas.brushSize = \
|
self.parentCanvas.brushSize = \
|
||||||
[a+1 for a in 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
|
# {{{ canvasIncrCanvasHeight(self, event): XXX
|
||||||
def canvasIncrCanvasHeight(self, event):
|
def canvasIncrCanvasHeight(self, event):
|
||||||
@ -196,8 +196,7 @@ class MiRCARTCanvasInterface():
|
|||||||
self.parentCanvas.canvasImportStore.importNew(newCanvasSize)
|
self.parentCanvas.canvasImportStore.importNew(newCanvasSize)
|
||||||
self.canvasPathName = None
|
self.canvasPathName = None
|
||||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||||
self.parentFrame.onCanvasUpdate( \
|
self.parentFrame.onCanvasUpdate(pathName="", undoLevel=-1)
|
||||||
newPathName="", newUndoLevel=-1)
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasOpen(self, event): XXX
|
# {{{ canvasOpen(self, event): XXX
|
||||||
def canvasOpen(self, event):
|
def canvasOpen(self, event):
|
||||||
@ -220,7 +219,7 @@ class MiRCARTCanvasInterface():
|
|||||||
self.parentCanvas.canvasImportStore.importIntoPanel()
|
self.parentCanvas.canvasImportStore.importIntoPanel()
|
||||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||||
self.parentFrame.onCanvasUpdate( \
|
self.parentFrame.onCanvasUpdate( \
|
||||||
newPathName=self.canvasPathName, newUndoLevel=-1)
|
pathName=self.canvasPathName, undoLevel=-1)
|
||||||
return True
|
return True
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasPaste(self, event): XXX
|
# {{{ canvasPaste(self, event): XXX
|
||||||
@ -261,22 +260,22 @@ class MiRCARTCanvasInterface():
|
|||||||
# {{{ canvasToolCircle(self, event): XXX
|
# {{{ canvasToolCircle(self, event): XXX
|
||||||
def canvasToolCircle(self, event):
|
def canvasToolCircle(self, event):
|
||||||
self.canvasTool = MiRCARTToolCircle(self.parentCanvas)
|
self.canvasTool = MiRCARTToolCircle(self.parentCanvas)
|
||||||
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
|
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasToolLine(self, event): XXX
|
# {{{ canvasToolLine(self, event): XXX
|
||||||
def canvasToolLine(self, event):
|
def canvasToolLine(self, event):
|
||||||
self.canvasTool = MiRCARTToolLine(self.parentCanvas)
|
self.canvasTool = MiRCARTToolLine(self.parentCanvas)
|
||||||
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
|
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasToolRect(self, event): XXX
|
# {{{ canvasToolRect(self, event): XXX
|
||||||
def canvasToolRect(self, event):
|
def canvasToolRect(self, event):
|
||||||
self.canvasTool = MiRCARTToolRect(self.parentCanvas)
|
self.canvasTool = MiRCARTToolRect(self.parentCanvas)
|
||||||
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
|
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasToolText(self, event): XXX
|
# {{{ canvasToolText(self, event): XXX
|
||||||
def canvasToolText(self, event):
|
def canvasToolText(self, event):
|
||||||
self.canvasTool = MiRCARTToolText(self.parentCanvas)
|
self.canvasTool = MiRCARTToolText(self.parentCanvas)
|
||||||
self.parentFrame.onCanvasUpdate(newToolName=self.canvasTool.name)
|
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasUndo(self, event): XXX
|
# {{{ canvasUndo(self, event): XXX
|
||||||
def canvasUndo(self, event):
|
def canvasUndo(self, event):
|
||||||
|
@ -33,8 +33,7 @@ import os, wx
|
|||||||
|
|
||||||
class MiRCARTFrame(MiRCARTGeneralFrame):
|
class MiRCARTFrame(MiRCARTGeneralFrame):
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
panelCanvas = None
|
panelCanvas = None; lastPanelState = {};
|
||||||
lastBrushSize = lastCellPos = lastColours = lastPathName = lastSize = lastToolName = lastUndoLevel = None
|
|
||||||
|
|
||||||
# {{{ Commands
|
# {{{ Commands
|
||||||
# Id Type Id Labels Icon bitmap Accelerator [Initial state]
|
# Id Type Id Labels Icon bitmap Accelerator [Initial state]
|
||||||
@ -159,55 +158,43 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
|
|||||||
self.itemsById[eventId][7](self.panelCanvas.canvasInterface, event)
|
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
|
# {{{ 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):
|
def onCanvasUpdate(self, **kwargs):
|
||||||
if newBrushSize != None:
|
self.lastPanelState.update(kwargs)
|
||||||
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
|
|
||||||
textItems = []
|
textItems = []
|
||||||
if self.lastCellPos != None:
|
if "cellPos" in self.lastPanelState:
|
||||||
textItems.append("X: {:03d} Y: {:03d}".format( \
|
textItems.append("X: {:03d} Y: {:03d}".format( \
|
||||||
*self.lastCellPos))
|
*self.lastPanelState["cellPos"]))
|
||||||
if self.lastSize != None:
|
if "size" in self.lastPanelState:
|
||||||
textItems.append("W: {:03d} H: {:03d}".format( \
|
textItems.append("W: {:03d} H: {:03d}".format( \
|
||||||
*self.lastSize))
|
*self.lastPanelState["size"]))
|
||||||
if self.lastBrushSize != None:
|
if "brushSize" in self.lastPanelState:
|
||||||
textItems.append("Brush: {:02d}x{:02d}".format( \
|
textItems.append("Brush: {:02d}x{:02d}".format( \
|
||||||
*self.lastBrushSize))
|
*self.lastPanelState["brushSize"]))
|
||||||
if self.lastColours != None:
|
if "colours" in self.lastPanelState:
|
||||||
textItems.append("FG: {:02d}, BG: {:02d}".format( \
|
textItems.append("FG: {:02d}, BG: {:02d}".format( \
|
||||||
*self.lastColours))
|
*self.lastPanelState["colours"]))
|
||||||
textItems.append("{} on {}".format( \
|
textItems.append("{} on {}".format( \
|
||||||
MiRCARTColours[self.lastColours[0]][4], \
|
MiRCARTColours[self.lastPanelState["colours"][0]][4], \
|
||||||
MiRCARTColours[self.lastColours[1]][4]))
|
MiRCARTColours[self.lastPanelState["colours"][1]][4]))
|
||||||
if self.lastPathName != None:
|
if "pathName" in self.lastPanelState:
|
||||||
if self.lastPathName != "":
|
if self.lastPanelState["pathName"] != "":
|
||||||
basePathName = os.path.basename(self.lastPathName)
|
basePathName = os.path.basename(self.lastPanelState["pathName"])
|
||||||
textItems.append("Current file: {}".format(basePathName))
|
textItems.append("Current file: {}".format(basePathName))
|
||||||
self.SetTitle("{} - MiRCART".format(basePathName))
|
self.SetTitle("{} - MiRCART".format(basePathName))
|
||||||
else:
|
else:
|
||||||
self.SetTitle("MiRCART")
|
self.SetTitle("MiRCART")
|
||||||
if self.lastToolName != None:
|
if "toolName" in self.lastPanelState:
|
||||||
textItems.append("Current tool: {}".format(self.lastToolName))
|
textItems.append("Current tool: {}".format( \
|
||||||
|
self.lastPanelState["toolName"]))
|
||||||
self.statusBar.SetStatusText(" | ".join(textItems))
|
self.statusBar.SetStatusText(" | ".join(textItems))
|
||||||
if self.lastUndoLevel != None:
|
if "undoLevel" in self.lastPanelState:
|
||||||
if self.lastUndoLevel >= 0:
|
if self.lastPanelState["undoLevel"] >= 0:
|
||||||
self.menuItemsById[self.CID_UNDO[0]].Enable(True)
|
self.menuItemsById[self.CID_UNDO[0]].Enable(True)
|
||||||
self.toolBar.EnableTool(self.CID_UNDO[0], True)
|
self.toolBar.EnableTool(self.CID_UNDO[0], True)
|
||||||
else:
|
else:
|
||||||
self.menuItemsById[self.CID_UNDO[0]].Enable(False)
|
self.menuItemsById[self.CID_UNDO[0]].Enable(False)
|
||||||
self.toolBar.EnableTool(self.CID_UNDO[0], 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.menuItemsById[self.CID_REDO[0]].Enable(True)
|
||||||
self.toolBar.EnableTool(self.CID_REDO[0], True)
|
self.toolBar.EnableTool(self.CID_REDO[0], True)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user