Skip to content

Commit 7d189cc

Browse files
Initial settings edit button on Preferences. Make backup of settings.cfg
1 parent 9d2a143 commit 7d189cc

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/robotide/application/application.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from contextlib import contextmanager
2121
from pathlib import Path
2222

23-
from pygments.styles.dracula import background
24-
2523
from ..namespace import Namespace
2624
from ..controller import Project
2725
from ..spec import librarydatabase

src/robotide/preferences/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(self, settings):
4949
self.settings = settings
5050
self._preference_panels = []
5151
self._add_builtin_preferences()
52+
self.settings_path = self.settings._default_path
53+
print(f"DEBUG: preferences/__init__.py Preferences settings_path={self.settings_path}")
5254

5355
@property
5456
def preference_panels(self):

src/robotide/preferences/editor.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from wx.lib.scrolledpanel import ScrolledPanel
3737

3838
from .settings import RideSettings
39+
from ..widgets import ButtonWithHandler, HorizontalSizer
3940

4041
_ = wx.GetTranslation # To keep linter/code analyser happy
4142
builtins.__dict__['_'] = wx.GetTranslation
@@ -198,16 +199,28 @@ class PanelContainer(wx.Panel):
198199
Each page has a title area, and an area for a preferences panel
199200
"""
200201
def __init__(self, *args, **kwargs):
202+
from ..editor import customsourceeditor
201203
super(PanelContainer, self).__init__(*args, **kwargs)
202204

203205
self._current_panel = None
204206
self._settings = RideSettings()
205207
self.settings = self._settings['General']
206208
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()
211+
config_button = ButtonWithHandler(self, _('Settings'), bitmap='wrench_orange.png',
212+
fsize=self.settings[FONT_SIZE],
213+
handler=lambda e: customsourceeditor.main(self._settings.user_path))
214+
config_button.SetBackgroundColour(self.settings['background'])
215+
config_button.SetOwnBackgroundColour(self.settings['background'])
216+
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)
207219
self.panels_container = ScrolledPanel(self, wx.ID_ANY, style=wx.TAB_TRAVERSAL)
208220
self.panels_container.SetupScrolling()
209221
sizer = wx.BoxSizer(wx.VERTICAL)
210-
sizer.Add(self.title, 0, wx.TOP | wx.LEFT | wx.EXPAND, 4)
222+
sizer.Add(hsizer)
223+
# sizer.Add(self.title, 0, wx.TOP | wx.LEFT | wx.EXPAND, 4)
211224
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)
212225
sizer.Add(self.panels_container, 1, wx.EXPAND)
213226
self.SetSizer(sizer)

src/robotide/preferences/general.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(self, settings, *args, **kwargs):
8686
# don't have the time to do that right now, so this will have
8787
# to suffice.
8888

89+
# print(f"DEBUG: preferences/general.py GeneralPeferences settings_path={self._settings._default_path}")
8990
ui_language = self._select_ui_language()
9091
font_editor = self._create_font_editor()
9192
colors_sizer = self.create_colors_sizer()

src/robotide/preferences/settings.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def _copy_or_migrate_user_settings(settings_dir, source_path, dest_file_name):
4949
m_error = None
5050
if not os.path.exists(source_path):
5151
raise(FileNotFoundError(source_path))
52+
else:
53+
shutil.copyfile(source_path, source_path + '._backup')
5254
if not dest_file_name:
5355
dest_file_name = os.path.basename(source_path)
5456
settings_path = os.path.join(settings_dir, dest_file_name)
@@ -60,12 +62,12 @@ def _copy_or_migrate_user_settings(settings_dir, source_path, dest_file_name):
6062
SettingsMigrator(source_path, settings_path).migrate()
6163
# print(f"DEBUG: settings After migration {source_path} with {settings_path}")
6264
except ConfigObjError as parsing_error:
63-
print("WARNING! corrupted configuration file replaced with defaults")
65+
print("WARNING! corrupted configuration file replaced with defaults\n"
66+
f"A backup of the settings is at: {source_path + '._backup'}")
6467
print(parsing_error)
6568
m_error = parsing_error
6669
shutil.copyfile(settings_path, settings_path + '_old_broken')
67-
print("(backed up corrupted configuration file at: %s)" %
68-
(settings_path + '_old_broken'))
70+
print(f"(backed up corrupted configuration file at: {settings_path + '_old_broken'}")
6971
shutil.copyfile(source_path, settings_path)
7072
# print("DEBUG: source %s corrupted settings %s\n" % (source_path, settings_path))
7173
finally: # DEBUG Try to merge some settings
@@ -362,22 +364,24 @@ def __init__(self, path=None):
362364
elif path.endswith('.cfg') and os.path.exists(path):
363365
self._default_path = path
364366
# print(f"DEBUG: settings.py RideSettings SETTINGS {self._default_path=}")
365-
user_path = initialize_settings(self._default_path)
366-
Settings.__init__(self, user_path)
367-
self._settings_dir = os.path.dirname(user_path)
367+
self.user_path = initialize_settings(self._default_path)
368+
Settings.__init__(self, self.user_path)
369+
self._settings_dir = os.path.dirname(self.user_path)
368370
# print(f"DEBUG: RideSettings, self._settings_dir={self._settings_dir}")
369371
self.get('install root', os.path.dirname(os.path.dirname(__file__)))
370372
self.executable = self.get('executable', EXECUTABLE)
371373
if self.executable != EXECUTABLE:
372374
digest = 0
373375
for c in EXECUTABLE:
374376
digest += ord(c)
375-
new_user_path = user_path.replace("settings.cfg", f"settings_{digest}.cfg")
376-
new_user_path = initialize_settings(user_path, new_user_path)
377+
new_user_path = self.user_path.replace("settings.cfg", f"settings_{digest}.cfg")
378+
new_user_path = initialize_settings(self.user_path, new_user_path)
379+
self.user_path = new_user_path
377380
Settings.__init__(self, new_user_path)
378381
self._settings_dir = os.path.dirname(new_user_path)
379382
self.set('install root', os.path.dirname(os.path.dirname(__file__)))
380-
self.executable = self.set('executable', EXECUTABLE)
383+
self.set('executable', EXECUTABLE)
384+
self.set('last_settings_path', self.user_path)
381385

382386
def get_path(self, *parts):
383387
"""Returns path which combines settings directory and given parts."""

0 commit comments

Comments
 (0)