Skip to content

Commit

Permalink
Fix issue #166 as proposed by ecyoung3
Browse files Browse the repository at this point in the history
  • Loading branch information
slabko authored and adamerose committed Feb 11, 2023
1 parent e3328f7 commit b05f93a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pandasgui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def init_ui(self):
self.make_menu_bar()
self.setCentralWidget(self.splitter)

# Create a copy of the settings in case the SettingsStore reference has
# been discarded by Qt prematurely
# https://stackoverflow.com/a/17935694/10342097
self.store.settings = self.store.settings.copy()

# Signals
self.store.settings.settingsChanged.connect(self.apply_settings)

Expand Down
15 changes: 15 additions & 0 deletions pandasgui/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ def reset_to_defaults(self):
for setting_name, setting_value in DEFAULT_SETTINGS.items():
self[setting_name].value = setting_value

def copy(self):
"""
Create a copy of the settings with a new QObject. Intended as a workaround
to this bug: https://github.com/adamerose/PandasGUI/issues/166
"""
# Create new settings instance
new_settings = SettingsStore()

# Copy every attribute that's a Setting
for attr, value in self.__dict__.items():
if isinstance(value, Setting):
setattr(new_settings, attr, value)

return new_settings

def __repr__(self):
return '\n'.join([f"{key} = {val.value}" for key, val in self.__dict__.items()])

Expand Down

0 comments on commit b05f93a

Please sign in to comment.