Skip to content

Commit e2ba9f2

Browse files
committed
automatically load and save options just like any other user data
1 parent d4d8287 commit e2ba9f2

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

filmatyk/gui.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(self, debugMode=False, isOnLinux=False):
146146
self.dataManager = DataManager(self.getFilename(), VERSION)
147147
userdata = self.dataManager.load()
148148
# create the options manager
149-
self.options = Options()
149+
self.options = Options(userdata.options_json)
150150
# construct the window: first the notebook for tabbed view
151151
self.notebook = ttk.Notebook(root)
152152
self.notebook.grid(row=0, column=0, padx=5, pady=5, sticky=tk.NW)
@@ -255,7 +255,9 @@ def saveUserData(self):
255255
# if there is no need to save anything - stop right there too
256256
if not (
257257
any([db.isDirty for db in self.databases]) or
258-
any([ps.isDirty for ps in self.presenters])):
258+
any([ps.isDirty for ps in self.presenters]) or
259+
self.options.isDirty
260+
):
259261
return
260262
# construct the UserData object
261263
serialized_data = UserData(
@@ -265,7 +267,8 @@ def saveUserData(self):
265267
series_conf=self.presenters[1].storeToString(),
266268
series_data=self.databases[1].storeToString(),
267269
games_conf=self.presenters[2].storeToString(),
268-
games_data=self.databases[2].storeToString()
270+
games_data=self.databases[2].storeToString(),
271+
options_json=self.options.storeToString(),
269272
)
270273
# request the manager to save it
271274
self.dataManager.save(serialized_data)

filmatyk/userdata.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
translation of the old data format (as seen in the file) to the current format
2929
(as required by UserData and thus Main).
3030
31-
If a new version changes the UserData layout, *ALL* previous loaders have to be
32-
updated to return this new layout. Therefore it is best not to modify the order
33-
and names of UserData arguments.
31+
If a new version changes the UserData layout, the DataManager.save method must
32+
be updated to reflect that. Additionally, all previously registered loaders
33+
must be able to return the new object. When adding a new element to UserData,
34+
it should go without problems (just provide a default argument), but if a new
35+
layout removes some fields... this will need special handling - probably for
36+
*all* legacy loaders.
3437
"""
3538

3639
import os
@@ -49,6 +52,7 @@ def __init__(
4952
series_data='',
5053
games_conf='',
5154
games_data='',
55+
options_json='{}',
5256
is_empty=True
5357
):
5458
self.username = username
@@ -58,6 +62,7 @@ def __init__(
5862
self.series_data = series_data
5963
self.games_conf = games_conf
6064
self.games_data = games_data
65+
self.options_json = options_json
6166
self.is_empty = is_empty
6267

6368

@@ -97,6 +102,8 @@ def save(self, userData):
97102
user_file.write(self.version + '\n')
98103
user_file.write('#USERNAME\n')
99104
user_file.write(userData.username + '\n')
105+
user_file.write('#OPTIONS\n')
106+
user_file.write(userData.options_json + '\n')
100107
user_file.write('#MOVIES\n')
101108
user_file.write(userData.movies_conf + '\n')
102109
user_file.write(userData.movies_data + '\n')
@@ -212,3 +219,16 @@ def loader100b(user_data):
212219
games_conf=user_data[6],
213220
games_data=user_data[7]
214221
)
222+
223+
@DataManager.registerLoaderSince('1.0.0-beta.4')
224+
def loader100b4(user_data):
225+
return UserData(
226+
username=user_data[1],
227+
options_json=user_data[2],
228+
movies_conf=user_data[3],
229+
movies_data=user_data[4],
230+
series_conf=user_data[5],
231+
series_data=user_data[6],
232+
games_conf=user_data[7],
233+
games_data=user_data[8],
234+
)

0 commit comments

Comments
 (0)