def __init__(self, dock=True): # Check if UI should be dockable or not if dock: # Yes, use function to get the dock parent = getDock() else: # No, remove all instances of the dock so we wont get multiple UIs deleteDock() # If UI already exists, delete it first try: pm.deleteUI('lightingManager') except: logger.debug('No previous UI exists') # Create dialog window that our manager will be inside # Store as parent for our current UI to be put inside parent = QtWidgets.QDialog(parent=getMayaMainWindow()) parent.setObjectName('lightingManager') parent.setWindowTitle('Lighting Manager') layout = QtWidgets.QVBoxLayout(parent) # Send our parent to be properly initialized super(LightManager, self).__init__(parent=parent) # Build and populate our UI with exisitng lights self.buildUI() self.populate() # Add Lighting Manager to our parent and show our parent # Maya dock automatically shows, but QDialog will not automatically show self.parent().layout().addWidget(self) if not dock: parent.show()
def results_ui(self, status, color="white", logPath=None): self.msgDialog = QtWidgets.QDialog(parent=self) self.msgDialog.setModal(True) self.msgDialog.setObjectName("Result_Dialog") self.msgDialog.setWindowTitle("Transfer Results") self.msgDialog.resize(300,120) layoutMain = QtWidgets.QVBoxLayout() self.msgDialog.setLayout(layoutMain) infoHeader = QtWidgets.QLabel(status) infoHeader.setStyleSheet("" "border: 18px solid black;" "background-color: black;" "font-size: 14px;" "color: {0}" "".format(color)) layoutMain.addWidget(infoHeader) layoutH = QtWidgets.QHBoxLayout() layoutMain.addLayout(layoutH) if logPath: showLogButton = QtWidgets.QPushButton("Show Log File") layoutH.addWidget(showLogButton) showLogButton.clicked.connect(lambda x=logPath: os.startfile(x)) okButton = QtWidgets.QPushButton("OK") layoutH.addWidget(okButton) okButton.clicked.connect(self.msgDialog.close) self.msgDialog.show()
def showPropertyEditor(self): tree = EditPropertiesTreeWidget() count = self.contentLayout.count() folders = {} for i in range(count): item = self.contentLayout.itemAt(i) w = item.widget() if w: if w.title() in ["Inputs"]: for key, group in w.groups.items(): if key not in folders: folders[key] = {} #for e in range(group.groupLayout.count()): # w = group.groupLayout.itemAt(e).widget() # folders[key][w.getLabel()] = group.groupLayout.itemAt(e).widget() for fold in folders: folder = tree.addFolder(fold) #for widg in folders[fold]: # child = tree.addNormal(widg,folder) d = QtWidgets.QDialog() d.setLayout(QtWidgets.QHBoxLayout()) d.layout().addWidget(tree) d.exec_() newOrder = tree.model_to_dict()
def __init__(self): self.namespace = None # if the ui exists then delete it old_window = omui.MQtUtil_findWindow('ribbonTools') if old_window: cmds.deleteUI('ribbonTools') # create a new dialog and give it the main maya window as its parent # store it as the parent for our current UI to be put inside parent = QtWidgets.QDialog(parent=getMayaMainWindow()) # set its name so that we can find and delete it later parent.setObjectName('ribbonTools') parent.setWindowTitle('Ribbon Tools') super(RibbonTools, self).__init__(parent=parent) dlgLayout = QtWidgets.QVBoxLayout(parent) self.buildUI() self.parent().layout().addWidget(self) parent.show()
def __init__(self, dock=True): if dock: parent = getDock() else: deleteDock() # try this, if there is no ui, continue try: pm.deleteUI('lightingManager') except: logger.debug('No previous UI exists') parent = QtWidgets.QDialog(parent=getMayaMainWindow()) parent.setObjectName('lightingManager') parent.setWindowTitle('Lighting Manager') layout = QtWidgets.QVBoxLayout(parent) # super to LightManager super(LightManager, self).__init__(parent=parent) self.buildUI() self.populate() self.parent().layout().addWidget(self) if not dock: parent.show()
def preview_icons(): '''Show an icon preview dialog''' from Qt import QtWidgets from construct_ui.widgets import IconButton app = QtWidgets.QApplication.instance() standalone = False if not app: standalone = True app = QtWidgets.QApplication([]) init() clipboard = app.clipboard() dialog = QtWidgets.QDialog() layout = QtWidgets.QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) columns = 3 for i, resource_path in enumerate(list('icons')): icon = IconButton(resource_path) label = QtWidgets.QLabel(resource_path) copy = lambda: clipboard.setText(resource_path) icon.clicked.connect(copy, strong=True) col, row = (i % columns) * 2, int(i * (1.0 / float(columns))) layout.addWidget(icon, row, col) layout.addWidget(label, row, col + 1) dialog.setLayout(layout) dialog.setStyleSheet(style(':/styles/dark')) if standalone: dialog.exec_()
def launch_yes_no_dialog(title, message, show_not_again_checkbox=True, parent=None): ''' Launch a dialog box that has "yes" and "no" buttons. Optionally display a checkbox that asks whether to show this dialog box again. return the result of this dialog (True/False) and whether the user checked on the "Don't ask again" checkbox (True/False). ''' dialog = QtWidgets.QDialog(parent=parent) dialog.setWindowTitle(title) dialog.verticalLayout = QtWidgets.QVBoxLayout(dialog) # Create the dialogs main message (Qlabel) dialog.label = QtWidgets.QLabel(dialog) dialog.label.setAlignment(QtCore.Qt.AlignCenter) dialog.label.setTextInteractionFlags(dialog.label.textInteractionFlags() | QtCore.Qt.TextBrowserInteraction) dialog.label.setTextFormat(QtCore.Qt.RichText) dialog.label.setOpenExternalLinks(True) dialog.label.setText(message) dialog.verticalLayout.addWidget(dialog.label) dialog.widget = QtWidgets.QWidget(dialog) dialog.horizontalLayout = QtWidgets.QHBoxLayout(dialog.widget) dialog.horizontalLayout.setContentsMargins(-1, -1, -1, 0) dialog.horizontalLayout.setObjectName("horizontalLayout") dialog.verticalLayout.addWidget(dialog.widget) # Create the "Don\t ask again" checkbox dialog.checkBox = QtWidgets.QCheckBox(dialog.widget) dialog.checkBox.setText("Don\'t ask again") dialog.horizontalLayout.addWidget(dialog.checkBox) # Create the buttonbox with "yes" and "no buttons" dialog.buttonBox = QtWidgets.QDialogButtonBox(dialog.widget) dialog.buttonBox.setOrientation(QtCore.Qt.Horizontal) dialog.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Yes) dialog.horizontalLayout.addWidget(dialog.buttonBox) # Connect the buttonbox signals dialog.buttonBox.accepted.connect(dialog.accept) dialog.buttonBox.rejected.connect(dialog.reject) QtCore.QMetaObject.connectSlotsByName(dialog) # Hide the checkbox if not desired if not show_not_again_checkbox: dialog.checkBox.hide() # Resize the dialog box to scale to its contents dialog.adjustSize() # Launch the dialog yes = dialog.exec_() dont_notify_again = dialog.checkBox.isChecked() return bool(yes), dont_notify_again
def create_ui(self): self.main_dialog = QtWidgets.QDialog() self.main_dialog.setMinimumSize(1000, 400) main_layout = QtWidgets.QVBoxLayout() self.main_dialog.setLayout(main_layout) self.main_dialog.setWindowTitle(self.message) space_left = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) size = QtCore.QSize(256, 256) # We introduce the usage of gifs to grab attention in this UI, via which we expect artists' interactions # to continue to auto fix unpublished work paths when required gifs = glob.glob(os.path.join(self.gif_path, 'choice*.gif')) gif = random.choice(gifs) mov = QtGui.QMovie(gif) mov.setScaledSize(size) self.mov_label.setMovie(mov) mov.start() space_right = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.mov_layout.addItem(space_left) self.mov_layout.addWidget(self.mov_label) self.mov_layout.addItem(space_right) main_layout.addLayout(self.mov_layout) message_font = QtGui.QFont() message_font.setBold(True) self.message_label.setFont(message_font) main_layout.addWidget(self.message_label) self.report_unpublished.setPlainText(self.unpublished) self.report_unpublished.setReadOnly(True) self.report_unpublished.setLineWrapMode(QtWidgets.QTextEdit.NoWrap) main_layout.addWidget(self.report_unpublished) self.progress_note.setFont(message_font) self.progress_note.setStyle(QtWidgets.QStyleFactory.create('Plastique')) main_layout.addWidget(self.progress_note) space = QtWidgets.QLabel() main_layout.addWidget(space) self.success_label.setFont(message_font) main_layout.addWidget(self.success_label) self.success_label.hide() self.report_replaced.setStyle(QtWidgets.QStyleFactory.create('Plastique')) self.report_replaced.setStyleSheet("color: #288f62") main_layout.addWidget(self.report_replaced) self.report_replaced.hide() spacer_1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) spacer_2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) btn_layout = QtWidgets.QHBoxLayout() btn_layout.addItem(spacer_1) btn_layout.addItem(spacer_2) btn_layout.addWidget(self.rewire_nodes_btn) main_layout.addLayout(btn_layout) self.main_dialog.setLayout(main_layout) self.main_dialog.adjustSize()
def __init__(self, parent): self.ui_name = 'Editor' super(EditorUI, self).__init__(parent) self.newWindow = QtWidgets.QDialog(parent=parent) self.Converter = parent.Converter self.build_ui() self.populate_ui()
def __init__(self): parent = QtWidgets.QDialog(parent=getMayaMainWindow()) parent.setObjectName('Building Generator') parent.setWindowTitle('Building Generator') parent.resize(265, 300) parent.show() super(BuildingGenerator, self).__init__(parent=parent) self.buildUI() self.populate()
def unitTest_SpinBox(): app = QtWidgets.QApplication(sys.argv) testDialog = QtWidgets.QDialog() layTest = QtWidgets.QHBoxLayout() layTest.addWidget(MoneySpinner()) testDialog.setLayout(layTest) ex = testDialog StyleUtils.setStyleSheet(ex) ex.show() sys.exit(app.exec_())
def test_load_ui_dialog(): """Tests to see if the baseinstance loading loads a QDialog properly""" import sys from Qt import QtWidgets, QtCompat app = QtWidgets.QApplication(sys.argv) win = QtWidgets.QDialog() QtCompat.loadUi(self.ui_qdialog, win) assert hasattr(win, 'lineEdit'), \ "loadUi could not load instance to main window" app.exit()
def test_load_ui_existingLayoutOnDialog(): """Tests to see if loading a ui onto a layout in a Dialog works""" import sys from Qt import QtWidgets, QtCompat msgs = 'QLayout: Attempting to add QLayout "" to QDialog ' \ '"Dialog", which already has a layout' with ignoreQtMessageHandler([msgs]): app = QtWidgets.QApplication(sys.argv) win = QtWidgets.QDialog() QtWidgets.QComboBox(win) QtWidgets.QHBoxLayout(win) QtCompat.loadUi(self.ui_qdialog, win) app.exit()
def ask(title, question): dlg = QtWidgets.QDialog() dlg.setWindowTitle(title) yes = QtWidgets.QPushButton('Yes') yes.clicked.connect(dlg.accept) no = QtWidgets.QPushButton('No') no.clicked.connect(dlg.reject) lyt = QtWidgets.QGridLayout() lyt.addWidget(QtWidgets.QLabel(question), 0, 0, 1, 2) lyt.addWidget(yes, 1, 0) lyt.addWidget(no, 1, 1) dlg.setLayout(lyt) return dlg.exec_()
def dialog(cls, parent=None, *args, **kwargs): """Create the window as a dialog. Methods of .dialogAccept and .dialogReject will be added. Any variables given to these will be returned. Output: (accepted[bool], data[list]) """ # Create application if it doesn't exist inst = app = QtWidgets.QApplication.instance() if app is None: app = QtWidgets.QApplication(sys.argv) dialog = QtWidgets.QDialog(parent=parent) dialog.setWindowTitle(getattr(cls, 'WindowName', 'New Window')) if inst is None: app.setActiveWindow(dialog) # Inheirt the class to set attributes class windowClass(cls): WindowDockable = False _DialogData = [] # Method of getting data returned from dialog def dialogAccept(self, *args): self._DialogData += args return dialog.accept() def dialogReject(self, *args): self._DialogData += args return dialog.reject() # Setup layout layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) #layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) windowInstance = windowClass(*args, **kwargs) layout.addWidget(windowInstance) dialog.setLayout(layout) # Finish setting up window windowInstance.loadWindowPosition() windowInstance.windowReady.emit() try: return (dialog.exec_(), windowInstance._DialogData) finally: windowInstance.saveWindowPosition() windowClass.clearWindowInstance(windowClass.WindowID)
def __init__(self, dock=False): # So first we check if we want this to be able to dock # <=MAYA2016: If using Maya 2016 and below, we need to create our widget first and then create the dock. # This is the opposite of Maya 2017's behavior. if dock: parent = None else: # Otherwise, lets remove all instances of the dock incase it's already docked deleteDock() # Then if we have a UI called lightingManager, we'll delete it so that we can only have one instance of this # A try except is a very important part of programming when we don't want an error to stop our code # We first try to do something and if we fail, then we do something else. try: pm.deleteUI('lightingManager') except: logger.debug('No previous UI exists') # Then we create a new dialog and give it the main maya window as its parent # we also store it as the parent for our current UI to be put inside parent = QtWidgets.QDialog(parent=getMayaMainWindow()) # We set its name so that we can find and delete it later # <=Maya2016: This also lets us attach the light manager to our dock control parent.setObjectName('lightingManager') # Then we set the title parent.setWindowTitle('Lighting Manager') # Finally we give it a layout dlgLayout = QtWidgets.QVBoxLayout(parent) # Now we are on to our actual widget # We've figured out our parent, so lets send that to the QWidgets initialization method super(LightingManager, self).__init__(parent=parent) # We call our buildUI method to construct our UI self.buildUI() # Now we can tell it to populate with widgets for every light self.populate() # <=Maya2016: For Maya 2016 and below we need to create the dock after we create our widget if dock: getDock() else: # We then add ourself to our parents layout self.parent().layout().addWidget(self) # Finally if we're not docked, then we show our parent parent.show()
def skinDialog(self): qDialog = QtWidgets.QDialog(self) groupBox = QtWidgets.QGroupBox(qDialog) groupBox.setGeometry(QtCore.QRect(5, 5, 250, 131)) label = QtWidgets.QLabel(unicode('原模型:' , 'gbk') , groupBox) label.setGeometry(QtCore.QRect(5, 20, 60, 20)) label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter) self.skilineEdit = QtWidgets.QLineEdit(groupBox) self.skilineEdit.setGeometry(QtCore.QRect(75, 20, 130, 20)) self.skilineEdit.setEnabled(False) self.skilineBout = QtWidgets.QPushButton('GET' , groupBox) self.skilineBout.setGeometry(QtCore.QRect(215, 20, 30, 20)) label_2 = QtWidgets.QLabel(unicode('传递模型:' , 'gbk') , groupBox) label_2.setGeometry(QtCore.QRect(5, 50, 60, 20)) label_2.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter) self.skilineEdit2 = QtWidgets.QLineEdit(groupBox) self.skilineEdit2.setGeometry(QtCore.QRect(75, 50, 131, 20)) self.skilineEdit2.setEnabled(False) self.skilineBout2 = QtWidgets.QPushButton('GET' , groupBox) self.skilineBout2.setGeometry(QtCore.QRect(215, 50, 30, 20)) self.skiButton = QtWidgets.QPushButton('OK' , groupBox) self.skiButton.setGeometry(QtCore.QRect(130, 90, 41, 20)) self.skiButton2 = QtWidgets.QPushButton('Close' , groupBox) self.skiButton2.setGeometry(QtCore.QRect(180, 90, 41, 20)) self.skilineBout.clicked.connect(functools.partial(self.setDialogText , self.skilineEdit)) self.skilineBout2.clicked.connect(functools.partial(self.setSeveralText , self.skilineEdit2)) self.skiButton.clicked.connect(functools.partial(self.oneToNumberSkin , qDialog)) self.skiButton2.clicked.connect(qDialog.reject) qDialog.resize(260,140) qDialog.setMinimumSize(QtCore.QSize(260,140)) qDialog.setMaximumSize(QtCore.QSize(260,140)) qDialog.show()
def creatorDialog(self): qDialog = QtWidgets.QDialog(self) groupBox = QtWidgets.QGroupBox(qDialog) groupBox.setGeometry(QtCore.QRect(5, 5, 250, 131)) label = QtWidgets.QLabel(unicode('匹配的模型:' , 'gbk') , groupBox) label.setGeometry(QtCore.QRect(5, 20, 60, 20)) self.QialoglineEdit = QtWidgets.QLineEdit(groupBox) self.QialoglineEdit.setGeometry(QtCore.QRect(75, 20, 130, 20)) self.QialoglineEdit.setEnabled(False) self.QialoglineBout = QtWidgets.QPushButton('GET' , groupBox) self.QialoglineBout.setGeometry(QtCore.QRect(215, 20, 30, 20)) label_2 = QtWidgets.QLabel(unicode('对应的模型:' , 'gbk') , groupBox) label_2.setGeometry(QtCore.QRect(5, 50, 60, 20)) self.QialoglineEdit2 = QtWidgets.QLineEdit(groupBox) self.QialoglineEdit2.setGeometry(QtCore.QRect(75, 50, 131, 20)) self.QialoglineEdit2.setEnabled(False) self.QialoglineBout2 = QtWidgets.QPushButton('GET' , groupBox) self.QialoglineBout2.setGeometry(QtCore.QRect(215, 50, 30, 20)) self.QialogButton = QtWidgets.QPushButton('OK' , groupBox) self.QialogButton.setGeometry(QtCore.QRect(130, 90, 41, 20)) self.QialogButton2 = QtWidgets.QPushButton('Close' , groupBox) self.QialogButton2.setGeometry(QtCore.QRect(180, 90, 41, 20)) self.QialoglineBout.clicked.connect(functools.partial(self.setDialogText , self.QialoglineEdit)) self.QialoglineBout2.clicked.connect(functools.partial(self.setDialogText , self.QialoglineEdit2)) self.QialogButton.clicked.connect(functools.partial(self.dialogAccept , qDialog)) self.QialogButton2.clicked.connect(qDialog.reject) qDialog.resize(260,140) qDialog.setMinimumSize(QtCore.QSize(260,140)) qDialog.setMaximumSize(QtCore.QSize(260,140)) #qDialog.exec_() qDialog.show()
def wait_message(self, title, message): """ A dialog box will be displayed with the given message and title """ dialog = QtWidgets.QDialog(parent=self.ui) layout = QtWidgets.QHBoxLayout() dialog.label = QtWidgets.QLabel() dialog.label.setText(message) dialog.label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) layout.addWidget(dialog.label) dialog.setLayout(layout) dialog.setWindowTitle(title) dialog.show() # TODO: This stupid for-loop with a print statement is hack to force a redraw/update to the dialog. Otherwise it's blank. Tried a million things. This is the only one that works..most of the time. for i in range(5): print "", QtWidgets.QApplication.processEvents() return dialog
def __init__(self, dock=True): if dock: parent = getDock() else: deleteDock() if cmd.window('lightRigger', query=True, exists=True): cmd.deleteUI('lightRigger') parent = QtWidgets.QDialog(parent=getMayaMainWindow()) parent.setObjectName('lightRigger') parent.setWindowTitle('Light Rigger') layout = QtWidgets.QVBoxLayout(parent) super(LightRigger, self).__init__(parent=parent) self.buildUI() self.populate() self.parent().layout().addWidget(self) if not dock: parent.show()
def wrapper(*args, **kwds): parent = args[ 0] # The first argument will be the wrapped method's class instance (i.e. self), which will be used as the parent dialog = QtWidgets.QDialog(parent=parent) layout = QtWidgets.QHBoxLayout() dialog.label = QtWidgets.QLabel() dialog.label.setText(message) dialog.label.setTextInteractionFlags( QtCore.Qt.TextSelectableByMouse) layout.addWidget(dialog.label) dialog.setLayout(layout) dialog.setWindowTitle(title) dialog.show() # TODO: This stupid for-loop with a print statement is hack to force a redraw/update to the dialog. Otherwise it's blank. # Tried a million things. This is the only one that works..most of the time. for _ in range(5): print "", QtWidgets.QApplication.processEvents() try: return func(*args, **kwds) finally: dialog.done(0)
def __init__(self, dock = False): if dock: parent = getDock() else: deleteDock() try: pm.deleteUI('parkManager') except: print 'No previous UI exists' parent = QtWidgets.QDialog(parent=getMayaMainWindow()) parent.setObjectName('parkManager') parent.setWindowTitle('Park Manager') self.mainLayout = QtWidgets.QVBoxLayout(parent) super(ParkUI, self).__init__(parent = parent) #self.setWindowTitle('Park UI') self.library = treeCreator.Tree() self.parkWidth = 10 self.parkLength = 10 self.bushesDistribution = 0 self.treesDistribution = 0 self.previewTree = None self.minHeight = 4.0 self.maxHeight = 8.0 self.minRadius = 0.5 self.maxRadius = 0.5 self.branches = 4 self.leafColor1 = QtGui.QColor(0,255,0) self.leafColor2 = QtGui.QColor(0,200,0) self.leafColor3 = QtGui.QColor(0,128,0) self.trunkColor = QtGui.QColor(30,8,0) self.buildUI() self.parent().layout().addWidget(self) if not dock: parent.show()
def __init__(self): # check to see if window exists, if not delete it old_window = omui.MQtUtil_findWindow('testUI') if old_window: cmds.deleteUI('testUI') # Then we create a new dialog and give it the main maya window as its parent # we also store it as the parent for our current UI to be put inside parent = QtWidgets.QDialog(parent=getMayaMainWindow()) # We set its name so that we can find and delete it later parent.setObjectName('testUI') # Then we set the title parent.setWindowTitle('Test UI') # look up pyqt documentation to see what QWidget's init method takes super(MainUI, self).__init__(parent=parent) dlgLayout = QtWidgets.QVBoxLayout(parent) # We call our buildUI method to construct our UI self.buildUI() self.parent().layout().addWidget(self) parent.show()
def show_header(): def null(): print('Action') app = QtWidgets.QApplication(sys.argv) resources.init() dialog = QtWidgets.QDialog() apply_style(dialog, ':/styles/dark') header = widgets.Header('Hello World!') header.add_menu_item('Item 1', null) header.add_menu_item('Item 2', null) header.add_menu_item('Item 3', null) header.add_menu_item('Item 4', null) layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(header) layout.setAlignment(QtCore.Qt.AlignTop) dialog.setLayout(layout) sys.exit(dialog.exec_())
def connect(self): self.updateWindow=QtWidgets.QDialog() self.ui_update=Ui_Dialog() self.ui_update.setupUi(self.updateWindow) self.updateWindow.show()
def launch_yes_no_cancel_dialog(title, message, show_not_again_checkbox=True, parent=None): ''' Launch a dialog box that has "yes", "no" and "cancel" buttons. Optionally display a checkbox that asks whether to show this dialog box again. This is different from the Yes/No style of dialog since it offers three choices. As a consequence, the return code needs to return one of three statuses. return the result of this dialog (0/1/2) for 'Yes'/'No'/'Cancel' respectively, and whether the user checked the "Don't ask again" checkbox (True/False). ''' dialog = QtWidgets.QDialog(parent=parent) dialog.setWindowTitle(title) dialog.verticalLayout = QtWidgets.QVBoxLayout(dialog) # Create the dialogs main message (Qlabel) dialog.label = QtWidgets.QLabel(dialog) dialog.label.setAlignment(QtCore.Qt.AlignCenter) dialog.label.setTextInteractionFlags(dialog.label.textInteractionFlags() | QtCore.Qt.TextBrowserInteraction) dialog.label.setTextFormat(QtCore.Qt.RichText) dialog.label.setText(message) dialog.verticalLayout.addWidget(dialog.label) dialog.widget = QtWidgets.QWidget(dialog) dialog.horizontalLayout = QtWidgets.QHBoxLayout(dialog.widget) dialog.horizontalLayout.setContentsMargins(-1, -1, -1, 0) dialog.verticalLayout.addWidget(dialog.widget) # Create the "Don't ask again" checkbox dialog.checkBox = QtWidgets.QCheckBox(dialog.widget) dialog.checkBox.setText("Don't ask again") dialog.horizontalLayout.addWidget(dialog.checkBox) # Create the buttonbox dialog.buttonBox = QtWidgets.QDialogButtonBox(dialog.widget) dialog.buttonBox.setOrientation(QtCore.Qt.Horizontal) # Create the "Yes", "No" and "Cancel" options dialog.yesButton = QtWidgets.QPushButton('Yes', dialog.widget) dialog.noButton = QtWidgets.QPushButton('No', dialog.widget) dialog.cancelButton = QtWidgets.QPushButton('Cancel', dialog.widget) # Link the buttons to their respective return values dialog.yesButton.clicked.connect(lambda: dialog.done(1)) dialog.noButton.clicked.connect(lambda: dialog.done(2)) dialog.cancelButton.clicked.connect(lambda: dialog.done(0)) # Add the buttons to the UI dialog.buttonBox.addButton(dialog.yesButton, QtWidgets.QDialogButtonBox.ActionRole) dialog.buttonBox.addButton(dialog.noButton, QtWidgets.QDialogButtonBox.ActionRole) dialog.buttonBox.addButton(dialog.cancelButton, QtWidgets.QDialogButtonBox.ActionRole) dialog.horizontalLayout.addWidget(dialog.buttonBox) # Connect the buttonbox signals QtCore.QMetaObject.connectSlotsByName(dialog) # Hide the checkbox if not desired if not show_not_again_checkbox: dialog.checkBox.hide() # Resize the dialog box to scale to its contents dialog.adjustSize() # Launch the dialog yes = dialog.exec_() dont_notify_again = dialog.checkBox.isChecked() return yes, dont_notify_again
self.horizontalLayout.addItem(spacerItem) self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setMaximumSize(QtCore.QSize(30, 16777215)) self.pushButton.setObjectName("pushButton") self.horizontalLayout.addWidget(self.pushButton) self.verticalLayout.addLayout(self.horizontalLayout) self.listWidget = QtWidgets.QListWidget(Form) self.listWidget.setObjectName("listWidget") self.verticalLayout.addWidget(self.listWidget) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): Form.setWindowTitle(QtCompat.translate("Form", "Form", None, -1)) self.pushButton.setText(QtCompat.translate("Form", "+", None, -1)) if __name__ == '__main__': from Qt.QtWidgets import QApplication, QStyleFactory import sys app = QApplication(sys.argv) app.setStyle(QStyleFactory.create("plastique")) wm = QtWidgets.QDialog() w = Ui_Form() w.setupUi(wm) wm.show() sys.exit(app.exec_())
def show_history(self): # Show history popup if not self._history: return widget = QtWidgets.QListWidget() widget.setSelectionMode(widget.NoSelection) widget.setStyleSheet(""" * { font-family: "Courier New"; } """) largest_label_num_chars = 0 largest_action_label = max(len(x[0].label) for x in self._history) action_session_role = QtCore.Qt.UserRole + 1 for action, session in reversed(self._history): project = session.get("AVALON_PROJECT") asset = session.get("AVALON_ASSET") task = session.get("AVALON_TASK") breadcrumb = " > ".join(x for x in [project, asset, task] if x) m = "{{action:{0}}} | {{breadcrumb}}".format(largest_action_label) label = m.format(action=action.label, breadcrumb=breadcrumb) icon = lib.get_action_icon(action) item = QtWidgets.QListWidgetItem(icon, label) item.setData(action_session_role, (action, session)) largest_label_num_chars = max(largest_label_num_chars, len(label)) widget.addItem(item) # Show history dialog = QtWidgets.QDialog(parent=self) dialog.setWindowTitle("Action History") dialog.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Popup) dialog.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) layout = QtWidgets.QVBoxLayout(dialog) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(widget) def on_clicked(index): data = index.data(action_session_role) self.trigger_history.emit(data) dialog.close() widget.clicked.connect(on_clicked) # padding + icon + text width = 40 + (largest_label_num_chars * 7) entry_height = 21 height = entry_height * len(self._history) point = QtGui.QCursor().pos() dialog.setGeometry(point.x() - width, point.y() - height, width, height) dialog.exec_() self.widget_popup = widget
def get_input(title, data, options=FormOptions()): """ Get input from user If the user accepts the dialog then the current values will be written back to the data object. Note that for list queries this will change the value type! Args: title (str): Dialog title data (dict | OrderedDict): Input data to build tha dialog for options(FormOptions): Options to control dialog behavior Returns: bool: Returns True if dialog is accepted, False otherwise """ dialog = QtWidgets.QDialog() dialog.setWindowTitle(title) layout = QtWidgets.QGridLayout(dialog) layout.setContentsMargins(2, 2, 2, 2) layout.setSpacing(4) widgets = {} for row, key in enumerate(data): label = QtWidgets.QLabel(key + ':') layout.addWidget(label) value = data[key] if isinstance(value, bool): widget = QtWidgets.QCheckBox() widget.setChecked(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, QtGui.QColor): widget = ColorSwatchButton() widget.set_color(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, float): widget = QtWidgets.QDoubleSpinBox() widget.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) widget.setMaximum(options.numeric_max) widget.setMinimum(options.numeric_min) widget.setDecimals(options.numeric_precision) widget.setValue(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, int): widget = QtWidgets.QSpinBox() widget.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) widget.setMaximum(options.numeric_max) widget.setMinimum(options.numeric_min) widget.setValue(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, str): widget = QtWidgets.QLineEdit(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, list): if options.list_displays_as_radios: widget = QtWidgets.QWidget() widget_layout = QtWidgets.QHBoxLayout(widget) widget_layout.setContentsMargins(2, 2, 2, 2) widget_layout.setSpacing(2) is_checked = False for item in value: button = QtWidgets.QRadioButton(item) widget_layout.addWidget(button) if not is_checked: button.setChecked(True) is_checked = True layout.addWidget(widget, row, 1) widgets[key] = widget else: widget = QtWidgets.QComboBox() widget.addItems(value) layout.addWidget(widget, row, 1) widgets[key] = widget elif isinstance(value, QtGui.QVector2D) or isinstance( value, QtGui.QVector3D): widget = QtWidgets.QWidget() widget_layout = QtWidgets.QHBoxLayout(widget) widget_layout.setContentsMargins(2, 2, 2, 2) widget_layout.setSpacing(2) x_widget = QtWidgets.QDoubleSpinBox() x_widget.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) x_widget.setMaximum(options.numeric_max) x_widget.setMinimum(options.numeric_min) x_widget.setDecimals(options.numeric_precision) x_widget.setValue(value.x()) y_widget = QtWidgets.QDoubleSpinBox() y_widget.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) y_widget.setMaximum(options.numeric_max) y_widget.setMinimum(options.numeric_min) y_widget.setDecimals(options.numeric_precision) y_widget.setValue(value.y()) widget_layout.addWidget(x_widget) widget_layout.addWidget(y_widget) if isinstance(value, QtGui.QVector3D): z_widget = QtWidgets.QDoubleSpinBox() z_widget.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) z_widget.setMaximum(options.numeric_max) z_widget.setMinimum(options.numeric_min) z_widget.setDecimals(options.numeric_precision) z_widget.setValue(value.y()) widget_layout.addWidget(z_widget) layout.addWidget(widget, row, 1) widgets[key] = widget else: raise ValueError( 'Data of type "{}" is not supported!'.format(value_type)) button_layout = QtWidgets.QHBoxLayout() button_layout.setContentsMargins(2, 2, 2, 2) button_layout.setSpacing(2) layout.addLayout(button_layout, len(data) + 1, 0, 1, 2) ok_button = QtWidgets.QPushButton('Ok') ok_button.setDefault(True) ok_button.clicked.connect(dialog.accept) button_layout.addWidget(ok_button) cancel_button = QtWidgets.QPushButton('Cancel') cancel_button.clicked.connect(dialog.reject) button_layout.addWidget(cancel_button) if dialog.exec_() != QtWidgets.QDialog.Accepted: dialog.deleteLater() return False for key in data: value = data[key] if isinstance(value, bool): data[key] = widgets[key].isChecked() elif isinstance(value, QtGui.QColor): data[key] = widgets[key].color() elif isinstance(value, float) or isinstance(value, int): data[key] = widgets[key].value() elif isinstance(value, str): data[key] = widgets[key].text() elif isinstance(value, list): if options.list_displays_as_radios: children = widgets[key].children() for index, child in enumerate(children): if not isinstance(child, QtWidgets.QRadioButton): continue if child.isChecked(): if options.list_returns_index: data[key] = index else: data[key] = child.text() else: if options.list_returns_index: data[key] = widgets[key].currentIndex() else: data[key] = widgets[key].currentText() elif isinstance(value, QtGui.QVector2D): children = widgets[key].children() data[key] = QtGui.QVector2D(children[1].value(), children[2].value()) elif isinstance(value, QtGui.QVector3D): children = widgets[key].children() data[key] = QtGui.QVector3D(children[1].value(), children[2].value(), children[3].value()) dialog.deleteLater() return True
def __init__(self): super(Login_Dialog_ui, self).__init__() self.Dialog = QtWidgets.QDialog() self.Dialog.setStyleSheet(style.load_stylesheet()) self.Dialog.setObjectName("Dialog") self.Dialog.resize(SIZE_W, SIZE_H) self.Dialog.setMinimumSize(QtCore.QSize(SIZE_W, SIZE_H)) self.verticalLayoutWidget = QtWidgets.QWidget(self.Dialog) self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, SIZE_W + 1, SIZE_H + 1)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setContentsMargins(10, 5, 10, 5) self.verticalLayout.setObjectName("verticalLayout") self.user_label = QtWidgets.QLabel(self.verticalLayoutWidget) sizePolicy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.user_label.sizePolicy().hasHeightForWidth()) self.user_label.setSizePolicy(sizePolicy) self.user_label.setMinimumSize(QtCore.QSize(150, 28)) font = QtGui.QFont() font.setFamily("DejaVu Sans Condensed") font.setPointSize(9) font.setBold(True) font.setWeight(50) font.setKerning(True) self.user_label.setFont(font) self.user_label.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor)) self.user_label.setTextFormat(QtCore.Qt.RichText) self.user_label.setObjectName("user_label") self.verticalLayout.addWidget(self.user_label) self.user_input = QtWidgets.QLineEdit(self.verticalLayoutWidget) self.user_input.setEnabled(True) self.user_input.setFrame(True) self.user_input.setObjectName("user_input") self.verticalLayout.addWidget(self.user_input) self.passw_label = QtWidgets.QLabel(self.verticalLayoutWidget) sizePolicy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.passw_label.sizePolicy().hasHeightForWidth()) self.passw_label.setSizePolicy(sizePolicy) self.passw_label.setMinimumSize(QtCore.QSize(150, 28)) font = QtGui.QFont() font.setFamily("DejaVu Sans Condensed") font.setPointSize(9) font.setBold(True) font.setWeight(50) font.setKerning(True) self.passw_label.setFont(font) self.passw_label.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor)) self.passw_label.setTextFormat(QtCore.Qt.RichText) self.passw_label.setObjectName("passw_label") self.verticalLayout.addWidget(self.passw_label) self.passw_input = QtWidgets.QLineEdit(self.verticalLayoutWidget) self.passw_input.setEnabled(True) self.passw_input.setInputMethodHints( QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText | QtCore.Qt.ImhSensitiveData) self.passw_input.setInputMask("") self.passw_input.setText("") self.passw_input.setFrame(True) self.passw_input.setEchoMode(QtWidgets.QLineEdit.Password) self.passw_input.setReadOnly(False) self.passw_input.setObjectName("passw_input") self.verticalLayout.addWidget(self.passw_input) spacerItem = QtWidgets.QSpacerItem( 20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem) self.buttonBox = QtWidgets.QDialogButtonBox(self.verticalLayoutWidget) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) self.retranslateUi(self.Dialog) self.buttonBox.accepted.connect(self.execute) self.buttonBox.rejected.connect(self.Dialog.reject) QtCore.QMetaObject.connectSlotsByName(self.Dialog) self.Dialog.setTabOrder(self.user_input, self.passw_input)