conductor.lib.pyside_utils module

class conductor.lib.pyside_utils.CheckBoxTreeWidget(parent=None)

Bases: sphinx.ext.autodoc.importer._MockObject

This is a QTreeWidget that has been modified to

addTopLevelCheckboxItem(tree_item, is_checked=False)

Add the given QTreeWidgetItem as a top level widget and add a checkbox to it.

checkbox_column_idx = 0
contextMenuEvent(event)
icon_filepath_checked = ''
icon_filepath_checked_disabled = ''
icon_filepath_unchecked = ''
icon_filepath_unchecked_disabled = ''
initializeUi()
setCheckboxStyleSheet()
class conductor.lib.pyside_utils.FilePrefs(company_name, application_name)

Bases: conductor.lib.pyside_utils.UserPrefs

This class facilicates the saving/loading of user preferences from/to disk while providing a structured scope to save that preference to. A scope is either global or file-specific. Scopes are achieved by using QtSettings’ “groups” (i.e. namespaces). All scopes of settings are written to the same preference file. An example use-case for these scopes is when a user wants preferences to be saved for a particular file that they have opened at the moment. Or a user might want preferences to be applied regardless of what file is opened at the moment.

GROUP_FILE_PREFS = 'file/prefs'
GROUP_GLOBAL_PREFS = 'global/prefs'
clearFilePrefs(filepath)

Clear all of the preferences found in the given filepath’s group/namespace

clearGlobalPrefs()

Clear all of the preferences found in the global group/namespace

getFilePref(filepath, pref_name)

Return the user preferences for the given preference for the given file

getFilePrefs(filepath)

Return a dictionary of all user preferences for the given file

getGlobalPref(pref_name)

Return the value for given global preference

Parameters:pref_name (str) – The name of the preference to return a value for, e.g. “frame_range”
getGlobalPrefs()

Return a dictionary of all global preferences

getPref(pref_name, filepath=None)

High level convenience function that will return the preference value for either a global or file-specific preference.

Parameters:
  • pref_name (str) – The name of the preference to return a value for, e.g. “frame_range”
  • filepath (str) – The name of the file to return the preference value for. If the filepath is not provided, then the global preference will be searched for.
getPrefs(filepath=None)

High level convenience function that will return a dictionary of either file-specific preferences

Parameters:filepath (str) – The name of the file to return the preference values for. If the filepath is not provided, then the global preferences will be returned.
setFilePref(filepath, pref_name, value)

Set the given preference to the given value for the given file

Parameters:
  • pref_name (str) – The name of the preference to set a value for, e.g. “frame_range”
  • value (object) – The value to save for the preference, e.g. “1001-1040”
setFilePrefs(filepath, values)

Set the the given preference values for the given file

Parameters:
  • filepath (str) – The name of the file to set the preference value for. If the filepath is not provided, then a global preference will be set.
  • values (dict[str]) – Mapping of preference names to their new values.
setGlobalPref(pref_name, value)

Set the value for given global preference

Parameters:pref_name (str) – The name of the preference to return a value for, e.g. “frame_range”
setGlobalPrefs(values)

Set the the given values to the global preferences

Parameters:value (dict[str]) – Mapping of preference names to their new values.
setPref(pref_name, value, filepath=None)

High level convenience function that will set the preference value for either a global or file-specific preference.

Parameters:
  • pref_name (str) – The name of the preference to set a value for, e.g. “frame_range”
  • value (object) – The value to save for the preference, e.g. “1001-1040”
  • filepath (str) – The name of the file to set the preference value for. If the filepath is not provided, then a global preference will be set.
setPrefs(values, filepath=None)

High level convenience function that will set the given preference values for either global or file-specific scope.

Parameters:
  • pref_name (str) – The name of the preference to set a value for, e.g. “frame_range”
  • value (dict[str]) – Mapping of preference names to their new values.
  • filepath (str) – The name of the file to set the preference value for. If the filepath is not provided, then a global preference will be set.
class conductor.lib.pyside_utils.UiFilePrefs(company_name, application_name, file_widgets=(), global_widgets=())

Bases: conductor.lib.pyside_utils.FilePrefs

Extends the parent class to allow the state of the UI’s widget to be recorded, and then restored at a later point.

Because this class must read widget values and write those values to a text file and conversely, read those values from a text file and apply them back to the widgets, there needs to be binding/mapping of getters/setters so that different widget types can properly read/set the values from/to the preferences file. This binding class must be provided upon instantiation.

This class adds two more scopes (groups) to it’s parent classes’:

  • “global/widgets”. Group for storing global widget preferences
  • “file/widgets”. Group for storing file-specific widget preferences
GROUP_FILE_WIDGETS = 'file/widgets'
GROUP_GLOBAL_WIDGETS = 'global/widgets'
clearFilePrefs(filepath)

Clear all of the preferences found in the given filepath’s group/namespace

clearGlobalPrefs()

Clear all of the preferences found in the global group/namespace

getFileWidgetPref(filepath, widget_name)

Return the preference for the given widget name for the given file

Parameters:
  • filepath (str) – The file path to get preferences for.
  • widget_name (str) – The name of the widget object, e.g. “ui_frames_lnedt”
getFileWidgetPrefs(filepath)

Return all widget preferences for the given file

Parameters:filepath (str) – The file path to get preferences for.
getGlobalWidgetPref(widget_name)

Return the global preference value for the given widget name

Parameters:widget_name (str) – The name of the widget object, e.g. “ui_frames_lnedt”
getGlobalWidgetPrefs()

Return the all global widget preferences

getPref(pref_name, filepath=None, is_widget=False)

High level convenience function that returns the value for the given preference name. If a filepath is given, return the preference stored for that specific file, otherwise return the global value.

Parameters:
  • pref_name (str) – The name of the preference, such as “Dont_bug_me”,
  • filepath (str) – The name of the file to return the preference value for.
  • is_widget (bool) – Indicates that the pref_name is widget_name.
Returns:

The value of the preference, e.g “yes”, “no”, “true”, “false”.

Return type:

str

getPrefs(filepath=None, is_widget=False)

High level convenience function that will return a dictionary of either file-specific preferences or global preferences.

Parameters:
  • filepath (str) – The name of the file to return the preference values for. If the filepath is not provided, then the global preferences will be returned.
  • is_widget (bool) – Indicates that the pref_name is widget_name.
Returns:

Values of the preferences.

Return type:

dict

getWidgetByName(widget_name)

Return the widget object that has the given widget object name. Raise an exception if it cannot be found. Only widgets that have been provided upon this class’s instantiation will be searched.

loadFileWidgetPrefs(filepath)

Load/apply any user prefs for the given file (read from the qt prefs file). The prefs file is located/created via the company_name and application_name.

Parameters:filepath (str) – File path for the currently opened file to load widget preferences for.
loadGlobalWidgetPrefs()

Load/apply any global user prefs.

saveFileWidgetPrefs(filepath)

Save widget settings for the given file.

saveGlobalWidgetPrefs()

Save user widget settings to the global prefs

setFileWidgetPref(filepath, widget_name, value)

Record the given value for the given widget (name) for the given file path.

Parameters:
  • filepath (str) – The file path to save preferences for.
  • widget_name (str) – The name of the widget object, e.g. “ui_frames_lnedt”
  • value (object) – The value to record for the widget, .e.g “1001x2”
setFileWidgetPrefs(filepath, widget_values)

Record the given widget values for the given filepath

Parameters:widget_values (dict[str]) – Widget names mapped to their values.
setGlobalWidgetPref(widget_name, value)

Record the given value for the given widget (name) to the global preferences

Parameters:
  • widget_name (str) – The name of the widget object, e.g. “ui_frames_lnedt”
  • value (object) – The value to record for the widget, e.g. “1001x2”
setGlobalWidgetPrefs(widget_values)

Record the given widget values to the global preferences

Parameters:widget_values (dict[str]) – Widget names mapped to their values.
setPref(pref_name, value, filepath=None, is_widget=False)

High level convenience function that will set the preference value for either a global preference or file-specific preference.

Parameters:
  • pref_name (str) – The name of the preference to set a value for, e.g. “frame_range”
  • value (object) – The value to save for the preference, e.g. “1001-1040”.
  • filepath (str) – The name of the file to set the preference value for. If the filepath is not provided, then a global preference will be set.
setPrefs(values, filepath=None, is_widget=False)

High level convenience function that will set the given preference values for either the global scope or a file-specific scope.

Parameters:
  • values (dict[str]) – Mapping of preference names to their new values.
  • filepath (str) – The name of the file to set the preference values for. If the filepath is not provided, then the values will be set for the global prefs.
  • is_widget (bool) – Indicates whether the preference if for a QWidget or not.
widget_mapper

alias of WidgetGettrSettr

class conductor.lib.pyside_utils.UiLoader(baseinstance)

Bases: sphinx.ext.autodoc.importer._MockObject

Load a Qt Designer .ui file and returns an instance of the user interface.

To Do:
Re-write docs/comments for this class

This was taken almost 100% verbatim from a stack overflow example.

createWidget(class_name, parent=None, name='')
classmethod loadUi(uifile, baseinstance=None)

Load a Qt Designer .ui file and returns an instance of the user interface.

uifile: the file name or file-like object containing the .ui file. baseinstance: the optional instance of the Qt base class. If specified then the user interface is created in it. Otherwise a new instance of the base class is automatically created. Return type: the QWidget sub-class that implements the user interface.

class conductor.lib.pyside_utils.UserPrefs(company_name, application_name)

Bases: object

Base level helper-class to faciliate saving/loading user preferences to/from disk.

ENCODER = '^||^'
classmethod castToBool(value)

Cast the given value to a bool (if it’s considered a “bool” type).

clear()

A convenience method to QSetting’s clear method. Deletes preferences

clearGroup(group)

Clear all keys/values from given group

classmethod encodeGroupName(group_name)

Unfortunately qsettings uses the “/” as a special character to indicate nested keys in a group name. We may want to use forward slashes in our keys (such as a filepath), so we swap out the forward slash with different set of characters (i.e. “encode” the “/” to something else)

getSettingsFilepath()

Return the filepath to the QSettings file

getValue(key, group=None, cast_bools=True)

Return the value for the given key. If a group is given, search the group for the key and return its value.

Parameters:
  • key (str) – The name of the preference to return a value for.
  • group (str) – The preference group/namespace to search for the preference. If not specified, will use the default/root namespace
  • cast_bools (bool) – Cast any “true” or “false” values to python bools
getValues(group=None, cast_bools=True)

Return all preference values found in the given preference group. If no a preference group is specified, use the default/root preference group. Return a dictionary, where the key is the preference name, and the value is the preference value.

Parameters:
  • key (str) – The name of the preference to return a value for.
  • group (str) – The preference group/namespace to search for the preference. If not specified, will use the default/root namespace
  • cast_bools (bool) – Cast any “true” or “false” values to python bools
setValue(key, value, group=None)

Set the value for the given preference in the given preference group. If no preference group is specified, set the value in the default/root preference group.

Note that if a python bool is given as a value, QSettings automatically converts this to a lowercase string version of it (“false”, “true”).

Parameters:
  • key (str) – The name of the preference to set a value for.
  • value (str or) – The value to set the preference to.
  • group (str) – The preference group/namespace to set the preference for If not specified, will use the default/root namespace.
setValues(values, group=None)

Set the given preference values in the given preference group. If no a preference group is specified, use the default/root preference group. Return a dictionary, where the key is the preference name, and the value is the preference value.

Parameters:
  • key (str) – The name of the preference to set a value for.
  • group (str) – The preference group/namespace to search for the preference. If not specified, will use the default/root namespace
  • cast_bools (bool) – Cast any “true” or “false” values to python bools
sync()

A convenience method to QSetting’s synch method. Syncs pref data from memory to disk and visa versa. This doesn’t have to be called, but QT doesn’t write the settings to disk everytime a change is made…so this is a way to ensure that it does at critical moments.

class conductor.lib.pyside_utils.WidgetGettrSettr

Bases: object

Provides getter/setter functionality for QWidgets, making it easier to read/load widget values. This is particularly useful when needing to record a widget’s value for user preferences, and conversely, reapplying those settings back to the widget.

Every widget type must be mapped to a getter and setter method.

classmethod getCheckBoxValue(checkbox)

Define getter function for QCheckbox widgets

classmethod getComboBoxValue(combobox)

Define getter function for QCombobobox widgets Store the text in the combobox (rather than the current index). This allows the ordering of the items to change while maintaining the correct preference behavior

classmethod getGettrMap()

Return a dictionary mapping of “getter” functions that provide a mapping between a Widget type and a function that can read a value from that widget type (i.e. read a human entered value from the widget).

This dictionary should be expanded as needed, when other widget types are required for reading/loading data to/from.

classmethod getLineeditValue(lineedit)

Define getter function for QLineEdit widgets

classmethod getRadioButtonValue(radiobutton)

Define getter function for QRadioButton widgets

classmethod getSettrMap()

Return a dictionary mapping of “setter” functions that provide a mapping between a Widget type and a function that can write a value to that widget type (i.e populat the widget with that value).

This dictionary should be expanded as needed, when other widget types are required for reading/loading data to/from.

classmethod getSpinboxValue(spinbox)

Define getter function for QSpinBox widgets

classmethod getWidgetValue(widget)

Return the value for the given widget object. Because a widget can be of any class, and every widget class has different methods for retrieving its values, this function uses a mapping of different getter functions for each widget type. More widget types may need to be added to this mapping in the future.

classmethod setCheckBoxValue(checkbox, value)

Define setter function for QCheckbox widgets Since the value comes from qsettings (which casts bools to strings and lowercase), we have to do a little processing.

classmethod setComboBoxValue(combobox, value)

Define setter function for QComobobox widgets

Find the given text value in the combobox items. If no items contain the text, the index will be set to -1 (blank). This makes sense, as it will tell the user that their preference value is no longer valid, and to select something different.

classmethod setLineEditValue(lineedit, value)

Define setter function for QLineEdit widgets

classmethod setRadioButtonValue(radiobutton, value)

Define setter function for QRadioButton widgets. Since the value comes from qsettings (which casts bools to strings and lowercase), we have to do a little processing.

classmethod setSpinboxValue(spinbox, value)

Define setter function for QSpinBox widgets

classmethod setWidgetValue(widget, widget_value)

Set the given value on the widget object Because a widget can be of any class, and every widget class has different methods for setting its values, this function uses a mapping of different setter functions for each widget type. see cls.getGettrMap

Parameters:
  • widget (QWidget) – QWidget derivative (must have a getter/setter mapping in cls.getSettrMap)
  • widget_value – The value to populate the widget with.
conductor.lib.pyside_utils.get_all_tree_items(tree_widget)

For the given QTreeWidget, return all of its QTreeWidgetItems. This is an exhaustive, recursive search, capturing all top level as well as child QTreeWidgetItems.

conductor.lib.pyside_utils.get_qt_check_flag(is_checked)
conductor.lib.pyside_utils.get_top_level_items(tree_widget)

For the given QTreeWidget, return all top level QTreeItems

conductor.lib.pyside_utils.get_widgets_by_property(widget, property_name, match_value=False, property_value=None)

For the given widget, return all child widgets (and potentially the original widget), which have a property of the given property_name. Optionally, return only those widgets whose given property matches the given property_value

conductor.lib.pyside_utils.launch_error_box(title, message, parent=None)

Launches a QErrorMessage dialog box with the given title and message.

conductor.lib.pyside_utils.launch_message_box(title, message, is_richtext=False, parent=None)

Launches a very basic message dialog box with the given title and message.

Parameters:is_richtext (bool) – If True, will set the given as RichText. This will also allow the text to support hyperlink behavior.
conductor.lib.pyside_utils.launch_yes_no_cancel_dialog(title, message, show_not_again_checkbox=True, parent=None)

Launch a dialog box that has “yes”, “no” and “cancel” buttons. Optionally display a checkbox that asks whether to show this dialog box again. This is different from the Yes/No style of dialog since it offers three choices. As a consequence, the return code needs to return one of three statuses. return the result of this dialog (0/1/2) for ‘Yes’/’No’/’Cancel’ respectively, and whether the user checked the “Don’t ask again” checkbox (True/False).

conductor.lib.pyside_utils.launch_yes_no_dialog(title, message, show_not_again_checkbox=True, parent=None)

Launch a dialog box that has “yes” and “no” buttons. Optionally display a checkbox that asks whether to show this dialog box again. return the result of this dialog (True/False) and whether the user checked on the “Don’t ask again” checkbox (True/False).

conductor.lib.pyside_utils.wait_cursor(func)

Wraps the decorated function so that while it is running, the mouse cursor changes to waiting icon.

conductor.lib.pyside_utils.wait_message(title, message)

Wraps the decorated method so that while it runs, a dialog box will be displayed with the given message and title