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

PyGobject(十四)布局容器之Button篇——Gtk.LockButton

2016-07-26 15:22 651 查看
GtkLockButton
继承关系

Methods

Virtual Methods

Properties

Signals

例子

Gtk.LockButton

继承关系

Gtk.LockButton锁定与解锁按钮,常用来进行权限管理。Gtk.LockButton是Gtk.Button的直接子类



Methods

方法修饰词方法名及参数
staticnew (permission)
get_permission ()
set_permission (permission)

Virtual Methods

Properties

NameTypeFlagsShort Description
permissionGio.Permissionr/wThe Gio.Permission object controlling this button
text-lockstrr/w/c锁定状态显示的文本
text-unlockstrr/w/c解锁状态显示的文本
tooltip-lockstrr/w/c提示用户锁定时显示的文本
tooltip-not-authorizedstrr/w/c提示用户不能获得授权时显示的文本
tooltip-unlockstrr/w/c提示用户解锁时显示的文本

Signals

NameShort 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息