hydrus/include/ClientGUICollapsible.py

147 lines
3.7 KiB
Python
Raw Normal View History

2015-03-18 21:46:29 +00:00
import ClientConstants as CC
import ClientGUICommon
import ClientGUIOptionsPanels
import wx
class CollapsibleOptions( ClientGUICommon.StaticBox ):
options_panel_class = ClientGUIOptionsPanels.OptionsPanel
staticbox_title = 'not implemented'
def __init__( self, parent ):
ClientGUICommon.StaticBox.__init__( self, parent, self.staticbox_title )
self._collapsible_panel = CollapsiblePanel( self )
self._options_panel = self.options_panel_class( self._collapsible_panel )
self._collapsible_panel.SetPanel( self._options_panel )
self.AddF( self._collapsible_panel, CC.FLAGS_EXPAND_PERPENDICULAR )
2015-08-05 18:42:35 +00:00
def ExpandCollapse( self ):
self._collapsible_panel.ExpandCollapse()
2015-03-18 21:46:29 +00:00
2015-08-05 18:42:35 +00:00
def GetOptions( self ):
return self._options_panel.GetOptions()
2015-07-22 19:40:39 +00:00
2015-08-05 18:42:35 +00:00
def SetOptions( self, options ):
self._options_panel.SetOptions( options )
2015-03-18 21:46:29 +00:00
2015-05-20 21:31:40 +00:00
class CollapsibleOptionsImportFiles( CollapsibleOptions ):
2015-03-18 21:46:29 +00:00
2015-05-20 21:31:40 +00:00
options_panel_class = ClientGUIOptionsPanels.OptionsPanelImportFiles
staticbox_title = 'import options - files'
2015-03-18 21:46:29 +00:00
class CollapsibleOptionsTags( CollapsibleOptions ):
options_panel_class = ClientGUIOptionsPanels.OptionsPanelTags
2015-05-20 21:31:40 +00:00
staticbox_title = 'import options - tags'
2015-03-18 21:46:29 +00:00
def __init__( self, parent, namespaces = None ):
CollapsibleOptions.__init__( self, parent )
if namespaces is None: namespaces = []
self.SetNamespaces( namespaces )
def SetNamespaces( self, namespaces ):
self._options_panel.SetNamespaces( namespaces )
2016-10-26 20:45:34 +00:00
if self._collapsible_panel.IsExpanded():
self._collapsible_panel.ExpandCollapse()
2015-03-18 21:46:29 +00:00
class CollapsiblePanel( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__( self, parent )
self._expanded = False
self._panel = None
self._vbox = wx.BoxSizer( wx.VERTICAL )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2016-10-26 20:45:34 +00:00
self._button = ClientGUICommon.BetterButton( self, 'expand', self.ExpandCollapse )
2015-03-18 21:46:29 +00:00
line = wx.StaticLine( self, style = wx.LI_HORIZONTAL )
2016-08-31 19:55:14 +00:00
hbox.AddF( self._button, CC.FLAGS_VCENTER )
2015-03-18 21:46:29 +00:00
hbox.AddF( line, CC.FLAGS_EXPAND_DEPTH_ONLY )
self._vbox.AddF( hbox, CC.FLAGS_EXPAND_PERPENDICULAR )
self.SetSizer( self._vbox )
2016-10-26 20:45:34 +00:00
def ExpandCollapse( self ):
2015-03-18 21:46:29 +00:00
if self._expanded:
2016-03-23 19:42:56 +00:00
self._button.SetLabelText( 'expand' )
2015-03-18 21:46:29 +00:00
self._panel.Hide()
self._expanded = False
else:
2016-03-23 19:42:56 +00:00
self._button.SetLabelText( 'collapse' )
2015-03-18 21:46:29 +00:00
self._panel.Show()
self._expanded = True
2015-06-17 20:01:41 +00:00
parent = self
2015-03-18 21:46:29 +00:00
2015-06-17 20:01:41 +00:00
while not isinstance( parent, wx.ScrolledWindow ) and not isinstance( parent, wx.TopLevelWindow ):
parent = parent.GetParent()
2015-03-18 21:46:29 +00:00
2015-06-17 20:01:41 +00:00
if isinstance( parent, wx.ScrolledWindow ):
parent.FitInside()
else:
2015-03-18 21:46:29 +00:00
2015-06-17 20:01:41 +00:00
parent.Layout()
2015-03-18 21:46:29 +00:00
2016-12-14 21:19:07 +00:00
event = CC.SizeChangedEvent( -1 )
wx.CallAfter( self.ProcessEvent, event )
2015-03-18 21:46:29 +00:00
2016-10-26 20:45:34 +00:00
def IsExpanded( self ):
return self._expanded
2015-03-18 21:46:29 +00:00
def SetPanel( self, panel ):
self._panel = panel
self._vbox.AddF( self._panel, CC.FLAGS_EXPAND_BOTH_WAYS )
self._panel.Hide()
2016-12-14 21:19:07 +00:00