Python gi.repository.Gtk 模块,Switch() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用gi.repository.Gtk.Switch()

项目:games_nebula    作者:yancharkin    | 项目源码 | 文件源码
def set_new_page_active(self):

        last_page_number = self.notebook.get_n_pages() - 1

        if self.notebook.get_current_page() != last_page_number:
            self.notebook.set_current_page(last_page_number)
        else:
            return

        GObject.timeout_add(100, self.set_new_page_active)

    # Switch behavior and reset filters by RMB and LMB
项目:draobpilc    作者:awamper    | 项目源码 | 文件源码
def add_boolean(self, text, key):
        item = Gtk.Switch()
        item.set_halign(Gtk.Align.END)
        item.set_active(self._settings[key])
        self._settings.bind(key, item, 'active', Gio.SettingsBindFlags.DEFAULT)

        return self.add_row(text, item)
项目:MTodo    作者:mortezaipo    | 项目源码 | 文件源码
def __init__(self, name: str):
        """Initialize Switch class."""
        self._name = name
        self._widget = Gtk.Switch()
        self._widget.set_name(self._name)
项目:ExpressGui    作者:mattbruning    | 项目源码 | 文件源码
def __init__(self, express, selector):
        Gtk.Switch.__init__(self)
        self.express = express
        self.selector = selector
        self.connect("notify::active", self.switch_toggle, None)
项目:lightdm-settings    作者:linuxmint    | 项目源码 | 文件源码
def __init__(self, keyfile, settings, key):
        self.key = key
        self.keyfile = keyfile
        try:
            self.value = keyfile.get_boolean(GROUP_NAME, key)
        except:
            self.value = settings.get_boolean(key)
        Gtk.Switch.__init__(self)
        self.set_active(self.value)
        self.connect("notify::active", self.on_toggled)
项目:lightdm-settings    作者:linuxmint    | 项目源码 | 文件源码
def __init__(self, keyfile, key, value):
        self.key = key
        self.keyfile = keyfile
        Gtk.Switch.__init__(self)
        self.set_active(value)
        self.connect("notify::active", self.on_toggled)
项目:national-geographic-wallpaper    作者:atareao    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Dialog.__init__(
            self,
            _('National Geographic Wallpaper'),
            None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_size_request(350, 80)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close_application)

        self.config = Config()
        self.croni = Croni()
        self.autostart = Autostart()

        grid = Gtk.Grid()
        grid.set_row_spacing(5)
        grid.set_column_spacing(5)
        grid.set_border_width(5)
        self.get_content_area().add(grid)

        label10 = Gtk.Label(_('Change wallpaper automatically?') + ':')
        label10.set_alignment(0, 0.5)
        grid.add(label10)

        self.switch = Gtk.Switch()
        self.switch.set_active(self.croni.is_enabled())
        hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL, 5)
        hbox.pack_start(self.switch, False, False, 0)
        grid.attach(hbox, 1, 0, 1, 1)

        label20 = Gtk.Label(_('Select backgrounds source') + ':')
        label20.set_alignment(0, 0.5)
        grid.attach(label20, 0, 1, 1, 1)

        source_store = Gtk.ListStore(str, str)
        source_store.append([_('National Geographic'), 'national-geographic'])
        source_store.append([_('Bing'), 'bing'])
        source_store.append([_('GoPro'), 'gopro'])
        source_store.append([_('Powder'), 'powder'])
        source_store.append([_('Fstoppers'), 'fstoppers'])
        source_store.append([_('Desktoppr'), 'desktoppr'])
        source_store.append([_('Nasa'), 'nasa'])
        self.combobox_source = Gtk.ComboBox.new()
        self.combobox_source.set_model(source_store)
        cell1 = Gtk.CellRendererText()
        self.combobox_source.pack_start(cell1, True)
        self.combobox_source.add_attribute(cell1, 'text', 0)
        grid.attach(self.combobox_source, 1, 1, 1, 1)

        button = Gtk.Button(_('Change now'))
        button.connect('clicked', self.button_pressed)
        hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL, 5)
        hbox.pack_start(button, True, False, 0)
        grid.attach(hbox, 0, 2, 2, 1)

        self.load_preferences()

        self.show_all()
项目:bracer    作者:deikatsuo    | 项目源码 | 文件源码
def create_switch(self, p, g, l, b, d='Default'):
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                      spacing=12,
                      expand=True,
                      visible=True)

        title = Gtk.Label(halign='start',
                          expand=True,
                          visible=True,
                          label=l)

        subtitle = Gtk.Label(halign='start', expand=True, visible=True)
        subtitle.get_style_context().add_class('dim-label')
        subtitle.set_markup('<small>'+str(d)+'</small>')

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                       expand=True,
                       visible=True)

        vbox.pack_start(title, True, True, 0)
        vbox.pack_start(subtitle, True, True, 0)
        box.pack_start(vbox, True, True, 0)

        switch = Gtk.Switch(visible=True, expand=False)
        Bracer.settings.bind(b, switch, "active", Gio.SettingsBindFlags.DEFAULT)

        switch_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                       spacing=6,
                       expand=False,
                       visible=True)

        switch_box.pack_start(switch, True, False, 0)
        pack = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                       spacing=6,
                       expand=True,
                       visible=True)

        pack.pack_start(box, True, True, 0)
        pack.pack_end(switch_box, False, False, 0)
        ready = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                        spacing=6,
                        expand=True,
                        visible=True)

        ready.pack_start(pack, True, True, 0)
        self.ids.append(self.prefs.add_custom(p, g, ready, None, 1000))