MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / _compute_filename

Method _compute_filename

PySimpleGUI/PySimpleGUI.py:22542–22594  ·  view source on GitHub ↗

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 n

(self, filename=None, path=None)

Source from the content-addressed store, hash-verified

22540 self.default_value = default
22541
22542 def _compute_filename(self, filename=None, path=None):
22543 """
22544 Creates the full filename given the path or the filename or both.
22545
22546 :param filename: The name of the file to use. Can be a full path and filename or just filename
22547 :type filename: (str or None)
22548 :param path: The folder that the settings file will be stored in. Do not include the filename.
22549 :type path: (str or None)
22550 :return: Tuple with (full filename, path, filename)
22551 :rtype: Tuple[str, str, str]
22552 """
22553 if filename is not None:
22554 dirname_from_filename = os.path.dirname(filename) # see if a path was provided as part of filename
22555 if dirname_from_filename:
22556 path = dirname_from_filename
22557 filename = os.path.basename(filename)
22558 elif self.filename is not None:
22559 filename = self.filename
22560 else:
22561 filename = os.path.splitext(os.path.basename(sys.argv[0]))[0]
22562 if filename == '__main__': # if got __main__ then try an alternative approach
22563 filename = os.path.splitext(os.path.basename(sys.modules["__main__"].__file__))[0]
22564 if filename == '__main__':
22565 # filename = os.path.splitext(os.path.basename(__file__))[0] # likely to be PySimpleGUI.py which may be a problem...
22566 filename = os.path.splitext(os.path.basename(inspect.getsourcefile(lambda: 0)))[0]
22567 if filename == '__main__':
22568 print(f'Error setting the default settings filename. Please report this error. filename = {filename}')
22569 if not self.use_config_file: # add the extension to the filename
22570 filename += '.json'
22571 else:
22572 filename += '.ini'
22573
22574 if path is None:
22575 if self.path is not None:
22576 # path = self.path
22577 path = os.path.expanduser(self.path) # expand user provided path in case it has user ~ in it. Don't think it'll hurt
22578 elif DEFAULT_USER_SETTINGS_PATH is not None: # if user set the path manually system-wide using set options
22579 path = os.path.expanduser(DEFAULT_USER_SETTINGS_PATH)
22580 elif running_trinket():
22581 path = os.path.expanduser(DEFAULT_USER_SETTINGS_TRINKET_PATH)
22582 elif running_replit():
22583 path = os.path.expanduser(DEFAULT_USER_SETTINGS_REPLIT_PATH)
22584 elif running_windows():
22585 path = os.path.expanduser(DEFAULT_USER_SETTINGS_WIN_PATH)
22586 elif running_linux():
22587 path = os.path.expanduser(DEFAULT_USER_SETTINGS_LINUX_PATH)
22588 elif running_mac():
22589 path = os.path.expanduser(DEFAULT_USER_SETTINGS_MAC_PATH)
22590 else:
22591 path = '.'
22592
22593 full_filename = os.path.join(path, filename)
22594 return (full_filename, path, filename)
22595
22596 def set_location(self, filename=None, path=None):
22597 """

Callers 2

set_locationMethod · 0.95
existsMethod · 0.95

Calls 5

running_trinketFunction · 0.85
running_replitFunction · 0.85
running_macFunction · 0.85
running_windowsFunction · 0.70
running_linuxFunction · 0.70

Tested by

no test coverage detected