From 9c6b7fa9b29befa5a0f41eb8541ebec8f4831623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 15 Sep 2019 13:52:44 +0200 Subject: [PATCH] Implements object tool operators context menu. libgui/GuiFrame.py: _FUCK_ _YOU_ WXPYTHON libroar/RoarCanvasCommandsOperators.py: I _FUCKING_ _HATE_ WXPYTHON libroar/RoarCanvasWindow.py: DIE IN A DITCH WXPYTHON YOU ROTTING PILE OF FUCKING HIPPOPOTAMUS SHIT libroar/RoarClient.py: I HATE WXPYTHON I HATE WXPYTHON I HATE WXPYTHON I HATE WXPYTHON I HATE WXPYTHON --- libgui/GuiFrame.py | 6 +++--- libroar/RoarCanvasCommandsOperators.py | 10 ++++++++-- libroar/RoarCanvasWindow.py | 7 ++++++- libroar/RoarClient.py | 8 +++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libgui/GuiFrame.py b/libgui/GuiFrame.py index 4ddec1a..d5793ce 100644 --- a/libgui/GuiFrame.py +++ b/libgui/GuiFrame.py @@ -129,7 +129,7 @@ class GuiFrame(wx.Frame): # }}} # {{{ loadMenus(self, menus) def loadMenus(self, menus): - menuBar = wx.MenuBar() + self.menuBar = wx.MenuBar() for menu in menus: menuWindow = wx.Menu() for menuItem in menu[1:]: @@ -140,8 +140,8 @@ class GuiFrame(wx.Frame): menuWindow.AppendSubMenu(menuSubWindow, menuItem[0], menuItem[0]) else: self._initMenu(menuItem, menuWindow) - menuBar.Append(menuWindow, menu[0]) - self.SetMenuBar(menuBar) + self.menuBar.Append(menuWindow, menu[0]) + self.SetMenuBar(self.menuBar) # }}} # {{{ loadToolBars(self, toolBars) def loadToolBars(self, toolBars): diff --git a/libroar/RoarCanvasCommandsOperators.py b/libroar/RoarCanvasCommandsOperators.py index 153554d..9618279 100644 --- a/libroar/RoarCanvasCommandsOperators.py +++ b/libroar/RoarCanvasCommandsOperators.py @@ -26,12 +26,18 @@ class RoarCanvasCommandsOperators(): if (self.currentTool.__class__ == ToolObject) \ and (self.currentTool.toolState >= self.currentTool.TS_SELECT): viewRect = self.parentCanvas.GetViewStart() - eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + if self.parentCanvas.popupEventDc == None: + eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + else: + eventDc = self.parentCanvas.popupEventDc self.currentTool.setRegion(self.parentCanvas.canvas, None, region, [len(region[0]), len(region)], self.currentTool.external) self.currentTool.onSelectEvent(self.parentCanvas.canvas, (0, 0), self.parentCanvas.dispatchPatchSingle, eventDc, True, wx.MOD_NONE, None, self.currentTool.targetRect, viewRect) else: viewRect = self.parentCanvas.GetViewStart() - eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + if self.parentCanvas.popupEventDc == None: + eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + else: + eventDc = self.parentCanvas.popupEventDc self.parentCanvas.canvas.journal.begin() dirty = False for numRow in range(len(region)): diff --git a/libroar/RoarCanvasWindow.py b/libroar/RoarCanvasWindow.py index b1a9236..c939974 100644 --- a/libroar/RoarCanvasWindow.py +++ b/libroar/RoarCanvasWindow.py @@ -151,7 +151,11 @@ class RoarCanvasWindow(GuiWindow): viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), 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, event.GetModifiers(), mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect): + if mouseRightDown \ + and (self.commands.currentTool.__class__ == ToolObject) \ + and (self.commands.currentTool.toolState >= self.commands.currentTool.TS_SELECT): + self.popupEventDc = eventDc; self.PopupMenu(self.operatorsMenu); self.popupEventDc = None; + elif not self.applyTool(eventDc, True, None, event.GetModifiers(), mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect): event.Skip() # }}} # {{{ onMouseWheel(self, event) @@ -184,6 +188,7 @@ class RoarCanvasWindow(GuiWindow): super().__init__(parent, pos, scrollStep, [w * h for w, h in zip(cellSize, size)]) self.backend, self.canvas, self.cellSize, self.commands, self.parentFrame = backend(self.size, cellSize), canvas, cellSize, commands(self, parentFrame), parentFrame self.brushColours, self.brushPos, self.brushSize, self.dirty, self.lastCellState = [4, 1], [0, 0], [1, 1], False, None + self.popupEventDc = None self.dropTarget = RoarCanvasWindowDropTarget(self) self.SetDropTarget(self.dropTarget) self.Bind(wx.EVT_MOUSEWHEEL, self.onMouseWheel) diff --git a/libroar/RoarClient.py b/libroar/RoarClient.py index aa02ff0..728090d 100644 --- a/libroar/RoarClient.py +++ b/libroar/RoarClient.py @@ -12,7 +12,7 @@ from RoarCanvasCommands import RoarCanvasCommands from RoarCanvasWindow import RoarCanvasWindow from glob import glob -import os, random, sys +import os, random, sys, wx class RoarClient(GuiFrame): # {{{ _getIconPathName(self) @@ -55,4 +55,10 @@ class RoarClient(GuiFrame): self.assetsWindow = RoarAssetsWindow(GuiCanvasWxBackend, defaultCellSize, self) self.canvasPanel.commands.canvasAssetsWindowShow(None) + # XXX + self.canvasPanel.operatorsMenu = wx.Menu() + for menuItem in self.canvasPanel.commands.menus[3][1:]: + menuItemWindow = self.canvasPanel.operatorsMenu.Append(menuItem.attrDict["id"], menuItem.attrDict["label"], menuItem.attrDict["caption"]) + self.Bind(wx.EVT_MENU, self.onMenu, menuItemWindow) + # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120