PyGobject(七十四)Gtk.Widget之Gtk.Scale

在介紹Gtk.Scale之前先介紹一下他的父類,Gtk.Range

Gtk.Range

Gtk.Range使Adjustment可視化,是Gtk.Scale和Gtk.Scrollbar部件的公共基類。
這裏寫圖片描述

Methods

方法修飾詞 方法名及參數
get_adjustment ()
get_fill_level ()
get_flippable ()
get_inverted ()
get_lower_stepper_sensitivity ()
get_min_slider_size ()
get_range_rect ()
get_restrict_to_fill_level ()
get_round_digits ()
get_show_fill_level ()
get_slider_range ()
get_slider_size_fixed ()
get_upper_stepper_sensitivity ()
get_value ()
set_adjustment (adjustment)
set_fill_level (fill_level)
set_flippable (flippable)
set_increments (step, page)
set_inverted (setting)
set_lower_stepper_sensitivity (sensitivity)
set_min_slider_size (min_size)
set_range (min, max)
set_restrict_to_fill_level (restrict_to_fill_level)
set_round_digits (round_digits)
set_show_fill_level (show_fill_level)
set_slider_size_fixed (size_fixed)
set_upper_stepper_sensitivity (sensitivity)
set_value (value)

Virtual Methods

do_adjust_bounds (new_value)
do_change_value (scroll, new_value)
do_get_range_border (border_)
do_move_slider (scroll)
do_value_changed ()

Properties

Name Type Flags Short Description
adjustment Gtk.Adjustment r/w/c The Gtk.Adjustment that contains the current value of this range object
fill-level float r/w/en The fill level.
inverted bool r/w/en Invert direction slider moves to increase range value
lower-stepper-sensitivity Gtk.SensitivityType r/w/en The sensitivity policy for the stepper that points to the adjustment’s lower side
restrict-to-fill-level bool r/w/en Whether to restrict the upper boundary to the fill level.
round-digits int r/w/en The number of digits to round the value to.
show-fill-level bool r/w/en Whether to display a fill level indicator graphics on trough.
upper-stepper-sensitivity Gtk.SensitivityType r/w/en The sensitivity policy for the stepper that points to the adjustment’s upper side

Signals

Name Short Description
adjust-bounds Emitted before clamping a value, to give the application a chance to adjust the bounds.
change-value The Gtk.Range ::change-value signal is emitted when a scroll action is performed on a range.
move-slider Virtual function that moves the slider.
value-changed Emitted when the range value changes.

Gtk.Scale

Gtk.Scale滑動條或刻度尺

繼承關係

Gtk.Scale是Gtk.Range的直接子類
這裏寫圖片描述
這裏寫圖片描述

Methods

方法修飾詞 方法名及參數
static new (orientation, adjustment)
static new_with_range (orientation, min, max, step)
add_mark (value, position, markup)
clear_marks ()
get_digits ()
get_draw_value ()
get_has_origin ()
get_layout ()
get_layout_offsets ()
get_value_pos ()
set_digits (digits)
set_draw_value (draw_value)
set_has_origin (has_origin)
set_value_pos (pos)

Virtual Methods

do_draw_value ()
do_format_value (value)
do_get_layout_offsets ()

Properties

Name Type Flags Short Description
digits int r/w/en The number of decimal places that are displayed in the value
draw-value bool r/w/en Whether the current value is displayed as a string next to the slider
has-origin bool r/w/en Whether the scale has an origin
value-pos Gtk.PositionType r/w/en The position in which the current value is displayed

Signals

Name Short Description
format-value Signal which allows you to change how the scale value is displayed.

例子

這裏寫圖片描述
代碼:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/14
# section 118
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.csdn.net/a87b01c14
# created: 16/7/14

TITLE = "Scale"
DESCRIPTION = """
A Gtk.Scale is a slider control used to select a numeric value. To use it,
you’ll probably want to investigate the methods on its base class,
Gtk.Range, in addition to the methods for Gtk.Scale itself.
"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Gio, GLib


class ScaleWindow(Gtk.Window):
    def __init__(self, *args, **kwargs):
        Gtk.Window.__init__(self, title="Scale Example")
        self.set_size_request(250, 200)
        box = Gtk.VBox(spacing=6)
        ad1 = Gtk.Adjustment(value=50, lower=0, upper=100, step_increment=1, page_increment=1,
                             page_size=0)
        ad2 = Gtk.Adjustment(value=50, lower=0, upper=100, step_increment=1, page_increment=1,
                             page_size=0)
        scale1 = Gtk.Scale(adjustment=ad1)
        scale1.set_show_fill_level(True)
        box.pack_start(scale1, False, False, 0)
        scale2 = Gtk.Scale(adjustment=ad2)
        for i in [x * 10 for x in range(11)]:
            scale2.add_mark(i, Gtk.PositionType.BOTTOM)
        box.pack_start(scale2, False, False, 0)
        self.add(box)


def main():
    win = ScaleWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()





代碼下載地址:http://download.csdn.net/detail/a87b01c14/9594728

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章