00001
00002
00003
00004
00005
00006
00007
00008 import os
00009 import pwd
00010 import gobject
00011 import gtk
00012 import gtk.glade
00013 import vte
00014 from gettext import gettext
00015
00016 import environment
00017 import view
00018 import config
00019 import settings
00020
00021 datadir = None
00022
00023 def init_extension(d):
00024 global datadir
00025 datadir = d
00026
00027
00028
00029
00030 class Launcher (environment.LauncherExtension):
00031 def __init__(self):
00032 environment.LauncherExtension.__init__(self)
00033
00034 label = gettext('Terminal emulator')
00035 self.action = gtk.Action(None, label, None, None)
00036 self.action.set_visible(True)
00037
00038 def get_action(self):
00039 return self.action
00040
00041 def create(self):
00042 return View()
00043
00044 gobject.type_register(Launcher)
00045
00046
00047
00048
00049 class View (view.AbstractView):
00050 def __init__(self):
00051 view.AbstractView.__init__(self)
00052
00053 self.terminal = vte.Terminal()
00054 self.terminal.set_property('can-focus', True)
00055 self.terminal.connect('child-exited', vte.Terminal.destroy)
00056
00057 targets = (
00058 ('TEXT', 0, 0),
00059 ('STRING', 0, 1),
00060 ('text/uri-list', 0, 10),
00061 ('_NETSCAPE_URL', 0, 11),
00062 )
00063 self.terminal.drag_dest_set(gtk.DEST_DEFAULT_ALL, targets, gtk.gdk.ACTION_COPY)
00064 self.terminal.connect('drag-data-received', self.on_terminal_received)
00065
00066 path = os.path.join(datadir, 'encode', 'terminal-view.glade')
00067 self.glade = gtk.glade.XML(path)
00068
00069 conf = config.Directory('encode/terminal')
00070 font = conf.get_string('font')
00071 lines = conf.get_int ('scrollback_lines')
00072 chars = conf.get_string('word_chars')
00073 command = conf.get_string('command')
00074
00075 if font:
00076 self.terminal.set_font_from_string(font)
00077 if lines and lines > 0:
00078 self.terminal.set_scrollback_lines(lines)
00079 if chars:
00080 self.terminal.set_word_chars(chars)
00081
00082 if not command:
00083 uid = os.getuid()
00084 entry = pwd.getpwuid(uid)
00085 command = entry[6]
00086
00087 self.terminal.show()
00088 self.terminal.fork_command(command)
00089
00090 def on_terminal_received(self, terminal, context, x, y, selection, target, timestamp):
00091 if target < 10:
00092 text = selection.data
00093 else:
00094 prefix = 'file://'
00095 hostname = 'localhost'
00096
00097 text = ''
00098 for uri in selection.data.split():
00099 if uri.startswith(prefix):
00100 path = uri[len(prefix):]
00101 if path.startswith(hostname):
00102 path = source_path[len(hostname):]
00103 else:
00104 path = uri
00105
00106 text += path
00107 text += ' '
00108
00109 self.terminal.feed_child(text)
00110 self.terminal.grab_focus()
00111
00112 context.finish(True, False, timestamp)
00113
00114 def get_label(self):
00115 return self.glade.get_widget('title')
00116
00117 def get_widget(self):
00118 return self.terminal
00119
00120 gobject.type_register(View)
00121
00122
00123
00124
00125 if 'set' not in __builtins__:
00126 import sets
00127 set = sets.Set
00128
00129 class Settings (settings.SettingsExtension):
00130 def __init__(self):
00131 settings.SettingsExtension.__init__(self)
00132
00133 path = os.path.join(datadir, 'encode', 'terminal-settings.glade')
00134 self.glade = gtk.glade.XML(path)
00135 self.glade.signal_autoconnect(self)
00136
00137 self.config = config.Directory('encode/terminal')
00138
00139 self.dirty = set((
00140 'font',
00141 'lines',
00142 ))
00143 self.revert()
00144
00145 def get_name(self):
00146 return gettext('Terminal')
00147
00148 def get_title(self):
00149 return gettext('Terminal emulator')
00150
00151 def get_widget(self):
00152 return self.glade.get_widget('table')
00153
00154 def apply(self):
00155 if 'font' in self.dirty:
00156 fontbutton = self.glade.get_widget('font_fontbutton')
00157 font = fontbutton.get_font_name()
00158
00159 self.config.set_string('font', font)
00160
00161 if 'lines' in self.dirty:
00162 spinbutton = self.glade.get_widget('lines_spinbutton')
00163 lines = spinbutton.get_value_as_int()
00164
00165 self.config.set_int('scrollback_lines', lines)
00166
00167 self.dirty.clear()
00168
00169 def revert(self):
00170 if 'font' in self.dirty:
00171 font = self.config.get_string('font')
00172
00173 fontbutton = self.glade.get_widget('font_fontbutton')
00174 fontbutton.set_font_name(font)
00175
00176 if 'lines' in self.dirty:
00177 lines = self.config.get_int('scrollback_lines')
00178
00179 spinbutton = self.glade.get_widget('lines_spinbutton')
00180 spinbutton.set_value(lines)
00181
00182 self.dirty.clear()
00183
00184 def on_font_set(self, fontbutton):
00185 self.dirty.add('font')
00186 self.modified()
00187
00188 def on_lines_changed(self, spinbutton):
00189 self.dirty.add('lines')
00190 self.modified()
00191
00192 gobject.type_register(Settings)