items.delegate#

Item delegate used to draw bookmark, asset and file items.

Defines ItemDelegate, the base delegate class, subclasses and helper functions.

The list views have a number of custom features, such as clickable in-line icons, folder names, custom thumbnails that the delegate implements. Since we’re using list views with a single column, the item layout is defined by a series of custom rectangles (see ItemDelegate.get_rectangles().). These are used by the paint methods use to drawn elements and the views to define interactive regions.

The downside of painting manually a complex layout is performance and no doubt the module could be more optimised. Still, most of the expensive functions are backed by caches.

Classes:

AssetItemViewDelegate([parent])

The delegate used to render bookmarks.items.asset_items.AssetItemView items.

BookmarkItemViewDelegate([parent])

The delegate used to render bookmarks.items.bookmark_items.BookmarkItemView items.

FavouriteItemViewDelegate([parent])

The delegate used to render bookmarks.items.favourite_items.FavouriteItemView items.

FileItemViewDelegate([parent])

The delegate used to render bookmarks.items.file_items.FileItemView items.

ItemDelegate([parent])

The main delegate used to represent lists derived from base.BaseItemView.

Functions:

add_clickable_rectangle(index, option, rect, ...)

Add a clickable rectangle and its contents.

draw_file_text_segments(it, font, metrics, ...)

Draws the given list of text segments.

draw_gradient_background(*args)

Helper method used to draw file items' gradient background.

draw_painter_path(painter, x, y, font, text)

Paints the given text using QPainterPath.

draw_subdir_bg_rectangles(text_edge, *args)

Draws the rectangle behind the subdir item labels.

elided_text(metrics, text, elide_mode, width)

Utility function used to elide the given text to fit to the given width.

get_asset_text_segments(text, label)

Caches and returns the text segments used to paint asset items.

get_bookmark_text_segments(text, label)

Caches and returns the text segments used to paint bookmark items.

get_clickable_cache_key(index, rect)

Returns the cache key used to store sub-folder background rectangles.

get_clickable_rectangles(index, rect)

Returns a cached interactive rectangle region.

get_description_cache_key(index, rect, button)

Returns the cache key used to store sub-folder background rectangles.

get_description_rectangle(index, rect, button)

Returns a cached interactive rectangle region.

get_file_detail_text_segments(index)

Returns the FileItemView item common.FileDetailsRole segments associated with custom colors.

get_file_text_segments(s, k, f)

Caches and returns the text segments used to paint file items.

get_subdir_bg_cache_key(index, rect)

Returns the cache key used to store sub-folder background rectangles.

get_subdir_cache_key(index, rect)

Returns the cache key used to store sub-folder rectangles.

get_subdir_rectangles(option, index, ...)

Returns the rectangles used to render sub-folder item labels.

get_text_segments(index)

Returns a list of text segments used to paint item names.

save_painter(func)

Decorator used to save and restore the painter state.

subdir_text_it(pp)

Yields text elements to be rendered as sub-folder item labels.

Data:

DCC_ICONS

Used to paint a DCC icon if the asset name contains any of these names

regex_remove_seq_marker

Regex used to sanitize collapsed sequence items

regex_remove_version

Regex used to sanitize version numbers

class bookmarks.items.delegate.AssetItemViewDelegate(parent=None)[source]#

Bases: ItemDelegate

The delegate used to render bookmarks.items.asset_items.AssetItemView items.

Methods:

paint(painter, option, index)

Paints a bookmarks.items.asset_items.AssetItemView item.

sizeHint(option, index)

Returns the item's size hint.

Attributes:

fallback_thumb

The item's default thumbnail image

paint(painter, option, index)[source]#

Paints a bookmarks.items.asset_items.AssetItemView item.

sizeHint(option, index)[source]#

Returns the item’s size hint.

fallback_thumb = 'asset_item'#

The item’s default thumbnail image

class bookmarks.items.delegate.BookmarkItemViewDelegate(parent=None)[source]#

Bases: ItemDelegate

The delegate used to render bookmarks.items.bookmark_items.BookmarkItemView items.

Methods:

paint(painter, option, index)

Paints a bookmarks.items.bookmark_items.BookmarkItemView item.

setEditorData(self, editor, index)

setModelData(self, editor, model, index)

sizeHint(option, index)

Returns the item's size hint.

Attributes:

fallback_thumb

The item's default thumbnail image

paint(painter, option, index)[source]#

Paints a bookmarks.items.bookmark_items.BookmarkItemView item.

setEditorData(self, editor: PySide2.QtWidgets.QWidget, index: PySide2.QtCore.QModelIndex) None[source]#
setModelData(self, editor: PySide2.QtWidgets.QWidget, model: PySide2.QtCore.QAbstractItemModel, index: PySide2.QtCore.QModelIndex) None[source]#
sizeHint(option, index)[source]#

Returns the item’s size hint.

fallback_thumb = 'bookmark_item'#

The item’s default thumbnail image

class bookmarks.items.delegate.FavouriteItemViewDelegate(parent=None)[source]#

Bases: FileItemViewDelegate

The delegate used to render bookmarks.items.favourite_items.FavouriteItemView items.

Attributes:

fallback_thumb

The item's default thumbnail image

fallback_thumb = 'favourite_item'#

The item’s default thumbnail image

class bookmarks.items.delegate.FileItemViewDelegate(parent=None)[source]#

Bases: ItemDelegate

The delegate used to render bookmarks.items.file_items.FileItemView items.

Methods:

paint(painter, option, index)

Paints a bookmarks.items.file_items.FileItemView item.

sizeHint(option, index)

Returns the item's size hint.

Attributes:

fallback_thumb

The item's default thumbnail image

paint(painter, option, index)[source]#

Paints a bookmarks.items.file_items.FileItemView item.

sizeHint(option, index)[source]#

Returns the item’s size hint.

fallback_thumb = 'file_item'#

The item’s default thumbnail image

class bookmarks.items.delegate.ItemDelegate(parent=None)[source]#

Bases: QAbstractItemDelegate

The main delegate used to represent lists derived from base.BaseItemView.

Methods:

createEditor(self, parent, option, index)

draw_file_description(font, metrics, ...)

Draws file items' descriptions.

draw_subdir_rectangles(bg_rect, *args)

Helper method used to draw the subdirectories of file items.

get_paint_arguments(painter, option, index)

A utility class for gathering all the arguments needed to paint the individual list elements.

get_rectangles(index)

Return all rectangles needed to paint an item.

paint(painter, option, index)

Paints an item.

paint_active(*args)

Paints the background for all list items.

paint_archived(*args)

Paints a gray overlay when an item is archived.

paint_asset_name(*args[, offset])

Paints name of the AssetWidget's items.

paint_background(*args)

Paints the background for all list items.

paint_bookmark_name(*args)

Paints name of the BookmarkWidget's items.

paint_dcc_icon(*args)

Paints the item's DCC icon.

paint_default(*args)

Paints a gray overlay when an item is archived.

paint_deleted(*args, **kwargs)

Paints a deleted item.

paint_description_editor_background(*args, ...)

Paints the background of the item.

paint_drag_source(*args, **kwargs)

Overlay do indicate the source of a drag operation.

paint_file_name(*args)

Paints the clickable sub-folders and the filename of file items.

paint_hover(*args)

Paints the background for all list items.

paint_inline_background(*args)

Paints the item's inline buttons background.

paint_inline_count(painter, rect, ...)

Paints an item count.

paint_inline_icons(*args)

Paints the item's inline buttons background.

paint_name(*args)

Paints the name of the item.

paint_selection_indicator(*args)

Paints the leading rectangle indicating the selection.

paint_shotgun_status(*args)

Paints the item's ShotGrid configuration status.

paint_slack_status(*args)

Paints the item's Slack configuration status.

paint_thumbnail(*args)

Paints an item's thumbnail.

paint_thumbnail_drop_indicator(*args)

Paints a drop indicator used when dropping thumbnail onto the item.

paint_thumbnail_shadow(*args)

Paints the item's thumbnail shadow.

setEditorData(self, editor, index)

setModelData(self, editor, model, index)

updateEditorGeometry(self, editor, option, index)

createEditor(self, parent: PySide2.QtWidgets.QWidget, option: PySide2.QtWidgets.QStyleOptionViewItem, index: PySide2.QtCore.QModelIndex) PySide2.QtWidgets.QWidget[source]#
draw_file_description(font, metrics, left_limit, right_limit, offset, large_mode, *args)[source]#

Draws file items’ descriptions.

draw_subdir_rectangles(bg_rect, *args)[source]#

Helper method used to draw the subdirectories of file items.

get_paint_arguments(painter, option, index, antialiasing=False)[source]#

A utility class for gathering all the arguments needed to paint the individual list elements.

get_rectangles(index)[source]#

Return all rectangles needed to paint an item.

Parameters

index (QModelIndex) – An item index.

Returns

Dictionary containing count number of rectangles.

Return type

dict

paint(painter, option, index)[source]#

Paints an item.

paint_active(*args)[source]#

Paints the background for all list items.

paint_archived(*args)[source]#

Paints a gray overlay when an item is archived.

paint_asset_name(*args, offset=0)[source]#

Paints name of the AssetWidget’s items.

paint_background(*args)[source]#

Paints the background for all list items.

paint_bookmark_name(*args)[source]#

Paints name of the BookmarkWidget’s items.

paint_dcc_icon(*args)[source]#

Paints the item’s DCC icon.

paint_default(*args)[source]#

Paints a gray overlay when an item is archived.

paint_deleted(*args, **kwargs)[source]#

Paints a deleted item.

paint_description_editor_background(*args, **kwargs)[source]#

Paints the background of the item.

paint_drag_source(*args, **kwargs)[source]#

Overlay do indicate the source of a drag operation.

paint_file_name(*args)[source]#

Paints the clickable sub-folders and the filename of file items.

paint_hover(*args)[source]#

Paints the background for all list items.

paint_inline_background(*args)[source]#

Paints the item’s inline buttons background.

paint_inline_count(painter, rect, cursor_position, count, icon)[source]#

Paints an item count.

paint_inline_icons(*args)[source]#

Paints the item’s inline buttons background.

paint_name(*args)[source]#

Paints the name of the item.

paint_selection_indicator(*args)[source]#

Paints the leading rectangle indicating the selection.

paint_shotgun_status(*args)[source]#

Paints the item’s ShotGrid configuration status.

paint_slack_status(*args)[source]#

Paints the item’s Slack configuration status.

paint_thumbnail(*args)[source]#

Paints an item’s thumbnail.

If a requested QPixmap has never been drawn before we will create and store it by calling bookmarks.images.get_thumbnail(). This method is backed by bookmarks.images.ImageCache and stores the requested pixmap for future use.

If no associated image data is available, we will use a generic thumbnail associated with the item’s type, or a fallback thumbnail set by the delegate.

See the bookmarks.images module for implementation details.

paint_thumbnail_drop_indicator(*args)[source]#

Paints a drop indicator used when dropping thumbnail onto the item.

paint_thumbnail_shadow(*args)[source]#

Paints the item’s thumbnail shadow.

setEditorData(self, editor: PySide2.QtWidgets.QWidget, index: PySide2.QtCore.QModelIndex) None[source]#
setModelData(self, editor: PySide2.QtWidgets.QWidget, model: PySide2.QtCore.QAbstractItemModel, index: PySide2.QtCore.QModelIndex) None[source]#
updateEditorGeometry(self, editor: PySide2.QtWidgets.QWidget, option: PySide2.QtWidgets.QStyleOptionViewItem, index: PySide2.QtCore.QModelIndex) None[source]#
bookmarks.items.delegate.add_clickable_rectangle(index, option, rect, text)[source]#

Add a clickable rectangle and its contents.

Parameters
  • index (QModelIndex) – The item’s index.

  • option (QStyleOption) – Style option instance.

  • rect (QRect) – The clickable area.

  • text (str) – The text of the rectangle.

bookmarks.items.delegate.draw_file_text_segments(it, font, metrics, offset, *args)[source]#

Draws the given list of text segments.

bookmarks.items.delegate.draw_gradient_background(*args)[source]#

Helper method used to draw file items’ gradient background.

Parameters

text_edge (float) – The left edge of the text to avoid clipping.

bookmarks.items.delegate.draw_painter_path(painter, x, y, font, text)[source]#

Paints the given text using QPainterPath.

This exists to ensure consistent aliased text rendering across all platforms. The path rendering comes with a performance trade-off so the QPainterPaths are cached and stored for later use.

Parameters
  • painter (QPainter) – The painter used to draw the text.

  • x (float) – Horizontal position.

  • y (float) – Vertical position.

  • font (QFont) – The font used to render the path.

  • text (str) – The text to render.

bookmarks.items.delegate.draw_subdir_bg_rectangles(text_edge, *args)[source]#

Draws the rectangle behind the subdir item labels.

Parameters

text_edge (float) – The left edge of the text to avoid clipping.

bookmarks.items.delegate.elided_text(metrics, text, elide_mode, width)[source]#

Utility function used to elide the given text to fit to the given width.

Parameters
  • metrics (QFontMetrics) – A font metrics instance.

  • text (str) – The text to elide.

  • elide_mode (int) – A text elide mode flag.

  • width (float) – The width to text must fit.

Returns

The elided text.

Return type

str

bookmarks.items.delegate.get_asset_text_segments(text, label)[source]#

Caches and returns the text segments used to paint asset items.

Used to mimic rich-text like coloring of individual text elements.

Parameters
  • text (str) – The source text.

  • label (str) – Item’s label string.

Returns

A dict of (str, QColor) pairs.

Return type

dict

bookmarks.items.delegate.get_bookmark_text_segments(text, label)[source]#

Caches and returns the text segments used to paint bookmark items.

Used to mimic rich-text like coloring of individual text elements.

Parameters
  • text (str) – The source text.

  • label (str) – Item’s label string.

Returns

A dict of (str, QColor) pairs.

Return type

dict

bookmarks.items.delegate.get_clickable_cache_key(index, rect)[source]#

Returns the cache key used to store sub-folder background rectangles.

Parameters
  • index (QModelIndex) – Item index.

  • rect (QRect) – The item’s rectangle.

Returns

The cache key.

Return type

str

bookmarks.items.delegate.get_clickable_rectangles(index, rect)[source]#

Returns a cached interactive rectangle region.

Parameters
  • index (QtCore.QModelIndex) – The item’s index.

  • rect (QRect) – The item’s visual rectangle.

Returns

A tuple of (QRect, str) pairs.

Return type

tuple

bookmarks.items.delegate.get_description_cache_key(index, rect, button)[source]#

Returns the cache key used to store sub-folder background rectangles.

Parameters
  • index (QModelIndex) – Item index.

  • rect (QRect) – The item’s rectangle.

  • button (bool) – Inline icon visibility state.

Returns

The cache key.

Return type

str

bookmarks.items.delegate.get_description_rectangle(index, rect, button)[source]#

Returns a cached interactive rectangle region.

Parameters
  • index (QtCore.QModelIndex) – The item’s index.

  • rect (QRect) – The item’s visual rectangle.

  • button (bool) – Button visibility state.

Returns

A tuple of (QRect, str) pairs.

Return type

tuple

bookmarks.items.delegate.get_file_detail_text_segments(index)[source]#

Returns the FileItemView item common.FileDetailsRole segments associated with custom colors.

Parameters

index (QModelIndex) – The index currently being painted.

Returns

A dictionary of tuples “{0: (str, QtGui.QColor)}”.

Return type

dict

bookmarks.items.delegate.get_file_text_segments(s, k, f)[source]#

Caches and returns the text segments used to paint file items.

Used to mimic rich-text like coloring of individual text elements.

Parameters
  • s (str) – Item’s display name.

  • k (str) – Item’s file path.

  • f (str) – Item’s frame role data.

Returns

A dict of (str, QColor) pairs.

Return type

dict

bookmarks.items.delegate.get_subdir_bg_cache_key(index, rect)[source]#

Returns the cache key used to store sub-folder background rectangles.

Returns

The cache key.

Return type

str

bookmarks.items.delegate.get_subdir_cache_key(index, rect)[source]#

Returns the cache key used to store sub-folder rectangles.

Returns

The cache key.

Return type

str

bookmarks.items.delegate.get_subdir_rectangles(option, index, rectangles, metrics)[source]#

Returns the rectangles used to render sub-folder item labels.

bookmarks.items.delegate.get_text_segments(index)[source]#

Returns a list of text segments used to paint item names.

Text segments mimic rich text like rendering where each segment can be coloured individually.

Parameters

index (QModelIndex) – A QModelIndex instance.

Returns

The text / colour pairs used to paint segments.

Return type

dict

bookmarks.items.delegate.save_painter(func)[source]#

Decorator used to save and restore the painter state.

bookmarks.items.delegate.subdir_text_it(pp)[source]#

Yields text elements to be rendered as sub-folder item labels.

bookmarks.items.delegate.DCC_ICONS = {'aftereffects': 'aep', 'afx': 'aep', 'blender': 'blend', 'c4d': 'c4d', 'cinema4d': 'c4d', 'hou': 'hip', 'maya': 'ma', 'nuke': 'nk', 'photoshop': 'psd'}#

Used to paint a DCC icon if the asset name contains any of these names

bookmarks.items.delegate.regex_remove_seq_marker = re.compile('[{}]*', re.IGNORECASE)#

Regex used to sanitize collapsed sequence items

bookmarks.items.delegate.regex_remove_version = re.compile('(.*)(v)([{0-9\\-}]+.*)', re.IGNORECASE)#

Regex used to sanitize version numbers