37 from .settings
import RideSettings
46 def __init__(self, parent, title, preferences, style="auto"):
47 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(850, 660),
48 style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE)
50 self.SetLayoutDirection(wx.Layout_LeftToRight)
51 self.Bind(wx.EVT_CLOSE, self.
OnCloseOnClose)
56 self.
fontfont = self.GetFont()
59 self.SetFont(self.
fontfont)
60 self.SetBackgroundColour(Colour(self.
_general_settings_general_settings[
'background']))
61 self.SetOwnBackgroundColour(Colour(self.
_general_settings_general_settings[
'secondary background']))
62 self.SetForegroundColour(Colour(self.
_general_settings_general_settings[
'foreground']))
63 self.SetOwnForegroundColour(Colour(self.
_general_settings_general_settings[
'secondary foreground']))
66 panels = preferences.preference_panels
67 if style
not in (
"tree",
"notebook",
"single",
"auto"):
68 raise Exception(
"invalid style; must be one of 'tree','notebook','single' or 'auto'")
70 if style ==
"tree" or (style ==
"auto" and len(panels) > TREE_THRESHOLD):
71 self.
_sw_sw = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_LIVE_UPDATE|wx.SP_3D)
72 self.
_tree_tree = wx.TreeCtrl(self.
_sw_sw, wx.ID_ANY,
73 style=wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
78 sizer = wx.BoxSizer(wx.VERTICAL)
79 sizer.Add(self.
_sw_sw, 1, wx.EXPAND)
82 self.
_tree_tree.SetOwnBackgroundColour(Colour(self.
_general_settings_general_settings[
'secondary background']))
84 self.
_tree_tree.SetOwnForegroundColour(Colour(self.
_general_settings_general_settings[
'secondary foreground']))
87 self.
_tree_tree.SelectItem(self.
_tree_tree.GetFirstChild(self.
_tree_tree.GetRootItem())[0])
90 elif style ==
"notebook" or (style ==
"auto" and len(panels) > 1):
99 for panel_class
in sorted(panels, key=
lambda p: p.location):
103 panel = container.AddPanel(panel_class)
104 container.ShowPanel(panel)
105 self.
_notebook_notebook.AddPage(container, panel.GetTitle())
106 sizer = wx.BoxSizer(wx.VERTICAL)
107 sizer.Add(self.
_notebook_notebook, 1, wx.EXPAND)
112 sizer = wx.BoxSizer(wx.VERTICAL)
113 sizer.Add(self.
_container_container, 1, wx.EXPAND)
116 panel = self.
_container_container.AddPanel(panels[0])
133 instance_or_class = self.
_tree_tree.GetItemData(event.GetItem())
134 if isinstance(instance_or_class, wx.Panel):
135 panel = instance_or_class
139 self.
_panels_panels.append(panel)
140 self.
_tree_tree.SetItemData(event.GetItem(), panel)
150 self.
_tree_tree.AddRoot(
"Root")
151 for panel_class
in panels:
152 location = panel_class.location
153 if not isinstance(location, tuple):
156 location = (location,)
158 self.
_tree_tree.SetItemData(item, panel_class)
159 self.
_tree_tree.ExpandAll()
162 item = self.
_tree_tree.GetRootItem()
163 for text
in location:
174 if self.
_tree_tree.ItemHasChildren(parent):
175 item, cookie = self.
_tree_tree.GetFirstChild(parent)
177 if self.
_tree_tree.GetItemText(item).strip().
lower() == text.strip().
lower():
179 item, cookie = self.
_tree_tree.GetNextChild(parent, cookie)
181 item = self.
_tree_tree.AppendItem(parent, text)
185 if self.
_tree_tree.ItemHasChildren(parent):
186 item, cookie = self.
_tree_tree.GetFirstChild(parent)
189 item, cookie = self.
_tree_tree.GetNextChild(parent, cookie)
202 super(PanelContainer, self).
__init__(*args, **kwargs)
207 self.
titletitle = wx.StaticText(self, label=
"Your message here")
208 self.
panels_containerpanels_container = ScrolledPanel(self, wx.ID_ANY, style=wx.TAB_TRAVERSAL)
210 sizer = wx.BoxSizer(wx.VERTICAL)
211 sizer.Add(self.
titletitle, 0, wx.TOP|wx.LEFT|wx.EXPAND, 4)
212 sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 4)
217 font = self.
titletitle.GetFont()
218 font.SetFaceName(self.
settingssettings[
'font face'])
219 font.SetPointSize(self.
settingssettings[
'font size'])
221 self.
titletitle.SetFont(font)
222 self.
titletitle.SetForegroundColour(self.
settingssettings[
'foreground'])
223 self.
titletitle.SetBackgroundColour(self.
settingssettings[
'background'])
224 self.SetForegroundColour(self.
settingssettings[
'foreground'])
225 self.SetBackgroundColour(self.
settingssettings[
'background'])
229 panel = panel_class(parent=self.
panels_containerpanels_container, settings=settings)
238 self.SetForegroundColour(self.
settingssettings[
'foreground'])
239 self.SetBackgroundColour(self.
settingssettings[
'background'])
240 panel.SetForegroundColour(self.
settingssettings[
'foreground'])
241 panel.SetBackgroundColour(self.
settingssettings[
'background'])
244 item = sizer.GetItem(panel)
245 title = getattr(panel,
"title", panel.location[-1])
247 font = self.
titletitle.GetFont()
248 font.SetFaceName(self.
settingssettings[
'font face'])
249 font.SetPointSize(self.
settingssettings[
'font size'])
252 self.
titletitle.SetFont(font)
253 self.
titletitle.SetForegroundColour(self.
settingssettings[
'foreground'])
254 self.
titletitle.SetBackgroundColour(self.
settingssettings[
'background'])
256 sizer.Add(panel, 1, wx.EXPAND)
261 self.
titletitle.SetLabel(title)
This contains a preference panel.
def SetTitle(self, title)
Set the title of the panel.
def __init__(self, *args, **kwargs)
def AddPanel(self, panel_class, settings)
Add a panel to the dialog.
def ShowPanel(self, panel)
Arrange for the given panel to be shown.
A dialog for showing the preference panels.
def _get_item(self, location)
def OnTreeSelection(self, event)
Show panel that corresponds to selected tree item.
def _get_children(self, parent)
def _get_child_item(self, parent, text)
Returns the tree item with the given text under the given parent.
def __init__(self, parent, title, preferences, style="auto")
def _populate_tree(self, panels)
Recreate the hierarchical tree of preferences panels.