00001 #!/usr/bin/env python 00002 # -*- coding: utf-8 -*- 00003 00004 # ---------------------------------------------------------------------------- 00005 # pyjama - python jamendo audioplayer 00006 # Copyright (c) 2008 Daniel Nögel 00007 # 00008 # This program is free software: you can redistribute it and/or modify 00009 # it under the terms of the GNU General Public License as published by 00010 # the Free Software Foundation, either version 3 of the License, or 00011 # (at your option) any later version. 00012 # 00013 # This program is distributed in the hope that it will be useful, 00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 # GNU General Public License for more details. 00017 # You should have received a copy of the GNU General Public License 00018 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 # ---------------------------------------------------------------------------- 00020 00021 ## @package clBrowserInterface 00022 # Manages pyjama's browser interface 00023 00024 # 00025 # You are probably looking for the integrated webbrowser or PMC 00026 # have a look at mozplug-plugin in the first case or pmc in 00027 # the second one! 00028 # This file only manages urls and opens them in your default 00029 # browser or mozplug 00030 # 00031 00032 import webbrowser 00033 00034 ## Browser Interface class 00035 class Browser(): 00036 ## Constructor 00037 # @param self Object Pointer 00038 # @param pyjama Pyjama Reference 00039 def __init__(self, pyjama): 00040 ## Pyjama Reference 00041 self.pyjama = pyjama 00042 self.pyjama.Events.add_event("open_url") 00043 self.pyjama.Events.connect_event("open_url", self.ev_open_url) 00044 ## The current Browser to be used 00045 self.browser = self.webbrowser # user's default browser 00046 00047 ## Set a new browser 00048 # @param self Object Pointer 00049 # @param function_to_call Function to when a browser is opend 00050 def set_browser(self, function_to_call): 00051 self.browser = function_to_call 00052 00053 ## Set the browser to be used to default 00054 # @param self Object Pointer 00055 def set_default_browser(self): 00056 self.browser = self.webbrowser 00057 00058 ## called when then "open_url" event is raised 00059 # @param self Object Pointer 00060 # @param url The url that has been passed to the "open_url" event 00061 # @param force_default When set to True, the url is opened in the default browser 00062 # default value is False 00063 def ev_open_url(self, url, force_default=False): 00064 if force_default: 00065 self.webbrowser(url) 00066 else: 00067 self.browser(url) 00068 00069 ################################################################### 00070 # 00071 # Open a given URL in the standard webbrowser 00072 # RETURNS: ? 00073 # 00074 ## The default webbrowser 00075 # @param self Object Pointer 00076 # @param url The URL to open 00077 def webbrowser(self, url): 00078 return webbrowser.open_new_tab(url) # mod_webbrowser is the module webbrowser // some naming issues :)
1.5.8