def _setup_bindings(self): mgr = get_conf_manager() bindings = mgr['keyboard_shortcuts.*'] for action_name, binding in bindings.iteritems(): # Set up the global key bindings. action = action_name.split('_', 1)[1] KeyBindingManager().add_binding_from_string(binding, self.capture, (None, False, action))
def _upload_file(filename): """ Upload the file `filename` to the configured sharing service, and shortens the URL with the configured URL shortener. Also copies the shortened URL to the clipboard, and runs the post upload hook (if there is one). """ configmanager = get_conf_manager() sharingservice = get_sharing_service_from_conf(configmanager) urlprovider = get_url_shortener_from_conf(configmanager) try: StatusIcon().statusicon.set_icon_from_file(os.path.join(PATHS['ICONS_PATH'], 'icon-uploading.png')) # Store the file online url = sharingservice.store(filename) print 'Saved to', url except Exception, e: import traceback traceback.print_exc() print type(e) if isinstance(e, SharingError): try: title = e.args[1] except IndexError: title = e.default_title notify(title, e.args[0]) elif isinstance(e, URLError): notify('Connection error', 'You may be disconnected from the internet, or the server you are using may be down.') StatusIcon().statusicon.set_icon_from_file(os.path.join(PATHS['ICONS_PATH'], 'icon-uploadfailed.png')) timer = Timer(5, StatusIcon().reset_icon) timer.setDaemon(True) timer.start() return None
def setup_defaults(): """ Sort out some of the default options for the config manager. """ conf_manager = get_conf_manager() defaults = { 'sharing.sharingservice': 'tinypic', 'sharing.shortener': 'none', 'sharing.shortener_anonymous': 1, 'keyboard_shortcuts.capture_area': '<Control>Print', 'keyboard_shortcuts.capture_window': '<Control><Shift>Print', 'keyboard_shortcuts.capture_screen': '<Super>Print', 'use_temp_directory': 1, } conf_manager.settings.defaults.update(defaults)
import gtk from snappy.backend.configmanagers import get_conf_manager from snappy.ui.gtk.dialogs.preferences import PreferencesArea from snappy.ui.gtk.keybindings import KeyBindingManager conf_manager = get_conf_manager() class MainAreaTab(PreferencesArea): def startup(self): print self.get_widget_by_name('quickshot') for name, binding in conf_manager['keyboard_shortcuts.*'].iteritems(): self.get_widget_by_name(name).set_text(binding) self.get_widget_by_name('use_temp_directory').set_active(int(conf_manager['use_temp_directory'])) self.modifier_keyvals = ( 'Control_L', 'Control_R', 'Alt_L', 'Alt_R', 'Shift_L', 'Shift_R', 'Super_L', 'Super_R', #more? needs testing... ) self.modifiers_mask = 0 for modifier in (gtk.gdk.CONTROL_MASK, gtk.gdk.SHIFT_MASK, gtk.gdk.MOD1_MASK, gtk.gdk.SUPER_MASK, gtk.gdk.HYPER_MASK): self.modifiers_mask |= modifier def kbd_entry_focus(self, widget, event, data=None): KeyBindingManager().ungrab() gtk.gdk.keyboard_grab(widget.window) global oldtext
def __init__(self): self.configmanager = get_conf_manager()