def setupUi(self, editPrefSkel): editPrefSkel.setObjectName(_fromUtf8('editPrefSkel')) editPrefSkel.resize(668, 530) # Add Pane for TreeView self.verticalLayout = QtGui.QVBoxLayout(editPrefSkel) self.verticalLayout.setObjectName(_fromUtf8('verticalLayout')) # The TreeView for QAbstractItemModel to attach to self.prefTreeView = QtGui.QTreeView(editPrefSkel) self.prefTreeView.setObjectName(_fromUtf8('prefTreeView')) self.verticalLayout.addWidget(self.prefTreeView) # Add Pane for buttons self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8('horizontalLayout')) # #self.redrawBUT = QtGui.QPushButton(editPrefSkel) #self.redrawBUT.setObjectName(_fromUtf8('redrawBUT')) #self.horizontalLayout.addWidget(self.redrawBUT) ## #self.unloadFeaturesAndModelsBUT = QtGui.QPushButton(editPrefSkel) #self.unloadFeaturesAndModelsBUT.setObjectName(_fromUtf8('unloadFeaturesAndModelsBUT')) #self.horizontalLayout.addWidget(self.unloadFeaturesAndModelsBUT) # self.defaultPrefsBUT = QtGui.QPushButton(editPrefSkel) self.defaultPrefsBUT.setObjectName(_fromUtf8('defaultPrefsBUT')) self.horizontalLayout.addWidget(self.defaultPrefsBUT) # Buttons are a child of the View self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(editPrefSkel) QtCore.QMetaObject.connectSlotsByName(editPrefSkel)
def paint(self, painter, option, index): # This method will be called every time a particular cell is # in view and that view is changed in some way. We ask the # delegates parent (in this case a table view) if the index # in question (the table cell) already has a widget associated # with it. If not, create one with the text for this index and # connect its clicked signal to a slot in the parent view so # we are notified when its used and can do something. if not self.parent().indexWidget(index): self.parent().setIndexWidget( index, QtGui.QPushButton(index.data().toString(), self.parent(), clicked=self.parent().cellButtonClicked))
def user_option(parent=None, msg='msg', title='user_option', options=['Yes', 'No'], use_cache=False, default=None, detailed_msg=None): """ Prompts user with several options with ability to save decision Args: parent (None): msg (str): title (str): options (list): use_cache (bool): default (str): default option Returns: str: reply CommandLine: python -m guitool.guitool_dialogs --test-user_option Example: >>> # GUI_DOCTEST >>> from guitool.guitool_dialogs import * # NOQA >>> import guitool >>> guitool.ensure_qtapp() >>> parent = None >>> msg = 'msg' >>> title = 'user_option' >>> options = ['Yes', 'No'] >>> use_cache = False >>> default = 'Yes' >>> # execute function >>> detailed_msg = 'hi' >>> reply = user_option(parent, msg, title, options, use_cache, default, detailed_msg) >>> result = str(reply) >>> print(result) >>> ut.quit_if_noshow() >>> #guitool.guitool_main.qtapp_loop() """ if ut.VERBOSE: print('[gt] user_option:\n %r: %s' % (title, msg)) # Recall decision cache_id = title + msg if use_cache: reply = _guitool_cache_read(cache_id, default=None) if reply is not None: return reply # Create message box msgbox = _newMsgBox(msg, title, parent, resizable=detailed_msg is not None) # _addOptions(msgbox, options) # def _addOptions(msgbox, options): #msgbox.addButton(QtGui.QMessageBox.Close) options = list(options)[::-1] for opt in options: role = QtGui.QMessageBox.ApplyRole msgbox.addButton(QtGui.QPushButton(opt), role) # Set default button if default is not None: assert default in options, ('default=%r is not in options=%r' % (default, options)) for qbutton in msgbox.buttons(): if default == qbutton.text(): msgbox.setDefaultButton(qbutton) if use_cache: # Add a remember me option if caching is on dontPrompt = _cacheReply(msgbox) if detailed_msg is not None: msgbox.setDetailedText(detailed_msg) # Wait for output optx = msgbox.exec_() if optx == QtGui.QMessageBox.Cancel: # User Canceled return None try: # User Selected an option reply = options[optx] except KeyError as ex: # This should be unreachable code. print('[gt] USER OPTION EXCEPTION !') print('[gt] optx = %r' % optx) print('[gt] options = %r' % options) print('[gt] ex = %r' % ex) raise # Remember decision if caching is on if use_cache and dontPrompt.isChecked(): _guitool_cache_write(cache_id, reply) # Close the message box del msgbox return reply