3
# terminal.py - Embeded VTE terminal for gedit
4
# This file is part of gedit
6
# Copyright (C) 2005-2006 - Paolo Borelli
8
# gedit is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# gedit is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with gedit; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor,
21
# Boston, MA 02110-1301 USA
29
class GeditTerminal(gtk.HBox):
30
"""VTE terminal which follows gnome-terminal default profile options"""
32
GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
36
'audible_bell' : False,
38
'background_color' : '#000000',
39
'backspace_binding' : 'ascii-del',
40
'cursor_blinks' : False,
41
'emulation' : 'xterm',
42
'font_name' : 'Monospace 10',
43
'foreground_color' : '#AAAAAA',
44
'scroll_on_keystroke' : False,
45
'scroll_on_output' : False,
46
'scrollback_lines' : 100,
47
'visible_bell' : False
51
gtk.HBox.__init__(self, False, 4)
53
gconf_client.add_dir(self.GCONF_PROFILE_DIR,
54
gconf.CLIENT_PRELOAD_RECURSIVE)
56
self._vte = vte.Terminal()
57
self.reconfigure_vte()
58
self._vte.set_size(30, 5)
59
self._vte.set_size_request(200, 50)
61
self.pack_start(self._vte)
63
self._scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
64
self._scrollbar.show()
65
self.pack_start(self._scrollbar, False, False, 0)
67
gconf_client.notify_add(self.GCONF_PROFILE_DIR,
68
self.on_gconf_notification)
70
self._vte.connect("button-press-event", self.on_vte_button_press)
71
self._vte.connect("popup-menu", self.on_vte_popup_menu)
72
self._vte.connect("child-exited", lambda term: term.fork_command())
74
self._vte.fork_command()
76
def reconfigure_vte(self):
78
if gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_system_font"):
79
font_name = gconf_get_str("/desktop/gnome/interface/monospace_font",
80
self.defaults['font_name'])
82
font_name = gconf_get_str(self.GCONF_PROFILE_DIR + "/font",
83
self.defaults['font_name'])
86
self._vte.set_font(pango.FontDescription(font_name))
91
fg_color = gconf_get_str(self.GCONF_PROFILE_DIR + "/foreground_color",
92
self.defaults['foreground_color'])
93
bg_color = gconf_get_str(self.GCONF_PROFILE_DIR + "/background_color",
94
self.defaults['background_color'])
95
self._vte.set_colors(gtk.gdk.color_parse (fg_color),
96
gtk.gdk.color_parse (bg_color),
99
self._vte.set_cursor_blinks(gconf_get_bool(self.GCONF_PROFILE_DIR + "/cursor_blinks",
100
self.defaults['cursor_blinks']))
102
self._vte.set_audible_bell(not gconf_get_bool(self.GCONF_PROFILE_DIR + "/silent_bell",
103
not self.defaults['audible_bell']))
105
self._vte.set_scrollback_lines(gconf_get_int(self.GCONF_PROFILE_DIR + "/scrollback_lines",
106
self.defaults['scrollback_lines']))
108
self._vte.set_allow_bold(gconf_get_bool(self.GCONF_PROFILE_DIR + "/allow_bold",
109
self.defaults['allow_bold']))
111
self._vte.set_scroll_on_keystroke(gconf_get_bool(self.GCONF_PROFILE_DIR + "/scroll_on_keystroke",
112
self.defaults['scroll_on_keystroke']))
114
self._vte.set_scroll_on_output(gconf_get_bool(self.GCONF_PROFILE_DIR + "/scroll_on_output",
115
self.defaults['scroll_on_output']))
117
self._vte.set_emulation(self.defaults['emulation'])
118
self._vte.set_visible_bell(self.defaults['visible_bell'])
120
def on_gconf_notification(self, client, cnxn_id, entry, what):
121
self.reconfigure_vte()
123
def on_vte_button_press(self, term, event):
124
if event.button == 3:
128
def on_vte_popup_menu(self, term):
131
def create_popup_menu(self):
134
item = gtk.ImageMenuItem(gtk.STOCK_COPY)
135
item.connect("activate", lambda menu_item: self._vte.copy_clipboard())
138
item = gtk.ImageMenuItem(gtk.STOCK_PASTE)
139
item.connect("activate", lambda menu_item: self._vte.paste_clipboard())
145
def do_popup(self, event = None):
146
menu = self.create_popup_menu()
148
if event is not None:
149
menu.popup(None, None, None, event.button, event.time)
151
menu.popup(None, None,
152
lambda m: gedit.utils.menu_position_under_widget(m, self),
153
0, gtk.get_current_event_time())
154
menu.select_first(False)
156
class TerminalWindowHelper(object):
157
def __init__(self, window):
158
self._window = window
160
self._panel = GeditTerminal()
164
image.set_from_icon_name("utilities-terminal", gtk.ICON_SIZE_MENU)
166
bottom = window.get_bottom_panel()
167
bottom.add_item(self._panel, "Terminal", image)
169
def deactivate(self):
170
bottom = window.get_bottom_panel()
171
bottom.remove_item(self._panel)
176
class TerminalPlugin(gedit.Plugin):
177
WINDOW_DATA_KEY = "TerminalPluginWindowData"
180
gedit.Plugin.__init__(self)
182
def activate(self, window):
183
helper = TerminalWindowHelper(window)
184
window.set_data(self.WINDOW_DATA_KEY, helper)
186
def deactivate(self, window):
187
window.get_data(self.WINDOW_DATA_KEY).deactivate()
188
window.set_data(self.WINDOW_DATA_KEY, None)
190
def update_ui(self, window):
191
window.get_data(self.WINDOW_DATA_KEY).update_ui()
193
gconf_client = gconf.client_get_default()
194
def gconf_get_bool(key, default = False):
195
val = gconf_client.get(key)
197
if val is not None and val.type == gconf.VALUE_BOOL:
198
return val.get_bool()
202
def gconf_get_str(key, default = ""):
203
val = gconf_client.get(key)
205
if val is not None and val.type == gconf.VALUE_STRING:
206
return val.get_string()
210
def gconf_get_int(key, default = 0):
211
val = gconf_client.get(key)
213
if val is not None and val.type == gconf.VALUE_INT:
219
# ex:ts=4:et: Let's conform to PEP8