mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 15:26:37 +00:00
MiRCART.py:MiRCARTCanvas.{_onMouseEvent,onPaint,__init__}(): switch addressing mode of self.canvasMap to [Y][X].
MiRCART.py:MiRCARTCanvas.get{Height,Map,Width}(): added for MiRCARTFrame.onFileSaveAs(). MiRCART.py:MiRCARTFrame.onFileSaveAs(): initial implementation.
This commit is contained in:
parent
427290e783
commit
42e18ec252
51
MiRCART.py
51
MiRCART.py
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import sys
|
import os, sys
|
||||||
|
|
||||||
# {{{ mircColours: mIRC colour number to RGBA map given none of ^[BFV_] (bold, italic, reverse, underline)
|
# {{{ mircColours: mIRC colour number to RGBA map given none of ^[BFV_] (bold, italic, reverse, underline)
|
||||||
mircColours = [
|
mircColours = [
|
||||||
@ -68,11 +68,11 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
if event.LeftIsDown():
|
if event.LeftIsDown():
|
||||||
eventDc.SetBrush(self.brushFg);
|
eventDc.SetBrush(self.brushFg);
|
||||||
eventDc.SetPen(self.penFg)
|
eventDc.SetPen(self.penFg)
|
||||||
self.canvasMap[mapX][mapY] = [self.mircFg, self.mircFg, " "]
|
self.canvasMap[mapY][mapX] = [self.mircFg, self.mircFg, " "]
|
||||||
elif event.RightIsDown():
|
elif event.RightIsDown():
|
||||||
eventDc.SetBrush(self.brushBg);
|
eventDc.SetBrush(self.brushBg);
|
||||||
eventDc.SetPen(self.penBg)
|
eventDc.SetPen(self.penBg)
|
||||||
self.canvasMap[mapX][mapY] = [self.mircBg, self.mircBg, " "]
|
self.canvasMap[mapY][mapX] = [self.mircBg, self.mircBg, " "]
|
||||||
eventDc.DrawRectangle(rectX, rectY, \
|
eventDc.DrawRectangle(rectX, rectY, \
|
||||||
self.cellSize[0], self.cellSize[1])
|
self.cellSize[0], self.cellSize[1])
|
||||||
# }}}
|
# }}}
|
||||||
@ -84,6 +84,18 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
def getForegroundColour(self):
|
def getForegroundColour(self):
|
||||||
return self.mircFg
|
return self.mircFg
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ getHeight(): XXX
|
||||||
|
def getHeight(self):
|
||||||
|
return self.canvasSize[1]
|
||||||
|
# }}}
|
||||||
|
# {{{ getMap(): XXX
|
||||||
|
def getMap(self):
|
||||||
|
return self.canvasMap
|
||||||
|
# }}}
|
||||||
|
# {{{ getWidth(): XXX
|
||||||
|
def getWidth(self):
|
||||||
|
return self.canvasSize[0]
|
||||||
|
# }}}
|
||||||
# {{{ onCharHook(): XXX
|
# {{{ onCharHook(): XXX
|
||||||
def onCharHook(self, event):
|
def onCharHook(self, event):
|
||||||
keyCode = event.GetKeyCode()
|
keyCode = event.GetKeyCode()
|
||||||
@ -104,9 +116,9 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
eventDc.Clear()
|
eventDc.Clear()
|
||||||
for cellX in range(0, self.canvasSize[0]):
|
for cellX in range(0, self.canvasSize[0]):
|
||||||
for cellY in range(0, self.canvasSize[1]):
|
for cellY in range(0, self.canvasSize[1]):
|
||||||
eventDc.SetBackground(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellX][cellY][0]]), wx.BRUSHSTYLE_SOLID))
|
eventDc.SetBackground(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellY][cellX][0]]), wx.BRUSHSTYLE_SOLID))
|
||||||
eventDc.SetBrush(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellX][cellY][1]]), wx.BRUSHSTYLE_SOLID))
|
eventDc.SetBrush(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellY][cellX][1]]), wx.BRUSHSTYLE_SOLID))
|
||||||
eventDc.SetPen(wx.Pen(wx.Colour(mircColours[self.canvasMap[cellX][cellY][1]]), 1))
|
eventDc.SetPen(wx.Pen(wx.Colour(mircColours[self.canvasMap[cellY][cellX][1]]), 1))
|
||||||
rectX = cellX * self.cellSize[0]; rectY = cellY * self.cellSize[1];
|
rectX = cellX * self.cellSize[0]; rectY = cellY * self.cellSize[1];
|
||||||
eventDc.DrawRectangle(rectX, rectY, \
|
eventDc.DrawRectangle(rectX, rectY, \
|
||||||
self.cellSize[0], self.cellSize[1])
|
self.cellSize[0], self.cellSize[1])
|
||||||
@ -133,7 +145,7 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
cellSize[1] * canvasSize[1]))
|
cellSize[1] * canvasSize[1]))
|
||||||
|
|
||||||
self.canvasPos = canvasPos; self.canvasSize = canvasSize;
|
self.canvasPos = canvasPos; self.canvasSize = canvasSize;
|
||||||
self.canvasMap = [[[1, 1, " "] for y in range(canvasSize[1])] for x in range(canvasSize[0])]
|
self.canvasMap = [[[1, 1, " "] for x in range(canvasSize[0])] for y in range(canvasSize[1])]
|
||||||
self.cellPos = (0, 0); self.cellSize = cellSize;
|
self.cellPos = (0, 0); self.cellSize = cellSize;
|
||||||
self.brushBg = wx.Brush(wx.Colour(mircColours[1]), wx.BRUSHSTYLE_SOLID)
|
self.brushBg = wx.Brush(wx.Colour(mircColours[1]), wx.BRUSHSTYLE_SOLID)
|
||||||
self.brushFg = wx.Brush(wx.Colour(mircColours[4]), wx.BRUSHSTYLE_SOLID)
|
self.brushFg = wx.Brush(wx.Colour(mircColours[4]), wx.BRUSHSTYLE_SOLID)
|
||||||
@ -198,7 +210,30 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
# }}}
|
# }}}
|
||||||
# {{{ onFileSaveAs(): XXX
|
# {{{ onFileSaveAs(): XXX
|
||||||
def onFileSaveAs(self, event):
|
def onFileSaveAs(self, event):
|
||||||
pass
|
with wx.FileDialog(self, "Save As...", os.getcwd(), "", \
|
||||||
|
"*.txt", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
||||||
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
with open(dialog.GetPath(), "w") as file:
|
||||||
|
canvasMap = self.panelCanvas.getMap()
|
||||||
|
canvasHeight = self.panelCanvas.getHeight()
|
||||||
|
canvasWidth = self.panelCanvas.getWidth()
|
||||||
|
for canvasRow in range(0, canvasHeight):
|
||||||
|
colourLastBg = colourLastFg = None;
|
||||||
|
for canvasCol in range(0, canvasWidth):
|
||||||
|
canvasColBg = canvasMap[canvasRow][canvasCol][0]
|
||||||
|
canvasColFg = canvasMap[canvasRow][canvasCol][1]
|
||||||
|
canvasColText = canvasMap[canvasRow][canvasCol][2]
|
||||||
|
if colourLastBg != canvasColBg \
|
||||||
|
or colourLastFg != canvasColFg:
|
||||||
|
colourLastBg = canvasColBg; colourLastFg = canvasColFg;
|
||||||
|
file.write("" + str(canvasColFg) + "," + str(canvasColBg))
|
||||||
|
file.write(canvasColText)
|
||||||
|
file.write("\n")
|
||||||
|
except IOError as error:
|
||||||
|
wx.LogError("IOError {}".format(error))
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onFileExit(): XXX
|
# {{{ onFileExit(): XXX
|
||||||
def onFileExit(self, event):
|
def onFileExit(self, event):
|
||||||
|
Loading…
Reference in New Issue
Block a user