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

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

项目:rpi-backlight    作者:linusg    | 项目源码 | 文件源码
def gui():
    """Start the graphical user interface."""
    try:
        import gi
        gi.require_version("Gtk", "3.0")
        from gi.repository import Gtk
    except ImportError:
        print("Sorry, this needs pygobject to be installed!")
        sys.exit()

    win = Gtk.Window(title="Set display brightness")

    ad1 = Gtk.Adjustment(value=get_actual_brightness(), lower=11, upper=255)
    scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=ad1)

    def on_scale_changed(s, _):
        value = int(s.get_value())
        set_brightness(value)

    scale.connect("button-release-event", on_scale_changed)
    scale.connect("key_release_event", on_scale_changed)
    scale.connect("scroll-event", on_scale_changed)
    scale.set_size_request(350, 50)

    # Main Container
    main_container = Gtk.Fixed()
    main_container.put(scale, 10, 10)

    # Main Window
    win.connect("delete-event", Gtk.main_quit)
    win.connect("destroy", Gtk.main_quit)
    win.add(main_container)
    win.resize(400, 50)
    win.set_position(Gtk.WindowPosition.CENTER)

    win.show_all()
    Gtk.main()
项目:backlight-indicator    作者:atareao    | 项目源码 | 文件源码
def __init__(self, value):
        #
        Gtk.Dialog.__init__(self,
                            'Backlight Indicator | ' + _('Set backlight'),
                            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.connect('close', self.close_ok)
        self.set_icon_from_file(comun.ICON)
        #
        vbox0 = Gtk.VBox(spacing=5)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        frame0 = Gtk.Frame()
        vbox0.pack_start(frame0, False, True, 1)
        table0 = Gtk.Table(2, 2, False)
        frame0.add(table0)
        label23 = Gtk.Label(_('Backlight') + ':')
        label23.set_alignment(0, 0.5)
        table0.attach(label23, 0, 1, 0, 1,
                      xpadding=5, ypadding=5)
        configuration = Configuration()
        minimum_backlight = configuration.get('minimum-backlight')
        maximum_backlight = configuration.get('maximum-backlight')
        ba = BacklightManager()
        backlight = ba.get_backlight()
        adjustment3 = Gtk.Adjustment(backlight,
                                     minimum_backlight,
                                     maximum_backlight, 5, 10, 1)
        self.backlight = Gtk.Scale()
        self.backlight.set_digits(0)
        self.backlight.set_size_request(200, 10)
        self.backlight.set_adjustment(adjustment3)
        table0.attach(self.backlight, 1, 2, 0, 1,
                      xpadding=5, ypadding=5)
        self.backlight.set_value(value)
        self.show_all()