Skip to content

Commit f9184c5

Browse files
committed
Settings: getter -> cl.app; housekeeping
- classes.app will have a get_settings() function (which we should try to migrate to, from classes.settings.get_settings() - in addition, the OpenShotApp instance has a get_settings() METHOD which is most-preferable (`from classes.app import get_app; s = get_app().get_settings()`)
1 parent 2609203 commit f9184c5

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/classes/app.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,22 @@
5555
except ImportError:
5656
pass
5757

58+
def get_app():
59+
""" Get the current QApplication instance of OpenShot """
60+
return QApplication.instance()
61+
62+
63+
def get_settings():
64+
"""Get a reference to the app's settings object"""
65+
return get_app().get_settings()
66+
5867
try:
5968
# Enable High-DPI resolutions
6069
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
6170
except AttributeError:
6271
pass # Quietly fail for older Qt5 versions
6372

6473

65-
def get_app():
66-
""" Returns the current QApplication instance of OpenShot """
67-
return QApplication.instance()
68-
6974

7075
class OpenShotApp(QApplication):
7176
""" This class is the primary QApplication for OpenShot.
@@ -297,6 +302,11 @@ def settings_load_error(self, filepath=None):
297302
% {"file_path": filepath}
298303
)
299304

305+
def get_settings(self):
306+
if not hasattr(self, "settings"):
307+
return None
308+
return self.settings
309+
300310
def _tr(self, message):
301311
return self.translate("", message)
302312

src/classes/settings.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
def get_settings():
3939
""" Get the current application's settings instance """
40-
return SettingStore.get_app().settings
40+
return SettingStore.get_app().get_settings()
4141

4242

4343
class SettingStore(JsonDataStore):
@@ -72,20 +72,22 @@ def set(self, key, value):
7272
""" Store setting, but adding isn't allowed. All possible settings must be in default settings file. """
7373
key = key.lower()
7474

75-
# Load user setting's values (for easy merging)
76-
user_values = {}
77-
for item in self._data:
78-
if "setting" in item and "value" in item:
79-
user_values[item["setting"].lower()] = item
75+
# Index settings values (for easy updates)
76+
user_values = {
77+
item["setting"].lower(): item
78+
for item in self._data
79+
if all(["setting" in item, "value" in item])
80+
}
8081

8182
# Save setting
8283
if key in user_values:
83-
user_values[key]["value"] = value
84+
user_values[key].update({"value": value})
8485
else:
8586
log.warn(
8687
"{} key '{}' not valid. The following are valid: {}".format(
87-
self.data_type, key,
88-
list(self._data.keys()),
88+
self.data_type,
89+
key,
90+
list(self._data.keys()),
8991
))
9092

9193
def load(self):

0 commit comments

Comments
 (0)