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-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
|
|
|
canvasPos = canvasSize = canvasTools = cellSize = None
|
|
|
|
|
|
|
|
# {{{ Commands
|
2018-01-07 14:20:27 +00:00
|
|
|
# Id Type Id Labels Icon bitmap Accelerator [Initial state]
|
2018-01-07 15:43:41 +00:00
|
|
|
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)
|
2018-01-07 22:49:57 +00:00
|
|
|
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...", \
|
2018-01-07 15:43:41 +00:00
|
|
|
"Export to Pasteb&in...", None, None, haveUrllib)
|
2018-01-07 22:49:57 +00:00
|
|
|
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)
|
|
|
|
CID_INCRBRUSH = (0x10e, TID_COMMAND, "Increase brush size", \
|
2018-01-07 15:43:41 +00:00
|
|
|
"&Increase brush size", wx.ART_PLUS, None)
|
2018-01-07 22:49:57 +00:00
|
|
|
CID_DECRBRUSH = (0x10f, TID_COMMAND, "Decrease brush size", \
|
2018-01-07 15:43:41 +00:00
|
|
|
"&Decrease brush size", wx.ART_MINUS, None)
|
2018-01-07 22:49:57 +00:00
|
|
|
CID_SOLID_BRUSH = (0x110, TID_SELECT, "Solid brush", "&Solid brush", None, None, True)
|
|
|
|
CID_RECT = (0x111, TID_SELECT, "Rectangle", "&Rectangle", None, None, True)
|
|
|
|
CID_CIRCLE = (0x112, TID_SELECT, "Circle", "&Circle", None, None, False)
|
|
|
|
CID_LINE = (0x113, TID_SELECT, "Line", "&Line", None, None, False)
|
|
|
|
CID_COLOUR00 = (0x114, TID_COMMAND, "Colour #00", "Colour #00", None, None)
|
|
|
|
CID_COLOUR01 = (0x115, TID_COMMAND, "Colour #01", "Colour #01", None, None)
|
|
|
|
CID_COLOUR02 = (0x116, TID_COMMAND, "Colour #02", "Colour #02", None, None)
|
|
|
|
CID_COLOUR03 = (0x117, TID_COMMAND, "Colour #03", "Colour #03", None, None)
|
|
|
|
CID_COLOUR04 = (0x118, TID_COMMAND, "Colour #04", "Colour #04", None, None)
|
|
|
|
CID_COLOUR05 = (0x119, TID_COMMAND, "Colour #05", "Colour #05", None, None)
|
|
|
|
CID_COLOUR06 = (0x11a, TID_COMMAND, "Colour #06", "Colour #06", None, None)
|
|
|
|
CID_COLOUR07 = (0x11b, TID_COMMAND, "Colour #07", "Colour #07", None, None)
|
|
|
|
CID_COLOUR08 = (0x11c, TID_COMMAND, "Colour #08", "Colour #08", None, None)
|
|
|
|
CID_COLOUR09 = (0x11d, TID_COMMAND, "Colour #09", "Colour #09", None, None)
|
|
|
|
CID_COLOUR10 = (0x11e, TID_COMMAND, "Colour #10", "Colour #10", None, None)
|
|
|
|
CID_COLOUR11 = (0x11f, TID_COMMAND, "Colour #11", "Colour #11", None, None)
|
|
|
|
CID_COLOUR12 = (0x120, TID_COMMAND, "Colour #12", "Colour #12", None, None)
|
|
|
|
CID_COLOUR13 = (0x121, TID_COMMAND, "Colour #13", "Colour #13", None, None)
|
|
|
|
CID_COLOUR14 = (0x122, TID_COMMAND, "Colour #14", "Colour #14", None, None)
|
|
|
|
CID_COLOUR15 = (0x123, 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-07 14:20:27 +00:00
|
|
|
CID_INCRBRUSH, CID_DECRBRUSH, CID_SOLID_BRUSH))
|
2018-01-07 01:08:35 +00:00
|
|
|
MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \
|
|
|
|
CID_RECT, CID_CIRCLE, CID_LINE))
|
|
|
|
# }}}
|
|
|
|
# {{{ 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-07 14:20:27 +00:00
|
|
|
CID_INCRBRUSH, CID_DECRBRUSH, CID_SOLID_BRUSH, NID_TOOLBAR_SEP, \
|
2018-01-07 01:08:35 +00:00
|
|
|
CID_RECT, CID_CIRCLE, CID_LINE, NID_TOOLBAR_SEP, \
|
|
|
|
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, ( \
|
|
|
|
CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO))
|
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-07 15:43:41 +00:00
|
|
|
# {{{ _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
|
|
|
# {{{ _setPaletteToolBitmaps(self): XXX
|
|
|
|
def _setPaletteToolBitmaps(self):
|
|
|
|
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)
|
|
|
|
self.toolBar.SetToolNormalBitmap( \
|
|
|
|
paletteDescr[numColour][0], toolBitmap)
|
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-07 22:49:57 +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-07 22:49:57 +00:00
|
|
|
self.panelCanvas.canvasStore.exportBitmapToPngFile( \
|
|
|
|
self.panelCanvas.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-07 22:49:57 +00:00
|
|
|
imgurResult = self.panelCanvas.canvasStore.exportBitmapToImgur( \
|
|
|
|
"c9a6efb3d7932fd", self.panelCanvas.canvasBitmap, "", "", 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 = \
|
|
|
|
self.panelCanvas.canvasStore.exportPastebin( \
|
|
|
|
"", \
|
|
|
|
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)
|
|
|
|
self.panelCanvas.canvasStore.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-07 03:19:38 +00:00
|
|
|
self.panelCanvas.canvasStore.importTextFile(self.canvasPathName)
|
|
|
|
self.panelCanvas.canvasStore.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-07 15:43:41 +00:00
|
|
|
self.panelCanvas.canvasStore.exportTextFile( \
|
|
|
|
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
|
|
|
|
def onCanvasMotion(self, event, mapPoint=None):
|
|
|
|
eventType = event.GetEventType()
|
|
|
|
if eventType == wx.wxEVT_ENTER_WINDOW:
|
|
|
|
pass
|
|
|
|
elif eventType == wx.wxEVT_MOTION:
|
|
|
|
self._updateStatusBar(showPos=mapPoint)
|
|
|
|
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]:
|
|
|
|
self.panelCanvas.undo()
|
|
|
|
elif cid == self.CID_REDO[0]:
|
|
|
|
self.panelCanvas.redo()
|
|
|
|
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
|
|
|
|
elif cid == self.CID_INCRBRUSH[0]:
|
2018-01-08 00:18:52 +00:00
|
|
|
self.panelCanvas.brushSize = \
|
2018-01-07 23:25:59 +00:00
|
|
|
[a+1 for a in self.panelCanvas.brushSize]
|
2018-01-08 00:18:52 +00:00
|
|
|
elif cid == self.CID_DECRBRUSH[0] \
|
|
|
|
and self.panelCanvas.brushSize[0] > 1 \
|
|
|
|
and self.panelCanvas.brushSize[1] > 1:
|
|
|
|
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]:
|
|
|
|
pass
|
|
|
|
elif cid == self.CID_CIRCLE[0]:
|
|
|
|
pass
|
|
|
|
elif cid == self.CID_LINE[0]:
|
|
|
|
pass
|
2018-01-08 00:18:52 +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;
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
#
|
|
|
|
# __init__(self, parent, appSize=(800, 600), canvasPos=(25, 50), cellSize=(7, 14), canvasSize=(100, 30), canvasTools=[]): initialisation method
|
|
|
|
def __init__(self, parent, appSize=(800, 600), canvasPos=(25, 50), cellSize=(7, 14), canvasSize=(100, 30), canvasTools=[]):
|
2018-01-07 15:43:41 +00:00
|
|
|
panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
|
|
|
self._setPaletteToolBitmaps()
|
2018-01-07 03:19:38 +00:00
|
|
|
self.canvasPos = canvasPos; self.cellSize = cellSize; self.canvasSize = canvasSize;
|
2018-01-07 01:08:35 +00:00
|
|
|
self.canvasPathName = None
|
|
|
|
self.canvasTools = canvasTools
|
2018-01-07 15:43:41 +00:00
|
|
|
self.panelCanvas = MiRCARTCanvas(panelSkin, parentFrame=self, \
|
|
|
|
canvasPos=self.canvasPos, canvasSize=self.canvasSize, \
|
2018-01-07 03:19:38 +00:00
|
|
|
canvasTools=self.canvasTools, cellSize=self.cellSize)
|
|
|
|
self.canvasNew()
|
2018-01-07 01:08:35 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|