2019-09-01 14:34:00 +00:00
#!/usr/bin/env python3
#
2019-09-04 09:47:09 +00:00
# GuiCanvasInterface.py -- XXX
2019-09-04 14:23:59 +00:00
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
2019-09-01 14:34:00 +00:00
#
2019-09-03 16:58:50 +00:00
from ToolCircle import ToolCircle
2019-09-06 08:29:45 +00:00
from ToolFill import ToolFill
2019-09-03 16:58:50 +00:00
from ToolLine import ToolLine
from ToolSelectClone import ToolSelectClone
from ToolSelectMove import ToolSelectMove
from ToolRect import ToolRect
from ToolText import ToolText
2019-09-04 09:47:09 +00:00
2019-09-03 16:58:50 +00:00
from glob import glob
2019-09-04 09:47:09 +00:00
from GuiCanvasInterfaceAbout import GuiCanvasInterfaceAbout
2019-09-05 15:13:35 +00:00
from ImgurApiKey import ImgurApiKey
2019-09-04 10:50:21 +00:00
import io , os , random , wx , wx . adv
2019-09-01 14:34:00 +00:00
2019-09-04 09:47:09 +00:00
class GuiCanvasInterface ( ) :
2019-09-01 14:34:00 +00:00
""" XXX """
2019-09-06 08:29:45 +00:00
# {{{ _dialogSaveChanges(self): XXX
2019-09-01 14:34:00 +00:00
def _dialogSaveChanges ( self ) :
2019-09-06 08:29:45 +00:00
with wx . MessageDialog ( self . parentCanvas , \
" Do you want to save changes to {} ? " . format ( self . canvasPathName ) , \
" " , wx . CANCEL | wx . CANCEL_DEFAULT | wx . ICON_QUESTION | wx . YES_NO ) as dialog :
2019-09-01 14:34:00 +00:00
dialogChoice = dialog . ShowModal ( )
return dialogChoice
# }}}
2019-09-03 16:58:50 +00:00
# {{{ canvasAbout(self, event): XXX
def canvasAbout ( self , event ) :
2019-09-04 09:47:09 +00:00
GuiCanvasInterfaceAbout ( self . parentFrame )
2019-09-03 16:58:50 +00:00
# }}}
2019-09-01 14:34:00 +00:00
# {{{ canvasBrushSolid(self, event): XXX
def canvasBrushSolid ( self , event ) :
pass
# }}}
# {{{ canvasColour(self, event, numColour): XXX
def canvasColour ( self , event , numColour ) :
if event . GetEventType ( ) == wx . wxEVT_TOOL :
self . parentCanvas . brushColours [ 0 ] = numColour
elif event . GetEventType ( ) == wx . wxEVT_TOOL_RCLICKED :
self . parentCanvas . brushColours [ 1 ] = numColour
self . parentFrame . onCanvasUpdate ( colours = self . parentCanvas . brushColours )
# }}}
# {{{ canvasCopy(self, event): XXX
def canvasCopy ( self , event ) :
pass
# }}}
# {{{ canvasCut(self, event): XXX
def canvasCut ( self , event ) :
pass
# }}}
2019-09-06 08:29:45 +00:00
# {{{ canvasDelete(self, event): XXX
def canvasDelete ( self , event ) :
pass
# }}}
# {{{ canvasExit(self, event): XXX
def canvasExit ( self , event ) :
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 ( event )
self . parentFrame . Close ( True )
# }}}
# {{{ canvasNew(self, event, newCanvasSize=None): XXX
def canvasNew ( self , event , newCanvasSize = None ) :
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 ( event )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
if newCanvasSize == None :
newCanvasSize = list ( self . parentCanvas . defaultCanvasSize )
newMap = [ [ [ 1 , 1 , 0 , " " ] for x in range ( newCanvasSize [ 0 ] ) ] for y in range ( newCanvasSize [ 1 ] ) ]
self . parentCanvas . onStoreUpdate ( newCanvasSize , newMap )
self . canvasPathName = None
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
self . parentFrame . onCanvasUpdate ( pathName = " " , undoLevel = - 1 )
# }}}
# {{{ canvasOpen(self, event): XXX
def canvasOpen ( self , event ) :
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 ( event )
with wx . FileDialog ( self . parentCanvas , " Open " , os . getcwd ( ) , " " , " mIRC art files (*.txt)|*.txt|All Files (*.*)|*.* " , wx . FD_OPEN ) as dialog :
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
self . canvasPathName = dialog . GetPath ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
import pdb ; pdb . set_trace ( )
rc , error = self . parentCanvas . canvasImportStore . importTextFile ( self . canvasPathName )
if rc :
self . parentCanvas . onStoreUpdate ( self . parentCanvas . canvasImportStore . inSize , self . parentCanvas . canvasImportStore . outMap )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
self . parentFrame . onCanvasUpdate ( pathName = self . canvasPathName , undoLevel = - 1 )
return True
else :
print ( " error: {} " . format ( error ) , file = sys . stderr )
return False
# }}}
# {{{ canvasPaste(self, event): XXX
def canvasPaste ( self , event ) :
pass
# }}}
# {{{ canvasRedo(self, event): XXX
def canvasRedo ( self , event ) :
self . parentCanvas . _dispatchDeltaPatches ( self . parentCanvas . canvasJournal . popRedo ( ) )
# }}}
# {{{ canvasSave(self, event): XXX
def canvasSave ( self , event ) :
if self . canvasPathName == None :
if self . canvasSaveAs ( event ) == False :
return
try :
with open ( self . canvasPathName , " w " , encoding = " utf-8 " ) as outFile :
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
self . parentCanvas . canvasExportStore . exportTextFile ( \
self . parentCanvas . canvasMap , self . parentCanvas . canvasSize , outFile )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
return True
except IOError as error :
return False
# }}}
# {{{ canvasSaveAs(self, event): XXX
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 :
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
self . canvasPathName = dialog . GetPath ( )
return self . canvasSave ( event )
# }}}
# {{{ canvasUndo(self, event): XXX
def canvasUndo ( self , event ) :
self . parentCanvas . _dispatchDeltaPatches ( self . parentCanvas . canvasJournal . popUndo ( ) )
# }}}
2019-09-01 14:34:00 +00:00
# {{{ canvasDecrBrushHeight(self, event): XXX
def canvasDecrBrushHeight ( self , event ) :
if self . parentCanvas . brushSize [ 1 ] > 1 :
self . parentCanvas . brushSize [ 1 ] - = 1
self . parentFrame . onCanvasUpdate ( brushSize = self . parentCanvas . brushSize )
# }}}
# {{{ canvasDecrBrushHeightWidth(self, event): XXX
def canvasDecrBrushHeightWidth ( self , event ) :
self . canvasDecrBrushHeight ( event )
self . canvasDecrBrushWidth ( event )
# }}}
# {{{ canvasDecrBrushWidth(self, event): XXX
def canvasDecrBrushWidth ( self , event ) :
if self . parentCanvas . brushSize [ 0 ] > 1 :
self . parentCanvas . brushSize [ 0 ] - = 1
self . parentFrame . onCanvasUpdate ( brushSize = self . parentCanvas . brushSize )
# }}}
# {{{ canvasDecrCanvasHeight(self, event): XXX
def canvasDecrCanvasHeight ( self , event ) :
if self . parentCanvas . canvasSize [ 1 ] > 1 :
2019-09-06 08:29:45 +00:00
self . parentCanvas . resize ( [ self . parentCanvas . canvasSize [ 0 ] , self . parentCanvas . canvasSize [ 1 ] - 1 ] )
2019-09-01 14:34:00 +00:00
# }}}
# {{{ canvasDecrCanvasHeightWidth(self, event): XXX
def canvasDecrCanvasHeightWidth ( self , event ) :
self . canvasDecrCanvasHeight ( event )
self . canvasDecrCanvasWidth ( event )
# }}}
# {{{ canvasDecrCanvasWidth(self, event): XXX
def canvasDecrCanvasWidth ( self , event ) :
if self . parentCanvas . canvasSize [ 0 ] > 1 :
2019-09-06 08:29:45 +00:00
self . parentCanvas . resize ( [ self . parentCanvas . canvasSize [ 0 ] - 1 , self . parentCanvas . canvasSize [ 1 ] ] )
2019-09-01 14:34:00 +00:00
# }}}
2019-09-06 08:29:45 +00:00
# {{{ canvasIncrBrushHeight(self, event): XXX
def canvasIncrBrushHeight ( self , event ) :
self . parentCanvas . brushSize [ 1 ] + = 1
self . parentFrame . onCanvasUpdate ( brushSize = self . parentCanvas . brushSize )
2019-09-01 14:34:00 +00:00
# }}}
2019-09-06 08:29:45 +00:00
# {{{ canvasIncrBrushHeightWidth(self, event): XXX
def canvasIncrBrushHeightWidth ( self , event ) :
self . canvasIncrBrushHeight ( event )
self . canvasIncrBrushWidth ( event )
2019-09-01 14:34:00 +00:00
# }}}
2019-09-06 08:29:45 +00:00
# {{{ canvasIncrBrushWidth(self, event): XXX
def canvasIncrBrushWidth ( self , event ) :
self . parentCanvas . brushSize [ 0 ] + = 1
self . parentFrame . onCanvasUpdate ( brushSize = self . parentCanvas . brushSize )
# }}}
# {{{ canvasIncrCanvasHeight(self, event): XXX
def canvasIncrCanvasHeight ( self , event ) :
self . parentCanvas . resize ( [ self . parentCanvas . canvasSize [ 0 ] , self . parentCanvas . canvasSize [ 1 ] + 1 ] )
2019-09-04 10:50:21 +00:00
# }}}
2019-09-06 08:29:45 +00:00
# {{{ canvasIncrCanvasHeightWidth(self, event): XXX
def canvasIncrCanvasHeightWidth ( self , event ) :
self . canvasIncrCanvasHeight ( event )
self . canvasIncrCanvasWidth ( event )
# }}}
# {{{ canvasIncrCanvasWidth(self, event): XXX
def canvasIncrCanvasWidth ( self , event ) :
self . parentCanvas . resize ( [ self . parentCanvas . canvasSize [ 0 ] + 1 , self . parentCanvas . canvasSize [ 1 ] ] )
# }}}
Implements importing from {ANSI,SAUCE} and exporting to ANSI files.
assets/tools/{MiRCARTTo{Ansi,PngFile},SAUCETo{Ansi,MiRCART}}.py: reimplemented using Canvas{Ex,Im}portStore.
libcanvas/Canvas.py: minor cleanup.
libcanvas/CanvasExportStore.py:export{Ansi,Png}File(): merged from assets/tools/MiRCARTTo{Ansi,PngFile}.py.
libcanvas/CanvasImportStore.py:import{Ansi,Sauce}File(): merged from assets/tools/SAUCETo{Ansi,MiRCART}.py.
libcanvas/Colours.py:{AnsiBgToMiRCARTColours,AnsiFgToMiRCARTColours,AnsiFgBoldToMiRCARTColours}{}: merged from assets/tools/SAUCEToMiRCART.py.
libcanvas/Colours.py:{ColourMap{Bold,Normal}}[]: merged from assets/tools/MiRCARTToPngFile.py.
libcanvas/Colours.py: minor cleanup.
libgui/GuiCanvasInterface.py:canvas{ExportAsAnsi,Import{Ansi,Sauce}}(): implemented.
libgui/GuiFrame.py: adds CID_{EXPORT_AS_{ANSI,SAUCE},IMPORT_{ANSI,SAUCE}}.
assets/text/TODO: updated.
2019-09-05 14:55:07 +00:00
# {{{ canvasExportAsAnsi(self, event): XXX
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 :
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
outPathName = dialog . GetPath ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
with open ( outPathName , " w " , encoding = " utf-8 " ) as outFile :
self . parentCanvas . canvasExportStore . exportAnsiFile ( self . parentCanvas . canvasMap , self . parentCanvas . canvasSize , outFile )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
return True
# }}}
2019-09-01 14:34:00 +00:00
# {{{ canvasExportAsPng(self, event): XXX
def canvasExportAsPng ( self , event ) :
Implements importing from {ANSI,SAUCE} and exporting to ANSI files.
assets/tools/{MiRCARTTo{Ansi,PngFile},SAUCETo{Ansi,MiRCART}}.py: reimplemented using Canvas{Ex,Im}portStore.
libcanvas/Canvas.py: minor cleanup.
libcanvas/CanvasExportStore.py:export{Ansi,Png}File(): merged from assets/tools/MiRCARTTo{Ansi,PngFile}.py.
libcanvas/CanvasImportStore.py:import{Ansi,Sauce}File(): merged from assets/tools/SAUCETo{Ansi,MiRCART}.py.
libcanvas/Colours.py:{AnsiBgToMiRCARTColours,AnsiFgToMiRCARTColours,AnsiFgBoldToMiRCARTColours}{}: merged from assets/tools/SAUCEToMiRCART.py.
libcanvas/Colours.py:{ColourMap{Bold,Normal}}[]: merged from assets/tools/MiRCARTToPngFile.py.
libcanvas/Colours.py: minor cleanup.
libgui/GuiCanvasInterface.py:canvas{ExportAsAnsi,Import{Ansi,Sauce}}(): implemented.
libgui/GuiFrame.py: adds CID_{EXPORT_AS_{ANSI,SAUCE},IMPORT_{ANSI,SAUCE}}.
assets/text/TODO: updated.
2019-09-05 14:55:07 +00:00
with wx . FileDialog ( self . parentFrame , " Save As... " , os . getcwd ( ) , " " , " PNG (*.png)|*.png|All Files (*.*)|*.* " , wx . FD_SAVE | wx . FD_OVERWRITE_PROMPT ) as dialog :
2019-09-01 14:34:00 +00:00
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
outPathName = dialog . GetPath ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
self . parentCanvas . canvasExportStore . exportBitmapToPngFile ( \
2019-09-04 14:36:57 +00:00
self . parentCanvas . canvasBackend . canvasBitmap , outPathName , wx . BITMAP_TYPE_PNG )
2019-09-01 14:34:00 +00:00
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
return True
# }}}
# {{{ canvasExportImgur(self, event): XXX
def canvasExportImgur ( self , event ) :
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
rc , status , result = self . parentCanvas . canvasExportStore . exportBitmapToImgur ( \
self . imgurApiKey , self . parentCanvas . canvasBackend . canvasBitmap , " " , " " , wx . BITMAP_TYPE_PNG )
2019-09-01 14:34:00 +00:00
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
2019-09-06 08:29:45 +00:00
if rc :
2019-09-01 14:34:00 +00:00
if not wx . TheClipboard . IsOpened ( ) :
2019-09-06 08:29:45 +00:00
wx . TheClipboard . Open ( ) ; wx . TheClipboard . SetData ( wx . TextDataObject ( result ) ) ; wx . TheClipboard . Close ( ) ;
wx . MessageBox ( " Exported to Imgur: {} " . format ( result ) , " Export to Imgur " , wx . ICON_INFORMATION | wx . OK )
2019-09-01 14:34:00 +00:00
else :
2019-09-06 08:29:45 +00:00
wx . MessageBox ( " Failed to export to Imgur: {} " . format ( result ) , " Export to Imgur " , wx . ICON_EXCLAMATION | wx . OK )
2019-09-01 14:34:00 +00:00
# }}}
# {{{ canvasExportPastebin(self, event): XXX
def canvasExportPastebin ( self , event ) :
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
pasteStatus , pasteResult = \
self . parentCanvas . canvasExportStore . exportPastebin ( \
" 253ce2f0a45140ee0a44ca99aa49260 " , \
self . parentCanvas . canvasMap , \
2019-09-01 14:34:00 +00:00
self . parentCanvas . canvasSize )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
if pasteStatus :
if not wx . TheClipboard . IsOpened ( ) :
wx . TheClipboard . Open ( )
wx . TheClipboard . SetData ( wx . TextDataObject ( pasteResult ) )
wx . TheClipboard . Close ( )
2019-09-06 08:29:45 +00:00
wx . MessageBox ( " Exported to Pastebin: " + pasteResult , " Export to Pastebin " , wx . OK | wx . ICON_INFORMATION )
2019-09-01 14:34:00 +00:00
else :
2019-09-06 08:29:45 +00:00
wx . MessageBox ( " Failed to export to Pastebin: " + pasteResult , " Export to Pastebin " , wx . OK | wx . ICON_EXCLAMATION )
# }}}
# {{{ canvasExportToClipboard(self, event): XXX
def canvasExportToClipboard ( self , event ) :
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
rc , outBuffer = self . parentCanvas . canvasExportStore . exportTextBuffer ( self . parentCanvas . canvasMap , self . parentCanvas . canvasSize )
if rc and wx . TheClipboard . Open ( ) :
wx . TheClipboard . SetData ( wx . TextDataObject ( outBuffer ) )
wx . TheClipboard . Close ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
return True
2019-09-01 14:34:00 +00:00
# }}}
Implements importing from {ANSI,SAUCE} and exporting to ANSI files.
assets/tools/{MiRCARTTo{Ansi,PngFile},SAUCETo{Ansi,MiRCART}}.py: reimplemented using Canvas{Ex,Im}portStore.
libcanvas/Canvas.py: minor cleanup.
libcanvas/CanvasExportStore.py:export{Ansi,Png}File(): merged from assets/tools/MiRCARTTo{Ansi,PngFile}.py.
libcanvas/CanvasImportStore.py:import{Ansi,Sauce}File(): merged from assets/tools/SAUCETo{Ansi,MiRCART}.py.
libcanvas/Colours.py:{AnsiBgToMiRCARTColours,AnsiFgToMiRCARTColours,AnsiFgBoldToMiRCARTColours}{}: merged from assets/tools/SAUCEToMiRCART.py.
libcanvas/Colours.py:{ColourMap{Bold,Normal}}[]: merged from assets/tools/MiRCARTToPngFile.py.
libcanvas/Colours.py: minor cleanup.
libgui/GuiCanvasInterface.py:canvas{ExportAsAnsi,Import{Ansi,Sauce}}(): implemented.
libgui/GuiFrame.py: adds CID_{EXPORT_AS_{ANSI,SAUCE},IMPORT_{ANSI,SAUCE}}.
assets/text/TODO: updated.
2019-09-05 14:55:07 +00:00
# {{{ canvasImportAnsi(self, event): XXX
def canvasImportAnsi ( self , event ) :
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 ( event )
with wx . FileDialog ( self . parentCanvas , " Open " , os . getcwd ( ) , " " , " ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.* " , wx . FD_OPEN ) as dialog :
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
self . canvasPathName = dialog . GetPath ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
rc , error = self . parentCanvas . canvasImportStore . importAnsiFile ( self . canvasPathName )
if rc :
self . parentCanvas . onStoreUpdate ( self . parentCanvas . canvasImportStore . inSize , self . parentCanvas . canvasImportStore . outMap )
self . canvasPathName = " (Imported) "
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
self . parentFrame . onCanvasUpdate ( pathName = " (Imported) " , undoLevel = - 1 )
return True
else :
print ( " error: {} " . format ( error ) , file = sys . stderr )
return False
Implements importing from {ANSI,SAUCE} and exporting to ANSI files.
assets/tools/{MiRCARTTo{Ansi,PngFile},SAUCETo{Ansi,MiRCART}}.py: reimplemented using Canvas{Ex,Im}portStore.
libcanvas/Canvas.py: minor cleanup.
libcanvas/CanvasExportStore.py:export{Ansi,Png}File(): merged from assets/tools/MiRCARTTo{Ansi,PngFile}.py.
libcanvas/CanvasImportStore.py:import{Ansi,Sauce}File(): merged from assets/tools/SAUCETo{Ansi,MiRCART}.py.
libcanvas/Colours.py:{AnsiBgToMiRCARTColours,AnsiFgToMiRCARTColours,AnsiFgBoldToMiRCARTColours}{}: merged from assets/tools/SAUCEToMiRCART.py.
libcanvas/Colours.py:{ColourMap{Bold,Normal}}[]: merged from assets/tools/MiRCARTToPngFile.py.
libcanvas/Colours.py: minor cleanup.
libgui/GuiCanvasInterface.py:canvas{ExportAsAnsi,Import{Ansi,Sauce}}(): implemented.
libgui/GuiFrame.py: adds CID_{EXPORT_AS_{ANSI,SAUCE},IMPORT_{ANSI,SAUCE}}.
assets/text/TODO: updated.
2019-09-05 14:55:07 +00:00
# }}}
2019-09-04 10:50:21 +00:00
# {{{ canvasImportFromClipboard(self, event): XXX
def canvasImportFromClipboard ( self , event ) :
rc = False
2019-09-06 08:29:45 +00:00
if wx . TheClipboard . IsSupported ( wx . DataFormat ( wx . DF_TEXT ) ) \
2019-09-04 10:50:21 +00:00
and wx . TheClipboard . Open ( ) :
inBuffer = wx . TextDataObject ( )
if wx . TheClipboard . GetData ( inBuffer ) :
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 ( event )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
rc , error = self . parentCanvas . canvasImportStore . importTextBuffer ( io . StringIO ( inBuffer . GetText ( ) ) )
if rc :
self . parentCanvas . onStoreUpdate ( self . parentCanvas . canvasImportStore . inSize , self . parentCanvas . canvasImportStore . outMap )
self . canvasPathName = " (Clipboard) "
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
self . parentFrame . onCanvasUpdate ( pathName = " (Clipboard) " , undoLevel = - 1 )
else :
print ( " error: {} " . format ( error ) , file = sys . stderr )
2019-09-04 10:50:21 +00:00
wx . TheClipboard . Close ( )
if not rc :
with wx . MessageDialog ( self . parentCanvas , " Clipboard does not contain text data and/or cannot be opened " , " " , wx . ICON_QUESTION | wx . OK | wx . OK_DEFAULT ) as dialog :
dialog . ShowModal ( )
# }}}
Implements importing from {ANSI,SAUCE} and exporting to ANSI files.
assets/tools/{MiRCARTTo{Ansi,PngFile},SAUCETo{Ansi,MiRCART}}.py: reimplemented using Canvas{Ex,Im}portStore.
libcanvas/Canvas.py: minor cleanup.
libcanvas/CanvasExportStore.py:export{Ansi,Png}File(): merged from assets/tools/MiRCARTTo{Ansi,PngFile}.py.
libcanvas/CanvasImportStore.py:import{Ansi,Sauce}File(): merged from assets/tools/SAUCETo{Ansi,MiRCART}.py.
libcanvas/Colours.py:{AnsiBgToMiRCARTColours,AnsiFgToMiRCARTColours,AnsiFgBoldToMiRCARTColours}{}: merged from assets/tools/SAUCEToMiRCART.py.
libcanvas/Colours.py:{ColourMap{Bold,Normal}}[]: merged from assets/tools/MiRCARTToPngFile.py.
libcanvas/Colours.py: minor cleanup.
libgui/GuiCanvasInterface.py:canvas{ExportAsAnsi,Import{Ansi,Sauce}}(): implemented.
libgui/GuiFrame.py: adds CID_{EXPORT_AS_{ANSI,SAUCE},IMPORT_{ANSI,SAUCE}}.
assets/text/TODO: updated.
2019-09-05 14:55:07 +00:00
# {{{ canvasImportSauce(self, event): XXX
def canvasImportSauce ( self , event ) :
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 ( event )
with wx . FileDialog ( self . parentCanvas , " Open " , os . getcwd ( ) , " " , " SAUCE files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.* " , wx . FD_OPEN ) as dialog :
if dialog . ShowModal ( ) == wx . ID_CANCEL :
return False
else :
self . canvasPathName = dialog . GetPath ( )
self . parentCanvas . SetCursor ( wx . Cursor ( wx . CURSOR_WAIT ) )
2019-09-06 08:29:45 +00:00
rc , error = self . parentCanvas . canvasImportStore . importSauceFile ( self . canvasPathName )
if rc :
self . parentCanvas . onStoreUpdate ( self . parentCanvas . canvasImportStore . inSize , self . parentCanvas . canvasImportStore . outMap )
self . canvasPathName = " (Imported) "
self . parentCanvas . SetCursor ( wx . Cursor ( wx . NullCursor ) )
self . parentFrame . onCanvasUpdate ( pathName = " (Imported) " , undoLevel = - 1 )
return True
else :
print ( " error: {} " . format ( error ) , file = sys . stderr )
return False
2019-09-01 14:34:00 +00:00
# }}}
2019-09-06 08:29:45 +00:00
2019-09-01 14:34:00 +00:00
# {{{ canvasToolCircle(self, event): XXX
def canvasToolCircle ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolCircle ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_CIRCLE [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_CIRCLE [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_CIRCLE [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolFill(self, event): XXX
def canvasToolFill ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolFill ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_FILL [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_FILL [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_FILL [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolLine(self, event): XXX
def canvasToolLine ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolLine ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_LINE [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_LINE [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_LINE [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolSelectClone(self, event): XXX
def canvasToolSelectClone ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolSelectClone ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_CLONE_SELECT [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_CLONE_SELECT [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_CLONE_SELECT [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolSelectMove(self, event): XXX
def canvasToolSelectMove ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolSelectMove ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_MOVE_SELECT [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_MOVE_SELECT [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_MOVE_SELECT [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolRect(self, event): XXX
def canvasToolRect ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolRect ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_RECT [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_RECT [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_RECT [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
# {{{ canvasToolText(self, event): XXX
def canvasToolText ( self , event ) :
2019-09-03 16:58:50 +00:00
self . canvasTool = ToolText ( self . parentCanvas )
2019-09-01 14:34:00 +00:00
self . parentFrame . menuItemsById [ self . parentFrame . CID_TEXT [ 0 ] ] . Check ( True )
toolBar = self . parentFrame . toolBarItemsById [ self . parentFrame . CID_TEXT [ 0 ] ] . GetToolBar ( )
toolBar . ToggleTool ( self . parentFrame . CID_TEXT [ 0 ] , True )
self . parentFrame . onCanvasUpdate ( toolName = self . canvasTool . name )
# }}}
#
# __init__(self, parentCanvas, parentFrame):
def __init__ ( self , parentCanvas , parentFrame ) :
2019-09-05 15:13:35 +00:00
self . canvasPathName , self . imgurApiKey = None , ImgurApiKey . imgurApiKey
2019-09-04 09:47:09 +00:00
self . parentCanvas , self . parentFrame = parentCanvas , parentFrame
2019-09-01 14:34:00 +00:00
self . canvasToolRect ( None )
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120