当前位置: 首页>>代码示例>>Python>>正文


Python QButtonGroup.checkedButton方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QButtonGroup.checkedButton方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.checkedButton方法的具体用法?Python QButtonGroup.checkedButton怎么用?Python QButtonGroup.checkedButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QButtonGroup的用法示例。


在下文中一共展示了QButtonGroup.checkedButton方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ChooseBlogDialog

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]
class ChooseBlogDialog(QDialog, Ui_ChooseBlogDialog):
    def __init__(self, available_blogs, addToDB):
        QDialog.__init__(self)
        Ui_ChooseBlogDialog.__init__(self)
        self.func = addToDB
        self.setupUi(self)
        radioboxLayout = QVBoxLayout()
        self.radiobuttonGroup = QButtonGroup()
        self.radios = []
        for blog in available_blogs:
            radio = BlogRadio("Blog Title: %s,   Url: %s" %(blog.blogname, blog.homeurl), blog)
            self.radiobuttonGroup.addButton(radio)
            radioboxLayout.addWidget(radio)
            self.radios.append(radio)
        self.chooseBlogFrame.setLayout(radioboxLayout)
        self.adjustSize()
        connect(self.chooseBlogButtonBox, SIGNAL("accepted()"), self.addBlog) #AddBlogDialog.accept)
        connect(self.chooseBlogButtonBox, SIGNAL("rejected()"), self.reject)#AddBlogDialog.reject)

    def addBlog(self):
        if self.radiobuttonGroup.checkedButton():
            self.func(self.radiobuttonGroup.checkedButton().blog)
            self.accept()
        else:
            QMessageBox.warning(self, "Choose A Blog", "Please choose a blog and click OK.  If you do not want to add a blog, Please click 'Cancel'", QMessageBox.Ok, QMessageBox.Ok)
        pass
开发者ID:sharmi,项目名称:rubrique,代码行数:28,代码来源:chooseblogdialog.py

示例2: AutoFieldsDockWidget

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]

#.........这里部分代码省略.........
            self.frameFields.setEnabled( True )
            self.frameExpression.setEnabled( True )

        # List common fields in cboField and get geometries selected
        geometryTypeSet = self.updateFieldList()


        # Update expression controls
        if 0 in geometryTypeSet and len( geometryTypeSet ) == 1: # Points
            self.optXCoord.setEnabled( True )
            self.optYCoord.setEnabled( True )
            self.optLength.setEnabled( False )
            self.optPerimeter.setEnabled( False )
            self.optArea.setEnabled( False )
        elif 1 in geometryTypeSet and len( geometryTypeSet ) == 1: # Lines
            self.optXCoord.setEnabled( False )
            self.optYCoord.setEnabled( False )
            self.optLength.setEnabled( True )
            self.optPerimeter.setEnabled( False )
            self.optArea.setEnabled( False )
        elif 2 in geometryTypeSet and len( geometryTypeSet ) == 1: # Polygons
            self.optXCoord.setEnabled( False )
            self.optYCoord.setEnabled( False )
            self.optLength.setEnabled( False )
            self.optPerimeter.setEnabled( True )
            self.optArea.setEnabled( True )
        else:
            self.optXCoord.setEnabled( False )
            self.optYCoord.setEnabled( False )
            self.optLength.setEnabled( False )
            self.optPerimeter.setEnabled( False )
            self.optArea.setEnabled( False )

        if not self.btnGroup.checkedButton().isEnabled():
            self.optCustomExpression.setChecked( True ) # Default selection
            self.updateExpressionControls( self.optCustomExpression )

        self.expressionDlg = None # Initialize the dialog


    def updateFieldList( self ):
        """ Update field list and return geometries selected """
        commonFields = []
        geometryTypeSet = set()
        bFirstFlag = True
        for item in self.tblLayers.selectedItems():
            if item.column() == 1: # It's the layer name item
                self.msg.show( "ID " + item.data( Qt.UserRole ), 'info', True ) # Get layer id
                layer = QgsMapLayerRegistry.instance().mapLayer( item.data( Qt.UserRole ) )
                geometryTypeSet.add( layer.geometryType() )
                tmpFields = [field.name() for field in layer.dataProvider().fields()] # Get field names stored in the provider
                if bFirstFlag: # Initialize commonFields
                    commonFields = tmpFields
                    bFirstFlag = False
                else: # Intersect fields
                    if commonFields: # Avoid intersecting if no common fields
                        commonFields = list( set( commonFields ) & set( tmpFields ) )

        commonFields.sort()
        self.msg.show( "FIELDS: "+ str(commonFields), 'info', True)

        self.cboField.clear()
        if not commonFields:
            self.optExistingField.setEnabled( False )
            self.optNewField.setChecked( True )
        else:
开发者ID:gacarrillor,项目名称:AutoFields,代码行数:70,代码来源:AutoFieldsDockWidget.py

示例3: DefaultSelectParameterWidget

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]

#.........这里部分代码省略.........

    def get_parameter(self):
        """Obtain list parameter object from the current widget state.

        :returns: A DefaultSelectParameter from the current state of widget.
        """
        current_index = self.input.currentIndex()
        selected_value = self.input.itemData(current_index, Qt.UserRole)
        if hasattr(selected_value, 'toPyObject'):
            selected_value = selected_value.toPyObject()

        try:
            self._parameter.value = selected_value
        except ValueError:
            err = self.raise_invalid_type_exception()
            raise err

        radio_button_checked_id = self.default_input_button_group.checkedId()
        # No radio button checked, then default value = None
        if radio_button_checked_id == -1:
            self._parameter.default = None
        # The last radio button (custom) is checked, get the value from the
        # line edit
        elif (radio_button_checked_id ==
                len(self._parameter.default_values) - 1):
            self._parameter.default_values[radio_button_checked_id] \
                = self.custom_value.value()
            self._parameter.default = self.custom_value.value()
        else:
            self._parameter.default = self._parameter.default_values[
                radio_button_checked_id]

        return self._parameter

    def set_default(self, default):
        """Set default value by item's string.

        :param default: The default.
        :type default: str, int

        :returns: True if success, else False.
        :rtype: bool
        """
        # Find index of choice
        try:
            default_index = self._parameter.default_values.index(default)
            self.default_input_button_group.button(default_index).setChecked(
                True)
        except ValueError:
            last_index = len(self._parameter.default_values) - 1
            self.default_input_button_group.button(last_index).setChecked(
                True)
            self.custom_value.setValue(default)

        self.toggle_custom_value()

    def toggle_custom_value(self):
        radio_button_checked_id = self.default_input_button_group.checkedId()
        if (radio_button_checked_id ==
                len(self._parameter.default_values) - 1):
            self.custom_value.setDisabled(False)
        else:
            self.custom_value.setDisabled(True)

    def toggle_input(self):
        """Change behaviour of radio button based on input."""
        current_index = self.input.currentIndex()
        # If current input is not a radio button enabler, disable radio button.
        if self.input.itemData(current_index, Qt.UserRole) != (
                self.radio_button_enabler):
            self.disable_radio_button()
        # Otherwise, enable radio button.
        else:
            self.enable_radio_button()

    def set_selected_radio_button(self):
        """Set selected radio button to 'Do not report'."""
        dont_use_button = self.default_input_button_group.button(
            len(self._parameter.default_values) - 2)
        dont_use_button.setChecked(True)

    def disable_radio_button(self):
        """Disable radio button group and custom value input area."""
        checked = self.default_input_button_group.checkedButton()
        if checked:
            self.default_input_button_group.setExclusive(False)
            checked.setChecked(False)
            self.default_input_button_group.setExclusive(True)
        for button in self.default_input_button_group.buttons():
            button.setDisabled(True)
        self.custom_value.setDisabled(True)

    def enable_radio_button(self):
        """Enable radio button and custom value input area then set selected
        radio button to 'Do not report'.
        """
        for button in self.default_input_button_group.buttons():
            button.setEnabled(True)
        self.set_selected_radio_button()
        self.custom_value.setEnabled(True)
开发者ID:timlinux,项目名称:inasafe,代码行数:104,代码来源:default_select_parameter_widget.py

示例4: OptionWidget

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]

#.........这里部分代码省略.........
                    else:
                        icon = QIcon(path)
                except:
                    icon = QIcon()

                button.setCheckable(True)
                button.setText(desc)
                button.setProperty("value", data)
                button.setIcon(icon)
                button.setIconSize(QSize(24, 24))
                if isinstance(self.widget.layout(), QBoxLayout):
                    self.widget.layout().addWidget(button)
                else:
                    self.widget.layout().addWidget(button, rowcount, column)
                self.group.addButton(button)

    def initWidget(self, widget, config):
        if not widget.layout():
            widget.setLayout(QGridLayout())
            widget.layout().setContentsMargins(0, 0, 0, 0)

    def updatefromconfig(self):
        super(OptionWidget, self).updatefromconfig()

        for button in self.group.buttons():
            self.group.removeButton(button)
            self.widget.layout().removeWidget(button)
            button.deleteLater()
            button.setParent(None)

        listconfig = self.config['list']
        multiselect = self.config.get('multi', False)
        self._buildfromlist(listconfig, multiselect)

        super(OptionWidget, self).endupdatefromconfig()

    def validate(self, *args):
        button = self.group.checkedButton()
        if button:
            return True

        return False

    @property
    def buttons(self):
        return self.group.buttons()

    @property
    def nullvalues(self):
        return ['NULL']

    @property
    def multioption(self):
        return self.config.get('multi', False)

    def setvalue(self, value):
        def set_button(setvalue):
            for button in self.group.buttons():
                buttonvalue = button.property("value")
                if (setvalue is None and buttonvalue in self.nullvalues) or buttonvalue == str(setvalue):
                    button.setChecked(True)
                    self.emitvaluechanged()
                    return

        if value in self.nullvalues:
            value = None

        if self.multioption and value:
            values = value.split(';')
        else:
            values = [value]

        for value in values:
            set_button(value)

    def value(self):
        def _returnvalue():
            if self.multioption:
                _values = []
                checked = [button for button in self.group.buttons() if button.isChecked()]
                for button in checked:
                    value = button.property("value")
                    _values.append(value)
                if not _values:
                    return None
                return ";".join(_values)
            else:
                checked = self.group.checkedButton()
                if not checked:
                    return None

                value = checked.property("value")
                return value

        returnvalue = _returnvalue()

        if returnvalue in self.nullvalues:
            returnvalue = None

        return returnvalue
开发者ID:skeenp,项目名称:Roam,代码行数:104,代码来源:optionwidget.py

示例5: OptionWidget

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]
class OptionWidget(EditorWidget):
    widgettype = 'Option Row'

    def __init__(self, *args):
        super(OptionWidget, self).__init__(*args)
        self._bindvalue = None
        self.group = QButtonGroup()
        self.group.setExclusive(True)
        self.group.buttonClicked.connect(self.emitvaluechanged)

    def createWidget(self, parent):
        widget = QWidget(parent)
        return widget

    def _buildfromlist(self, listconfig):
        items = listconfig['items']
        for item in items:
            parts = item.split(';')
            data = parts[0]
            try:
                desc = parts[1]
            except IndexError:
                desc = data

            button = QPushButton()

            icon = QIcon()
            try:
                path = parts[2]
                if path.startswith("#"):
                    # Colour the button with the hex value
                    style = """
                        QPushButton:checked  {{
                            border: 3px solid rgb(137, 175, 255);
                        background-color: {colour};
                        }}""".format(colour=path)
                    button.setStyleSheet(style)
                elif path.endswith("_icon"):
                    icon = QIcon(":/icons/{}".format(path))
                else:
                    icon = QIcon(path)
            except:
                icon = QIcon()

            button.setCheckable(True)
            button.setText(desc)
            button.setProperty("value", data)
            button.setIcon(icon)
            button.setIconSize(QSize(24, 24))
            self.widget.layout().addWidget(button)
            self.group.addButton(button)

    def initWidget(self, widget):
        if not widget.layout():
            widget.setLayout(QHBoxLayout())
            widget.layout().setContentsMargins(0, 0, 0, 0)

    def updatefromconfig(self):
        super(OptionWidget, self).updatefromconfig()

        for button in self.group.buttons():
            self.group.removeButton(button)
            self.widget.layout().removeWidget(button)
            button.deleteLater()
            button.setParent(None)

        listconfig = self.config['list']
        self._buildfromlist(listconfig)

        super(OptionWidget, self).endupdatefromconfig()

    def validate(self, *args):
        button = self.group.checkedButton()
        if button:
            return True

        return False

    @property
    def nullvalues(self):
        return ['NULL']

    def setvalue(self, value):
        if value in self.nullvalues:
            value = None

        for button in self.group.buttons():
            buttonvalue = button.property("value")
            if (value is None and buttonvalue in self.nullvalues) or buttonvalue == str(value):
                button.setChecked(True)
                self.emitvaluechanged()
                return

    def value(self):
        button = self.group.checkedButton()
        if not button:
            return None

        value = button.property("value")

#.........这里部分代码省略.........
开发者ID:HeatherHillers,项目名称:Roam,代码行数:103,代码来源:optionwidget.py

示例6: OptionWidget

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]
class OptionWidget(EditorWidget):
    widgettype = 'Option Row'
    def __init__(self, *args):
        super(OptionWidget, self).__init__(*args)
        self._bindvalue = None
        self.group = QButtonGroup()
        self.group.setExclusive(True)
        self.group.buttonClicked.connect(self.emitvaluechanged)

    def createWidget(self, parent):
        widget = QWidget(parent)
        widget.setLayout(QHBoxLayout())
        widget.layout().setContentsMargins(0,0,0,0)
        return widget

    def _buildfromlist(self, listconfig):
        items = listconfig['items']
        for item in items:
            parts = item.split(';')
            data = parts[0]
            try:
                desc = parts[1]
            except IndexError:
                desc = data

            try:
                path = parts[2]
                if path.endswith("_icon"):
                    icon = QIcon(":/icons/{}".format(path))
                else:
                    icon = QIcon(path)
            except:
                icon = QIcon()


            button = QPushButton()
            button.setCheckable(True)
            button.setText(desc)
            button.setProperty("value", data)
            button.setIcon(icon)
            button.setIconSize(QSize(24,24))
            self.widget.layout().addWidget(button)
            self.group.addButton(button)

    def initWidget(self, widget):
        pass

    def updatefromconfig(self):
        super(OptionWidget, self).updatefromconfig()
        listconfig = self.config['list']
        self._buildfromlist(listconfig)

        super(OptionWidget, self).endupdatefromconfig()

    def validate(self, *args):
        button = self.group.checkedButton()
        if button:
            self.raisevalidationupdate(True)
        else:
            self.raisevalidationupdate(False)
        self.emitvaluechanged()

    def setvalue(self, value):
        for button in self.group.buttons():
            if button.property("value") == value:
                button.setChecked(True)
                return

    def value(self):
        button = self.group.checkedButton()
        if not button:
            return None
        return button.property("value")
开发者ID:henriquespedro,项目名称:Roam,代码行数:75,代码来源:optionwidget.py

示例7: EthernetEditor

# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import checkedButton [as 别名]
class EthernetEditor(QFrame):
    def __init__(self, ethernet, parent=None):
        QFrame.__init__(self, parent)

        self.ethernet = ethernet

        self.buildGUI()
        self.fillValues()

    def buildGUI(self):
        #general setup
        form = QFormLayout(self)

        self.label = OptionnalLine(hint="Optional interface name")
        form.addRow(self.tr("Interface name"), self.label)

        self.speed_group = QButtonGroup()
        self.speed_box = QGroupBox(tr("Force an ethernet speed"))
        speed_layout = QVBoxLayout(self.speed_box)

        self.speed_GFull = QRadioButton(tr("Gigabit full duplex"))
        self.speed_GHalf = QRadioButton(tr("Gigabit half duplex"))
        self.speed_100Full = QRadioButton(tr("100 Mb Full duplex"))
        self.speed_100Half = QRadioButton(tr("100 Mb Half duplex"))
        self.speed_10Full = QRadioButton(tr("10 Mb Full duplex"))
        self.speed_10Half = QRadioButton(tr("10 Mb Half duplex"))

        def toggle(value):
            if value:
                self.speed_GFull.click()

        self.speed_box.setCheckable(True)
        self.speed_box.setChecked(Qt.Unchecked)
        self.connect(self.speed_box, SIGNAL('toggled(bool)'), toggle)

        for item in (
            self.speed_GFull,
            self.speed_GHalf,
            self.speed_100Full,
            self.speed_100Half,
            self.speed_10Full,
            self.speed_10Half,
            ):
            self.speed_group.addButton(item)
            speed_layout.addWidget(item)

        form.addRow(self.speed_box)

    def fillValues(self):
        name = self.ethernet.user_label
        if name != "":
            self.label.setText(name)
            self.label.checkEmpty()
            self.label.setStyleSheet('')

        if self.ethernet.eth_auto:
            self.speed_box.setChecked(Qt.Unchecked)
            return

        self.speed_box.setChecked(Qt.Checked)
        if self.ethernet.eth_duplex == Ethernet.FULL:
            if self.ethernet.eth_speed == 10:
                button = self.speed_10Full
            elif self.ethernet.eth_speed == 100:
                button = self.speed_100Full
            else:
                button = self.speed_GFull
        else:
            if self.ethernet.eth_speed == 10:
                button = self.speed_10Half
            elif self.ethernet.eth_speed == 100:
                button = self.speed_100Half
            else:
                button = self.speed_GHalf


        button.setChecked(Qt.Checked)

    def getConfig(self):
        auto = not self.speed_box.isChecked()
        if auto:
            return True, None, None
        selection = self.speed_group.checkedButton()
        if selection is self.speed_GFull:
            return False, 1000, Ethernet.FULL
        elif self.speed_GHalf:
            return False, 1000, Ethernet.HALF
        elif self.speed_100Full:
            return False, 100, Ethernet.FULL
        elif self.speed_100Half:
            return False, 100, Ethernet.HALF
        elif self.speed_10Full:
            return False, 10, Ethernet.FULL
        elif self.speed_10Half:
            return False, 10, Ethernet.HALF

        assert False, "this selection is unknown"

    def setName(self):
        new_name = self.label.value()
#.........这里部分代码省略.........
开发者ID:maximerobin,项目名称:Ufwi,代码行数:103,代码来源:ethernet_editor.py


注:本文中的PyQt4.QtGui.QButtonGroup.checkedButton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。