Preferences File Behaviour
01 Dec 2020 06:57 - 01 Dec 2020 07:50 #190741
by phillc54
Preferences File Behaviour was created by phillc54
I have some strange behaviour when saving/loading preferences. I have the following functions in a module:
The reload function is called on startup and behaves correctly for both True and False.
After startup if the reload function is called then it behaves correctly.
After the save funcion is called, the Origin in the prefs file correctly reflects the state. Then when reload is called it gives a message in the terminal 'bool' object has no attribute 'lower' and the Origin in the preference file is always set to False as is the parent.origin variable.
All float, int and str preferences work correctly.
EDIT:
I converted the lines to the below and it works correctly:
EDIT 2: I should also add that I have several other bool preferences that are only loaded at startup and saved at shutdown and they all behave correctly.
Warning: Spoiler!
def save(parent):
print('\nSAVE FUNCTION')
print('origin before read =',parent.origin,type(parent.origin))
parent.origin = parent.w.ccenter.isChecked()
print('origin after read =',parent.origin,type(parent.origin))
print('save origin')
parent.w.PREFS_.putpref('Origin', parent.origin, bool, 'CONVERSATIONAL')
print('origin saved')
print('origin after saving =',parent.origin,type(parent.origin))
def reload(parent):
print('\nLOAD FUNCTION')
print('load origin')
parent.origin = parent.w.PREFS_.getpref('Origin', False, bool, 'CONVERSATIONAL')
print('origin loaded')
print('origin after loading =',parent.origin,type(parent.origin))
The reload function is called on startup and behaves correctly for both True and False.
After startup if the reload function is called then it behaves correctly.
After the save funcion is called, the Origin in the prefs file correctly reflects the state. Then when reload is called it gives a message in the terminal 'bool' object has no attribute 'lower' and the Origin in the preference file is always set to False as is the parent.origin variable.
Warning: Spoiler!
SAVE FUNCTION
origin before read = False <class 'bool'>
origin after read = True <class 'bool'>
save origin
origin saved
origin after saving = True <class 'bool'>
LOAD FUNCTION
load origin
'bool' object has no attribute 'lower'
origin loaded
origin after loading = False <class 'bool'>
All float, int and str preferences work correctly.
EDIT:
I converted the lines to the below and it works correctly:
Warning: Spoiler!
parent.w.PREFS_.putpref('Origin', int(parent.origin), int, 'CONVERSATIONAL')
parent.origin = bool(parent.w.PREFS_.getpref('Origin', False, int, 'CONVERSATIONAL'))
EDIT 2: I should also add that I have several other bool preferences that are only loaded at startup and saved at shutdown and they all behave correctly.
Last edit: 01 Dec 2020 07:50 by phillc54.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
02 Dec 2020 03:28 #190833
by cmorley
Replied by cmorley on topic Preferences File Behaviour
I'll try to look into this soon. Is this with python3?
Please Log in or Create an account to join the conversation.
02 Dec 2020 03:56 #190837
by phillc54
Replied by phillc54 on topic Preferences File Behaviour
Yes, but I haven't tried on python2. Not a big issue as the workaround does work well. If I get a chance today I will try on python2.
Please Log in or Create an account to join the conversation.
02 Dec 2020 05:15 #190839
by phillc54
Replied by phillc54 on topic Preferences File Behaviour
Identical behaviour on python2.
Please Log in or Create an account to join the conversation.
Moderators: cmorley
Time to create page: 0.071 seconds