Focus contents of various pages when user switches to their tabs

This commit is contained in:
DarkPhoenix
2019-04-24 09:02:28 +03:00
parent d35bf6514f
commit 71aa557770
8 changed files with 14 additions and 10 deletions

View File

@@ -34,6 +34,7 @@ from gui.toggle_panel import TogglePanel
class AdditionsPane(TogglePanel):
def __init__(self, parent):
TogglePanel.__init__(self, parent, force_layout=1)
@@ -86,8 +87,8 @@ class AdditionsPane(TogglePanel):
PANES = ["Drones", "Fighters", "Cargo", "Implants", "Boosters", "Projected", "Command", "Notes"]
def select(self, name):
self.notebook.SetSelection(self.PANES.index(name))
def select(self, name, focus=True):
self.notebook.SetSelection(self.PANES.index(name), focus=focus)
def getName(self, idx):
return self.PANES[idx]

View File

@@ -35,7 +35,7 @@ class AddToCargo(ContextMenuSingle):
typeID = int(mainItem.ID)
command = cmd.GuiAddCargoCommand(fitID=fitID, itemID=typeID, amount=1)
if self.mainFrame.command.Submit(command):
self.mainFrame.additionsPane.select("Cargo")
self.mainFrame.additionsPane.select("Cargo", focus=False)
AddToCargo.register()

View File

@@ -30,7 +30,7 @@ class AddToCargoAmmo(ContextMenuSingle):
typeID = int(mainItem.ID)
command = cmd.GuiAddCargoCommand(fitID=fitID, itemID=typeID, amount=1000)
if self.mainFrame.command.Submit(command):
self.mainFrame.additionsPane.select("Cargo")
self.mainFrame.additionsPane.select("Cargo", focus=False)
AddToCargoAmmo.register()

View File

@@ -44,7 +44,7 @@ class DroneAddStack(ContextMenuSingle):
itemID=int(mainItem.ID),
amount=self.amount)
if self.mainFrame.command.Submit(command):
self.mainFrame.additionsPane.select('Drones')
self.mainFrame.additionsPane.select('Drones', focus=False)
DroneAddStack.register()

View File

@@ -35,7 +35,6 @@ class FillWithItem(ContextMenuSingle):
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(
fitID=self.mainFrame.getActiveFit(),
itemID=int(mainItem.ID)))
self.mainFrame.additionsPane.select('Drones')
FillWithItem.register()

View File

@@ -45,7 +45,7 @@ class ProjectItem(ContextMenuSingle):
else:
success = False
if success:
self.mainFrame.additionsPane.select('Projected')
self.mainFrame.additionsPane.select('Projected', focus=False)
ProjectItem.register()

View File

@@ -49,6 +49,7 @@ class ResourcesViewFull(StatsView):
self.toggleContext("fighter")
else:
self.toggleContext("drone")
event.Skip()
def toggleContext(self, context):
# Apparently you cannot .Hide(True) on a Window, otherwise I would just .Hide(context !== x).

View File

@@ -64,8 +64,9 @@ class PageChanging(_PageChanging, NotebookTabChangeEvent, VetoAble):
class PageChanged(_PageChanged, NotebookTabChangeEvent):
def __init__(self, old, new):
_PageChanged.__init__(self)
def __init__(self, old, new, *args, **kwargs):
_PageChanged.__init__(self, *args, **kwargs)
NotebookTabChangeEvent.__init__(self, old, new)
@@ -236,13 +237,15 @@ class ChromeNotebook(wx.Panel):
self.tabs_container.DisableTab(idx, toggle)
def SetSelection(self, page):
def SetSelection(self, page, focus=True):
old_selection = self.GetSelection()
if old_selection != page:
self._active_page.Hide()
self._active_page = self._pages[page]
self.tabs_container.SetSelected(page)
self.ShowActive()
if focus:
self._active_page.SetFocus()
wx.PostEvent(self, PageChanged(old_selection, page))
def DeletePage(self, n):