Implemented stats window reuse (on ctrl/cmd pressed)
This commit is contained in:
@@ -2,6 +2,7 @@ from gui.contextMenu import ContextMenu
|
||||
from gui.itemStats import ItemStatsDialog
|
||||
import gui.mainFrame
|
||||
import service
|
||||
import wx
|
||||
|
||||
class ItemStats(ContextMenu):
|
||||
def __init__(self):
|
||||
@@ -31,6 +32,22 @@ class ItemStats(ContextMenu):
|
||||
if context == "module" and stuff.isEmpty:
|
||||
return
|
||||
|
||||
dlg=ItemStatsDialog(stuff, context.capitalize() if context not in self.REPLACES else self.REPLACES[context])
|
||||
mstate = wx.GetMouseState()
|
||||
reuse = False
|
||||
|
||||
if mstate.ControlDown() or mstate.CmdDown():
|
||||
reuse = True
|
||||
|
||||
if self.mainFrame.GetActiveStatsWindow() == None and reuse:
|
||||
dlg=ItemStatsDialog(stuff, context.capitalize() if context not in self.REPLACES else self.REPLACES[context])
|
||||
|
||||
elif reuse:
|
||||
lastWnd = self.mainFrame.GetActiveStatsWindow()
|
||||
pos = lastWnd.GetPosition()
|
||||
dlg=ItemStatsDialog(stuff, context.capitalize() if context not in self.REPLACES else self.REPLACES[context], pos)
|
||||
lastWnd.closeEvent(None)
|
||||
|
||||
else:
|
||||
dlg=ItemStatsDialog(stuff, context.capitalize() if context not in self.REPLACES else self.REPLACES[context])
|
||||
|
||||
ItemStats.register()
|
||||
|
||||
@@ -30,10 +30,10 @@ import service
|
||||
|
||||
class ItemStatsDialog(wx.Dialog):
|
||||
counter = 0
|
||||
def __init__(self, victim, context = None):
|
||||
def __init__(self, victim, context = None, pos = wx.DefaultPosition):
|
||||
wx.Dialog.__init__(self,
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
wx.ID_ANY, title="Item stats",
|
||||
wx.ID_ANY, title="Item stats", pos = pos,
|
||||
style = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX |
|
||||
wx.MAXIMIZE_BOX | wx.RESIZE_BORDER| wx.SYSTEM_MENU)
|
||||
|
||||
@@ -66,11 +66,11 @@ class ItemStatsDialog(wx.Dialog):
|
||||
self.mainSizer.Add(self.container, 1, wx.EXPAND)
|
||||
self.SetSizer(self.mainSizer)
|
||||
|
||||
parent = gui.mainFrame.MainFrame.getInstance()
|
||||
self.parentWnd = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
dlgsize = self.GetSize()
|
||||
psize = parent.GetSize()
|
||||
ppos = parent.GetPosition()
|
||||
psize = self.parentWnd.GetSize()
|
||||
ppos = self.parentWnd.GetPosition()
|
||||
|
||||
ItemStatsDialog.counter += 1
|
||||
self.dlgOrder = ItemStatsDialog.counter
|
||||
@@ -82,18 +82,27 @@ class ItemStatsDialog(wx.Dialog):
|
||||
|
||||
dlgx = ppos.x + counter * dlgStep
|
||||
dlgy = ppos.y + counter * dlgStep
|
||||
self.SetPosition((dlgx,dlgy))
|
||||
if pos == wx.DefaultPosition:
|
||||
self.SetPosition((dlgx,dlgy))
|
||||
else:
|
||||
self.SetPosition(pos)
|
||||
self.parentWnd.RegisterStatsWindow(self)
|
||||
|
||||
self.Show()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.closeEvent)
|
||||
self.Bind(wx.EVT_ACTIVATE, self.OnActivate)
|
||||
|
||||
def OnActivate(self, event):
|
||||
self.parentWnd.SetActiveStatsWindow(self)
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
||||
if self.dlgOrder==ItemStatsDialog.counter:
|
||||
ItemStatsDialog.counter -= 1
|
||||
self.parentWnd.UnregisterStatsWindow(self)
|
||||
|
||||
self.Destroy()
|
||||
event.Skip()
|
||||
|
||||
###########################################################################
|
||||
## Class ItemStatsContainer
|
||||
|
||||
@@ -124,6 +124,8 @@ class MainFrame(wx.Frame):
|
||||
self.closePageId = wx.NewId()
|
||||
|
||||
self.graphFrame = None
|
||||
self.statsWnds = []
|
||||
self.activeStatsWnd = None
|
||||
|
||||
#Add menu
|
||||
self.SetMenuBar(MainMenuBar())
|
||||
@@ -134,6 +136,25 @@ class MainFrame(wx.Frame):
|
||||
#Show ourselves
|
||||
self.Show()
|
||||
|
||||
def SetActiveStatsWindow(self, wnd):
|
||||
self.activeStatsWnd = wnd
|
||||
|
||||
def GetActiveStatsWindow(self):
|
||||
|
||||
if self.activeStatsWnd in self.statsWnds:
|
||||
return self.activeStatsWnd
|
||||
|
||||
if len(self.statsWnds) > 0:
|
||||
return self.statsWnds[len(self.statsWnds) - 1]
|
||||
else:
|
||||
return None
|
||||
|
||||
def RegisterStatsWindow(self, wnd):
|
||||
self.statsWnds.append(wnd)
|
||||
|
||||
def UnregisterStatsWindow(self, wnd):
|
||||
self.statsWnds.remove(wnd)
|
||||
|
||||
def getActiveFit(self):
|
||||
p = self.fitMultiSwitch.GetSelectedPage()
|
||||
m = getattr(p, "getActiveFit", None)
|
||||
|
||||
Reference in New Issue
Block a user