Gtk.LockButton
Gtk.LockButton — A widget to unlock or lock privileged operations
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.Button
╰── Gtk.LockButton
Functions:
- new
(permission:Gio.Permission=None) -> Gtk.Widget
- get_permission
(self) -> Gio.Permission
- set_permission
(self, permission:Gio.Permission=None)
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 #GPermission object. Concrete implementations of #GPermission may use PolicyKit or some other authorization framework. To obtain a PolicyKit-based #GPermission, use polkit_permission_new().
If the user is not currently allowed to perform the action, but can obtain the permission, the widget looks like this: ![](lockbutton-locked.png)
and the user can click the button to request the permission. Depending on the platform, this may pop up an authentication dialog or ask the user to authenticate in some other way. Once the user has obtained the permission, the widget changes to this:
![](lockbutton-unlocked.png)
and the permission can be dropped again by clicking the button. If the user is not able to obtain the permission at all, the widget looks like this:
![](lockbutton-sorry.png)
If the user has the permission and cannot drop it, the button is hidden.
The text (and tooltips) that are shown in the various cases can be adjusted with the Gtk.LockButton:text-lock
, Gtk.LockButton:text-unlock
,
Function Details:
new()
new (permission:Gio.Permission=None) -> Gtk.Widget
Creates a new lock button which reflects the permission
.
Returns: a new Gtk.LockButton
Since: 3.2
get_permission()
get_permission (self) -> Gio.Permission
Obtains the GPermission object that controls button
.
Returns: the GPermission of
button
.Since: 3.2
set_permission()
set_permission (self, permission:Gio.Permission=None)
Sets the GPermission object that controls button
.
- Since: 3.2
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Polkit
from gi.repository import Gio
import os
def check_authorization(lockbutton):
authority.check_authorization(subject, action_id, None, Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION, cancellable, check_authorization_cb, mainloop)
def check_authorization_cb(authority, res, loop):
try:
result = authority.check_authorization_finish(res)
if result.get_is_authorized():
print("Authorized")
elif result.get_is_challenge():
print("Challenge")
else:
print("Not authorized")
except GObject.GError as error:
print("Error checking authorization: %s" % error.message)
if __name__ == "__main__":
action_id = "org.freedesktop.policykit.exec"
mainloop = GObject.MainLoop()
authority = Polkit.Authority.get()
cancellable = Gio.Cancellable()
subject = Polkit.UnixProcess.new(os.getppid())
window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)
lockbutton = Gtk.LockButton()
lockbutton.connect("clicked", check_authorization)
window.add(lockbutton)
window.show_all()
mainloop.run()