Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _insert_options(self, menu):
"""Add configuration options to menu."""
menu.append(Gtk.SeparatorMenuItem())
menu.append(self._menuitem(
_('Mount disc image'),
self._icons.get_icon('losetup', Gtk.IconSize.MENU),
run_bg(lambda _: self._losetup())
))
menu.append(Gtk.SeparatorMenuItem())
menu.append(self._menuitem(
_("Enable automounting"),
icon=None,
onclick=lambda _: self._daemon.automounter.toggle_on(),
checked=self._daemon.automounter.is_on(),
))
menu.append(self._menuitem(
_("Enable notifications"),
icon=None,
onclick=lambda _: self._daemon.notify.toggle(),
checked=self._daemon.notify.active,
))
# append menu item for closing the application
if self._quit_action:
def _add_action(self, notification, action, label, callback, *args):
"""
Show an action button button in mount notifications.
Note, this only works with some libnotify services.
"""
on_action_click = run_bg(lambda *_: callback(*args))
try:
# this is the correct signature for Notify-0.7, the last argument
# being 'user_data':
notification.add_action(action, label, on_action_click, None)
except TypeError:
# this is the signature for some older version, I don't know what
# the last argument is for.
notification.add_action(action, label, on_action_click, None, None)
# gi.Notify does not store hard references to the notification
# objects. When a signal is received and the notification does not
# exist anymore, no handler will be called. Therefore, we need to
# prevent these notifications from being destroyed by storing
# references:
notification.connect('closed', self._notifications.remove)
self._notifications.append(notification)
def make_action_callback(node):
return run_bg(lambda _: node.action())
for node in items:
@run_bg
def auto_add(self, device):
return self._mounter.auto_add(device, automount=self._automount)
from shell scripts.
The command can contain modern pythonic format placeholders like:
{device_file}. The following placeholders are supported:
event, device_file, device_id, device_size, drive, drive_label, id_label,
id_type, id_usage, id_uuid, mount_path, root
:param str command_format: command to run when an event occurs.
:param mounter: Mounter object
"""
udisks = mounter.udisks
for event in ['device_mounted', 'device_unmounted',
'device_locked', 'device_unlocked',
'device_added', 'device_removed',
'job_failed']:
udisks.connect(event, run_bg(DeviceCommand(command_format, event=event)))
global Gtk
Gtk = require_Gtk()
builder = Gtk.Builder.new()
builder.add_from_string(dialog_definition)
window = builder.get_object('entry_dialog')
self.entry = builder.get_object('entry')
show_password = builder.get_object('show_password')
show_password.set_label(_('Show password'))
show_password.connect('clicked', self.on_show_password)
allow_keyfile = options.get('allow_keyfile')
keyfile_button = builder.get_object('keyfile_button')
keyfile_button.set_label(_('Open keyfile…'))
keyfile_button.set_visible(allow_keyfile)
keyfile_button.connect('clicked', run_bg(self.on_open_keyfile))
allow_cache = options.get('allow_cache')
cache_hint = options.get('cache_hint')
self.use_cache = builder.get_object('remember')
self.use_cache.set_label(_('Cache password'))
self.use_cache.set_visible(allow_cache)
self.use_cache.set_active(cache_hint)
label = builder.get_object('message')
label.set_label(message)
window.set_title(title)
window.set_keep_above(True)
super().__init__(window)