def showMenu( self ): """ Creates a menu to display for the editing of template information. """ item = self.uiMenuTREE.currentItem() menu = QMenu(self) act = menu.addAction('Add Menu...') act.setIcon(QIcon(projexui.resources.find('img/folder.png'))) act.triggered.connect(self.createMenu) if ( item and item.data(0, Qt.UserRole) == 'menu' ): act = menu.addAction('Rename Menu...') ico = QIcon(projexui.resources.find('img/edit.png')) act.setIcon(ico) act.triggered.connect(self.renameMenu) act = menu.addAction('Add Separator') act.setIcon(QIcon(projexui.resources.find('img/ui/splitter.png'))) act.triggered.connect(self.createSeparator) menu.addSeparator() act = menu.addAction('Remove Item') act.setIcon(QIcon(projexui.resources.find('img/remove.png'))) act.triggered.connect(self.removeItem) act.setEnabled(item is not None) menu.exec_(QCursor.pos())
def showMenu(self): """ Creates a menu to display for the editing of template information. """ item = self.uiMenuTREE.currentItem() menu = QMenu(self) act = menu.addAction('Add Menu...') act.setIcon(QIcon(projexui.resources.find('img/folder.png'))) act.triggered.connect(self.createMenu) if (item and item.data(0, Qt.UserRole) == 'menu'): act = menu.addAction('Rename Menu...') ico = QIcon(projexui.resources.find('img/edit.png')) act.setIcon(ico) act.triggered.connect(self.renameMenu) act = menu.addAction('Add Separator') act.setIcon(QIcon(projexui.resources.find('img/ui/splitter.png'))) act.triggered.connect(self.createSeparator) menu.addSeparator() act = menu.addAction('Remove Item') act.setIcon(QIcon(projexui.resources.find('img/remove.png'))) act.triggered.connect(self.removeItem) act.setEnabled(item is not None) menu.exec_(QCursor.pos())
def unholdAction(self): """ Unholds the action from being blocked on the leave event. """ self._actionHeld = False point = self.mapFromGlobal(QCursor.pos()) self.setCurrentAction(self.actionAt(point))
def handleButtonClick(self, button): """ Handle the event when a user clicks on one of the part buttons. :param button | <QToolButton> """ path = button.property('path') is_completer = button.property('is_completer') # popup a completion menu if (unwrapVariant(is_completer)): model = self.navigationModel() if (not model): return sep = self.separator() path = nativestring(unwrapVariant(path)) item = model.itemByPath(path, includeRoot=True) if (not item): return curr_path = nativestring(self.text()).strip(self.separator()) curr_path = curr_path.replace(path, '').strip(self.separator()) child_name = '' if (curr_path): child_name = curr_path.split(self.separator())[0] index = model.indexFromItem(item) self._completerTree.move(QCursor.pos()) self._completerTree.setRootIndex(index) self._completerTree.verticalScrollBar().setValue(0) if (child_name): child_item = None for i in range(item.rowCount()): child = item.child(i) if (child.text() == child_name): child_item = child break if (child_item): child_index = model.indexFromItem(child_item) self._completerTree.setCurrentIndex(child_index) self._completerTree.scrollTo(child_index) self._completerTree.show() self._completerTree.setUpdatesEnabled(True) else: self.setText(unwrapVariant(path))
def handleButtonClick( self, button ): """ Handle the event when a user clicks on one of the part buttons. :param button | <QToolButton> """ path = button.property('path') is_completer = button.property('is_completer') # popup a completion menu if ( unwrapVariant(is_completer) ): model = self.navigationModel() if ( not model ): return sep = self.separator() path = nativestring(unwrapVariant(path)) item = model.itemByPath(path, includeRoot = True) if ( not item ): return curr_path = nativestring(self.text()).strip(self.separator()) curr_path = curr_path.replace(path, '').strip(self.separator()) child_name = '' if ( curr_path ): child_name = curr_path.split(self.separator())[0] index = model.indexFromItem(item) self._completerTree.move(QCursor.pos()) self._completerTree.setRootIndex(index) self._completerTree.verticalScrollBar().setValue(0) if ( child_name ): child_item = None for i in range(item.rowCount()): child = item.child(i) if ( child.text() == child_name ): child_item = child break if ( child_item ): child_index = model.indexFromItem(child_item) self._completerTree.setCurrentIndex(child_index) self._completerTree.scrollTo(child_index) self._completerTree.show() self._completerTree.setUpdatesEnabled(True) else: self.setText(unwrapVariant(path))
def hoverEnterEvent(self, event): """ Processes when this hotspot is entered. :param event | <QHoverEvent> :return <bool> | processed """ self._hovered = True if self.toolTip(): QToolTip.showText(QCursor.pos(), self.toolTip()) return True return self.style() == XNodeHotspot.Style.Icon
def eventFilter(self, object, event): """ Processes when the window is moving to update the position for the popup if in popup mode. :param object | <QObject> event | <QEvent> """ if not self.isVisible(): return False links = self.positionLinkedTo() is_dialog = self.currentMode() == self.Mode.Dialog if object not in links: return False if event.type() == event.Close: self.close() return False if event.type() == event.Hide and not is_dialog: self.hide() return False if event.type() == event.Move and not is_dialog: deltaPos = event.pos() - event.oldPos() self.move(self.pos() + deltaPos) return False if self.currentMode() != self.Mode.ToolTip: return False if event.type() == event.Leave: pos = object.mapFromGlobal(QCursor.pos()) if (not object.rect().contains(pos)): self.close() event.accept() return True if event.type() in (event.MouseButtonPress, event.MouseButtonDblClick): self.close() event.accept() return True return False
def popout(self): self.setParent(self.window()) self.setWindowFlags(Qt.Dialog) self.show() self.raise_() self.activateWindow() pos = QCursor.pos() w = self.width() self.move(pos.x() - w / 2.0, pos.y() - 10) # set the popup instance for this class to this widget key = '_{0}__popupInstance'.format(type(self).__name__) if not hasattr(type(self), key): setattr(type(self), key, weakref.ref(self)) self.poppedOut.emit()
def showToolTip(text, point=None, anchor=None, parent=None, background=None, foreground=None, key=None, seconds=5): """ Displays a popup widget as a tooltip bubble. :param text | <str> point | <QPoint> || None anchor | <XPopupWidget.Mode.Anchor> || None parent | <QWidget> || None background | <QColor> || None foreground | <QColor> || None key | <str> || None seconds | <int> """ if point is None: point = QCursor.pos() if parent is None: parent = QApplication.activeWindow() if anchor is None and parent is None: anchor = XPopupWidget.Anchor.TopCenter # create a new tooltip widget widget = XPopupWidget(parent) widget.setToolTipMode() widget.setResizable(False) # create the tooltip label label = QLabel(text, widget) label.setOpenExternalLinks(True) label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) label.setMargin(3) label.setIndent(3) label.adjustSize() widget.setCentralWidget(label) # update the tip label.adjustSize() widget.adjustSize() palette = widget.palette() if not background: background = palette.color(palette.ToolTipBase) if not foreground: foreground = palette.color(palette.ToolTipText) palette.setColor(palette.Window, QColor(background)) palette.setColor(palette.WindowText, QColor(foreground)) widget.setPalette(palette) widget.centralWidget().setPalette(palette) if anchor is None: widget.setAutoCalculateAnchor(True) else: widget.setAnchor(anchor) widget.setAutoCloseOnFocusOut(True) widget.setAttribute(Qt.WA_DeleteOnClose) widget.popup(point) widget.startTimer(1000 * seconds) return widget
def popup(self, pos=None): """ Pops up this widget at the inputed position. The inputed point should \ be in global space. :param pos | <QPoint> :return <bool> success """ if self._first and self.centralWidget() is not None: self.adjustSize() self._first = False if not self.signalsBlocked(): self.aboutToShow.emit() if not pos: pos = QCursor.pos() if self.currentMode() == XPopupWidget.Mode.Dialog and \ self.isVisible(): return False elif self.currentMode() == XPopupWidget.Mode.Dialog: self.setPopupMode() # auto-calculate the point if self.autoCalculateAnchor(): self.setAnchor(self.mapAnchorFrom(self.parent(), pos)) pad = self.popupPadding() # determine where to move based on the anchor anchor = self.anchor() # MODIFY X POSITION # align x-left if ( anchor & (XPopupWidget.Anchor.TopLeft | XPopupWidget.Anchor.BottomLeft) ): pos.setX(pos.x() - pad) # align x-center elif ( anchor & (XPopupWidget.Anchor.TopCenter | XPopupWidget.Anchor.BottomCenter) ): pos.setX(pos.x() - self.width() / 2) # align x-right elif ( anchor & (XPopupWidget.Anchor.TopRight | XPopupWidget.Anchor.BottomRight) ): pos.setX(pos.x() - self.width() + pad) # align x-padded elif ( anchor & (XPopupWidget.Anchor.RightTop | XPopupWidget.Anchor.RightCenter | XPopupWidget.Anchor.RightBottom) ): pos.setX(pos.x() - self.width()) # MODIFY Y POSITION # align y-top if ( anchor & (XPopupWidget.Anchor.LeftTop | XPopupWidget.Anchor.RightTop) ): pos.setY(pos.y() - pad) # align y-center elif ( anchor & (XPopupWidget.Anchor.LeftCenter | XPopupWidget.Anchor.RightCenter) ): pos.setY(pos.y() - self.height() / 2) # align y-bottom elif ( anchor & (XPopupWidget.Anchor.LeftBottom | XPopupWidget.Anchor.RightBottom) ): pos.setY(pos.y() - self.height() + pad) # align y-padded elif ( anchor & (XPopupWidget.Anchor.BottomLeft | XPopupWidget.Anchor.BottomCenter | XPopupWidget.Anchor.BottomRight) ): pos.setY(pos.y() - self.height()) self.adjustMask() self.move(pos) self.update() self.setUpdatesEnabled(True) if self.isAnimated(): anim = QPropertyAnimation(self, 'windowOpacity') anim.setParent(self) anim.setStartValue(0.0) anim.setEndValue(self.windowOpacity()) anim.setDuration(500) anim.finished.connect(anim.deleteLater) self.setWindowOpacity(0.0) else: anim = None self.show() if self.currentMode() != XPopupWidget.Mode.ToolTip: self.activateWindow() widget = self.centralWidget() if widget: self.centralWidget().setFocus() if anim: anim.start() if not self.signalsBlocked(): self.shown.emit() return True
def showProfileMenu(self, point): """ Prompts the user for profile menu options. Editing needs to be enabled for this to work. """ if not self.isEditingEnabled(): return trigger = self.actionAt(point) if (isinstance(trigger, XViewProfileAction)): prof = trigger.profile() else: prof = None # define the menu menu = QMenu(self) acts = {} text = self.profileText() # user right clicked on a profile if prof: acts['edit'] = menu.addAction('Edit {0}...'.format(text)) acts['save'] = menu.addAction('Save Layout') menu.addSeparator() acts['copy'] = menu.addAction('Copy {0}'.format(text)) acts['export'] = menu.addAction('Export {0}...'.format(text)) menu.addSeparator() acts['remove'] = menu.addAction('Delete {0}'.format(text)) # show toolbar options else: acts['new'] = menu.addAction('New Layout'.format(text)) menu.addSeparator() acts['save_as'] = menu.addAction('Save Layout as...') if QApplication.clipboard().text(): acts['paste'] = menu.addAction('Paste {0}'.format(text)) acts['import'] = menu.addAction('Import {0}...'.format(text)) for key, act in acts.items(): act.setIcon(QIcon(resources.find('img/{0}.png'.format(key)))) # run the menu act = menu.exec_(QCursor.pos()) # create a new profile if act is None: return elif act == acts.get('new'): self.clearActive() # create a new clear profile elif act == acts.get('save_as'): self.saveProfileAs() # edit an existing profile elif act == acts.get('edit'): self.editProfile(prof) # save or create a new profile elif act == acts.get('save'): self.saveProfileLayout(prof) # copy profile elif act == acts.get('copy'): QApplication.clipboard().setText(prof.toString()) # export elif act == acts.get('export'): self.exportProfile(prof) # export elif act == acts.get('import'): self.importProfile() # paste profile elif act == acts.get('paste'): text = QApplication.clipboard().text() try: prof = XViewProfile.fromString(text) except: prof = None QMessageBox.information(self.window(), 'Invalid {0}'.format(text), 'The clipboard text does not contain '\ 'a properly formated {0}'.format(text)) if prof and not prof.isEmpty(): self.createProfile(profile=prof) # paste as profile elif act == acts.get('paste_as'): text = QApplication.clipboard().text() prof = XViewProfile.fromString(text) if not prof.isEmpty(): if XViewProfileDialog.edit(self, prof): self.createProfile(profile=prof) # remove the profile elif act == acts.get('remove'): self.removeProfile(prof)
def showToolTip( text, point = None, anchor = None, parent = None, background = None, foreground = None, key = None, seconds = 5 ): """ Displays a popup widget as a tooltip bubble. :param text | <str> point | <QPoint> || None anchor | <XPopupWidget.Mode.Anchor> || None parent | <QWidget> || None background | <QColor> || None foreground | <QColor> || None key | <str> || None seconds | <int> """ if point is None: point = QCursor.pos() if parent is None: parent = QApplication.activeWindow() if anchor is None and parent is None: anchor = XPopupWidget.Anchor.TopCenter # create a new tooltip widget widget = XPopupWidget(parent) widget.setToolTipMode() widget.setResizable(False) # create the tooltip label label = QLabel(text, widget) label.setOpenExternalLinks(True) label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) label.setMargin(3) label.setIndent(3) label.adjustSize() widget.setCentralWidget(label) # update the tip label.adjustSize() widget.adjustSize() palette = widget.palette() if not background: background = palette.color(palette.ToolTipBase) if not foreground: foreground = palette.color(palette.ToolTipText) palette.setColor(palette.Window, QColor(background)) palette.setColor(palette.WindowText, QColor(foreground)) widget.setPalette(palette) widget.centralWidget().setPalette(palette) if anchor is None: widget.setAutoCalculateAnchor(True) else: widget.setAnchor(anchor) widget.setAutoCloseOnFocusOut(True) widget.setAttribute(Qt.WA_DeleteOnClose) widget.popup(point) widget.startTimer(1000 * seconds) return widget
def popup(self, pos=None): """ Pops up this widget at the inputed position. The inputed point should \ be in global space. :param pos | <QPoint> :return <bool> success """ if self._first and self.centralWidget() is not None: self.adjustSize() self._first = False if not self.signalsBlocked(): self.aboutToShow.emit() if not pos: pos = QCursor.pos() if self.currentMode() == XPopupWidget.Mode.Dialog and \ self.isVisible(): return False elif self.currentMode() == XPopupWidget.Mode.Dialog: self.setPopupMode() # auto-calculate the point if self.autoCalculateAnchor(): self.setAnchor(self.mapAnchorFrom(self.parent(), pos)) pad = self.popupPadding() # determine where to move based on the anchor anchor = self.anchor() # MODIFY X POSITION # align x-left if (anchor & (XPopupWidget.Anchor.TopLeft | XPopupWidget.Anchor.BottomLeft)): pos.setX(pos.x() - pad) # align x-center elif (anchor & (XPopupWidget.Anchor.TopCenter | XPopupWidget.Anchor.BottomCenter)): pos.setX(pos.x() - self.width() / 2) # align x-right elif ( anchor & (XPopupWidget.Anchor.TopRight | XPopupWidget.Anchor.BottomRight)): pos.setX(pos.x() - self.width() + pad) # align x-padded elif (anchor & (XPopupWidget.Anchor.RightTop | XPopupWidget.Anchor.RightCenter | XPopupWidget.Anchor.RightBottom)): pos.setX(pos.x() - self.width()) # MODIFY Y POSITION # align y-top if (anchor & (XPopupWidget.Anchor.LeftTop | XPopupWidget.Anchor.RightTop)): pos.setY(pos.y() - pad) # align y-center elif (anchor & (XPopupWidget.Anchor.LeftCenter | XPopupWidget.Anchor.RightCenter)): pos.setY(pos.y() - self.height() / 2) # align y-bottom elif (anchor & (XPopupWidget.Anchor.LeftBottom | XPopupWidget.Anchor.RightBottom)): pos.setY(pos.y() - self.height() + pad) # align y-padded elif ( anchor & (XPopupWidget.Anchor.BottomLeft | XPopupWidget.Anchor.BottomCenter | XPopupWidget.Anchor.BottomRight)): pos.setY(pos.y() - self.height()) self.adjustMask() self.move(pos) self.update() self.setUpdatesEnabled(True) if self.isAnimated(): anim = QPropertyAnimation(self, 'windowOpacity') anim.setParent(self) anim.setStartValue(0.0) anim.setEndValue(self.windowOpacity()) anim.setDuration(500) anim.finished.connect(anim.deleteLater) self.setWindowOpacity(0.0) else: anim = None self.show() if self.currentMode() != XPopupWidget.Mode.ToolTip: self.activateWindow() widget = self.centralWidget() if widget: self.centralWidget().setFocus() if anim: anim.start() if not self.signalsBlocked(): self.shown.emit() return True