Release 4.31.0
This commit is contained in:
parent
9e4bf95b33
commit
1ec6e6b1ff
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
version = __version__ = "4.30.0.28 Unreleased\nAdded ability to set icon for popup_get_file when icon is set as parameter, changed __version__ to be same as 'ver' (the shortened version number), added Window.set_cursor, changed install to use version instead of __version__, changed back __version__ to be the long-form of the version number so that installs from GitHub will work again, trying another version change, Multiline.print (and cprint) now autoscrolls, additional check for combo update to allow setting both disabled & readonly parms, docstring fix for Multiline.update, added main_get_debug_data, reformatted look and feel table, fixed spelling error suppress_popup, None as initial value for Input element treated as '', added patch for no titlebar on Mac if version < 8.6.10, fix for Spin.get not returning correct type, added default extension to FileSaveAs and SaveAs buttons, added readonly option to Spin, UserSettings object interface, enable user to set default value for UserSettings, MenuBar get colorful!, ButtonMenu added colors & fixed border depth, read_all_windows checks queue prior to going into mainloop, Multiline docstring fix, window.read check to see if thread message in queue first, added option to enable Mac patch for no_titlebar, renamed parts of UserSettings to prep for release, UserSettings delete item interface added, UserSetting removed adding entry and saving when no entry found"
|
||||
version = __version__ = "4.31.0 Released 13-Nov-2020"
|
||||
|
||||
__version__ = version.split()[0] # For PEP 396 and PEP 345
|
||||
|
||||
|
@ -16337,13 +16337,13 @@ class UserSettings:
|
|||
# to access the user settings without diarectly using the UserSettings class
|
||||
_default_for_function_interface = None # type: UserSettings
|
||||
|
||||
def __init__(self, filename=None, path=None):
|
||||
def __init__(self, filename=None, path=None, silent_on_error=False):
|
||||
"""
|
||||
User Settings
|
||||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
"""
|
||||
self.path = path
|
||||
|
@ -16351,6 +16351,7 @@ class UserSettings:
|
|||
self.full_filename = None
|
||||
self.dict = {}
|
||||
self.default_value = None
|
||||
self.silent_on_error = silent_on_error
|
||||
if filename is not None or path is not None:
|
||||
self.load(filename=filename, path=path)
|
||||
|
||||
|
@ -16374,13 +16375,14 @@ class UserSettings:
|
|||
self.default_value = default
|
||||
|
||||
|
||||
|
||||
def _compute_filename(self, filename=None, path=None):
|
||||
"""
|
||||
Creates the full filename given the path or the filename or both.
|
||||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
:return: Tuple with (full filename, path, filename)
|
||||
:rtype: Tuple[str, str, str]
|
||||
|
@ -16417,7 +16419,7 @@ class UserSettings:
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
"""
|
||||
cfull_filename, cpath, cfilename = self._compute_filename(filename=filename, path=path)
|
||||
|
@ -16441,7 +16443,7 @@ class UserSettings:
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
:return: The full pathname of the settings file that has both the path and filename combined.
|
||||
:rtype: (str)
|
||||
|
@ -16472,8 +16474,9 @@ class UserSettings:
|
|||
with open(self.full_filename, 'w') as f:
|
||||
json.dump(self.dict, f)
|
||||
except Exception as e:
|
||||
print('*** Error saving settings to file:***\n', self.full_filename, e)
|
||||
print(_create_error_message())
|
||||
if not self.silent_on_error:
|
||||
print('*** Error saving settings to file:***\n', self.full_filename, e)
|
||||
print(_create_error_message())
|
||||
return self.full_filename
|
||||
|
||||
|
||||
|
@ -16506,7 +16509,7 @@ class UserSettings:
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
"""
|
||||
if filename is not None or path is not None or (filename is None and path is None):
|
||||
|
@ -16514,8 +16517,9 @@ class UserSettings:
|
|||
try:
|
||||
os.remove(self.full_filename)
|
||||
except Exception as e:
|
||||
print('*** User settings delete filename warning ***\n', e)
|
||||
print(_create_error_message())
|
||||
if not self.silent_on_error:
|
||||
print('*** User settings delete filename warning ***\n', e)
|
||||
print(_create_error_message())
|
||||
self.dict = {}
|
||||
|
||||
|
||||
|
@ -16546,8 +16550,9 @@ class UserSettings:
|
|||
with open(self.full_filename, 'r') as f:
|
||||
self.dict = json.load(f)
|
||||
except Exception as e:
|
||||
print('*** Error reading settings from file: ***\n', self.full_filename, e)
|
||||
print(_create_error_message())
|
||||
if not self.silent_on_error:
|
||||
print('*** Error reading settings from file: ***\n', self.full_filename, e)
|
||||
print(_create_error_message())
|
||||
|
||||
return self.dict
|
||||
|
||||
|
@ -16558,7 +16563,7 @@ class UserSettings:
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str or None)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str or None)
|
||||
"""
|
||||
cfull_filename, cpath, cfilename = self._compute_filename(filename=filename, path=path)
|
||||
|
@ -16573,7 +16578,7 @@ class UserSettings:
|
|||
then a default filename will be used.
|
||||
After value has been deleted, the settings file is written to disk.
|
||||
|
||||
:param key: Setting to be saved. Can be any valid dictionary key type (hashable)
|
||||
:param key: Setting to be deleted. Can be any valid dictionary key type (i.e. must be hashable)
|
||||
:type key: (Any)
|
||||
"""
|
||||
if self.full_filename is None:
|
||||
|
@ -16583,8 +16588,9 @@ class UserSettings:
|
|||
del self.dict[key]
|
||||
self.save()
|
||||
else:
|
||||
print('*** Warning - key ', key, ' not found in settings ***\n')
|
||||
print(_create_error_message())
|
||||
if not self.silent_on_error:
|
||||
print('*** Warning - key ', key, ' not found in settings ***\n')
|
||||
print(_create_error_message())
|
||||
|
||||
|
||||
def set(self, key, value):
|
||||
|
@ -16609,9 +16615,8 @@ class UserSettings:
|
|||
"""
|
||||
Returns the value of a specified setting. If the setting is not found in the settings dictionary, then
|
||||
the user specified default value will be returned. It no default is specified and nothing is found, then
|
||||
None is returned. If the key isn't in the dictionary, then it will be added and the settings file saved.
|
||||
If no filename has been specified up to this point, then a default filename will be assigned and used.
|
||||
The settings are SAVED prior to returning.
|
||||
the "default value" is returned. This default can be specified in this call, or previously defined
|
||||
by calling set_default. If nothing specified now or previously, then None is returned as default.
|
||||
|
||||
:param key: Key used to lookup the setting in the settings dictionary
|
||||
:type key: (Any)
|
||||
|
@ -16641,8 +16646,10 @@ class UserSettings:
|
|||
Returns the current settings dictionary. If you've not setup the filename for the
|
||||
settings, a default one will be used and then read.
|
||||
|
||||
Note that you can display the dictionary in text format by printing the object itself.
|
||||
|
||||
:return: The current settings dictionary
|
||||
:rtype: (dict)
|
||||
:rtype: Dict
|
||||
"""
|
||||
if self.full_filename is None:
|
||||
self.set_location()
|
||||
|
@ -16712,7 +16719,7 @@ def user_settings_filename(filename=None, path=None):
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str)
|
||||
:return: The full pathname of the settings file that has both the path and filename combined.
|
||||
:rtype: (str)
|
||||
|
@ -16731,7 +16738,7 @@ def user_settings_delete_filename(filename=None, path=None):
|
|||
|
||||
:param filename: The name of the file to use. Can be a full path and filename or just filename
|
||||
:type filename: (str)
|
||||
:param path: The folder that the settings file will be stored in. Do no include the filename.
|
||||
:param path: The folder that the settings file will be stored in. Do not include the filename.
|
||||
:type path: (str)
|
||||
"""
|
||||
settings = UserSettings._default_for_function_interface
|
||||
|
@ -16836,6 +16843,7 @@ def user_settings_file_exists(filename=None, path=None):
|
|||
return settings.exists(filename=filename, path=path)
|
||||
|
||||
|
||||
|
||||
def user_settings_write_new_dictionary(settings_dict):
|
||||
"""
|
||||
Writes a specified dictionary to the currently defined settings filename.
|
||||
|
@ -16847,6 +16855,17 @@ def user_settings_write_new_dictionary(settings_dict):
|
|||
settings.write_new_dictionary(settings_dict)
|
||||
|
||||
|
||||
def user_settings_silent_on_error(silent_on_error=False):
|
||||
"""
|
||||
Used to control the display of error messages. By default, error messages are displayed to stdout.
|
||||
|
||||
:param silent_on_error: If True then all error messages are silenced (not displayed on the console)
|
||||
:type silent_on_error: (bool)
|
||||
"""
|
||||
settings = UserSettings._default_for_function_interface
|
||||
settings.silent_on_error = silent_on_error
|
||||
|
||||
|
||||
def user_settings():
|
||||
"""
|
||||
Returns the current settings dictionary. If you've not setup the filename for the
|
||||
|
|
|
@ -27,6 +27,7 @@ Button(button_text="",
|
|||
tooltip=None,
|
||||
file_types=(('ALL Files', '*.*'),),
|
||||
initial_folder=None,
|
||||
default_extension="",
|
||||
disabled=False,
|
||||
change_submits=False,
|
||||
enable_events=False,
|
||||
|
@ -61,6 +62,7 @@ Parameter Descriptions:
|
|||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| Tuple[Tuple[str, str], ...] | file_types | the filetypes that will be used to match files. To indicate all files: (("ALL Files", "*.*"),). Note - NOT SUPPORTED ON MAC |
|
||||
| str | initial_folder | starting path for folders and files |
|
||||
| str | default_extension | If no extension entered by user, add this to filename (only used in saveas dialogs) |
|
||||
| bool | disabled | If True button will be created disabled |
|
||||
| bool | change_submits | DO NOT USE. Only listed for backwards compat - Use enable_events instead |
|
||||
| bool | enable_events | Turns on the element specific events. If this button is a target, should it generate an event when filled in |
|
||||
|
@ -374,7 +376,11 @@ ButtonMenu(button_text,
|
|||
size=(None, None),
|
||||
auto_size_button=None,
|
||||
button_color=None,
|
||||
text_color=None,
|
||||
background_color=None,
|
||||
disabled_text_color=None,
|
||||
font=None,
|
||||
item_font=None,
|
||||
pad=None,
|
||||
key=None,
|
||||
k=None,
|
||||
|
@ -387,25 +393,29 @@ Parameter Descriptions:
|
|||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| str | button_text | Text to be displayed on the button |
|
||||
| List[List[str]] | menu_def | A list of lists of Menu items to show when this element is clicked. See docs for format as they are the same for all menu types |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| bool | disabled | If True button will be created disabled |
|
||||
| str | image_filename | image filename if there is a button image. GIFs and PNGs only. |
|
||||
| Union[bytes, str] | image_data | Raw or Base64 representation of the image to put on button. Choose either filename or data |
|
||||
| (int, int) | image_size | Size of the image in pixels (width, height) |
|
||||
| int | image_subsample | amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc |
|
||||
| int | border_width | width of border around button in pixels |
|
||||
| (int, int) | size | (width, height) of the button in characters wide, rows high |
|
||||
| bool | auto_size_button | if True the button size is sized to fit the text |
|
||||
| Tuple[str, str] or str | button_color | of button. Easy to remember which is which if you say "ON" between colors. "red" on "green" |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element (left/right, top/bottom) or ((left, right), (top, bottom)) |
|
||||
| Union[str, int, tuple, object] | key | Used with window.FindElement and with return values to uniquely identify this element to uniquely identify this element |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| bool | tearoff | Determines if menus should allow them to be torn off |
|
||||
| bool | visible | set visibility state of the element |
|
||||
| Any | metadata | User metadata that can be set to ANYTHING |
|
||||
| str | button_text | Text to be displayed on the button |
|
||||
| List[List[str]] | menu_def | A list of lists of Menu items to show when this element is clicked. See docs for format as they are the same for all menu types |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| bool | disabled | If True button will be created disabled |
|
||||
| str | image_filename | image filename if there is a button image. GIFs and PNGs only. |
|
||||
| Union[bytes, str] | image_data | Raw or Base64 representation of the image to put on button. Choose either filename or data |
|
||||
| (int, int) | image_size | Size of the image in pixels (width, height) |
|
||||
| int | image_subsample | amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc |
|
||||
| int | border_width | width of border around button in pixels |
|
||||
| (int, int) | size | (width, height) of the button in characters wide, rows high |
|
||||
| bool | auto_size_button | if True the button size is sized to fit the text |
|
||||
| Tuple[str, str] or str | button_color | of button. Easy to remember which is which if you say "ON" between colors. "red" on "green" |
|
||||
| str | background_color | color of the background |
|
||||
| str | text_color | element's text color. Can be in #RRGGBB format or a color name "black" |
|
||||
| str | disabled_text_color | color to use for text when item is disabled. Can be in #RRGGBB format or a color name "black" |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| Union[str, Tuple[str, int]] | item_font | specifies the font family, size, etc, for the menu items |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element (left/right, top/bottom) or ((left, right), (top, bottom)) |
|
||||
| Union[str, int, tuple, object] | key | Used with window.FindElement and with return values to uniquely identify this element to uniquely identify this element |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| bool | tearoff | Determines if menus should allow them to be torn off |
|
||||
| bool | visible | set visibility state of the element |
|
||||
| Any | metadata | User metadata that can be set to ANYTHING |
|
||||
|
||||
### Click
|
||||
|
||||
|
@ -4081,6 +4091,8 @@ Parameter Descriptions:
|
|||
```
|
||||
Menu(menu_definition,
|
||||
background_color=None,
|
||||
text_color=None,
|
||||
disabled_text_color=None,
|
||||
size=(None, None),
|
||||
tearoff=False,
|
||||
font=None,
|
||||
|
@ -4095,16 +4107,18 @@ Parameter Descriptions:
|
|||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| List[List[Tuple[str, List[str]]] | menu_definition | ??? |
|
||||
| str | background_color | color of the background |
|
||||
| (int, int) | size | Not used in the tkinter port |
|
||||
| bool | tearoff | if True, then can tear the menu off from the window ans use as a floating window. Very cool effect |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element (left/right, top/bottom) or ((left, right), (top, bottom)) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| Union[str, int, tuple, object] | key | Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| bool | visible | set visibility state of the element |
|
||||
| Any | metadata | User metadata that can be set to ANYTHING |
|
||||
| List[List[Tuple[str, List[str]]] | menu_definition | The Menu definition specified using lists (docs explain the format) |
|
||||
| str | background_color | color of the background |
|
||||
| str | text_color | element's text color. Can be in #RRGGBB format or a color name "black" |
|
||||
| str | disabled_text_color | color to use for text when item is disabled. Can be in #RRGGBB format or a color name "black" |
|
||||
| (int, int) | size | Not used in the tkinter port |
|
||||
| bool | tearoff | if True, then can tear the menu off from the window ans use as a floating window. Very cool effect |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element (left/right, top/bottom) or ((left, right), (top, bottom)) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| Union[str, int, tuple, object] | key | Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| bool | visible | set visibility state of the element |
|
||||
| Any | metadata | User metadata that can be set to ANYTHING |
|
||||
|
||||
### SetFocus
|
||||
|
||||
|
@ -4355,9 +4369,9 @@ Parameter Descriptions:
|
|||
| bool | write_only | If True then no entry will be added to the values dictionary when the window is read |
|
||||
| bool | auto_refresh | If True then anytime the element is updated, the window will be refreshed so that the change is immediately displayed |
|
||||
| bool | reroute_stdout | If True then all output to stdout will be output to this element |
|
||||
| bool | reroute_stderr | If True then all output to stdout will be output to this element |
|
||||
| bool | reroute_stderr | If True then all output to stderr will be output to this element |
|
||||
| bool | reroute_cprint | If True your cprint calls will output to this element. It's the same as you calling cprint_set_output_destination |
|
||||
| bool | echo_stdout_stderr | If True then output to stdout will be output to this element AND also to the normal console location |
|
||||
| bool | echo_stdout_stderr | If True then output to stdout and stderr will be output to this element AND also to the normal console location |
|
||||
| bool | focus | if True initial focus will go to this element |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element (left/right, top/bottom) or ((left, right), (top, bottom)) |
|
||||
|
@ -6267,6 +6281,7 @@ Spin(values,
|
|||
disabled=False,
|
||||
change_submits=False,
|
||||
enable_events=False,
|
||||
readonly=False,
|
||||
size=(None, None),
|
||||
auto_size_text=None,
|
||||
font=None,
|
||||
|
@ -6289,6 +6304,7 @@ Parameter Descriptions:
|
|||
| bool | disabled | set disable state |
|
||||
| bool | change_submits | DO NOT USE. Only listed for backwards compat - Use enable_events instead |
|
||||
| bool | enable_events | Turns on the element specific events. Spin events happen when an item changes |
|
||||
| bool | readonly | Turns on the element specific events. Spin events happen when an item changes |
|
||||
| (int, int) | size | (width, height) width = characters-wide, height = rows-high |
|
||||
| bool | auto_size_text | if True will size the element to match the length of the text |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
|
@ -6344,11 +6360,15 @@ Parameter Descriptions:
|
|||
### Update
|
||||
|
||||
Changes some of the settings for the Spin Element. Must call `Window.Read` or `Window.Finalize` prior
|
||||
Note that the state can be in 3 states only.... enabled, disabled, readonly even
|
||||
though more combinations are available. The easy way to remember is that if you
|
||||
change the readonly parameter then you are enabling the element.
|
||||
|
||||
```
|
||||
Update(value=None,
|
||||
values=None,
|
||||
disabled=None,
|
||||
readonly=None,
|
||||
visible=None)
|
||||
```
|
||||
|
||||
|
@ -6358,7 +6378,8 @@ Parameter Descriptions:
|
|||
|--|--|--|
|
||||
| Any | value | set the current value from list of choices |
|
||||
| List[Any] | values | set available choices |
|
||||
| bool | disabled | disable or enable state of the element |
|
||||
| bool | disabled | disable. Note disabled and readonly cannot be mixed. It must be one OR the other |
|
||||
| bool | readonly | make element readonly. Note disabled and readonly cannot be mixed. It must be one OR the other |
|
||||
| bool | visible | control visibility of element |
|
||||
|
||||
### bind
|
||||
|
@ -6509,11 +6530,15 @@ unhide_row()
|
|||
### update
|
||||
|
||||
Changes some of the settings for the Spin Element. Must call `Window.Read` or `Window.Finalize` prior
|
||||
Note that the state can be in 3 states only.... enabled, disabled, readonly even
|
||||
though more combinations are available. The easy way to remember is that if you
|
||||
change the readonly parameter then you are enabling the element.
|
||||
|
||||
```
|
||||
update(value=None,
|
||||
values=None,
|
||||
disabled=None,
|
||||
readonly=None,
|
||||
visible=None)
|
||||
```
|
||||
|
||||
|
@ -6523,7 +6548,8 @@ Parameter Descriptions:
|
|||
|--|--|--|
|
||||
| Any | value | set the current value from list of choices |
|
||||
| List[Any] | values | set available choices |
|
||||
| bool | disabled | disable or enable state of the element |
|
||||
| bool | disabled | disable. Note disabled and readonly cannot be mixed. It must be one OR the other |
|
||||
| bool | readonly | make element readonly. Note disabled and readonly cannot be mixed. It must be one OR the other |
|
||||
| bool | visible | control visibility of element |
|
||||
|
||||
## StatusBar Element
|
||||
|
@ -8730,6 +8756,234 @@ Unhides (makes visible again) the row container that the Element is located on.
|
|||
unhide_row()
|
||||
```
|
||||
|
||||
## UserSettings (Class interface to User Settings APIs... can also use the function call interface)
|
||||
|
||||
User Settings
|
||||
|
||||
```
|
||||
UserSettings(filename=None,
|
||||
path=None,
|
||||
silent_on_error=False)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| (str or None) | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
|
||||
### delete_entry
|
||||
|
||||
Deletes an individual entry. If no filename has been specified up to this point,
|
||||
then a default filename will be used.
|
||||
After value has been deleted, the settings file is written to disk.
|
||||
|
||||
```
|
||||
delete_entry(key)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| Any | key | Setting to be deleted. Can be any valid dictionary key type (i.e. must be hashable) |
|
||||
|
||||
### delete_file
|
||||
|
||||
Deltes the filename and path for your settings file. Either paramter can be optional.
|
||||
If you don't choose a path, one is provided for you that is OS specific
|
||||
Windows path default = users/name/AppData/Local/PySimpleGUI/settings.
|
||||
If you don't choose a filename, your application's filename + '.json' will be used
|
||||
Also sets your current dictionary to a blank one.
|
||||
|
||||
```
|
||||
delete_file(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| (str or None) | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
|
||||
### exists
|
||||
|
||||
Check if a particular settings file exists. Returns True if file exists
|
||||
|
||||
```
|
||||
exists(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| (str or None) | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
|
||||
### get
|
||||
|
||||
Returns the value of a specified setting. If the setting is not found in the settings dictionary, then
|
||||
the user specified default value will be returned. It no default is specified and nothing is found, then
|
||||
the "default value" is returned. This default can be specified in this call, or previously defined
|
||||
by calling set_default. If nothing specified now or previously, then None is returned as default.
|
||||
|
||||
```
|
||||
get(key, default=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| Any | key | Key used to lookup the setting in the settings dictionary |
|
||||
| Any | default | Value to use should the key not be found in the dictionary |
|
||||
| (Any) | **RETURN** | Value of specified settings
|
||||
|
||||
### get_dict
|
||||
|
||||
Returns the current settings dictionary. If you've not setup the filename for the
|
||||
settings, a default one will be used and then read.
|
||||
|
||||
Note that you can display the dictionary in text format by printing the object itself.
|
||||
|
||||
`get_dict()`
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|---|---|---|
|
||||
|<type>| **return** | The current settings dictionary |
|
||||
|
||||
### get_filename
|
||||
|
||||
Sets the filename and path for your settings file. Either paramter can be optional.
|
||||
|
||||
If you don't choose a path, one is provided for you that is OS specific
|
||||
Windows path default = users/name/AppData/Local/PySimpleGUI/settings.
|
||||
|
||||
If you don't choose a filename, your application's filename + '.json' will be used.
|
||||
|
||||
Normally the filename and path are split in the user_settings calls. However for this call they
|
||||
can be combined so that the filename contains both the path and filename.
|
||||
|
||||
```
|
||||
get_filename(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| (str or None) | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
| (str) | **RETURN** | The full pathname of the settings file that has both the path and filename combined.
|
||||
|
||||
### load
|
||||
|
||||
Specifies the path and filename to use for the settings and reads the contents of the file.
|
||||
The filename can be a full filename including a path, or the path can be specified separately.
|
||||
If no filename is specified, then the caller's filename will be used with the extension ".json"
|
||||
|
||||
```
|
||||
load(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | Filename to load settings from (and save to in the future) |
|
||||
| (str or None) | path | Path to the file. Defaults to a specific folder depending on the operating system |
|
||||
| (dict) | **RETURN** | The settings dictionary (i.e. all settings)
|
||||
|
||||
### read
|
||||
|
||||
Reads settings file and returns the dictionary.
|
||||
|
||||
`read()`
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|---|---|---|
|
||||
|<type>| **return** | settings dictionary |
|
||||
|
||||
### save
|
||||
|
||||
Saves the current settings dictionary. If a filename or path is specified in the call, then it will override any
|
||||
previously specitfied filename to create a new settings file. The settings dictionary is then saved to the newly defined file.
|
||||
|
||||
```
|
||||
save(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The fFilename to save to. Can specify a path or just the filename. If no filename specified, then the caller's filename will be used. |
|
||||
| (str or None) | path | The (optional) path to use to save the file. |
|
||||
| (str) | **RETURN** | The full path and filename used to save the settings
|
||||
|
||||
### set
|
||||
|
||||
Sets an individual setting to the specified value. If no filename has been specified up to this point,
|
||||
then a default filename will be used.
|
||||
After value has been modified, the settings file is written to disk.
|
||||
|
||||
```
|
||||
set(key, value)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| Any | key | Setting to be saved. Can be any valid dictionary key type |
|
||||
| Any | value | Value to save as the setting's value. Can be anything |
|
||||
|
||||
### set_default_value
|
||||
|
||||
Set the value that will be returned if a requested setting is not found
|
||||
|
||||
```
|
||||
set_default_value(default)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| Any | default | value to be returned if a setting is not found in the settings dictionary |
|
||||
|
||||
### set_location
|
||||
|
||||
Sets the location of the settings file
|
||||
|
||||
```
|
||||
set_location(filename=None, path=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| (str or None) | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| (str or None) | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
|
||||
### write_new_dictionary
|
||||
|
||||
Writes a specified dictionary to the currently defined settings filename.
|
||||
|
||||
```
|
||||
write_new_dictionary(settings_dict)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| dict | settings_dict | The dictionary to be written to the currently defined settings file |
|
||||
|
||||
## Window
|
||||
|
||||
Represents a single Window
|
||||
|
@ -10318,6 +10572,7 @@ FileSaveAs(button_text="Save As...",
|
|||
target=(555666777, -1),
|
||||
file_types=(('ALL Files', '*.*'),),
|
||||
initial_folder=None,
|
||||
default_extension="",
|
||||
disabled=False,
|
||||
tooltip=None,
|
||||
size=(None, None),
|
||||
|
@ -10336,19 +10591,21 @@ Parameter Descriptions:
|
|||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| str | button_text | text in the button (Default value = 'Save As...') |
|
||||
| Tuple[Tuple[str, str], ...] | target | key or (row,col) target for the button (Default value = (ThisRow, -1)) :param file_types: (Default value = (("ALL Files", "*.*"))) |
|
||||
| bool | initial_folder | starting path for folders and files :param disabled: set disable state for element (Default = False) |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| (int, int) | size | (w,h) w=characters-wide, h=rows-high |
|
||||
| bool | auto_size_button | True if button size is determined by button text |
|
||||
| Tuple[str, str] or str | button_color | button color (foreground, background) |
|
||||
| bool | change_submits | If True, pressing Enter key submits window (Default = False) |
|
||||
| bool | enable_events | Turns on the element specific events.(Default = False) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element in pixels (left/right, top/bottom) |
|
||||
| Union[str, int, tuple, object] | key | key for uniquely identify this element (for window.FindElement) |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| str | button_text | text in the button (Default value = 'Save As...') |
|
||||
| Tuple[Tuple[str, str], ...] | target | key or (row,col) target for the button (Default value = (ThisRow, -1)) :param file_types: (Default value = (("ALL Files", "*.*"))) |
|
||||
| str | default_extension | If no extension entered by user, add this to filename (only used in saveas dialogs) |
|
||||
| str | initial_folder | starting path for folders and files |
|
||||
| bool | disabled | set disable state for element (Default = False) |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| (int, int) | size | (w,h) w=characters-wide, h=rows-high |
|
||||
| bool | auto_size_button | True if button size is determined by button text |
|
||||
| Tuple[str, str] or str | button_color | button color (foreground, background) |
|
||||
| bool | change_submits | If True, pressing Enter key submits window (Default = False) |
|
||||
| bool | enable_events | Turns on the element specific events.(Default = False) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element in pixels (left/right, top/bottom) |
|
||||
| Union[str, int, tuple, object] | key | key for uniquely identify this element (for window.FindElement) |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| (Button) | **RETURN** | returns a button
|
||||
|
||||
Allows browsing of multiple files. File list is returned as a single list with the delimeter defined using the variable
|
||||
|
@ -10743,6 +11000,7 @@ SaveAs(button_text="Save As...",
|
|||
target=(555666777, -1),
|
||||
file_types=(('ALL Files', '*.*'),),
|
||||
initial_folder=None,
|
||||
default_extension="",
|
||||
disabled=False,
|
||||
tooltip=None,
|
||||
size=(None, None),
|
||||
|
@ -10761,19 +11019,21 @@ Parameter Descriptions:
|
|||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| str | button_text | text in the button (Default value = 'Save As...') |
|
||||
| Tuple[Tuple[str, str], ...] | target | key or (row,col) target for the button (Default value = (ThisRow, -1)) :param file_types: (Default value = (("ALL Files", "*.*"))) |
|
||||
| bool | initial_folder | starting path for folders and files :param disabled: set disable state for element (Default = False) |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| (int, int) | size | (w,h) w=characters-wide, h=rows-high |
|
||||
| bool | auto_size_button | True if button size is determined by button text |
|
||||
| Tuple[str, str] or str | button_color | button color (foreground, background) |
|
||||
| bool | change_submits | If True, pressing Enter key submits window (Default = False) |
|
||||
| bool | enable_events | Turns on the element specific events.(Default = False) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element in pixels (left/right, top/bottom) |
|
||||
| Union[str, int, tuple, object] | key | key for uniquely identify this element (for window.FindElement) |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| str | button_text | text in the button (Default value = 'Save As...') |
|
||||
| Tuple[Tuple[str, str], ...] | target | key or (row,col) target for the button (Default value = (ThisRow, -1)) :param file_types: (Default value = (("ALL Files", "*.*"))) |
|
||||
| str | default_extension | If no extension entered by user, add this to filename (only used in saveas dialogs) |
|
||||
| str | initial_folder | starting path for folders and files |
|
||||
| bool | disabled | set disable state for element (Default = False) |
|
||||
| str | tooltip | text, that will appear when mouse hovers over the element |
|
||||
| (int, int) | size | (w,h) w=characters-wide, h=rows-high |
|
||||
| bool | auto_size_button | True if button size is determined by button text |
|
||||
| Tuple[str, str] or str | button_color | button color (foreground, background) |
|
||||
| bool | change_submits | If True, pressing Enter key submits window (Default = False) |
|
||||
| bool | enable_events | Turns on the element specific events.(Default = False) |
|
||||
| Union[str, Tuple[str, int]] | font | specifies the font family, size, etc |
|
||||
| (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | pad | Amount of padding to put around element in pixels (left/right, top/bottom) |
|
||||
| Union[str, int, tuple, object] | key | key for uniquely identify this element (for window.FindElement) |
|
||||
| Union[str, int, tuple, object] | k | Same as the Key. You can use either k or key. Which ever is set will be used. |
|
||||
| (Button) | **RETURN** | returns a button
|
||||
|
||||
```
|
||||
|
@ -13672,7 +13932,8 @@ SetOptions(icon=None,
|
|||
suppress_error_popups=None,
|
||||
suppress_raise_key_errors=None,
|
||||
suppress_key_guessing=None,
|
||||
enable_treeview_869_patch=None)
|
||||
enable_treeview_869_patch=None,
|
||||
enable_mac_notitlebar_patch=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
@ -13719,6 +13980,7 @@ Parameter Descriptions:
|
|||
| bool | suppress_raise_key_errors | If True then key errors won't be raised (you'll still get popup error) |
|
||||
| bool | suppress_key_guessing | If True then key errors won't try and find closest matches for you |
|
||||
| bool | enable_treeview_869_patch | If True, then will use the treeview color patch for tk 8.6.9 |
|
||||
| bool | enable_mac_notitlebar_patch | If True then Windows with no titlebar use an alternative technique when tkinter version < 8.6.10 |
|
||||
| None | **RETURN** | None
|
||||
|
||||
## The Test Harness
|
||||
|
@ -14044,7 +14306,7 @@ Parameter Descriptions:
|
|||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| str | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| str | path | The folder that the settings file will be stored in. Do no include the filename. |
|
||||
| str | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
|
||||
Determines if a settings file exists. If so a boolean True is returned.
|
||||
If either a filename or a path is not included, then the appropriate default
|
||||
|
@ -14081,7 +14343,7 @@ Parameter Descriptions:
|
|||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| str | filename | The name of the file to use. Can be a full path and filename or just filename |
|
||||
| str | path | The folder that the settings file will be stored in. Do no include the filename. |
|
||||
| str | path | The folder that the settings file will be stored in. Do not include the filename. |
|
||||
| (str) | **RETURN** | The full pathname of the settings file that has both the path and filename combined.
|
||||
|
||||
Returns the value of a specified setting. If the setting is not found in the settings dictionary, then
|
||||
|
@ -14148,6 +14410,18 @@ Parameter Descriptions:
|
|||
| Any | key | Setting to be saved. Can be any valid dictionary key type |
|
||||
| Any | value | Value to save as the setting's value. Can be anything |
|
||||
|
||||
Used to control the display of error messages. By default, error messages are displayed to stdout.
|
||||
|
||||
```
|
||||
user_settings_silent_on_error(silent_on_error=False)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
||||
|Type|Name|Meaning|
|
||||
|--|--|--|
|
||||
| bool | silent_on_error | If True then all error messages are silenced (not displayed on the console) |
|
||||
|
||||
Writes a specified dictionary to the currently defined settings filename.
|
||||
|
||||
```
|
||||
|
@ -14317,7 +14591,8 @@ set_options(icon=None,
|
|||
suppress_error_popups=None,
|
||||
suppress_raise_key_errors=None,
|
||||
suppress_key_guessing=None,
|
||||
enable_treeview_869_patch=None)
|
||||
enable_treeview_869_patch=None,
|
||||
enable_mac_notitlebar_patch=None)
|
||||
```
|
||||
|
||||
Parameter Descriptions:
|
||||
|
@ -14364,6 +14639,7 @@ Parameter Descriptions:
|
|||
| bool | suppress_raise_key_errors | If True then key errors won't be raised (you'll still get popup error) |
|
||||
| bool | suppress_key_guessing | If True then key errors won't try and find closest matches for you |
|
||||
| bool | enable_treeview_869_patch | If True, then will use the treeview color patch for tk 8.6.9 |
|
||||
| bool | enable_mac_notitlebar_patch | If True then Windows with no titlebar use an alternative technique when tkinter version < 8.6.10 |
|
||||
| None | **RETURN** | None
|
||||
|
||||
## Old Themes (Look and Feel) - Replaced by theme()
|
||||
|
|
217
docs/index.md
217
docs/index.md
|
@ -5859,7 +5859,16 @@ There have already been some demo programs written that use JSON files to store
|
|||
|
||||
User settings are stored in a Python dictionary which is saved to / loaded from disk. Individual settings are thus keys into a dictionary. You do not need to explicitly read nor write the file. Changing any entry will cause the file to be saved. Reading any entry will cause the file to be read if it hasn't already been read.
|
||||
|
||||
## List of Calls
|
||||
## Two Interfaces
|
||||
|
||||
There are 2 ways to access User Settings
|
||||
|
||||
1. User Settings function calls
|
||||
2. The `UserSettings` class
|
||||
|
||||
They both offer the same basic operations. The class interface has an added benefit of being able to access the individual settings using the same syntax as Python dictionary.
|
||||
|
||||
## List of Calls for Function Interface
|
||||
|
||||
|Function|Description|
|
||||
| --- | --- |
|
||||
|
@ -5974,6 +5983,102 @@ One of the situations where you may want to explicitly read/load the settings fi
|
|||
|
||||
Like so much of PySimpleGUI, as much as possible is automatically done on your behalf. This includes the requirement of saving and loading your settings file. Even naming your settings file is optional.
|
||||
|
||||
## The `UserSettings` Class Interface
|
||||
|
||||
The `UserSettings` class makes working with settings look like a Python dictionary. The familiar [ ] syntax is used to read, write and delete entries.
|
||||
|
||||
### Creating a `UserSettings` Object
|
||||
|
||||
The first step is to create your setting object. The parameters are the same as calling the `user_settings_filename` function. If you want to use the default values, then leave the parameters unchanged.
|
||||
|
||||
```python
|
||||
settings = sg.UserSettings()
|
||||
```
|
||||
|
||||
This is the same as calling `sg.user_settings_filename()`
|
||||
|
||||
### Reading, Writing, and Deleting an Individual Settings Using [ ] Syntax
|
||||
|
||||
The first operation will be to create the User Settings object.
|
||||
|
||||
```python
|
||||
settings = sg.UserSettings()
|
||||
```
|
||||
|
||||
To read a setting the dictionary-style [ ] syntax is used. If the item's name is `'-item-'`, then reading the value is achieved by writing
|
||||
|
||||
```python
|
||||
item_value = settings['-item-']
|
||||
```
|
||||
|
||||
Writing the setting is the same syntax except the expression is reversed.
|
||||
|
||||
```python
|
||||
settings['-item-'] = new_value
|
||||
```
|
||||
|
||||
To delete an item, again the dictionary style syntax is used.
|
||||
|
||||
```python
|
||||
del settings['-item-']
|
||||
```
|
||||
|
||||
You can also call the delete_entry method to delete the entry.
|
||||
|
||||
```python
|
||||
settings.delete_entry('-item-')
|
||||
```
|
||||
|
||||
### `UserSettings` Methods
|
||||
|
||||
You'll find all of the `UserSettings` methods available to you detailed in the Call Reference documentation.
|
||||
|
||||
One operation in particular that is not achievable using the [ ] notation is a "get" operation with a default value. For dictionaries, this method is `get` and for the `UserSettings` class the method is also called `get`. They both have an optional second parameter that represents a "default value" should the key not be found in the dictionary.
|
||||
|
||||
If you would like a setting with key `'-item-'` to return an empty string `''` instead of `None` if they key isn't found, then you can use this code to achieve that:
|
||||
|
||||
```python
|
||||
value = settings.get('-item-', '')
|
||||
```
|
||||
|
||||
It's the same kind of syntax that you're used to using with dictionaries.
|
||||
|
||||
### Default Value
|
||||
|
||||
Normally the default value will be `None` if a key is not found and you get the value of the entry using the bracket format:
|
||||
|
||||
```python
|
||||
item_value = settings['-item-']
|
||||
```
|
||||
|
||||
You can change the default value by calling `settings.set_default_value(new_default)`. This will set the default value to return in the case when no key is found. Note that an exception is not raised when there is a key error (see next section on error handling). Instead, the default value is returned with a warning displayed.
|
||||
|
||||
## Displaying the Settings Dictionary
|
||||
|
||||
The class interface makes it easy to dump out the dictionary. If you print the UserSettings object you'll get a printout of the dictionary.
|
||||
|
||||
Note that you'll need to "load" the settings from disk if you haven't performed any operations on the settings.
|
||||
|
||||
```python
|
||||
settings = sg.UserSettings()
|
||||
settings.load()
|
||||
print(settings)
|
||||
```
|
||||
|
||||
If you were to print the dictionary after creating the object, then the `load` is not needed
|
||||
|
||||
```python
|
||||
settings = sg.UserSettings()
|
||||
print(settings['-item-'])
|
||||
print(settings)
|
||||
```
|
||||
|
||||
To print the dictionary using the function call interface:
|
||||
|
||||
```python
|
||||
print(sg.user_settings())
|
||||
```
|
||||
|
||||
## Error Handling for User Settings
|
||||
|
||||
From a GUI perspective, user settings are not critical to the GUI operations itself. There is nothing about settings that will cause your window to not function. As a result, errors that occur in the User Settings are "soft errors". An error message is displayed along with information about how you called the function, when possible, and then execution continues.
|
||||
|
@ -5987,10 +6092,10 @@ Example error message. If you executed this code:
|
|||
```python
|
||||
def main():
|
||||
sg.user_settings_filename(path='...')
|
||||
sg.user_settings_set_entry('test',123)
|
||||
sg.user_settings_set_entry('-test-',123)
|
||||
```
|
||||
|
||||
Then you'll get an error when trying to set the 'test' entry because `'...'` is not a valid path.
|
||||
Then you'll get an error when trying to set the '-test-' entry because `'...'` is not a valid path.
|
||||
|
||||
```
|
||||
*** Error saving settings to file:***
|
||||
|
@ -6000,11 +6105,25 @@ The error originated from:
|
|||
File "C:/Users/mike/.PyCharmCE2019.1/config/scratches/scratch_1065.py"
|
||||
line 8
|
||||
in main
|
||||
sg.user_settings_set_entry('test',123)
|
||||
sg.user_settings_set_entry('-test-',123)
|
||||
```
|
||||
|
||||
You should be able to easily figure out these errors as they are file operations and the error messages are clear in detailing what's happened and where the call originated.
|
||||
|
||||
### Silenting the Errors
|
||||
|
||||
If you're the type that doesn't want to see any error messages printed out on your console, then you can silence the error output.
|
||||
|
||||
When using the class interface, there is a parameter `silent_on_error` that you can set to `True`.
|
||||
|
||||
For the function interface, call the function `user_settings_silent_on_error()` and set the parameter to `True`
|
||||
|
||||
## Coding Convention for User Settings Keys
|
||||
|
||||
The User Settings prompted a new coding convention that's been added to PySimpleGUI examples. As you're likely aware, keys in layouts have the format `'-KEY-`'. For UserSettings, a similar format is used, but instead of the string being in all upper case, the characters are lower case. In the example below, the user setting for "filename" has a User Setting key of `'-filename-'`. Coding conventions are a good thing to have in your projects. You don't have to follow this one of course, but you're urged to create your own for places in your code that it makes sense. You could say that PEP8 is one giant coding convention for the Python language as a whole. You don't have to follow it, but most Python programmers do. We follow it "by convention".
|
||||
|
||||
The reason this is done in PySimpleGUI is so that the keys are immediately recognizable. Perhaps your application has dictionaries that you use. If you follow the PySimpleGUI coding convention of Element keys have the format `'-KEY-'` and User Settings keys have the format of `'-key-'`, then you'll immediately understand what a specific key is used for. Your company may have its own coding conventions so follow those if appropriate instead of what you see in the PySimpleGUI examples.
|
||||
|
||||
## Example User Settings Usage
|
||||
|
||||
One of the primary places settings are likely to be used is for filenames / folder names. How many times have you run the same program and needed to enter the same filename? Even if the name of the file is on your clipboard, it's still a pain in the ass to paste it into the input field every time you run the code. Wouldn't it be so much simpler if your program remembered the last value you entered? Well, that's exactly why this set of APIs was developed.... again it was from laziness that this capability gained life.
|
||||
|
@ -6020,13 +6139,13 @@ Let's say your layout had this typical file input row:
|
|||
To automatically fill in the `Input` to be the last value entered, use this layout row:
|
||||
|
||||
```python
|
||||
[sg.Input(sg.user_settings_get_entry('filename', ''), key='-IN-'), sg.FileBrowse()]
|
||||
[sg.Input(sg.user_settings_get_entry('-filename-', ''), key='-IN-'), sg.FileBrowse()]
|
||||
```
|
||||
|
||||
When your user clicks OK or closes the window in a way that is in a positive way (instead of cancelling), then add this statement to save the value.
|
||||
|
||||
```python
|
||||
sg.user_settings_set_entry('filename', values['-IN-'])
|
||||
sg.user_settings_set_entry('-filename-', values['-IN-'])
|
||||
```
|
||||
|
||||
Here's an entire program demonstrating this way of using user settings
|
||||
|
@ -6037,7 +6156,7 @@ Here's an entire program demonstrating this way of using user settings
|
|||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[sg.Text('Enter a filename:')],
|
||||
[sg.Input(sg.user_settings_get_entry('filename', ''), key='-IN-'), sg.FileBrowse()],
|
||||
[sg.Input(sg.user_settings_get_entry('-filename-', ''), key='-IN-'), sg.FileBrowse()],
|
||||
[sg.B('Save'), sg.B('Exit Without Saving', key='Exit')]]
|
||||
|
||||
window = sg.Window('Filename Example', layout)
|
||||
|
@ -6047,7 +6166,7 @@ while True:
|
|||
if event in (sg.WINDOW_CLOSED, 'Exit'):
|
||||
break
|
||||
elif event == 'Save':
|
||||
sg.user_settings_set_entry('filename', values['-IN-'])
|
||||
sg.user_settings_set_entry('-filename-', values['-IN-'])
|
||||
|
||||
window.close()
|
||||
```
|
||||
|
@ -6058,6 +6177,48 @@ In 2 lines of code you've just made life for your user so much easier. And, by
|
|||
sg.user_settings_filename(path='.')
|
||||
```
|
||||
|
||||
## Example Using UserSettings Class with [ ] Syntax
|
||||
|
||||
The same example can be written using the `UserSettings` class and the [ ] lookup syntax.
|
||||
|
||||
Here's the same program as above.
|
||||
|
||||
```python
|
||||
import PySimpleGUI as sg
|
||||
|
||||
settings = sg.UserSettings()
|
||||
|
||||
layout = [[sg.Text('Enter a filename:')],
|
||||
[sg.Input(settings.get('-filename-', ''), key='-IN-'), sg.FileBrowse()],
|
||||
[sg.B('Save'), sg.B('Exit Without Saving', key='Exit')]]
|
||||
|
||||
window = sg.Window('Filename Example', layout)
|
||||
|
||||
while True:
|
||||
event, values = window.read()
|
||||
if event in (sg.WINDOW_CLOSED, 'Exit'):
|
||||
break
|
||||
elif event == 'Save':
|
||||
settings['-filename-'] = values['-IN-']
|
||||
|
||||
window.close()
|
||||
```
|
||||
|
||||
If you were to place these 2 examples in the same file so that one ran after the other, you will find that the same settings file is used and thus the value saved in the first example will be read by the second one.
|
||||
|
||||
There was one additional line of code added:
|
||||
|
||||
```python
|
||||
settings.set_default_value('') # Set the default not-found value to ''
|
||||
|
||||
```
|
||||
|
||||
Strictly speaking, this line isn't needed because the Input Element now takes `None` to be the same as a value of `''`, but to produce identical results I added this line of code.
|
||||
|
||||
## Demo Programs
|
||||
|
||||
There are a number of demo programs that show how to use UserSettings to create a richer experience for your users by remember the last value input into input elements or by adding a Combobox with a history of previously entered values. These upgrades make for a much easier to use GUI, especially when you find yourself typing in the same values or using the same files/folders.
|
||||
|
||||
## Brief Caution - User Settings Stick Around
|
||||
|
||||
If you're using the default path, remember that previous runs of your file may have old settings that are still in your settings file. It can get confusing when you've forgotten that you previously wrote a setting. Not seeing the filename can have drawbacks like this.
|
||||
|
@ -6521,9 +6682,9 @@ If you've created a GitHub for your project that uses PySimpleGUI then please po
|
|||
| 2.7.0 | July 30, 2018 - realtime buttons, window_location default setting
|
||||
| 2.8.0 | Aug 9, 2018 - New None default option for Checkbox element, text color option for all elements, return values as a dictionary, setting focus, binding return key
|
||||
| 2.9.0 | Aug 16,2018 - Screen flash fix, `do_not_clear` input field option, `autosize_text` defaults to `True` now, return values as ordered dict, removed text target from progress bar, rework of return values and initial return values, removed legacy Form.Refresh() method (replaced by Form.ReadNonBlockingForm()), COLUMN elements!!, colored text defaults
|
||||
| 2.10.0 | Aug 25, 2018 - Keyboard & Mouse features (Return individual keys as if buttons, return mouse scroll-wheel as button, bind return-key to button, control over keyboard focus), SaveAs Button, Update & Get methods for InputText, Update for Listbox, Update & Get for Checkbox, Get for Multiline, Color options for Text Element Update, Progess bar Update can change max value, Update for Button to change text & colors, Update for Image Element, Update for Slider, Form level text justification, Turn off default focus, scroll bar for Listboxes, Images can be from filename or from in-RAM, Update for Image). Fixes - text wrapping in buttons, msg box, removed slider borders entirely and others
|
||||
| 2.11.0 | Aug 29, 2018 - Lots of little changes that are needed for the demo programs to work. Buttons have their own default element size, fix for Mac default button color, padding support for all elements, option to immediately return if list box gets selected, FilesBrowse button, Canvas Element, Frame Element, Slider resolution option, Form.Refresh method, better text wrapping, 'SystemDefault' look and feel settin
|
||||
| 2.20.0 | Sept 4, 2018 - Some sizable features this time around of interest to advanced users. Renaming of the MsgBox functions to Popup. Renaming GetFile, etc, to PopupGetFile. High-level windowing capabilities start with Popup, PopupNoWait/PopupNonblocking, PopupNoButtons, default icon, change_submits option for Listbox/Combobox/Slider/Spin/, New OptionMenu element, updating elements after shown, system defaul color option for progress bars, new button type (Dummy Button) that only closes a window, SCROLLABLE Columns!! (yea, playing in the Big League now), LayoutAndShow function removed, form.Fill - bulk updates to forms, FindElement - find element based on key value (ALL elements have keys now), no longer use grid packing for row elements (a potentially huge change), scrolled text box sizing changed, new look and feel themes (Dark, Dark2, Black, Tan, TanBlue, DarkTanBlue, DarkAmber, DarkBlue, Reds, Green)
|
||||
| 2.10.0 | Aug 25, 2018 - Keyboard & Mouse features (Return individual keys as if buttons, return mouse scroll-wheel as button, bind return-key to button, control over keyboard focus), SaveAs Button, Update & Get methods for InputText, Update for Listbox, Update & Get for Checkbox, Get for Multiline, Color options for Text Element Update, Progress bar Update can change max value, Update for Button to change text & colors, Update for Image Element, Update for Slider, Form level text justification, Turn off default focus, scroll bar for Listboxes, Images can be from filename or from in-RAM, Update for Image). Fixes - text wrapping in buttons, msg box, removed slider borders entirely and others
|
||||
| 2.11.0 | Aug 29, 2018 - Lots of little changes that are needed for the demo programs to work. Buttons have their own default element size, fix for Mac default button color, padding support for all elements, option to immediately return if list box gets selected, FilesBrowse button, Canvas Element, Frame Element, Slider resolution option, Form.Refresh method, better text wrapping, 'SystemDefault' look and feel setting
|
||||
| 2.20.0 | Sept 4, 2018 - Some sizable features this time around of interest to advanced users. Renaming of the MsgBox functions to Popup. Renaming GetFile, etc, to PopupGetFile. High-level windowing capabilities start with Popup, PopupNoWait/PopupNonblocking, PopupNoButtons, default icon, change_submits option for Listbox/Combobox/Slider/Spin/, New OptionMenu element, updating elements after shown, system default color option for progress bars, new button type (Dummy Button) that only closes a window, SCROLLABLE Columns!! (yea, playing in the Big League now), LayoutAndShow function removed, form.Fill - bulk updates to forms, FindElement - find element based on key value (ALL elements have keys now), no longer use grid packing for row elements (a potentially huge change), scrolled text box sizing changed, new look and feel themes (Dark, Dark2, Black, Tan, TanBlue, DarkTanBlue, DarkAmber, DarkBlue, Reds, Green)
|
||||
| 2.30.0 | Sept 6, 2018 - Calendar Chooser (button), borderless windows, load/save form to disk
|
||||
| 3.0.0 | Sept 7, 2018 - The "fix for poor choice of 2.x numbers" release. Color Chooser (button), "grab anywhere" windows are on by default, disable combo boxes, Input Element text justification (last part needed for 'tables'), Image Element changes to support OpenCV?, PopupGetFile and PopupGetFolder have better no_window option
|
||||
| 3.01.01 | Sept 10, 2018 - Menus! (sort of a big deal)
|
||||
|
@ -7983,6 +8144,40 @@ User Settings APIs, lots more themes, theme swatch previewer, test harness addit
|
|||
* updated `pin` layout helper function - added `shrink` parameter
|
||||
* Main debugger window set to keep on top
|
||||
|
||||
## 4.31.0 PySimpleGUI 13-Nov-2020
|
||||
|
||||
User Settings class, write_event_value fixes, Menus get colors, Mac no_titlebar patch
|
||||
|
||||
* InputText element - Now treating None as '' for default
|
||||
* Combo - handling update calls with both disabled and readonly set
|
||||
* Spin - readonly
|
||||
* Added parameter added when creating
|
||||
* Added parameter to update
|
||||
* Spin.get() now returns value rather than string version of value
|
||||
* Multiline print now autoscrolls by default
|
||||
* FileSaveAs and SaveAs now has default_extension parameter like the popup_get_file has
|
||||
* Button Menu - Color and font changes
|
||||
* New create parameters - background color, text color, disabled text color, item font
|
||||
* Fixed problem with button always being flat
|
||||
* Menu (Menubar) - Color changes
|
||||
* New create paramters - text color, disabled text color.
|
||||
* Hooked up background color parameter that was already there but not functional
|
||||
* write_event_value - fixed race conditions
|
||||
* Window.read() and read_all_windows() now checks the thread queue for events before starting tkinter's mainloop in case events are queued
|
||||
* Window.set_cursor added so that window's cursor can be set just like can be set for individual elements
|
||||
* Icon is now set when no_window option used on popup_get_file or popup_get_folder
|
||||
* Reformatted the theme definitions to save a LOT of lines of code
|
||||
* UserSettings class
|
||||
* Added a class interface for User Settings
|
||||
* Can still use the function interface if desired
|
||||
* One advantage of class is that [ ] can be used to get and set entries
|
||||
* Looks and acts much like a "persistent global dictionary"
|
||||
* The User Settings function interfaces now use the class
|
||||
* main_get_debug_data()
|
||||
* Function added that will display a popup and add to the clipboard data needed for GitHub Issues
|
||||
* Added button to Test Harness to display the popup with version data
|
||||
* Mac - Added parm enable_mac_notitlebar_patch to set_options to enable apply a "patch" if the Window has no_titlebar set.
|
||||
|
||||
## Upcoming
|
||||
|
||||
The future for PySimpleGUI looks bright!
|
||||
|
|
Loading…
Reference in New Issue