2009-08-10 23:42:39 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminal.py - classes necessary to provide Terminal widgets"""
|
|
|
|
|
|
|
|
import sys
|
2009-08-19 00:06:38 +00:00
|
|
|
import os
|
2009-08-10 23:42:39 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
2009-08-19 00:06:38 +00:00
|
|
|
import gobject
|
2009-09-06 21:55:37 +00:00
|
|
|
import re
|
2009-08-10 23:42:39 +00:00
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
from version import APP_NAME
|
|
|
|
from util import dbg, err, gerr
|
|
|
|
import util
|
2009-08-18 11:55:37 +00:00
|
|
|
from config import Config
|
2009-08-19 00:06:38 +00:00
|
|
|
from cwd import get_default_cwd
|
2009-09-04 21:12:13 +00:00
|
|
|
from newterminator import Terminator
|
2009-08-18 12:44:41 +00:00
|
|
|
from titlebar import Titlebar
|
2009-10-08 19:27:49 +00:00
|
|
|
from terminal_popup_menu import TerminalPopupMenu
|
2009-08-18 12:47:46 +00:00
|
|
|
from searchbar import Searchbar
|
2009-09-02 23:52:36 +00:00
|
|
|
from translation import _
|
2009-08-18 11:55:37 +00:00
|
|
|
|
2009-08-10 23:42:39 +00:00
|
|
|
try:
|
|
|
|
import vte
|
|
|
|
except ImportError:
|
2009-08-18 11:55:37 +00:00
|
|
|
gerr('You need to install python bindings for libvte')
|
2009-08-10 23:42:39 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-08-18 12:54:46 +00:00
|
|
|
# pylint: disable-msg=R0904
|
2009-08-10 23:42:39 +00:00
|
|
|
class Terminal(gtk.VBox):
|
|
|
|
"""Class implementing the VTE widget and its wrappings"""
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
__gsignals__ = {
|
|
|
|
'close-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-09-02 20:10:28 +00:00
|
|
|
'title-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING,)),
|
2009-09-04 21:48:35 +00:00
|
|
|
'enumerate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_INT,)),
|
2009-09-04 23:34:09 +00:00
|
|
|
'group-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'ungroup-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-09-06 20:54:33 +00:00
|
|
|
'ungroup-all': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-09-06 21:55:37 +00:00
|
|
|
'split-horiz': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'split-vert': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'tab-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'tab-top-new': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-10-08 23:22:01 +00:00
|
|
|
'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-10-12 21:05:19 +00:00
|
|
|
'zoom': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'maximise': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-08-19 00:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_TYPE_VTE = 8
|
|
|
|
|
2009-09-04 21:12:13 +00:00
|
|
|
terminator = None
|
2009-08-11 22:27:56 +00:00
|
|
|
vte = None
|
2009-08-19 00:06:38 +00:00
|
|
|
terminalbox = None
|
2009-10-06 23:08:13 +00:00
|
|
|
scrollbar = None
|
2009-08-18 12:44:41 +00:00
|
|
|
titlebar = None
|
|
|
|
searchbar = None
|
|
|
|
|
2009-09-04 21:12:13 +00:00
|
|
|
group = None
|
2009-08-19 00:06:38 +00:00
|
|
|
cwd = None
|
2009-09-02 20:10:28 +00:00
|
|
|
command = None
|
2009-08-19 00:06:38 +00:00
|
|
|
clipboard = None
|
2009-09-06 21:55:37 +00:00
|
|
|
pid = None
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
matches = None
|
|
|
|
config = None
|
2009-08-18 12:44:41 +00:00
|
|
|
default_encoding = None
|
2009-08-11 22:27:56 +00:00
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
composite_support = None
|
|
|
|
|
2009-08-10 23:42:39 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
2009-08-11 22:27:56 +00:00
|
|
|
gtk.VBox.__init__(self)
|
2009-08-19 00:06:38 +00:00
|
|
|
self.__gobject_init__()
|
|
|
|
|
2009-09-04 21:12:13 +00:00
|
|
|
self.terminator = Terminator()
|
2009-09-04 21:48:35 +00:00
|
|
|
self.connect('enumerate', self.terminator.do_enumerate)
|
2009-09-04 23:34:09 +00:00
|
|
|
self.connect('group-tab', self.terminator.group_tab)
|
|
|
|
self.connect('ungroup-tab', self.terminator.ungroup_tab)
|
2009-10-08 23:22:01 +00:00
|
|
|
self.connect('focus-in', self.terminator.focus_changed)
|
2009-09-04 21:48:35 +00:00
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
self.matches = {}
|
|
|
|
|
|
|
|
self.config = Config()
|
2009-08-11 22:27:56 +00:00
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
self.cwd = get_default_cwd()
|
|
|
|
self.clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
|
|
|
|
|
2009-08-11 22:27:56 +00:00
|
|
|
self.vte = vte.Terminal()
|
2009-08-11 22:48:19 +00:00
|
|
|
self.vte.set_size(80, 24)
|
|
|
|
self.vte._expose_data = None
|
2009-10-01 21:15:50 +00:00
|
|
|
if not hasattr(self.vte, "set_opacity") or \
|
|
|
|
not hasattr(self.vte, "is_composited"):
|
2009-08-19 00:06:38 +00:00
|
|
|
self.composite_support = False
|
2009-08-11 22:48:19 +00:00
|
|
|
self.vte.show()
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-08-18 12:44:41 +00:00
|
|
|
self.default_encoding = self.vte.get_encoding()
|
2009-08-18 11:55:37 +00:00
|
|
|
self.update_url_matches(self.config['try_posix_regexp'])
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
self.terminalbox = self.create_terminalbox()
|
|
|
|
|
2009-08-18 12:44:41 +00:00
|
|
|
self.titlebar = Titlebar()
|
2009-08-19 00:06:38 +00:00
|
|
|
self.titlebar.connect_icon(self.on_group_button_press)
|
2009-09-02 23:52:36 +00:00
|
|
|
self.titlebar.connect('edit-done', self.on_edit_done)
|
2009-09-02 20:18:36 +00:00
|
|
|
self.connect('title-change', self.titlebar.set_terminal_title)
|
|
|
|
|
2009-08-18 12:44:41 +00:00
|
|
|
self.searchbar = Searchbar()
|
|
|
|
|
|
|
|
self.show()
|
|
|
|
self.pack_start(self.titlebar, False)
|
|
|
|
self.pack_start(self.terminalbox)
|
|
|
|
self.pack_end(self.searchbar)
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
self.connect_signals()
|
|
|
|
|
|
|
|
os.putenv('COLORTERM', 'gnome-terminal')
|
|
|
|
|
|
|
|
env_proxy = os.getenv('http_proxy')
|
|
|
|
if not env_proxy:
|
|
|
|
if self.config['http_proxy'] and self.config['http_proxy'] != '':
|
|
|
|
os.putenv('http_proxy', self.config['http_proxy'])
|
|
|
|
|
|
|
|
def create_terminalbox(self):
|
|
|
|
"""Create a GtkHBox containing the terminal and a scrollbar"""
|
|
|
|
|
|
|
|
terminalbox = gtk.HBox()
|
2009-10-06 23:08:13 +00:00
|
|
|
self.scrollbar = gtk.VScrollbar(self.vte.get_adjustment())
|
2009-08-19 00:06:38 +00:00
|
|
|
position = self.config['scrollbar_position']
|
|
|
|
|
|
|
|
if position not in ('hidden', 'disabled'):
|
2009-10-06 23:08:13 +00:00
|
|
|
self.scrollbar.show()
|
2009-08-19 00:06:38 +00:00
|
|
|
|
|
|
|
if position == 'left':
|
|
|
|
func = terminalbox.pack_end
|
|
|
|
else:
|
|
|
|
func = terminalbox.pack_start
|
|
|
|
|
|
|
|
func(self.vte)
|
2009-10-06 23:08:13 +00:00
|
|
|
func(self.scrollbar, False)
|
2009-08-19 00:06:38 +00:00
|
|
|
terminalbox.show()
|
|
|
|
|
|
|
|
return(terminalbox)
|
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
def update_url_matches(self, posix = True):
|
|
|
|
"""Update the regexps used to match URLs"""
|
|
|
|
userchars = "-A-Za-z0-9"
|
|
|
|
passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
|
|
|
|
hostchars = "-A-Za-z0-9"
|
|
|
|
pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'\""
|
|
|
|
schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
|
|
|
|
user = "[" + userchars + "]+(:[" + passchars + "]+)?"
|
|
|
|
urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]"
|
|
|
|
|
|
|
|
if posix:
|
2009-08-19 18:02:33 +00:00
|
|
|
dbg ('update_url_matches: Trying POSIX URL regexps')
|
2009-08-18 11:55:37 +00:00
|
|
|
lboundry = "[[:<:]]"
|
|
|
|
rboundry = "[[:>:]]"
|
|
|
|
else: # GNU
|
2009-08-19 18:02:33 +00:00
|
|
|
dbg ('update_url_matches: Trying GNU URL regexps')
|
2009-08-18 11:55:37 +00:00
|
|
|
lboundry = "\\<"
|
|
|
|
rboundry = "\\>"
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['full_uri'] = self.vte.match_add(lboundry + schemes +
|
2009-08-18 11:55:37 +00:00
|
|
|
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
|
|
|
|
urlpath + ")?" + rboundry + "/?")
|
|
|
|
|
|
|
|
if self.matches['full_uri'] == -1:
|
|
|
|
if posix:
|
|
|
|
err ('update_url_matches: POSIX match failed, trying GNU')
|
|
|
|
self.update_url_matches(posix = False)
|
|
|
|
else:
|
|
|
|
err ('update_url_matches: Failed adding URL match patterns')
|
|
|
|
else:
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['voip'] = self.vte.match_add(lboundry +
|
2009-08-18 11:55:37 +00:00
|
|
|
'(callto:|h323:|sip:)' + "[" + userchars + "+][" +
|
|
|
|
userchars + ".]*(:[0-9]+)?@?[" + pathchars + "]+" +
|
|
|
|
rboundry)
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['addr_only'] = self.vte.match_add (lboundry +
|
2009-08-18 11:55:37 +00:00
|
|
|
"(www|ftp)[" + hostchars + "]*\.[" + hostchars +
|
|
|
|
".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?")
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['email'] = self.vte.match_add (lboundry +
|
2009-08-18 12:54:46 +00:00
|
|
|
"(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9]\
|
|
|
|
[a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+\
|
|
|
|
[.a-zA-Z0-9-]*" + rboundry)
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['nntp'] = self.vte.match_add (lboundry +
|
2009-08-18 12:54:46 +00:00
|
|
|
'''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@\
|
|
|
|
[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry)
|
2009-08-18 11:55:37 +00:00
|
|
|
# if the url looks like a Launchpad changelog closure entry
|
|
|
|
# LP: #92953 - make it a url to http://bugs.launchpad.net
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['launchpad'] = self.vte.match_add (
|
2009-08-18 11:55:37 +00:00
|
|
|
'\\bLP:? #?[0-9]+\\b')
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
def connect_signals(self):
|
|
|
|
"""Connect all the gtk signals and drag-n-drop mechanics"""
|
|
|
|
|
|
|
|
self.vte.connect('key-press-event', self.on_keypress)
|
|
|
|
self.vte.connect('button-press-event', self.on_buttonpress)
|
|
|
|
self.vte.connect('popup-menu', self.popup_menu)
|
|
|
|
|
|
|
|
srcvtetargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE)]
|
|
|
|
dsttargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE),
|
|
|
|
('text/plain', 0, 0), ('STRING', 0, 0), ('COMPOUND_TEXT', 0, 0)]
|
|
|
|
|
|
|
|
for (widget, mask) in [
|
|
|
|
(self.vte, gtk.gdk.CONTROL_MASK | gtk.gdk.BUTTON3_MASK),
|
|
|
|
(self.titlebar, gtk.gdk.CONTROL_MASK)]:
|
|
|
|
widget.drag_source_set(mask, srcvtetargets, gtk.gdk.ACTION_MOVE)
|
|
|
|
|
|
|
|
self.vte.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
|
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
|
|
|
|
dsttargets, gtk.gdk.ACTION_MOVE)
|
|
|
|
|
|
|
|
for widget in [self.vte, self.titlebar]:
|
|
|
|
widget.connect('drag-begin', self.on_drag_begin, self)
|
|
|
|
widget.connect('drag-data-get', self.on_drag_data_get,
|
|
|
|
self)
|
|
|
|
|
|
|
|
self.vte.connect('drag-motion', self.on_drag_motion, self)
|
|
|
|
self.vte.connect('drag-data-received',
|
|
|
|
self.on_drag_data_received, self)
|
|
|
|
|
|
|
|
if self.config['copy_on_selection']:
|
|
|
|
self.vte.connect('selection-changed', lambda widget:
|
|
|
|
self.vte.copy_clipboard())
|
|
|
|
|
|
|
|
if self.composite_support:
|
|
|
|
self.vte.connect('composited-changed',
|
|
|
|
self.on_composited_changed)
|
|
|
|
|
2009-09-06 22:53:48 +00:00
|
|
|
self.vte.connect('window-title-changed', lambda x:
|
|
|
|
self.emit('title-change', self.get_window_title()))
|
2009-08-19 00:06:38 +00:00
|
|
|
self.vte.connect('grab-focus', self.on_vte_focus)
|
|
|
|
self.vte.connect('focus-in-event', self.on_vte_focus_in)
|
|
|
|
self.vte.connect('resize-window', self.on_resize_window)
|
|
|
|
self.vte.connect('size-allocate', self.on_vte_size_allocate)
|
|
|
|
|
|
|
|
if self.config['exit_action'] == 'restart':
|
|
|
|
self.vte.connect('child-exited', self.spawn_child)
|
|
|
|
elif self.config['exit_action'] in ('close', 'left'):
|
2009-09-06 21:55:37 +00:00
|
|
|
self.vte.connect('child-exited', lambda x: self.emit('close-term'))
|
2009-08-19 00:06:38 +00:00
|
|
|
|
|
|
|
self.vte.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
|
|
|
self.vte.connect('enter_notify_event',
|
|
|
|
self.on_vte_notify_enter)
|
|
|
|
|
|
|
|
self.vte.connect_after('realize', self.reconfigure)
|
2009-08-19 18:02:33 +00:00
|
|
|
self.vte.connect_after('realize', self.spawn_child)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-09-02 23:52:36 +00:00
|
|
|
def create_popup_group_menu(self, widget, event = None):
|
|
|
|
"""Pop up a menu for the group widget"""
|
|
|
|
if event:
|
|
|
|
button = event.button
|
|
|
|
time = event.time
|
|
|
|
else:
|
|
|
|
button = 0
|
|
|
|
time = 0
|
|
|
|
|
|
|
|
menu = self.populate_group_menu()
|
|
|
|
menu.show_all()
|
|
|
|
menu.popup(None, None, self.position_popup_group_menu, button, time,
|
|
|
|
widget)
|
|
|
|
return(True)
|
|
|
|
|
|
|
|
def populate_group_menu(self):
|
|
|
|
"""Fill out a group menu"""
|
|
|
|
menu = gtk.Menu()
|
|
|
|
groupitem = None
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Assign to group...'))
|
|
|
|
item.connect('activate', self.create_group)
|
|
|
|
menu.append(item)
|
2009-09-04 21:12:13 +00:00
|
|
|
|
|
|
|
if len(self.terminator.groups) > 0:
|
|
|
|
groupitem = gtk.RadioMenuItem(groupitem, _('None'))
|
|
|
|
groupitem.set_active(self.group == None)
|
|
|
|
groupitem.connect('activate', self.set_group, None)
|
|
|
|
menu.append(groupitem)
|
|
|
|
|
|
|
|
for group in self.terminator.groups:
|
|
|
|
item = gtk.RadioMenuItem(groupitem, group, False)
|
|
|
|
item.set_active(self.group == group)
|
|
|
|
item.connect('toggled', self.set_group, group)
|
|
|
|
menu.append(item)
|
|
|
|
groupitem = item
|
|
|
|
|
|
|
|
if self.group != None or len(self.terminator.groups) > 0:
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
if self.group != None:
|
|
|
|
item = gtk.MenuItem(_('Remove group %s') % self.group)
|
|
|
|
item.connect('activate', self.ungroup, self.group)
|
|
|
|
menu.append(item)
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
if util.has_ancestor(self, gtk.Notebook):
|
2009-09-04 23:34:09 +00:00
|
|
|
item = gtk.MenuItem(_('G_roup all in tab'))
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x: self.emit('group_tab'))
|
2009-09-04 23:34:09 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
if len(self.terminator.groups) > 0:
|
|
|
|
item = gtk.MenuItem(_('Ungr_oup all in tab'))
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x: self.emit('ungroup_tab'))
|
2009-09-04 23:34:09 +00:00
|
|
|
menu.append(item)
|
2009-09-04 21:12:13 +00:00
|
|
|
|
|
|
|
if len(self.terminator.groups) > 0:
|
|
|
|
item = gtk.MenuItem(_('Remove all groups'))
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x: self.emit('ungroup-all'))
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
if self.group != None:
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Close group %s') % self.group)
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x:
|
2009-09-04 21:12:13 +00:00
|
|
|
self.terminator.closegroupedterms(self))
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
groupitem = None
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
for key, value in {_('Broadcast off'):'off',
|
2009-09-04 21:12:13 +00:00
|
|
|
_('Broadcast group'):'group',
|
|
|
|
_('Broadcast all'):'all'}.items():
|
|
|
|
groupitem = gtk.RadioMenuItem(groupitem, key)
|
|
|
|
groupitem.set_active(self.terminator.groupsend ==
|
|
|
|
self.terminator.groupsend_type[value])
|
|
|
|
groupitem.connect('activate', self.set_groupsend,
|
|
|
|
self.terminator.groupsend_type[value])
|
|
|
|
menu.append(groupitem)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
item = gtk.CheckMenuItem(_('Split to this group'))
|
|
|
|
item.set_active(self.terminator.splittogroup)
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('toggled', lambda x: self.do_splittogroup_toggle())
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.CheckMenuItem(_('Autoclean groups'))
|
|
|
|
item.set_active(self.terminator.autocleangroups)
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('toggled', lambda x: self.do_autocleangroups_toggle())
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Insert terminal number'))
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x: self.emit('enumerate', False))
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Insert padded terminal number'))
|
2009-09-06 20:54:33 +00:00
|
|
|
item.connect('activate', lambda x: self.emit('enumerate', True))
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
2009-09-02 23:52:36 +00:00
|
|
|
|
|
|
|
return(menu)
|
|
|
|
|
|
|
|
def position_popup_group_menu(self, menu, widget):
|
|
|
|
"""Calculate the position of the group popup menu"""
|
|
|
|
screen_w = gtk.gdk.screen_width()
|
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
|
|
|
|
widget_win = widget.get_window()
|
|
|
|
widget_x, widget_y = widget_win.get_origin()
|
|
|
|
widget_w, widget_h = widget_win.get_size()
|
|
|
|
|
|
|
|
menu_w, menu_h = menu.size_request()
|
|
|
|
|
|
|
|
if widget_y + widget_h + menu_h > screen_h:
|
|
|
|
menu_y = max(widget_y - menu_h, 0)
|
|
|
|
else:
|
|
|
|
menu_y = widget_y + widget_h
|
|
|
|
|
|
|
|
return(widget_x, menu_y, 1)
|
|
|
|
|
|
|
|
def create_group(self, item):
|
|
|
|
"""Create a new group"""
|
2009-10-14 12:05:07 +00:00
|
|
|
#FIXME: Make this work
|
2009-09-02 23:52:36 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-04 21:12:13 +00:00
|
|
|
def set_groupsend(self, widget, value):
|
|
|
|
"""Set the groupsend mode"""
|
|
|
|
# FIXME: Can we think of a smarter way of doing this than poking?
|
|
|
|
self.terminator.groupsend = value
|
|
|
|
|
|
|
|
def do_splittogroup_toggle(self):
|
|
|
|
"""Toggle the splittogroup mode"""
|
|
|
|
# FIXME: Can we think of a smarter way of doing this than poking?
|
|
|
|
self.terminator.splittogroup = not self.terminator.splittogroup
|
|
|
|
|
|
|
|
def do_autocleangroups_toggle(self):
|
|
|
|
"""Toggle the autocleangroups mode"""
|
|
|
|
# FIXME: Can we think of a smarter way of doing this than poking?
|
|
|
|
self.terminator.autocleangroups = not self.terminator.autocleangroups
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def reconfigure(self, widget=None):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Reconfigure our settings"""
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: actually reconfigure our settings
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-02 20:10:28 +00:00
|
|
|
def get_window_title(self):
|
|
|
|
"""Return the window title"""
|
|
|
|
return(self.vte.get_window_title() or str(self.command))
|
|
|
|
|
2009-09-02 23:52:36 +00:00
|
|
|
def on_group_button_press(self, widget, event):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Handler for the group button"""
|
2009-09-02 23:52:36 +00:00
|
|
|
if event.button == 1:
|
|
|
|
self.create_popup_group_menu(widget, event)
|
|
|
|
return(False)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
def on_keypress(self, widget, event):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Handler for keyboard events"""
|
2009-10-14 12:05:07 +00:00
|
|
|
if not event:
|
|
|
|
dbg('Terminal::on_keypress: Called on %s with no event' % widget)
|
|
|
|
return(False)
|
|
|
|
|
|
|
|
# FIXME: Does keybindings really want to live in Terminator()?
|
|
|
|
mapping = self.terminator.keybindings.lookup(event)
|
|
|
|
|
|
|
|
if mapping == "hide_window":
|
|
|
|
return(False)
|
|
|
|
|
|
|
|
if mapping and mapping not in ['close_window', 'full_screen']:
|
|
|
|
dbg('Terminal::on_keypress: lookup found: %r' % mapping)
|
|
|
|
# handle the case where user has re-bound copy to ctrl+<key>
|
|
|
|
# we only copy if there is a selection otherwise let it fall through
|
|
|
|
# to ^<key>
|
|
|
|
if (mapping == "copy" and event.state & gtk.gdk.CONTROL_MASK):
|
|
|
|
if self._vte.get_has_selection ():
|
|
|
|
getattr(self, "key_" + mapping)()
|
|
|
|
return(True)
|
|
|
|
else:
|
|
|
|
getattr(self, "key_" + mapping)()
|
|
|
|
return(True)
|
|
|
|
|
|
|
|
# FIXME: This is all clearly wrong. We should be doing this better
|
|
|
|
# FIXMS: maybe we can emit the key event and let Terminator() care?
|
|
|
|
if self.terminator.groupsend != 0 and self.vte.is_focus():
|
|
|
|
if self.group and self.terminator.groupsend == 1:
|
|
|
|
self.terminator.group_emit(self, self.group, 'key-press-event',
|
|
|
|
event)
|
|
|
|
if self.terminator.groupsend == 2:
|
|
|
|
self.terminator.all_emit(self, 'key-press-event', event)
|
|
|
|
|
|
|
|
return(False)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
def on_buttonpress(self, widget, event):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Handler for mouse events"""
|
2009-09-03 13:47:14 +00:00
|
|
|
# Any button event should grab focus
|
2009-09-06 21:55:37 +00:00
|
|
|
widget.grab_focus()
|
2009-09-03 13:47:14 +00:00
|
|
|
|
|
|
|
if event.button == 1:
|
|
|
|
# Ctrl+leftclick on a URL should open it
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK == gtk.gdk.CONTROL_MASK:
|
|
|
|
url = self.check_for_url(event)
|
|
|
|
if url:
|
|
|
|
self.open_url(url, prepare=True)
|
|
|
|
elif event.button == 2:
|
|
|
|
# middleclick should paste the clipboard
|
|
|
|
self.paste_clipboard(True)
|
|
|
|
return(True)
|
|
|
|
elif event.button == 3:
|
|
|
|
# rightclick should display a context menu if Ctrl is not pressed
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK == 0:
|
2009-09-06 21:55:37 +00:00
|
|
|
self.popup_menu(widget, event)
|
2009-09-03 13:47:14 +00:00
|
|
|
return(True)
|
|
|
|
|
|
|
|
return(False)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-09-03 13:47:14 +00:00
|
|
|
def popup_menu(self, widget, event=None):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Display the context menu"""
|
2009-10-08 19:27:49 +00:00
|
|
|
menu = TerminalPopupMenu(self)
|
|
|
|
menu.show(widget, event)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-10-06 23:08:13 +00:00
|
|
|
def do_scrollbar_toggle(self):
|
|
|
|
self.toggle_widget_visibility(self.scrollbar)
|
|
|
|
|
|
|
|
def do_title_toggle(self):
|
|
|
|
self.toggle_widget_visibility(self.titlebar)
|
|
|
|
|
|
|
|
def toggle_widget_visibility(self, widget):
|
|
|
|
if widget.get_property('visible'):
|
|
|
|
widget.hide()
|
|
|
|
else:
|
|
|
|
widget.show()
|
|
|
|
|
2009-10-08 20:27:00 +00:00
|
|
|
def on_encoding_change(self, widget, encoding):
|
|
|
|
"""Handle the encoding changing"""
|
|
|
|
current = self.vte.get_encoding()
|
|
|
|
if current != encoding:
|
|
|
|
dbg('on_encoding_change: setting encoding to: %s' % encoding)
|
|
|
|
self.custom_encoding = not (encoding == self.config['encoding'])
|
|
|
|
self.vte.set_encoding(encoding)
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_drag_begin(self, widget, drag_context, data):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_drag_data_get(self, widget, drag_context, selection_data, info, time,
|
|
|
|
data):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_drag_motion(self, widget, drag_context, x, y, time, data):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
|
|
|
|
info, time, data):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
def on_vte_focus(self, widget):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
def on_vte_focus_out(self, widget, event):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
def on_vte_focus_in(self, widget, event):
|
2009-10-08 23:22:01 +00:00
|
|
|
self.emit('focus-in')
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-09-02 23:52:36 +00:00
|
|
|
def on_edit_done(self, widget):
|
|
|
|
"""A child widget is done editing a label, return focus to VTE"""
|
|
|
|
self.vte.grab_focus()
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
def on_resize_window(self):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_vte_size_allocate(self, widget, allocation):
|
|
|
|
self.titlebar.update_terminal_size(self.vte.get_column_count(),
|
|
|
|
self.vte.get_row_count())
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_vte_notify_enter(self, term, event):
|
2009-10-14 12:05:07 +00:00
|
|
|
# FIXME: Implement this
|
2009-08-19 00:06:38 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def hide_titlebar(self):
|
|
|
|
self.titlebar.hide()
|
|
|
|
|
|
|
|
def show_titlebar(self):
|
|
|
|
self.titlebar.show()
|
|
|
|
|
2009-10-06 23:08:13 +00:00
|
|
|
def is_zoomed(self):
|
|
|
|
"""Determine if we are a zoomed terminal"""
|
|
|
|
widget = self.get_parent()
|
|
|
|
while True:
|
|
|
|
tmp = widget.get_parent()
|
|
|
|
if not tmp:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
widget = tmp
|
|
|
|
|
|
|
|
try:
|
|
|
|
prop = widget.get_property('term-zoomed')
|
|
|
|
except TypeError:
|
|
|
|
prop = False
|
|
|
|
|
|
|
|
return(prop)
|
|
|
|
|
|
|
|
def zoom(self):
|
|
|
|
"""Zoom ourself to fill the window"""
|
2009-10-12 21:05:19 +00:00
|
|
|
self.emit('zoom')
|
2009-10-06 23:08:13 +00:00
|
|
|
|
|
|
|
def maximise(self):
|
|
|
|
"""Maximise ourself to fill the window"""
|
2009-10-12 21:05:19 +00:00
|
|
|
self.emit('maximise')
|
2009-10-06 23:08:13 +00:00
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def spawn_child(self, widget=None):
|
|
|
|
update_records = self.config['update_records']
|
|
|
|
login = self.config['login_shell']
|
|
|
|
args = []
|
|
|
|
shell = None
|
|
|
|
command = None
|
|
|
|
|
|
|
|
if self.config['use_custom_command']:
|
|
|
|
command = self.config['custom_command']
|
|
|
|
|
2009-09-06 21:55:37 +00:00
|
|
|
shell = util.shell_lookup()
|
2009-08-19 18:02:33 +00:00
|
|
|
|
|
|
|
if self.config['login_shell']:
|
|
|
|
args.insert(0, "-%s" % shell)
|
|
|
|
else:
|
|
|
|
args.insert(0, shell)
|
|
|
|
|
|
|
|
if command is not None:
|
|
|
|
args += ['-c', command]
|
|
|
|
|
|
|
|
if shell is None:
|
|
|
|
self.vte.feed(_('Unable to find a shell'))
|
|
|
|
return(-1)
|
|
|
|
|
|
|
|
os.putenv('WINDOWID', '%s' % self.vte.get_parent_window().xid)
|
|
|
|
|
|
|
|
self.pid = self.vte.fork_command(command=shell, argv=args, envv=[],
|
|
|
|
loglastlog=login, logwtmp=update_records,
|
|
|
|
logutmp=update_records, directory=self.cwd)
|
2009-09-02 20:10:28 +00:00
|
|
|
self.command = shell
|
2009-08-19 18:02:33 +00:00
|
|
|
|
|
|
|
self.titlebar.update()
|
|
|
|
|
|
|
|
if self.pid == -1:
|
|
|
|
self.vte.feed(_('Unable to start shell:') + shell)
|
|
|
|
return(-1)
|
|
|
|
|
2009-09-03 13:47:14 +00:00
|
|
|
def check_for_url(self, event):
|
|
|
|
"""Check if the mouse is over a URL"""
|
|
|
|
return (self.vte.match_check(int(event.x / self.vte.get_char_width()),
|
|
|
|
int(event.y / self.vte.get_char_height())))
|
|
|
|
|
2009-09-04 19:12:35 +00:00
|
|
|
def prepare_url(self, urlmatch):
|
|
|
|
"""Prepare a URL from a VTE match"""
|
|
|
|
url = urlmatch[0]
|
|
|
|
match = urlmatch[1]
|
|
|
|
|
|
|
|
if match == self.matches['email'] and url[0:7] != 'mailto:':
|
|
|
|
url = 'mailto:' + url
|
|
|
|
elif match == self.matches['addr_only'] and url[0:3] == 'ftp':
|
|
|
|
url = 'ftp://' + url
|
|
|
|
elif match == self.matches['addr_only']:
|
|
|
|
url = 'http://' + url
|
2009-09-04 21:12:13 +00:00
|
|
|
elif match == self.matches['launchpad']:
|
2009-09-04 19:12:35 +00:00
|
|
|
for item in re.findall(r'[0-9]+', url):
|
|
|
|
url = 'https://bugs.launchpad.net/bugs/%s' % item
|
|
|
|
return(url)
|
|
|
|
else:
|
|
|
|
return(url)
|
|
|
|
|
2009-09-03 13:47:14 +00:00
|
|
|
def open_url(self, url, prepare=False):
|
2009-09-04 19:12:35 +00:00
|
|
|
"""Open a given URL, conditionally unpacking it from a VTE match"""
|
|
|
|
if prepare == True:
|
|
|
|
url = self.prepare_url(url)
|
|
|
|
dbg('open_url: URL: %s (prepared: %s)' % (url, prepare))
|
2009-10-15 11:57:50 +00:00
|
|
|
gtk.show_uri(None, url, gtk.gdk.CURRENT_TIME)
|
2009-09-03 13:47:14 +00:00
|
|
|
|
|
|
|
def paste_clipboard(self, primary=False):
|
|
|
|
"""Paste one of the two clipboards"""
|
2009-09-04 21:48:35 +00:00
|
|
|
for term in self.terminator.get_target_terms():
|
|
|
|
if primary:
|
|
|
|
term.vte.paste_primary()
|
|
|
|
else:
|
|
|
|
term.vte.paste_clipboard()
|
2009-09-03 13:47:14 +00:00
|
|
|
self.vte.grab_focus()
|
2009-09-04 19:12:35 +00:00
|
|
|
|
2009-09-04 21:48:35 +00:00
|
|
|
def feed(self, text):
|
|
|
|
"""Feed the supplied text to VTE"""
|
|
|
|
self.vte.feed_child(text)
|
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
gobject.type_register(Terminal)
|
2009-08-10 23:42:39 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|