`
deepfuture
  • 浏览: 4421076 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80204
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70603
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103764
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:286965
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15084
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:68000
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32384
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46134
社区版块
存档分类
最新评论

pygtk-spin_button微调

 
阅读更多

相对当前值做调整

spin_button.spin(direction, increment)
direction参数如下:
SPIN_STEP_FORWARD
SPIN_STEP_BACKWARD
SPIN_PAGE_FORWARD
SPIN_PAGE_BACKWARD
SPIN_HOME
SPIN_END
SPIN_USER_DEFINED

 

 

设置Spin_button在最低和最高值范围值之间滑动

spin_button.set_wrap(wrap)

只允许输入数字

spin_button.set_numeric(numeric)

使用 SpinButton将值四舍五入为最接近step_increment后的值,snap_to_ticks为TRUE或FALSE

spin_button.set_snap_to_ticks(snap_to_ticks)

 

spin_button.set_update_policy(policy)

policy的值是:

UPDATE_ALWAYS,忽略错误直接转化
UPDATE_IF_VALID,如果是数字才转化

设置小数点位数

spin_button.set_digits(digits)

 

#!/usr/bin/env python

# example spinbutton.py

import pygtk
pygtk.require('2.0')
import gtk

class SpinButtonExample:
	def toggle_snap(self, widget, spin):
		spin.set_snap_to_ticks(widget.get_active())

	def toggle_numeric(self, widget, spin):
		spin.set_numeric(widget.get_active())

	def change_digits(self, widget, spin, spin1):
		spin1.set_digits(spin.get_value_as_int())

	def get_value(self, widget, data, spin, spin2, label):
		if data == 1:
			buf = "%d" % spin.get_value_as_int()
		else:
			buf = "%0.*f" % (spin.get_value_as_int(),spin.get_value())
			label.set_text(buf)

	def __init__(self):
		window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		window.connect("destroy", lambda w: gtk.main_quit())
		window.set_title("Spin Button")

		main_vbox = gtk.VBox(False, 5)
		main_vbox.set_border_width(10)
		window.add(main_vbox)

		frame = gtk.Frame("Not accelerated")
		main_vbox.pack_start(frame, True, True, 0)

		vbox = gtk.VBox(False, 0)
		vbox.set_border_width(5)
		frame.add(vbox)

		# Day, month, year spinners
		hbox = gtk.HBox(False, 0)
		vbox.pack_start(hbox, True, True, 5)

		vbox2 = gtk.VBox(False, 0)
		hbox.pack_start(vbox2, True, True, 5)

		label = gtk.Label("Day :")
		label.set_alignment(0, 0.5)
		vbox2.pack_start(label, False, True, 0)

		adj = gtk.Adjustment(1.0, 1.0, 31.0, 1.0, 5.0, 0.0)
		spinner = gtk.SpinButton(adj, 0, 0)
		spinner.set_wrap(True)
		vbox2.pack_start(spinner, False, True, 0)

		vbox2 = gtk.VBox(False, 0)
		hbox.pack_start(vbox2, True, True, 5)

		label = gtk.Label("Month :")
		label.set_alignment(0, 0.5)
		vbox2.pack_start(label, False, True, 0)

		adj = gtk.Adjustment(1.0, 1.0, 12.0, 1.0, 5.0, 0.0)
		spinner = gtk.SpinButton(adj, 0, 0)
		spinner.set_wrap(True)
		vbox2.pack_start(spinner, False, True, 0)

		vbox2 = gtk.VBox(False, 0)
		hbox.pack_start(vbox2, True, True, 5)

		label = gtk.Label("Year :")
		label.set_alignment(0, 0.5)
		vbox2.pack_start(label, False, True, 0)

		adj = gtk.Adjustment(1998.0, 0.0, 2100.0, 1.0, 100.0, 0.0)
		spinner = gtk.SpinButton(adj, 0, 0)
		spinner.set_wrap(False)
		spinner.set_size_request(55, -1)
		vbox2.pack_start(spinner, False, True, 0)

		frame = gtk.Frame("Accelerated")
		main_vbox.pack_start(frame, True, True, 0)

		vbox = gtk.VBox(False, 0)
		vbox.set_border_width(5)
		frame.add(vbox)

		hbox = gtk.HBox(False, 0)
		vbox.pack_start(hbox, False, True, 5)

		vbox2 = gtk.VBox(False, 0)
		hbox.pack_start(vbox2, True, True, 5)

		label = gtk.Label("Value :")
		label.set_alignment(0, 0.5)
		vbox2.pack_start(label, False, True, 0)

		adj = gtk.Adjustment(0.0, -10000.0, 10000.0, 0.5, 100.0, 0.0)
		spinner1 = gtk.SpinButton(adj, 1.0, 2)
		spinner1.set_wrap(True)
		spinner1.set_size_request(100, -1)
		vbox2.pack_start(spinner1, False, True, 0)

		vbox2 = gtk.VBox(False, 0)
		hbox.pack_start(vbox2, True, True, 5)

		label = gtk.Label("Digits :")
		label.set_alignment(0, 0.5)
		vbox2.pack_start(label, False, True, 0)

		adj = gtk.Adjustment(2, 1, 5, 1, 1, 0)
		spinner2 = gtk.SpinButton(adj, 0.0, 0)
		spinner2.set_wrap(True)
		adj.connect("value_changed", self.change_digits, spinner2, spinner1)
		vbox2.pack_start(spinner2, False, True, 0)

		hbox = gtk.HBox(False, 0)
		vbox.pack_start(hbox, False, True, 5)

		button = gtk.CheckButton("Snap to 0.5-ticks")
		button.connect("clicked", self.toggle_snap, spinner1)
		vbox.pack_start(button, True, True, 0)
		button.set_active(True)

		button = gtk.CheckButton("Numeric only input mode")
		button.connect("clicked", self.toggle_numeric, spinner1)
		vbox.pack_start(button, True, True, 0)
		button.set_active(True)

		val_label = gtk.Label("")

		hbox = gtk.HBox(False, 0)
		vbox.pack_start(hbox, False, True, 5)
		button = gtk.Button("Value as Int")
		button.connect("clicked", self.get_value, 1, spinner1, spinner2,
		val_label)
		hbox.pack_start(button, True, True, 5)

		button = gtk.Button("Value as Float")
		button.connect("clicked", self.get_value, 2, spinner1, spinner2,
		val_label)
		hbox.pack_start(button, True, True, 5)

		vbox.pack_start(val_label, True, True, 0)
		val_label.set_text("0")

		hbox = gtk.HBox(False, 0)
		main_vbox.pack_start(hbox, False, True, 0)

		button = gtk.Button("Close")
		button.connect("clicked", lambda w: gtk.main_quit())
		hbox.pack_start(button, True, True, 5)
		window.show_all()
def main():
	gtk.main()
	return 0

if __name__ == "__main__":
	SpinButtonExample()
	main()

 



 

  • 大小: 28.5 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics