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

PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton

2016-07-26 15:33 591 查看
GtkScaleButton
继承关系

Methods

Virtual Methods

Properties

Signals

例子

Gtk.ScaleButton

继承关系

Gtk.ScaleButton根据滑块位置,显示不同的图片。Gtk.ScaleButton是Gtk.Button的直接子类



Methods

方法修饰词方法名及参数
staticnew (size, min, max, step, icons)
get_adjustment ()
get_minus_button ()
get_plus_button ()
get_popup ()
get_value ()
set_adjustment (adjustment)
set_icons (icons)
set_value (value)

Virtual Methods

do_value_changed (value)

Properties

NameTypeFlagsShort Description
adjustmentGtk.Adjustmentr/wScaleButton值的范围
icons[str]r/wList of icon names
sizeGtk.IconSizer/w/enThe icon size
valuefloatr/w/enThe value of the scale

Signals

NameShort Description
popdownThe ::popdown signal is a keybinding signal which gets emitted to popdown the scale widget.
popupThe ::popup signal is a keybinding signal which gets emitted to popup the scale widget.
value-changedThe ::value-changed signal is emitted when the value field has changed.

例子



代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/27
# section 016
TITLE = "ScaleButton"
DESCRIPTION = """
Gtk.ScaleButton provides a button which pops up a scale widget.
This kind of widget is commonly used for volume controls in multimedia applications,
and GTK+ provides a Gtk.VolumeButton subclass that is tailored for this use case.
"""
import gi

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

# 最高的图标要放在第二位
icons = ["microphone-sensitivity-muted-symbolic.symbolic", "microphone-sensitivity-high-symbolic.symbolic",
"microphone-sensitivity-low-symbolic.symbolic", "microphone-sensitivity-medium-symbolic.symbolic"]

class ScaleButtonWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ScaleButton Demo")
self.set_border_width(10)
self.set_default_size(200, 300)
box = Gtk.Box()
sbtn = Gtk.ScaleButton(icons=icons)
sbtn.connect("value_changed", self.change)
box.add(sbtn)
self.add(box)

def change(self, btn, value):
# print(value)
pass

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

if __name__ == "__main__":
main()


分析主要代码

定义显示的图片名称列表,默认显示的放在第一个,最后显示的图片放第二个,其余依次排放

icons =
["microphone-sensitivity-muted-symbolic.symbolic",
"microphone-sensitivity-high-symbolic.symbolic",
"microphone-sensitivity-low-symbolic.symbolic", "microphone-sensitivity-medium-symbolic.symbolic"]


定义一个ScaleButton,指定其icons属性

sbtn = Gtk.ScaleButton(icons=icons)


绑定”value_changed”信号

sbtn.connect("value_changed", self.change)


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