1
- """
1
+ """
2
2
@file
3
- @brief This file loads and saves settings
3
+ @brief This file loads and saves settings
4
4
@author Noah Figg <[email protected] >
5
5
@author Jonathan Thomas <[email protected] >
6
6
@author Olivier Girard <[email protected] >
7
-
7
+
8
8
@section LICENSE
9
-
9
+
10
10
Copyright (c) 2008-2018 OpenShot Studios, LLC
11
11
(http://www.openshotstudios.com). This file is part of
12
12
OpenShot Video Editor (http://www.openshot.org), an open-source project
13
13
dedicated to delivering high quality video editing and animation solutions
14
14
to the world.
15
-
15
+
16
16
OpenShot Video Editor is free software: you can redistribute it and/or modify
17
17
it under the terms of the GNU General Public License as published by
18
18
the Free Software Foundation, either version 3 of the License, or
19
19
(at your option) any later version.
20
-
20
+
21
21
OpenShot Video Editor is distributed in the hope that it will be useful,
22
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
24
GNU General Public License for more details.
25
-
25
+
26
26
You should have received a copy of the GNU General Public License
27
27
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
28
28
"""
29
29
30
30
# SettingStore - class which allows getting/storing of settings, loading and saving to json
31
31
import os
32
32
33
- from PyQt5 .QtCore import QStandardPaths , QCoreApplication
34
- from PyQt5 .QtWidgets import QMessageBox
35
-
36
- from classes .logger import log
37
33
from classes import info
34
+ from classes .logger import log
38
35
from classes .json_data import JsonDataStore
39
36
40
37
41
38
def get_settings ():
42
- """ Get the current QApplication 's settings instance """
43
- return QCoreApplication . instance ().settings
39
+ """ Get the current application 's settings instance """
40
+ return SettingStore . get_app ().settings
44
41
45
42
46
43
class SettingStore (JsonDataStore ):
47
44
""" This class only allows setting pre-existing keys taken from default settings file, and merges user settings
48
45
on load, assumes default OS dir."""
49
46
50
- def __init__ (self ):
51
- JsonDataStore .__init__ (self )
47
+ @classmethod
48
+ def save_app (cls , app_reference ):
49
+ cls ._app = app_reference
50
+
51
+ @classmethod
52
+ def get_app (cls ):
53
+ if hasattr (cls , "_app" ):
54
+ return cls ._app
55
+ return None
56
+
57
+ def __init__ (self , parent = None ):
58
+ super ().__init__ ()
59
+ # Also keep track of our parent, if defined
60
+ if parent :
61
+ SettingStore .save_app (parent )
52
62
# Set the data type name for logging clarity (base class functions use this variable)
53
63
self .data_type = "user settings"
54
64
self .settings_filename = "openshot.settings"
@@ -72,8 +82,11 @@ def set(self, key, value):
72
82
if key in user_values :
73
83
user_values [key ]["value" ] = value
74
84
else :
75
- log .warn ("{} key '{}' not valid. The following are valid: {}" .format (self .data_type , key ,
76
- list (self ._data .keys ())))
85
+ log .warn (
86
+ "{} key '{}' not valid. The following are valid: {}" .format (
87
+ self .data_type , key ,
88
+ list (self ._data .keys ()),
89
+ ))
77
90
78
91
def load (self ):
79
92
""" Load user settings file from disk, merging with allowed settings in default settings file.
@@ -90,17 +103,16 @@ def load(self):
90
103
91
104
# Load user settings (if found)
92
105
if os .path .exists (os .fsencode (file_path )):
93
-
94
106
# Will raise exception to caller on failure to read
95
107
try :
96
108
user_settings = self .read_from_file (file_path )
97
109
except Exception as ex :
98
- log .error ("Error loading settings file: %s" % ex )
99
-
100
- _ = QCoreApplication .instance ()._tr
101
- QMessageBox .warning (None , _ ("Settings Error" ),
102
- _ ("Error loading settings file: %(file_path)s. Settings will be reset." ) % { "file_path" : file_path })
110
+ log .error ("Error loading settings file: %s" , ex )
103
111
user_settings = {}
112
+ app = SettingStore .get_app ()
113
+ if app :
114
+ # We have a parent, ask to show a message box
115
+ app .settings_load_error (file_path )
104
116
105
117
# Merge default and user settings, excluding settings not in default, Save settings
106
118
self ._data = self .merge_settings (default_settings , user_settings )
0 commit comments