mirror of
https://github.com/lalbornoz/roar.git
synced 2024-12-23 12:56:37 +00:00
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:
parent
5fd20d31b1
commit
4ce163d906
@ -146,9 +146,14 @@ class MiRCARTCanvas(wx.Panel):
|
||||
for numNewCol in range(newCanvasSize[0]):
|
||||
self.canvasMap[numNewRow].append([[1, 1], 0, " "])
|
||||
self.canvasSize = newCanvasSize
|
||||
self.SetSize(*self.canvasPos, \
|
||||
*[a*b for a,b in zip(self.canvasSize, \
|
||||
self.canvasBackend.cellSize)])
|
||||
newWinSize = [a*b for a,b in \
|
||||
zip(self.canvasSize, 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.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
|
||||
self.parentFrame.onCanvasUpdate( \
|
||||
|
@ -119,18 +119,18 @@ class MiRCARTCanvasInterface():
|
||||
return False
|
||||
else:
|
||||
outPathName = dialog.GetPath()
|
||||
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
self.parentCanvas.canvasExportStore.exportBitmapToPngFile( \
|
||||
self.parentCanvas.canvasBackend.canvasBitmap, outPathName, \
|
||||
wx.BITMAP_TYPE_PNG)
|
||||
self.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
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))
|
||||
imgurResult = self.parentCanvas.canvasExportStore.exportBitmapToImgur( \
|
||||
"c9a6efb3d7932fd", self.parentCanvas.canvasBackend.canvasBitmap, \
|
||||
"c9a6efb3d7932fd", self.parentCanvas.canvasBackend.canvasBitmap, \
|
||||
"", "", wx.BITMAP_TYPE_PNG)
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
if imgurResult[0] == 200:
|
||||
@ -138,21 +138,21 @@ class MiRCARTCanvasInterface():
|
||||
wx.TheClipboard.Open()
|
||||
wx.TheClipboard.SetData(wx.TextDataObject(imgurResult[1]))
|
||||
wx.TheClipboard.Close()
|
||||
wx.MessageBox("Exported to Imgur: " + imgurResult[1], \
|
||||
wx.MessageBox("Exported to Imgur: " + imgurResult[1], \
|
||||
"Export to Imgur", wx.OK|wx.ICON_INFORMATION)
|
||||
else:
|
||||
wx.MessageBox("Failed to export to Imgur: " + imgurResult[1], \
|
||||
wx.MessageBox("Failed to export to Imgur: " + imgurResult[1], \
|
||||
"Export to Imgur", wx.OK|wx.ICON_EXCLAMATION)
|
||||
# }}}
|
||||
# {{{ canvasExportPastebin(self, event): XXX
|
||||
def canvasExportPastebin(self, event):
|
||||
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
pasteStatus, pasteResult = \
|
||||
self.parentCanvas.canvasExportStore.exportPastebin( \
|
||||
self.parentCanvas.canvasExportStore.exportPastebin( \
|
||||
"253ce2f0a45140ee0a44ca99aa49260", \
|
||||
self.parentCanvas.canvasMap, \
|
||||
self.parentCanvas.canvasMap, \
|
||||
self.parentCanvas.canvasSize)
|
||||
self.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
if pasteStatus:
|
||||
if not wx.TheClipboard.IsOpened():
|
||||
wx.TheClipboard.Open()
|
||||
@ -240,11 +240,11 @@ class MiRCARTCanvasInterface():
|
||||
return
|
||||
try:
|
||||
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.canvasMap, \
|
||||
self.parentCanvas.canvasSize, outFile)
|
||||
self.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
return True
|
||||
except IOError as error:
|
||||
return False
|
||||
|
@ -27,7 +27,7 @@ from MiRCARTCanvasInterface import MiRCARTCanvasInterface
|
||||
from MiRCARTColours import MiRCARTColours
|
||||
from MiRCARTGeneralFrame import MiRCARTGeneralFrame, \
|
||||
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
|
||||
|
||||
@ -107,11 +107,12 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
|
||||
# }}}
|
||||
# {{{ Toolbars
|
||||
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
|
||||
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_SEP, \
|
||||
CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \
|
||||
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \
|
||||
CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \
|
||||
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, NID_TOOLBAR_SEP, \
|
||||
CID_NEW, CID_OPEN, CID_SAVE, CID_SAVEAS, NID_TOOLBAR_HSEP, \
|
||||
CID_UNDO, CID_REDO, NID_TOOLBAR_HSEP, \
|
||||
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_HSEP, \
|
||||
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_VSEP, \
|
||||
CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \
|
||||
CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \
|
||||
CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \
|
||||
@ -193,27 +194,36 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
|
||||
if "undoLevel" in self.lastPanelState:
|
||||
if self.lastPanelState["undoLevel"] >= 0:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
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
|
||||
def __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(25, 50), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):
|
||||
# __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=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):
|
||||
self._initPaletteToolBitmaps()
|
||||
panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
||||
self.panelCanvas = MiRCARTCanvas(panelSkin, parentFrame=self, \
|
||||
defaultCanvasPos=defaultCanvasPos, \
|
||||
defaultCanvasSize=defaultCanvasSize, \
|
||||
self.panelSkin = super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
||||
self.panelCanvas = MiRCARTCanvas(self.panelSkin, parentFrame=self, \
|
||||
defaultCanvasPos=defaultCanvasPos, \
|
||||
defaultCanvasSize=defaultCanvasSize, \
|
||||
defaultCellSize=defaultCellSize)
|
||||
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
|
||||
|
@ -37,12 +37,14 @@ TID_TOOLBAR = (0x007)
|
||||
#
|
||||
# Non-items
|
||||
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):
|
||||
"""XXX"""
|
||||
itemsById = menuItemsById = toolBarItemsById = None
|
||||
statusBar = toolBar = None
|
||||
statusBar = toolBars = None
|
||||
panelSkin = sizerSkin = None
|
||||
|
||||
# {{{ _initAccelTable(self, accelsDescr): XXX
|
||||
def _initAccelTable(self, accelsDescr):
|
||||
@ -83,28 +85,41 @@ class MiRCARTGeneralFrame(wx.Frame):
|
||||
# {{{ _initToolBars(self, toolBarsDescr, panelSkin): XXX
|
||||
def _initToolBars(self, toolBarsDescr, panelSkin):
|
||||
self.toolBarItemsById = {}
|
||||
self.toolBar = wx.ToolBar(panelSkin, -1, \
|
||||
style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER)
|
||||
self.toolBar.SetToolBitmapSize((16,16))
|
||||
self.sizerSkin = wx.BoxSizer(wx.VERTICAL)
|
||||
self.toolBars = [None]; numToolBar = 0;
|
||||
for toolBarItem in toolBarsDescr[2]:
|
||||
if toolBarItem == NID_TOOLBAR_SEP:
|
||||
self.toolBar.AddSeparator()
|
||||
if self.toolBars[numToolBar] == None:
|
||||
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:
|
||||
self.itemsById[toolBarItem[0]] = toolBarItem
|
||||
toolBarItemWindow = self.toolBar.AddTool( \
|
||||
toolBarItem[0], toolBarItem[2], toolBarItem[4][2])
|
||||
toolBarItemWindow = \
|
||||
self.toolBars[numToolBar].AddTool( \
|
||||
toolBarItem[0], toolBarItem[2], \
|
||||
toolBarItem[4][2])
|
||||
self.toolBarItemsById[toolBarItem[0]] = toolBarItemWindow
|
||||
if toolBarItem[6] != None \
|
||||
and toolBarItem[1] == TID_COMMAND:
|
||||
toolBarItemWindow.Enable(toolBarItem[6])
|
||||
self.Bind(wx.EVT_TOOL, 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
|
||||
def _initToolBitmaps(self, toolBarsDescr):
|
||||
for toolBarItem in toolBarsDescr[2]:
|
||||
if toolBarItem == NID_TOOLBAR_SEP:
|
||||
if toolBarItem == NID_TOOLBAR_HSEP \
|
||||
or toolBarItem == NID_TOOLBAR_VSEP:
|
||||
continue
|
||||
elif toolBarItem[4] == None:
|
||||
toolBarItem[4] = ["", None, wx.ArtProvider.GetBitmap( \
|
||||
|
Loading…
Reference in New Issue
Block a user