MiRCARTCanvas.py:MiRCARTCanvas.resize(): call SetSize() w/o changing position.

MiRCARTCanvas.py:MiRCARTCanvas.resize(): call SetMinSize() in addition to SetSize().
MiRCARTCanvas.py:MiRCARTCanvas.resize(): call Layout() on canvas panel window and its parents.
MiRCARTCanvasInterface.py: always call SetCursor() w/ self.parentCanvas.
MiRCARTFrame.py: moves colour toolbar items to separate toolbar.
MiRCARTFrame.py:MiRCARTFrame.__init__(): add canvas panel to and initialise sizer.
MiRCARTGeneralFrame.py: adds support for multiple toolbars via vertical box sizer.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-10 21:28:15 +01:00
parent 5fd20d31b1
commit 4ce163d906
4 changed files with 71 additions and 41 deletions

View File

@ -146,9 +146,14 @@ class MiRCARTCanvas(wx.Panel):
for numNewCol in range(newCanvasSize[0]): for numNewCol in range(newCanvasSize[0]):
self.canvasMap[numNewRow].append([[1, 1], 0, " "]) self.canvasMap[numNewRow].append([[1, 1], 0, " "])
self.canvasSize = newCanvasSize self.canvasSize = newCanvasSize
self.SetSize(*self.canvasPos, \ newWinSize = [a*b for a,b in \
*[a*b for a,b in zip(self.canvasSize, \ zip(self.canvasSize, self.canvasBackend.cellSize)]
self.canvasBackend.cellSize)]) self.SetMinSize(newWinSize)
self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *newWinSize)
curWindow = self
while curWindow != None:
curWindow.Layout()
curWindow = curWindow.GetParent()
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize) self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo(); self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
self.parentFrame.onCanvasUpdate( \ self.parentFrame.onCanvasUpdate( \

View File

@ -119,11 +119,11 @@ class MiRCARTCanvasInterface():
return False return False
else: else:
outPathName = dialog.GetPath() outPathName = dialog.GetPath()
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
self.parentCanvas.canvasExportStore.exportBitmapToPngFile( \ self.parentCanvas.canvasExportStore.exportBitmapToPngFile( \
self.parentCanvas.canvasBackend.canvasBitmap, outPathName, \ self.parentCanvas.canvasBackend.canvasBitmap, outPathName, \
wx.BITMAP_TYPE_PNG) wx.BITMAP_TYPE_PNG)
self.SetCursor(wx.Cursor(wx.NullCursor)) self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
return True return True
# }}} # }}}
# {{{ canvasExportImgur(self, event): XXX # {{{ canvasExportImgur(self, event): XXX
@ -146,13 +146,13 @@ class MiRCARTCanvasInterface():
# }}} # }}}
# {{{ canvasExportPastebin(self, event): XXX # {{{ canvasExportPastebin(self, event): XXX
def canvasExportPastebin(self, event): def canvasExportPastebin(self, event):
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
pasteStatus, pasteResult = \ pasteStatus, pasteResult = \
self.parentCanvas.canvasExportStore.exportPastebin( \ self.parentCanvas.canvasExportStore.exportPastebin( \
"253ce2f0a45140ee0a44ca99aa49260", \ "253ce2f0a45140ee0a44ca99aa49260", \
self.parentCanvas.canvasMap, \ self.parentCanvas.canvasMap, \
self.parentCanvas.canvasSize) self.parentCanvas.canvasSize)
self.SetCursor(wx.Cursor(wx.NullCursor)) self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
if pasteStatus: if pasteStatus:
if not wx.TheClipboard.IsOpened(): if not wx.TheClipboard.IsOpened():
wx.TheClipboard.Open() wx.TheClipboard.Open()
@ -240,11 +240,11 @@ class MiRCARTCanvasInterface():
return return
try: try:
with open(self.canvasPathName, "w") as outFile: with open(self.canvasPathName, "w") as outFile:
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
self.parentCanvas.canvasExportStore.exportTextFile( \ self.parentCanvas.canvasExportStore.exportTextFile( \
self.parentCanvas.canvasMap, \ self.parentCanvas.canvasMap, \
self.parentCanvas.canvasSize, outFile) self.parentCanvas.canvasSize, outFile)
self.SetCursor(wx.Cursor(wx.NullCursor)) self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
return True return True
except IOError as error: except IOError as error:
return False return False

View File

@ -27,7 +27,7 @@ from MiRCARTCanvasInterface import MiRCARTCanvasInterface
from MiRCARTColours import MiRCARTColours from MiRCARTColours import MiRCARTColours
from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \ from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \
TID_ACCELS, TID_COMMAND, TID_LIST, TID_MENU, TID_NOTHING, TID_SELECT, TID_TOOLBAR, \ TID_ACCELS, TID_COMMAND, TID_LIST, TID_MENU, TID_NOTHING, TID_SELECT, TID_TOOLBAR, \
NID_MENU_SEP, NID_TOOLBAR_SEP NID_MENU_SEP, NID_TOOLBAR_HSEP, NID_TOOLBAR_VSEP
import os, wx import os, wx
@ -107,11 +107,12 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
# }}} # }}}
# {{{ Toolbars # {{{ Toolbars
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \ BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_SEP, \ CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_HSEP, \
CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \ CID_UNDO, CID_REDO, NID_TOOLBAR_HSEP, \
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_HSEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \ CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_HSEP, \
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, NID_TOOLBAR_SEP, \ CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, \
NID_TOOLBAR_VSEP, \
CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \ CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \
CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \ CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \
CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \ CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \
@ -193,27 +194,36 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
if "undoLevel" in self.lastPanelState: if "undoLevel" in self.lastPanelState:
if self.lastPanelState["undoLevel"] >= 0: if self.lastPanelState["undoLevel"] >= 0:
self.menuItemsById[self.CID_UNDO[0]].Enable(True) self.menuItemsById[self.CID_UNDO[0]].Enable(True)
self.toolBar.EnableTool(self.CID_UNDO[0], True) toolBar = self.toolBarItemsById[self.CID_UNDO[0]].GetToolBar()
toolBar.EnableTool(self.CID_UNDO[0], True)
else: else:
self.menuItemsById[self.CID_UNDO[0]].Enable(False) self.menuItemsById[self.CID_UNDO[0]].Enable(False)
self.toolBar.EnableTool(self.CID_UNDO[0], False) toolBar = self.toolBarItemsById[self.CID_UNDO[0]].GetToolBar()
toolBar.EnableTool(self.CID_UNDO[0], False)
if self.lastPanelState["undoLevel"] > 0: if self.lastPanelState["undoLevel"] > 0:
self.menuItemsById[self.CID_REDO[0]].Enable(True) self.menuItemsById[self.CID_REDO[0]].Enable(True)
self.toolBar.EnableTool(self.CID_REDO[0], True) toolBar = self.toolBarItemsById[self.CID_REDO[0]].GetToolBar()
toolBar.EnableTool(self.CID_REDO[0], True)
else: else:
self.menuItemsById[self.CID_REDO[0]].Enable(False) self.menuItemsById[self.CID_REDO[0]].Enable(False)
self.toolBar.EnableTool(self.CID_REDO[0], False) toolBar = self.toolBarItemsById[self.CID_REDO[0]].GetToolBar()
toolBar.EnableTool(self.CID_REDO[0], False)
# }}} # }}}
# #
# __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(25, 50), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): initialisation method # __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): initialisation method
def __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(25, 50), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): def __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):
self._initPaletteToolBitmaps() self._initPaletteToolBitmaps()
panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize) self.panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
self.panelCanvas = MiRCARTCanvas(panelSkin, parentFrame=self, \ self.panelCanvas = MiRCARTCanvas(self.panelSkin, parentFrame=self, \
defaultCanvasPos=defaultCanvasPos, \ defaultCanvasPos=defaultCanvasPos, \
defaultCanvasSize=defaultCanvasSize, \ defaultCanvasSize=defaultCanvasSize, \
defaultCellSize=defaultCellSize) defaultCellSize=defaultCellSize)
self.panelCanvas.canvasInterface.canvasNew(None) self.panelCanvas.canvasInterface.canvasNew(None)
self.sizerSkin.AddSpacer(5)
self.sizerSkin.Add(self.panelCanvas, wx.ALL|wx.EXPAND)
self.panelSkin.SetSizer(self.sizerSkin)
self.panelSkin.SetAutoLayout(1)
self.sizerSkin.Fit(self.panelSkin)
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -37,12 +37,14 @@ TID_TOOLBAR = (0x007)
# #
# Non-items # Non-items
NID_MENU_SEP = (0x200, TID_NOTHING) NID_MENU_SEP = (0x200, TID_NOTHING)
NID_TOOLBAR_SEP = (0x201, TID_NOTHING) NID_TOOLBAR_HSEP = (0x201, TID_NOTHING)
NID_TOOLBAR_VSEP = (0x202, TID_NOTHING)
class MiRCARTGeneralFrame(wx.Frame): class MiRCARTGeneralFrame(wx.Frame):
"""XXX""" """XXX"""
itemsById = menuItemsById = toolBarItemsById = None itemsById = menuItemsById = toolBarItemsById = None
statusBar = toolBar = None statusBar = toolBars = None
panelSkin = sizerSkin = None
# {{{ _initAccelTable(self, accelsDescr): XXX # {{{ _initAccelTable(self, accelsDescr): XXX
def _initAccelTable(self, accelsDescr): def _initAccelTable(self, accelsDescr):
@ -83,28 +85,41 @@ class MiRCARTGeneralFrame(wx.Frame):
# {{{ _initToolBars(self, toolBarsDescr, panelSkin): XXX # {{{ _initToolBars(self, toolBarsDescr, panelSkin): XXX
def _initToolBars(self, toolBarsDescr, panelSkin): def _initToolBars(self, toolBarsDescr, panelSkin):
self.toolBarItemsById = {} self.toolBarItemsById = {}
self.toolBar = wx.ToolBar(panelSkin, -1, \ self.sizerSkin = wx.BoxSizer(wx.VERTICAL)
style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER) self.toolBars = [None]; numToolBar = 0;
self.toolBar.SetToolBitmapSize((16,16))
for toolBarItem in toolBarsDescr[2]: for toolBarItem in toolBarsDescr[2]:
if toolBarItem == NID_TOOLBAR_SEP: if self.toolBars[numToolBar] == None:
self.toolBar.AddSeparator() self.toolBars[numToolBar] = \
wx.ToolBar(panelSkin, -1, \
style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER)
self.toolBars[numToolBar].SetToolBitmapSize((16,16))
if toolBarItem == NID_TOOLBAR_HSEP:
self.toolBars[numToolBar].AddSeparator()
elif toolBarItem == NID_TOOLBAR_VSEP:
numToolBar += 1; self.toolBars.append(None);
else: else:
self.itemsById[toolBarItem[0]] = toolBarItem self.itemsById[toolBarItem[0]] = toolBarItem
toolBarItemWindow = self.toolBar.AddTool( \ toolBarItemWindow = \
toolBarItem[0], toolBarItem[2], toolBarItem[4][2]) self.toolBars[numToolBar].AddTool( \
toolBarItem[0], toolBarItem[2], \
toolBarItem[4][2])
self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow
if toolBarItem[6] != None \ if toolBarItem[6] != None \
and toolBarItem[1] == TID_COMMAND: and toolBarItem[1] == TID_COMMAND:
toolBarItemWindow.Enable(toolBarItem[6]) toolBarItemWindow.Enable(toolBarItem[6])
self.Bind(wx.EVT_TOOL, self.onInput, toolBarItemWindow) self.Bind(wx.EVT_TOOL, self.onInput, toolBarItemWindow)
self.Bind(wx.EVT_TOOL_RCLICKED, self.onInput, toolBarItemWindow) self.Bind(wx.EVT_TOOL_RCLICKED, self.onInput, toolBarItemWindow)
self.toolBar.Realize(); self.toolBar.Fit(); for numToolBar in range(len(self.toolBars)):
self.sizerSkin.Add( \
self.toolBars[numToolBar], 0, wx.ALIGN_LEFT, 4)
self.toolBars[numToolBar].Realize()
self.toolBars[numToolBar].Fit()
# }}} # }}}
# {{{ _initToolBitmaps(self, toolBarsDescr): XXX # {{{ _initToolBitmaps(self, toolBarsDescr): XXX
def _initToolBitmaps(self, toolBarsDescr): def _initToolBitmaps(self, toolBarsDescr):
for toolBarItem in toolBarsDescr[2]: for toolBarItem in toolBarsDescr[2]:
if toolBarItem == NID_TOOLBAR_SEP: if toolBarItem == NID_TOOLBAR_HSEP \
or toolBarItem == NID_TOOLBAR_VSEP:
continue continue
elif toolBarItem[4] == None: elif toolBarItem[4] == None:
toolBarItem[4] = ["", None, wx.ArtProvider.GetBitmap( \ toolBarItem[4] = ["", None, wx.ArtProvider.GetBitmap( \