Skip to content

Commit

Permalink
automatically load and save options just like any other user data
Browse files Browse the repository at this point in the history
  • Loading branch information
Noiredd committed May 20, 2020
1 parent d4d8287 commit e2ba9f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
9 changes: 6 additions & 3 deletions filmatyk/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(self, debugMode=False, isOnLinux=False):
self.dataManager = DataManager(self.getFilename(), VERSION)
userdata = self.dataManager.load()
# create the options manager
self.options = Options()
self.options = Options(userdata.options_json)
# construct the window: first the notebook for tabbed view
self.notebook = ttk.Notebook(root)
self.notebook.grid(row=0, column=0, padx=5, pady=5, sticky=tk.NW)
Expand Down Expand Up @@ -255,7 +255,9 @@ def saveUserData(self):
# if there is no need to save anything - stop right there too
if not (
any([db.isDirty for db in self.databases]) or
any([ps.isDirty for ps in self.presenters])):
any([ps.isDirty for ps in self.presenters]) or
self.options.isDirty
):
return
# construct the UserData object
serialized_data = UserData(
Expand All @@ -265,7 +267,8 @@ def saveUserData(self):
series_conf=self.presenters[1].storeToString(),
series_data=self.databases[1].storeToString(),
games_conf=self.presenters[2].storeToString(),
games_data=self.databases[2].storeToString()
games_data=self.databases[2].storeToString(),
options_json=self.options.storeToString(),
)
# request the manager to save it
self.dataManager.save(serialized_data)
Expand Down
26 changes: 23 additions & 3 deletions filmatyk/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
translation of the old data format (as seen in the file) to the current format
(as required by UserData and thus Main).
If a new version changes the UserData layout, *ALL* previous loaders have to be
updated to return this new layout. Therefore it is best not to modify the order
and names of UserData arguments.
If a new version changes the UserData layout, the DataManager.save method must
be updated to reflect that. Additionally, all previously registered loaders
must be able to return the new object. When adding a new element to UserData,
it should go without problems (just provide a default argument), but if a new
layout removes some fields... this will need special handling - probably for
*all* legacy loaders.
"""

import os
Expand All @@ -49,6 +52,7 @@ def __init__(
series_data='',
games_conf='',
games_data='',
options_json='{}',
is_empty=True
):
self.username = username
Expand All @@ -58,6 +62,7 @@ def __init__(
self.series_data = series_data
self.games_conf = games_conf
self.games_data = games_data
self.options_json = options_json
self.is_empty = is_empty


Expand Down Expand Up @@ -97,6 +102,8 @@ def save(self, userData):
user_file.write(self.version + '\n')
user_file.write('#USERNAME\n')
user_file.write(userData.username + '\n')
user_file.write('#OPTIONS\n')
user_file.write(userData.options_json + '\n')
user_file.write('#MOVIES\n')
user_file.write(userData.movies_conf + '\n')
user_file.write(userData.movies_data + '\n')
Expand Down Expand Up @@ -212,3 +219,16 @@ def loader100b(user_data):
games_conf=user_data[6],
games_data=user_data[7]
)

@DataManager.registerLoaderSince('1.0.0-beta.4')
def loader100b4(user_data):
return UserData(
username=user_data[1],
options_json=user_data[2],
movies_conf=user_data[3],
movies_data=user_data[4],
series_conf=user_data[5],
series_data=user_data[6],
games_conf=user_data[7],
games_data=user_data[8],
)

0 comments on commit e2ba9f2

Please sign in to comment.