mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 07:16:38 +00:00
libgui/GuiFrame.py:{_init,load}Menu(): split from loadMenu(), implement nested (sub)menus.
libroar/RoarCanvasCommandsEdit.py: put {brush,canvas} size commands into submenu. libroar/RoarCanvasCommandsFile.py: put {ex,im}port commands into submenu. assets/text/TODO: updated.
This commit is contained in:
parent
7226639977
commit
245925406e
@ -15,8 +15,9 @@ High-priority list:
|
||||
4) GUI:
|
||||
a) switch to GTK
|
||||
b) replace logo w/ canvas panel in About dialogue
|
||||
c) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
|
||||
d) {copy,cut,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
|
||||
c) Settings/Settings window (e.g. autosave, hide cursor on leaving window, ...)
|
||||
d) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
|
||||
e) {copy,cut,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
|
||||
5) cleanup & refactor
|
||||
6) object tool: reset {clone,move} state on each transition to target state
|
||||
|
||||
|
@ -63,12 +63,43 @@ class GuiFrame(wx.Frame):
|
||||
icon.CopyFromBitmap(wx.Bitmap(iconPathName, wx.BITMAP_TYPE_ANY))
|
||||
self.SetIcon(icon)
|
||||
# }}}
|
||||
# {{{ _initMenu(self, menuItem, menuWindow)
|
||||
def _initMenu(self, menuItem, menuWindow):
|
||||
if menuItem == NID_MENU_SEP:
|
||||
menuWindow.AppendSeparator()
|
||||
else:
|
||||
if menuItem.attrDict["id"] == None:
|
||||
menuItem.attrDict["id"] = wx.NewId()
|
||||
self.itemsById[menuItem.attrDict["id"]] = menuItem
|
||||
if hasattr(menuItem, "isSelect"):
|
||||
menuItemWindow = menuWindow.AppendRadioItem(menuItem.attrDict["id"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
elif hasattr(menuItem, "isSubMenu"):
|
||||
menuItem.attrDict["menu"] = wx.Menu()
|
||||
menuItemWindow = menuWindow.AppendSubMenu(menuItem.attrDict["menu"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
else:
|
||||
menuItemWindow = menuWindow.Append(menuItem.attrDict["id"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
if menuItem.attrDict["accel"] != None:
|
||||
menuItemWindow.SetAccel(menuItem.attrDict["accelEntry"])
|
||||
self.menuItemsById[menuItem.attrDict["id"]] = menuItemWindow
|
||||
self.Bind(wx.EVT_MENU, self.onMenu, menuItemWindow)
|
||||
if menuItem.attrDict["initialState"] != None:
|
||||
if hasattr(menuItem, "isSelect"):
|
||||
menuItemWindow.Check(menuItem.attrDict["initialState"])
|
||||
else:
|
||||
menuItemWindow.Enable(menuItem.attrDict["initialState"])
|
||||
# }}}
|
||||
|
||||
# {{{ loadAccels(self, menus, toolBars)
|
||||
def loadAccels(self, menus, toolBars):
|
||||
def loadAccels_(accels):
|
||||
nonlocal accelTableEntries
|
||||
accels_ = []
|
||||
for accel in accels:
|
||||
if type(accel) == tuple:
|
||||
accels_ += accel[1:]
|
||||
else:
|
||||
accels_ += [accel]
|
||||
for accel in accels_:
|
||||
if (not accel in [NID_MENU_SEP, NID_TOOLBAR_HSEP]) \
|
||||
and (accel.attrDict["accel"] != None):
|
||||
accelTableEntries += [wx.AcceleratorEntry()]
|
||||
@ -102,28 +133,13 @@ class GuiFrame(wx.Frame):
|
||||
for menu in menus:
|
||||
menuWindow = wx.Menu()
|
||||
for menuItem in menu[1:]:
|
||||
if menuItem == NID_MENU_SEP:
|
||||
menuWindow.AppendSeparator()
|
||||
if type(menuItem) == tuple:
|
||||
menuSubWindow = wx.Menu()
|
||||
for menuSubItem in menuItem[1:]:
|
||||
self._initMenu(menuSubItem, menuSubWindow)
|
||||
menuWindow.AppendSubMenu(menuSubWindow, menuItem[0], menuItem[0])
|
||||
else:
|
||||
if menuItem.attrDict["id"] == None:
|
||||
menuItem.attrDict["id"] = wx.NewId()
|
||||
self.itemsById[menuItem.attrDict["id"]] = menuItem
|
||||
if hasattr(menuItem, "isSelect"):
|
||||
menuItemWindow = menuWindow.AppendRadioItem(menuItem.attrDict["id"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
elif hasattr(menuItem, "isSubMenu"):
|
||||
menuItem.attrDict["menu"] = wx.Menu()
|
||||
menuItemWindow = menuWindow.AppendSubMenu(menuItem.attrDict["menu"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
else:
|
||||
menuItemWindow = menuWindow.Append(menuItem.attrDict["id"], menuItem.attrDict["label"], menuItem.attrDict["caption"])
|
||||
if menuItem.attrDict["accel"] != None:
|
||||
menuItemWindow.SetAccel(menuItem.attrDict["accelEntry"])
|
||||
self.menuItemsById[menuItem.attrDict["id"]] = menuItemWindow
|
||||
self.Bind(wx.EVT_MENU, self.onMenu, menuItemWindow)
|
||||
if menuItem.attrDict["initialState"] != None:
|
||||
if hasattr(menuItem, "isSelect"):
|
||||
menuItemWindow.Check(menuItem.attrDict["initialState"])
|
||||
else:
|
||||
menuItemWindow.Enable(menuItem.attrDict["initialState"])
|
||||
self._initMenu(menuItem, menuWindow)
|
||||
menuBar.Append(menuWindow, menu[0])
|
||||
self.SetMenuBar(menuBar)
|
||||
# }}}
|
||||
|
@ -160,10 +160,11 @@ class RoarCanvasCommandsEdit():
|
||||
self.canvasUndo, self.canvasRedo, NID_MENU_SEP,
|
||||
self.canvasCut, self.canvasCopy, self.canvasPaste,
|
||||
self.canvasDelete, NID_MENU_SEP,
|
||||
self.canvasCanvasSize(self.canvasCanvasSize, 1, True), self.canvasCanvasSize(self.canvasCanvasSize, 1, False), self.canvasCanvasSize(self.canvasCanvasSize, 0, True), self.canvasCanvasSize(self.canvasCanvasSize, 0, False), NID_MENU_SEP,
|
||||
self.canvasCanvasSize(self.canvasCanvasSize, 2, True), self.canvasCanvasSize(self.canvasCanvasSize, 2, False), NID_MENU_SEP,
|
||||
self.canvasBrushSize(self.canvasBrushSize, 0, True), self.canvasBrushSize(self.canvasBrushSize, 0, False), self.canvasBrushSize(self.canvasBrushSize, 1, True), self.canvasBrushSize(self.canvasBrushSize, 1, False), NID_MENU_SEP,
|
||||
self.canvasBrushSize(self.canvasBrushSize, 2, True), self.canvasBrushSize(self.canvasBrushSize, 2, False), NID_MENU_SEP,
|
||||
("Canvas size", self.canvasCanvasSize(self.canvasCanvasSize, 1, True), self.canvasCanvasSize(self.canvasCanvasSize, 1, False), self.canvasCanvasSize(self.canvasCanvasSize, 0, True), self.canvasCanvasSize(self.canvasCanvasSize, 0, False), NID_MENU_SEP,
|
||||
self.canvasCanvasSize(self.canvasCanvasSize, 2, True), self.canvasCanvasSize(self.canvasCanvasSize, 2, False),),
|
||||
("Brush size", self.canvasBrushSize(self.canvasBrushSize, 0, True), self.canvasBrushSize(self.canvasBrushSize, 0, False), self.canvasBrushSize(self.canvasBrushSize, 1, True), self.canvasBrushSize(self.canvasBrushSize, 1, False), NID_MENU_SEP,
|
||||
self.canvasBrushSize(self.canvasBrushSize, 2, True), self.canvasBrushSize(self.canvasBrushSize, 2, False),),
|
||||
NID_MENU_SEP,
|
||||
self.canvasBrush(self.canvasBrush, 0), NID_MENU_SEP,
|
||||
self.canvasAssetsWindowHide, self.canvasAssetsWindowShow,
|
||||
),
|
||||
|
@ -103,8 +103,9 @@ class RoarCanvasCommandsFile():
|
||||
if self._promptSaveChanges():
|
||||
self.parentFrame.Close(True)
|
||||
# }}}
|
||||
|
||||
# {{{ canvasExportAsAnsi(self, event)
|
||||
@GuiCommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None)
|
||||
@GuiCommandDecorator("Export as ANSI...", "Export as &ANSI...", None, None, None)
|
||||
def canvasExportAsAnsi(self, event):
|
||||
with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
||||
if self.lastDir != None:
|
||||
@ -163,7 +164,7 @@ class RoarCanvasCommandsFile():
|
||||
wx.MessageBox("Failed to export to Pastebin: " + pasteResult, "Export to Pastebin", wx.OK|wx.ICON_EXCLAMATION)
|
||||
# }}}
|
||||
# {{{ canvasExportToClipboard(self, event)
|
||||
@GuiCommandDecorator("Export to clipboard", "&Export to clipboard", None, None, None)
|
||||
@GuiCommandDecorator("Export to clipboard", "Export to &clipboard", None, None, None)
|
||||
def canvasExportToClipboard(self, event):
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
rc, outBuffer = self.parentCanvas.canvas.exportStore.exportTextBuffer(self.parentCanvas.canvas.map, self.parentCanvas.canvas.size)
|
||||
@ -173,8 +174,9 @@ class RoarCanvasCommandsFile():
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
return True
|
||||
# }}}
|
||||
|
||||
# {{{ canvasImportAnsi(self, event)
|
||||
@GuiCommandDecorator("Import ANSI...", "Import ANSI...", None, None, None)
|
||||
@GuiCommandDecorator("Import ANSI...", "Import &ANSI...", None, None, None)
|
||||
def canvasImportAnsi(self, event):
|
||||
def canvasImportAnsi_(pathName):
|
||||
rc, error = self.parentCanvas.canvas.importStore.importAnsiFile(pathName)
|
||||
@ -182,7 +184,7 @@ class RoarCanvasCommandsFile():
|
||||
self._importFile(canvasImportAnsi_, True, "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*")
|
||||
# }}}
|
||||
# {{{ canvasImportFromClipboard(self, event)
|
||||
@GuiCommandDecorator("Import from clipboard", "&Import from clipboard", None, None, None)
|
||||
@GuiCommandDecorator("Import from clipboard", "Import from &clipboard", None, None, None)
|
||||
def canvasImportFromClipboard(self, event):
|
||||
def canvasImportFromClipboard_(pathName):
|
||||
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) \
|
||||
@ -199,13 +201,14 @@ class RoarCanvasCommandsFile():
|
||||
self._import(canvasImportFromClipboard_, True, None)
|
||||
# }}}
|
||||
# {{{ canvasImportSauce(self, event)
|
||||
@GuiCommandDecorator("Import SAUCE...", "Import SAUCE...", None, None, None)
|
||||
@GuiCommandDecorator("Import SAUCE...", "Import &SAUCE...", None, None, None)
|
||||
def canvasImportSauce(self, event):
|
||||
def canvasImportSauce_(pathName):
|
||||
rc, error = self.parentCanvas.canvas.importStore.importSauceFile(pathName)
|
||||
return (rc, error, self.parentCanvas.canvas.importStore.outMap, pathName, self.parentCanvas.canvas.importStore.inSize)
|
||||
self._importFile(canvasImportSauce_, True, "SAUCE files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*")
|
||||
# }}}
|
||||
|
||||
# {{{ canvasNew(self, event, newCanvasSize=None)
|
||||
@GuiCommandDecorator("New", "&New", ["", wx.ART_NEW], [wx.ACCEL_CTRL, ord("N")], None)
|
||||
def canvasNew(self, event, newCanvasSize=None):
|
||||
@ -275,8 +278,9 @@ class RoarCanvasCommandsFile():
|
||||
self.menus = (
|
||||
("&File",
|
||||
self.canvasNew, self.canvasOpen, self.canvasOpenRecent, self.canvasSave, self.canvasSaveAs, NID_MENU_SEP,
|
||||
self.canvasExportAsAnsi, self.canvasExportToClipboard, self.canvasExportImgur, self.canvasExportPastebin, self.canvasExportAsPng, NID_MENU_SEP,
|
||||
self.canvasImportAnsi, self.canvasImportFromClipboard, self.canvasImportSauce, NID_MENU_SEP,
|
||||
("&Export...", self.canvasExportAsAnsi, self.canvasExportToClipboard, self.canvasExportImgur, self.canvasExportPastebin, self.canvasExportAsPng,),
|
||||
("&Import...", self.canvasImportAnsi, self.canvasImportFromClipboard, self.canvasImportSauce,),
|
||||
NID_MENU_SEP,
|
||||
self.canvasExit,
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user