From 7564914cf0e17d8f90173527314a2607d10bc33a Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Mon, 4 Oct 2010 08:52:45 +0200 Subject: [PATCH] Add an early draft for context menus --- gui/builtinContextMenus/__init__.py | 9 +---- gui/builtinContextMenus/itemStats.py | 16 ++++++++ gui/contextMenu.py | 60 ++++++++++++++++++++++++++++ gui/fittingView.py | 10 +++++ 4 files changed, 87 insertions(+), 8 deletions(-) create mode 100755 gui/builtinContextMenus/itemStats.py create mode 100755 gui/contextMenu.py diff --git a/gui/builtinContextMenus/__init__.py b/gui/builtinContextMenus/__init__.py index e79bdd159..9df27e8f4 100755 --- a/gui/builtinContextMenus/__init__.py +++ b/gui/builtinContextMenus/__init__.py @@ -1,8 +1 @@ -__all__ = [] - -menus = {} -def registerMenu(menu): - menus[menu.name] = menu - -def getMenu(name): - return menus[name] +__all__ = ["itemStats"] \ No newline at end of file diff --git a/gui/builtinContextMenus/itemStats.py b/gui/builtinContextMenus/itemStats.py new file mode 100755 index 000000000..86063ab82 --- /dev/null +++ b/gui/builtinContextMenus/itemStats.py @@ -0,0 +1,16 @@ +from gui.contextMenu import ContextMenu + +class ItemStats(ContextMenu): + def __init__(self): + pass + + def display(self, context): + return True + + def getText(self, context): + return "Item stats" + + def activate(self, context): + pass + +ItemStats.register() \ No newline at end of file diff --git a/gui/contextMenu.py b/gui/contextMenu.py new file mode 100755 index 000000000..6b6a2033e --- /dev/null +++ b/gui/contextMenu.py @@ -0,0 +1,60 @@ +#=============================================================================== +# Copyright (C) 2010 Diego Duclos +# +# This file is part of pyfa. +# +# pyfa is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# pyfa is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with pyfa. If not, see . +#=============================================================================== + +import wx + +class ContextMenu(object): + menus = set() + @classmethod + def register(cls): + cls.menus.add(cls()) + + @classmethod + def getMenu(cls, *contexts): + menu = wx.Menu() + for i, m in enumerate(cls.menus): + amount = 0 + for context in contexts: + if m.display(context): + amount += 1 + item = wx.MenuItem(menu, wx.ID_ANY, m.getText(context)) + bitmap = m.getBitmap(context) + if bitmap: + item.SetBitmap(bitmap) + + menu.AppendItem(item) + + if amount > 0 and i != len(cls.menus) - 1: + menu.AppendSeparator() + + return menu + + def display(self, context): + raise NotImplementedError() + + def activate(self, context): + raise NotImplementedError() + + def getText(self, context): + raise NotImplementedError() + + def getBitmap(self, context): + return None + +from gui.builtinContextMenus import * \ No newline at end of file diff --git a/gui/fittingView.py b/gui/fittingView.py index 52d2ba930..04d307de4 100644 --- a/gui/fittingView.py +++ b/gui/fittingView.py @@ -22,6 +22,7 @@ import wx.lib.newevent import service import gui.mainFrame import gui.display as d +from gui.contextMenu import ContextMenu import sys from eos.types import Slot @@ -41,6 +42,7 @@ class FittingView(d.Display): d.Display.__init__(self, parent) self.mainFrame.Bind(FIT_CHANGED, self.fitChanged) self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem) + self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu) self.activeFitID = None #Gets called from the fitMultiSwitch when it decides its time @@ -107,3 +109,11 @@ class FittingView(d.Display): pass finally: event.Skip() + + def scheduleMenu(self, event): + event.Skip() + wx.CallAfter(self.spawnMenu) + + def spawnMenu(self): + menu = ContextMenu.getMenu("fitting") + self.PopupMenu(menu) \ No newline at end of file