diff --git a/gui/additionsPane.py b/gui/additionsPane.py index 00a126a30..90edcc68b 100644 --- a/gui/additionsPane.py +++ b/gui/additionsPane.py @@ -30,7 +30,7 @@ from gui.builtinAdditionPanes.implantView import ImplantView from gui.builtinAdditionPanes.notesView import NotesView from gui.builtinAdditionPanes.projectedView import ProjectedView from gui.chrome_tabs import PFNotebook -from gui.pyfatogglepanel import TogglePanel +from gui.toggle_panel import TogglePanel class AdditionsPane(TogglePanel): diff --git a/gui/chrome_tabs.py b/gui/chrome_tabs.py index ce97f6c5a..4e454d014 100644 --- a/gui/chrome_tabs.py +++ b/gui/chrome_tabs.py @@ -1380,6 +1380,8 @@ class PFNotebookPagePreview(wx.Frame): if __name__ == "__main__": + # need to set up some paths, since bitmap loader requires config to have things + # Should probably change that so that it's not dependant on config import os os.chdir('..') import config diff --git a/gui/pyfatogglepanel.py b/gui/pyfatogglepanel.py deleted file mode 100644 index 75af0b214..000000000 --- a/gui/pyfatogglepanel.py +++ /dev/null @@ -1,199 +0,0 @@ -########################################################################### -# pyfatogllepanel.py -# -# Author: Darriele - HomeWorld -# -# Project home: https://github.com/pyfa-org/Pyfa - pyfa project -# Some portions of code are based on -# AGW:pycollapsiblepane generic implementation of wx.CollapsiblePane -# AGW:pycollapsiblepane credits ( from the original source file used ): -# Andrea Gavana, @ 09 Aug 2007 -# Latest Revision: 12 Apr 2010, 12.00 GMT -# -# Module description: -# TogglePanel class is a wx.collipsablepane like implementation that uses -# some optimization from awg::pycollipsablepane to provide certain -# features tailored for PYFA needs. -# -# This module is part of PYFA (PYthon Fitting Assitant) and it shares the same -# licence ( read PYFA licence notice: gpl.txt ) -# -# Notes: leave the commented code as it is, those line will be removed someday -########################################################################### - -# noinspection PyPackageRequirements -import wx -from gui.bitmap_loader import BitmapLoader - - -class TogglePanel(wx.Panel): - def __init__(self, parent, forceLayout=-1): - wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.Size(-1, -1), - style=wx.TAB_TRAVERSAL) - - self._toggle = 1 - self.parent = parent - self.forceLayout = forceLayout - self.bkColour = self.GetBackgroundColour() - - # Create the main sizer of this panel - self.mainSizer = wx.BoxSizer(wx.VERTICAL) - self.SetSizer(self.mainSizer) - # parentSize = parent.GetMinSize() - - # Create the header panel - self.headerPanel = wx.Panel(self) - self.mainSizer.Add(self.headerPanel, 0, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT, 1) - - # Load expanded/collapsed bitmaps from the icons folder - self.bmpExpanded = BitmapLoader.getBitmap("down-arrow2", "gui") - self.bmpCollapsed = BitmapLoader.getBitmap("up-arrow2", "gui") - - # Make the bitmaps have the same color as window text - sysTextColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT) - - img = self.bmpExpanded.ConvertToImage() - img.Replace(0, 0, 0, sysTextColour[0], sysTextColour[1], sysTextColour[2]) - self.bmpExpanded = wx.BitmapFromImage(img) - - img = self.bmpCollapsed.ConvertToImage() - img.Replace(0, 0, 0, sysTextColour[0], sysTextColour[1], sysTextColour[2]) - self.bmpCollapsed = wx.BitmapFromImage(img) - - self.headerBmp = wx.StaticBitmap(self.headerPanel) - self.headerBmp.SetBitmap(self.bmpExpanded) - - # Create the header sizer and add static bitmap and static text controls to it - - headerSizer = wx.BoxSizer(wx.HORIZONTAL) - self.headerPanel.SetSizer(headerSizer) - - hbmpSizer = wx.BoxSizer(wx.HORIZONTAL) - hlblSizer = wx.BoxSizer(wx.HORIZONTAL) - self.hcntSizer = wx.BoxSizer(wx.HORIZONTAL) - - hbmpSizer.Add(self.headerBmp, 0, 0, 5) - - self.headerLabel = wx.StaticText(self.headerPanel, wx.ID_ANY, "PYFA", wx.DefaultPosition, wx.DefaultSize, 0) - hlblSizer.Add(self.headerLabel, 0, wx.EXPAND, 5) - - headerSizer.Add(hbmpSizer, 0, wx.RIGHT, 5) - headerSizer.Add(hlblSizer, 0, wx.RIGHT, 5) - headerSizer.Add(self.hcntSizer, 0, wx.RIGHT, 5) - - # Set the static text font weight to BOLD - - headerFont = parent.GetFont() - headerFont.SetWeight(wx.BOLD) - self.headerLabel.SetFont(headerFont) - - # Create the content panel and its main sizer - - self.contentSizer = wx.BoxSizer(wx.VERTICAL) - self.contentPanel = wx.Panel(self) - self.contentPanel.SetSizer(self.contentSizer) - - self.mainSizer.Add(self.contentPanel, 0, wx.EXPAND | wx.RIGHT | wx.LEFT, 5) - - self.Layout() - - # Connect Events - self.headerLabel.Bind(wx.EVT_LEFT_UP, self.toggleContent) - self.headerBmp.Bind(wx.EVT_LEFT_UP, self.toggleContent) - self.headerPanel.Bind(wx.EVT_LEFT_UP, self.toggleContent) - - def __del__(self): - pass - - def AddToggleItem(self, hitem): - hitem.Bind(wx.EVT_LEFT_UP, self.toggleContent) - - def GetHeaderContentSizer(self): - return self.hcntSizer - - def GetHeaderPanel(self): - return self.headerPanel - - def InsertItemInHeader(self, item): - self.hcntSizer.Add(item, 0, 0, 0) - self.Layout() - - def AddSizer(self, sizer): - self.contentSizer.Add(sizer, 0, wx.EXPAND | wx.ALL, 0) - self.Layout() - - def GetContentPane(self): - return self.contentPanel - - def SetLabel(self, label): - self.headerLabel.SetLabel(label) - - def IsCollapsed(self): - """ Returns ``True`` if the pane window is currently hidden. """ - if self._toggle == 1: - return False - else: - return True - - def IsExpanded(self): - """ Returns ``True`` if the pane window is currently shown. """ - if self._toggle == 1: - return False - else: - return True - - def OnStateChange(self, sz): - """ - Handles the status changes (collapsing/expanding). - - :param sz: an instance of `wx.Size`. - """ - - # minimal size has priority over the best size so set here our min size - self.SetMinSize(sz) - self.SetSize(sz) - - self.parent.GetSizer().SetSizeHints(self.parent) - - if self.IsCollapsed(): - # expanded . collapsed transition - if self.parent.GetSizer(): - # we have just set the size hints... - sz = self.parent.GetSizer().CalcMin() - - # use SetClientSize() and not SetSize() otherwise the size for - # e.g. a wxFrame with a menubar wouldn't be correctly set - self.parent.SetClientSize(sz) - else: - self.parent.Layout() - else: - # collapsed . expanded transition - # force our parent to "fit", i.e. expand so that it can honour - # our minimal size - self.parent.Fit() - - # Toggle the content panel (hide/show) - def toggleContent(self, event): - self.Freeze() - - if self._toggle == 1: - self.contentMinSize = self.contentPanel.GetSize() - self.contentPanel.Hide() - self.headerBmp.SetBitmap(self.bmpCollapsed) - else: - self.contentPanel.Show() - self.headerBmp.SetBitmap(self.bmpExpanded) - - self._toggle *= -1 - self.Layout() - self.Thaw() - - if self.forceLayout == -1: - if wx.VERSION >= (3, 0): - x, y = self.GetBestSize() - y -= self.contentPanel.GetSize()[1] - else: - x, y = self.GetBestSize() - self.OnStateChange((x, y)) - else: - self.parent.Layout() diff --git a/gui/statsPane.py b/gui/statsPane.py index ce09e2e62..e39007ff7 100644 --- a/gui/statsPane.py +++ b/gui/statsPane.py @@ -28,7 +28,7 @@ import gui.globalEvents as GE # import gui.builtinViews.fittingView as fv from gui.statsView import StatsView from gui.contextMenu import ContextMenu -from gui.pyfatogglepanel import TogglePanel +from gui.toggle_panel import TogglePanel from logbook import Logger pyfalog = Logger(__name__) diff --git a/gui/toggle_panel.py b/gui/toggle_panel.py new file mode 100644 index 000000000..7340af112 --- /dev/null +++ b/gui/toggle_panel.py @@ -0,0 +1,187 @@ +#=============================================================================== +# TogglePanel is based on PyCollapsiblePane - includes a few improvements +# such as adding items to header, lack of button implementation ("GTK +# expander" style is implemented with plain text with unicode arrows rather +# than drawn geometry), etc. +# +# When adding TogglePanel to sizer, it is important to ensure the following: +# sizer is vertical +# set proportion = 0 +# +# ToDo: Create animations for collapsing / expanding +# +#=============================================================================== + +import wx + + +class TogglePanel (wx.Panel): + def __init__(self, parent, force_layout=False, *args, **kargs): + super().__init__(parent, *args, **kargs) + + self._toggled = True + self.parent = parent + self.force_layout = force_layout + + # Create the main sizer of this panel + self.main_sizer = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(self.main_sizer) + + # Create the header panel, set sizer, and add to main sizer + self.header_panel = wx.Panel(self) + header_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.header_panel.SetSizer(header_sizer) + + self.main_sizer.Add(self.header_panel, 0, wx.EXPAND | wx.TOP | + wx.BOTTOM | wx.RIGHT, 1) + + # Add arrow + self.header_arrow = wx.StaticText(self.header_panel, wx.ID_ANY, + "\u25bc") + header_sizer.Add(self.header_arrow, 0, wx.RIGHT, 5) + + # Add header text + self.header_label = wx.StaticText(self.header_panel, wx.ID_ANY, "") + font = parent.GetFont() + font.SetWeight(wx.BOLD) + self.header_label.SetFont(font) + header_sizer.Add(self.header_label, 0, wx.RIGHT, 5) + + # Add a sizer for additional header items if we need it + self.hcontent_sizer = wx.BoxSizer(wx.HORIZONTAL) + header_sizer.Add(self.hcontent_sizer, 0, wx.RIGHT, 5) + + # Create the content panel, set sizer, and add to main sizer + self.content_panel = wx.Panel(self) + self.content_sizer = wx.BoxSizer(wx.VERTICAL) + self.content_panel.SetSizer(self.content_sizer) + + self.main_sizer.Add(self.content_panel, 0, wx.EXPAND | wx.RIGHT | + wx.LEFT, 5) + + self.Layout() + + # Connect Events + self.header_label.Bind(wx.EVT_LEFT_UP, self.ToggleContent) + self.header_arrow.Bind(wx.EVT_LEFT_UP, self.ToggleContent) + self.header_panel.Bind(wx.EVT_LEFT_UP, self.ToggleContent) + + def __del__(self): + pass + + def AddToggleItem(self, item): + item.Bind(wx.EVT_LEFT_UP, self.ToggleContent) + + def GetHeaderContentSizer(self): + return self.hcontent_sizer + + def GetHeaderPanel(self): + return self.header_panel + + def InsertItemInHeader(self, item): + self.hcontent_sizer.Add(item, 0, 0, 0) + self.AddToggleItem(item) + self.Layout() + + def AddSizer(self, sizer): + self.content_sizer.Add(sizer, 0, wx.EXPAND | wx.ALL, 0) + self.Layout() + + def GetContentPanel(self): + return self.content_panel + + def SetLabel(self, label): + self.header_label.SetLabel(label) + + def IsCollapsed(self): + return not self._toggled + + def IsExpanded(self): + return self._toggled + + def OnStateChange(self, sz): + self.SetSize(sz) + + self.parent.GetSizer().SetSizeHints(self.parent) + + if not self._toggled: + if self.parent.GetSizer(): + # we have just set the size hints... + sz = self.parent.GetSizer().CalcMin() + + # use SetClientSize() and not SetSize() otherwise the size for + # e.g. a wxFrame with a menubar wouldn't be correctly set + self.parent.SetClientSize(sz) + else: + self.parent.Layout() + else: + # force our parent to "fit", i.e. expand so that it can honor + # our minimal size + self.parent.Fit() + + def ToggleContent(self, event): + #self.Freeze() + + if self._toggled: + # If we are expanded, save previous size and collapse by setting + # content height to 0 + self.content_min_size = self.content_panel.GetSize() + self.content_panel.SetMinSize((self.content_min_size[0], 0)) + self.header_arrow.SetLabel("\u25b6") + else: + # If we are collapsed, set content size to previously saved value + self.content_panel.SetMinSize(self.content_min_size) + self.header_arrow.SetLabel("\u25bc") + + self._toggled = not self._toggled + + #self.Thaw() + + if self.force_layout: + self.parent.Layout() + else: + self.OnStateChange(self.GetBestSize()) + +if __name__ == "__main__": + class TestPanel(wx.Panel): + def __init__(self, parent): + super().__init__(parent, size=(-1, -1)) + + if 'wxMSW' in wx.PlatformInfo: + color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE) + self.SetBackgroundColour(color) + + main_sizer = wx.BoxSizer(wx.VERTICAL) + + # Generate 3 test panels with different font sizes + for x in range(3): + toggle_panel = TogglePanel(self) + toggle_panel.SetLabel("Test Header") + + content_panel = toggle_panel.GetContentPanel() + content_panel.SetBackgroundColour(wx.WHITE) + + content_sizer = wx.BoxSizer(wx.HORIZONTAL) + header = wx.StaticText(content_panel, -1, "TogglePanel Test") + header.SetFont(wx.Font(10+(x*3), wx.SWISS, wx.NORMAL, wx.BOLD)) + content_sizer.Add(header, 0, wx.ALL, 10) + content_panel.SetSizer(content_sizer) + + main_sizer.Add(toggle_panel, 0, wx.EXPAND | wx.ALL, 2) + + self.SetSizer(main_sizer) + + class Frame(wx.Frame): + def __init__(self, title): + super().__init__(None, title=title, size=(500, 500)) + main_sizer = wx.BoxSizer(wx.VERTICAL) + + self.statsPane = TestPanel(self) + main_sizer.Add(self.statsPane, 0, wx.EXPAND) + + self.SetSizerAndFit(main_sizer) + + app = wx.App(redirect=False) # Error messages go to popup window + top = Frame("Test Toggle Panel") + top.Show() + app.MainLoop()