# -*- coding: utf8 -*- # # Adds a terminal to gedit's bottom pane # import gedit import pango, gtk, vte, gconf # Defaults. def_audible = 0 def_background = None def_blink = 0 def_command = None def_emulation = "xterm" def_font_name = "monospace 10" def_fgcol = "AAAAAA" def_bgcol = "000000" def_scrollback = 100 def_transparent = 0 def_visible = 0 class GeditTerminal(vte.Terminal): """vte terminal which follows gnome-terminal default profile options""" def __init__(self): vte.Terminal.__init__(self) self.gconf = gconf.client_get_default() # TODO retrieve the profile from GConf self.gconf.add_dir("/apps/gnome-terminal/profiles/Default", gconf.CLIENT_PRELOAD_RECURSIVE) if not self.gconf.get_bool("/apps/gnome-terminal/profiles/Default/use_system_font"): self.set_font(self.gconf.get_string("/apps/gnome-terminal/profiles/Default/font")) else: self.set_font(self.gconf.get_string("/desktop/gnome/interface/monospace_font")) # todo # if not self.gconf.get_bool("/apps/gnome-terminal/profiles/Default/use_theme_colors"): # self.set_colors(self.gconf.get_string("/apps/gnome-terminal/profiles/Default/foregound_color"), # self.gconf.get_string("/apps/gnome-terminal/profiles/Default/backgound_color")) # else: # self.set_colors(gtk.gdk.color_parse (self.gconf.get_string("/apps/gnome-terminal/profiles/Default/foregound_color")), # gtk.gdk.color_parse (self.gconf.get_string("/apps/gnome-terminal/profiles/Default/backgound_color"))) # TODO more GConf getting self.set_cursor_blinks(def_blink) self.set_emulation(def_emulation) self.set_scrollback_lines(def_scrollback) self.set_audible_bell(def_audible) self.set_visible_bell(def_visible) # GConf notification self.gconf.notify_add("/apps/gnome-terminal/profiles/Default/font", lambda x, y, z, a: self.set_font(z.value.get_string())) #is this bad if the value isn't a string? # TODO: add more notofications # set a reasonably small size... this is ugly but it seems # the only way to make vte behave. self.set_size(30, 7) self.set_size_request(200, 50) # Start up the default command, the user's shell. self.fork_command() self.connect("child-exited", lambda t: t.fork_command()) def set_font(self, font_name): try: font = pango.FontDescription(font_name) except: font = pango.FontDescription(def_font_name) vte.Terminal.set_font(self, font) def set_colors(self, fg_col, bg_col): vte.Terminal.set_colors(self, fg_col, bg_col, []) class VtePlugin(gedit.Plugin): def __init__(self): gedit.Plugin.__init__(self) def activate(self, window): terminal = GeditTerminal() self.pane = gtk.HBox(0) self.pane.set_resize_mode(gtk.RESIZE_IMMEDIATE) self.pane.pack_start(terminal) scrollbar = gtk.VScrollbar(terminal.get_adjustment()) self.pane.pack_start(scrollbar, False, False, 0) self.pane.show_all() image = gtk.Image() image.set_from_icon_name("gnome-terminal", gtk.ICON_SIZE_MENU) bottom = window.get_bottom_panel() bottom.add_item(self.pane, "Terminal", image) def deactivate(self, window): bottom = window.get_bottom_panel() bottom.remove_item(self.pane) def update_ui(self, window): pass