您的位置:首页 > 移动开发 > Objective-C

PyGobject(七十三)Gtk.Widget之Gtk.SpinButton

2016-08-01 13:09 746 查看
GtkSpinButton
继承关系

Methods

Virtual Methods

Properties

Signals

例子

Gtk.SpinButton

Gtk.SpinButton带有加减号的输入框,输入内容必须在给定的范围内

继承关系

Gtk.SpinButton是Gtk.Entry的直接子类



Methods

方法修饰词方法名及参数
staticnew (adjustment, climb_rate, digits)
staticnew_with_range (min, max, step)
configure (adjustment, climb_rate, digits)
get_adjustment ()
get_digits ()
get_increments ()
get_numeric ()
get_range ()
get_snap_to_ticks ()
get_update_policy ()
get_value ()
get_value_as_int ()
get_wrap ()
set_adjustment (adjustment)
set_digits (digits)
set_increments (step, page)
set_numeric (numeric)
set_range (min, max)
set_snap_to_ticks (snap_to_ticks)
set_update_policy (policy)
set_value (value)
set_wrap (wrap)
spin (direction, increment)
update ()

Virtual Methods

do_change_value (scroll)
do_input (new_value)
do_output ()
do_value_changed ()
do_wrapped ()

Properties

NameTypeFlagsShort Description
adjustmentGtk.Adjustmentr/wThe adjustment that holds the value of the spin button
climb-ratefloatr/w/enThe acceleration rate when you hold down a button
digitsintr/w/enThe number of decimal places to display
numericboolr/w/enWhether non-numeric characters should be ignored
snap-to-ticksboolr/w/enWhether erroneous values are automatically changed to a spin button’s nearest step increment
update-policyGtk.SpinButtonUpdatePolicyr/w/enWhether the spin button should update always, or only when the value is legal
valuefloatr/w/enReads the current value, or sets a new value
wrapboolr/w/enWhether a spin button should wrap upon reaching its limits

Signals

NameShort Description
change-valueThe ::change-value signal is a keybinding signal which gets emitted when the user initiates a value change.
inputThe ::input signal can be used to influence the conversion of the users input into a double value.
outputThe ::output signal can be used to change to formatting of the value that is displayed in the spin buttons entry.
value-changedThe ::value-changed signal is emitted when the value represented by spinbutton changes.
wrappedThe ::wrapped signal is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa.

例子



代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/14
# section 117
TITLE = "SpinButton"
DESCRIPTION = """
A Gtk.SpinButton is an ideal way to allow the user to set the value of some attribute.
Rather than having to directly type a number into a Gtk.Entry, Gtk.SpinButton allows
the user to click on one of two arrows to increment or decrement the displayed value.
"""
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class SpinButtonWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="SpinButton Demo")
self.set_border_width(10)

hbox = Gtk.Box(spacing=6)
self.add(hbox)

# lower<value<upper-page_size
# step_increment鼠标左键(或者键盘上下键)按下增加或减少的值.page_increment键盘PageDown或PageUp按下增加或减少的值
# 当鼠标右键按下时,直接显示最大值或者最小值
adjustment = Gtk.Adjustment(value=0, lower=0, upper=20, step_increment=1, page_increment=2, page_size=1)
self.spinbutton = Gtk.SpinButton()
self.spinbutton.set_adjustment(adjustment)
self.spinbutton.connect("value-changed", self.change_value)
hbox.pack_start(self.spinbutton, False, False, 0)

check_numeric = Gtk.CheckButton("Numeric")
check_numeric.connect("toggled", self.on_numeric_toggled)
hbox.pack_start(check_numeric, False, False, 0)

check_ifvalid = Gtk.CheckButton("If Valid")
check_ifvalid.connect("toggled", self.on_ifvalid_toggled)
hbox.pack_start(check_ifvalid, False, False, 0)

# 如果勾选,只能输入数字,其它字符不能输入
def on_numeric_toggled(self, button):
self.spinbutton.set_numeric(button.get_active())

# 如果勾选,只有合法的数值才会更新.输入不合法的数值,还是显示原来的数值.
# 当不勾选时,输入不合法的数值,第一次显示upper-page_size,后面就显示输入的数值
def on_ifvalid_toggled(self, button):
if button.get_active():
policy = Gtk.SpinButtonUpdatePolicy.IF_VALID
else:
policy = Gtk.SpinButtonUpdatePolicy.ALWAYS
self.spinbutton.set_update_policy(policy)

@staticmethod
def change_value(widget):
print("change_value", widget.get_value())

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

if __name__ == "__main__":
main()


代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息