Python gtk 模块,CheckButton() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用gtk.CheckButton()

项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def do_live_warning(self, radio):
        d = gtk.MessageDialog(parent=self, buttons=gtk.BUTTONS_OK)
        d.set_markup("<big><b>" + _("Note:") + "</b></big>")
        msg = _("The {vendor} {model} operates in <b>live mode</b>. "
                "This means that any changes you make are immediately sent "
                "to the radio. Because of this, you cannot perform the "
                "<u>Save</u> or <u>Upload</u> operations. If you wish to "
                "edit the contents offline, please <u>Export</u> to a CSV "
                "file, using the <b>File menu</b>.")
        msg = msg.format(vendor=radio.VENDOR, model=radio.MODEL)
        d.format_secondary_markup(msg)

        again = gtk.CheckButton(_("Don't show this again"))
        again.show()
        d.vbox.pack_start(again, 0, 0, 0)
        d.run()
        CONF.set_bool("live_mode", again.get_active(), "noconfirm")
        d.destroy()
项目:ecel    作者:ARL-UTEP-OC    | 项目源码 | 文件源码
def create_checkbox_hbox(self, label, value, trace, sensitivity_group, constraints=None):
        hbox_main = gtk.HBox()
        checkbutton_option = gtk.CheckButton(label.title())
        checkbutton_option.set_active(value)
        if label.lower() == "enabled":
            checkbutton_option.connect("toggled", self.enabled_checkbox_toggled, sensitivity_group)
        hbox_main.pack_start(checkbutton_option)

        self.plugin_config_widgets.append(checkbutton_option)
        self.plugin_config_traces.append(trace)
        sensitivity_group.append(checkbutton_option)
        self.sensitivity_groups.append(sensitivity_group)
        self.sensitivity_groups_switch.append(checkbutton_option)

        return hbox_main
项目:ecel    作者:ARL-UTEP-OC    | 项目源码 | 文件源码
def create_options_hbox(self, label, value, trace, sensitivity_group, constraints=None):
        hbox_main = gtk.HBox()
        label_text = gtk.Label(label.title())
        label_text.set_alignment(0, 0.5)
        label_text.set_padding(8,8)
        checkbuttons = []
        selected_options = value
        if constraints is None:
            options = []
        else:
            options = constraints
        for option in options:
            new_button = gtk.CheckButton(option)
            if option in selected_options:
                new_button.set_active(True)
            checkbuttons.append(new_button)
        hbox_main.pack_start(label_text)
        for checkbutton in checkbuttons:
            hbox_main.pack_start(checkbutton)

        self.plugin_config_widgets.append(checkbuttons)
        self.plugin_config_traces.append(trace)
        sensitivity_group.append(label_text)
        sensitivity_group.append(checkbuttons)

        return hbox_main
项目:tintwizard    作者:vanadey    | 项目源码 | 文件源码
def createCheckButton(parent, text="", active=False, gridX=0, gridY=0, sizeX=1, sizeY=1, xExpand=True, yExpand=True, handler=None):
    """Creates a checkbox widget and adds it to a parent widget."""
    temp = gtk.CheckButton(text if text != "" else None)
    temp.set_active(active)
    temp.connect("toggled", handler)

    parent.attach(temp, gridX, gridX+sizeX, gridY, gridY+sizeY, xoptions=gtk.EXPAND if xExpand else 0, yoptions=gtk.EXPAND if yExpand else 0)

    return temp
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def create_M_file() :
    p = os.path.join(NCAM_DIR, NGC_DIR, 'M123')
    with open(p, 'wb') as f :
        f.write('#!/usr/bin/env python\n# coding: utf-8\n')

        f.write("import gtk\nimport os\nimport pygtk\npygtk.require('2.0')\nfrom gtk import gdk\n\n")

        f.write("fname = '%s'\n" % os.path.join(NCAM_DIR, CATALOGS_DIR, 'no_skip_dlg.conf'))
        f.write('if os.path.isfile(fname) :\n    exit(0)\n\n')

        f.write("msg = '%s'\n" % _('Stop LinuxCNC program,&#10;toggle the shown button,&#10;then restart'))
        f.write("msg1 = '%s'\n" % _('Skip block not active'))
        f.write("icon_fname = '%s'\n\n" % os.path.join(NCAM_DIR, GRAPHICS_DIR, 'skip_block.png'))

        f.write('dlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_NONE, message_format = msg1)\n\n')

        f.write("dlg.set_title('NativeCAM')\ndlg.format_secondary_markup(msg)\n\n")

        f.write('dlg.set_image(gtk.Image())\n')
        f.write('dlg.get_image().set_from_pixbuf(gdk.pixbuf_new_from_file_at_size(icon_fname, 80, 80))\n\n')

        f.write('cb = gtk.CheckButton(label = "%s")\n' % _("Do not show again"))
        f.write('dlg.get_content_area().pack_start(cb, True, True, 0)\n')
        f.write('dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus()\n\n')

        f.write('dlg.set_keep_above(True)\ndlg.show_all()\n\ndlg.run()\n')
        f.write("if cb.get_active() :\n    open(fname, 'w').close()\n")
        f.write('exit(0)\n')

    os.chmod(p, 0o755)
    mess_dlg(_('LinuxCNC needs to be restarted now'))
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def msg_inv(self, msg, msgid):
        msg = msg.replace('&#176;', '°')
        print('\n%(feature_name)s : %(msg)s' % {'feature_name':self.get_name(), 'msg':msg})

        if (("ALL:msgid-0" in EXCL_MESSAGES) or
                ("%s:msgid-0" % (self.get_type()) in EXCL_MESSAGES) or
                (("%s:msgid-%d" % (self.get_type(), msgid)) in EXCL_MESSAGES)) :
            return

        # create dialog with image and checkbox
        dlg = gtk.MessageDialog(parent = None,
            flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            type = gtk.MESSAGE_WARNING,
            buttons = gtk.BUTTONS_NONE,
            message_format = self.get_name())
        dlg.set_title('NativeCAM')
        dlg.format_secondary_text(msg)
        img = gtk.Image()
        img.set_from_pixbuf(self.get_icon(add_dlg_icon_size))
        dlg.set_image(img)
        cb = gtk.CheckButton(label = _("Do not show again"))
        dlg.get_content_area().pack_start(cb, True, True, 0)
        dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus()

        dlg.set_keep_above(True)
        dlg.show_all()
        dlg.run()
        if cb.get_active() :
            GLOBAL_PREF.add_excluded_msg(self.get_type(), msgid)
        dlg.destroy()
项目:gui-o-matic    作者:mailpile    | 项目源码 | 文件源码
def _main_window_add_actions(self, button_box):
        for action in self.config['main_window'].get('actions', []):
            if action.get('type', 'button') == 'button':
                widget = gtk.Button(label=action.get('label', 'OK'))
                event = "clicked"
            elif action['type'] == 'checkbox':
                widget = gtk.CheckButton(label=action.get('label', '?'))
                event = "toggled"
            else:
                raise NotImplementedError('We only have buttons atm.')

            if action.get('position', 'left') in ('left', 'top'):
                button_box.pack_start(widget, False, True)
            elif action['position'] in ('right', 'bottom'):
                button_box.pack_end(widget, False, True)
            else:
                raise NotImplementedError('Invalid position: %s'
                                          % action['position'])

            if action.get('op'):
                def activate(o, a):
                    return lambda d: self._do(o, a)
                widget.connect(event,
                    activate(action['op'], action.get('args', [])))

            widget.set_sensitive(action.get('sensitive', True))
            self.items[action['item']] = widget
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def create_tag_vbox(self, widget, tab):
    for i in widget.get_children():
        i.destroy()
    for i in self.tags_ids:
        tag_id = self.tags_ids[i]
        tag_name = self.db.session.query(db.Tag.name).filter_by(tag_id=tag_id).first().name
        tab[i] = gtk.CheckButton(tag_name)
        tab[i].set_active(False)
        widget.pack_start(tab[i])
    widget.show_all()
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def update_config(self,widget,var_type=None):
        if isinstance(widget,gtk.Adjustment):
            value = widget.get_value()
        elif isinstance(widget,gtk.CheckButton):
            value = widget.get_active()
        self.atual_config[var_type] = value
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _init(self, data):
        self._widget = gtk.CheckButton("Enabled")
        self._widget.set_active(self._mem_value())
        self._widget.connect("toggled", self.toggled)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _add(self, tab, row, name, editor, text):

        label, editor, img = super(MultiMemoryDetailEditor, self)._add(
            tab, row, name, editor, text, 1)

        selector = gtk.CheckButton()
        tab.attach(selector, 0, 1, row, row + 1,
                   xoptions=gtk.FILL, yoptions=0, xpadding=0, ypadding=3)
        selector.show()
        self._toggle_selector(selector, label, editor, img)
        selector.connect("toggled", self._toggle_selector, label, editor, img)
        self._selections[name] = selector
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _show_instructions(self, radio, message):
        if message is None:
            return

        if CONF.get_bool("clone_instructions", "noconfirm"):
            return

        d = gtk.MessageDialog(parent=self, buttons=gtk.BUTTONS_OK)
        d.set_markup("<big><b>" + _("{name} Instructions").format(
                     name=radio.get_name()) + "</b></big>")
        msg = _("{instructions}").format(instructions=message)
        d.format_secondary_markup(msg)

        again = gtk.CheckButton(
            _("Don't show instructions for any radio again"))
        again.show()
        again.connect("toggled", lambda action:
                      self.clonemenu.set_active(not action.get_active()))
        d.vbox.pack_start(again, 0, 0, 0)
        h_button_box = d.vbox.get_children()[2]
        try:
            ok_button = h_button_box.get_children()[0]
            ok_button.grab_default()
            ok_button.grab_focus()
        except AttributeError:
            # don't grab focus on GTK+ 2.0
            pass
        d.run()
        d.destroy()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def show_warning(msg, text,
                 parent=None, buttons=None, title="Warning",
                 can_squelch=False):
    if buttons is None:
        buttons = gtk.BUTTONS_OK
    d = gtk.MessageDialog(buttons=buttons,
                          parent=parent,
                          type=gtk.MESSAGE_WARNING)
    d.set_title(title)
    d.set_property("text", msg)
    l = gtk.Label(_("Details") + ":")
    l.show()
    d.vbox.pack_start(l, 0, 0, 0)
    l = gtk.Label(_("Proceed?"))
    l.show()
    d.get_action_area().pack_start(l, 0, 0, 0)
    d.get_action_area().reorder_child(l, 0)
    textview = _add_text(d, text)
    textview.set_wrap_mode(gtk.WRAP_WORD)
    if not parent:
        d.set_position(gtk.WIN_POS_CENTER_ALWAYS)
    if can_squelch:
        cb = gtk.CheckButton(_("Do not show this next time"))
        cb.show()
        d.vbox.pack_start(cb, 0, 0, 0)

    d.set_size_request(600, 400)
    r = d.run()
    d.destroy()
    if can_squelch:
        return r, cb.get_active()
    return r
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def addParam(self, name, field, ptype, *args):
        x = self.tblGeneral.rows
        self.tblGeneral.rows += 1
        value = eval(field)
        if ptype==bool:
            obj = gtk.CheckButton()
            obj.set_label(name)
            obj.set_active(value)
            obj.set_alignment(0, 0.5)            
            obj.show()
            obj.field=field
            self.tblGeneral.attach(obj, 0, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)            
        elif ptype==int:            
            obj = gtk.SpinButton(climb_rate=10)
            if len(args)==2:
                obj.set_range(args[0], args[1])
            obj.set_increments(1, 10)
            obj.set_numeric(True)
            obj.set_value(value)                        
            obj.show()
            obj.field=field
            lbl = gtk.Label(name)
            lbl.set_alignment(0, 0.5)
            lbl.show()
            self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
            self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
        elif ptype==list:
            obj = gtk.combo_box_new_text()
            for s in args[0]:
                obj.append_text(s)
            obj.set_active(value)
            obj.show()
            obj.field=field
            lbl = gtk.Label(name)
            lbl.set_alignment(0, 0.5)
            lbl.show()
            self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
            self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
        else:            
            obj = gtk.Entry()
            obj.set_text(value)            
            obj.show()
            obj.field=field
            lbl = gtk.Label(name)
            lbl.set_alignment(0, 0.5)
            lbl.show()
            self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
            self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def on_okbutton1_clicked(self, widget, *args):
        for obj in self.tblGeneral:
            if hasattr(obj, "field"):
                if isinstance(obj, gtk.CheckButton):
                    value = obj.get_active()
                elif isinstance(obj, gtk.SpinButton):
                    value = obj.get_value_as_int()
                elif isinstance(obj, gtk.ComboBox):
                    value = obj.get_active()
                else:
                    value = '"%s"' % (obj.get_text())
                exec("%s=%s" % (obj.field, value))

        if self.get_widget("chkDefaultColors").get_active():
            conf.FONT_COLOR=""
            conf.BACK_COLOR=""
        else:
            conf.FONT_COLOR = self.btnFColor.selected_color
            conf.BACK_COLOR = self.btnBColor.selected_color

        if self.btnFont.selected_font.to_string() != 'monospace' and not self.chkDefaultFont.get_active():
            conf.FONT = self.btnFont.selected_font.to_string()
        else:
            conf.FONT = ''

        #Guardar shortcuts
        scuts={}
        for x in self.treeModel:
            if x[0]!='' and x[1]!='':
                scuts[x[1]] = [x[0]]
        for x in self.treeModel2:
            if x[0]!='' and x[1]!='':
                scuts[x[1]] = x[0]        
        global shortcuts        
        shortcuts = scuts

        #Boton donate
        global wMain
        if conf.HIDE_DONATE:
            wMain.get_widget("btnDonate").hide_all()
        else:
            wMain.get_widget("btnDonate").show_all()

        #Recrear menu de comandos personalizados
        wMain.populateCommandsMenu()        
        wMain.writeConfig()

        self.get_widget("wConfig").destroy()
    #-- Wconfig.on_okbutton1_clicked }

    #-- Wconfig.on_btnBColor_clicked {
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def _setup_widgets(self):

        h_space = 4 # horizontal space

        # create the frames to contein the diferent settings.
        f_time = gtk.Frame(label="Time")
        f_oskin = gtk.Frame(label="Onion Skin")
        self.set_size_request(300,-1)
        self.vbox.pack_start(f_time,True,True,h_space)
        self.vbox.pack_start(f_oskin,True,True,h_space)

        # create the time settings.
        th = gtk.HBox()
        fps,fps_spin = Utils.spin_button("Framerate",'int',self.last_config[FRAMERATE],1,100) #conf fps

        th.pack_start(fps,True,True,h_space)

        f_time.add(th)
        # create onion skin settings
        ov = gtk.VBox()
        f_oskin.add(ov)

        # fist line
        oh1 = gtk.HBox()
        depth,depth_spin = Utils.spin_button("Depth",'int',self.last_config[OSKIN_DEPTH],1,4,1) #conf depth

        on_play = gtk.CheckButton("On Play")
        on_play.set_active(self.last_config[OSKIN_ONPLAY])

        oh1.pack_start(depth,True,True,h_space)
        oh1.pack_start(on_play,True,True,h_space)
        ov.pack_start(oh1)
        # second line
        oh2 = gtk.HBox()
        forward = gtk.CheckButton("Forward")
        forward.set_active(self.last_config[OSKIN_FORWARD])

        backward = gtk.CheckButton("Backward")
        backward.set_active(self.last_config[OSKIN_BACKWARD])

        oh2.pack_start(forward,True,True,h_space)
        oh2.pack_start(backward,True,True,h_space)

        ov.pack_start(oh2)
        # last line

        # connect a callback to all

        fps_spin.connect("value_changed",self.update_config,FRAMERATE)
        depth_spin.connect("value_changed",self.update_config,OSKIN_DEPTH)
        on_play.connect("toggled",self.update_config,OSKIN_ONPLAY)
        forward.connect("toggled",self.update_config,OSKIN_FORWARD)
        backward.connect("toggled",self.update_config,OSKIN_BACKWARD)

        # show all
        self.show_all()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def do_columns(self):
        eset = self.get_current_editorset()
        driver = directory.get_driver(eset.rthread.radio.__class__)
        radio_name = "%s %s %s" % (eset.rthread.radio.VENDOR,
                                   eset.rthread.radio.MODEL,
                                   eset.rthread.radio.VARIANT)
        d = gtk.Dialog(title=_("Select Columns"),
                       parent=self,
                       buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        vbox = gtk.VBox()
        vbox.show()
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        sw.add_with_viewport(vbox)
        sw.show()
        d.vbox.pack_start(sw, 1, 1, 1)
        d.set_size_request(-1, 300)
        d.set_resizable(False)

        labelstr = _("Visible columns for {radio}").format(radio=radio_name)
        label = gtk.Label(labelstr)
        label.show()
        vbox.pack_start(label)

        fields = []
        memedit = eset.get_current_editor()  # .editors["memedit"]
        unsupported = memedit.get_unsupported_columns()
        for colspec in memedit.cols:
            if colspec[0].startswith("_"):
                continue
            elif colspec[0] in unsupported:
                continue
            label = colspec[0]
            visible = memedit.get_column_visible(memedit.col(label))
            widget = gtk.CheckButton(label)
            widget.set_active(visible)
            fields.append(widget)
            vbox.pack_start(widget, 1, 1, 1)
            widget.show()

        res = d.run()
        selected_columns = []
        if res == gtk.RESPONSE_OK:
            for widget in fields:
                colnum = memedit.col(widget.get_label())
                memedit.set_column_visible(colnum, widget.get_active())
                if widget.get_active():
                    selected_columns.append(widget.get_label())

        d.destroy()

        CONF.set(driver, ",".join(selected_columns), "memedit_columns")