mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-30 02:26:38 +00:00
MiRCARTCanvasStore.py: split & merge MiRCART{FromTextFile,ToPastebin,ToTextFile}.py.
This commit is contained in:
parent
4abf68e168
commit
a58781ed7a
@ -23,6 +23,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from MiRCARTCanvasJournal import MiRCARTCanvasJournal
|
from MiRCARTCanvasJournal import MiRCARTCanvasJournal
|
||||||
|
from MiRCARTCanvasStore import MiRCARTCanvasStore
|
||||||
from MiRCARTColours import MiRCARTColours
|
from MiRCARTColours import MiRCARTColours
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
@ -32,8 +33,18 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None
|
canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None
|
||||||
canvasBitmap = canvasMap = canvasTools = None
|
canvasBitmap = canvasMap = canvasTools = None
|
||||||
mircBg = mircFg = mircBrushes = mircPens = None
|
mircBg = mircFg = mircBrushes = mircPens = None
|
||||||
canvasJournal = None
|
canvasJournal = canvasStore = None
|
||||||
|
|
||||||
|
# {{{ _initBrushesAndPens(self): XXX
|
||||||
|
def _initBrushesAndPens(self):
|
||||||
|
self.mircBrushes = [None for x in range(len(MiRCARTColours))]
|
||||||
|
self.mircPens = [None for x in range(len(MiRCARTColours))]
|
||||||
|
for mircColour in range(0, len(MiRCARTColours)):
|
||||||
|
self.mircBrushes[mircColour] = wx.Brush( \
|
||||||
|
wx.Colour(MiRCARTColours[mircColour]), wx.BRUSHSTYLE_SOLID)
|
||||||
|
self.mircPens[mircColour] = wx.Pen( \
|
||||||
|
wx.Colour(MiRCARTColours[mircColour]), 1)
|
||||||
|
# }}}
|
||||||
# {{{ _drawPatch(self, patch, eventDc, tmpDc, atPoint): XXX
|
# {{{ _drawPatch(self, patch, eventDc, tmpDc, atPoint): XXX
|
||||||
def _drawPatch(self, patch, eventDc, tmpDc, atPoint):
|
def _drawPatch(self, patch, eventDc, tmpDc, atPoint):
|
||||||
absPoint = self._relMapPointToAbsPoint((patch[0], patch[1]), atPoint)
|
absPoint = self._relMapPointToAbsPoint((patch[0], patch[1]), atPoint)
|
||||||
@ -69,6 +80,7 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
def _setMapCell(self, absMapPoint, colourFg, colourBg, char):
|
def _setMapCell(self, absMapPoint, colourFg, colourBg, char):
|
||||||
self.canvasMap[absMapPoint[1]][absMapPoint[0]] = [colourFg, colourBg, char]
|
self.canvasMap[absMapPoint[1]][absMapPoint[0]] = [colourFg, colourBg, char]
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ onClose(self, event): XXX
|
# {{{ onClose(self, event): XXX
|
||||||
def onClose(self, event):
|
def onClose(self, event):
|
||||||
self.Destroy(); self.__del__();
|
self.Destroy(); self.__del__();
|
||||||
@ -106,10 +118,30 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
def redo(self):
|
def redo(self):
|
||||||
return self.canvasJournal.redo()
|
return self.canvasJournal.redo()
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ resize(self, newCanvasSize): XXX
|
||||||
|
def resize(self, newCanvasSize):
|
||||||
|
if newCanvasSize != self.canvasSize:
|
||||||
|
self.SetSize(*self.canvasPos, \
|
||||||
|
newCanvasSize[0] * self.cellSize[0], \
|
||||||
|
newCanvasSize[1] * self.cellSize[1])
|
||||||
|
for numRow in range(0, self.canvasSize[1]):
|
||||||
|
for numNewCol in range(self.canvasSize[0], newCanvasSize[0]):
|
||||||
|
self.canvasMap[numRow].append([1, 1, " "])
|
||||||
|
for numNewRow in range(self.canvasSize[1], newCanvasSize[1]):
|
||||||
|
self.canvasMap.append([])
|
||||||
|
for numNewCol in range(0, newCanvasSize[0]):
|
||||||
|
self.canvasMap[numNewRow].append([1, 1, " "])
|
||||||
|
self.canvasSize = newCanvasSize
|
||||||
|
canvasWinSize = ( \
|
||||||
|
self.cellSize[0] * self.canvasSize[0], \
|
||||||
|
self.cellSize[1] * self.canvasSize[1])
|
||||||
|
self.canvasBitmap = wx.Bitmap(canvasWinSize)
|
||||||
|
# }}}
|
||||||
# {{{ undo(self): XXX
|
# {{{ undo(self): XXX
|
||||||
def undo(self):
|
def undo(self):
|
||||||
return self.canvasJournal.undo()
|
return self.canvasJournal.undo()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ __del__(self): destructor method
|
# {{{ __del__(self): destructor method
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.canvasBitmap != None:
|
if self.canvasBitmap != None:
|
||||||
@ -124,30 +156,19 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# _init__(self, parent, parentFrame, canvasPos, cellSize, canvasSize, canvasTools): initialisation method
|
# _init__(self, parent, parentFrame, canvasPos, cellSize, canvasSize, canvasTools): initialisation method
|
||||||
def __init__(self, parent, parentFrame, canvasPos, cellSize, canvasSize, canvasTools):
|
def __init__(self, parent, parentFrame, canvasPos, canvasSize, canvasTools, cellSize):
|
||||||
self.parentFrame = parentFrame
|
self.parentFrame = parentFrame
|
||||||
canvasWinSize = (cellSize[0] * canvasSize[0], cellSize[1] * canvasSize[1])
|
self.canvasPos = canvasPos; self.canvasSize = canvasSize;
|
||||||
super().__init__(parent, pos=canvasPos, size=canvasWinSize)
|
self.canvasTools = [canvasTool(self) for canvasTool in canvasTools]
|
||||||
self.canvasPos = canvasPos; self.canvasSize = canvasSize; self.canvasWinSize = canvasWinSize;
|
self.cellSize = cellSize
|
||||||
self.cellPos = (0, 0); self.cellSize = cellSize;
|
|
||||||
|
|
||||||
self.canvasBitmap = wx.Bitmap(canvasWinSize)
|
self.cellPos = (0, 0)
|
||||||
self.canvasMap = [[[1, 1, " "] for x in range(canvasSize[0])] for y in range(canvasSize[1])]
|
self.mircBg = 1; self.mircFg = 4; self._initBrushesAndPens();
|
||||||
self.canvasTools = []
|
self.canvasJournal = MiRCARTCanvasJournal(parentCanvas=self)
|
||||||
for canvasTool in canvasTools:
|
self.canvasStore = MiRCARTCanvasStore(parentCanvas=self)
|
||||||
self.canvasTools.append(canvasTool(self))
|
|
||||||
|
|
||||||
self.mircBg = 1; self.mircFg = 4;
|
|
||||||
self.mircBrushes = [None for x in range(len(MiRCARTColours))]
|
|
||||||
self.mircPens = [None for x in range(len(MiRCARTColours))]
|
|
||||||
for mircColour in range(0, len(MiRCARTColours)):
|
|
||||||
self.mircBrushes[mircColour] = wx.Brush( \
|
|
||||||
wx.Colour(MiRCARTColours[mircColour]), wx.BRUSHSTYLE_SOLID)
|
|
||||||
self.mircPens[mircColour] = wx.Pen( \
|
|
||||||
wx.Colour(MiRCARTColours[mircColour]), 1)
|
|
||||||
|
|
||||||
self.canvasJournal = MiRCARTCanvasJournal(self)
|
|
||||||
|
|
||||||
|
super().__init__(parent, pos=canvasPos, \
|
||||||
|
size=[w*h for w,h in zip(canvasSize, cellSize)])
|
||||||
self.Bind(wx.EVT_CLOSE, self.onClose)
|
self.Bind(wx.EVT_CLOSE, self.onClose)
|
||||||
self.Bind(wx.EVT_LEFT_DOWN, self.onMouseEvent)
|
self.Bind(wx.EVT_LEFT_DOWN, self.onMouseEvent)
|
||||||
self.Bind(wx.EVT_MOTION, self.onMouseEvent)
|
self.Bind(wx.EVT_MOTION, self.onMouseEvent)
|
||||||
|
@ -83,6 +83,11 @@ class MiRCARTCanvasJournal():
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ reset(self): XXX
|
||||||
|
def reset(self):
|
||||||
|
self.patchesTmp = []
|
||||||
|
self.patchesUndo = [None]; self.patchesUndoLevel = 0;
|
||||||
|
# }}}
|
||||||
# {{{ undo(self): XXX
|
# {{{ undo(self): XXX
|
||||||
def undo(self):
|
def undo(self):
|
||||||
if self.patchesUndo[self.patchesUndoLevel] != None:
|
if self.patchesUndo[self.patchesUndoLevel] != None:
|
||||||
@ -98,8 +103,6 @@ class MiRCARTCanvasJournal():
|
|||||||
#
|
#
|
||||||
# __init__(self, parentCanvas): initialisation method
|
# __init__(self, parentCanvas): initialisation method
|
||||||
def __init__(self, parentCanvas):
|
def __init__(self, parentCanvas):
|
||||||
self.parentCanvas = parentCanvas
|
self.parentCanvas = parentCanvas; self.reset();
|
||||||
self.patchesTmp = []
|
|
||||||
self.patchesUndo = [None]; self.patchesUndoLevel = 0;
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# MiRCARTFromTextFile.py -- XXX
|
# MiRCARTCanvasStore.py -- XXX
|
||||||
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -22,9 +22,26 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
class MiRCARTFromTextFile():
|
import base64
|
||||||
|
import io
|
||||||
|
import wx
|
||||||
|
|
||||||
|
try:
|
||||||
|
from MiRCARTToPngFile import MiRCARTToPngFile
|
||||||
|
haveMiRCARTToPngFile = True
|
||||||
|
except ImportError:
|
||||||
|
haveMiRCARTToPngFile = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
import requests, urllib.request
|
||||||
|
haveUrllib = True
|
||||||
|
except ImportError:
|
||||||
|
haveUrllib = False
|
||||||
|
|
||||||
|
class MiRCARTCanvasStore():
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
inFile = inSize = outMap = None
|
inFile = inSize = outMap = None
|
||||||
|
parentCanvas = None
|
||||||
|
|
||||||
#
|
#
|
||||||
# _CellState(): Cell state
|
# _CellState(): Cell state
|
||||||
@ -60,8 +77,72 @@ class MiRCARTFromTextFile():
|
|||||||
else:
|
else:
|
||||||
return cellState | bit
|
return cellState | bit
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _transform(self): XXX
|
|
||||||
def _transform(self):
|
# {{{ exportPastebin(self, apiDevKey): XXX
|
||||||
|
def exportPastebin(self, apiDevKey):
|
||||||
|
if haveUrllib:
|
||||||
|
outFile = io.StringIO(); self.exportTextFile(outFile);
|
||||||
|
requestData = { \
|
||||||
|
"api_dev_key": self.apiDevKey, \
|
||||||
|
"api_option": "paste", \
|
||||||
|
"api_paste_code": base64.b64encode(outFile.read()), \
|
||||||
|
"api_paste_name": pasteName, \
|
||||||
|
"api_paste_private": pastePrivate}
|
||||||
|
responseHttp = requests.post("https://pastebin.com/post.php", \
|
||||||
|
data=requestData)
|
||||||
|
if responseHttp.status_code == 200:
|
||||||
|
return responseHttp.text
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
# }}}
|
||||||
|
# {{{ exportPngFile(self): XXX
|
||||||
|
def exportPngFile(self, pathName):
|
||||||
|
if haveMiRCARTToPngFile:
|
||||||
|
outFile = io.StringIO(); self.exportTextFile(outFile);
|
||||||
|
MiRCARTToPng(outFile).export(pathName)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
# }}}
|
||||||
|
# {{{ exportTextFile(self, outFile): XXX
|
||||||
|
def exportTextFile(self, outFile):
|
||||||
|
canvasMap = self.parentCanvas.canvasMap
|
||||||
|
canvasSize = self.parentCanvas.canvasSize
|
||||||
|
for canvasRow in range(0, canvasSize[1]):
|
||||||
|
canvasLastColours = []
|
||||||
|
for canvasCol in range(0, canvasSize[0]):
|
||||||
|
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
||||||
|
canvasColText = self.canvasMap[canvasRow][canvasCol][2]
|
||||||
|
if canvasColColours != canvasLastColours:
|
||||||
|
canvasLastColours = canvasColColours
|
||||||
|
outFile.write("\x03" + \
|
||||||
|
str(canvasColColours[0]) + \
|
||||||
|
"," + str(canvasColColours[1]))
|
||||||
|
outFile.write(canvasColText)
|
||||||
|
outFile.write("\n")
|
||||||
|
# }}}
|
||||||
|
# {{{ importIntoPanel(self): XXX
|
||||||
|
def importIntoPanel(self):
|
||||||
|
canvasSize = self.inSize; self.parentCanvas.resize(canvasSize);
|
||||||
|
self.parentCanvas.canvasJournal.reset()
|
||||||
|
eventDc = wx.ClientDC(self.parentCanvas); tmpDc = wx.MemoryDC();
|
||||||
|
tmpDc.SelectObject(self.parentCanvas.canvasBitmap)
|
||||||
|
for numRow in range(0, len(self.outMap)):
|
||||||
|
for numCol in range(0, len(self.outMap[numRow])):
|
||||||
|
self.parentCanvas.onJournalUpdate(False, \
|
||||||
|
(numCol, numRow), [numCol, numRow, \
|
||||||
|
self.outMap[numRow][numCol][0][0], \
|
||||||
|
self.outMap[numRow][numCol][0][1], \
|
||||||
|
self.outMap[numRow][numCol][2]], \
|
||||||
|
eventDc, tmpDc, (0, 0))
|
||||||
|
wx.SafeYield()
|
||||||
|
# }}}
|
||||||
|
# {{{ importTextFile(self, pathName): XXX
|
||||||
|
def importTextFile(self, pathName):
|
||||||
|
self.inFile = open(pathName, "r")
|
||||||
|
self.inSize = self.outMap = None;
|
||||||
inCurColourSpec = ""; inCurRow = -1;
|
inCurColourSpec = ""; inCurRow = -1;
|
||||||
inLine = self.inFile.readline()
|
inLine = self.inFile.readline()
|
||||||
inSize = [0, 0]; outMap = []; inMaxCols = 0;
|
inSize = [0, 0]; outMap = []; inMaxCols = 0;
|
||||||
@ -125,23 +206,38 @@ class MiRCARTFromTextFile():
|
|||||||
inMaxCols = max(inMaxCols, inRowCols)
|
inMaxCols = max(inMaxCols, inRowCols)
|
||||||
inLine = self.inFile.readline()
|
inLine = self.inFile.readline()
|
||||||
inSize[0] = inMaxCols; self.inSize = inSize; self.outMap = outMap;
|
inSize[0] = inMaxCols; self.inSize = inSize; self.outMap = outMap;
|
||||||
|
self.inFile.close()
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ getMap(self): XXX
|
# {{{ importNew(self, newCanvasSize=None): XXX
|
||||||
def getMap(self):
|
def importNew(self, newCanvasSize=None):
|
||||||
if self.outMap == None:
|
if newCanvasSize != None:
|
||||||
self._transform()
|
self.parentCanvas.resize(newCanvasSize)
|
||||||
return self.outMap
|
self.parentCanvas.canvasJournal.reset()
|
||||||
# }}}
|
self.parentCanvas.canvasMap = [[[1, 1, " "] \
|
||||||
# {{{ getSize(self): XXX
|
for x in range(self.parentCanvas.canvasSize[0])] \
|
||||||
def getSize(self):
|
for y in range(self.parentCanvas.canvasSize[1])]
|
||||||
if self.inSize == None:
|
canvasWinSize = ( \
|
||||||
self._transform()
|
self.parentCanvas.cellSize[0] * self.parentCanvas.canvasSize[0], \
|
||||||
return self.inSize
|
self.parentCanvas.cellSize[1] * self.parentCanvas.canvasSize[1])
|
||||||
|
if self.parentCanvas.canvasBitmap != None:
|
||||||
|
self.parentCanvas.canvasBitmap.Destroy()
|
||||||
|
self.parentCanvas.canvasBitmap = wx.Bitmap(canvasWinSize)
|
||||||
|
eventDc = wx.ClientDC(self.parentCanvas); tmpDc = wx.MemoryDC();
|
||||||
|
tmpDc.SelectObject(self.parentCanvas.canvasBitmap)
|
||||||
|
for numRow in range(0, len(self.parentCanvas.canvasMap)):
|
||||||
|
for numCol in range(0, len(self.parentCanvas.canvasMap[numRow])):
|
||||||
|
self.parentCanvas.onJournalUpdate(False, \
|
||||||
|
(numCol, numRow), [numCol, numRow, 1, 1, " "], \
|
||||||
|
eventDc, tmpDc, (0, 0))
|
||||||
|
wx.SafeYield()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
# __init__(self): initialisation method
|
# __init__(self, inFile=None, parentCanvas=None): initialisation method
|
||||||
def __init__(self, inFile):
|
def __init__(self, inFile=None, parentCanvas=None):
|
||||||
self.inFile = inFile; self.inSize = None; self.outMap = None;
|
self.inFile = inFile; self.inSize = self.outMap = None;
|
||||||
|
self.parentCanvas = parentCanvas
|
||||||
|
if inFile != None:
|
||||||
|
self.importTextFile(inFile)
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
from MiRCARTCanvas import MiRCARTCanvas
|
from MiRCARTCanvas import MiRCARTCanvas
|
||||||
from MiRCARTColours import MiRCARTColours
|
from MiRCARTColours import MiRCARTColours
|
||||||
from MiRCARTFromTextFile import MiRCARTFromTextFile
|
|
||||||
from MiRCARTToTextFile import MiRCARTToTextFile
|
|
||||||
import os, wx
|
import os, wx
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -194,31 +192,26 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
outPathName = dialog.GetPath()
|
outPathName = dialog.GetPath()
|
||||||
outTmpFile = io.StringIO()
|
self.panelCanvas.exportPngFile(outhPathName)
|
||||||
outToTextFile = MiRCARTToTextFile( \
|
|
||||||
self.panelCanvas.canvasMap, self.canvasSize)
|
|
||||||
outToTextFile.export(outTmpFile)
|
|
||||||
MiRCARTToPngFile(tmpFile).export(outPathName)
|
|
||||||
return True
|
return True
|
||||||
|
except IOError as error:
|
||||||
|
pass
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasExportPastebin(self): XXX
|
# {{{ canvasExportPastebin(self): XXX
|
||||||
def canvasExportPastebin(self):
|
def canvasExportPastebin(self):
|
||||||
MiRCARTToPastebin("253ce2f0a45140ee0a44ca99aa49260", \
|
try:
|
||||||
self.panelCanvas.canvasMap, self.canvasSize).export()
|
self.panelCanvas.exportPastebin("253ce2f0a45140ee0a44ca99aa49260")
|
||||||
|
return True
|
||||||
|
except IOError as error:
|
||||||
|
pass
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasNew(self, canvasPos=None, canvasSize=None, cellSize=None): XXX
|
# {{{ canvasNew(self, newCanvasSize=None): XXX
|
||||||
def canvasNew(self, canvasPos=None, canvasSize=None, cellSize=None):
|
def canvasNew(self, newCanvasSize=None):
|
||||||
canvasPos = canvasPos if canvasPos != None else self.canvasPos
|
if newCanvasSize == None:
|
||||||
canvasSize = canvasSize if canvasSize != None else self.canvasSize
|
newCanvasSize = (100, 30)
|
||||||
cellSize = cellSize if cellSize != None else self.cellSize
|
self.panelCanvas.canvasStore.importNew(newCanvasSize)
|
||||||
if self.panelCanvas != None:
|
|
||||||
self.panelCanvas.Close(); self.panelCanvas = None;
|
|
||||||
self.canvasPos = canvasPos; self.canvasSize = canvasSize;
|
|
||||||
self.cellSize = cellSize
|
|
||||||
self.panelCanvas = MiRCARTCanvas(self.panelSkin, parentFrame=self, \
|
|
||||||
canvasPos=self.canvasPos, cellSize=self.cellSize, \
|
|
||||||
canvasSize=self.canvasSize, canvasTools=self.canvasTools)
|
|
||||||
self._updateStatusBar(); self.onCanvasUpdate();
|
self._updateStatusBar(); self.onCanvasUpdate();
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasOpen(self): XXX
|
# {{{ canvasOpen(self): XXX
|
||||||
@ -229,22 +222,9 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.canvasPathName = dialog.GetPath()
|
self.canvasPathName = dialog.GetPath()
|
||||||
with open(self.canvasPathName, "r") as newFile:
|
self.panelCanvas.canvasStore.importTextFile(self.canvasPathName)
|
||||||
newFromTextFile = MiRCARTFromTextFile(newFile)
|
self.panelCanvas.canvasStore.importIntoPanel()
|
||||||
newMap = newFromTextFile.getMap()
|
self._updateStatusBar(); self.onCanvasUpdate();
|
||||||
self.canvasNew(canvasSize=newFromTextFile.getSize())
|
|
||||||
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
|
|
||||||
tmpDc.SelectObject(self.panelCanvas.canvasBitmap)
|
|
||||||
for newNumRow in range(0, len(newMap)):
|
|
||||||
for newNumCol in range(0, len(newMap[newNumRow])):
|
|
||||||
self.panelCanvas.onJournalUpdate(False, \
|
|
||||||
(newNumCol, newNumRow), \
|
|
||||||
[newNumCol, newNumRow, \
|
|
||||||
newMap[newNumRow][newNumCol][0][0], \
|
|
||||||
newMap[newNumRow][newNumCol][0][1], \
|
|
||||||
newMap[newNumRow][newNumCol][2]], \
|
|
||||||
eventDc, tmpDc, (0, 0))
|
|
||||||
wx.SafeYield()
|
|
||||||
return True
|
return True
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ canvasSave(self): XXX
|
# {{{ canvasSave(self): XXX
|
||||||
@ -253,9 +233,8 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
if self.canvasSaveAs() == False:
|
if self.canvasSaveAs() == False:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with open(self.canvasPathName, "w") as outFile:
|
self.panelCanvas.exportTextFile(self.canvasPathName)
|
||||||
MiRCARTToTextFile(self.panelCanvas.canvasMap, \
|
return True
|
||||||
self.panelCanvas.canvasSize).export(outFile)
|
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
pass
|
pass
|
||||||
# }}}
|
# }}}
|
||||||
@ -345,6 +324,7 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
def __init__(self, parent, appSize=(800, 600), canvasPos=(25, 50), cellSize=(7, 14), canvasSize=(100, 30), canvasTools=[]):
|
def __init__(self, parent, appSize=(800, 600), canvasPos=(25, 50), cellSize=(7, 14), canvasSize=(100, 30), canvasTools=[]):
|
||||||
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
||||||
self.panelSkin = wx.Panel(self, wx.ID_ANY)
|
self.panelSkin = wx.Panel(self, wx.ID_ANY)
|
||||||
|
self.canvasPos = canvasPos; self.cellSize = cellSize; self.canvasSize = canvasSize;
|
||||||
self.canvasPathName = None
|
self.canvasPathName = None
|
||||||
|
|
||||||
self.menuItemsById = {}; self.menuBar = wx.MenuBar();
|
self.menuItemsById = {}; self.menuBar = wx.MenuBar();
|
||||||
@ -370,6 +350,9 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
self.statusBar = self.CreateStatusBar();
|
self.statusBar = self.CreateStatusBar();
|
||||||
self.SetFocus(); self.Show(True);
|
self.SetFocus(); self.Show(True);
|
||||||
self.canvasTools = canvasTools
|
self.canvasTools = canvasTools
|
||||||
self.canvasNew(canvasPos, canvasSize, cellSize)
|
self.panelCanvas = MiRCARTCanvas(self.panelSkin, parentFrame=self, \
|
||||||
|
canvasPos=self.canvasPos, canvasSize=self.canvasSize, \
|
||||||
|
canvasTools=self.canvasTools, cellSize=self.cellSize)
|
||||||
|
self.canvasNew()
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# MiRCARTToPastebin.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.
|
|
||||||
#
|
|
||||||
|
|
||||||
from MiRCARTToTextFile import MiRCARTToTextFile
|
|
||||||
import io
|
|
||||||
import base64
|
|
||||||
import requests, urllib.request
|
|
||||||
|
|
||||||
class MiRCARTToPastebin():
|
|
||||||
apiDevKey = outFile = outToTextFile = None
|
|
||||||
|
|
||||||
# export(self): XXX
|
|
||||||
def export(self):
|
|
||||||
self.outToTextFile.export(self.outFile, pasteName="", pastePrivate=0)
|
|
||||||
requestData = { \
|
|
||||||
"api_dev_key": self.apiDevKey, \
|
|
||||||
"api_option": "paste", \
|
|
||||||
"api_paste_code": base64.b64encode(self.outFile.read()), \
|
|
||||||
"api_paste_name": pasteName, \
|
|
||||||
"api_paste_private": pastePrivate}
|
|
||||||
responseHttp = requests.post("https://pastebin.com/post.php", \
|
|
||||||
data=requestData)
|
|
||||||
if responseHttp.status_code == 200:
|
|
||||||
return responseHttp.text
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# __init__(self, canvasMap, canvasSize): XXX
|
|
||||||
def __init__(self, apiDevKey, canvasMap, canvasSize):
|
|
||||||
self.apiDevKey = apiDevKey
|
|
||||||
self.outFile = io.StringIO()
|
|
||||||
self.outToTextFile = MiRCARTToTextFile(canvasMap, canvasSize)
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
|
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# MiRCARTToTextFile.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.
|
|
||||||
#
|
|
||||||
|
|
||||||
class MiRCARTToTextFile():
|
|
||||||
canvasMap = canvasSize = None
|
|
||||||
|
|
||||||
# export(self, outFile): XXX
|
|
||||||
def export(self, outFile):
|
|
||||||
for canvasRow in range(0, self.canvasSize[1]):
|
|
||||||
canvasLastColours = []
|
|
||||||
for canvasCol in range(0, self.canvasSize[0]):
|
|
||||||
canvasColColours = self.canvasMap[canvasRow][canvasCol][0:2]
|
|
||||||
canvasColText = self.canvasMap[canvasRow][canvasCol][2]
|
|
||||||
if canvasColColours != canvasLastColours:
|
|
||||||
canvasLastColours = canvasColColours
|
|
||||||
outFile.write("\x03" + \
|
|
||||||
str(canvasColColours[0]) + \
|
|
||||||
"," + str(canvasColColours[1]))
|
|
||||||
outFile.write(canvasColText)
|
|
||||||
outFile.write("\n")
|
|
||||||
|
|
||||||
# __init__(self, canvasMap, canvasSize): XXX
|
|
||||||
def __init__(self, canvasMap, canvasSize):
|
|
||||||
self.canvasMap = canvasMap; self.canvasSize = canvasSize;
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
|
Loading…
Reference in New Issue
Block a user