Add an early draft for context menus

This commit is contained in:
cncfanatics
2010-10-04 08:52:45 +02:00
parent 7eac2649bc
commit 7564914cf0
4 changed files with 87 additions and 8 deletions

View File

@@ -1,8 +1 @@
__all__ = []
menus = {}
def registerMenu(menu):
menus[menu.name] = menu
def getMenu(name):
return menus[name]
__all__ = ["itemStats"]

View File

@@ -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()

60
gui/contextMenu.py Executable file
View File

@@ -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 <http://www.gnu.org/licenses/>.
#===============================================================================
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 *

View File

@@ -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)