mirror of
https://github.com/lalbornoz/roar.git
synced 2024-12-22 12:26:37 +00:00
libroar/RoarClient.py, libgui/GuiFrame.py: split from libgui/GuiFrame.py.
libroar/RoarCanvasWindow.py, libgui/GuiWindow.py: split from libgui/GuiCanvasPanel.py. roar.py: updated.
This commit is contained in:
parent
116e5915dc
commit
8fd0294ef8
@ -212,7 +212,7 @@ class GuiCanvasInterface():
|
||||
def canvasImportEmpty(pathName):
|
||||
nonlocal newCanvasSize
|
||||
if newCanvasSize == None:
|
||||
newCanvasSize = list(self.parentCanvas.defaultCanvasSize)
|
||||
newCanvasSize = list(self.parentCanvas.canvas.size)
|
||||
newMap = [[[1, 1, 0, " "] for x in range(newCanvasSize[0])] for y in range(newCanvasSize[1])]
|
||||
return (True, "", newMap, None, newCanvasSize)
|
||||
if self._promptSaveChanges():
|
||||
@ -335,7 +335,7 @@ class GuiCanvasInterface():
|
||||
self.update(toolName=self.currentTool.name)
|
||||
viewRect = self.parentCanvas.GetViewStart()
|
||||
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas, viewRect)
|
||||
self.parentCanvas.applyTool(eventDc, wx.wxEVT_MOTION, None, None, self.parentCanvas.brushPos, False, False, False, self.currentTool, viewRect)
|
||||
self.parentCanvas.applyTool(eventDc, True, None, None, self.parentCanvas.brushPos, False, False, False, self.currentTool, viewRect)
|
||||
setattr(canvasTool_, "attrDict", f.attrList[idx])
|
||||
setattr(canvasTool_, "isSelect", True)
|
||||
return canvasTool_
|
||||
|
@ -104,8 +104,8 @@ class GuiCanvasWxBackend():
|
||||
self._lastBrushBg, self._lastBrushFg, self._lastPen = None, None, None
|
||||
return eventDc
|
||||
# }}}
|
||||
# {{{ onPanelPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect)
|
||||
def onPanelPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect):
|
||||
# {{{ onPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect)
|
||||
def onPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect):
|
||||
if self.canvasBitmap != None:
|
||||
if viewRect == (0, 0):
|
||||
eventDc = wx.BufferedPaintDC(panelWindow, self.canvasBitmap)
|
||||
|
@ -4,22 +4,23 @@
|
||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||
#
|
||||
|
||||
from Canvas import Canvas
|
||||
from GuiCanvasColours import Colours
|
||||
from GuiCanvasPanel import GuiCanvasPanel
|
||||
from GuiCanvasWxBackend import GuiCanvasWxBackend
|
||||
|
||||
from glob import glob
|
||||
import os, random, sys, wx
|
||||
import os, sys, wx
|
||||
|
||||
#
|
||||
# Non-items (0xf000-0xffff)
|
||||
NID_MENU_SEP = 0xf000
|
||||
NID_TOOLBAR_HSEP = 0xf001
|
||||
NID_MENU_SEP = 0xf000
|
||||
NID_TOOLBAR_HSEP = 0xf001
|
||||
|
||||
class GuiFrame(wx.Frame):
|
||||
# {{{ _initAccelTable(self, accels)
|
||||
def _initAccelTable(self, accels):
|
||||
# {{{ _initIcon(self, iconPathName)
|
||||
def _initIcon(self, iconPathName):
|
||||
icon = wx.Icon()
|
||||
icon.CopyFromBitmap(wx.Bitmap(iconPathName, wx.BITMAP_TYPE_ANY))
|
||||
self.SetIcon(icon)
|
||||
# }}}
|
||||
|
||||
# {{{ loadAccels(self, accels)
|
||||
def loadAccels(self, accels):
|
||||
accelTableEntries = []
|
||||
for accel in accels:
|
||||
if accel.attrDict["accel"] != None:
|
||||
@ -29,17 +30,25 @@ class GuiFrame(wx.Frame):
|
||||
accelTableEntries[-1].Set(*accel.attrDict["accel"], accel.attrDict["id"])
|
||||
accel.attrDict["accelEntry"] = accelTableEntries[-1]
|
||||
self.itemsById[accel.attrDict["id"]] = accel
|
||||
self.Bind(wx.EVT_MENU, self.onInput, id=accel.attrDict["id"])
|
||||
self.Bind(wx.EVT_MENU, self.onMenu, id=accel.attrDict["id"])
|
||||
self.SetAcceleratorTable(wx.AcceleratorTable(accelTableEntries))
|
||||
# }}}
|
||||
# {{{ _initIcon(self)
|
||||
def _initIcon(self):
|
||||
iconPathNames = glob(os.path.join("assets", "images", "logo*.bmp"))
|
||||
iconPathName = iconPathNames[random.randint(0, len(iconPathNames) - 1)]
|
||||
icon = wx.Icon(); icon.CopyFromBitmap(wx.Bitmap(iconPathName, wx.BITMAP_TYPE_ANY)); self.SetIcon(icon);
|
||||
# {{{ loadBitmap(self, basePathName, descr, size=(16, 16))
|
||||
def loadBitmap(self, basePathName, descr, size=(16, 16)):
|
||||
if descr == None:
|
||||
descr = ["", None, wx.ArtProvider.GetBitmap(wx.ART_HELP, wx.ART_TOOLBAR, size)]
|
||||
elif (descr[0] == "") and (descr[1] != None):
|
||||
descr = ["", None, wx.ArtProvider.GetBitmap(descr[1], wx.ART_TOOLBAR, size)]
|
||||
elif descr[0] != "":
|
||||
bitmap, bitmapPathName = wx.Bitmap((16, 16)), os.path.join(basePathName, descr[0])
|
||||
bitmap.LoadFile(bitmapPathName, wx.BITMAP_TYPE_ANY)
|
||||
descr = ["", None, bitmap]
|
||||
elif len(descr) == 3:
|
||||
descr = ("", None, descr[2])
|
||||
return descr
|
||||
# }}}
|
||||
# {{{ _initMenus(self, menus)
|
||||
def _initMenus(self, menus):
|
||||
# {{{ loadMenus(self, menus)
|
||||
def loadMenus(self, menus):
|
||||
menuBar = wx.MenuBar()
|
||||
for menu in menus:
|
||||
menuWindow = wx.Menu()
|
||||
@ -57,7 +66,7 @@ class GuiFrame(wx.Frame):
|
||||
if menuItem.attrDict["accel"] != None:
|
||||
menuItemWindow.SetAccel(menuItem.attrDict["accelEntry"])
|
||||
self.menuItemsById[menuItem.attrDict["id"]] = menuItemWindow
|
||||
self.Bind(wx.EVT_MENU, self.onInput, menuItemWindow)
|
||||
self.Bind(wx.EVT_MENU, self.onMenu, menuItemWindow)
|
||||
if menuItem.attrDict["initialState"] != None:
|
||||
if hasattr(menuItem, "isSelect"):
|
||||
menuItemWindow.Check(menuItem.attrDict["initialState"])
|
||||
@ -66,14 +75,10 @@ class GuiFrame(wx.Frame):
|
||||
menuBar.Append(menuWindow, menu[0])
|
||||
self.SetMenuBar(menuBar)
|
||||
# }}}
|
||||
# {{{ _initStatusBar(self)
|
||||
def _initStatusBar(self):
|
||||
self.statusBar = self.CreateStatusBar()
|
||||
# }}}
|
||||
# {{{ _initToolBars(self, toolBars, panelSkin)
|
||||
def _initToolBars(self, toolBars, panelSkin):
|
||||
# {{{ loadToolBars(self, toolBars)
|
||||
def loadToolBars(self, toolBars):
|
||||
for toolBar in toolBars:
|
||||
self.toolBars.append(wx.ToolBar(panelSkin, -1, style=wx.TB_FLAT | wx.HORIZONTAL | wx.TB_NODIVIDER))
|
||||
self.toolBars.append(wx.ToolBar(self.panelSkin, -1, style=wx.TB_FLAT | wx.HORIZONTAL | wx.TB_NODIVIDER))
|
||||
self.toolBars[-1].SetToolBitmapSize((16, 16))
|
||||
for toolBarItem in toolBar:
|
||||
if toolBarItem == NID_TOOLBAR_HSEP:
|
||||
@ -87,8 +92,8 @@ class GuiFrame(wx.Frame):
|
||||
else:
|
||||
toolBarItemWindow = self.toolBars[-1].AddTool(toolBarItem.attrDict["id"], toolBarItem.attrDict["caption"], toolBarItem.attrDict["icon"][2], shortHelp=toolBarItem.attrDict["label"])
|
||||
self.toolBarItemsById[toolBarItem.attrDict["id"]] = toolBarItemWindow
|
||||
self.Bind(wx.EVT_TOOL, self.onInput, toolBarItemWindow)
|
||||
self.Bind(wx.EVT_TOOL_RCLICKED, self.onInput, toolBarItemWindow)
|
||||
self.Bind(wx.EVT_TOOL, self.onMenu, toolBarItemWindow)
|
||||
self.Bind(wx.EVT_TOOL_RCLICKED, self.onMenu, toolBarItemWindow)
|
||||
if toolBarItem.attrDict["initialState"] != None:
|
||||
if hasattr(toolBarItem, "isSelect"):
|
||||
toolBarItemWindow.Toggle(toolBarItem.attrDict["initialState"])
|
||||
@ -98,77 +103,34 @@ class GuiFrame(wx.Frame):
|
||||
self.sizerSkin.Add(toolBar, 0, wx.ALIGN_LEFT | wx.ALL, 3)
|
||||
toolBar.Realize(); toolBar.Fit();
|
||||
# }}}
|
||||
# {{{ _initToolBitmaps(self, toolBars)
|
||||
def _initToolBitmaps(self, toolBars):
|
||||
for toolBar in toolBars:
|
||||
for toolBarItem in toolBar:
|
||||
if toolBarItem == NID_TOOLBAR_HSEP:
|
||||
continue
|
||||
elif toolBarItem.attrDict["icon"] == None:
|
||||
toolBarItem.attrDict["icon"] = ["", None, wx.ArtProvider.GetBitmap(wx.ART_HELP, wx.ART_TOOLBAR, (16, 16))]
|
||||
elif (toolBarItem.attrDict["icon"][0] == "") \
|
||||
and (toolBarItem.attrDict["icon"][1] != None):
|
||||
toolBarItem.attrDict["icon"] = ["", None, wx.ArtProvider.GetBitmap(toolBarItem.attrDict["icon"][1], wx.ART_TOOLBAR, (16, 16))]
|
||||
elif (toolBarItem.attrDict["icon"][0] == "") \
|
||||
and (toolBarItem.attrDict["icon"][1] == None):
|
||||
toolBarItem.attrDict["icon"] = ["", None, toolBarItem.attrDict["icon"][2]]
|
||||
elif toolBarItem.attrDict["icon"][0] != "":
|
||||
toolBitmapPathName = os.path.dirname(sys.argv[0])
|
||||
toolBitmapPathName = os.path.join(toolBitmapPathName, "assets", "images", toolBarItem.attrDict["icon"][0])
|
||||
toolBitmap = wx.Bitmap((16, 16))
|
||||
toolBitmap.LoadFile(toolBitmapPathName, wx.BITMAP_TYPE_ANY)
|
||||
toolBarItem.attrDict["icon"] = ["", None, toolBitmap]
|
||||
# {{{ addWindow(self, window, border=14, expand=False)
|
||||
def addWindow(self, window, border=14, expand=False):
|
||||
flags = wx.ALL; flags = flags | wx.EXPAND if expand else flags;
|
||||
self.sizerSkin.Add(window, 0, flags, border); self.sizerSkin.Fit(self.panelSkin);
|
||||
# }}}
|
||||
|
||||
# {{{ onChar(self, event)
|
||||
def onChar(self, event):
|
||||
self.canvasPanel.onPanelInput(event)
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onInput(self, event)
|
||||
def onInput(self, event):
|
||||
eventId = event.GetId(); self.itemsById[eventId](self.canvasPanel.interface, event);
|
||||
# {{{ onMenu(self, event)
|
||||
def onMenu(self, event):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onMouseWheel(self, event)
|
||||
def onMouseWheel(self, event):
|
||||
self.canvasPanel.GetEventHandler().ProcessEvent(event)
|
||||
event.Skip()
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, canvasInterface, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): initialisation method
|
||||
def __init__(self, canvasInterface, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):
|
||||
super().__init__(parent, wx.ID_ANY, "", size=appSize)
|
||||
self.itemsById, self.menuItemsById, self.toolBarItemsById = {}, {}, {}; self.lastId = 0;
|
||||
# __init__(self, iconPathName, size, parent=None, title=""): initialisation method
|
||||
def __init__(self, iconPathName, size, parent=None, title=""):
|
||||
super().__init__(parent, wx.ID_ANY, title, size=size)
|
||||
self.itemsById, self.lastId, self.menuItemsById, self.toolBarItemsById = {}, 0, {}, {}
|
||||
self.panelSkin, self.sizerSkin, self.toolBars = wx.Panel(self, wx.ID_ANY), wx.BoxSizer(wx.VERTICAL), []
|
||||
|
||||
self.canvas, self.canvasPanel = Canvas(defaultCanvasSize), None
|
||||
self.canvasPanel = GuiCanvasPanel(self.panelSkin, self, GuiCanvasWxBackend, self.canvas, defaultCanvasPos, defaultCanvasSize, defaultCellSize, canvasInterface)
|
||||
|
||||
# Initialise accelerators (hotkeys)
|
||||
# Initialise icon
|
||||
# Initialise menu bar, menus & menu items
|
||||
# Initialise status bar
|
||||
# Initialise toolbar & toolbar items
|
||||
self._initAccelTable(self.canvasPanel.interface.accels)
|
||||
self._initIcon()
|
||||
self._initMenus(self.canvasPanel.interface.menus)
|
||||
self._initStatusBar()
|
||||
self._initToolBitmaps(self.canvasPanel.interface.toolBars)
|
||||
self._initToolBars(self.canvasPanel.interface.toolBars, self.panelSkin)
|
||||
|
||||
self.sizerSkin.AddSpacer(5)
|
||||
self.sizerSkin.Add(self.canvasPanel, 0, wx.ALL | wx.EXPAND, 14)
|
||||
self.panelSkin.SetSizer(self.sizerSkin)
|
||||
self.panelSkin.SetAutoLayout(1)
|
||||
self.sizerSkin.Fit(self.panelSkin)
|
||||
|
||||
self.canvasPanel.interface.canvasNew(None)
|
||||
self.canvasPanel.interface.canvasTool(self.canvasPanel.interface.canvasTool, 5)(self.canvasPanel.interface, None)
|
||||
self.canvasPanel.interface.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours)
|
||||
|
||||
self.Bind(wx.EVT_CHAR, self.onChar)
|
||||
self.Bind(wx.EVT_MOUSEWHEEL, self.onMouseWheel)
|
||||
|
||||
# Set focus on & show window
|
||||
self.SetFocus(); self.Show(True);
|
||||
self.sizerSkin.AddSpacer(5); self.panelSkin.SetSizer(self.sizerSkin); self.panelSkin.SetAutoLayout(1);
|
||||
self._initIcon(iconPathName); self.statusBar = self.CreateStatusBar();
|
||||
self.sizerSkin.Fit(self.panelSkin); self.SetFocus(); self.Show(True);
|
||||
for event, f in ((wx.EVT_CHAR, self.onChar), (wx.EVT_MENU, self.onMenu), (wx.EVT_MOUSEWHEEL, self.onMouseWheel)):
|
||||
self.Bind(event, f)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
70
libgui/GuiWindow.py
Normal file
70
libgui/GuiWindow.py
Normal file
@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# GuiWindow.py
|
||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||
#
|
||||
|
||||
import wx
|
||||
|
||||
class GuiWindow(wx.ScrolledWindow):
|
||||
# {{{ _updateScrollBars(self)
|
||||
def _updateScrollBars(self):
|
||||
clientSize = self.GetClientSize()
|
||||
if (self.size[0] > clientSize[0]) or (self.size[1] > clientSize[1]):
|
||||
self.scrollFlag = True; super().SetVirtualSize(self.size);
|
||||
elif self.scrollFlag \
|
||||
and ((self.size[0] <= clientSize[0]) or (self.size[1] <= clientSize[1])):
|
||||
self.scrollFlag = False; super().SetVirtualSize((0, 0));
|
||||
# }}}
|
||||
|
||||
# {{{ onClose(self, event)
|
||||
def onClose(self, event):
|
||||
self.Destroy()
|
||||
# }}}
|
||||
# {{{ onKeyboardInput(self, event)
|
||||
def onKeyboardInput(self, event):
|
||||
return False
|
||||
# }}}
|
||||
# {{{ onLeaveWindow(self, event)
|
||||
def onLeaveWindow(self, event):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onMouseInput(self, event)
|
||||
def onMouseInput(self, event):
|
||||
return False
|
||||
# }}}
|
||||
# {{{ onPaint(self, event)
|
||||
def onPaint(self, event):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onScroll(self, event)
|
||||
def onScroll(self, event):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onSize(self, event)
|
||||
def onSize(self, event):
|
||||
self._updateScrollBars(); event.Skip();
|
||||
# }}}
|
||||
# {{{ resize(self, newSize)
|
||||
def resize(self, newSize):
|
||||
self.size = newSize; self._updateScrollBars();
|
||||
self.SetMinSize(self.size); self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *self.size);
|
||||
curWindow = self
|
||||
while curWindow != None:
|
||||
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, parent, pos, scrollStep, size): initialisation method
|
||||
def __init__(self, parent, pos, scrollStep, size):
|
||||
super().__init__(parent, pos=pos, size=size)
|
||||
self.pos, self.scrollFlag, self.scrollStep, self.size = pos, False, scrollStep, size
|
||||
for eventType, f in (
|
||||
(wx.EVT_CHAR, self.onKeyboardInput), (wx.EVT_CLOSE, self.onClose), (wx.EVT_LEAVE_WINDOW, self.onLeaveWindow),
|
||||
(wx.EVT_LEFT_DOWN, self.onMouseInput), (wx.EVT_MOTION, self.onMouseInput), (wx.EVT_PAINT, self.onPaint),
|
||||
(wx.EVT_RIGHT_DOWN, self.onMouseInput), (wx.EVT_SCROLLWIN_LINEDOWN, self.onScroll), (wx.EVT_SCROLLWIN_LINEUP, self.onScroll),
|
||||
(wx.EVT_SIZE, self.onSize)):
|
||||
self.Bind(eventType, f)
|
||||
self.SetScrollRate(*self.scrollStep); self._updateScrollBars();
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# GuiCanvasPanel.py
|
||||
# RoarCanvasWindow.py
|
||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||
#
|
||||
|
||||
import wx
|
||||
from GuiWindow import GuiWindow
|
||||
|
||||
class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
class RoarCanvasWindow(GuiWindow):
|
||||
# {{{ _drawPatch(self, eventDc, isCursor, patch, viewRect)
|
||||
def _drawPatch(self, eventDc, isCursor, patch, viewRect):
|
||||
if not self.canvas.dirtyCursor:
|
||||
@ -16,35 +16,24 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
||||
self.canvas.journal.pushCursor(patchDelta)
|
||||
# }}}
|
||||
# {{{ _updateScrollBars(self)
|
||||
def _updateScrollBars(self):
|
||||
clientSize = self.GetClientSize()
|
||||
if (self.winSize[0] > clientSize[0]) \
|
||||
or (self.winSize[1] > clientSize[1]):
|
||||
self.scrollFlag = True; super().SetVirtualSize(self.winSize);
|
||||
elif self.scrollFlag \
|
||||
and ((self.winSize[0] <= clientSize[0]) \
|
||||
or (self.winSize[1] <= clientSize[1])):
|
||||
self.scrollFlag = False; super().SetVirtualSize((0, 0));
|
||||
# }}}
|
||||
|
||||
# {{{ applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect)
|
||||
def applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect):
|
||||
# {{{ applyTool(self, eventDc, eventMouse, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect)
|
||||
def applyTool(self, eventDc, eventMouse, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect):
|
||||
dirty, self.canvas.dirtyCursor, rc = False, False, False
|
||||
self.canvas.journal.begin()
|
||||
if eventType == wx.wxEVT_CHAR:
|
||||
rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
||||
else:
|
||||
if eventMouse:
|
||||
if (mapPoint[0] < self.canvas.size[0]) \
|
||||
and (mapPoint[1] < self.canvas.size[1]):
|
||||
self.brushPos = mapPoint
|
||||
rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
else:
|
||||
rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
||||
if dirty:
|
||||
self.dirty = True
|
||||
self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||
else:
|
||||
self.interface.update(cellPos=mapPoint if mapPoint else self.brushPos)
|
||||
self.canvas.journal.end()
|
||||
if eventType == wx.wxEVT_MOTION:
|
||||
self.interface.update(cellPos=mapPoint)
|
||||
return rc
|
||||
# }}}
|
||||
# {{{ dispatchDeltaPatches(self, deltaPatches)
|
||||
@ -73,11 +62,7 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
|
||||
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
||||
if self.canvas.resize(newSize, commitUndo):
|
||||
self.winSize = [a * b for a, b in zip(newSize, self.backend.cellSize)]; self._updateScrollBars();
|
||||
self.SetMinSize(self.winSize); self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *self.winSize);
|
||||
curWindow = self
|
||||
while curWindow != None:
|
||||
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||
super().resize([a * b for a, b in zip(newSize, self.backend.cellSize)])
|
||||
self.backend.resize(newSize, self.backend.cellSize)
|
||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self, viewRect);
|
||||
if deltaSize[0] > 0:
|
||||
@ -100,39 +85,32 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
self.backend.drawPatch(eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]], self.GetViewStart())
|
||||
# }}}
|
||||
|
||||
# {{{ onPanelClose(self, event)
|
||||
def onPanelClose(self, event):
|
||||
self.Destroy()
|
||||
# }}}
|
||||
# {{{ onPanelInput(self, event)
|
||||
def onPanelInput(self, event):
|
||||
eventType, viewRect = event.GetEventType(), self.GetViewStart()
|
||||
eventDc = self.backend.getDeviceContext(self, viewRect)
|
||||
if eventType == wx.wxEVT_CHAR:
|
||||
keyChar, keyModifiers = chr(event.GetUnicodeKey()), event.GetModifiers()
|
||||
mapPoint, mouseDragging, mouseLeftDown, mouseRightDown = None, None, None, None
|
||||
else:
|
||||
keyChar, keyModifiers = None, None
|
||||
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
|
||||
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
||||
if not self.applyTool(eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.interface.currentTool, self.GetViewStart()):
|
||||
# {{{ onKeyboardInput(self, event)
|
||||
def onKeyboardInput(self, event):
|
||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self, viewRect);
|
||||
keyChar, keyModifiers = chr(event.GetUnicodeKey()), event.GetModifiers()
|
||||
if not self.applyTool(eventDc, False, keyChar, keyModifiers, None, None, None, None, self.interface.currentTool, viewRect):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onPanelLeaveWindow(self, event)
|
||||
def onPanelLeaveWindow(self, event):
|
||||
# {{{ onLeaveWindow(self, event)
|
||||
def onLeaveWindow(self, event):
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart())
|
||||
# }}}
|
||||
# {{{ onPanelPaint(self, event)
|
||||
def onPanelPaint(self, event):
|
||||
self.backend.onPanelPaintEvent(self.canvas.size, self.defaultCellSize, self.GetClientSize(), self, self.GetViewStart())
|
||||
# {{{ onMouseInput(self, event)
|
||||
def onMouseInput(self, event):
|
||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self, viewRect);
|
||||
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
|
||||
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
||||
if not self.applyTool(eventDc, True, None, None, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.interface.currentTool, viewRect):
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onPanelSize(self, event)
|
||||
def onPanelSize(self, event):
|
||||
self._updateScrollBars(); event.Skip();
|
||||
# {{{ onPaint(self, event)
|
||||
def onPaint(self, event):
|
||||
self.backend.onPaintEvent(self.canvas.size, self.cellSize, self.GetClientSize(), self, self.GetViewStart())
|
||||
# }}}
|
||||
# {{{ onPanelScroll(self, event)
|
||||
def onPanelScroll(self, event):
|
||||
# {{{ onScroll(self, event)
|
||||
def onScroll(self, event):
|
||||
if self.canvas.dirtyCursor:
|
||||
viewRect = self.GetViewStart()
|
||||
eventDc = self.backend.getDeviceContext(self, viewRect)
|
||||
@ -142,24 +120,10 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, parent, parentFrame, backend, canvas, defaultCanvasPos, defaultCanvasSize, defaultCellSize, interface): initialisation method
|
||||
def __init__(self, parent, parentFrame, backend, canvas, defaultCanvasPos, defaultCanvasSize, defaultCellSize, interface):
|
||||
self.winSize = [w * h for w, h in zip(defaultCanvasSize, defaultCellSize)]
|
||||
super().__init__(parent, pos=defaultCanvasPos, size=self.winSize)
|
||||
self.backend, self.interface = backend(defaultCanvasSize, defaultCellSize), interface(self, parentFrame)
|
||||
self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1]
|
||||
self.canvas, self.canvasPos, self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = canvas, defaultCanvasPos, defaultCanvasPos, defaultCanvasSize, defaultCellSize
|
||||
self.dirty, self.parentFrame, self.scrollFlag = False, parentFrame, False
|
||||
self.SetScrollRate(*defaultCellSize); self._updateScrollBars();
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.onPanelClose)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelLeaveWindow)
|
||||
self.Bind(wx.EVT_CHAR, self.onPanelInput)
|
||||
for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN):
|
||||
self.Bind(eventType, self.onPanelInput)
|
||||
self.Bind(wx.EVT_PAINT, self.onPanelPaint)
|
||||
self.Bind(wx.EVT_SCROLLWIN_LINEDOWN, self.onPanelScroll)
|
||||
self.Bind(wx.EVT_SCROLLWIN_LINEUP, self.onPanelScroll)
|
||||
self.Bind(wx.EVT_SIZE, self.onPanelSize)
|
||||
# __init__(self, backend, canvas, cellSize, interface, parent, parentFrame, pos, scrollStep, size): initialisation method
|
||||
def __init__(self, backend, canvas, cellSize, interface, parent, parentFrame, pos, scrollStep, size):
|
||||
super().__init__(parent, pos, scrollStep, [w * h for w, h in zip(cellSize, size)])
|
||||
self.backend, self.canvas, self.cellSize, self.interface, self.parentFrame = backend(self.size, cellSize), canvas, cellSize, interface(self, parentFrame), parentFrame
|
||||
self.brushColours, self.brushPos, self.brushSize, self.dirty = [4, 1], [0, 0], [1, 1], False
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
59
libroar/RoarClient.py
Normal file
59
libroar/RoarClient.py
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# RoarClient.py
|
||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||
#
|
||||
|
||||
from Canvas import Canvas
|
||||
from GuiCanvasInterface import GuiCanvasInterface
|
||||
from GuiCanvasWxBackend import GuiCanvasWxBackend
|
||||
from GuiFrame import GuiFrame, NID_TOOLBAR_HSEP
|
||||
from RoarCanvasWindow import RoarCanvasWindow
|
||||
|
||||
from glob import glob
|
||||
import os, random, sys
|
||||
|
||||
class RoarClient(GuiFrame):
|
||||
# {{{ _getIconPathName(self)
|
||||
def _getIconPathName(self):
|
||||
iconPathNames = glob(os.path.join("assets", "images", "logo*.bmp"))
|
||||
return iconPathNames[random.randint(0, len(iconPathNames) - 1)]
|
||||
# }}}
|
||||
# {{{ _initToolBitmaps(self, toolBars)
|
||||
def _initToolBitmaps(self, toolBars):
|
||||
basePathName = os.path.join(os.path.dirname(sys.argv[0]), "assets", "images")
|
||||
for toolBar in toolBars:
|
||||
for toolBarItem in [i for i in toolBar if i != NID_TOOLBAR_HSEP]:
|
||||
toolBarItem.attrDict["icon"] = self.loadBitmap(basePathName, toolBarItem.attrDict["icon"])
|
||||
# }}}
|
||||
|
||||
# {{{ onChar(self, event)
|
||||
def onChar(self, event):
|
||||
self.canvasPanel.onKeyboardInput(event)
|
||||
# }}}
|
||||
# {{{ onMenu(self, event)
|
||||
def onMenu(self, event):
|
||||
eventId = event.GetId(); self.itemsById[eventId](self.canvasPanel.interface, event);
|
||||
# }}}
|
||||
# {{{ onMouseWheel(self, event)
|
||||
def onMouseWheel(self, event):
|
||||
self.canvasPanel.GetEventHandler().ProcessEvent(event)
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, parent, defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14), size=(840, 630), title=""): initialisation method
|
||||
def __init__(self, parent, defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14), size=(840, 630), title=""):
|
||||
super().__init__(self._getIconPathName(), size, parent, title)
|
||||
self.canvas = Canvas(defaultCanvasSize)
|
||||
self.canvasPanel = RoarCanvasWindow(GuiCanvasWxBackend, self.canvas, defaultCellSize, GuiCanvasInterface, self.panelSkin, self, defaultCanvasPos, defaultCellSize, defaultCanvasSize)
|
||||
self.loadAccels(self.canvasPanel.interface.accels)
|
||||
self.loadMenus(self.canvasPanel.interface.menus)
|
||||
self._initToolBitmaps(self.canvasPanel.interface.toolBars)
|
||||
self.loadToolBars(self.canvasPanel.interface.toolBars)
|
||||
|
||||
self.canvasPanel.interface.canvasNew(None)
|
||||
self.canvasPanel.interface.canvasTool(self.canvasPanel.interface.canvasTool, 5)(self.canvasPanel.interface, None)
|
||||
self.canvasPanel.interface.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours)
|
||||
self.addWindow(self.canvasPanel, expand=True)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
18
roar.py
18
roar.py
@ -6,23 +6,21 @@
|
||||
|
||||
import os, sys
|
||||
[sys.path.append(os.path.join(os.getcwd(), path)) for path in \
|
||||
["libcanvas", "libgui", "librtl", "libtools"]]
|
||||
["libcanvas", "libgui", "libroar", "librtl", "libtools"]]
|
||||
|
||||
from GuiCanvasInterface import GuiCanvasInterface
|
||||
from GuiFrame import GuiFrame
|
||||
from RoarClient import RoarClient
|
||||
import wx
|
||||
|
||||
#
|
||||
# Entry point
|
||||
def main(*argv):
|
||||
wxApp, appFrame = wx.App(False), GuiFrame(GuiCanvasInterface, None)
|
||||
if len(argv) > 1 \
|
||||
and len(argv[1]) > 0:
|
||||
appFrame.canvasPanel.interface.canvasPathName = argv[1]
|
||||
rc, error = appFrame.canvasPanel.canvas.importStore.importTextFile(argv[1])
|
||||
wxApp, roarClient = wx.App(False), RoarClient(None)
|
||||
if (len(argv) > 1) and (len(argv[1]) > 0):
|
||||
roarClient.canvasPanel.interface.canvasPathName = argv[1]
|
||||
rc, error = roarClient.canvasPanel.canvas.importStore.importTextFile(argv[1])
|
||||
if rc:
|
||||
appFrame.canvasPanel.update(appFrame.canvasPanel.canvas.importStore.inSize, False, appFrame.canvasPanel.canvas.importStore.outMap)
|
||||
appFrame.canvasPanel.interface.update(pathName=argv[1], undoLevel=-1)
|
||||
roarClient.canvasPanel.update(roarClient.canvasPanel.canvas.importStore.inSize, False, roarClient.canvasPanel.canvas.importStore.outMap)
|
||||
roarClient.canvasPanel.interface.update(pathName=argv[1], undoLevel=-1)
|
||||
else:
|
||||
print("error: {}".format(error), file=sys.stderr)
|
||||
wxApp.MainLoop()
|
||||
|
Loading…
Reference in New Issue
Block a user