[kupfer: 14/67] Add Terminal configuration to Preferences



commit fccbafbf723395931dca408ba29170ac383d79ee
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Mar 15 22:52:28 2011 +0100

    Add Terminal configuration to Preferences

 data/preferences.ui      |   32 ++++++++++++++++++++++++++++++++
 kupfer/core/settings.py  |    2 +-
 kupfer/terminal.py       |   13 ++++++++++++-
 kupfer/ui/preferences.py |   27 +++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index f5e0f01..0314343 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -125,6 +125,37 @@
                             <property name="position">1</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkFrame" id="frame3">
+                            <property name="visible">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkAlignment" id="alignment5">
+                                <property name="visible">True</property>
+                                <property name="top_padding">6</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkComboBox" id="terminal_combobox">
+                                    <property name="visible">True</property>
+                                    <signal name="changed" handler="on_terminal_combobox_changed"/>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label11">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Terminal&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -619,4 +650,5 @@ An unticked source's contents are only available by locating its subcatalog and
       </object>
     </child>
   </object>
+  <object class="GtkListStore" id="liststore1"/>
 </interface>
diff --git a/kupfer/core/settings.py b/kupfer/core/settings.py
index 6c58cad..0acd39c 100644
--- a/kupfer/core/settings.py
+++ b/kupfer/core/settings.py
@@ -383,7 +383,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		return self.get_config("Tools", tool_id)
 
 	def set_preferred_tool(self, tool_id, value):
-		return self._set_config("Tools", tool_id, key)
+		return self._set_config("Tools", tool_id, value)
 
 
 # Section, Key, Value
diff --git a/kupfer/terminal.py b/kupfer/terminal.py
index 8c610db..0727932 100644
--- a/kupfer/terminal.py
+++ b/kupfer/terminal.py
@@ -1,3 +1,4 @@
+import os
 
 _TERMINALS = []
 
@@ -24,12 +25,22 @@ def register_terminal(terminal_description):
 def unregister_terminal(terminal_id):
 	_TERMINALS[:] = [t for t in _TERMINALS if t.app_id != terminal_id]
 
+def get_valid_terminals():
+	for term in _TERMINALS:
+		# iterate over $PATH directories
+		PATH = os.environ.get("PATH") or os.defpath
+		for execdir in PATH.split(os.pathsep):
+			exepath = os.path.join(execdir, term.argv[0])
+			if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath):
+				yield term
+				break
+
 def get_configured_terminal():
 	"""
 	Return the configured Terminal object
 	"""
 	from kupfer.core import settings
-	setctl = settings.SettingsController()
+	setctl = settings.GetSettingsController()
 	id_ = setctl.get_preferred_tool('terminal')
 	for term in _TERMINALS:
 		if term.app_id == id_:
diff --git a/kupfer/ui/preferences.py b/kupfer/ui/preferences.py
index 246f41c..bd4b244 100644
--- a/kupfer/ui/preferences.py
+++ b/kupfer/ui/preferences.py
@@ -17,6 +17,7 @@ from kupfer.ui import keybindings
 from kupfer.ui.credentials_dialog import ask_user_credentials
 from kupfer.ui import getkey_dialog
 from kupfer import plugin_support
+from kupfer import terminal
 
 # index in GtkNotebook
 PLUGIN_LIST_PAGE = 2
@@ -119,6 +120,26 @@ class PreferencesWindowController (pretty.OutputMixin):
 		checkusecommandkeys.set_active(setctl.get_use_command_keys())
 		checkcloseonunfocus.set_active(setctl.get_close_on_unfocus())
 
+		# List store with columns (Name, ID) 
+		terminal_combobox = builder.get_object("terminal_combobox")
+		terminal_combobox_store = gtk.ListStore(gobject.TYPE_STRING,
+		                                        gobject.TYPE_STRING)
+		terminal_combobox.set_model(terminal_combobox_store)
+		terminal_combobox_cell = gtk.CellRendererText()
+		terminal_combobox.pack_start(terminal_combobox_cell, True)
+		terminal_combobox.add_attribute(terminal_combobox_cell, 'text', 0)
+
+		term_id = setctl.get_preferred_tool('terminal')
+		# fill in the available terminals
+		terminals = utils.locale_sort(terminal.get_valid_terminals())
+		term_iter = None
+		for term in terminals:
+			_it = terminal_combobox_store.append((unicode(term), term.get_id()))
+			if term.get_id() == term_id:
+				term_iter = _it
+		term_iter = term_iter or terminal_combobox_store.get_iter_first()
+		terminal_combobox.set_active_iter(term_iter)
+
 		# Plugin List
 		columns = [
 			{"key": "plugin_id", "type": str },
@@ -747,6 +768,12 @@ class PreferencesWindowController (pretty.OutputMixin):
 			return
 		self.buttonremovedirectory.set_sensitive(True)
 
+	def on_terminal_combobox_changed(self, widget):
+		setctl = settings.GetSettingsController()
+		itr = widget.get_active_iter()
+		term_id = widget.get_model().get_value(itr, 1)
+		setctl.set_preferred_tool('terminal', term_id)
+
 	def show(self):
 		self.window.present()
 	def show_focus_plugin(self, plugin_id):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]