3131"""
3232
3333import builtins
34+ import os .path
35+
3436import wx
3537from wx import Colour
3638from wx .lib .scrolledpanel import ScrolledPanel
3739
3840from .settings import RideSettings
39- from ..widgets import ButtonWithHandler , HorizontalSizer
41+ from ..widgets import ButtonWithHandler
4042
4143_ = wx .GetTranslation # To keep linter/code analyser happy
4244builtins .__dict__ ['_' ] = wx .GetTranslation
@@ -199,23 +201,21 @@ class PanelContainer(wx.Panel):
199201 Each page has a title area, and an area for a preferences panel
200202 """
201203 def __init__ (self , * args , ** kwargs ):
202- from ..editor import customsourceeditor
203204 super (PanelContainer , self ).__init__ (* args , ** kwargs )
204-
205+ self . parent = self . GetParent ()
205206 self ._current_panel = None
206207 self ._settings = RideSettings ()
207208 self .settings = self ._settings ['General' ]
208209 self .title = wx .StaticText (self , label = "Your message here" )
209- print (f"DEBUG: preferences/editor.py PanelContainer settings_path={ self ._settings .user_path } " )
210- hsizer = HorizontalSizer ()
210+ hsizer = wx .BoxSizer (wx .HORIZONTAL )
211211 config_button = ButtonWithHandler (self , _ ('Settings' ), bitmap = 'wrench_orange.png' ,
212212 fsize = self .settings [FONT_SIZE ],
213- handler = lambda e : customsourceeditor . main (self ._settings .user_path ))
213+ handler = lambda e : self . on_edit_settings (self ._settings .user_path ))
214214 config_button .SetBackgroundColour (self .settings ['background' ])
215215 config_button .SetOwnBackgroundColour (self .settings ['background' ])
216216 config_button .SetForegroundColour (self .settings ['foreground' ])
217- hsizer .Add (self . title , 0 , wx .TOP | wx .LEFT | wx .EXPAND , 10 )
218- hsizer .add_expanding ( config_button , 1 , 10 )
217+ hsizer .Add (config_button , 0 , wx .TOP | wx .RIGHT | wx .EXPAND , 4 )
218+ hsizer .Add ( self . title , 0 , wx . TOP | wx . LEFT | wx . EXPAND , 4 )
219219 self .panels_container = ScrolledPanel (self , wx .ID_ANY , style = wx .TAB_TRAVERSAL )
220220 self .panels_container .SetupScrolling ()
221221 sizer = wx .BoxSizer (wx .VERTICAL )
@@ -269,3 +269,12 @@ def ShowPanel(self, panel):
269269 def SetTitle (self , title ):
270270 """Set the title of the panel"""
271271 self .title .SetLabel (title )
272+
273+ def on_edit_settings (self , settings_path ):
274+ """Starts Text Editor for settings file and closes all if changed"""
275+ from ..editor import customsourceeditor
276+ from ..context import SETTINGS_DIRECTORY
277+ main_settings_path = os .path .join (SETTINGS_DIRECTORY , 'settings.cfg' )
278+ customsourceeditor .main (main_settings_path )
279+ # DEBUG close parent test
280+ # self.parent.Close()
0 commit comments