Implement a right click context menu for items.

This commit is contained in:
cncfanatics
2010-08-24 16:46:25 +02:00
parent 5288cfd275
commit ccecff5e43
3 changed files with 60 additions and 1 deletions

42
gui/itemStats.py Normal file
View File

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

View File

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

View File

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