Skip to content

Commit

Permalink
Operator Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Titov committed Mar 26, 2021
1 parent 354c07d commit d705ef5
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 139 deletions.
4 changes: 2 additions & 2 deletions python2.7libs/houdini_tdk/operator_manager/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def paint(self, painter, option, index):
painter.save()

row_rect = QRectF(option.rect)
row_rect.setLeft(45)
row_rect.setRight(option.widget.width())

icon_rect = QRectF(option.rect)
icon_rect.setRight(45)

text_rect = QRectF(row_rect)
text_rect.setLeft(45)
text_rect.setRight(row_rect.right() - 30)

selection_rect = QRectF(row_rect)
Expand All @@ -56,7 +56,7 @@ def paint(self, painter, option, index):
super(OperatorManagerLibraryDelegate, self).paint(painter, option, index)
painter.restore()

if option.state & QStyle.State_Selected and index.column() == 0:
if option.state & QStyle.State_Selected:
painter.fillRect(selection_rect, option.palette.highlight())

metrics = painter.fontMetrics()
Expand Down
10 changes: 6 additions & 4 deletions python2.7libs/houdini_tdk/operator_manager/model/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def updateData(self):
self.endResetModel()

def hasChildren(self, parent):
if not parent.isValid() or not parent.parent().isValid():
if not parent.isValid():
return bool(self._libraries)
elif isinstance(parent.internalPointer(), basestring):
return True

return False
Expand All @@ -117,11 +119,11 @@ def parent(self, index):
return QModelIndex()

item = index.internalPointer()
if not isinstance(item, basestring):
if isinstance(item, basestring):
return QModelIndex()
else:
lib_path = item.libraryFilePath()
return self.createIndex(self._definitions[lib_path].index(item), 0, lib_path)
else:
return QModelIndex()

def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
Expand Down
178 changes: 45 additions & 133 deletions python2.7libs/houdini_tdk/operator_manager/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
from PySide2.QtGui import *
from PySide2.QtCore import *

import hou

from .delegate import OperatorManagerLibraryDelegate

ICON_SIZE = 16


class OperatorManagerView(QTreeView):
def __init__(self):
Expand All @@ -47,132 +43,48 @@ def __init__(self):
self.setIconSize(QSize(16, 16))

self.setItemDelegate(OperatorManagerLibraryDelegate())
# self.setAlternatingRowColors(True) # Disabled due to a bug that clipping delegate's text

self.__createActions()
self.__createContextMenus()

def __createActions(self):
self._open_location_action = QAction(hou.qt.Icon('BUTTONS_folder', ICON_SIZE, ICON_SIZE), 'Open location')

self._install_library_action = QAction('Install')

self._uninstall_library_action = QAction('Uninstall')

self._reinstall_library_action = QAction(hou.qt.Icon('MISC_loading', ICON_SIZE, ICON_SIZE), 'Reinstall')

self._merge_with_library_action = QAction('Merge with Library')

self._pack_action = QAction(hou.qt.Icon('DESKTOP_otl', ICON_SIZE, ICON_SIZE), 'Pack')

self._unpack_action = QAction(hou.qt.Icon('DESKTOP_expanded_otl', ICON_SIZE, ICON_SIZE), 'Unpack')

self._backup_list_action = QAction(hou.qt.Icon('BUTTONS_history', ICON_SIZE, ICON_SIZE), 'Backups...')

self._open_type_properties_action = QAction(hou.qt.Icon('BUTTONS_gear_mini', ICON_SIZE, ICON_SIZE),
'Open type properties...')

self._change_instances_to_action = QAction('Change instances to...')

self._run_hda_doctor_action = QAction(hou.qt.Icon('SOP_polydoctor', ICON_SIZE, ICON_SIZE), 'Run HDA Doctor...')

self._find_usages_action = QAction(hou.qt.Icon('BUTTONS_search', ICON_SIZE, ICON_SIZE), 'Find usages...')

self._find_dependencies_action = QAction(hou.qt.Icon('PANETYPES_network', ICON_SIZE, ICON_SIZE),
'Find dependencies...')

self._show_statistics_action = QAction(hou.qt.Icon('BUTTONS_info', ICON_SIZE, ICON_SIZE), 'Show statistics...')

self._create_instance_action = QAction('Instance')

self._create_new_hda_action = QAction(hou.qt.Icon('SOP_compile_begin', ICON_SIZE, ICON_SIZE),
'New HDA...')

self._create_new_version_action = QAction(hou.qt.Icon('BUTTONS_multi_insertbefore', ICON_SIZE, ICON_SIZE),
'New version...')

self._create_black_box_action = QAction(hou.qt.Icon('NETVIEW_hda_locked_badge', ICON_SIZE, ICON_SIZE),
'Black box...')

self._copy_action = QAction(hou.qt.Icon('BUTTONS_copy', ICON_SIZE, ICON_SIZE), 'Copy...')

self._move_action = QAction(hou.qt.Icon('BUTTONS_move_to_right', ICON_SIZE, ICON_SIZE), 'Move...')

self._rename_action = QAction(hou.qt.Icon('MISC_rename', ICON_SIZE, ICON_SIZE), 'Rename...')

self._add_alias_action = QAction(hou.qt.Icon('BUTTONS_tag', ICON_SIZE, ICON_SIZE), 'Add alias...')

self._delete_action = QAction(hou.qt.Icon('BUTTONS_delete', ICON_SIZE, ICON_SIZE), 'Delete')

self._hide_action = QAction(hou.qt.Icon('BUTTONS_close', ICON_SIZE, ICON_SIZE), 'Hide')

self._deprecate_action = QAction(hou.qt.Icon('BUTTONS_do_not', ICON_SIZE, ICON_SIZE), 'Deprecate')

self._compare_action = QAction(hou.qt.Icon('BUTTONS_restore', ICON_SIZE, ICON_SIZE), 'Compare...')

def __createContextMenus(self):
self._library_menu = QMenu(self)

self._library_menu.addAction(self._open_location_action)
self._library_menu.addSeparator()
self._library_menu.addAction(self._install_library_action)
self._library_menu.addAction(self._uninstall_library_action)
self._library_menu.addAction(self._reinstall_library_action)
self._library_menu.addSeparator()
self._library_menu.addAction(self._merge_with_library_action)
self._library_menu.addAction(self._pack_action)
self._library_menu.addAction(self._unpack_action)
self._library_menu.addSeparator()
self._library_menu.addAction(self._backup_list_action)

self._definition_menu = QMenu(self)

self._definition_menu.addAction(self._open_type_properties_action)
self._definition_menu.addAction(self._change_instances_to_action)

self._definition_inspect_menu = QMenu('Inspect', self)
self._definition_menu.addMenu(self._definition_inspect_menu)

self._definition_inspect_menu.addAction(self._run_hda_doctor_action)
self._definition_inspect_menu.addAction(self._find_usages_action)
self._definition_inspect_menu.addAction(self._find_dependencies_action)
self._definition_inspect_menu.addAction(self._show_statistics_action)

self._definition_create_menu = QMenu('Create', self)
self._definition_menu.addMenu(self._definition_create_menu)

self._definition_create_menu.addAction(self._create_instance_action)
self._definition_create_menu.addAction(self._create_new_hda_action)
self._definition_create_menu.addAction(self._create_new_version_action)
self._definition_create_menu.addAction(self._create_black_box_action)

self._definition_edit_menu = QMenu('Edit', self)
self._definition_menu.addMenu(self._definition_edit_menu)

self._definition_edit_menu.addAction(self._copy_action)
self._definition_edit_menu.addSeparator()
self._definition_edit_menu.addAction(self._move_action)
self._definition_edit_menu.addAction(self._rename_action)
self._definition_edit_menu.addAction(self._add_alias_action)
self._definition_edit_menu.addSeparator()
self._definition_edit_menu.addAction(self._delete_action)
self._definition_edit_menu.addAction(self._hide_action)
self._definition_edit_menu.addAction(self._deprecate_action)

self._definition_menu.addAction(self._compare_action)

self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showContextMenu)

def showContextMenu(self):
index = self.currentIndex()

if not index.isValid():
return

if isinstance(index.data(Qt.UserRole), basestring):
self._library_menu.exec_(QCursor.pos())
else:
icon = index.model().index(index.row(), 0, index.parent()).data(Qt.DecorationRole)
self._create_instance_action.setIcon(icon)
self._definition_menu.exec_(QCursor.pos())
# self.setAlternatingRowColors(True) # Todo: Disabled due to a bug that clipping delegate's text

self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)

def hasSelection(self):
"""Returns True if selection model has selected items, False otherwise."""
return self.selectionModel().hasSelection()

def isSingleSelection(self):
"""Returns True if selection contains only one row."""
return self.hasSelection() and len(self.selectionModel().selectedRows(0)) == 1

def isMultipleSelection(self):
"""Returns True if selection contains more than one row."""
return self.hasSelection() and len(self.selectionModel().selectedRows(0)) > 1

def selectedIndex(self):
"""
Returns a single selected index.
Should be used only when isSingleSelection is True.
Raised IndexError if no selection.
"""
return self.selectionModel().selectedIndexes()[0]

def indexDepth(self, index):
"""Returns level of nesting of the index. Root has level 0."""
depth = 0
while index.isValid():
index = index.parent()
depth += 1
return depth

def deselectDifferingDepth(self, target_index):
"""Remove items with differing level of nesting from the selection model."""
selection_model = self.selectionModel()
target_depth = self.indexDepth(target_index)
for index in selection_model.selectedIndexes():
depth = self.indexDepth(index)
if depth != target_depth:
selection_model.select(index, QItemSelectionModel.Deselect)

def deselectDifferringParent(self, target_index):
raise NotImplementedError
Loading

0 comments on commit d705ef5

Please sign in to comment.