MiRCART.py:mircColours, MiRCARTCanvas.{onPaint,__init__}(): moved from MiRCARTCanvas.mircColours.

MiRCART.py:MiRCARTCanvas.get{Background,Foreground}Colour: added for MiRCARTFrame._updateStatusBar().
MiRCART.py:MiRCARTCanvas.onCharHook(): merged into MiRCARTCanvas.onPaletteEvent().
MiRCART.py:MiRCARTCanvas.onPaletteEvent(): set self.{mirc,brush,pen}{Fg,Bg} from colour choice event.
MiRCART.py:MiRCARTPalette: implements 16 colour palette panels GUI.
MiRCART.py:MiRCARTFrame._updateStatusBar(): show canvas {fore,back}ground colours in status bar.
MiRCART.py:MiRCARTFrame.onPaletteEvent(): hand off to MiRCARTCanvas.onPaletteEvent() and call _updateStatusBar().
MiRCART.py:MiRCARTFrame.__init__(): fix `&File' menu item order.
MiRCART.py:MiRCARTFrame.__init__(): create & update status bar.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-04 17:26:12 +01:00
parent 1a2dd5f692
commit 427290e783

View File

@ -25,13 +25,6 @@
import wx import wx
import sys import sys
class MiRCARTCanvas(wx.Panel):
"""XXX"""
canvasPos = canvasSize = None
canvasMap = None
cellPos = cellSize = None
brushBg = brushFg = penBg = penFg = None
mircBg = mircFg = None
# {{{ 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 = [
(255, 255, 255, 255), # White (255, 255, 255, 255), # White
@ -53,6 +46,14 @@ class MiRCARTCanvas(wx.Panel):
] ]
# }}} # }}}
class MiRCARTCanvas(wx.Panel):
"""XXX"""
canvasPos = canvasSize = None
canvasMap = None
cellPos = cellSize = None
brushBg = brushFg = penBg = penFg = None
mircBg = mircFg = None
# {{{ _onMouseEvent(): XXX # {{{ _onMouseEvent(): XXX
def _onMouseEvent(self, event): def _onMouseEvent(self, event):
eventObject = event.GetEventObject() eventObject = event.GetEventObject()
@ -75,17 +76,18 @@ class MiRCARTCanvas(wx.Panel):
eventDc.DrawRectangle(rectX, rectY, \ eventDc.DrawRectangle(rectX, rectY, \
self.cellSize[0], self.cellSize[1]) self.cellSize[0], self.cellSize[1])
# }}} # }}}
# {{{ getBackgroundColour(): XXX
def getBackgroundColour(self):
return self.mircBg
# }}}
# {{{ getForegroundColour(): XXX
def getForegroundColour(self):
return self.mircFg
# }}}
# {{{ onCharHook(): XXX # {{{ onCharHook(): XXX
def onCharHook(self, event): def onCharHook(self, event):
keyCode = event.GetKeyCode() keyCode = event.GetKeyCode()
if keyCode == wx.WXK_UP: pass
self.mircFg = self.mircFg + 1 if self.mircFg < 15 else 15
elif keyCode == wx.WXK_DOWN:
self.mircFg = self.mircFg - 1 if self.mircFg > 0 else 0
self.brushBg = wx.Brush(wx.Colour(self.mircColours[self.mircBg]), wx.BRUSHSTYLE_SOLID)
self.brushFg = wx.Brush(wx.Colour(self.mircColours[self.mircFg]), wx.BRUSHSTYLE_SOLID)
self.penBg = wx.Pen(wx.Colour(self.mircColours[self.mircBg]), 1)
self.penFg = wx.Pen(wx.Colour(self.mircColours[self.mircFg]), 1)
# }}} # }}}
# {{{ onLeftDown(): XXX # {{{ onLeftDown(): XXX
def onLeftDown(self, event): def onLeftDown(self, event):
@ -102,20 +104,29 @@ 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(self.mircColours[self.canvasMap[cellX][cellY][0]]), wx.BRUSHSTYLE_SOLID)) eventDc.SetBackground(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellX][cellY][0]]), wx.BRUSHSTYLE_SOLID))
eventDc.SetBrush(wx.Brush(wx.Colour(self.mircColours[self.canvasMap[cellX][cellY][1]]), wx.BRUSHSTYLE_SOLID)) eventDc.SetBrush(wx.Brush(wx.Colour(mircColours[self.canvasMap[cellX][cellY][1]]), wx.BRUSHSTYLE_SOLID))
eventDc.SetPen(wx.Pen(wx.Colour(self.mircColours[self.canvasMap[cellX][cellY][1]]), 1)) eventDc.SetPen(wx.Pen(wx.Colour(mircColours[self.canvasMap[cellX][cellY][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])
# }}} # }}}
# {{{ onPaletteEvent(): XXX
def onPaletteEvent(self, leftDown, rightDown, numColour):
if leftDown:
self.mircFg = numColour
self.brushFg = wx.Brush(wx.Colour(mircColours[self.mircFg]), wx.BRUSHSTYLE_SOLID)
self.penFg = wx.Pen(wx.Colour(mircColours[self.mircFg]), 1)
elif rightDown:
self.mircBg = numColour
self.brushBg = wx.Brush(wx.Colour(mircColours[self.mircBg]), wx.BRUSHSTYLE_SOLID)
self.penBg = wx.Pen(wx.Colour(mircColours[self.mircBg]), 1)
# }}}
# {{{ onRightDown(): XXX # {{{ onRightDown(): XXX
def onRightDown(self, event): def onRightDown(self, event):
self._onMouseEvent(event) self._onMouseEvent(event)
# }}} # }}}
# {{{ Initialisation method
#
# Initialisation method
def __init__(self, parent, canvasPos, cellSize, canvasSize): def __init__(self, parent, canvasPos, cellSize, canvasSize):
super().__init__(parent, pos=canvasPos, size=( \ super().__init__(parent, pos=canvasPos, size=( \
cellSize[0] * canvasSize[0], cellSize[0] * canvasSize[0],
@ -124,10 +135,10 @@ class MiRCARTCanvas(wx.Panel):
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 y in range(canvasSize[1])] for x in range(canvasSize[0])]
self.cellPos = (0, 0); self.cellSize = cellSize; self.cellPos = (0, 0); self.cellSize = cellSize;
self.brushBg = wx.Brush(wx.Colour(self.mircColours[1]), wx.BRUSHSTYLE_SOLID) self.brushBg = wx.Brush(wx.Colour(mircColours[1]), wx.BRUSHSTYLE_SOLID)
self.brushFg = wx.Brush(wx.Colour(self.mircColours[4]), wx.BRUSHSTYLE_SOLID) self.brushFg = wx.Brush(wx.Colour(mircColours[4]), wx.BRUSHSTYLE_SOLID)
self.penBg = wx.Pen(wx.Colour(self.mircColours[1]), 1) self.penBg = wx.Pen(wx.Colour(mircColours[1]), 1)
self.penFg = wx.Pen(wx.Colour(self.mircColours[4]), 1) self.penFg = wx.Pen(wx.Colour(mircColours[4]), 1)
self.mircBg = 1; self.mircFg = 4; self.mircBg = 1; self.mircFg = 4;
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
@ -136,12 +147,55 @@ class MiRCARTCanvas(wx.Panel):
self.Bind(wx.EVT_MOTION, self.onMotion) self.Bind(wx.EVT_MOTION, self.onMotion)
self.Bind(wx.EVT_PAINT, self.onPaint) self.Bind(wx.EVT_PAINT, self.onPaint)
self.Bind(wx.EVT_RIGHT_DOWN, self.onRightDown) self.Bind(wx.EVT_RIGHT_DOWN, self.onRightDown)
# }}}
class MiRCARTPalette(wx.Panel):
"""XXX"""
panelsByColour = onPaletteEvent = None
# {{{ onLeftDown(): XXX
def onLeftDown(self, event):
numColour = int(event.GetEventObject().GetName())
self.onPaletteEvent(True, False, numColour)
# }}}
# {{{ onRightDown(): XXX
def onRightDown(self, event):
numColour = int(event.GetEventObject().GetName())
self.onPaletteEvent(False, True, numColour)
# }}}
# {{{ Initialisation method
def __init__(self, parent, parentPos, cellSize, onPaletteEvent):
panelSizeW = 6 * cellSize[0]; panelSizeH = 2 * cellSize[1];
paletteSize = (panelSizeW * 16, panelSizeH)
super().__init__(parent, pos=parentPos, size=paletteSize)
self.panelsByColour = [None] * len(mircColours)
for numColour in range(0, len(mircColours)):
posX = (numColour * (cellSize[0] * 6))
self.panelsByColour[numColour] = wx.Panel(self, \
pos=(posX, 0), size=(panelSizeW, panelSizeH))
self.panelsByColour[numColour].SetBackgroundColour( \
wx.Colour(mircColours[numColour]))
self.panelsByColour[numColour].Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
self.panelsByColour[numColour].Bind(wx.EVT_RIGHT_DOWN, self.onRightDown)
self.panelsByColour[numColour].SetName(str(numColour))
self.onPaletteEvent = onPaletteEvent
# }}}
class MiRCARTFrame(wx.Frame): class MiRCARTFrame(wx.Frame):
"""XXX""" """XXX"""
menuFile = menuFileSaveAs = menuFileExit = menuBar = None menuFile = menuFileSaveAs = menuFileExit = menuBar = None
panelSkin = panelCanvas = None panelSkin = panelCanvas = panelPalette = None
statusBar = None
# {{{ _updateStatusBar(): XXX
def _updateStatusBar(self):
text = "Foreground colour:"
text += " " + str(self.panelCanvas.getForegroundColour())
text += " | "
text += "Background colour:"
text += " " + str(self.panelCanvas.getBackgroundColour())
self.statusBar.SetStatusText(text)
# }}}
# {{{ onFileSaveAs(): XXX # {{{ onFileSaveAs(): XXX
def onFileSaveAs(self, event): def onFileSaveAs(self, event):
pass pass
@ -150,27 +204,35 @@ class MiRCARTFrame(wx.Frame):
def onFileExit(self, event): def onFileExit(self, event):
self.Close(True) self.Close(True)
# }}} # }}}
# {{{ onPaletteEvent(): XXX
# def onPaletteEvent(self, leftDown, rightDown, numColour):
# Initialisation method self.panelCanvas.onPaletteEvent(leftDown, rightDown, numColour)
self._updateStatusBar()
# }}}
# {{{ Initialisation method
def __init__(self, parent, appSize=(1024, 768), canvasPos=(25, 25), cellSize=(7, 14), canvasSize=(80, 25)): def __init__(self, parent, appSize=(1024, 768), canvasPos=(25, 25), cellSize=(7, 14), canvasSize=(80, 25)):
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize) super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
self.menuFile = wx.Menu() self.menuFile = wx.Menu()
self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit")
self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...") self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...")
self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit")
self.menuBar = wx.MenuBar() self.menuBar = wx.MenuBar()
self.menuBar.Append(self.menuFile, "&File") self.menuBar.Append(self.menuFile, "&File")
self.panelSkin = wx.Panel(self, wx.ID_ANY) self.panelSkin = wx.Panel(self, wx.ID_ANY)
self.panelCanvas = MiRCARTCanvas(self.panelSkin, \ self.panelCanvas = MiRCARTCanvas(self.panelSkin, \
canvasPos=canvasPos, cellSize=cellSize, canvasSize=canvasSize) canvasPos=canvasPos, cellSize=cellSize, canvasSize=canvasSize)
self.panelPalette = MiRCARTPalette(self.panelSkin, \
(25, (canvasSize[1] + 3) * cellSize[1]), cellSize, self.onPaletteEvent)
self.statusBar = self.CreateStatusBar()
self._updateStatusBar()
self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit) self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit)
self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs) self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs)
self.CreateStatusBar()
self.SetMenuBar(self.menuBar) self.SetMenuBar(self.menuBar)
self.Show(True) self.Show(True)
# }}}
# #
# Entry point # Entry point