def listItemRightClicked(self, QPos): self.listMenu = QtGui.QMenu() self.listMenu.setStyleSheet(""" QMenu { background-color: #313131; border: 1px solid ; } QMenu::item::selected { background-color: #1e1e1e; } """) import_mtl = self.listMenu.addAction("Import Material") import_klf = self.listMenu.addAction("Import Lookfile") import_Lmtl = self.listMenu.addAction("Create Material") delete_mtl = self.listMenu.addAction("Delete Material") self.connect(import_mtl, QtCore.SIGNAL("triggered()"), self.importMtl) self.connect(import_klf, QtCore.SIGNAL("triggered()"), self.importKlf) self.connect(import_Lmtl, QtCore.SIGNAL("triggered()"), self.importLmtl) self.connect(delete_mtl, QtCore.SIGNAL("triggered()"), self.deleteMtl) parentPosition = self.listWidget.mapToGlobal(QtCore.QPoint(0, 0)) self.listMenu.move(parentPosition + QPos) self.listMenu.show()
def buildWidgets(self, hints): """Creates most of the UI widgets""" label = QtGui.QLabel(" (PyMock)", self) label.setProperty('smallFont', True) label.setProperty('boldFont', True) p = label.palette() p.setColor(QtGui.QPalette.WindowText, QtGui.QColor(255, 200, 0)) p.setColor(QtGui.QPalette.Text, QtGui.QColor(255, 200, 0)) label.setPalette(p) self.layout().addWidget(label) self.layout().addWidget(QtGui.QLabel("mock://")) self.__showEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__showEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__shotEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__shotEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__assetEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__assetEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__versionEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__versionEdit) self.connect(self.__showEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__shotEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__assetEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__versionEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus)
def __init__(self): QtGui.QFrame.__init__(self) QtGui.QHBoxLayout(self) self.__showList = self.__buildListWidget("Show", self.layout()) self.__shotList = self.__buildListWidget("Shot", self.layout()) self.__nameList = self.__buildListWidget("Asset", self.layout()) self.__versionList = self.__buildListWidget("Version", self.layout()) self.connect(self.__showList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateShow) self.connect(self.__shotList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateShot) self.connect(self.__nameList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateAsset) self.connect(self.__versionList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateVersion) self.__widgetsDict = { "show": self.__showList, "shot": self.__shotList, "name": self.__nameList, "version": self.__versionList, } self.__showList.clear() self.__showList.addItems(_getShows())
def __init__(self, *args): """ Initialize and configure the button widget """ Widgets.FilterablePopupButton.__init__(self, *args) self.setFixedHeight(24) self.setFlat(False) self.setSorting(False) QtCore.QObject.connect(self, QtCore.SIGNAL('aboutToShow'), self.__on_aboutToShow) QtCore.QObject.connect(self, QtCore.SIGNAL('itemChosen'), self.__on_itemChosen) self.__pathToDisplayInfo = {} self.__pixmaps = \ {'camera': QtGui.QPixmap(ScenegraphIconManager.GetPixmap('camera')), 'light': QtGui.QPixmap(ScenegraphIconManager.GetPixmap('light'))} self.__scenegraphPixmap = None # Argument is reference to the widget which allows us to get the node if args[0]: self.__node = args[0].getNode() # displayMode will be set to either <DISPLAY_LIGHTS, DISPLAY_CAMERAS, # DISPLAY_LIGHTS | DISPLAY_CAMERAS> if the mode is # DISPLAY_LIGHTS | DISPLAY_CAMERAS, then this indicates that the button # is the big center one at the bottom of the viewports. It will draw # the camera/light name in text, rather than pixmaps as its icon. self.__displayMode = 0 self.setAcceptDrops(True)
def __init__(self, parent): UI4.Tabs.BaseTab.__init__(self, parent) QtGui.QVBoxLayout(self) self.layout().setContentsMargins(4, 4, 4, 4) self._MonitorColorControl__monitorGammaWidget = QT4Color.MonitorGammaWidget( self) self.layout().addWidget(self._MonitorColorControl__monitorGammaWidget, 0) self.connect(self._MonitorColorControl__monitorGammaWidget, QtCore.SIGNAL('valueChanged'), self._MonitorColorControl__monitorChanged_CB) self._MonitorColorControl__colorGradeWidget = QT4Color.ColorGradeWidget( self, title='Primary Color Grade', createChildrenInScroll=True) self.layout().addWidget(self._MonitorColorControl__colorGradeWidget, 10) self.connect(self._MonitorColorControl__colorGradeWidget, QtCore.SIGNAL('valueChanged'), self._MonitorColorControl__gradeChanged_CB) self._MonitorColorControl__updateTimer = QtCore.QTimer(self) self.connect(self._MonitorColorControl__updateTimer, QtCore.SIGNAL('timeout()'), self._MonitorColorControl__timer_CB) Utils.EventModule.RegisterCollapsedHandler( self._MonitorColorControl__monitor_drawStateUpdated_CB, 'monitor_drawStateUpdated', None, True)
def paintEvent(self, event): if self.picture: painter = QtGui.QPainter(self) painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) width = self.parent().width() height = self.parent().height() if height > (width * 429) / 1024: rect = QtCore.QRect(0, (height - (width * 429) / 1024) / 2, width, (width * 429) / 1024) else: rect = QtCore.QRect((width - (height * 1024) / 429) / 2, 0, (height * 1024) / 429, height) painter.drawPixmap(rect, self.picture)
def __init__(self): """Builds the initial combose box UI""" QtGui.QFrame.__init__(self) QtGui.QVBoxLayout(self) assetFrame = QtGui.QFrame(self) QtGui.QHBoxLayout(assetFrame) self.layout().addWidget(assetFrame) assetFrame.layout().addWidget(QtGui.QLabel("show:")) self.__showCombobox = QtGui.QComboBox() assetFrame.layout().addWidget(self.__showCombobox) assetFrame.layout().addWidget(QtGui.QLabel("shot:")) self.__shotCombobox = QtGui.QComboBox() assetFrame.layout().addWidget(self.__shotCombobox) assetFrame.layout().addWidget(QtGui.QLabel("asset:")) self.__assetCombobox = QtGui.QComboBox() assetFrame.layout().addWidget(self.__assetCombobox) assetFrame.layout().addWidget(QtGui.QLabel("version:")) self.__versionCombobox = QtGui.QComboBox() assetFrame.layout().addWidget(self.__versionCombobox) self.connect(self.__showCombobox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.__updateShow) self.connect(self.__shotCombobox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.__updateShot) self.connect(self.__assetCombobox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.__updateAsset) self.connect(self.__versionCombobox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.__updateVersion) # Modify the integrated QListViews to lay out the items every time the # view is resized, so that changes in the application font preferences # are correctly reflected for combobox in (self.__showCombobox, self.__shotCombobox, self.__assetCombobox, self.__versionCombobox): combobox.view().setResizeMode(QtGui.QListView.Adjust) self.__sandboxCheckBox = QtGui.QCheckBox('Save to Sandbox', self) self.layout().addWidget(self.__sandboxCheckBox) self.__showCombobox.addItems(_getShows())
def __init__(self, castingSheetNode, parent, node, label, state): QtGui.QAction.__init__(self, label, parent) self.__node = node self.__state = state self.__castingSheetNode = castingSheetNode self.connect(self, QtCore.SIGNAL('triggered(bool)'), self.__go)
def __init__(self, parent): QtWidgets.QWidget.__init__(self, parent) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(4, 4, 4, 4) layout.setSpacing(2) self.__iconLabel = QtWidgets.QLabel('', self) self.__iconLabel.setFixedSize(QtCore.QSize(16, 16)) self.__textLabel = QtWidgets.QLabel('', self) self.__inputEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.__inputEdit.hide() layout.addWidget(self.__iconLabel) layout.addWidget(self.__textLabel) layout.addWidget(self.__inputEdit, 2) layout.addStretch() self.__enableCustomName = QtWidgets.QCheckBox('use custom asset name', self) self.__enableCustomName.hide() self.setFixedHeight(self.__inputEdit.height()) layout.addWidget(self.__enableCustomName) self.__enableCustomName.clicked.connect(self.__enableClicked) if hasattr(self.__inputEdit, 'EMITS_CUSTOM_FOCUS_EVENTS' ) and self.__inputEdit.EMITS_CUSTOM_FOCUS_EVENTS: self.__inputEdit.lostFocus.connect(self.__customFieldChanged) else: self.__inputEdit.lostFocus.connect(self.__customFieldChanged)
def _jump_to_sg(self): """ Jump to Shotgun, launch web browser. """ url = self.engine.context.shotgun_url QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
def __init__(self, parent, label, parentPath, nodeName, preselectMethod): QtGui.QAction.__init__(self, label, parent) self.__parentPath = parentPath self.__nodeName = nodeName self.__preselectMethod = preselectMethod self.connect(self, QtCore.SIGNAL('triggered(bool)'), self.go)
class kTitleLabel(QtGui.QLabel): resized = QtCore.pyqtSignal() def __init__(self, parent=None): QtGui.QToolButton.__init__(self, parent) self.resized.connect(self.setButtonGeometry) self.h = 40 self.button = QtGui.QToolButton() self.button.setAutoRaise(True) self.button.setIconSize(QtCore.QSize(28, 28)) self.button.setParent(self) def resizeEvent(self, event): self.resized.emit() return super(kTitleLabel, self).resizeEvent(event) def setButtonGeometry(self): self.button.setGeometry(self.width() - self.h, 0, self.h, self.h) def setIcon(self, path): self.button.setIcon(QtGui.QIcon(path)) def setScript(self, function): self.button.clicked.connect( lambda arg=None, args=function: self.runScript(args)) def runScript(self, script): exec(script) def setHeight(self, height): self.h = height self.setFixedHeight(height)
def buildWidgets(self, hints): """Creates most of the UI widgets""" label = QtGui.QLabel(" (PyMock)", self) label.setProperty('smallFont', True) label.setProperty('boldFont', True) p = label.palette() p.setColor(QtGui.QPalette.WindowText, QtGui.QColor(255, 200, 0)) p.setColor(QtGui.QPalette.Text, QtGui.QColor(255, 200, 0)) label.setPalette(p) self.layout().addWidget(label) self.__protocolLabel = QtGui.QLabel("mock://") self.layout().addWidget(self.__protocolLabel) self.__showEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__showEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__shotEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__shotEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__assetEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__assetEdit) self.layout().addWidget(QtGui.QLabel("/")) self.__versionEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.layout().addWidget(self.__versionEdit) self.connect(self.__showEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__shotEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__assetEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) self.connect(self.__versionEdit, QtCore.SIGNAL("lostFocus"), self.__lostFocus) # Add a context menu to the protocol label self.__protocolLabel.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.connect( self.__protocolLabel, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.onContextMenu) self.__popupMenu = QtGui.QMenu(self) self.__popupMenu.addAction("Swap protocol", self.onSwapProtocol)
def __init__(self): QtGui.QFrame.__init__(self) QtGui.QHBoxLayout(self) self.__tabWidget = QtGui.QTabWidget(self) self.layout().addWidget(self.__tabWidget) assetTab = QtGui.QFrame(self) QtGui.QHBoxLayout(assetTab) self.__tabWidget.addTab(assetTab, "Asset") self.__showList = self.__buildListWidget("Show", assetTab.layout()) self.__shotList = self.__buildListWidget("Shot", assetTab.layout()) self.__nameList = self.__buildListWidget("Asset", assetTab.layout()) self.__versionList = self.__buildListWidget("Version", assetTab.layout()) self.connect(self.__showList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateShow) self.connect(self.__shotList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateShot) self.connect(self.__nameList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateAsset) self.connect(self.__versionList, QtCore.SIGNAL("itemSelectionChanged()"), self.__updateVersion) sandboxTab = QtGui.QFrame(self) QtGui.QHBoxLayout(sandboxTab) self.__tabWidget.addTab(sandboxTab, "Sandbox") self.__sandboxList = self.__buildListWidget("Sandbox", sandboxTab.layout()) self.__widgetsDict = { "show": self.__showList, "shot": self.__shotList, "name": self.__nameList, "version": self.__versionList, "sandbox": self.__sandboxList, } self.__showList.clear() self.__showList.addItems(_getShows()) self.__sandboxList.addItems(_getSandboxFiles())
def __init__(self, parent=None): QtGui.QToolButton.__init__(self, parent) self.resized.connect(self.setButtonGeometry) self.h = 40 self.button = QtGui.QToolButton() self.button.setAutoRaise(True) self.button.setIconSize(QtCore.QSize(28, 28)) self.button.setParent(self)
def populate(self): self.listWidget.clear() self.listWidget.setIconSize( QtCore.QSize(self.icon_size.value(), self.icon_size.value())) self.listWidget.setGridSize( QtCore.QSize(self.icon_size.value() + 20, self.icon_size.value() + 30)) checkCat = str(self.catedoryCB.currentText()) if not checkCat == 'ALL': directory = os.path.join(self.directory, checkCat) self.popItems(directory) else: for root, dirs, files in os.walk(self.directory): for dir in dirs: directory = os.path.join(root, dir) self.popItems(directory)
def sizeHint(self): """ Get the size """ if self.__displayMode == (DISPLAY_LIGHTS | DISPLAY_CAMERAS): w = self.fontMetrics().width(self.text()) + 16 else: w=8 #set some initial arbitrary size if self.__scenegraphPixmap: w += self.__scenegraphPixmap.width() return QtCore.QSize(w, 24)
def aboutToDrag(item, dragObject): if not item: return item = item[0] mimeData = dragObject.mimeData() if not mimeData: mimeData = QtCore.QMimeData() dragObject.setMimeData(mimeData) mimeData.setData('ShadowManager/lightpass', item.getItemData().getName()) mimeData.setData('scenegraph/paths', item.getItemData().getName())
def __buildToolbar(self, parent): self.__toolbarLayout = QtGui.QHBoxLayout() parent.layout().addLayout(self.__toolbarLayout) self.__scopePopup = QtGui.QComboBox(parent) self.connect(self.__scopePopup, QtCore.SIGNAL('currentIndexChanged(const QString &)'), self.__refresh) self.__scopePopup.addItems([ 'Selected ShadingNodes', 'All ShadingNodes', 'Upstream of NetworkMaterial' ]) self.__toolbarLayout.addWidget(self.__scopePopup) self.__shadingNetworkMaterialsPopup = QtGui.QComboBox(parent) self.__shadingNetworkMaterialsPopup.addItems( [x.getName() for x in self.__getNetworkMaterials()]) self.connect(self.__shadingNetworkMaterialsPopup, QtCore.SIGNAL('currentIndexChanged(const QString &)'), self.__refresh) self.__shadingNetworkMaterialsPopup.hide() self.__toolbarLayout.addWidget(self.__shadingNetworkMaterialsPopup) self.__toolbarLayout.addStretch() self.__filterField = Widgets.FilterFieldWidget(parent) self.connect(self.__filterField, QtCore.SIGNAL('filterUpdate'), self.__filterUpdate) self.__toolbarLayout.addWidget(self.__filterField) self.__statusBar = QtGui.QLabel('', parent) parent.layout().addWidget(self.__statusBar)
def lightListWidgetMousePressEvent(event): """ Handle mouse events """ # Set up context menu (right-click) if event.button() == QtCore.Qt.RightButton: item = lightListWidget.itemAt(event.pos()) if not item: return scriptItem = item.getItemData() item.setHiliteColor(QtGui.QColor(32,32,32)) lightListWidget.update(lightListWidget.indexFromItem(item)) menu = QtGui.QMenu(None) # Render options UI4.Util.RenderMenu.AddRenderItemsToMenu( menu, scriptItem.getRenderNode(), None) menu.addSeparator() # Add 'Delete' action def delete(): # Delete selected light pass items for item in lightListWidget.selectedItems(): item.getItemData().delete() menu.addAction('Delete', delete) menu.addSeparator() # Add 'View From Render Node' action def viewNode(): NodegraphAPI.SetNodeViewed( scriptItem.getRenderNode(), True, exclusive=True) action = menu.addAction('View From Render Node', viewNode) action.setIcon(UI4.Util.IconManager.GetIcon( 'Icons/AttributeEditor/blue_snapback.png')) # Show menu pos = event.pos() pos = lightListWidget.mapToGlobal(QtCore.QPoint( pos.x(), pos.y() + lightListWidget.header().height())) try: menu.exec_(pos) finally: item.setHiliteColor(None) lightListWidget.update(lightListWidget.indexFromItem(item)) event.accept() self.updateLightList()
def dropEvent(self, event): """ Handle drop events on the camera/light picker button """ if event.source() == self: return if event.mimeData().hasFormat('scenegraph/paths'): locations = str(event.mimeData().data('scenegraph/paths')).split() if len(locations) == 1: location = locations[0] if _GetLocationType(self.__node, location) in ('light', 'camera'): self.emit(QtCore.SIGNAL('itemChosen'), None, [location, 'camera'])
def setDisplayMode(self, mode): """ Set display mode and corresponding tool tips, icons, etc. """ self.__displayMode = mode if self.__displayMode == (DISPLAY_LIGHTS | DISPLAY_CAMERAS): switchArea = self.getWidgetSwitchArea() self.__topHBox = QtGui.QFrame(switchArea) switchArea.layout().addWidget(self.__topHBox) self.__topHBox.setLayout(QtGui.QHBoxLayout()) spacer = QtGui.QLabel('', self) self.__topHBox.layout().addWidget(spacer) self.__topHBox.layout().setStretchFactor(spacer, 100) self.__lightsCheckbox = QtGui.QCheckBox("Lights", self.__topHBox) self.__lightsCheckbox.setChecked(True) self.__topHBox.layout().addWidget(self.__lightsCheckbox) QtCore.QObject.connect(self.__lightsCheckbox, QtCore.SIGNAL('stateChanged(int)'), self.__on_lightsCheckbox_stateChanged) self.__camerasCheckbox = QtGui.QCheckBox("Cameras", self.__topHBox) self.__camerasCheckbox.setChecked(True) self.__topHBox.layout().addWidget(self.__camerasCheckbox) QtCore.QObject.connect(self.__camerasCheckbox, QtCore.SIGNAL('stateChanged(int)'), self.__on_camerasCheckbox_stateChanged) self.setToolTip("Choose Light or Camera") elif mode & DISPLAY_LIGHTS: self.setScenegraphPixmap(self.__pixmaps['light']) self.setToolTip("Choose Light") else: self.setScenegraphPixmap(self.__pixmaps['camera']) self.setToolTip("Choose Camera")
def aboutToDrag(item, dragObject): if not item: return item = item[0] mimeData = dragObject.mimeData() if not mimeData: mimeData = QtCore.QMimeData() dragObject.setMimeData(mimeData) mimeData.setData('ShadowManager/renderpass', item.getItemData().getName()) mimeData.setData('python/text', 'NodegraphAPI.GetNode(%r).getRenderPasses()[%i]' % ( self.__node.getName(), item.getItemData().getIndex()))
def paintEvent(self, event): """ Overrides the base paint event so we can overlay our circle. """ QtGui.QLabel.paintEvent(self, event) if self.__xPoint > 0 and self.__yPoint > 0: paint = QtGui.QPainter() paint.begin(self) paint.setRenderHint(QtGui.QPainter.Antialiasing) paint.setPen(QtGui.QColor(0, 255, 0)) paint.setBrush(QtGui.QColor(0, 255, 0)) center = QtCore.QPoint(self.__xPoint, self.__yPoint) paint.drawEllipse(center, 5, 5) paint.end()
def __init__(self, parent): BaseTab.__init__(self, parent) # directories self.matlibPath = os.getenv('LIGHTSHADER_MATLIB') self.directory = os.path.join(self.matlibPath, 'material_library') self.resources = os.path.join(self.matlibPath, 'resources') ######################################################### # functions self.buildUI() self.categories() self.populate() # for right click self.listWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.listWidget.connect( self.listWidget, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.listItemRightClicked)
def treeWidgetMousePressEvent(event): """ Handle mouse events """ # Set up context menu (right-click) if event.button() == QtCore.Qt.RightButton: item = treeWidget.itemAt(event.pos()) if not item: return scriptItem = item.getItemData() item.setHiliteColor(QtGui.QColor(32,32,32)) treeWidget.update(treeWidget.indexFromItem(item)) menu = QtGui.QMenu(None) # Add 'Delete' action menu.addAction('Delete', scriptItem.delete) menu.addSeparator() # Add 'View From ShadowBranch Node' action def viewNode(): NodegraphAPI.SetNodeViewed( scriptItem.getShadowBranchNode(), True, exclusive=True) action = menu.addAction('View From ShadowBranch Node',viewNode) action.setIcon(UI4.Util.IconManager.GetIcon( 'Icons/AttributeEditor/blue_snapback.png')) # Show menu pos = event.pos() pos = treeWidget.mapToGlobal(QtCore.QPoint( pos.x(), pos.y())) try: menu.exec_(pos) finally: item.setHiliteColor(None) treeWidget.update(treeWidget.indexFromItem(item)) event.accept()
def __aboutToDragCallback(self, items, dragObject): itemData = items[0].getItemData() mimeType = 'nodegraph/noderefs' if 'node' in itemData: name = itemData['node'].getName() else: if 'port' in itemData: name = (' ').join( (x.getName() for x in self.node.getProductStructureForOutput( itemData['port'].getName()))) else: if itemData.get('type') == 'assetTree': name = '' mimeType = 'importatomic/assettree' else: name = self.node.getName() data = dragObject.mimeData() if not data: data = QtCore.QMimeData() data.setData(mimeType, name) if not dragObject.mimeData(): dragObject.setMimeData(data)
def __init__(self, parent, node): QtGui.QAction.__init__(self, "Add Pony", parent) self.__node = node if node: self.connect(self, QtCore.SIGNAL('triggered(bool)'), self.__triggered)
def __init__(self, parent, node): node.upgrade() self.__node = node QtGui.QWidget.__init__(self, parent) QtGui.QVBoxLayout(self) self.__frozen = True self.__updateTreeOnIdle = False self.__selectedPonyPolicy = None self.__preselectName = None # location FormWidget locationPolicy = UI4.FormMaster.CreateParameterPolicy( None, self.__node.getParameter('location')) factory = UI4.FormMaster.KatanaFactory.ParameterWidgetFactory w = factory.buildWidget(self, locationPolicy) self.layout().addWidget(w) # toolbar self.__toolbarLayout = QtGui.QHBoxLayout() self.layout().addItem(self.__toolbarLayout) self.__addButton = UI4.Widgets.ToolbarButton( 'Add Pony', self, UI4.Util.IconManager.GetPixmap('Icons/plus16.png'), rolloverPixmap=UI4.Util.IconManager.GetPixmap( 'Icons/plusHilite16.png')) self.connect(self.__addButton, QtCore.SIGNAL('clicked()'), self.__addButtonClicked) self.__toolbarLayout.addWidget(self.__addButton) self.__toolbarLayout.addStretch() # tree widget self.__treeStretchBox = UI4.Widgets.StretchBox(self, allowHorizontal=False, allowVertical=True) self.layout().addWidget(self.__treeStretchBox) self.__treeWidget = QT4Widgets.SortableTreeWidget( self.__treeStretchBox) self.__treeWidget.setHeaderLabels(['Name']) self.__treeWidget.setSelectionMode(QtGui.QTreeWidget.SingleSelection) self.__treeWidget.setAllColumnsShowFocus(True) self.__treeWidget.setRootIsDecorated(False) self.__treeWidget.header().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.__treeWidget.header().setClickable(False) self.connect(self.__treeWidget, QtCore.SIGNAL('itemSelectionChanged()'), self.__treeWidgetSelectionChanged) self.connect(self.__treeWidget, QtCore.SIGNAL('keyPressEvent'), self.__treeWidgetKeyPressCallback) self.__treeStretchBox.layout().addWidget(self.__treeWidget) self.__treeStretchBox.setFixedHeight(120) self.__formItemTree = QT4FormWidgets.FormItemTree(self) self.layout().addWidget(self.__formItemTree) self.__updateTreeContents() self.layout().addStretch()
def __listMousePressEvent(self, event): item = self.tree.itemAt(event.pos()) if not item: return pos = event.pos() pos = self.tree.mapToGlobal( QtCore.QPoint(pos.x(), pos.y() + self.tree.header().height())) self.__lastTreePos = event.pos() self.__lastPos = pos if event.button() == QtCore.Qt.LeftButton: local_pos = event.pos() global_pos = pos if self.__popupVersions(item, local_pos, global_pos): event.accept() else: if event.button() == QtCore.Qt.RightButton: if item.isSelected(): items = self.tree.selectedItems() else: items = [item] for item in items: dark = QtGui.QColor(32, 32, 32) item.setHiliteColor(dark) self.tree.update(self.tree.indexFromItem(item)) menu = QtWidgets.QMenu(None) types = set((i.getItemData()['type'] for i in items)) if len(types) > 1: menu.addAction(RemoveItemsAction(menu, self.node, items)) else: itemType = tuple(types)[0] if itemType == 'output': if str(item.text(NAME_COLUMN)) == 'default': a = menu.addAction( '(Default Output Cannot Be Removed)') a.setEnabled(False) else: menu.addAction( RemoveItemsAction(menu, self.node, items)) else: if itemType == 'assetTree': assetItem = item.getItemData()['assetItem'] if assetItem.isIgnorable(): menu.addAction( ToggleIgnoreItemsAction( menu, self.node, items, not assetItem.isIgnored())) if assetItem.isDeletable(): try: menu.addAction( RemoveItemsAction( menu, self.node, items)) except Exception as exception: log.exception( 'Error adding action to context menu: %s' % str(exception)) if assetItem.canDuplicate(): try: menu.addAction( DuplicateItemAction( menu, self.node, items)) except: import traceback traceback.print_exc() if len(items) == 1: assetItem.addToContextMenu(menu, self.node) menu.exec_(pos) for item in items: item.setHiliteColor(None) self.tree.update(self.tree.indexFromItem(item)) event.accept() return