示例#1
0
 def setupUi(self, editPrefSkel):
     editPrefSkel.setObjectName(_fromUtf8('editPrefSkel'))
     editPrefSkel.resize(668, 530)
     # Add Pane for TreeView
     self.verticalLayout = QtWidgets.QVBoxLayout(editPrefSkel)
     self.verticalLayout.setObjectName(_fromUtf8('verticalLayout'))
     # The TreeView for QtCore.QAbstractItemModel to attach to
     self.prefTreeView = QtWidgets.QTreeView(editPrefSkel)
     self.prefTreeView.setObjectName(_fromUtf8('prefTreeView'))
     self.verticalLayout.addWidget(self.prefTreeView)
     # Add Pane for buttons
     self.horizontalLayout = QtWidgets.QHBoxLayout()
     self.horizontalLayout.setObjectName(_fromUtf8('horizontalLayout'))
     #
     # self.redrawBUT = QtWidgets.QPushButton(editPrefSkel)
     # self.redrawBUT.setObjectName(_fromUtf8('redrawBUT'))
     # self.horizontalLayout.addWidget(self.redrawBUT)
     ##
     # self.unloadFeaturesAndModelsBUT = QtWidgets.QPushButton(editPrefSkel)
     # self.unloadFeaturesAndModelsBUT.setObjectName(_fromUtf8('unloadFeaturesAndModelsBUT'))
     # self.horizontalLayout.addWidget(self.unloadFeaturesAndModelsBUT)
     #
     self.defaultPrefsBUT = QtWidgets.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,
             QtWidgets.QPushButton(
                 index.data().toString(),
                 self.parent(),
                 clicked=self.parent().cellButtonClicked,
             ),
         )
示例#3
0
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 wbia.guitool.guitool_dialogs --test-user_option

    Example:
        >>> # GUI_DOCTEST
        >>> # xdoctest: +REQUIRES(--gui)
        >>> from wbia.guitool.guitool_dialogs import *  # NOQA
        >>> import wbia.guitool as gt
        >>> gt.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)
        >>> # xdoctest: +REQUIRES(--show)
        >>> ut.quit_if_noshow()
        >>> #gt.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(QtWidgets.QMessageBox.Close)
    options = list(options)[::-1]
    for opt in options:
        role = QtWidgets.QMessageBox.ApplyRole
        msgbox.addButton(QtWidgets.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 == QtWidgets.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