MiRCART{Canvas{,Interface},Frame}.py: merge on{StatusBar,Undo}Update() into onCanvasUpdate().

MiRCARTCanvas{Frame,Interface}.py: adds canvas{De,In}crCanvas{Height,Width}() & CID_*.
MiRCARTCanvasFrame.py:onCanvasUpdate(): updated.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-10 04:23:54 +01:00
parent 3e03126006
commit f9f910160f
3 changed files with 107 additions and 77 deletions

View File

@ -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.onUndoUpdate() self.parentFrame.onCanvasUpdate(newUndoLevel=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,9 +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.onUndoUpdate() self.parentFrame.onCanvasUpdate(newCellPos=self.brushPos, \
newUndoLevel=self.canvasJournal.patchesUndoLevel)
if eventType == wx.wxEVT_MOTION: if eventType == wx.wxEVT_MOTION:
self.parentFrame.onStatusBarUpdate(showPos=mapPoint) self.parentFrame.onCanvasUpdate(newCellPos=mapPoint)
# }}} # }}}
# {{{ onPanelLeaveWindow(self, event): XXX # {{{ onPanelLeaveWindow(self, event): XXX
def onPanelLeaveWindow(self, event): def onPanelLeaveWindow(self, event):
@ -149,7 +150,7 @@ class MiRCARTCanvas(wx.Panel):
self.canvasBackend.cellSize)]) self.canvasBackend.cellSize)])
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.onUndoUpdate() self.parentFrame.onCanvasUpdate(newUndoLevel=-1)
# }}} # }}}
# #
@ -161,6 +162,7 @@ class MiRCARTCanvas(wx.Panel):
self.parentFrame = parentFrame self.parentFrame = parentFrame
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(newColours=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)

View File

@ -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.onStatusBarUpdate() self.parentFrame.onCanvasUpdate(newColours=self.parentCanvas.brushColours)
# }}} # }}}
# {{{ canvasCopy(self, event): XXX # {{{ canvasCopy(self, event): XXX
def canvasCopy(self, event): def canvasCopy(self, event):
@ -86,10 +86,19 @@ class MiRCARTCanvasInterface():
self.parentCanvas.brushSize = \ self.parentCanvas.brushSize = \
[a-1 for a in self.parentCanvas.brushSize] [a-1 for a in self.parentCanvas.brushSize]
# }}} # }}}
# {{{ canvasDecrCanvas(self, event): XXX # {{{ canvasDecrCanvasHeight(self, event): XXX
def canvasDecrCanvas(self, event): def canvasDecrCanvasHeight(self, event):
newCanvasSize = [a-1 if a > 1 else a for a in self.parentCanvas.canvasSize] if self.parentCanvas.canvasSize[1] > 1:
self._updateCanvasSize(newCanvasSize) self._updateCanvasSize([ \
self.parentCanvas.canvasSize[0], \
self.parentCanvas.canvasSize[1]-1])
# }}}
# {{{ canvasDecrCanvasWidth(self, event): XXX
def canvasDecrCanvasWidth(self, event):
if self.parentCanvas.canvasSize[0] > 1:
self._updateCanvasSize([ \
self.parentCanvas.canvasSize[0]-1, \
self.parentCanvas.canvasSize[1]])
# }}} # }}}
# {{{ canvasDelete(self, event): XXX # {{{ canvasDelete(self, event): XXX
def canvasDelete(self, event): def canvasDelete(self, event):
@ -157,10 +166,17 @@ class MiRCARTCanvasInterface():
self.parentCanvas.brushSize = \ self.parentCanvas.brushSize = \
[a+1 for a in self.parentCanvas.brushSize] [a+1 for a in self.parentCanvas.brushSize]
# }}} # }}}
# {{{ canvasIncrCanvas(self, event): XXX # {{{ canvasIncrCanvasHeight(self, event): XXX
def canvasIncrCanvas(self, event): def canvasIncrCanvasHeight(self, event):
newCanvasSize = [a+1 for a in self.parentCanvas.canvasSize] self._updateCanvasSize([ \
self._updateCanvasSize(newCanvasSize) self.parentCanvas.canvasSize[0], \
self.parentCanvas.canvasSize[1]+1])
# }}}
# {{{ canvasIncrCanvasWidth(self, event): XXX
def canvasIncrCanvasWidth(self, event):
self._updateCanvasSize([ \
self.parentCanvas.canvasSize[0]+1, \
self.parentCanvas.canvasSize[1]])
# }}} # }}}
# {{{ canvasNew(self, event, newCanvasSize=None): XXX # {{{ canvasNew(self, event, newCanvasSize=None): XXX
def canvasNew(self, event, newCanvasSize=None): def canvasNew(self, event, newCanvasSize=None):
@ -178,8 +194,8 @@ 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.onStatusBarUpdate() self.parentFrame.onCanvasUpdate( \
self.parentFrame.onUndoUpdate() newPathName="", newUndoLevel=-1)
# }}} # }}}
# {{{ canvasOpen(self, event): XXX # {{{ canvasOpen(self, event): XXX
def canvasOpen(self, event): def canvasOpen(self, event):
@ -201,8 +217,8 @@ class MiRCARTCanvasInterface():
self.parentCanvas.canvasImportStore.importTextFile(self.canvasPathName) self.parentCanvas.canvasImportStore.importTextFile(self.canvasPathName)
self.parentCanvas.canvasImportStore.importIntoPanel() self.parentCanvas.canvasImportStore.importIntoPanel()
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor)) self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
self.parentFrame.onStatusBarUpdate(showFileName=self.canvasPathName) self.parentFrame.onCanvasUpdate( \
self.parentFrame.onUndoUpdate() newPathName=self.canvasPathName, newUndoLevel=-1)
return True return True
# }}} # }}}
# {{{ canvasPaste(self, event): XXX # {{{ canvasPaste(self, event): XXX

View File

@ -34,6 +34,7 @@ import os, wx
class MiRCARTFrame(MiRCARTGeneralFrame): class MiRCARTFrame(MiRCARTGeneralFrame):
"""XXX""" """XXX"""
panelCanvas = None panelCanvas = None
lastCellPos = lastColours = lastPathName = lastUndoLevel = None
# {{{ Commands # {{{ Commands
# Id Type Id Labels Icon bitmap Accelerator [Initial state] # Id Type Id Labels Icon bitmap Accelerator [Initial state]
@ -54,15 +55,19 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
CID_COPY = [0x10b, TID_COMMAND, "Copy", "&Copy", ["", wx.ART_COPY], None, False, MiRCARTCanvasInterface.canvasCopy] CID_COPY = [0x10b, TID_COMMAND, "Copy", "&Copy", ["", wx.ART_COPY], None, False, MiRCARTCanvasInterface.canvasCopy]
CID_PASTE = [0x10c, TID_COMMAND, "Paste", "&Paste", ["", wx.ART_PASTE], None, False, MiRCARTCanvasInterface.canvasPaste] CID_PASTE = [0x10c, TID_COMMAND, "Paste", "&Paste", ["", wx.ART_PASTE], None, False, MiRCARTCanvasInterface.canvasPaste]
CID_DELETE = [0x10d, TID_COMMAND, "Delete", "De&lete", ["", wx.ART_DELETE], None, False, MiRCARTCanvasInterface.canvasDelete] CID_DELETE = [0x10d, TID_COMMAND, "Delete", "De&lete", ["", wx.ART_DELETE], None, False, MiRCARTCanvasInterface.canvasDelete]
CID_INCR_CANVAS = [0x10e, TID_COMMAND, "Increase canvas size", \ CID_INCRW_CANVAS = [0x10e, TID_COMMAND, "Increase canvas width", \
"I&ncrease canvas size", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("+")], None, MiRCARTCanvasInterface.canvasIncrCanvas] "Increase canvas &width", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("D")], None, MiRCARTCanvasInterface.canvasIncrCanvasWidth]
CID_DECR_CANVAS = [0x10f, TID_COMMAND, "Decrease canvas size", \ CID_DECRW_CANVAS = [0x10f, TID_COMMAND, "Decrease canvas width", \
"D&ecrease canvas size", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("-")], None, MiRCARTCanvasInterface.canvasDecrCanvas] "Decrease canvas w&idth", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("A")], None, MiRCARTCanvasInterface.canvasDecrCanvasWidth]
CID_INCR_BRUSH = [0x110, TID_COMMAND, "Increase brush size", \ CID_INCRH_CANVAS = [0x110, TID_COMMAND, "Increase canvas height", \
"&Increase brush size", ["", wx.ART_PLUS], [wx.ACCEL_CTRL, ord("+")], None, MiRCARTCanvasInterface.canvasIncrBrush] "Increase canvas &height", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("S")], None, MiRCARTCanvasInterface.canvasIncrCanvasHeight]
CID_DECR_BRUSH = [0x111, TID_COMMAND, "Decrease brush size", \ CID_DECRH_CANVAS = [0x111, TID_COMMAND, "Decrease canvas height", \
"Decrease canvas h&eight", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("W")], None, MiRCARTCanvasInterface.canvasDecrCanvasHeight]
CID_INCR_BRUSH = [0x112, TID_COMMAND, "Increase brush size", \
"I&ncrease brush size", ["", wx.ART_PLUS], [wx.ACCEL_CTRL, ord("+")], None, MiRCARTCanvasInterface.canvasIncrBrush]
CID_DECR_BRUSH = [0x113, TID_COMMAND, "Decrease brush size", \
"&Decrease brush size", ["", wx.ART_MINUS], [wx.ACCEL_CTRL, ord("-")], None, MiRCARTCanvasInterface.canvasDecrBrush] "&Decrease brush size", ["", wx.ART_MINUS], [wx.ACCEL_CTRL, ord("-")], None, MiRCARTCanvasInterface.canvasDecrBrush]
CID_SOLID_BRUSH = [0x112, TID_SELECT, "Solid brush", "&Solid brush", None, None, True, MiRCARTCanvasInterface.canvasBrushSolid] CID_SOLID_BRUSH = [0x114, TID_SELECT, "Solid brush", "&Solid brush", None, None, True, MiRCARTCanvasInterface.canvasBrushSolid]
CID_RECT = [0x150, TID_SELECT, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True, MiRCARTCanvasInterface.canvasToolRect] CID_RECT = [0x150, TID_SELECT, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True, MiRCARTCanvasInterface.canvasToolRect]
CID_CIRCLE = [0x151, TID_SELECT, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False, MiRCARTCanvasInterface.canvasToolCircle] CID_CIRCLE = [0x151, TID_SELECT, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False, MiRCARTCanvasInterface.canvasToolCircle]
@ -87,34 +92,35 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
CID_COLOUR15 = [0x1af, TID_COMMAND, "Colour #15", "Colour #15", None, None, None, MiRCARTCanvasInterface.canvasColour] CID_COLOUR15 = [0x1af, TID_COMMAND, "Colour #15", "Colour #15", None, None, None, MiRCARTCanvasInterface.canvasColour]
# }}} # }}}
# {{{ Menus # {{{ Menus
MID_FILE = (0x300, TID_MENU, "File", "&File", ( \ MID_FILE = (0x300, TID_MENU, "File", "&File", ( \
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_MENU_SEP, \ CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_MENU_SEP, \
CID_EXPORT_AS_PNG, CID_EXPORT_IMGUR, CID_EXPORT_PASTEBIN, NID_MENU_SEP, \ CID_EXPORT_AS_PNG, CID_EXPORT_IMGUR, CID_EXPORT_PASTEBIN, NID_MENU_SEP, \
CID_EXIT)) CID_EXIT))
MID_EDIT = (0x301, TID_MENU, "Edit", "&Edit", ( \ MID_EDIT = (0x301, TID_MENU, "Edit", "&Edit", ( \
CID_UNDO, CID_REDO, NID_MENU_SEP, \ CID_UNDO, CID_REDO, NID_MENU_SEP, \
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_MENU_SEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_MENU_SEP, \
CID_INCR_CANVAS, CID_DECR_CANVAS, NID_MENU_SEP, \ CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, NID_MENU_SEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH)) CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH))
MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \ MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT)) CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT))
# }}} # }}}
# {{{ Toolbars # {{{ Toolbars
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \ BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_SEP, \ CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_SEP, \
CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \ CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \ CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, NID_TOOLBAR_SEP, \ CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, NID_TOOLBAR_SEP, \
CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \ CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \
CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \ CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \
CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \ CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \
CID_COLOUR15)) CID_COLOUR15))
# }}} # }}}
# {{{ Accelerators (hotkeys) # {{{ Accelerators (hotkeys)
AID_EDIT = (0x500, TID_ACCELS, ( \ AID_EDIT = (0x500, TID_ACCELS, ( \
CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO, \ CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO, \
CID_INCR_CANVAS, CID_DECR_CANVAS, CID_INCR_BRUSH, CID_DECR_BRUSH)) CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, \
CID_INCR_BRUSH, CID_DECR_BRUSH))
# }}} # }}}
# {{{ Lists # {{{ Lists
LID_ACCELS = (0x600, TID_LIST, (AID_EDIT)) LID_ACCELS = (0x600, TID_LIST, (AID_EDIT))
@ -152,43 +158,49 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
else: else:
self.itemsById[eventId][7](self.panelCanvas.canvasInterface, event) self.itemsById[eventId][7](self.panelCanvas.canvasInterface, event)
# }}} # }}}
# {{{ onStatusBarUpdate(self, showColours=None, showFileName=True, showPos=None): XXX # {{{ onCanvasUpdate(self, newCellPos=None, newColours=None, newPathName=None, newUndoLevel=None): XXX
def onStatusBarUpdate(self, showColours=True, showFileName=True, showPos=True): def onCanvasUpdate(self, newCellPos=None, newColours=None, newPathName=None, newUndoLevel=None):
if showColours == True: if newCellPos != None:
showColours = self.panelCanvas.brushColours self.lastCellPos = newCellPos
if showPos == True: if newColours != None:
showPos = self.panelCanvas.brushPos self.lastColours = newColours
if showFileName == True: if newPathName != None:
showFileName = self.panelCanvas.canvasInterface.canvasPathName self.lastPathName = newPathName
if newUndoLevel != None:
self.lastUndoLevel = newUndoLevel
textItems = [] textItems = []
if showPos != None: if self.lastCellPos != None:
textItems.append("X: {:03d} Y: {:03d}".format( \ textItems.append("X: {:03d} Y: {:03d}".format( \
showPos[0], showPos[1])) *self.lastCellPos))
if showColours != None: if self.lastColours != None:
textItems.append("FG: {:02d}, BG: {:02d}".format( \ textItems.append("FG: {:02d}, BG: {:02d}".format( \
showColours[0],showColours[1])) *self.lastColours))
textItems.append("{} on {}".format( \ textItems.append("{} on {}".format( \
MiRCARTColours[showColours[0]][4], \ MiRCARTColours[self.lastColours[0]][4], \
MiRCARTColours[showColours[1]][4])) MiRCARTColours[self.lastColours[1]][4]))
if showFileName != None: if self.lastPathName != None:
textItems.append("Current file: {}".format( \ if self.lastPathName != "":
os.path.basename(showFileName))) basePathName = os.path.basename(self.lastPathName)
textItems.append("Current file: {}".format(basePathName))
self.SetTitle("{} - MiRCART".format(basePathName))
else:
self.SetTitle("MiRCART")
if self.lastUndoLevel != None:
textItems.append("Undo level: {}".format(self.lastUndoLevel))
self.statusBar.SetStatusText(" | ".join(textItems)) self.statusBar.SetStatusText(" | ".join(textItems))
# }}} if self.lastUndoLevel != None:
# {{{ onUndoUpdate(self): XXX if self.lastUndoLevel >= 0:
def onUndoUpdate(self): self.menuItemsById[self.CID_UNDO[0]].Enable(True)
if self.panelCanvas.canvasJournal.patchesUndo[self.panelCanvas.canvasJournal.patchesUndoLevel] != None: self.toolBar.EnableTool(self.CID_UNDO[0], True)
self.menuItemsById[self.CID_UNDO[0]].Enable(True) else:
self.toolBar.EnableTool(self.CID_UNDO[0], True) self.menuItemsById[self.CID_UNDO[0]].Enable(False)
else: self.toolBar.EnableTool(self.CID_UNDO[0], False)
self.menuItemsById[self.CID_UNDO[0]].Enable(False) if self.lastUndoLevel > 0:
self.toolBar.EnableTool(self.CID_UNDO[0], False) self.menuItemsById[self.CID_REDO[0]].Enable(True)
if self.panelCanvas.canvasJournal.patchesUndoLevel > 0: self.toolBar.EnableTool(self.CID_REDO[0], True)
self.menuItemsById[self.CID_REDO[0]].Enable(True) else:
self.toolBar.EnableTool(self.CID_REDO[0], True) self.menuItemsById[self.CID_REDO[0]].Enable(False)
else: self.toolBar.EnableTool(self.CID_REDO[0], False)
self.menuItemsById[self.CID_REDO[0]].Enable(False)
self.toolBar.EnableTool(self.CID_REDO[0], False)
# }}} # }}}
# #