python.shotgun_model.util module¶
-
compare_shotgun_data
(a, b)[source]¶ Compares two shotgun data structures. Both inputs are assumed to contain utf-8 encoded data.
Returns: True if a is same as b, false otherwise
-
get_sanitized_data
(item, role)[source]¶ Alternative method to the data() methods offered on QStandardItem and QModelIndex. This helper method ensures that complex data is returned in a correct and consistent fashion. All string data is returned as utf-8 encoded byte streams and complex data structures are returned as python native objects (rather than QVariants).
Using this method whenever working with complex model data ensures that the code behaves consistently across pyside and pyqt and is using utf-8 encoded strings rather than unicode.
Parameters: - item – QStandardItem or QModelIndex or similar
- role – Role identifier to be passed to the item object’s data() method.
Returns: native python objects
-
get_sg_data
(item)[source]¶ Helper method.
Retrieves the shotgun data associated with the object passed in. The object passed in is typically a QStandardItem or a QModelIndex or any other object which implements a data(ROLE) method signature.
Parameters: item – QStandardItem or QModelIndex or similar Returns: Shotgun data or None if no data was associated
-
sanitize_for_qt_model
(val)[source]¶ Useful when you have shotgun (or other) data and want to prepare it for storage as role data in a model.
Qt/pyside/pyqt automatically changes the data to be unicode according to internal rules of its own, sometimes resulting in unicode errors. A safe strategy for storing unicode data inside Qt model roles is therefore to ensure everything is converted to unicode prior to insertion into the model. This method ensures that. All string values will be coonverted to unicode. UTF-8 is assumed for all strings:
in: {“a”:”aaa”, “b”: 123, “c”: {“x”:”y”, “z”:”aa”}, “d”: [ {“x”:”y”, “z”:”aa”} ] } out: {‘a’: u’aaa’, ‘c’: {‘x’: u’y’, ‘z’: u’aa’}, ‘b’: 123, ‘d’: [{‘x’: u’y’, ‘z’: u’aa’}]}
This method is the counterpart to sanitize_qt() which is the reciprocal of this operation. When working with Qt models and shotgun data, we recommend the following best practices:
- when sg data is inserted into a role in model, run it through sanitize_for_qt_model() first
- When taking it back out again, run it through sanitize_qt()
Parameters: val – value to convert Returns: sanitized data