2018-01-07 01:08:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# MiRCARTFrame.py -- XXX
|
|
|
|
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
#
|
|
|
|
|
2018-01-07 15:43:41 +00:00
|
|
|
from MiRCARTCanvas import MiRCARTCanvas, haveUrllib
|
2018-01-07 01:08:35 +00:00
|
|
|
from MiRCARTColours import MiRCARTColours
|
2018-01-07 15:43:41 +00:00
|
|
|
from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \
|
2018-01-08 00:43:54 +00:00
|
|
|
TID_ACCELS, TID_COMMAND, TID_LIST, TID_MENU, TID_NOTHING, TID_SELECT, TID_TOOLBAR
|
2018-01-08 15:12:11 +00:00
|
|
|
from MiRCARTToolCircle import MiRCARTToolCircle
|
|
|
|
from MiRCARTToolLine import MiRCARTToolLine
|
|
|
|
from MiRCARTToolRect import MiRCARTToolRect
|
2018-01-08 19:28:43 +00:00
|
|
|
from MiRCARTToolText import MiRCARTToolText
|
2018-01-07 15:43:41 +00:00
|
|
|
|
2018-01-07 01:08:35 +00:00
|
|
|
import os, wx
|
|
|
|
|
2018-01-07 15:43:41 +00:00
|
|
|
class MiRCARTFrame(MiRCARTGeneralFrame):
|
2018-01-07 01:08:35 +00:00
|
|
|
"""XXX"""
|
2018-01-07 15:43:41 +00:00
|
|
|
panelCanvas = canvasPathName = None
|
2018-01-07 01:08:35 +00:00
|
|
|
|
|
|
|
# {{{ Commands
|
2018-01-08 19:28:43 +00:00
|
|
|
# Id Type Id Labels Icon bitmap Accelerator [Initial state]
|
|
|
|
CID_NEW = [0x100, TID_COMMAND, "New", "&New", ["", wx.ART_NEW], [wx.ACCEL_CTRL, ord("N")]]
|
|
|
|
CID_OPEN = [0x101, TID_COMMAND, "Open", "&Open", ["", wx.ART_FILE_OPEN], [wx.ACCEL_CTRL, ord("O")]]
|
|
|
|
CID_SAVE = [0x102, TID_COMMAND, "Save", "&Save", ["", wx.ART_FILE_SAVE], [wx.ACCEL_CTRL, ord("S")]]
|
|
|
|
CID_SAVEAS = [0x103, TID_COMMAND, "Save As...", "Save &As...", ["", wx.ART_FILE_SAVE_AS], None]
|
|
|
|
CID_EXPORT_AS_PNG = [0x104, TID_COMMAND, "Export as PNG...", \
|
|
|
|
"Export as PN&G...", None, None]
|
|
|
|
CID_EXPORT_IMGUR = [0x105, TID_COMMAND, "Export to Imgur...", \
|
|
|
|
"Export to I&mgur...", None, None, haveUrllib]
|
|
|
|
CID_EXPORT_PASTEBIN = [0x106, TID_COMMAND, "Export to Pastebin...", \
|
|
|
|
"Export to Pasteb&in...", None, None, haveUrllib]
|
|
|
|
CID_EXIT = [0x107, TID_COMMAND, "Exit", "E&xit", None, None]
|
|
|
|
CID_UNDO = [0x108, TID_COMMAND, "Undo", "&Undo", ["", wx.ART_UNDO], [wx.ACCEL_CTRL, ord("Z")], False]
|
|
|
|
CID_REDO = [0x109, TID_COMMAND, "Redo", "&Redo", ["", wx.ART_REDO], [wx.ACCEL_CTRL, ord("Y")], False]
|
|
|
|
CID_CUT = [0x10a, TID_COMMAND, "Cut", "Cu&t", ["", wx.ART_CUT], None, False]
|
|
|
|
CID_COPY = [0x10b, TID_COMMAND, "Copy", "&Copy", ["", wx.ART_COPY], None, False]
|
|
|
|
CID_PASTE = [0x10c, TID_COMMAND, "Paste", "&Paste", ["", wx.ART_PASTE], None, False]
|
|
|
|
CID_DELETE = [0x10d, TID_COMMAND, "Delete", "De&lete", ["", wx.ART_DELETE], None, False]
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_INCR_CANVAS = [0x10e, TID_COMMAND, "Increase canvas size", \
|
2018-01-09 03:02:17 +00:00
|
|
|
"I&ncrease canvas size", ["", wx.ART_PLUS], [wx.ACCEL_ALT, ord("+")]]
|
|
|
|
CID_DECR_CANVAS = [0x10f, TID_COMMAND, "Decrease canvas size", \
|
|
|
|
"D&ecrease canvas size", ["", wx.ART_MINUS], [wx.ACCEL_ALT, ord("-")]]
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_INCR_BRUSH = [0x110, TID_COMMAND, "Increase brush size", \
|
2018-01-08 19:28:43 +00:00
|
|
|
"&Increase brush size", ["", wx.ART_PLUS], [wx.ACCEL_CTRL, ord("+")]]
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_DECR_BRUSH = [0x111, TID_COMMAND, "Decrease brush size", \
|
2018-01-08 19:28:43 +00:00
|
|
|
"&Decrease brush size", ["", wx.ART_MINUS], [wx.ACCEL_CTRL, ord("-")]]
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_SOLID_BRUSH = [0x112, TID_SELECT, "Solid brush", "&Solid brush", None, None, True]
|
2018-01-08 19:28:43 +00:00
|
|
|
|
|
|
|
CID_RECT = [0x150, TID_SELECT, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True]
|
|
|
|
CID_CIRCLE = [0x151, TID_SELECT, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False]
|
|
|
|
CID_LINE = [0x152, TID_SELECT, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False]
|
|
|
|
CID_TEXT = [0x153, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False]
|
|
|
|
|
|
|
|
CID_COLOUR00 = [0x1a0, TID_COMMAND, "Colour #00", "Colour #00", None, None]
|
|
|
|
CID_COLOUR01 = [0x1a1, TID_COMMAND, "Colour #01", "Colour #01", None, None]
|
|
|
|
CID_COLOUR02 = [0x1a2, TID_COMMAND, "Colour #02", "Colour #02", None, None]
|
|
|
|
CID_COLOUR03 = [0x1a3, TID_COMMAND, "Colour #03", "Colour #03", None, None]
|
|
|
|
CID_COLOUR04 = [0x1a4, TID_COMMAND, "Colour #04", "Colour #04", None, None]
|
|
|
|
CID_COLOUR05 = [0x1a5, TID_COMMAND, "Colour #05", "Colour #05", None, None]
|
|
|
|
CID_COLOUR06 = [0x1a6, TID_COMMAND, "Colour #06", "Colour #06", None, None]
|
|
|
|
CID_COLOUR07 = [0x1a7, TID_COMMAND, "Colour #07", "Colour #07", None, None]
|
|
|
|
CID_COLOUR08 = [0x1a8, TID_COMMAND, "Colour #08", "Colour #08", None, None]
|
|
|
|
CID_COLOUR09 = [0x1a9, TID_COMMAND, "Colour #09", "Colour #09", None, None]
|
|
|
|
CID_COLOUR10 = [0x1aa, TID_COMMAND, "Colour #10", "Colour #10", None, None]
|
|
|
|
CID_COLOUR11 = [0x1ab, TID_COMMAND, "Colour #11", "Colour #11", None, None]
|
|
|
|
CID_COLOUR12 = [0x1ac, TID_COMMAND, "Colour #12", "Colour #12", None, None]
|
|
|
|
CID_COLOUR13 = [0x1ad, TID_COMMAND, "Colour #13", "Colour #13", None, None]
|
|
|
|
CID_COLOUR14 = [0x1ae, TID_COMMAND, "Colour #14", "Colour #14", None, None]
|
|
|
|
CID_COLOUR15 = [0x1af, TID_COMMAND, "Colour #15", "Colour #15", None, None]
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ Non-items
|
|
|
|
NID_MENU_SEP = (0x200, TID_NOTHING)
|
|
|
|
NID_TOOLBAR_SEP = (0x201, TID_NOTHING)
|
|
|
|
# }}}
|
|
|
|
# {{{ Menus
|
|
|
|
MID_FILE = (0x300, TID_MENU, "File", "&File", ( \
|
|
|
|
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_MENU_SEP, \
|
2018-01-07 22:49:57 +00:00
|
|
|
CID_EXPORT_AS_PNG, CID_EXPORT_IMGUR, CID_EXPORT_PASTEBIN, NID_MENU_SEP, \
|
2018-01-07 01:08:35 +00:00
|
|
|
CID_EXIT))
|
|
|
|
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, \
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_INCR_CANVAS, CID_DECR_CANVAS, NID_MENU_SEP, \
|
|
|
|
CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH))
|
2018-01-07 01:08:35 +00:00
|
|
|
MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \
|
2018-01-08 19:28:43 +00:00
|
|
|
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT))
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ Toolbars
|
|
|
|
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
|
|
|
|
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_SEP, \
|
|
|
|
CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \
|
|
|
|
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \
|
2018-01-08 19:28:43 +00:00
|
|
|
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, NID_TOOLBAR_SEP, \
|
2018-01-07 01:08:35 +00:00
|
|
|
CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \
|
|
|
|
CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \
|
|
|
|
CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \
|
|
|
|
CID_COLOUR15))
|
|
|
|
# }}}
|
|
|
|
# {{{ Accelerators (hotkeys)
|
2018-01-07 15:43:41 +00:00
|
|
|
AID_EDIT = (0x500, TID_ACCELS, ( \
|
2018-01-08 23:21:43 +00:00
|
|
|
CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO, \
|
2018-01-09 03:02:17 +00:00
|
|
|
CID_INCR_CANVAS, CID_DECR_CANVAS, CID_INCR_BRUSH, CID_DECR_BRUSH))
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
2018-01-08 00:43:54 +00:00
|
|
|
# {{{ Lists
|
|
|
|
LID_ACCELS = (0x600, TID_LIST, (AID_EDIT))
|
|
|
|
LID_MENUS = (0x601, TID_LIST, (MID_FILE, MID_EDIT, MID_TOOLS))
|
|
|
|
LID_TOOLBARS = (0x602, TID_LIST, (BID_TOOLBAR))
|
|
|
|
# }}}
|
2018-01-07 01:08:35 +00:00
|
|
|
|
2018-01-08 19:28:43 +00:00
|
|
|
# {{{ _initPaletteToolBitmaps(self): XXX
|
|
|
|
def _initPaletteToolBitmaps(self):
|
2018-01-07 15:43:41 +00:00
|
|
|
paletteDescr = ( \
|
|
|
|
self.CID_COLOUR00, self.CID_COLOUR01, self.CID_COLOUR02, self.CID_COLOUR03, self.CID_COLOUR04, \
|
|
|
|
self.CID_COLOUR05, self.CID_COLOUR06, self.CID_COLOUR07, self.CID_COLOUR08, self.CID_COLOUR09, \
|
|
|
|
self.CID_COLOUR10, self.CID_COLOUR11, self.CID_COLOUR12, self.CID_COLOUR13, self.CID_COLOUR14, \
|
|
|
|
self.CID_COLOUR15)
|
|
|
|
for numColour in range(len(paletteDescr)):
|
|
|
|
toolBitmapColour = MiRCARTColours[numColour][0:4]
|
|
|
|
toolBitmap = wx.Bitmap((16,16))
|
|
|
|
toolBitmapDc = wx.MemoryDC(); toolBitmapDc.SelectObject(toolBitmap);
|
|
|
|
toolBitmapBrush = wx.Brush( \
|
|
|
|
wx.Colour(toolBitmapColour), wx.BRUSHSTYLE_SOLID)
|
|
|
|
toolBitmapDc.SetBrush(toolBitmapBrush)
|
|
|
|
toolBitmapDc.SetBackground(toolBitmapBrush)
|
|
|
|
toolBitmapDc.SetPen(wx.Pen(wx.Colour(toolBitmapColour), 1))
|
|
|
|
toolBitmapDc.DrawRectangle(0, 0, 16, 16)
|
2018-01-08 19:28:43 +00:00
|
|
|
paletteDescr[numColour][4] = ["", None, toolBitmap]
|
|
|
|
# }}}
|
|
|
|
# {{{ _dialogSaveChanges(self)
|
|
|
|
def _dialogSaveChanges(self):
|
|
|
|
with wx.MessageDialog(self, \
|
|
|
|
"Do you want to save changes to {}?".format( \
|
|
|
|
self.canvasPathName), "MiRCART", \
|
|
|
|
wx.CANCEL|wx.CANCEL_DEFAULT|wx.ICON_QUESTION|wx.YES_NO) as dialog:
|
|
|
|
dialogChoice = dialog.ShowModal()
|
|
|
|
return dialogChoice
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
2018-01-07 15:43:41 +00:00
|
|
|
# {{{ _updateStatusBar(self, showColours=None, showFileName=True, showPos=None): XXX
|
|
|
|
def _updateStatusBar(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.canvasPathName
|
|
|
|
textItems = []
|
|
|
|
if showPos != None:
|
|
|
|
textItems.append("X: {:03d} Y: {:03d}".format( \
|
|
|
|
showPos[0], showPos[1]))
|
|
|
|
if showColours != None:
|
|
|
|
textItems.append("FG: {:02d}, BG: {:02d}".format( \
|
|
|
|
showColours[0],showColours[1]))
|
|
|
|
textItems.append("{} on {}".format( \
|
|
|
|
MiRCARTColours[showColours[0]][4], \
|
|
|
|
MiRCARTColours[showColours[1]][4]))
|
|
|
|
if showFileName != None:
|
|
|
|
textItems.append("Current file: {}".format( \
|
|
|
|
os.path.basename(showFileName)))
|
|
|
|
self.statusBar.SetStatusText(" | ".join(textItems))
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
|
|
|
|
# {{{ canvasExportAsPng(self): XXX
|
|
|
|
def canvasExportAsPng(self):
|
2018-01-08 23:21:43 +00:00
|
|
|
with wx.FileDialog(self, self.CID_SAVEAS[2], os.getcwd(), "", \
|
2018-01-07 01:08:35 +00:00
|
|
|
"*.png", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
|
|
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
|
|
|
return False
|
|
|
|
else:
|
2018-01-07 15:43:41 +00:00
|
|
|
outPathName = dialog.GetPath()
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-09 23:48:13 +00:00
|
|
|
self.panelCanvas.canvasExportStore.exportBitmapToPngFile( \
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.canvasBackend.canvasBitmap, outPathName, \
|
2018-01-07 15:43:41 +00:00
|
|
|
wx.BITMAP_TYPE_PNG)
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 15:43:41 +00:00
|
|
|
return True
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
2018-01-07 22:49:57 +00:00
|
|
|
# {{{ canvasExportImgur(self): XXX
|
|
|
|
def canvasExportImgur(self):
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-09 23:48:13 +00:00
|
|
|
imgurResult = self.panelCanvas.canvasExportStore.exportBitmapToImgur( \
|
|
|
|
"c9a6efb3d7932fd", self.panelCanvas.canvasBackend.canvasBitmap, \
|
2018-01-08 23:21:43 +00:00
|
|
|
"", "", wx.BITMAP_TYPE_PNG)
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 22:49:57 +00:00
|
|
|
if imgurResult[0] == 200:
|
|
|
|
if not wx.TheClipboard.IsOpened():
|
|
|
|
wx.TheClipboard.Open()
|
|
|
|
wx.TheClipboard.SetData(wx.TextDataObject(imgurResult[1]))
|
|
|
|
wx.TheClipboard.Close()
|
|
|
|
wx.MessageBox("Exported to Imgur: " + imgurResult[1], \
|
|
|
|
"Export to Imgur", wx.OK|wx.ICON_INFORMATION)
|
|
|
|
else:
|
|
|
|
wx.MessageBox("Failed to export to Imgur: " + imgurResult[1], \
|
|
|
|
"Export to Imgur", wx.OK|wx.ICON_EXCLAMATION)
|
|
|
|
# }}}
|
2018-01-07 01:08:35 +00:00
|
|
|
# {{{ canvasExportPastebin(self): XXX
|
|
|
|
def canvasExportPastebin(self):
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-07 15:43:41 +00:00
|
|
|
pasteStatus, pasteResult = \
|
2018-01-09 23:48:13 +00:00
|
|
|
self.panelCanvas.canvasExportStore.exportPastebin( \
|
2018-01-07 15:43:41 +00:00
|
|
|
"253ce2f0a45140ee0a44ca99aa49260", \
|
|
|
|
self.panelCanvas.canvasMap, \
|
|
|
|
self.panelCanvas.canvasSize)
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 15:43:41 +00:00
|
|
|
if pasteStatus:
|
|
|
|
if not wx.TheClipboard.IsOpened():
|
|
|
|
wx.TheClipboard.Open()
|
|
|
|
wx.TheClipboard.SetData(wx.TextDataObject(pasteResult))
|
|
|
|
wx.TheClipboard.Close()
|
|
|
|
wx.MessageBox("Exported to Pastebin: " + pasteResult, \
|
|
|
|
"Export to Pastebin", wx.OK|wx.ICON_INFORMATION)
|
|
|
|
else:
|
|
|
|
wx.MessageBox("Failed to export to Pastebin: " + pasteResult, \
|
|
|
|
"Export to Pastebin", wx.OK|wx.ICON_EXCLAMATION)
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
2018-01-07 03:19:38 +00:00
|
|
|
# {{{ canvasNew(self, newCanvasSize=None): XXX
|
|
|
|
def canvasNew(self, newCanvasSize=None):
|
2018-01-07 15:43:41 +00:00
|
|
|
if self.canvasPathName != None:
|
|
|
|
saveChanges = self._dialogSaveChanges()
|
|
|
|
if saveChanges == wx.ID_CANCEL:
|
|
|
|
return
|
|
|
|
elif saveChanges == wx.ID_NO:
|
|
|
|
pass
|
|
|
|
elif saveChanges == wx.ID_YES:
|
|
|
|
self.canvasSave()
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-07 03:19:38 +00:00
|
|
|
if newCanvasSize == None:
|
|
|
|
newCanvasSize = (100, 30)
|
2018-01-09 23:48:13 +00:00
|
|
|
self.panelCanvas.canvasImportStore.importNew(newCanvasSize)
|
2018-01-07 15:43:41 +00:00
|
|
|
self.canvasPathName = None
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 01:08:35 +00:00
|
|
|
self._updateStatusBar(); self.onCanvasUpdate();
|
|
|
|
# }}}
|
|
|
|
# {{{ canvasOpen(self): XXX
|
|
|
|
def canvasOpen(self):
|
2018-01-07 15:43:41 +00:00
|
|
|
if self.canvasPathName != None:
|
|
|
|
saveChanges = self._dialogSaveChanges()
|
|
|
|
if saveChanges == wx.ID_CANCEL:
|
|
|
|
return
|
|
|
|
elif saveChanges == wx.ID_NO:
|
|
|
|
pass
|
|
|
|
elif saveChanges == wx.ID_YES:
|
|
|
|
self.canvasSave()
|
|
|
|
with wx.FileDialog(self, self.CID_OPEN[2], os.getcwd(), "", \
|
2018-01-07 01:08:35 +00:00
|
|
|
"*.txt", wx.FD_OPEN) as dialog:
|
|
|
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.canvasPathName = dialog.GetPath()
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-09 23:48:13 +00:00
|
|
|
self.panelCanvas.canvasImportStore.importTextFile(self.canvasPathName)
|
|
|
|
self.panelCanvas.canvasImportStore.importIntoPanel()
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 03:19:38 +00:00
|
|
|
self._updateStatusBar(); self.onCanvasUpdate();
|
|
|
|
return True
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ canvasSave(self): XXX
|
|
|
|
def canvasSave(self):
|
|
|
|
if self.canvasPathName == None:
|
|
|
|
if self.canvasSaveAs() == False:
|
|
|
|
return
|
|
|
|
try:
|
2018-01-07 15:43:41 +00:00
|
|
|
with open(self.canvasPathName, "w") as outFile:
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
2018-01-09 23:48:13 +00:00
|
|
|
self.panelCanvas.canvasExportStore.exportTextFile( \
|
2018-01-07 15:43:41 +00:00
|
|
|
self.panelCanvas.canvasMap, \
|
|
|
|
self.panelCanvas.canvasSize, outFile)
|
2018-01-07 22:55:26 +00:00
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
2018-01-07 15:43:41 +00:00
|
|
|
return True
|
2018-01-07 01:08:35 +00:00
|
|
|
except IOError as error:
|
2018-01-07 15:43:41 +00:00
|
|
|
return False
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ canvasSaveAs(self): XXX
|
|
|
|
def canvasSaveAs(self):
|
|
|
|
with wx.FileDialog(self, self.CID_SAVEAS[2], os.getcwd(), "", \
|
|
|
|
"*.txt", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
|
|
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.canvasPathName = dialog.GetPath()
|
2018-01-07 15:43:41 +00:00
|
|
|
return self.canvasSave()
|
|
|
|
# }}}
|
|
|
|
# {{{ onCanvasMotion(self, event): XXX
|
2018-01-08 23:21:43 +00:00
|
|
|
def onCanvasMotion(self, event, atPoint=None):
|
2018-01-07 15:43:41 +00:00
|
|
|
eventType = event.GetEventType()
|
|
|
|
if eventType == wx.wxEVT_ENTER_WINDOW:
|
2018-01-08 23:21:43 +00:00
|
|
|
self.SetFocus()
|
2018-01-07 15:43:41 +00:00
|
|
|
elif eventType == wx.wxEVT_MOTION:
|
2018-01-08 23:21:43 +00:00
|
|
|
self._updateStatusBar(showPos=atPoint)
|
2018-01-07 15:43:41 +00:00
|
|
|
elif eventType == wx.wxEVT_LEAVE_WINDOW:
|
|
|
|
pass
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ onCanvasUpdate(self): XXX
|
|
|
|
def onCanvasUpdate(self):
|
|
|
|
if self.panelCanvas.canvasJournal.patchesUndo[self.panelCanvas.canvasJournal.patchesUndoLevel] != None:
|
|
|
|
self.menuItemsById[self.CID_UNDO[0]].Enable(True)
|
2018-01-07 15:43:41 +00:00
|
|
|
self.toolBar.EnableTool(self.CID_UNDO[0], True)
|
2018-01-07 01:08:35 +00:00
|
|
|
else:
|
|
|
|
self.menuItemsById[self.CID_UNDO[0]].Enable(False)
|
2018-01-07 15:43:41 +00:00
|
|
|
self.toolBar.EnableTool(self.CID_UNDO[0], False)
|
2018-01-07 01:08:35 +00:00
|
|
|
if self.panelCanvas.canvasJournal.patchesUndoLevel > 0:
|
|
|
|
self.menuItemsById[self.CID_REDO[0]].Enable(True)
|
2018-01-07 15:43:41 +00:00
|
|
|
self.toolBar.EnableTool(self.CID_REDO[0], True)
|
2018-01-07 01:08:35 +00:00
|
|
|
else:
|
|
|
|
self.menuItemsById[self.CID_REDO[0]].Enable(False)
|
2018-01-07 15:43:41 +00:00
|
|
|
self.toolBar.EnableTool(self.CID_REDO[0], False)
|
2018-01-07 01:08:35 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ onFrameCommand(self, event): XXX
|
|
|
|
def onFrameCommand(self, event):
|
|
|
|
cid = event.GetId()
|
|
|
|
if cid == self.CID_NEW[0]:
|
|
|
|
self.canvasNew()
|
|
|
|
elif cid == self.CID_OPEN[0]:
|
|
|
|
self.canvasOpen()
|
|
|
|
elif cid == self.CID_SAVE[0]:
|
|
|
|
self.canvasSave()
|
|
|
|
elif cid == self.CID_SAVEAS[0]:
|
|
|
|
self.canvasSaveAs()
|
|
|
|
elif cid == self.CID_EXPORT_AS_PNG[0]:
|
|
|
|
self.canvasExportAsPng()
|
2018-01-07 22:49:57 +00:00
|
|
|
elif cid == self.CID_EXPORT_IMGUR[0]:
|
|
|
|
self.canvasExportImgur()
|
2018-01-07 01:08:35 +00:00
|
|
|
elif cid == self.CID_EXPORT_PASTEBIN[0]:
|
|
|
|
self.canvasExportPastebin()
|
|
|
|
elif cid == self.CID_EXIT[0]:
|
|
|
|
self.Close(True)
|
|
|
|
elif cid == self.CID_UNDO[0]:
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.popUndo()
|
2018-01-07 01:08:35 +00:00
|
|
|
elif cid == self.CID_REDO[0]:
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.popRedo()
|
2018-01-07 01:08:35 +00:00
|
|
|
elif cid == self.CID_CUT[0]:
|
|
|
|
pass
|
|
|
|
elif cid == self.CID_COPY[0]:
|
|
|
|
pass
|
|
|
|
elif cid == self.CID_PASTE[0]:
|
|
|
|
pass
|
|
|
|
elif cid == self.CID_DELETE[0]:
|
|
|
|
pass
|
2018-01-08 23:21:43 +00:00
|
|
|
elif cid == self.CID_INCR_CANVAS[0] \
|
|
|
|
or cid == self.CID_DECR_CANVAS[0]:
|
2018-01-09 21:23:27 +00:00
|
|
|
eventDc = self.panelCanvas.canvasBackend.getDeviceContext(self)
|
2018-01-08 23:21:43 +00:00
|
|
|
if cid == self.CID_INCR_CANVAS[0]:
|
|
|
|
newCanvasSize = [a+1 for a in self.panelCanvas.canvasSize]
|
|
|
|
else:
|
|
|
|
newCanvasSize = [a-1 if a > 1 else a for a in self.panelCanvas.canvasSize]
|
|
|
|
self.panelCanvas.resize(newCanvasSize)
|
|
|
|
self.panelCanvas.canvasBackend.resize( \
|
|
|
|
newCanvasSize, \
|
|
|
|
self.panelCanvas.canvasBackend.cellSize)
|
|
|
|
for numRow in range(self.panelCanvas.canvasSize[1] - 1):
|
|
|
|
self.panelCanvas.canvasMap.append([[1, 1], 0, " "])
|
|
|
|
self.panelCanvas.canvasMap.append([])
|
|
|
|
for numCol in range(self.panelCanvas.canvasSize[0]):
|
|
|
|
self.panelCanvas.canvasMap[-1].append([[1, 1], 0, " "])
|
|
|
|
self.panelCanvas.canvasBackend.drawPatch(eventDc, \
|
2018-01-09 21:23:27 +00:00
|
|
|
([numCol, self.panelCanvas.canvasSize[1] - 1], *[[1, 1], 0, " "]))
|
2018-01-08 23:21:43 +00:00
|
|
|
wx.SafeYield()
|
|
|
|
elif cid == self.CID_INCR_BRUSH[0]:
|
|
|
|
self.panelCanvas.brushSize = \
|
2018-01-07 23:25:59 +00:00
|
|
|
[a+1 for a in self.panelCanvas.brushSize]
|
2018-01-08 23:21:43 +00:00
|
|
|
elif cid == self.CID_DECR_BRUSH[0] \
|
|
|
|
and self.panelCanvas.brushSize[0] > 1 \
|
2018-01-08 00:18:52 +00:00
|
|
|
and self.panelCanvas.brushSize[1] > 1:
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.brushSize = \
|
2018-01-07 23:25:59 +00:00
|
|
|
[a-1 for a in self.panelCanvas.brushSize]
|
2018-01-07 14:20:27 +00:00
|
|
|
elif cid == self.CID_SOLID_BRUSH[0]:
|
2018-01-07 01:08:35 +00:00
|
|
|
pass
|
|
|
|
elif cid == self.CID_RECT[0]:
|
2018-01-08 15:12:11 +00:00
|
|
|
self.menuItemsById[cid].Check(True)
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.canvasCurTool = \
|
2018-01-08 15:12:11 +00:00
|
|
|
MiRCARTToolRect(self.panelCanvas)
|
2018-01-07 01:08:35 +00:00
|
|
|
elif cid == self.CID_CIRCLE[0]:
|
2018-01-08 15:12:11 +00:00
|
|
|
self.menuItemsById[cid].Check(True)
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.canvasCurTool = \
|
2018-01-08 15:12:11 +00:00
|
|
|
MiRCARTToolCircle(self.panelCanvas)
|
2018-01-07 01:08:35 +00:00
|
|
|
elif cid == self.CID_LINE[0]:
|
2018-01-08 15:12:11 +00:00
|
|
|
self.menuItemsById[cid].Check(True)
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.canvasCurTool = \
|
2018-01-08 15:12:11 +00:00
|
|
|
MiRCARTToolLine(self.panelCanvas)
|
2018-01-08 19:28:43 +00:00
|
|
|
elif cid == self.CID_TEXT[0]:
|
|
|
|
self.menuItemsById[cid].Check(True)
|
2018-01-08 23:21:43 +00:00
|
|
|
self.panelCanvas.canvasCurTool = \
|
2018-01-08 19:28:43 +00:00
|
|
|
MiRCARTToolText(self.panelCanvas)
|
2018-01-08 23:21:43 +00:00
|
|
|
elif cid >= self.CID_COLOUR00[0] \
|
2018-01-07 01:08:35 +00:00
|
|
|
and cid <= self.CID_COLOUR15[0]:
|
|
|
|
numColour = cid - self.CID_COLOUR00[0]
|
|
|
|
if event.GetEventType() == wx.wxEVT_TOOL:
|
2018-01-07 15:43:41 +00:00
|
|
|
self.panelCanvas.brushColours[0] = numColour
|
2018-01-07 01:08:35 +00:00
|
|
|
elif event.GetEventType() == wx.wxEVT_TOOL_RCLICKED:
|
2018-01-07 15:43:41 +00:00
|
|
|
self.panelCanvas.brushColours[1] = numColour
|
2018-01-07 01:08:35 +00:00
|
|
|
self._updateStatusBar()
|
|
|
|
# }}}
|
|
|
|
# {{{ __del__(self): destructor method
|
|
|
|
def __del__(self):
|
|
|
|
if self.panelCanvas != None:
|
|
|
|
self.panelCanvas.Close(); self.panelCanvas = None;
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
#
|
2018-01-08 23:21:43 +00:00
|
|
|
# __init__(self, parent, appSize=(840, 630), canvasPos=(25, 50), canvasSize=(125, 35), cellSize=(7, 14)): initialisation method
|
|
|
|
def __init__(self, parent, appSize=(840, 630), canvasPos=(25, 50), canvasSize=(125, 35), cellSize=(7, 14)):
|
2018-01-08 19:28:43 +00:00
|
|
|
self._initPaletteToolBitmaps()
|
2018-01-07 15:43:41 +00:00
|
|
|
panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
2018-01-07 01:08:35 +00:00
|
|
|
self.canvasPathName = None
|
2018-01-07 15:43:41 +00:00
|
|
|
self.panelCanvas = MiRCARTCanvas(panelSkin, parentFrame=self, \
|
2018-01-08 23:21:43 +00:00
|
|
|
canvasPos=canvasPos, canvasSize=canvasSize, cellSize=cellSize)
|
2018-01-08 15:12:11 +00:00
|
|
|
self.panelCanvas.canvasCurTool = MiRCARTToolRect(self.panelCanvas)
|
2018-01-07 03:19:38 +00:00
|
|
|
self.canvasNew()
|
2018-01-07 01:08:35 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|