From ccecff5e430d668f9ee977da416946f8d99d99cd Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Tue, 24 Aug 2010 16:46:25 +0200 Subject: [PATCH] Implement a right click context menu for items. --- gui/itemStats.py | 42 ++++++++++++++++++++++++++++++++++++++++++ gui/mainMenuBar.py | 4 +++- gui/marketBrowser.py | 15 +++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 gui/itemStats.py diff --git a/gui/itemStats.py b/gui/itemStats.py new file mode 100644 index 000000000..dc9cf57e8 --- /dev/null +++ b/gui/itemStats.py @@ -0,0 +1,42 @@ +#=============================================================================== +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with pyfa. If not, see . +#=============================================================================== + +import wx +import bitmapLoader + +class ItemStatsFrame(wx.Frame): + def __init__(self): + wx.Frame.__init__(self, None, wx.ID_ANY, title="pyfa - Item Stats") + + i = wx.IconFromBitmap(bitmapLoader.getBitmap("pyfa", "icons")) + self.SetIcon(i) + + self.SetMinSize((200, 400)) + self.SetSize((200, 400)) + self.SetMaxSize((200, 400)) + +class ItemStatsMenu(wx.Menu): + def __init__(self): + wx.Menu.__init__(self) + + self.showInfoId = wx.NewId() + self.Append(self.showInfoId, "&Item stats", "moo") + + def setItem(self, itemId): + pass diff --git a/gui/mainMenuBar.py b/gui/mainMenuBar.py index a300d0307..3e759d42f 100644 --- a/gui/mainMenuBar.py +++ b/gui/mainMenuBar.py @@ -22,6 +22,8 @@ import bitmapLoader class MainMenuBar(wx.MenuBar): def __init__(self): + self.characterEditorId = wx.NewId() + wx.MenuBar.__init__(self) # File menu @@ -47,7 +49,7 @@ class MainMenuBar(wx.MenuBar): charMenu = wx.Menu() self.Append(charMenu, "&Character") - charEditItem = wx.MenuItem(charMenu, 20, "Character &Editor\tCTRL+B") + charEditItem = wx.MenuItem(charMenu, self.characterEditorId, "Character &Editor\tCTRL+B") charEditItem.SetBitmap(bitmapLoader.getBitmap("character_small", "icons")) charMenu.AppendItem(charEditItem) diff --git a/gui/marketBrowser.py b/gui/marketBrowser.py index 9734d879f..157172dd9 100644 --- a/gui/marketBrowser.py +++ b/gui/marketBrowser.py @@ -21,6 +21,7 @@ import sys import wx import controller import bitmapLoader +from gui.itemStats import ItemStatsMenu class MarketBrowser(wx.Panel): def __init__(self, parent): @@ -117,6 +118,10 @@ class MarketBrowser(wx.Panel): cMarket.activateMetaGroup("normal") p.SetMinSize((wx.SIZE_AUTO_WIDTH, btn.GetSize()[1] + 5)) + #Bind context menus + self.itemStatsMenu = ItemStatsMenu() + self.itemView.Bind(wx.EVT_CONTEXT_MENU, self.contextMenu) + def addMarketViewImage(self, iconFile): if iconFile is None: return -1 @@ -287,6 +292,16 @@ class MarketBrowser(wx.Panel): if maxWidth > width: self.itemView.SetColumnWidth(0, maxWidth) + def contextMenu(self, event): + #Check if something is selected, if so, spawn the menu for it + selection = self.itemView.GetFirstSelected() + if selection == -1: + return + + itemId = self.itemView.GetItemData(selection) + self.itemStatsMenu.setItem(itemId) + self.PopupMenu(self.itemStatsMenu) + class MarketTree(wx.TreeCtrl): def __init__(self, parent): wx.TreeCtrl.__init__(self, parent)