libgui/GuiCanvasInterface.py: minor cleanup.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-08 19:02:19 +02:00
parent f6e2dbd64b
commit b83684073e
1 changed files with 130 additions and 146 deletions

View File

@ -24,29 +24,6 @@ from GuiFrame import NID_MENU_SEP, NID_TOOLBAR_HSEP
from ImgurApiKey import ImgurApiKey from ImgurApiKey import ImgurApiKey
import io, os, sys, wx import io, os, sys, wx
def GuiCanvasCommandDecorator(caption, label, icon, accel, initialState):
# {{{ GuiCanvasCommandDecoratorOuter(targetObject)
def GuiCanvasCommandDecoratorOuter(targetObject):
if callable(targetObject):
if not hasattr(targetObject, "attrDict"):
setattr(targetObject, "attrDict", [])
targetObject.attrDict = {"caption": caption, "label": label, "icon": icon, "accel": accel, "initialState": initialState, "id": None}
return targetObject
return GuiCanvasCommandDecoratorOuter
# }}}
def GuiCanvasSelectDecorator(idx, caption, label, icon, accel, initialState):
# {{{ GuiCanvasSelectDecoratorOuter(targetObject)
def GuiCanvasSelectDecoratorOuter(targetObject):
if callable(targetObject):
if not hasattr(targetObject, "attrList"):
setattr(targetObject, "attrList", [])
setattr(targetObject, "isSelect", True)
targetObject.attrList.insert(0, {"caption": caption, "label": label, "icon": icon, "accel": accel, "initialState": initialState, "id": None, "idx": idx})
return targetObject
return GuiCanvasSelectDecoratorOuter
# }}}
class GuiCanvasInterface(): class GuiCanvasInterface():
# {{{ _import(self, f, newDirty, pathName) # {{{ _import(self, f, newDirty, pathName)
def _import(self, f, newDirty, pathName): def _import(self, f, newDirty, pathName):
@ -114,13 +91,45 @@ class GuiCanvasInterface():
return True return True
# }}} # }}}
# {{{ CommandDecoratorOuter(targetObject)
def CommandDecorator(caption, label, icon, accel, initialState):
def CommandDecoratorOuter(targetObject):
if callable(targetObject):
if not hasattr(targetObject, "attrDict"):
setattr(targetObject, "attrDict", [])
targetObject.attrDict = {"caption": caption, "label": label, "icon": icon, "accel": accel, "initialState": initialState, "id": None}
return targetObject
return CommandDecoratorOuter
# }}}
# {{{ CommandListDecoratorOuter(targetObject)
def CommandListDecorator(idx, caption, label, icon, accel, initialState):
def CommandListDecoratorOuter(targetObject):
if callable(targetObject):
if not hasattr(targetObject, "attrList"):
setattr(targetObject, "attrList", [])
targetObject.attrList.insert(0, {"caption": caption, "label": label, "icon": icon, "accel": accel, "initialState": initialState, "id": None, "idx": idx})
return targetObject
return CommandListDecoratorOuter
# }}}
# {{{ SelectDecoratorOuter(targetObject)
def SelectDecorator(idx, caption, label, icon, accel, initialState):
def SelectDecoratorOuter(targetObject):
if callable(targetObject):
if not hasattr(targetObject, "attrList"):
setattr(targetObject, "attrList", [])
setattr(targetObject, "isSelect", True)
targetObject.attrList.insert(0, {"caption": caption, "label": label, "icon": icon, "accel": accel, "initialState": initialState, "id": None, "idx": idx})
return targetObject
return SelectDecoratorOuter
# }}}
# {{{ canvasAbout(self, event) # {{{ canvasAbout(self, event)
@GuiCanvasCommandDecorator("About", "&About", None, None, True) @CommandDecorator("About", "&About", None, None, True)
def canvasAbout(self, event): def canvasAbout(self, event):
GuiCanvasInterfaceAbout(self.parentFrame) GuiCanvasInterfaceAbout(self.parentFrame)
# }}} # }}}
# {{{ canvasBrush(self, f, idx) # {{{ canvasBrush(self, f, idx)
@GuiCanvasSelectDecorator(0, "Solid brush", "Solid brush", None, None, True) @SelectDecorator(0, "Solid brush", "Solid brush", None, None, True)
def canvasBrush(self, f, idx): def canvasBrush(self, f, idx):
def canvasBrush_(self, event): def canvasBrush_(self, event):
pass pass
@ -129,22 +138,22 @@ class GuiCanvasInterface():
return canvasBrush_ return canvasBrush_
# }}} # }}}
# {{{ canvasColour(self, f, idx) # {{{ canvasColour(self, f, idx)
@GuiCanvasSelectDecorator(0, "Colour #00", "Colour #00 (Bright White)", None, None, False) @SelectDecorator(0, "Colour #00", "Colour #00 (Bright White)", None, None, False)
@GuiCanvasSelectDecorator(1, "Colour #01", "Colour #01 (Black)", None, None, False) @SelectDecorator(1, "Colour #01", "Colour #01 (Black)", None, None, False)
@GuiCanvasSelectDecorator(2, "Colour #02", "Colour #02 (Blue)", None, None, False) @SelectDecorator(2, "Colour #02", "Colour #02 (Blue)", None, None, False)
@GuiCanvasSelectDecorator(3, "Colour #03", "Colour #03 (Green)", None, None, False) @SelectDecorator(3, "Colour #03", "Colour #03 (Green)", None, None, False)
@GuiCanvasSelectDecorator(4, "Colour #04", "Colour #04 (Red)", None, None, False) @SelectDecorator(4, "Colour #04", "Colour #04 (Red)", None, None, False)
@GuiCanvasSelectDecorator(5, "Colour #05", "Colour #05 (Light Red)", None, None, False) @SelectDecorator(5, "Colour #05", "Colour #05 (Light Red)", None, None, False)
@GuiCanvasSelectDecorator(6, "Colour #06", "Colour #06 (Pink)", None, None, False) @SelectDecorator(6, "Colour #06", "Colour #06 (Pink)", None, None, False)
@GuiCanvasSelectDecorator(7, "Colour #07", "Colour #07 (Yellow)", None, None, False) @SelectDecorator(7, "Colour #07", "Colour #07 (Yellow)", None, None, False)
@GuiCanvasSelectDecorator(8, "Colour #08", "Colour #08 (Light Yellow)", None, None, False) @SelectDecorator(8, "Colour #08", "Colour #08 (Light Yellow)", None, None, False)
@GuiCanvasSelectDecorator(9, "Colour #09", "Colour #09 (Light Green)", None, None, False) @SelectDecorator(9, "Colour #09", "Colour #09 (Light Green)", None, None, False)
@GuiCanvasSelectDecorator(10, "Colour #10", "Colour #10 (Cyan)", None, None, False) @SelectDecorator(10, "Colour #10", "Colour #10 (Cyan)", None, None, False)
@GuiCanvasSelectDecorator(11, "Colour #11", "Colour #11 (Light Cyan)", None, None, False) @SelectDecorator(11, "Colour #11", "Colour #11 (Light Cyan)", None, None, False)
@GuiCanvasSelectDecorator(12, "Colour #12", "Colour #12 (Light Blue)", None, None, False) @SelectDecorator(12, "Colour #12", "Colour #12 (Light Blue)", None, None, False)
@GuiCanvasSelectDecorator(13, "Colour #13", "Colour #13 (Light Pink)", None, None, False) @SelectDecorator(13, "Colour #13", "Colour #13 (Light Pink)", None, None, False)
@GuiCanvasSelectDecorator(14, "Colour #14", "Colour #14 (Grey)", None, None, False) @SelectDecorator(14, "Colour #14", "Colour #14 (Grey)", None, None, False)
@GuiCanvasSelectDecorator(15, "Colour #15", "Colour #15 (Light Grey)", None, None, False) @SelectDecorator(15, "Colour #15", "Colour #15 (Light Grey)", None, None, False)
def canvasColour(self, f, idx): def canvasColour(self, f, idx):
def canvasColour_(self, event): def canvasColour_(self, event):
if event.GetEventType() == wx.wxEVT_TOOL: if event.GetEventType() == wx.wxEVT_TOOL:
@ -157,7 +166,7 @@ class GuiCanvasInterface():
return canvasColour_ return canvasColour_
# }}} # }}}
# {{{ canvasColourAlpha(self, f, idx) # {{{ canvasColourAlpha(self, f, idx)
@GuiCanvasSelectDecorator(0, "Transparent colour", "Transparent colour", None, None, False) @SelectDecorator(0, "Transparent colour", "Transparent colour", None, None, False)
def canvasColourAlpha(self, f, idx): def canvasColourAlpha(self, f, idx):
def canvasColourAlpha_(self, event): def canvasColourAlpha_(self, event):
if event.GetEventType() == wx.wxEVT_TOOL: if event.GetEventType() == wx.wxEVT_TOOL:
@ -170,28 +179,28 @@ class GuiCanvasInterface():
return canvasColourAlpha_ return canvasColourAlpha_
# }}} # }}}
# {{{ canvasCopy(self, event) # {{{ canvasCopy(self, event)
@GuiCanvasCommandDecorator("Copy", "&Copy", ["", wx.ART_COPY], None, False) @CommandDecorator("Copy", "&Copy", ["", wx.ART_COPY], None, False)
def canvasCopy(self, event): def canvasCopy(self, event):
pass pass
# }}} # }}}
# {{{ canvasCut(self, event) # {{{ canvasCut(self, event)
@GuiCanvasCommandDecorator("Cut", "Cu&t", ["", wx.ART_CUT], None, False) @CommandDecorator("Cut", "Cu&t", ["", wx.ART_CUT], None, False)
def canvasCut(self, event): def canvasCut(self, event):
pass pass
# }}} # }}}
# {{{ canvasDelete(self, event) # {{{ canvasDelete(self, event)
@GuiCanvasCommandDecorator("Delete", "De&lete", ["", wx.ART_DELETE], None, False) @CommandDecorator("Delete", "De&lete", ["", wx.ART_DELETE], None, False)
def canvasDelete(self, event): def canvasDelete(self, event):
pass pass
# }}} # }}}
# {{{ canvasExit(self, event) # {{{ canvasExit(self, event)
@GuiCanvasCommandDecorator("Exit", "E&xit", None, [wx.ACCEL_CTRL, ord("X")], None) @CommandDecorator("Exit", "E&xit", None, [wx.ACCEL_CTRL, ord("X")], None)
def canvasExit(self, event): def canvasExit(self, event):
if self._promptSaveChanges(): if self._promptSaveChanges():
self.parentFrame.Close(True) self.parentFrame.Close(True)
# }}} # }}}
# {{{ canvasNew(self, event, newCanvasSize=None) # {{{ canvasNew(self, event, newCanvasSize=None)
@GuiCanvasCommandDecorator("New", "&New", ["", wx.ART_NEW], [wx.ACCEL_CTRL, ord("N")], None) @CommandDecorator("New", "&New", ["", wx.ART_NEW], [wx.ACCEL_CTRL, ord("N")], None)
def canvasNew(self, event, newCanvasSize=None): def canvasNew(self, event, newCanvasSize=None):
def canvasImportEmpty(pathName): def canvasImportEmpty(pathName):
nonlocal newCanvasSize nonlocal newCanvasSize
@ -203,7 +212,7 @@ class GuiCanvasInterface():
self._import(canvasImportEmpty, False, None) self._import(canvasImportEmpty, False, None)
# }}} # }}}
# {{{ canvasOpen(self, event) # {{{ canvasOpen(self, event)
@GuiCanvasCommandDecorator("Open", "&Open", ["", wx.ART_FILE_OPEN], [wx.ACCEL_CTRL, ord("O")], None) @CommandDecorator("Open", "&Open", ["", wx.ART_FILE_OPEN], [wx.ACCEL_CTRL, ord("O")], None)
def canvasOpen(self, event): def canvasOpen(self, event):
def canvasImportmIRC(pathName): def canvasImportmIRC(pathName):
rc, error = self.parentCanvas.canvas.importStore.importTextFile(pathName) rc, error = self.parentCanvas.canvas.importStore.importTextFile(pathName)
@ -211,18 +220,18 @@ class GuiCanvasInterface():
self._importFile(canvasImportmIRC, False, "mIRC art files (*.txt)|*.txt|All Files (*.*)|*.*") self._importFile(canvasImportmIRC, False, "mIRC art files (*.txt)|*.txt|All Files (*.*)|*.*")
# }}} # }}}
# {{{ canvasPaste(self, event) # {{{ canvasPaste(self, event)
@GuiCanvasCommandDecorator("Paste", "&Paste", ["", wx.ART_PASTE], None, False) @CommandDecorator("Paste", "&Paste", ["", wx.ART_PASTE], None, False)
def canvasPaste(self, event): def canvasPaste(self, event):
pass pass
# }}} # }}}
# {{{ canvasRedo(self, event) # {{{ canvasRedo(self, event)
@GuiCanvasCommandDecorator("Redo", "&Redo", ["", wx.ART_REDO], [wx.ACCEL_CTRL, ord("Y")], False) @CommandDecorator("Redo", "&Redo", ["", wx.ART_REDO], [wx.ACCEL_CTRL, ord("Y")], False)
def canvasRedo(self, event): def canvasRedo(self, event):
self.parentCanvas.dispatchDeltaPatches(self.parentCanvas.canvas.journal.popRedo()) self.parentCanvas.dispatchDeltaPatches(self.parentCanvas.canvas.journal.popRedo())
self.update(size=self.parentCanvas.canvas.size, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel) self.update(size=self.parentCanvas.canvas.size, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel)
# }}} # }}}
# {{{ canvasSave(self, event) # {{{ canvasSave(self, event)
@GuiCanvasCommandDecorator("Save", "&Save", ["", wx.ART_FILE_SAVE], [wx.ACCEL_CTRL, ord("S")], None) @CommandDecorator("Save", "&Save", ["", wx.ART_FILE_SAVE], [wx.ACCEL_CTRL, ord("S")], None)
def canvasSave(self, event): def canvasSave(self, event):
if self.canvasPathName == None: if self.canvasPathName == None:
if self.canvasSaveAs(event) == False: if self.canvasSaveAs(event) == False:
@ -239,7 +248,7 @@ class GuiCanvasInterface():
return False return False
# }}} # }}}
# {{{ canvasSaveAs(self, event) # {{{ canvasSaveAs(self, event)
@GuiCanvasCommandDecorator("Save As...", "Save &As...", ["", wx.ART_FILE_SAVE_AS], None, None) @CommandDecorator("Save As...", "Save &As...", ["", wx.ART_FILE_SAVE_AS], None, None)
def canvasSaveAs(self, event): def canvasSaveAs(self, event):
with wx.FileDialog(self.parentCanvas, "Save As", os.getcwd(), "", "mIRC art files (*.txt)|*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog: with wx.FileDialog(self.parentCanvas, "Save As", os.getcwd(), "", "mIRC art files (*.txt)|*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
if dialog.ShowModal() == wx.ID_CANCEL: if dialog.ShowModal() == wx.ID_CANCEL:
@ -249,92 +258,67 @@ class GuiCanvasInterface():
return self.canvasSave(event) return self.canvasSave(event)
# }}} # }}}
# {{{ canvasUndo(self, event) # {{{ canvasUndo(self, event)
@GuiCanvasCommandDecorator("Undo", "&Undo", ["", wx.ART_UNDO], [wx.ACCEL_CTRL, ord("Z")], False) @CommandDecorator("Undo", "&Undo", ["", wx.ART_UNDO], [wx.ACCEL_CTRL, ord("Z")], False)
def canvasUndo(self, event): def canvasUndo(self, event):
self.parentCanvas.dispatchDeltaPatches(self.parentCanvas.canvas.journal.popUndo()) self.parentCanvas.dispatchDeltaPatches(self.parentCanvas.canvas.journal.popUndo())
self.update(size=self.parentCanvas.canvas.size, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel) self.update(size=self.parentCanvas.canvas.size, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel)
# }}} # }}}
# {{{ canvasDecrBrushHeight(self, event) # {{{ canvasBrushSize(self, f, dimension, incrFlag)
@GuiCanvasCommandDecorator("Decrease brush height", "Decrease brush height", ["toolDecrBrushH.png"], None, None) @CommandListDecorator(0, "Decrease brush width", "Decrease brush width", ["toolDecrBrushW.png"], None, None)
def canvasDecrBrushHeight(self, event): @CommandListDecorator(1, "Decrease brush height", "Decrease brush height", ["toolDecrBrushH.png"], None, None)
if self.parentCanvas.brushSize[1] > 1: @CommandListDecorator(2, "Decrease brush size", "Decrease brush size", ["toolDecrBrushHW.png"], None, None)
self.parentCanvas.brushSize[1] -= 1 @CommandListDecorator(3, "Increase brush width", "Increase brush width", ["toolIncrBrushW.png"], None, None)
self.update(brushSize=self.parentCanvas.brushSize) @CommandListDecorator(4, "Increase brush height", "Increase brush height", ["toolIncrBrushH.png"], None, None)
@CommandListDecorator(5, "Increase brush size", "Increase brush size", ["toolIncrBrushHW.png"], None, None)
def canvasBrushSize(self, f, dimension, incrFlag):
def canvasBrushSize_(self, event):
if (dimension < 2) and not incrFlag:
if self.parentCanvas.brushSize[dimension] > 1:
self.parentCanvas.brushSize[dimension] -= 1
self.update(brushSize=self.parentCanvas.brushSize)
elif (dimension < 2) and incrFlag:
self.parentCanvas.brushSize[dimension] += 1
self.update(brushSize=self.parentCanvas.brushSize)
elif dimension == 2:
[self.canvasBrushSize(f, dimension_, incrFlag) for dimension_ in [0, 1]]
setattr(canvasBrushSize_, "attrDict", f.attrList[dimension + (0 if not incrFlag else 3)])
return canvasBrushSize_
# }}} # }}}
# {{{ canvasDecrBrushHeightWidth(self, event) # {{{ canvasCanvasSize(self, f, dimension, incrFlag)
@GuiCanvasCommandDecorator("Decrease brush size", "Decrease brush size", ["toolDecrBrushHW.png"], None, None) @CommandListDecorator(0, "Decrease canvas height", "Decrease canvas height", ["toolDecrCanvasH.png"], None, None)
def canvasDecrBrushHeightWidth(self, event): @CommandListDecorator(1, "Decrease canvas width", "Decrease canvas width", ["toolDecrCanvasW.png"], None, None)
self.canvasDecrBrushHeight(event) @CommandListDecorator(2, "Decrease canvas size", "Decrease canvas size", ["toolDecrCanvasHW.png"], None, None)
self.canvasDecrBrushWidth(event) @CommandListDecorator(3, "Increase canvas height", "Increase canvas height", ["toolIncrCanvasH.png"], None, None)
# }}} @CommandListDecorator(4, "Increase canvas width", "Increase canvas width", ["toolIncrCanvasW.png"], None, None)
# {{{ canvasDecrBrushWidth(self, event) @CommandListDecorator(5, "Increase canvas size", "Increase canvas size", ["toolIncrCanvasHW.png"], None, None)
@GuiCanvasCommandDecorator("Decrease brush width", "Decrease brush width", ["toolDecrBrushW.png"], None, None) def canvasCanvasSize(self, f, dimension, incrFlag):
def canvasDecrBrushWidth(self, event): def canvasCanvasSize_(self, event):
if self.parentCanvas.brushSize[0] > 1: if (dimension < 2) and not incrFlag:
self.parentCanvas.brushSize[0] -= 1 if dimension == 0:
self.update(brushSize=self.parentCanvas.brushSize) if self.parentCanvas.canvas.size[1] > 1:
# }}} self.parentCanvas.resize([self.parentCanvas.canvas.size[0], self.parentCanvas.canvas.size[1] - 1])
# {{{ canvasDecrCanvasHeight(self, event) elif dimension == 1:
@GuiCanvasCommandDecorator("Decrease canvas height", "Decrease canvas height", ["toolDecrCanvasH.png"], None, None) if self.parentCanvas.canvas.size[0] > 1:
def canvasDecrCanvasHeight(self, event): self.parentCanvas.resize([self.parentCanvas.canvas.size[0] - 1, self.parentCanvas.canvas.size[1]])
if self.parentCanvas.canvas.size[1] > 1: elif (dimension < 2) and incrFlag:
self.parentCanvas.resize([self.parentCanvas.canvas.size[0], self.parentCanvas.canvas.size[1] - 1]) if dimension == 0:
# }}} self.parentCanvas.resize([self.parentCanvas.canvas.size[0], self.parentCanvas.canvas.size[1] + 1])
# {{{ canvasDecrCanvasHeightWidth(self, event) elif dimension == 1:
@GuiCanvasCommandDecorator("Decrease canvas size", "Decrease canvas size", ["toolDecrCanvasHW.png"], None, None) self.parentCanvas.resize([self.parentCanvas.canvas.size[0] + 1, self.parentCanvas.canvas.size[1]])
def canvasDecrCanvasHeightWidth(self, event): elif dimension == 2:
self.canvasDecrCanvasHeight(event) [self.canvasCanvasSize(f, dimension_, incrFlag) for dimension_ in [0, 1]]
self.canvasDecrCanvasWidth(event) setattr(canvasCanvasSize_, "attrDict", f.attrList[dimension + (0 if not incrFlag else 3)])
# }}} return canvasCanvasSize_
# {{{ canvasDecrCanvasWidth(self, event)
@GuiCanvasCommandDecorator("Decrease canvas width", "Decrease canvas width", ["toolDecrCanvasW.png"], None, None)
def canvasDecrCanvasWidth(self, event):
if self.parentCanvas.canvas.size[0] > 1:
self.parentCanvas.resize([self.parentCanvas.canvas.size[0] - 1, self.parentCanvas.canvas.size[1]])
# }}}
# {{{ canvasIncrBrushHeight(self, event)
@GuiCanvasCommandDecorator("Increase brush height", "Increase brush height", ["toolIncrBrushH.png"], None, None)
def canvasIncrBrushHeight(self, event):
self.parentCanvas.brushSize[1] += 1
self.update(brushSize=self.parentCanvas.brushSize)
# }}}
# {{{ canvasIncrBrushHeightWidth(self, event)
@GuiCanvasCommandDecorator("Increase brush size", "Increase brush size", ["toolIncrBrushHW.png"], None, None)
def canvasIncrBrushHeightWidth(self, event):
self.canvasIncrBrushHeight(event)
self.canvasIncrBrushWidth(event)
# }}}
# {{{ canvasIncrBrushWidth(self, event)
@GuiCanvasCommandDecorator("Increase brush width", "Increase brush width", ["toolIncrBrushW.png"], None, None)
def canvasIncrBrushWidth(self, event):
self.parentCanvas.brushSize[0] += 1
self.update(brushSize=self.parentCanvas.brushSize)
# }}}
# {{{ canvasIncrCanvasHeight(self, event)
@GuiCanvasCommandDecorator("Increase canvas height", "Increase canvas height", ["toolIncrCanvasH.png"], None, None)
def canvasIncrCanvasHeight(self, event):
self.parentCanvas.resize([self.parentCanvas.canvas.size[0], self.parentCanvas.canvas.size[1] + 1])
# }}}
# {{{ canvasIncrCanvasHeightWidth(self, event)
@GuiCanvasCommandDecorator("Increase canvas size", "Increase canvas size", ["toolIncrCanvasHW.png"], None, None)
def canvasIncrCanvasHeightWidth(self, event):
self.canvasIncrCanvasHeight(event)
self.canvasIncrCanvasWidth(event)
# }}}
# {{{ canvasIncrCanvasWidth(self, event)
@GuiCanvasCommandDecorator("Increase canvas width", "Increase canvas width", ["toolIncrCanvasW.png"], None, None)
def canvasIncrCanvasWidth(self, event):
self.parentCanvas.resize([self.parentCanvas.canvas.size[0] + 1, self.parentCanvas.canvas.size[1]])
# }}} # }}}
# {{{ canvasTool(self, f, idx) # {{{ canvasTool(self, f, idx)
@GuiCanvasSelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False) @SelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False)
@GuiCanvasSelectDecorator(1, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False) @SelectDecorator(1, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False)
@GuiCanvasSelectDecorator(2, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False) @SelectDecorator(2, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False)
@GuiCanvasSelectDecorator(3, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False) @SelectDecorator(3, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False)
@GuiCanvasSelectDecorator(4, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False) @SelectDecorator(4, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False)
@GuiCanvasSelectDecorator(5, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True) @SelectDecorator(5, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True)
@GuiCanvasSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) @SelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False)
def canvasTool(self, f, idx): def canvasTool(self, f, idx):
def canvasTool_(self, event): def canvasTool_(self, event):
self.currentTool = [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, ToolRect, ToolText][idx](self.parentCanvas) self.currentTool = [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, ToolRect, ToolText][idx](self.parentCanvas)
@ -348,7 +332,7 @@ class GuiCanvasInterface():
# }}} # }}}
# {{{ canvasExportAsAnsi(self, event) # {{{ canvasExportAsAnsi(self, event)
@GuiCanvasCommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None) @CommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None)
def canvasExportAsAnsi(self, event): def canvasExportAsAnsi(self, event):
with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog: with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
if dialog.ShowModal() == wx.ID_CANCEL: if dialog.ShowModal() == wx.ID_CANCEL:
@ -362,7 +346,7 @@ class GuiCanvasInterface():
return True return True
# }}} # }}}
# {{{ canvasExportAsPng(self, event) # {{{ canvasExportAsPng(self, event)
@GuiCanvasCommandDecorator("Export as PNG...", "Export as PN&G...", None, None, None) @CommandDecorator("Export as PNG...", "Export as PN&G...", None, None, None)
def canvasExportAsPng(self, event): def canvasExportAsPng(self, event):
with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "PNG (*.png)|*.png|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog: with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "PNG (*.png)|*.png|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
if dialog.ShowModal() == wx.ID_CANCEL: if dialog.ShowModal() == wx.ID_CANCEL:
@ -375,7 +359,7 @@ class GuiCanvasInterface():
return True return True
# }}} # }}}
# {{{ canvasExportImgur(self, event) # {{{ canvasExportImgur(self, event)
@GuiCanvasCommandDecorator("Export to Imgur...", "Export to I&mgur...", None, None, haveUrllib) @CommandDecorator("Export to Imgur...", "Export to I&mgur...", None, None, haveUrllib)
def canvasExportImgur(self, event): def canvasExportImgur(self, event):
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
rc, status, result = self.parentCanvas.canvas.exportStore.exportBitmapToImgur(self.imgurApiKey, self.parentCanvas.backend.canvasBitmap, "", "", wx.BITMAP_TYPE_PNG) rc, status, result = self.parentCanvas.canvas.exportStore.exportBitmapToImgur(self.imgurApiKey, self.parentCanvas.backend.canvasBitmap, "", "", wx.BITMAP_TYPE_PNG)
@ -388,7 +372,7 @@ class GuiCanvasInterface():
wx.MessageBox("Failed to export to Imgur: {}".format(result), "Export to Imgur", wx.ICON_EXCLAMATION | wx.OK) wx.MessageBox("Failed to export to Imgur: {}".format(result), "Export to Imgur", wx.ICON_EXCLAMATION | wx.OK)
# }}} # }}}
# {{{ canvasExportPastebin(self, event) # {{{ canvasExportPastebin(self, event)
@GuiCanvasCommandDecorator("Export to Pastebin...", "Export to Pasteb&in...", None, None, haveUrllib) @CommandDecorator("Export to Pastebin...", "Export to Pasteb&in...", None, None, haveUrllib)
def canvasExportPastebin(self, event): def canvasExportPastebin(self, event):
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
pasteStatus, pasteResult = self.parentCanvas.canvas.exportStore.exportPastebin("", self.parentCanvas.canvas.map, self.parentCanvas.canvas.size) pasteStatus, pasteResult = self.parentCanvas.canvas.exportStore.exportPastebin("", self.parentCanvas.canvas.map, self.parentCanvas.canvas.size)
@ -403,7 +387,7 @@ class GuiCanvasInterface():
wx.MessageBox("Failed to export to Pastebin: " + pasteResult, "Export to Pastebin", wx.OK|wx.ICON_EXCLAMATION) wx.MessageBox("Failed to export to Pastebin: " + pasteResult, "Export to Pastebin", wx.OK|wx.ICON_EXCLAMATION)
# }}} # }}}
# {{{ canvasExportToClipboard(self, event) # {{{ canvasExportToClipboard(self, event)
@GuiCanvasCommandDecorator("Export to clipboard", "&Export to clipboard", None, None, None) @CommandDecorator("Export to clipboard", "&Export to clipboard", None, None, None)
def canvasExportToClipboard(self, event): def canvasExportToClipboard(self, event):
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
rc, outBuffer = self.parentCanvas.canvas.exportStore.exportTextBuffer(self.parentCanvas.canvas.map, self.parentCanvas.canvas.size) rc, outBuffer = self.parentCanvas.canvas.exportStore.exportTextBuffer(self.parentCanvas.canvas.map, self.parentCanvas.canvas.size)
@ -414,7 +398,7 @@ class GuiCanvasInterface():
return True return True
# }}} # }}}
# {{{ canvasImportAnsi(self, event) # {{{ canvasImportAnsi(self, event)
@GuiCanvasCommandDecorator("Import ANSI...", "Import ANSI...", None, None, None) @CommandDecorator("Import ANSI...", "Import ANSI...", None, None, None)
def canvasImportAnsi(self, event): def canvasImportAnsi(self, event):
def canvasImportAnsi_(pathName): def canvasImportAnsi_(pathName):
rc, error = self.parentCanvas.canvas.importStore.importAnsiFile(pathName) rc, error = self.parentCanvas.canvas.importStore.importAnsiFile(pathName)
@ -422,7 +406,7 @@ class GuiCanvasInterface():
self._importFile(canvasImportAnsi_, True, "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*") self._importFile(canvasImportAnsi_, True, "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*")
# }}} # }}}
# {{{ canvasImportFromClipboard(self, event) # {{{ canvasImportFromClipboard(self, event)
@GuiCanvasCommandDecorator("Import from clipboard", "&Import from clipboard", None, None, None) @CommandDecorator("Import from clipboard", "&Import from clipboard", None, None, None)
def canvasImportFromClipboard(self, event): def canvasImportFromClipboard(self, event):
def canvasImportFromClipboard_(pathName): def canvasImportFromClipboard_(pathName):
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) \ if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) \
@ -439,7 +423,7 @@ class GuiCanvasInterface():
self._import(canvasImportFromClipboard_, True, None) self._import(canvasImportFromClipboard_, True, None)
# }}} # }}}
# {{{ canvasImportSauce(self, event) # {{{ canvasImportSauce(self, event)
@GuiCanvasCommandDecorator("Import SAUCE...", "Import SAUCE...", None, None, None) @CommandDecorator("Import SAUCE...", "Import SAUCE...", None, None, None)
def canvasImportSauce(self, event): def canvasImportSauce(self, event):
def canvasImportSauce_(pathName): def canvasImportSauce_(pathName):
rc, error = self.parentCanvas.canvas.importStore.importSauceFile(pathName) rc, error = self.parentCanvas.canvas.importStore.importSauceFile(pathName)
@ -511,10 +495,10 @@ class GuiCanvasInterface():
canvasUndo, canvasRedo, NID_MENU_SEP, canvasUndo, canvasRedo, NID_MENU_SEP,
canvasCut, canvasCopy, canvasPaste, canvasCut, canvasCopy, canvasPaste,
canvasDelete, NID_MENU_SEP, canvasDelete, NID_MENU_SEP,
canvasIncrCanvasWidth, canvasDecrCanvasWidth, canvasIncrCanvasHeight, canvasDecrCanvasHeight, NID_MENU_SEP, canvasCanvasSize(None, canvasCanvasSize, 1, True), canvasCanvasSize(None, canvasCanvasSize, 1, False), canvasCanvasSize(None, canvasCanvasSize, 0, True), canvasCanvasSize(None, canvasCanvasSize, 0, False), NID_MENU_SEP,
canvasIncrCanvasHeightWidth, canvasDecrBrushHeightWidth, NID_MENU_SEP, canvasCanvasSize(None, canvasCanvasSize, 2, True), canvasCanvasSize(None, canvasCanvasSize, 2, False), NID_MENU_SEP,
canvasIncrBrushWidth, canvasDecrBrushWidth, canvasIncrBrushHeight, canvasDecrBrushHeight, NID_MENU_SEP, canvasBrushSize(None, canvasBrushSize, 0, True), canvasBrushSize(None, canvasBrushSize, 0, False), canvasBrushSize(None, canvasBrushSize, 1, True), canvasBrushSize(None, canvasBrushSize, 1, False), NID_MENU_SEP,
canvasIncrBrushHeightWidth, canvasDecrBrushHeightWidth, NID_MENU_SEP, canvasBrushSize(None, canvasBrushSize, 2, True), canvasBrushSize(None, canvasBrushSize, 2, False), NID_MENU_SEP,
canvasBrush(None, canvasBrush, 0), canvasBrush(None, canvasBrush, 0),
), ),
("&Tools", ("&Tools",
@ -528,8 +512,8 @@ class GuiCanvasInterface():
(canvasNew, canvasOpen, canvasSave, canvasSaveAs, NID_TOOLBAR_HSEP, (canvasNew, canvasOpen, canvasSave, canvasSaveAs, NID_TOOLBAR_HSEP,
canvasUndo, canvasRedo, NID_TOOLBAR_HSEP, canvasUndo, canvasRedo, NID_TOOLBAR_HSEP,
canvasCut, canvasCopy, canvasPaste, canvasDelete, NID_TOOLBAR_HSEP, canvasCut, canvasCopy, canvasPaste, canvasDelete, NID_TOOLBAR_HSEP,
canvasIncrCanvasWidth, canvasDecrCanvasWidth, canvasIncrCanvasHeight, canvasDecrCanvasHeight, NID_TOOLBAR_HSEP, canvasCanvasSize(None, canvasCanvasSize, 1, True), canvasCanvasSize(None, canvasCanvasSize, 1, False), canvasCanvasSize(None, canvasCanvasSize, 0, True), canvasCanvasSize(None, canvasCanvasSize, 0, False), NID_TOOLBAR_HSEP,
canvasIncrCanvasHeightWidth, canvasDecrCanvasHeightWidth, NID_TOOLBAR_HSEP, canvasCanvasSize(None, canvasCanvasSize, 2, True), canvasCanvasSize(None, canvasCanvasSize, 2, False), NID_TOOLBAR_HSEP,
canvasTool(None, canvasTool, 5), canvasTool(None, canvasTool, 0), canvasTool(None, canvasTool, 2), canvasTool(None, canvasTool, 3), canvasTool(None, canvasTool, 6), canvasTool(None, canvasTool, 1), canvasTool(None, canvasTool, 4), canvasTool(None, canvasTool, 5), canvasTool(None, canvasTool, 0), canvasTool(None, canvasTool, 2), canvasTool(None, canvasTool, 3), canvasTool(None, canvasTool, 6), canvasTool(None, canvasTool, 1), canvasTool(None, canvasTool, 4),
), ),
(canvasColour(None, canvasColour, 0), canvasColour(None, canvasColour, 1), canvasColour(None, canvasColour, 2), canvasColour(None, canvasColour, 3), (canvasColour(None, canvasColour, 0), canvasColour(None, canvasColour, 1), canvasColour(None, canvasColour, 2), canvasColour(None, canvasColour, 3),
@ -537,8 +521,8 @@ class GuiCanvasInterface():
canvasColour(None, canvasColour, 8), canvasColour(None, canvasColour, 9), canvasColour(None, canvasColour, 10), canvasColour(None, canvasColour, 11), canvasColour(None, canvasColour, 8), canvasColour(None, canvasColour, 9), canvasColour(None, canvasColour, 10), canvasColour(None, canvasColour, 11),
canvasColour(None, canvasColour, 12), canvasColour(None, canvasColour, 13), canvasColour(None, canvasColour, 14), canvasColour(None, canvasColour, 15), canvasColour(None, canvasColour, 12), canvasColour(None, canvasColour, 13), canvasColour(None, canvasColour, 14), canvasColour(None, canvasColour, 15),
canvasColourAlpha(None, canvasColourAlpha, 0), NID_TOOLBAR_HSEP, canvasColourAlpha(None, canvasColourAlpha, 0), NID_TOOLBAR_HSEP,
canvasIncrBrushWidth, canvasDecrBrushWidth, canvasIncrBrushHeight, canvasDecrBrushHeight, NID_TOOLBAR_HSEP, canvasBrushSize(None, canvasBrushSize, 1, True), canvasBrushSize(None, canvasBrushSize, 0, False), canvasBrushSize(None, canvasBrushSize, 1, True), canvasBrushSize(None, canvasBrushSize, 1, False), NID_TOOLBAR_HSEP,
canvasIncrBrushHeightWidth, canvasDecrBrushHeightWidth, canvasBrushSize(None, canvasBrushSize, 2, True), canvasBrushSize(None, canvasBrushSize, 2, False),
), ),
) )
# }}} # }}}