PyGobject(十四)布局容器之Button篇——Gtk.LockButton
2016-07-26 15:22
651 查看
GtkLockButton
继承关系
Methods
Virtual Methods
Properties
Signals
例子
![](https://img-blog.csdn.net/20160726145929110)
![](https://img-blog.csdn.net/20160726150824029)
![](https://img-blog.csdn.net/20160726150835107)
代码:
分析主要代码
创建一个LockButton,绑定”clicked”事件
创建Gio.SimplePermission对象,将permission的“allowed”属性与self.box的“sensitive”属性绑定
impl_update(allowed, can_acquire, can_release)[source]
Parameters:
allowed (bool) – ‘allowed’ property
can_acquire (bool) – the new value for the ‘can-acquire’ property
can_release (bool) – the new value for the ‘can-release’ property
设置LockButton的权限控制对象
/(ㄒoㄒ)/~~
无赖,我执行此代码一直显示
”Error releasing permission: Can’t acquire or release permission”
只好在点击事件中做文章
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
继承关系
Methods
Virtual Methods
Properties
Signals
例子
Gtk.LockButton
继承关系
Gtk.LockButton锁定与解锁按钮,常用来进行权限管理。Gtk.LockButton是Gtk.Button的直接子类Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (permission) |
get_permission () | |
set_permission (permission) |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
permission | Gio.Permission | r/w | The Gio.Permission object controlling this button |
text-lock | str | r/w/c | 锁定状态显示的文本 |
text-unlock | str | r/w/c | 解锁状态显示的文本 |
tooltip-lock | str | r/w/c | 提示用户锁定时显示的文本 |
tooltip-not-authorized | str | r/w/c | 提示用户不能获得授权时显示的文本 |
tooltip-unlock | str | r/w/c | 提示用户解锁时显示的文本 |
Signals
Name | Short Description |
---|
例子
代码:
#!/usr/bin/env python3 # Created by xiaosanyu at 16/6/27 # section 015 TITLE = "LockButton" DESCRIPTION = """ Gtk.LockButton is a widget that can be used in control panels or preference dialogs to allow users to obtain and revoke authorizations needed to operate the controls. The required authorization is represented by a Gio.Permission object. Concrete implementations of Gio.Permission may use PolicyKit or some other authorization framework. To obtain a PolicyKit-based Gio.Permission, use polkit_permission_new(). """ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, Gio, GObject class LockButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="LockButton Demo") self.set_border_width(10) parent = Gtk.HBox(spacing=6) self.box = Gtk.HBox(spacing=6, homogeneous=False) self.check_button = Gtk.CheckButton("check button") self.box.pack_start(self.check_button, False, False, 0) self.box.pack_start(Gtk.Button("button"), False, False, 0) circular_button = Gtk.Button.new_from_icon_name("emblem-system-symbolic", Gtk.IconSize.MENU) circular_button.get_style_context().add_class("circular") self.box.pack_start(circular_button, False, False, 0) lbtn = Gtk.LockButton() lbtn.connect("clicked", self.on_clicked) permission = Gio.SimplePermission.new(allowed=True) permission.impl_update(True, True, True) permission.bind_property("allowed", self.box, "sensitive", GObject.BindingFlags.SYNC_CREATE) lbtn.set_permission(permission) parent.pack_start(self.box, False, False, 0) parent.pack_start(lbtn, False, False, 0) self.add(parent) def on_clicked(self, button): if button.get_permission().get_allowed(): self.box.props.sensitive = False button.get_permission().impl_update(False, True, True) else: self.box.props.sensitive = True button.get_permission().impl_update(True, True, True) def main(): win = LockButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() if __name__ == "__main__": main()
分析主要代码
创建一个LockButton,绑定”clicked”事件
lbtn = Gtk.LockButton() lbtn.connect("clicked", self.on_clicked)
创建Gio.SimplePermission对象,将permission的“allowed”属性与self.box的“sensitive”属性绑定
permission = Gio.SimplePermission.new(allowed=True) permission.impl_update(True, True, True) permission.bind_property("allowed", self.check_button, "sensitive", GObject.BindingFlags.SYNC_CREATE)
impl_update(allowed, can_acquire, can_release)[source]
Parameters:
allowed (bool) – ‘allowed’ property
can_acquire (bool) – the new value for the ‘can-acquire’ property
can_release (bool) – the new value for the ‘can-release’ property
设置LockButton的权限控制对象
lbtn.set_permission(permission)
/(ㄒoㄒ)/~~
无赖,我执行此代码一直显示
”Error releasing permission: Can’t acquire or release permission”
只好在点击事件中做文章
def on_clicked(self, button): if button.get_permission().get_allowed(): self.box.props.sensitive = False button.get_permission().impl_update(False, True, True) else: self.box.props.sensitive = True button.get_permission().impl_update(True, True, True)
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法