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 7abd7679d2
commit 1b00bb3b2f
3 changed files with 107 additions and 77 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.onUndoUpdate()
self.parentFrame.onCanvasUpdate(newUndoLevel=self.canvasJournal.patchesUndoLevel)
# }}}
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
def _dispatchPatch(self, eventDc, isCursor, patch):
@ -98,9 +98,10 @@ class MiRCARTCanvas(wx.Panel):
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
self._dispatchPatch, eventDc)
if self._canvasDirty:
self.parentFrame.onUndoUpdate()
self.parentFrame.onCanvasUpdate(newCellPos=self.brushPos, \
newUndoLevel=self.canvasJournal.patchesUndoLevel)
if eventType == wx.wxEVT_MOTION:
self.parentFrame.onStatusBarUpdate(showPos=mapPoint)
self.parentFrame.onCanvasUpdate(newCellPos=mapPoint)
# }}}
# {{{ onPanelLeaveWindow(self, event): XXX
def onPanelLeaveWindow(self, event):
@ -149,7 +150,7 @@ class MiRCARTCanvas(wx.Panel):
self.canvasBackend.cellSize)])
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
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.canvasMap = None; self.canvasPos = canvasPos; self.canvasSize = canvasSize;
self.brushColours = [4, 1]; self.brushPos = [0, 0]; self.brushSize = [1, 1];
self.parentFrame.onCanvasUpdate(newColours=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.onStatusBarUpdate()
self.parentFrame.onCanvasUpdate(newColours=self.parentCanvas.brushColours)
# }}}
# {{{ canvasCopy(self, event): XXX
def canvasCopy(self, event):
@ -86,10 +86,19 @@ class MiRCARTCanvasInterface():
self.parentCanvas.brushSize = \
[a-1 for a in self.parentCanvas.brushSize]
# }}}
# {{{ canvasDecrCanvas(self, event): XXX
def canvasDecrCanvas(self, event):
newCanvasSize = [a-1 if a > 1 else a for a in self.parentCanvas.canvasSize]
self._updateCanvasSize(newCanvasSize)
# {{{ canvasDecrCanvasHeight(self, event): XXX
def canvasDecrCanvasHeight(self, event):
if self.parentCanvas.canvasSize[1] > 1:
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
def canvasDelete(self, event):
@ -157,10 +166,17 @@ class MiRCARTCanvasInterface():
self.parentCanvas.brushSize = \
[a+1 for a in self.parentCanvas.brushSize]
# }}}
# {{{ canvasIncrCanvas(self, event): XXX
def canvasIncrCanvas(self, event):
newCanvasSize = [a+1 for a in self.parentCanvas.canvasSize]
self._updateCanvasSize(newCanvasSize)
# {{{ canvasIncrCanvasHeight(self, event): XXX
def canvasIncrCanvasHeight(self, event):
self._updateCanvasSize([ \
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
def canvasNew(self, event, newCanvasSize=None):
@ -178,8 +194,8 @@ class MiRCARTCanvasInterface():
self.parentCanvas.canvasImportStore.importNew(newCanvasSize)
self.canvasPathName = None
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
self.parentFrame.onStatusBarUpdate()
self.parentFrame.onUndoUpdate()
self.parentFrame.onCanvasUpdate( \
newPathName="", newUndoLevel=-1)
# }}}
# {{{ canvasOpen(self, event): XXX
def canvasOpen(self, event):
@ -201,8 +217,8 @@ class MiRCARTCanvasInterface():
self.parentCanvas.canvasImportStore.importTextFile(self.canvasPathName)
self.parentCanvas.canvasImportStore.importIntoPanel()
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
self.parentFrame.onStatusBarUpdate(showFileName=self.canvasPathName)
self.parentFrame.onUndoUpdate()
self.parentFrame.onCanvasUpdate( \
newPathName=self.canvasPathName, newUndoLevel=-1)
return True
# }}}
# {{{ canvasPaste(self, event): XXX

View File

@ -34,6 +34,7 @@ import os, wx
class MiRCARTFrame(MiRCARTGeneralFrame):
"""XXX"""
panelCanvas = None
lastCellPos = lastColours = lastPathName = lastUndoLevel = None
# {{{ Commands
# 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_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_INCR_CANVAS = [0x10e, TID_COMMAND, "Increase canvas size", \
"I&ncrease canvas size", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("+")], None, MiRCARTCanvasInterface.canvasIncrCanvas]
CID_DECR_CANVAS = [0x10f, TID_COMMAND, "Decrease canvas size", \
"D&ecrease canvas size", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("-")], None, MiRCARTCanvasInterface.canvasDecrCanvas]
CID_INCR_BRUSH = [0x110, TID_COMMAND, "Increase brush size", \
"&Increase brush size", ["", wx.ART_PLUS], [wx.ACCEL_CTRL, ord("+")], None, MiRCARTCanvasInterface.canvasIncrBrush]
CID_DECR_BRUSH = [0x111, TID_COMMAND, "Decrease brush size", \
CID_INCRW_CANVAS = [0x10e, TID_COMMAND, "Increase canvas width", \
"Increase canvas &width", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("D")], None, MiRCARTCanvasInterface.canvasIncrCanvasWidth]
CID_DECRW_CANVAS = [0x10f, TID_COMMAND, "Decrease canvas width", \
"Decrease canvas w&idth", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("A")], None, MiRCARTCanvasInterface.canvasDecrCanvasWidth]
CID_INCRH_CANVAS = [0x110, TID_COMMAND, "Increase canvas height", \
"Increase canvas &height", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("S")], None, MiRCARTCanvasInterface.canvasIncrCanvasHeight]
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]
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_CIRCLE = [0x151, TID_SELECT, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False, MiRCARTCanvasInterface.canvasToolCircle]
@ -94,7 +99,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
MID_EDIT = (0x301, TID_MENU, "Edit", "&Edit", ( \
CID_UNDO, CID_REDO, 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))
MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT))
@ -114,7 +119,8 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
# {{{ Accelerators (hotkeys)
AID_EDIT = (0x500, TID_ACCELS, ( \
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
LID_ACCELS = (0x600, TID_LIST, (AID_EDIT))
@ -152,38 +158,44 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
else:
self.itemsById[eventId][7](self.panelCanvas.canvasInterface, event)
# }}}
# {{{ onStatusBarUpdate(self, showColours=None, showFileName=True, showPos=None): XXX
def onStatusBarUpdate(self, showColours=True, showFileName=True, showPos=True):
if showColours == True:
showColours = self.panelCanvas.brushColours
if showPos == True:
showPos = self.panelCanvas.brushPos
if showFileName == True:
showFileName = self.panelCanvas.canvasInterface.canvasPathName
# {{{ onCanvasUpdate(self, newCellPos=None, newColours=None, newPathName=None, newUndoLevel=None): XXX
def onCanvasUpdate(self, newCellPos=None, newColours=None, newPathName=None, newUndoLevel=None):
if newCellPos != None:
self.lastCellPos = newCellPos
if newColours != None:
self.lastColours = newColours
if newPathName != None:
self.lastPathName = newPathName
if newUndoLevel != None:
self.lastUndoLevel = newUndoLevel
textItems = []
if showPos != None:
if self.lastCellPos != None:
textItems.append("X: {:03d} Y: {:03d}".format( \
showPos[0], showPos[1]))
if showColours != None:
*self.lastCellPos))
if self.lastColours != None:
textItems.append("FG: {:02d}, BG: {:02d}".format( \
showColours[0],showColours[1]))
*self.lastColours))
textItems.append("{} on {}".format( \
MiRCARTColours[showColours[0]][4], \
MiRCARTColours[showColours[1]][4]))
if showFileName != None:
textItems.append("Current file: {}".format( \
os.path.basename(showFileName)))
MiRCARTColours[self.lastColours[0]][4], \
MiRCARTColours[self.lastColours[1]][4]))
if self.lastPathName != None:
if self.lastPathName != "":
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))
# }}}
# {{{ onUndoUpdate(self): XXX
def onUndoUpdate(self):
if self.panelCanvas.canvasJournal.patchesUndo[self.panelCanvas.canvasJournal.patchesUndoLevel] != None:
if self.lastUndoLevel != None:
if self.lastUndoLevel >= 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.panelCanvas.canvasJournal.patchesUndoLevel > 0:
if self.lastUndoLevel > 0:
self.menuItemsById[self.CID_REDO[0]].Enable(True)
self.toolBar.EnableTool(self.CID_REDO[0], True)
else: