PyGobject(十四)布局容器之Button篇——Gtk.LockButton
来源:互联网 发布:淘宝直播视频开店教程 编辑:程序博客网 时间:2024/05/22 02:22
- GtkLockButton
- 继承关系
- Methods
- Virtual Methods
- Properties
- Signals
- 例子
Gtk.LockButton
继承关系
Gtk.LockButton锁定与解锁按钮,常用来进行权限管理。Gtk.LockButton是Gtk.Button的直接子类
Methods
Virtual Methods
Properties
Signals
例子
代码:
#!/usr/bin/env python3# Created by xiaosanyu at 16/6/27# section 015TITLE = "LockButton"DESCRIPTION = """Gtk.LockButton is a widget that can be used in control panels or preference dialogsto 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 gigi.require_version('Gtk', '3.0')from gi.repository import Gtk, Gdk, Gio, GObjectclass 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
0 0
- PyGobject(十四)布局容器之Button篇——Gtk.LockButton
- PyGobject(五)布局容器之Button篇——Gtk.Button
- PyGobject(六)布局容器之Button篇——Gtk.ColorButton
- PyGobject(七)布局容器之Button篇——Gtk.FontButton
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- PyGobject(九)布局容器之Button篇——Gtk.ToggleButton
- PyGobject(十)布局容器之Button篇——Gtk.CheckButton
- PyGobject(十一)布局容器之Button篇——Gtk.RadioButton
- PyGobject(十二)布局容器之Button篇——Gtk.MenuButton
- PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton
- PyGobject(十六)布局容器之Button篇——Gtk.VolumeButton
- PyGobject(十七)布局容器之Button篇——Gtk.ModelButton
- PyGobject(十三)布局容器之Button篇——图片按钮和圆形按钮
- PyGobject(二十四)布局容器之Expander
- PyGobject(十八)布局容器之ActionBar
- PyGobject(十九)布局容器之Alignment
- PyGobject(三十)布局容器之StackSidebar
- PyGobject(三十一)布局容器之EventBox
- 泛型相关
- 【C语言】关于斐波那契数的求法
- 【转】IntelliJ IDEA导航特性Top20
- 100. Same Tree
- 单例模式与垃圾回收
- PyGobject(十四)布局容器之Button篇——Gtk.LockButton
- 接触Oracle锁定
- 临时记录
- mysql的sql_mode(SQL模式)调整对数据迁移的影响和处理
- 详解YUV数据格式
- Nginx常见的优化策略
- 跟我学系列之NIO的那些坑
- 跟我学系列之Netty源码图
- Android Telephony分析(二) ---- RegistrantList详解