def launch(self, files=(), paths=(), activate=False, ctx=None): """ Launch the represented application @files: a seq of GFiles (gio.File) @paths: a seq of bytestring paths @activate: activate instead of start new """ if self.serverid is not None: argv = [VIM, '--servername', self.serverid, '--remote'] else: argv = [VIM] if files: paths = [f.get_path() or f.get_uri() for f in files] if paths: argv.extend(paths) if paths or self.serverid is None: try: utils.spawn_async_raise(argv) except utils.SpawnError as exc: raise OperationError(exc) if self.serverid: ## focus the window we opened def error_handler(exc): ctx.register_late_error(OperationError(exc)) proxy_obj = get_plugin_service_obj(PLUGID) if proxy_obj: proxy_obj.Foreground(self.serverid, reply_handler=_dummy_handler, error_handler=error_handler)
def activate(self, leaf): text = leaf.object keys, orig_mods = gtk.accelerator_parse(text) m = { gtk.gdk.SHIFT_MASK: "Shift_L", gtk.gdk.CONTROL_MASK: "Control_L", gtk.gdk.SUPER_MASK: "Super_L", gtk.gdk.MOD1_MASK: "Alt_L", } mod_names = [] mods = orig_mods for mod in m: if mod & mods: mod_names.append(m[mod]) mods &= ~mod if mods != 0: raise OperationError("Keys not yet implemented: %s" % gtk.accelerator_get_label(keys, orig_mods)) key_arg = 'key %s' % (gtk.gdk.keyval_name(keys), ) mods_down = ['keydown ' + n for n in mod_names] mods_up = ['keyup ' + n for n in reversed(mod_names)] xte_paste_argv = ['xte', 'usleep 300000'] + \ mods_down + [key_arg] + mods_up try: utils.spawn_async_raise(xte_paste_argv) except utils.SpawnError as exc: raise OperationError(exc)
def run(self): toggle = int( _cmd_output("server config playlist.repeat_all".split(" "))[0][-1]) toggle = (toggle + 1) % 2 utils.spawn_async_raise( ([XMMS2] + ("server config playlist.repeat_all %d" % toggle).split(" ")))
def play_song(info): song_id = info["id"] if song_id in get_playlist_songs(): _jump_and_play(song_id); return utils.spawn_async_raise((XMMS2, "add", "id:%d" % song_id)) # Ensure that the song is first added so we can jump to it afterwards. glib.timeout_add(100, _jump_and_play, song_id)
def enqueue_songs(info, clear_queue=False): songs = list(info) if not songs: return if clear_queue: utils.spawn_async_raise((XMMS2, "playlist", "clear")) for song in songs: song_id = song["id"] utils.spawn_async_raise((XMMS2, "add", "id:%s" % song_id))
def play_song(info): song_id = info["id"] if song_id in get_playlist_songs(): _jump_and_play(song_id) return utils.spawn_async_raise((XMMS2, "add", "id:%d" % song_id)) # Ensure that the song is first added so we can jump to it afterwards. glib.timeout_add(100, _jump_and_play, song_id)
def activate(self, leaf): clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) interface.copy_to_clipboard(leaf, clip) xte_paste_argv = ['xte', INIT_DELAY, 'keydown Control_L', 'key v', 'keyup Control_L'] try: utils.spawn_async_raise(xte_paste_argv) except utils.SpawnError as exc: raise OperationError(exc)
def activate(self, leaf): clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) interface.copy_to_clipboard(leaf, clip) xte_paste_argv = ['xte', INIT_DELAY, 'keydown Control_L', 'key v', 'keyup Control_L'] try: utils.spawn_async_raise(xte_paste_argv) except utils.SpawnError as exc: raise OperationError(exc)
def activate(self, leaf): text = interface.get_text_representation(leaf) xte_paste_argv = ['xte', 'usleep 300000'] # replace all newlines with 'key Return' for line in text.splitlines(True): xte_paste_argv.append("str " + line.rstrip("\r\n")) if line.endswith("\n"): xte_paste_argv.append("key Return") try: utils.spawn_async_raise(xte_paste_argv) except utils.SpawnError as exc: raise OperationError(exc)
def activate_multiple(self, objects): xte_sendkey_argv = ['xte', INIT_DELAY] iterobjects = iter(objects) for obj in iterobjects: xte_sendkey_argv.extend(self.make_keystr_arguments(obj.object)) break for obj in iterobjects: xte_sendkey_argv.append(INTER_DELAY) xte_sendkey_argv.extend(self.make_keystr_arguments(obj.object)) try: utils.spawn_async_raise(xte_sendkey_argv) except utils.SpawnError as exc: raise OperationError(exc)
def _jump_and_play(song_id): utils.spawn_async_raise((XMMS2, "jump", "id:%d" % song_id)) utils.spawn_async_raise((XMMS2, "play")) # must return False so it's not called again return False
def activate(self, leaf): text = leaf.object try: utils.spawn_async_raise(['devhelp', '--search=%s' % text]) except utils.SpawnError as exc: raise OperationError(exc)
def spawn_async(argv): try: utils.spawn_async_raise(argv) except utils.SpawnError as exc: raise OperationError(exc)
def run(self): utils.spawn_async_raise((XMMS2, "prev"))
def run(self): utils.spawn_async_raise((XMMS2, "next"))
def run(self): utils.spawn_async_raise((XMMS2, "playlist", "clear"))
def run(self): toggle = int( _cmd_output("server config playlist.repeat_all".split(" "))[0][-1]) toggle = (toggle + 1) % 2 utils.spawn_async_raise(([XMMS2] + ("server config playlist.repeat_all %d" % toggle).split(" ")))
def run(self): utils.spawn_async_raise(([XMMS2] + "playlist shuffle".split(" ")))
def spawn_operation_err(argv): try: utils.spawn_async_raise(argv) except SpawnError as exc: raise OperationError(exc.args[0].message)
def activate(self, leaf): try: args = ['hamster-time-tracker', self.cmd] utils.spawn_async_raise(args) except utils.SpawnError as exc: raise OperationError(exc)
def activate(self, leaf): try: utils.spawn_async_raise([TRACKER_GUI_SEARCH, leaf.object]) except utils.SpawnError as exc: raise OperationError(exc)