def OpenUri(uri): """Open a URI in an external (web) browser. The given argument has to be a properly formed URI including the scheme (fe. HTTP). As of now failures will be silently discarded.""" # Situation 1, user defined a way of handling the protocol protocol = uri[:uri.find(":")] if protocol in PROTOCOL_HANDLERS: if PROTOCOL_HANDLERS[protocol].__class__ is types.MethodType: PROTOCOL_HANDLERS[protocol](uri.strip()) return if PROTOCOL_HANDLERS[protocol]: executeCommand(PROTOCOL_HANDLERS[protocol], uri) return # Situation 2, user did not define a way of handling the protocol, we'll leave it up to python if webbrowser: webbrowser.open(uri) return # Situation 3, we let Gnome VFS deal with it try: import gnomevfs gnomevfs.url_show(uri) return except Exception, e: pass
def OnFileManager(self, widget): if self.selected_folder is None: return path = self.selected_folder.replace("\\", os.sep) executable = self.frame.np.config.sections["ui"]["filemanager"] if "$" in executable: executeCommand(executable, path)
def OpenUri(uri, window): """Open a URI in an external (web) browser. The given argument has to be a properly formed URI including the scheme (fe. HTTP). As of now failures will be silently discarded.""" # Situation 1, user defined a way of handling the protocol protocol = uri[:uri.find(":")] if protocol in PROTOCOL_HANDLERS: if isinstance(PROTOCOL_HANDLERS[protocol], types.MethodType): PROTOCOL_HANDLERS[protocol](uri.strip()) return if PROTOCOL_HANDLERS[protocol]: executeCommand(PROTOCOL_HANDLERS[protocol], uri) return # Situation 2, user did not define a way of handling the protocol if sys.platform == "win32" and webbrowser: webbrowser.open(uri) return try: gtk.show_uri_on_window(window, uri, Gdk.CURRENT_TIME) except AttributeError: screen = window.get_screen() gtk.show_uri(screen, uri, Gdk.CURRENT_TIME)
def OpenUri(uri): """Open a URI in an external (web) browser. The given argument has to be a properly formed URI including the scheme (fe. HTTP). As of now failures will be silently discarded.""" # Situation 1, user defined a way of handling the protocol protocol = uri[:uri.find(":")] if protocol in PROTOCOL_HANDLERS: if NICOTINE.browser is not None and NICOTINE.np.config.sections["ui"]["open_in_mozembed"] and protocol in ("http", 'https'): NICOTINE.browser.load_url(uri, 0) return if PROTOCOL_HANDLERS[protocol].__class__ is types.MethodType: PROTOCOL_HANDLERS[protocol](uri.strip()) return if PROTOCOL_HANDLERS[protocol]: executeCommand(PROTOCOL_HANDLERS[protocol], uri) return # Situation 2, user did not define a way of handling the protocol, we'll leave it up to python if webbrowser: webbrowser.open(uri) return # Situation 3a, we let Gnome (new way?) deal with it try: import gnomevfs gnomevfs.url_show(uri) return except Exception, e: pass
def _OnPlayFiles(self, widget, prefix=""): executable = self.frame.np.config.sections["players"]["default"] downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] if "$" not in executable: return for fn in self.selected_transfers: if fn.file is None: continue playfile = None if os.path.exists(fn.file.name): playfile = fn.file.name else: # If this file doesn't exist anymore, it may have finished downloading and have been renamed # try looking in the download directory and match the original filename. basename = string.split(fn.filename, '\\')[-1] path = os.sep.join([downloaddir, basename]) if os.path.exists(path): playfile = path if playfile: executeCommand(executable, playfile, background=False)
def _OnPlayFiles(self, widget, prefix=""): executable = self.frame.np.config.sections["players"]["default"] downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] if "$" not in executable: return for fn in self.selected_transfers: if fn.file is None: continue playfile = None if os.path.exists(fn.file.name): playfile = fn.file.name else: # If this file doesn't exist anymore, it may have finished downloading and have been renamed # try looking in the download directory and match the original filename. basename = string.split(fn.filename, '\\')[-1] path = os.sep.join([downloaddir, basename]) if os.path.exists(path): playfile = path if playfile: executeCommand(executable, playfile, background=False)
def _OnPlayFiles(self, widget, prefix=""): executable = self.frame.np.config.sections["players"]["default"] if "$" not in executable: return for fn in self.selected_transfers: file = fn.filename.replace("\\", os.sep) if os.path.exists(file): executeCommand(executable, file, background=False)
def _OnPlayFiles(self, widget, prefix=""): executable = self.frame.np.config.sections["players"]["default"] if "$" not in executable: return for fn in self.selected_transfers: file = fn.filename.replace("\\", os.sep) if os.path.exists(file): executeCommand(executable, file, background=False)
def _OnPlayFiles(self, widget, prefix = ""): path = self.DirStore.GetPathString(self.selected_folder).replace("\\", os.sep) executable = self.frame.np.config.sections["players"]["default"] if "$" not in executable: return for fn in self.selected_files: file = os.sep.join([path, fn]) if os.path.exists(file): executeCommand(executable, file, background=False)
def audacious_command(self, command, subcommand = ''): #output = commands.getoutput("audtool %s %s" % (command, subcommand)).split('\n')[0] try: output = executeCommand("audtool %s %s" % (command, subcommand), returnoutput=True).split('\n')[0] except RuntimeError: output = executeCommand("audtool2 %s %s" % (command, subcommand), returnoutput=True).split('\n')[0] if output.startswith('audtool'): output = None self.audacious_running = False return output
def OnFileManager(self, widget): if self.selected_folder is None: return path = self.frame.np.shares.virtual2real(self.selected_folder) executable = self.frame.np.config.sections["ui"]["filemanager"] if "$" in executable: executeCommand(executable, path)
def OnFileManager(self, widget): if self.selected_folder is None: return path = self.frame.np.shares.virtual2real(self.selected_folder) executable = self.frame.np.config.sections["ui"]["filemanager"] if "$" in executable: executeCommand(executable, path)
def _OnPlayFiles(self, widget, prefix=""): path = self.frame.np.shares.virtual2real(self.selected_folder) executable = self.frame.np.config.sections["players"]["default"] if "$" not in executable: return for fn in self.selected_files: file = os.sep.join([path, fn]) if os.path.exists(file): executeCommand(executable, file, background=False)
def _OnPlayFiles(self, widget, prefix=""): path = self.frame.np.shares.virtual2real(self.selected_folder) executable = self.frame.np.config.sections["players"]["default"] if "$" not in executable: return for fn in self.selected_files: file = os.sep.join([path, fn]) if os.path.exists(file): executeCommand(executable, file, background=False)
def audacious_command(self, command, subcommand=''): """ Wrapper that calls audacious commandline audtool and parse the output """ try: output = executeCommand("audtool %s %s" % (command, subcommand), returnoutput=True).split('\n')[0] except RuntimeError: output = executeCommand("audtool2 %s %s" % (command, subcommand), returnoutput=True).split('\n')[0] if output.startswith('audtool'): output = None self.audacious_running = False return output
def OnOpenDirectory(self, widget): downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] incompletedir = self.frame.np.config.sections["transfers"]["incompletedir"] if incompletedir == "": incompletedir = downloaddir filemanager = self.frame.np.config.sections["ui"]["filemanager"] transfer = self.selected_transfers[0] command = "" if os.path.exists(transfer.path): executeCommand(filemanager, transfer.path) else: executeCommand(filemanager, incompletedir)
def OnOpenDirectory(self, widget): downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] incompletedir = self.frame.np.config.sections["transfers"][ "incompletedir"] if incompletedir == "": incompletedir = downloaddir filemanager = self.frame.np.config.sections["ui"]["filemanager"] transfer = self.selected_transfers[0] command = "" if os.path.exists(transfer.path): executeCommand(filemanager, transfer.path) else: executeCommand(filemanager, incompletedir)
def audacious_command(self, command, subcommand=''): """ Wrapper that calls audacious commandline audtool and parse the output """ try: output = executeCommand("audtool %s %s" % (command, subcommand), returnoutput=True).decode().split('\n')[0] except RuntimeError: output = executeCommand("audtool2 %s %s" % (command, subcommand), returnoutput=True).decode().split('\n')[0] if output.startswith('audtool'): output = None self.audacious_running = False return output
def mpd_command(self, command): output = executeCommand("mpc --format $", command, returnoutput=True).split('\n')[0] if output == '' or output.startswith("MPD_HOST") or output.startswith("volume: "): return None return output
def exaile(self): slist = self.NPFormat.child.get_text() output = executeCommand('exaile --get-album --get-artist --get-length --get-title', returnoutput=True) output = output.split('\n') self.title["title"] = output[0] self.title["artist"] = output[1] self.title["album"] = output[2] self.title["length"] = output[3] return True
def mpd_command(self, command): output = executeCommand("mpc --format $", command, returnoutput=True).decode().split('\n')[0] if output == '' or output.startswith("MPD_HOST") or output.startswith( "volume: "): return None return output
def other(self): try: othercommand = self.NPCommand.get_text() if othercommand == "": return None output = executeCommand(othercommand, returnoutput=True) self.title["nowplaying"] = output return True except Exception, error: self.frame.logMessage(_("ERROR: Executing '%(command)s' failed: %(error)s") % {"command": othercommand, "error": error}) return None
def exaile(self): """ Function to get exaile currently playing song """ # At this time exail doesn't support mpris2: it will com with exaile 4 # So we use the command line to query it output = executeCommand('exaile --get-album --get-artist --get-length --get-title', returnoutput=True) output = output.split('\n') self.title["title"] = output[0] self.title["artist"] = output[1] self.title["album"] = output[2] self.title["length"] = self.get_length_time(float(output[3])) if self.title['artist'] != "": self.title['nowplaying'] += self.title['artist'] if self.title['title'] != "": self.title['nowplaying'] += " - " + self.title['title'] return True
def OnOpenDirectory(self, widget): downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] incompletedir = self.frame.np.config.sections["transfers"]["incompletedir"] if incompletedir == "": incompletedir = downloaddir filemanager = self.frame.np.config.sections["ui"]["filemanager"] transfer = self.selected_transfers[0] complete_path = os.path.join(downloaddir, transfer.path) if transfer.path is "": if transfer.status is "Finished": executeCommand(filemanager, downloaddir) else: executeCommand(filemanager, incompletedir) elif os.path.exists(complete_path): # and tranfer.status is "Finished" executeCommand(filemanager, complete_path) else: executeCommand(filemanager, incompletedir)
def OnOpenDirectory(self, widget): downloaddir = self.frame.np.config.sections["transfers"]["downloaddir"] incompletedir = self.frame.np.config.sections["transfers"]["incompletedir"] if incompletedir == "": incompletedir = downloaddir filemanager = self.frame.np.config.sections["ui"]["filemanager"] transfer = next(iter(self.selected_transfers)) complete_path = os.path.join(downloaddir, transfer.path) if transfer.path == "": if transfer.status == "Finished": executeCommand(filemanager, downloaddir) else: executeCommand(filemanager, incompletedir) elif os.path.exists(complete_path): # and tranfer.status is "Finished" executeCommand(filemanager, complete_path) else: executeCommand(filemanager, incompletedir)
def exaile(self): """ Function to get exaile currently playing song """ # At this time exail doesn't support mpris2: it will com with exaile 4 # So we use the command line to query it output = executeCommand( 'exaile --get-album --get-artist --get-length --get-title', returnoutput=True) output = output.split('\n') self.title["title"] = output[0] self.title["artist"] = output[1] self.title["album"] = output[2] self.title["length"] = self.get_length_time(float(output[3])) if self.title['artist'] != "": self.title['nowplaying'] += self.title['artist'] if self.title['title'] != "": self.title['nowplaying'] += " - " + self.title['title'] return True
def banshee_command(self, commands): """ Wrapper that calls banshee commandline """ return executeCommand(" ".join(["banshee"] + commands), returnoutput=True)
def banshee_command(self, commands): """ Wrapper that calls banshee commandline """ return executeCommand(" ".join(["banshee"] + commands), returnoutput=True)
def tts_player(self, message): self.tts_playing = True executeCommand(self.frame.np.config.sections["ui"]["speechcommand"], message)
def amarok_command(self, command): output = executeCommand("dcop amarok player $", command, returnoutput=True).split('\n')[0] if output == 'call failed': output = None return output
def banshee_command(self, commands): return executeCommand(" ".join(["banshee"] + commands), returnoutput=True)