spinetoolbox.helpers
¶
General helper functions and classes.
authors: |
|
---|---|
date: | 10.1.2018 |
Module Contents¶
-
spinetoolbox.helpers.
supported_img_formats
()[source]¶ Function to check if reading .ico files is supported.
-
spinetoolbox.helpers.
pyside2_version_check
()[source]¶ Check that PySide2 version is older than 5.12, since this is not supported yet. Issue #238 in GitLab.
qt_version is the Qt version used to compile PySide2 as string. E.g. “5.11.2” qt_version_info is a tuple with each version component of Qt used to compile PySide2. E.g. (5, 11, 2)
-
spinetoolbox.helpers.
spinedb_api_version_check
()[source]¶ Check if spinedb_api is the correct version and explain how to upgrade if it is not.
-
spinetoolbox.helpers.
spine_engine_version_check
()[source]¶ Check if spine engine package is the correct version and explain how to upgrade if it is not.
-
spinetoolbox.helpers.
busy_effect
(func)[source]¶ Decorator to change the mouse cursor to ‘busy’ while a function is processed.
Parameters: func – Decorated function.
-
spinetoolbox.helpers.
get_datetime
(show, date=True)[source]¶ Returns date and time string for appending into Event Log messages.
Parameters: - show (bool) – True returns date and time string. False returns empty string.
- date (bool) – Whether or not the date should be included in the result
-
spinetoolbox.helpers.
create_dir
(base_path, folder='', verbosity=False)[source]¶ Create (input/output) directories recursively.
Parameters: - base_path (str) – Absolute path to wanted dir
- folder (str) – (Optional) Folder name. Usually short name of item.
- verbosity (bool) – True prints a message that tells if the directory already existed or if it was created.
Returns: True if directory already exists or if it was created successfully.
Raises: OSError if operation failed.
-
spinetoolbox.helpers.
create_output_dir_timestamp
()[source]¶ Creates a new timestamp string that is used as Tool output directory.
Returns: Timestamp string or empty string if failed.
-
spinetoolbox.helpers.
copy_files
(src_dir, dst_dir, includes=None, excludes=None)[source]¶ Function for copying files. Does not copy folders.
Parameters: - src_dir (str) – Source directory
- dst_dir (str) – Destination directory
- includes (list) – Included files (wildcards accepted)
- excludes (list) – Excluded files (wildcards accepted)
Returns: Number of files copied
Return type: count (int)
-
spinetoolbox.helpers.
erase_dir
(path, verbosity=False)[source]¶ Deletes a directory and all its contents without prompt.
Parameters: - path (str) – Path to directory
- verbosity (bool) – Print logging messages or not
-
spinetoolbox.helpers.
copy_dir
(widget, src_dir, dst_dir)[source]¶ Makes a copy of a directory. All files and folders are copied. Destination directory must not exist. Does not overwrite files.
Parameters: - widget (QWidget) – Parent widget for QMessageBoxes
- src_dir (str) – Absolute path to directory that will be copied
- dst_dir (str) – Absolute path to new directory
-
spinetoolbox.helpers.
recursive_overwrite
(widget, src, dst, ignore=None, silent=True)[source]¶ Copies everything from source directory to destination directory recursively. Overwrites existing files.
Parameters: - widget (QWidget) – Enables e.g. printing to Event Log
- src (str) – Source directory
- dst (str) – Destination directory
- ignore – Ignore function
- silent (bool) – If False, messages are sent to Event Log, If True, copying is done in silence
-
spinetoolbox.helpers.
rename_dir
(old_dir, new_dir, logger)[source]¶ Rename directory. Note: This is not used in renaming projects due to unreliability. Looks like it works fine in renaming project items though.
Parameters: - old_dir (str) – Absolute path to directory that will be renamed
- new_dir (str) – Absolute path to new directory
- logger (LoggerInterface) – A logger instance
-
spinetoolbox.helpers.
fix_name_ambiguity
(input_list, offset=0)[source]¶ Modify repeated entries in name list by appending an increasing integer.
-
spinetoolbox.helpers.
tuple_itemgetter
(itemgetter_func, num_indexes)[source]¶ Change output of itemgetter to always be a tuple even for one index
-
spinetoolbox.helpers.
format_string_list
(str_list)[source]¶ Return an unordered html list with all elements in str_list. Intended to print error logs as returned by spinedb_api.
Parameters: str_list (list(str)) –
-
spinetoolbox.helpers.
rows_to_row_count_tuples
(rows)[source]¶ Breaks a list of rows into a list of (row, count) tuples corresponding to chunks of successive rows.
-
spinetoolbox.helpers.
inverted
(input_)[source]¶ Inverts a dictionary that maps keys to a list of values. The output maps values to a list of keys that include the value in the input.
-
class
spinetoolbox.helpers.
IconListManager
(icon_size)[source]¶ A class to manage icons for icon list widgets.
-
class
spinetoolbox.helpers.
IconManager
[source]¶ A class to manage object class icons for data store forms.
-
create_object_pixmap
(self, display_icon)[source]¶ Create a pixmap corresponding to display_icon, cache it, and return it.
-
setup_object_pixmaps
(self, object_classes)[source]¶ Called after adding or updating object classes. Create the corresponding object pixmaps and clear obsolete entries from the relationship class icon cache.
-
-
class
spinetoolbox.helpers.
CharIconEngine
(char, color)[source]¶ Bases:
PySide2.QtGui.QIconEngine
Specialization of QIconEngine used to draw font-based icons.
-
spinetoolbox.helpers.
make_icon_id
(icon_code, color_code)[source]¶ Take icon and color codes, and return equivalent integer.
-
spinetoolbox.helpers.
interpret_icon_id
(display_icon)[source]¶ Take a display icon integer and return an equivalent tuple of icon and color code.
-
class
spinetoolbox.helpers.
ProjectDirectoryIconProvider
[source]¶ Bases:
PySide2.QtWidgets.QFileIconProvider
QFileIconProvider that provides a Spine icon to the Open Project Dialog when a Spine Toolbox project directory is encountered.
-
spinetoolbox.helpers.
path_in_dir
(path, directory)[source]¶ Returns True if the given path is in the given directory.
-
spinetoolbox.helpers.
serialize_path
(path, project_dir)[source]¶ Returns a dict representation of the given path.
If path is in project_dir, converts the path to relative. If path does not exist returns it as-is.
Parameters: - path (str) – path to serialize
- project_dir (str) – path to the project directory
Returns: Dictionary representing the given path
Return type: dict
-
spinetoolbox.helpers.
serialize_url
(url, project_dir)[source]¶ Return a dict representation of the given URL.
If the URL is a file that is in project dir, the URL is converted to a relative path.
Parameters: - url (str) – a URL to serialize
- project_dir (str) – path to the project directory
Returns: Dictionary representing the URL
Return type: dict