Rewrite based on the very informative, if somewhat pointless gedit terminal plugin.

Lots of functionality split out into classes, with a hacky __main__ to bung four terminals into gtk panes.
This commit is contained in:
Chris Jones 2006-11-09 21:18:31 -08:00
parent dd3658a196
commit 5242a0f3cb
2 changed files with 119 additions and 114 deletions

119
termiator.py Executable file
View File

@ -0,0 +1,119 @@
#!/usr/bin/python
import sys
import string
import getopt
import gtk
import vte
import gconf
import pango
class TerminatorTerm:
# FIXME: How do we get a list of profile keys to be dynamic about this?
GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
defaults = {
'allow_bold' : True,
'audible_bell' : False,
'background' : None,
'background_color' : '#000000',
'backspace_binding' : 'ascii-del',
'cursor_blinks' : False,
'emulation' : 'xterm',
'font_name' : 'Serif 10',
'foreground_color' : '#AAAAAA',
'scroll_on_keystroke' : False,
'scroll_on_output' : False,
'scrollback_lines' : 100,
'visible_bell' : False
}
def __init__ (self):
self.gconf_client = gconf.client_get_default ()
self.gconf_client.add_dir (self.GCONF_PROFILE_DIR, gconf.CLIENT_PRELOAD_RECURSIVE)
self._vte = vte.Terminal ()
self.reconfigure_vte ()
self._vte.show()
self._box = gtk.HBox ()
self._scrollbar = gtk.VScrollbar (self._vte.get_adjustment ())
self._scrollbar.show ()
self._box.pack_start (self._vte)
self._box.pack_start (self._scrollbar, False)
self.gconf_client.notify_add (self.GCONF_PROFILE_DIR, self.on_gconf_notification)
self._vte.connect ("button-press-event", self.on_vte_button_press)
#self._vte.connect ("popup-menu", self.on_vte_popup_menu)
self._vte.connect ("child-exited", lambda term: term.fork_command ())
self._vte.fork_command ()
def reconfigure_vte (self):
self._vte.set_emulation (self.defaults['emulation'])
if self.gconf_client.get_bool (self.GCONF_PROFILE_DIR + "/use_system_font"):
font_name = (self.gconf_client.get_string ("/desktop/gnome/interface/monospace_font_name") or self.defaults['font_name'])
else:
font_name = (self.gconf_client.get_string (self.GCONF_PROFILE_DIR + "/font") or self.defaults['font_name'])
try:
self._vte.set_font (pango.FontDescription (font_name))
except:
pass
# FIXME: Pull in the colors, cursor, bell, scrollback, bold, scroll, etc settings
def on_gconf_notification (self, client, cnxn_id, entry, what):
self.reconfigure_vte ()
def on_vte_button_press (self, term, event):
if event.button == 1:
print "Left mouse button"
self._vte.grab_focus ()
return True
if event.button == 3:
return True
def get_box (self):
return self._box
class Terminator:
def __init__ (self):
self.window = gtk.Window ()
self.window.connect ("delete_event", self.on_delete_event)
self.window.connect ("destroy", self.on_destroy_event)
def on_delete_event (self, widget, event, data=None):
# FIXME: return True if we want to keep the window open (ie a "Do you want to quit" requester)
return False
def on_destroy_event (self, widget, data=None):
gtk.main_quit ()
if __name__ == '__main__':
term = Terminator ()
t1 = TerminatorTerm ()
t2 = TerminatorTerm ()
t3 = TerminatorTerm ()
t4 = TerminatorTerm ()
pane1 = gtk.HPaned ()
pane1.add1 (t1.get_box ())
pane1.add2 (t2.get_box ())
pane2 = gtk.HPaned ()
pane2.add1 (t3.get_box ())
pane2.add2 (t4.get_box ())
vpane = gtk.VPaned ()
vpane.add1 (pane1)
vpane.add2 (pane2)
term.window.add (vpane)
term.window.show_all ()
gtk.main ()

View File

@ -1,114 +0,0 @@
#!/usr/bin/python
import sys
import string
import getopt
import gtk
import vte
def selected_cb(terminal, column, row, cb_data):
if (row == 15):
if (column < 40):
return 1
return 0
def restore_cb(terminal):
(text, attrs) = terminal.get_text(selected_cb, 1)
print "A portion of the text at restore-time is:"
print text
def child_exited_cb(terminal):
gtk.main_quit()
def maketerm():
terminal = vte.Terminal()
if (background):
terminal.set_background_image(background)
if (transparent):
terminal.set_background_transparent(gtk.TRUE)
terminal.set_cursor_blinks(blink)
terminal.set_emulation(emulation)
terminal.set_font_from_string(font)
terminal.set_scrollback_lines(scrollback)
terminal.set_audible_bell(audible)
terminal.set_visible_bell(visible)
terminal.connect("child-exited", child_exited_cb)
terminal.connect("restore-window", restore_cb)
if (command):
# Start up the specified command.
child_pid = terminal.fork_command(command)
else:
# Start up the default command, the user's shell.
child_pid = terminal.fork_command()
terminal.show()
return (terminal)
if __name__ == '__main__':
child_pid = -1;
# Defaults.
audible = 0
background = None
blink = 0
command = None
emulation = "xterm"
font = "mono 9"
scrollback = 100
transparent = 0
visible = 0
# Let the user override them.
(shorts, longs) = getopt.getopt(sys.argv[1:], "B:Tabc:f:n:t:v", ["background", "transparent", "audible", "blink", "command=", "font=", "scrollback=", "terminal=", "visible"])
for argpair in (shorts + longs):
if ((argpair[0] == '-B') or (argpair[0] == '--background')):
print "Setting background image to `" + argpair[1] + "'."
background = argpair[1]
if ((argpair[0] == '-T') or (argpair[0] == '--transparent')):
print "Setting transparency."
transparent = not transparent
if ((argpair[0] == '-a') or (argpair[0] == '--audible')):
print "Setting audible bell."
audible = not audible
if ((argpair[0] == '-b') or (argpair[0] == '--blink')):
print "Setting blinking cursor."
blink = not blink
if ((argpair[0] == '-c') or (argpair[0] == '--command')):
print "Running command `" + argpair[1] + "'."
command = argpair[1]
if ((argpair[0] == '-f') or (argpair[0] == '--font')):
print "Setting font to `" + argpair[1] + "'."
font = argpair[1]
if ((argpair[0] == '-n') or (argpair[0] == '--scrollback')):
scrollback = string.atoi(argpair[1])
if (scrollback == 0):
scrollback = 100
else:
print "Setting scrollback size to `" + str(scrollback) + "'."
if ((argpair[0] == '-t') or (argpair[0] == '--terminal')):
print "Setting terminal type to `" + argpair[1] + "'."
emulation = argpair[1]
if ((argpair[0] == '-v') or (argpair[0] == '--visible')):
print "Setting visible bell."
visible = not visible
window = gtk.Window()
terminal = maketerm()
terminal2 = maketerm()
scrollbar = gtk.VScrollbar()
scrollbar.set_adjustment(terminal.get_adjustment())
scrollbar2 = gtk.VScrollbar()
scrollbar2.set_adjustment(terminal.get_adjustment())
box = gtk.HBox()
box.pack_start(terminal)
box.pack_start(scrollbar, False)
box2 = gtk.HBox()
box2.pack_start(terminal2)
box2.pack_start(scrollbar2, False)
pane = gtk.HPaned()
pane.add1(box)
pane.add2(box2)
window.add(pane)
window.show_all()
gtk.main()