Denilson Sá avatar Denilson Sá committed d389619

Changed tabs to spaces.

Comments (0)

Files changed (1)

 
 try:
 
-	import pygtk
-	pygtk.require('2.0')
-	import gtk
+    import pygtk
+    pygtk.require('2.0')
+    import gtk
 
 except ImportError, e:
-	# It is possible that the ImportError has happened because of
-	# LD_LIBRARY_PATH environment variable. So, if this variable is set, it
-	# will be stripped and this script will try to call itself (yep! recursive!).
-	# However, if this doesn't help, the ImportError exception will just be
-	# raised again.
-	if os.environ.has_key("LD_LIBRARY_PATH") and os.environ["LD_LIBRARY_PATH"].strip():
-		newenv = dict(os.environ)
+    # It is possible that the ImportError has happened because of
+    # LD_LIBRARY_PATH environment variable. So, if this variable is set, it
+    # will be stripped and this script will try to call itself (yep! recursive!).
+    # However, if this doesn't help, the ImportError exception will just be
+    # raised again.
+    if os.environ.has_key("LD_LIBRARY_PATH") and os.environ["LD_LIBRARY_PATH"].strip():
+        newenv = dict(os.environ)
         newenv.pop("LD_LIBRARY_PATH")
-		# The OSError exception is not useful here. Let's ignore it.
-		try:
-			os.execvpe(sys.argv[0], sys.argv, newenv)
-		except OSError:
-			pass
-	raise e
+        # The OSError exception is not useful here. Let's ignore it.
+        try:
+            os.execvpe(sys.argv[0], sys.argv, newenv)
+        except OSError:
+            pass
+    raise e
 
 
 
 class program(object):
-	name     = "Browser Selector"
-	version  = "0.3"
-	date     = "2009-08-12"
-	author   = u"Denilson Figueiredo de Sá"
-	email    = "denilsonsa@gmail.com"
-	urls     = (
-		"http://bitbucket.org/denilsonsa/browser-selector/",
+    name     = "Browser Selector"
+    version  = "0.3"
+    date     = "2009-08-12"
+    author   = u"Denilson Figueiredo de Sá"
+    email    = "denilsonsa@gmail.com"
+    urls     = (
+        "http://bitbucket.org/denilsonsa/browser-selector/",
         "http://my.opera.com/CrazyTerabyte/",
-		"http://denilsonsa.selfip.org/~denilson/",
+        "http://denilsonsa.selfip.org/~denilson/",
     )
-	exe_file = "browser-selector"
-	conf_dir = "~/.config/browser-selector"
-	last_selected_file = "last_selected"
-	conf_file          = "conf.xml"
-	sample_conf_file   = """<?xml version="1.0" standalone="yes"?>
+    exe_file = "browser-selector"
+    conf_dir = "~/.config/browser-selector"
+    last_selected_file = "last_selected"
+    conf_file          = "conf.xml"
+    sample_conf_file   = """<?xml version="1.0" standalone="yes"?>
 <browserselector>
-	<browsers>
-		<browser
-			name="Mozilla Firefox"
-			cmd="firefox"
-			icon="/usr/share/pixmaps/firefox-icon.png"
-		/>
-		<browser
-			name="Konqueror"
-			cmd="konqueror"
-		/>
-		<browser
-			name="Opera"
-			cmd="opera"
-			icon="/usr/share/pixmaps/opera.xpm"
-		/>
-		<browser
-			name="Links (graphic)"
-			cmd="links -g"
-			icon="/usr/share/pixmaps/links.xpm"
-		/>
-		<browser
-			name="Dillo"
-			cmd="dillo"
-		/>
-	</browsers>
-	<config>
-		<option name="show_tooltips" value="true" />
-		<option name="show_images" value="true" />
-		<option name="save_last_selection" value="true" />
-	</config>
+    <browsers>
+        <browser
+            name="Mozilla Firefox"
+            cmd="firefox"
+            icon="/usr/share/pixmaps/firefox-icon.png"
+        />
+        <browser
+            name="Konqueror"
+            cmd="konqueror"
+        />
+        <browser
+            name="Opera"
+            cmd="opera"
+            icon="/usr/share/pixmaps/opera.xpm"
+        />
+        <browser
+            name="Links (graphic)"
+            cmd="links -g"
+            icon="/usr/share/pixmaps/links.xpm"
+        />
+        <browser
+            name="Dillo"
+            cmd="dillo"
+        />
+    </browsers>
+    <config>
+        <option name="show_tooltips" value="true" />
+        <option name="show_images" value="true" />
+        <option name="save_last_selection" value="true" />
+    </config>
 </browserselector>
 """
 
 
 
 class Browser(object):
-	"Simple object (or maybe just a struct) containing the browser data."
-	def __init__(self,name,cmd,icon=""):
-		self.name = name
-		self.cmd  = cmd
-		self.icon = icon
+    "Simple object (or maybe just a struct) containing the browser data."
+    def __init__(self,name,cmd,icon=""):
+        self.name = name
+        self.cmd  = cmd
+        self.icon = icon
 
 
-	def __repr__(self):
-		return "Browser(name=%s, cmd=%s, icon=%s)" % (repr(self.name), repr(self.cmd), repr(self.icon))
+    def __repr__(self):
+        return "Browser(name=%s, cmd=%s, icon=%s)" % (repr(self.name), repr(self.cmd), repr(self.icon))
 
 
-	def __str__(self):
-		return "Browser(%s)" % str(self.name)
+    def __str__(self):
+        return "Browser(%s)" % str(self.name)
 
 
 
 class config_object(object):
-	def __init__(self):
-		"Loads the configuration file(s). Extracted data can be accessed using attributes of this object."
-		# Defaults:
-		self.browsers = []
-		self.show_tooltips = True
-		self.show_images = True
-		self.save_last_selection = True
-		self.last_selected = 0
+    def __init__(self):
+        "Loads the configuration file(s). Extracted data can be accessed using attributes of this object."
+        # Defaults:
+        self.browsers = []
+        self.show_tooltips = True
+        self.show_images = True
+        self.save_last_selection = True
+        self.last_selected = 0
 
-		doc = xml.dom.minidom.parse(program.conf_file)
+        doc = xml.dom.minidom.parse(program.conf_file)
 
-		browsers_el = doc.getElementsByTagName("browsers")
-		if len(browsers_el) == 1:
-			browsers_el = browsers_el[0]
-			for i in browsers_el.getElementsByTagName("browser"):
-				self.browsers.append( Browser(
-					i.getAttribute("name"),
-					i.getAttribute("cmd"),
-					i.getAttribute("icon")
-				) )
-		elif len(browsers_el) != 1:
-			raise Exception("Invalid XML configuration file! Exactly one <browsers> element is required.")
+        browsers_el = doc.getElementsByTagName("browsers")
+        if len(browsers_el) == 1:
+            browsers_el = browsers_el[0]
+            for i in browsers_el.getElementsByTagName("browser"):
+                self.browsers.append( Browser(
+                    i.getAttribute("name"),
+                    i.getAttribute("cmd"),
+                    i.getAttribute("icon")
+                ) )
+        elif len(browsers_el) != 1:
+            raise Exception("Invalid XML configuration file! Exactly one <browsers> element is required.")
 
-		config_el = doc.getElementsByTagName("config")
-		if len(config_el) == 1:
-			config_el = config_el[0]
-			for i in config_el.getElementsByTagName("option"):
-				try:
-					name  = i.getAttribute("name").lower()
-					value = i.getAttribute("value")
-                    
-					if name == "show_tooltips":
-						self.show_tooltips = self.parse_boolean(value)
-					elif name == "show_images":
-						self.show_images = self.parse_boolean(value)
-					elif name == "save_last_selection":
-						self.save_last_selection = self.parse_boolean(value)
-				except ValueError, e:
-					raise ValueError("Invalid value while parsing '%s' option: %s" % (name, str(e)))
-		elif len(config_el) > 1:
-			raise Exception("Invalid XML configuration file! Only one <config> element is allowed.")
+        config_el = doc.getElementsByTagName("config")
+        if len(config_el) == 1:
+            config_el = config_el[0]
+            for i in config_el.getElementsByTagName("option"):
+                try:
+                    name  = i.getAttribute("name").lower()
+                    value = i.getAttribute("value")
 
-		doc.unlink()
+                    if name == "show_tooltips":
+                        self.show_tooltips = self.parse_boolean(value)
+                    elif name == "show_images":
+                        self.show_images = self.parse_boolean(value)
+                    elif name == "save_last_selection":
+                        self.save_last_selection = self.parse_boolean(value)
+                except ValueError, e:
+                    raise ValueError("Invalid value while parsing '%s' option: %s" % (name, str(e)))
+        elif len(config_el) > 1:
+            raise Exception("Invalid XML configuration file! Only one <config> element is allowed.")
 
-		# I think there must be some more elegant way of doing this.
-		# I don't think this is written in a pythonic way. If you have
-		# any better idea, please contact me!
-		f = None
-		try:
-			f = open(program.last_selected_file)
-			self.last_selected = int(f.read(9))
-		except Exception, e:
-			pass
-		if f:
-			f.close()
+        doc.unlink()
 
+        # I think there must be some more elegant way of doing this.
+        # I don't think this is written in a pythonic way. If you have
+        # any better idea, please contact me!
+        f = None
+        try:
+            f = open(program.last_selected_file)
+            self.last_selected = int(f.read(9))
+        except Exception, e:
+            pass
+        if f:
+            f.close()
 
-	def parse_boolean(self, value):
-		"""Extract and return the boolean value (True or False) corresponding to the passed string. This is done by comparing the value with a list of known strings.	The comparison is case-insensitive.
 
-		If 'value' contains one unrecognized string, then a ValueError exception is raised."""
-		value = value.lower()
-		if   value in ("true" ,"1","one" ,"yes","yep" ,"yeah"  ):
-			return True
-		elif value in ("false","0","zero","no" ,"nope","no way"):
-			return False
-		else:
-			raise ValueError("'%s' is not a boolean." % value)
+    def parse_boolean(self, value):
+        """Extract and return the boolean value (True or False) corresponding to the passed string. This is done by comparing the value with a list of known strings.   The comparison is case-insensitive.
+
+        If 'value' contains one unrecognized string, then a ValueError exception is raised."""
+        value = value.lower()
+        if   value in ("true" ,"1","one" ,"yes","yep" ,"yeah"  ):
+            return True
+        elif value in ("false","0","zero","no" ,"nope","no way"):
+            return False
+        else:
+            raise ValueError("'%s' is not a boolean." % value)
 
 
 
 class browser_select_window(object):
-	def __init__(self, url=""):
-		self.window = gtk.Window()
-		self.window.set_title(program.name+" "+program.version)
-		self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
-		self.window.set_border_width(12)
-		self.window.connect("delete_event", self.delete_event)
+    def __init__(self, url=""):
+        self.window = gtk.Window()
+        self.window.set_title(program.name+" "+program.version)
+        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+        self.window.set_border_width(12)
+        self.window.connect("delete_event", self.delete_event)
 
-		self.url = gtk.Entry()
-		self.url.set_activates_default(True)
-		self.url.set_text(url)
+        self.url = gtk.Entry()
+        self.url.set_activates_default(True)
+        self.url.set_text(url)
 
-		self.radio_selected = 0
-		self.radio_box = self.create_radio_buttons()
+        self.radio_selected = 0
+        self.radio_box = self.create_radio_buttons()
 
-		self.execute_button = gtk.Button(stock=gtk.STOCK_EXECUTE)
-		self.execute_button.connect("clicked", self.execute_clicked)
+        self.execute_button = gtk.Button(stock=gtk.STOCK_EXECUTE)
+        self.execute_button.connect("clicked", self.execute_clicked)
 
-		self.close_button = gtk.Button(stock=gtk.STOCK_CLOSE)
-		self.close_button.connect_object("clicked", self.delete_event, self.window, None)
+        self.close_button = gtk.Button(stock=gtk.STOCK_CLOSE)
+        self.close_button.connect_object("clicked", self.delete_event, self.window, None)
 
-		self.buttons_box = gtk.HButtonBox()
-		self.buttons_box.set_layout(gtk.BUTTONBOX_END)
-		self.buttons_box.add(self.execute_button)
-		self.buttons_box.add(self.close_button)
+        self.buttons_box = gtk.HButtonBox()
+        self.buttons_box.set_layout(gtk.BUTTONBOX_END)
+        self.buttons_box.add(self.execute_button)
+        self.buttons_box.add(self.close_button)
 
-		self.main_vbox = gtk.VBox(False,10)
-		self.main_vbox.pack_start(self.url, True, True, 0)
-		self.main_vbox.pack_start(self.radio_box, True, False, 0)
-		self.main_vbox.pack_start(self.buttons_box, False, True, 0)
-		self.window.add(self.main_vbox)
-		self.window.show_all()
+        self.main_vbox = gtk.VBox(False,10)
+        self.main_vbox.pack_start(self.url, True, True, 0)
+        self.main_vbox.pack_start(self.radio_box, True, False, 0)
+        self.main_vbox.pack_start(self.buttons_box, False, True, 0)
+        self.window.add(self.main_vbox)
+        self.window.show_all()
 
-		self.execute_button.set_flags(gtk.CAN_DEFAULT)
-		self.execute_button.grab_default()
-	
+        self.execute_button.set_flags(gtk.CAN_DEFAULT)
+        self.execute_button.grab_default()
+    
 
-	def create_radio_buttons(self):
-		"Reads the list of browsers and returns a VBox containing a radio button for each browser. Also adds tooltips and images to each radio button."
-		box = gtk.VBox(True,0)
-		if program.config.show_tooltips:
-			tooltips = gtk.Tooltips()
-			tooltips.enable()
-		radio = None
-		for (number, i) in enumerate(program.config.browsers):
-			radio = gtk.RadioButton(radio, i.name, True)
-			radio.connect("toggled", self.radio_button_toggled, number)
+    def create_radio_buttons(self):
+        "Reads the list of browsers and returns a VBox containing a radio button for each browser. Also adds tooltips and images to each radio button."
+        box = gtk.VBox(True,0)
+        if program.config.show_tooltips:
+            tooltips = gtk.Tooltips()
+            tooltips.enable()
+        radio = None
+        for (number, i) in enumerate(program.config.browsers):
+            radio = gtk.RadioButton(radio, i.name, True)
+            radio.connect("toggled", self.radio_button_toggled, number)
 
-			if number == program.config.last_selected:
-				radio.set_active(True)
-				# The next line is not actually needed, because previous line
-				# call will run the callback.
-				self.radio_selected = number
+            if number == program.config.last_selected:
+                radio.set_active(True)
+                # The next line is not actually needed, because previous line
+                # call will run the callback.
+                self.radio_selected = number
 
 
-			if program.config.show_tooltips:
-				tooltips.set_tip(radio, i.cmd)
+            if program.config.show_tooltips:
+                tooltips.set_tip(radio, i.cmd)
 
-			if program.config.show_images and os.path.isfile(i.icon):
-				image = gtk.Image()
-				# set_from_file() method never returns None. In case the file
-				# cannot be found or cannot be loaded, a "broken image" icon
-				# will be returned.
-				image.set_from_file(i.icon)
-				radio.set_image(image)
+            if program.config.show_images and os.path.isfile(i.icon):
+                image = gtk.Image()
+                # set_from_file() method never returns None. In case the file
+                # cannot be found or cannot be loaded, a "broken image" icon
+                # will be returned.
+                image.set_from_file(i.icon)
+                radio.set_image(image)
 
-			# The following two lines are required to make tooltips be
-			# displayed. It's stupid, but it's true. Maybe this will get
-			# better in GTK+ 2.12.
-			eb = gtk.EventBox()
-			eb.add(radio)
+            # The following two lines are required to make tooltips be
+            # displayed. It's stupid, but it's true. Maybe this will get
+            # better in GTK+ 2.12.
+            eb = gtk.EventBox()
+            eb.add(radio)
 
-			box.pack_start(eb, False, True, 0)
+            box.pack_start(eb, False, True, 0)
 
-		return box
-	
+        return box
+    
 
-	def execute_clicked(self, widget):
-		main.execute_browser(self.radio_selected, self.url.get_text())
+    def execute_clicked(self, widget):
+        main.execute_browser(self.radio_selected, self.url.get_text())
 
 
-	def radio_button_toggled(self, widget, number):
-		if widget.get_active():
-			self.radio_selected = number
+    def radio_button_toggled(self, widget, number):
+        if widget.get_active():
+            self.radio_selected = number
 
 
-	def delete_event(self, widget, event, data=None):
-		main.close_app()
-		return False
+    def delete_event(self, widget, event, data=None):
+        main.close_app()
+        return False
 
 
 
 class browser_selector(object):
-	def __init__(self):
-		"Main initializations."
-		program.conf_dir = os.path.expanduser(program.conf_dir)
-		program.conf_file = program.conf_dir + os.path.sep + program.conf_file
-		program.last_selected_file = program.conf_dir + os.path.sep + program.last_selected_file
+    def __init__(self):
+        "Main initializations."
+        program.conf_dir = os.path.expanduser(program.conf_dir)
+        program.conf_file = program.conf_dir + os.path.sep + program.conf_file
+        program.last_selected_file = program.conf_dir + os.path.sep + program.last_selected_file
 
 
-	def run(self):
-		"Main program."
-		if not os.path.isfile(program.conf_file):
-			if self.ask_to_create_conf_file():
-				self.create_conf_file()
-			else:
-				self.close_app(1)
-		program.config = config_object()
-		if len(sys.argv) == 2:
-			self.browser_select = browser_select_window(url=sys.argv[1])
-			self.browser_select.window.show()
-			gtk.main()
-			#self.browser_select.window.destroy()
-		else:
-			self.show_info_dialog()
+    def run(self):
+        "Main program."
+        if not os.path.isfile(program.conf_file):
+            if self.ask_to_create_conf_file():
+                self.create_conf_file()
+            else:
+                self.close_app(1)
+        program.config = config_object()
+        if len(sys.argv) == 2:
+            self.browser_select = browser_select_window(url=sys.argv[1])
+            self.browser_select.window.show()
+            gtk.main()
+            #self.browser_select.window.destroy()
+        else:
+            self.show_info_dialog()
 
 
-	def ask_to_create_conf_file(self):
-		"Opens a dialog asking the user if he/she wants to create a default configuration file. Returns True or False, depending on user choice."
-		dialog = gtk.MessageDialog(
-			parent         = None,
-			flags          = gtk.DIALOG_MODAL,
-			type           = gtk.MESSAGE_QUESTION,
-			buttons        = gtk.BUTTONS_YES_NO,
-			message_format = "Should a default configuration file be created?"
-		)
-		dialog.set_title(program.name+" "+program.version)
-		dialog.props.skip_taskbar_hint = False
-		dialog.format_secondary_markup(
-			('%s requires a configuration file before it can be used. Should it create a default configuration file now?\n\n'+
-			'If you answer yes, the file will be written to "%s".\n'+
-			'If you answer no, %s will quit.') % (program.name, program.conf_file, program.name)
-		)
-		dialog.set_default_response(gtk.RESPONSE_YES)
-		ret = dialog.run()
-		dialog.destroy()
-		# To discover the numerical values of each response:
-		# print gtk.ResponseType.__enum_values__
-		if ret == gtk.RESPONSE_YES:
-			return True
-		elif ret == gtk.RESPONSE_NO or ret == gtk.RESPONSE_DELETE_EVENT:
-			return False
-		else:
-			print "Received unknown response value: ",ret
-			return False
+    def ask_to_create_conf_file(self):
+        "Opens a dialog asking the user if he/she wants to create a default configuration file. Returns True or False, depending on user choice."
+        dialog = gtk.MessageDialog(
+            parent         = None,
+            flags          = gtk.DIALOG_MODAL,
+            type           = gtk.MESSAGE_QUESTION,
+            buttons        = gtk.BUTTONS_YES_NO,
+            message_format = "Should a default configuration file be created?"
+        )
+        dialog.set_title(program.name+" "+program.version)
+        dialog.props.skip_taskbar_hint = False
+        dialog.format_secondary_markup(
+            ('%s requires a configuration file before it can be used. Should it create a default configuration file now?\n\n'+
+            'If you answer yes, the file will be written to "%s".\n'+
+            'If you answer no, %s will quit.') % (program.name, program.conf_file, program.name)
+        )
+        dialog.set_default_response(gtk.RESPONSE_YES)
+        ret = dialog.run()
+        dialog.destroy()
+        # To discover the numerical values of each response:
+        # print gtk.ResponseType.__enum_values__
+        if ret == gtk.RESPONSE_YES:
+            return True
+        elif ret == gtk.RESPONSE_NO or ret == gtk.RESPONSE_DELETE_EVENT:
+            return False
+        else:
+            print "Received unknown response value: ",ret
+            return False
 
 
-	def show_info_dialog(self):
-		"Opens an info dialog containing a brief explanation about program usage and author name, e-mail and site."
-		dialog = gtk.MessageDialog(
-			parent         = None,
-			flags          = gtk.DIALOG_MODAL,
-			type           = gtk.MESSAGE_INFO,
-			buttons        = gtk.BUTTONS_OK
-		)
-		dialog.set_markup(
-			"<big><b>%s %s (%s)</b></big>\n" % (program.name, program.version, program.date) +
-			"\n"+
-			"<b>Usage:</b>\n"+
-			"<tt>%s <i>URL</i></tt>\n" % program.exe_file +
-			"\n"+
-			"%s is a program that receives one URL as parameter and allows the user to choose what program should open that URL. It is intended to be used as a default URL handler.\n" % program.name +
-			"\n"+
-			"Add this line to your login script to make %s your default URL handler:\n" % program.name +
-			"<tt>export BROWSER=%s</tt>\n" % program.exe_file +
-			"\n"+
-			"This program stores its configuration files at <tt>%s</tt>\n" % program.conf_dir +
-			"\n"+
-			"<b>Author:</b>\n%s\n%s\n" % (program.author, program.email) +
-			"\n".join(program.urls)
-		)
-		dialog.set_title(program.name+" "+program.version)
-		dialog.props.skip_taskbar_hint = False
-		dialog.set_default_response(gtk.RESPONSE_OK)
-		dialog.run()
-		dialog.destroy()
+    def show_info_dialog(self):
+        "Opens an info dialog containing a brief explanation about program usage and author name, e-mail and site."
+        dialog = gtk.MessageDialog(
+            parent         = None,
+            flags          = gtk.DIALOG_MODAL,
+            type           = gtk.MESSAGE_INFO,
+            buttons        = gtk.BUTTONS_OK
+        )
+        dialog.set_markup(
+            "<big><b>%s %s (%s)</b></big>\n" % (program.name, program.version, program.date) +
+            "\n"+
+            "<b>Usage:</b>\n"+
+            "<tt>%s <i>URL</i></tt>\n" % program.exe_file +
+            "\n"+
+            "%s is a program that receives one URL as parameter and allows the user to choose what program should open that URL. It is intended to be used as a default URL handler.\n" % program.name +
+            "\n"+
+            "Add this line to your login script to make %s your default URL handler:\n" % program.name +
+            "<tt>export BROWSER=%s</tt>\n" % program.exe_file +
+            "\n"+
+            "This program stores its configuration files at <tt>%s</tt>\n" % program.conf_dir +
+            "\n"+
+            "<b>Author:</b>\n%s\n%s\n" % (program.author, program.email) +
+            "\n".join(program.urls)
+        )
+        dialog.set_title(program.name+" "+program.version)
+        dialog.props.skip_taskbar_hint = False
+        dialog.set_default_response(gtk.RESPONSE_OK)
+        dialog.run()
+        dialog.destroy()
 
 
-	def create_conf_file(self):
-		"Creates the configuration directory and the default configuration file."
-		if not os.path.exists(program.conf_dir):
-			os.makedirs(program.conf_dir)
-		f = open(program.conf_file,"w")
-		f.write(program.sample_conf_file)
-		f.close()
+    def create_conf_file(self):
+        "Creates the configuration directory and the default configuration file."
+        if not os.path.exists(program.conf_dir):
+            os.makedirs(program.conf_dir)
+        f = open(program.conf_file,"w")
+        f.write(program.sample_conf_file)
+        f.close()
 
 
-	def execute_browser(self, index, url):
-		b = program.config.browsers[index]
-		try:
-			c = shlex.split(str(b.cmd))
-			for i,s in enumerate(c):
-				if "%s" in s:
-					c[i] = s.replace("%s", url)
-					break
-			else:
-				c.append(str(url))
-			p = subprocess.Popen(c)
-		except OSError, e:
-			dialog = gtk.MessageDialog(
-				parent         = self.browser_select.window,
-				flags          = gtk.DIALOG_MODAL,
-				type           = gtk.MESSAGE_ERROR,
-				buttons        = gtk.BUTTONS_OK,
-				message_format = "Error while trying to execute the selected application:\n%s" % str(e)
-			)
-			dialog.set_title(program.name+" "+program.version)
-			dialog.set_default_response(gtk.RESPONSE_OK)
-			dialog.run()
-			dialog.destroy()
-		else:
-			self.save_last_selection(index)
-			self.close_app(0)
+    def execute_browser(self, index, url):
+        b = program.config.browsers[index]
+        try:
+            c = shlex.split(str(b.cmd))
+            for i,s in enumerate(c):
+                if "%s" in s:
+                    c[i] = s.replace("%s", url)
+                    break
+            else:
+                c.append(str(url))
+            p = subprocess.Popen(c)
+        except OSError, e:
+            dialog = gtk.MessageDialog(
+                parent         = self.browser_select.window,
+                flags          = gtk.DIALOG_MODAL,
+                type           = gtk.MESSAGE_ERROR,
+                buttons        = gtk.BUTTONS_OK,
+                message_format = "Error while trying to execute the selected application:\n%s" % str(e)
+            )
+            dialog.set_title(program.name+" "+program.version)
+            dialog.set_default_response(gtk.RESPONSE_OK)
+            dialog.run()
+            dialog.destroy()
+        else:
+            self.save_last_selection(index)
+            self.close_app(0)
 
 
-	def save_last_selection(self, index):
-		if program.config.save_last_selection:
-			try:
-				f = open(program.last_selected_file,"w")
-				f.write(str(index))
-				f.close()
-			except:
-				pass
+    def save_last_selection(self, index):
+        if program.config.save_last_selection:
+            try:
+                f = open(program.last_selected_file,"w")
+                f.write(str(index))
+                f.close()
+            except:
+                pass
 
 
-	def close_app(self, status=0):
-		"Quits the application, by first ending GTK+ main loop, and then calling sys.exit()."
-		try:
-			gtk.main_quit()   # In case this is called outside of a mainloop
-		except RuntimeError:  # Then I will just ignore that.
-			pass
-		sys.exit(status)
+    def close_app(self, status=0):
+        "Quits the application, by first ending GTK+ main loop, and then calling sys.exit()."
+        try:
+            gtk.main_quit()   # In case this is called outside of a mainloop
+        except RuntimeError:  # Then I will just ignore that.
+            pass
+        sys.exit(status)
 
 
 
 if __name__ == "__main__":
-	main = browser_selector()
-	main.run()
+    main = browser_selector()
+    main.run()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.