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"""
|
|
|
|
|
2010-02-01 20:15:53 +00:00
|
|
|
from __future__ import division
|
2009-08-10 23:42:39 +00:00
|
|
|
import sys
|
2009-08-19 00:06:38 +00:00
|
|
|
import os
|
2010-01-25 12:35:34 +00:00
|
|
|
import signal
|
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-10-28 23:07:42 +00:00
|
|
|
import pango
|
|
|
|
import subprocess
|
2010-01-11 20:03:54 +00:00
|
|
|
import urllib
|
2009-08-10 23:42:39 +00:00
|
|
|
|
2010-01-11 20:03:54 +00:00
|
|
|
from util import dbg, err, gerr, get_top_window
|
2009-09-06 21:55:37 +00:00
|
|
|
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
|
2010-01-11 20:06:53 +00:00
|
|
|
from terminator 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 _
|
2010-01-18 19:48:24 +00:00
|
|
|
from signalman import Signalman
|
2009-12-17 23:17:32 +00:00
|
|
|
import plugin
|
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-11-14 18:55:51 +00:00
|
|
|
'zoom': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-10-12 21:05:19 +00:00
|
|
|
'maximise': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-11-14 18:55:51 +00:00
|
|
|
'unzoom': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-11-08 23:06:26 +00:00
|
|
|
'resize-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING,)),
|
2009-11-09 22:33:17 +00:00
|
|
|
'navigate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING,)),
|
2010-01-21 12:33:42 +00:00
|
|
|
'tab-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_INT,)),
|
2010-01-21 12:55:57 +00:00
|
|
|
'group-all': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2010-01-21 13:02:37 +00:00
|
|
|
'move-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING,)),
|
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
|
2010-01-12 00:33:55 +00:00
|
|
|
scrollbar_position = 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
|
2010-01-29 23:52:21 +00:00
|
|
|
origcwd = 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
|
2010-01-10 23:47:55 +00:00
|
|
|
custom_encoding = None
|
|
|
|
custom_font_size = None
|
2009-08-11 22:27:56 +00:00
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
composite_support = None
|
|
|
|
|
2010-01-10 17:15:14 +00:00
|
|
|
cnxids = None
|
2009-11-08 01:06:31 +00:00
|
|
|
|
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()
|
2010-01-04 13:11:16 +00:00
|
|
|
self.terminator.register_terminal(self)
|
|
|
|
|
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 = {}
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids = Signalman()
|
2009-08-18 11:55:37 +00:00
|
|
|
|
|
|
|
self.config = Config()
|
2009-08-11 22:27:56 +00:00
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
self.cwd = get_default_cwd()
|
2010-01-29 23:52:21 +00:00
|
|
|
self.origcwd = self.terminator.origcwd
|
2009-08-19 00:06:38 +00:00
|
|
|
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
|
2010-01-21 20:36:18 +00:00
|
|
|
else:
|
|
|
|
self.composite_support = True
|
2010-01-21 20:58:07 +00:00
|
|
|
dbg('composite_support: %s' % self.composite_support)
|
|
|
|
|
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()
|
|
|
|
|
2010-01-18 23:27:22 +00:00
|
|
|
self.titlebar = Titlebar(self)
|
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-10-15 13:17:37 +00:00
|
|
|
self.titlebar.connect('create-group', self.really_create_group)
|
2009-09-02 20:18:36 +00:00
|
|
|
|
2009-08-18 12:44:41 +00:00
|
|
|
self.searchbar = Searchbar()
|
2009-11-04 18:06:34 +00:00
|
|
|
self.searchbar.connect('end-search', self.on_search_done)
|
2009-08-18 12:44:41 +00:00
|
|
|
|
|
|
|
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'])
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def set_profile(self, _widget, profile):
|
2009-12-26 20:09:16 +00:00
|
|
|
"""Set our profile"""
|
2010-01-13 23:02:17 +00:00
|
|
|
if profile != self.config.get_profile():
|
|
|
|
self.config.set_profile(profile)
|
|
|
|
self.reconfigure()
|
2009-12-26 20:09:16 +00:00
|
|
|
|
|
|
|
def get_profile(self):
|
|
|
|
"""Return our profile name"""
|
|
|
|
return(self.config.profile)
|
|
|
|
|
2009-11-04 23:42:54 +00:00
|
|
|
def close(self):
|
|
|
|
"""Close ourselves"""
|
2009-12-09 13:02:45 +00:00
|
|
|
dbg('Terminal::close: emitting close-term')
|
2009-11-04 23:42:54 +00:00
|
|
|
self.emit('close-term')
|
2010-01-25 13:00:29 +00:00
|
|
|
try:
|
|
|
|
os.kill(self.pid, signal.SIGHUP)
|
|
|
|
except:
|
|
|
|
# We really don't want to care if this failed. Deep OS voodoo is
|
|
|
|
# not what we should be doing.
|
|
|
|
pass
|
2009-11-04 23:42:54 +00:00
|
|
|
|
2009-08-19 00:06:38 +00:00
|
|
|
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())
|
2010-01-12 00:33:55 +00:00
|
|
|
self.scrollbar.set_no_show_all(True)
|
|
|
|
self.scrollbar_position = self.config['scrollbar_position']
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2010-01-12 00:33:55 +00:00
|
|
|
if self.scrollbar_position not in ('hidden', 'disabled'):
|
2009-10-06 23:08:13 +00:00
|
|
|
self.scrollbar.show()
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2010-01-12 00:33:55 +00:00
|
|
|
if self.scrollbar_position == 'left':
|
2009-08-19 00:06:38 +00:00
|
|
|
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-11-14 23:12:58 +00:00
|
|
|
dbg ('Terminal::update_url_matches: Trying POSIX URL regexps')
|
2009-08-18 11:55:37 +00:00
|
|
|
lboundry = "[[:<:]]"
|
|
|
|
rboundry = "[[:>:]]"
|
|
|
|
else: # GNU
|
2009-11-14 23:12:58 +00:00
|
|
|
dbg ('Terminal::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:
|
2009-12-10 11:52:26 +00:00
|
|
|
err ('Terminal::update_url_matches: POSIX failed, trying GNU')
|
2009-08-18 11:55:37 +00:00
|
|
|
self.update_url_matches(posix = False)
|
|
|
|
else:
|
2009-12-10 11:52:26 +00:00
|
|
|
err ('Terminal::update_url_matches: Failed adding URL matches')
|
2009-08-18 11:55:37 +00:00
|
|
|
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 +
|
2010-01-14 13:52:48 +00:00
|
|
|
"(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9]" +
|
2010-01-19 19:44:23 +00:00
|
|
|
"[a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+" +
|
2010-01-14 13:52:48 +00:00
|
|
|
"[.a-zA-Z0-9-]*" + rboundry)
|
2009-08-19 00:06:38 +00:00
|
|
|
self.matches['nntp'] = self.vte.match_add (lboundry +
|
2010-01-19 19:44:23 +00:00
|
|
|
"""news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@""" +
|
2010-01-14 13:52:48 +00:00
|
|
|
"[-A-Za-z0-9.]+(:[0-9]+)?" + rboundry)
|
2009-08-18 11:55:37 +00:00
|
|
|
|
2009-12-17 23:17:32 +00:00
|
|
|
# Now add any matches from plugins
|
|
|
|
try:
|
|
|
|
registry = plugin.PluginRegistry()
|
|
|
|
registry.load_plugins()
|
|
|
|
plugins = registry.get_plugins_by_capability('url_handler')
|
|
|
|
|
|
|
|
for urlplugin in plugins:
|
|
|
|
name = urlplugin.handler_name
|
|
|
|
match = urlplugin.match
|
|
|
|
self.matches[name] = self.vte.match_add(match)
|
|
|
|
dbg('Terminal::update_matches: added plugin URL handler \
|
2009-12-30 01:05:51 +00:00
|
|
|
for %s (%s)' % (name, urlplugin.__class__.__name__))
|
2009-12-30 01:50:47 +00:00
|
|
|
except Exception, ex:
|
2009-12-17 23:17:32 +00:00
|
|
|
err('Terminal::update_url_matches: %s' % ex)
|
|
|
|
|
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),
|
2009-10-27 23:05:12 +00:00
|
|
|
(self.titlebar, gtk.gdk.BUTTON1_MASK)]:
|
2009-08-19 00:06:38 +00:00
|
|
|
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)
|
|
|
|
|
2010-01-18 19:48:24 +00:00
|
|
|
# FIXME: Shouldn't this be in configure()?
|
2009-08-19 00:06:38 +00:00
|
|
|
if self.config['copy_on_selection']:
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.new(self.vte, 'selection-changed',
|
2010-01-10 17:15:14 +00:00
|
|
|
lambda widget: self.vte.copy_clipboard())
|
2009-08-19 00:06:38 +00:00
|
|
|
|
|
|
|
if self.composite_support:
|
2010-01-21 20:36:18 +00:00
|
|
|
self.vte.connect('composited-changed', self.reconfigure)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
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('size-allocate', self.on_vte_size_allocate)
|
|
|
|
|
|
|
|
self.vte.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
|
|
|
self.vte.connect('enter_notify_event',
|
|
|
|
self.on_vte_notify_enter)
|
|
|
|
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.new(self.vte, 'realize', self.reconfigure)
|
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
|
|
|
|
|
2009-11-04 23:28:09 +00:00
|
|
|
item = gtk.MenuItem(_('New group...'))
|
2009-09-02 23:52:36 +00:00
|
|
|
item.connect('activate', self.create_group)
|
|
|
|
menu.append(item)
|
2009-11-20 05:40:31 +00:00
|
|
|
|
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-11-04 23:42:54 +00:00
|
|
|
self.terminator.closegroupedterms(self.group))
|
2009-09-04 21:12:13 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
groupitem = None
|
|
|
|
|
2009-11-20 06:11:12 +00:00
|
|
|
for key, value in {_('Broadcast all'):'all',
|
2009-09-04 21:12:13 +00:00
|
|
|
_('Broadcast group'):'group',
|
2009-11-20 06:11:12 +00:00
|
|
|
_('Broadcast off'):'off'}.items():
|
2009-09-04 21:12:13 +00:00
|
|
|
groupitem = gtk.RadioMenuItem(groupitem, key)
|
2009-11-20 06:11:12 +00:00
|
|
|
dbg('Terminal::populate_group_menu: %s active: %s' %
|
|
|
|
(key, self.terminator.groupsend ==
|
|
|
|
self.terminator.groupsend_type[value]))
|
2009-09-04 21:12:13 +00:00
|
|
|
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'))
|
2009-11-09 22:33:17 +00:00
|
|
|
item.set_active(self.config['split_to_group'])
|
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'))
|
2009-11-09 22:33:17 +00:00
|
|
|
item.set_active(self.config['autoclean_groups'])
|
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"""
|
2010-01-23 00:50:28 +00:00
|
|
|
_screen_w = gtk.gdk.screen_width()
|
2009-09-02 23:52:36 +00:00
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
|
2010-01-21 13:23:39 +00:00
|
|
|
if gtk.gtk_version >= (2, 14):
|
|
|
|
widget_win = widget.get_window()
|
|
|
|
else:
|
|
|
|
widget_win = widget.window
|
2009-09-02 23:52:36 +00:00
|
|
|
widget_x, widget_y = widget_win.get_origin()
|
2010-01-23 00:50:28 +00:00
|
|
|
_widget_w, widget_h = widget_win.get_size()
|
2009-09-02 23:52:36 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
_menu_w, menu_h = menu.size_request()
|
2009-09-02 23:52:36 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def set_group(self, _item, name):
|
2009-11-04 23:28:09 +00:00
|
|
|
"""Set a particular group"""
|
|
|
|
if self.group == name:
|
|
|
|
# already in this group, no action needed
|
|
|
|
return
|
2009-11-20 06:18:21 +00:00
|
|
|
dbg('Terminal::set_group: Setting group to %s' % name)
|
2009-11-04 23:28:09 +00:00
|
|
|
self.group = name
|
|
|
|
self.titlebar.set_group_label(name)
|
|
|
|
self.terminator.group_hoover()
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def create_group(self, _item):
|
2009-10-15 13:17:37 +00:00
|
|
|
"""Trigger the creation of a group via the titlebar (because popup
|
|
|
|
windows are really lame)"""
|
|
|
|
self.titlebar.create_group()
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def really_create_group(self, _widget, groupname):
|
2009-10-15 13:17:37 +00:00
|
|
|
"""The titlebar has spoken, let a group be created"""
|
2009-10-27 23:05:12 +00:00
|
|
|
self.terminator.create_group(groupname)
|
2009-11-04 23:28:09 +00:00
|
|
|
self.set_group(None, groupname)
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def ungroup(self, _widget, data):
|
2009-11-04 23:28:09 +00:00
|
|
|
"""Remove a group"""
|
|
|
|
# FIXME: Could we emit and have Terminator do this?
|
|
|
|
for term in self.terminator.terminals:
|
|
|
|
if term.group == data:
|
|
|
|
term.set_group(None, None)
|
|
|
|
self.terminator.group_hoover()
|
2009-09-02 23:52:36 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def set_groupsend(self, _widget, value):
|
2009-09-04 21:12:13 +00:00
|
|
|
"""Set the groupsend mode"""
|
|
|
|
# FIXME: Can we think of a smarter way of doing this than poking?
|
2009-11-20 06:11:12 +00:00
|
|
|
if value in self.terminator.groupsend_type.values():
|
|
|
|
dbg('Terminal::set_groupsend: setting groupsend to %s' % value)
|
2009-10-27 23:05:12 +00:00
|
|
|
self.terminator.groupsend = value
|
2009-09-04 21:12:13 +00:00
|
|
|
|
|
|
|
def do_splittogroup_toggle(self):
|
|
|
|
"""Toggle the splittogroup mode"""
|
2009-11-09 22:33:17 +00:00
|
|
|
self.config['split_to_group'] = not self.config['split_to_group']
|
2009-09-04 21:12:13 +00:00
|
|
|
|
|
|
|
def do_autocleangroups_toggle(self):
|
|
|
|
"""Toggle the autocleangroups mode"""
|
2009-11-09 22:33:17 +00:00
|
|
|
self.config['autoclean_groups'] = not self.config['autoclean_groups']
|
2009-09-04 21:12:13 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def reconfigure(self, _widget=None):
|
2009-08-19 00:06:38 +00:00
|
|
|
"""Reconfigure our settings"""
|
2009-11-08 01:06:31 +00:00
|
|
|
dbg('Terminal::reconfigure')
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.remove_signal(self.vte, 'realize')
|
2010-01-10 17:35:03 +00:00
|
|
|
|
|
|
|
# Handle child command exiting
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.remove_signal(self.vte, 'child-exited')
|
2010-01-10 17:35:03 +00:00
|
|
|
|
|
|
|
if self.config['exit_action'] == 'restart':
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.new(self.vte, 'child-exited', self.spawn_child)
|
2010-01-10 17:35:03 +00:00
|
|
|
elif self.config['exit_action'] in ('close', 'left'):
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.new(self.vte, 'child-exited',
|
2010-01-10 17:35:03 +00:00
|
|
|
lambda x: self.emit('close-term'))
|
2009-11-08 01:06:31 +00:00
|
|
|
|
2010-01-10 23:47:55 +00:00
|
|
|
self.vte.set_emulation(self.config['emulation'])
|
|
|
|
if self.custom_encoding != True:
|
|
|
|
self.vte.set_encoding(self.config['encoding'])
|
|
|
|
self.vte.set_word_chars(self.config['word_chars'])
|
|
|
|
self.vte.set_mouse_autohide(self.config['mouse_autohide'])
|
|
|
|
|
|
|
|
backspace = self.config['backspace_binding']
|
|
|
|
delete = self.config['delete_binding']
|
|
|
|
|
|
|
|
try:
|
|
|
|
if backspace == 'ascii-del':
|
2010-01-24 15:45:47 +00:00
|
|
|
backbind = vte.ERASE_ASCII_DELETE
|
|
|
|
elif backspace == 'control-h':
|
2010-01-10 23:47:55 +00:00
|
|
|
backbind = vte.ERASE_ASCII_BACKSPACE
|
2010-01-24 15:45:47 +00:00
|
|
|
elif backspace == 'escape-sequence':
|
|
|
|
backbind = vte.ERASE_DELETE_SEQUENCE
|
2010-01-10 23:47:55 +00:00
|
|
|
else:
|
2010-01-23 00:50:28 +00:00
|
|
|
backbind = vte.ERASE_AUTO
|
2010-01-10 23:47:55 +00:00
|
|
|
except AttributeError:
|
|
|
|
if backspace == 'ascii-del':
|
|
|
|
backbind = 2
|
2010-01-24 15:45:47 +00:00
|
|
|
elif backspace == 'control-h':
|
2010-01-10 23:47:55 +00:00
|
|
|
backbind = 1
|
2010-01-24 15:45:47 +00:00
|
|
|
elif backspace == 'escape-sequence':
|
|
|
|
backbind = 3
|
|
|
|
else:
|
|
|
|
backbind = 0
|
2010-01-10 23:47:55 +00:00
|
|
|
|
|
|
|
try:
|
2010-01-24 15:45:47 +00:00
|
|
|
if delete == 'ascii-del':
|
|
|
|
delbind = vte.ERASE_ASCII_DELETE
|
|
|
|
elif delete == 'control-h':
|
|
|
|
delbind = vte.ERASE_ASCII_BACKSPACE
|
|
|
|
elif delete == 'escape-sequence':
|
2010-01-10 23:47:55 +00:00
|
|
|
delbind = vte.ERASE_DELETE_SEQUENCE
|
|
|
|
else:
|
|
|
|
delbind = vte.ERASE_AUTO
|
|
|
|
except AttributeError:
|
2010-01-24 15:45:47 +00:00
|
|
|
if delete == 'ascii-del':
|
|
|
|
delbind = 2
|
|
|
|
elif delete == 'control-h':
|
|
|
|
delbind = 1
|
|
|
|
elif delete == 'escape-sequence':
|
2010-01-10 23:47:55 +00:00
|
|
|
delbind = 3
|
|
|
|
else:
|
|
|
|
delbind = 0
|
|
|
|
|
|
|
|
self.vte.set_backspace_binding(backbind)
|
|
|
|
self.vte.set_delete_binding(delbind)
|
|
|
|
|
|
|
|
if not self.custom_font_size:
|
|
|
|
try:
|
2010-01-21 21:39:05 +00:00
|
|
|
if self.config['use_system_font'] == True:
|
|
|
|
font = self.config.get_system_font()
|
|
|
|
else:
|
|
|
|
font = self.config['font']
|
|
|
|
self.vte.set_font(pango.FontDescription(font))
|
2010-01-10 23:47:55 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
self.vte.set_allow_bold(self.config['allow_bold'])
|
|
|
|
if self.config['use_theme_colors']:
|
|
|
|
fgcolor = self.vte.get_style().text[gtk.STATE_NORMAL]
|
|
|
|
bgcolor = self.vte.get_style().base[gtk.STATE_NORMAL]
|
|
|
|
else:
|
|
|
|
fgcolor = gtk.gdk.color_parse(self.config['foreground_color'])
|
|
|
|
bgcolor = gtk.gdk.color_parse(self.config['background_color'])
|
|
|
|
|
|
|
|
colors = self.config['palette'].split(':')
|
|
|
|
palette = []
|
|
|
|
for color in colors:
|
|
|
|
if color:
|
|
|
|
palette.append(gtk.gdk.color_parse(color))
|
|
|
|
self.vte.set_colors(fgcolor, bgcolor, palette)
|
|
|
|
if self.config['cursor_color'] != '':
|
2010-01-23 00:50:28 +00:00
|
|
|
self.vte.set_color_cursor(gtk.gdk.color_parse(
|
|
|
|
self.config['cursor_color']))
|
2010-01-10 23:47:55 +00:00
|
|
|
if hasattr(self.vte, 'set_cursor_shape'):
|
|
|
|
self.vte.set_cursor_shape(getattr(vte, 'CURSOR_SHAPE_' +
|
|
|
|
self.config['cursor_shape'].upper()))
|
|
|
|
|
|
|
|
background_type = self.config['background_type']
|
2010-01-21 20:58:07 +00:00
|
|
|
dbg('background_type=%s' % background_type)
|
2010-01-10 23:47:55 +00:00
|
|
|
if background_type == 'image' and \
|
|
|
|
self.config['background_image'] is not None and \
|
|
|
|
self.config['background_image'] != '':
|
|
|
|
self.vte.set_background_image_file(self.config['background_image'])
|
|
|
|
self.vte.set_scroll_background(self.config['scroll_background'])
|
|
|
|
else:
|
|
|
|
self.vte.set_background_image_file('')
|
|
|
|
self.vte.set_scroll_background(False)
|
|
|
|
|
|
|
|
if background_type in ('image', 'transparent'):
|
2010-01-23 00:50:28 +00:00
|
|
|
self.vte.set_background_tint_color(gtk.gdk.color_parse(
|
|
|
|
self.config['background_color']))
|
2010-01-21 20:58:07 +00:00
|
|
|
opacity = int(self.config['background_darkness'] * 65536)
|
2010-01-21 20:36:18 +00:00
|
|
|
saturation = 1.0 - float(self.config['background_darkness'])
|
|
|
|
dbg('setting background saturation: %f' % saturation)
|
|
|
|
self.vte.set_background_saturation(saturation)
|
2010-01-10 23:47:55 +00:00
|
|
|
else:
|
2010-01-21 20:58:07 +00:00
|
|
|
dbg('setting background_saturation: 1')
|
|
|
|
opacity = 65535
|
2010-01-10 23:47:55 +00:00
|
|
|
self.vte.set_background_saturation(1)
|
|
|
|
|
|
|
|
if self.composite_support:
|
2010-01-21 20:36:18 +00:00
|
|
|
dbg('setting opacity: %d' % opacity)
|
2010-01-10 23:47:55 +00:00
|
|
|
self.vte.set_opacity(opacity)
|
2010-01-21 20:58:07 +00:00
|
|
|
|
2010-01-21 20:36:18 +00:00
|
|
|
if self.config['background_type'] == 'transparent' and \
|
|
|
|
self.config['enable_real_transparency'] == False:
|
2010-01-21 20:58:07 +00:00
|
|
|
dbg('setting background_transparent=True')
|
2010-01-10 23:47:55 +00:00
|
|
|
self.vte.set_background_transparent(True)
|
2010-01-21 20:58:07 +00:00
|
|
|
else:
|
|
|
|
dbg('setting background_transparent=False')
|
2010-01-21 20:36:18 +00:00
|
|
|
self.vte.set_background_transparent(False)
|
2010-01-10 23:47:55 +00:00
|
|
|
|
|
|
|
self.vte.set_cursor_blinks(self.config['cursor_blink'])
|
|
|
|
|
|
|
|
if self.config['force_no_bell'] == True:
|
|
|
|
self.vte.set_audible_bell(False)
|
|
|
|
self.vte.set_visible_bell(False)
|
2010-01-21 12:14:12 +00:00
|
|
|
self.cnxids.remove_signal(self.vte, 'beep')
|
2010-01-10 23:47:55 +00:00
|
|
|
else:
|
|
|
|
self.vte.set_audible_bell(self.config['audible_bell'])
|
|
|
|
self.vte.set_visible_bell(self.config['visible_bell'])
|
2010-01-21 12:14:12 +00:00
|
|
|
self.cnxids.remove_signal(self.vte, 'beep')
|
2010-01-10 23:47:55 +00:00
|
|
|
if self.config['urgent_bell'] == True:
|
2010-01-21 00:13:56 +00:00
|
|
|
try:
|
|
|
|
self.cnxids.new(self.vte, 'beep', self.on_beep)
|
|
|
|
except TypeError:
|
|
|
|
err('beep signal unavailable with this version of VTE')
|
2010-01-10 23:47:55 +00:00
|
|
|
|
|
|
|
self.vte.set_scrollback_lines(self.config['scrollback_lines'])
|
|
|
|
self.vte.set_scroll_on_keystroke(self.config['scroll_on_keystroke'])
|
|
|
|
self.vte.set_scroll_on_output(self.config['scroll_on_output'])
|
|
|
|
|
2010-01-12 00:33:55 +00:00
|
|
|
if self.scrollbar_position != self.config['scrollbar_position']:
|
|
|
|
self.scrollbar_position = self.config['scrollbar_position']
|
2010-01-21 22:38:52 +00:00
|
|
|
if self.config['scrollbar_position'] in ['disabled', 'hidden']:
|
2010-01-12 00:33:55 +00:00
|
|
|
self.scrollbar.hide()
|
|
|
|
else:
|
|
|
|
self.scrollbar.show()
|
|
|
|
if self.config['scrollbar_position'] == 'left':
|
|
|
|
self.reorder_child(self.scrollbar, 0)
|
|
|
|
elif self.config['scrollbar_position'] == 'right':
|
|
|
|
self.reorder_child(self.vte, 0)
|
2010-01-10 23:47:55 +00:00
|
|
|
|
|
|
|
if hasattr(self.vte, 'set_alternate_screen_scroll'):
|
2010-01-23 00:50:28 +00:00
|
|
|
self.vte.set_alternate_screen_scroll(
|
|
|
|
self.config['alternate_screen_scroll'])
|
2010-01-10 23:47:55 +00:00
|
|
|
|
|
|
|
self.titlebar.update()
|
|
|
|
self.vte.queue_draw()
|
2009-08-19 00:06:38 +00:00
|
|
|
|
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)
|
|
|
|
|
2009-12-10 11:52:26 +00:00
|
|
|
if mapping and mapping not in ['close_window',
|
|
|
|
'full_screen',
|
|
|
|
'new_tab']:
|
2009-10-14 12:05:07 +00:00
|
|
|
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):
|
2009-10-28 12:53:18 +00:00
|
|
|
if self.vte.get_has_selection ():
|
2009-10-14 12:05:07 +00:00
|
|
|
getattr(self, "key_" + mapping)()
|
|
|
|
return(True)
|
2009-10-28 12:53:18 +00:00
|
|
|
else:
|
|
|
|
getattr(self, "key_" + mapping)()
|
|
|
|
return(True)
|
2009-10-14 12:05:07 +00:00
|
|
|
|
|
|
|
# FIXME: This is all clearly wrong. We should be doing this better
|
2010-01-20 23:46:13 +00:00
|
|
|
# maybe we can emit the key event and let Terminator() care?
|
|
|
|
groupsend = self.terminator.groupsend
|
|
|
|
groupsend_type = self.terminator.groupsend_type
|
|
|
|
if groupsend != groupsend_type['off'] and self.vte.is_focus():
|
|
|
|
if self.group and groupsend == groupsend_type['group']:
|
2009-10-14 12:05:07 +00:00
|
|
|
self.terminator.group_emit(self, self.group, 'key-press-event',
|
|
|
|
event)
|
2010-01-20 23:46:13 +00:00
|
|
|
if groupsend == groupsend_type['all']:
|
2009-10-14 12:05:07 +00:00
|
|
|
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):
|
2010-01-23 00:50:28 +00:00
|
|
|
"""Show or hide the terminal scrollbar"""
|
2009-10-06 23:08:13 +00:00
|
|
|
self.toggle_widget_visibility(self.scrollbar)
|
|
|
|
|
|
|
|
def toggle_widget_visibility(self, widget):
|
2010-01-23 00:50:28 +00:00
|
|
|
"""Show or hide a widget"""
|
2009-10-06 23:08:13 +00:00
|
|
|
if widget.get_property('visible'):
|
|
|
|
widget.hide()
|
|
|
|
else:
|
|
|
|
widget.show()
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_encoding_change(self, _widget, encoding):
|
2009-10-08 20:27:00 +00:00
|
|
|
"""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)
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_drag_begin(self, widget, drag_context, _data):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""Handle the start of a drag event"""
|
|
|
|
widget.drag_source_set_icon_pixbuf(util.widget_pixbuf(self, 512))
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_drag_data_get(self, _widget, _drag_context, selection_data, info,
|
|
|
|
_time, data):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""I have no idea what this does, drag and drop is a mystery. sorry."""
|
|
|
|
selection_data.set('vte', info,
|
|
|
|
str(data.terminator.terminals.index(self)))
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_drag_motion(self, widget, drag_context, x, y, _time, _data):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""*shrug*"""
|
|
|
|
if 'text/plain' in drag_context.targets:
|
|
|
|
# copy text from another widget
|
|
|
|
return
|
|
|
|
srcwidget = drag_context.get_source_widget()
|
|
|
|
if(isinstance(srcwidget, gtk.EventBox) and
|
|
|
|
srcwidget == self.titlebar) or widget == srcwidget:
|
|
|
|
# on self
|
|
|
|
return
|
|
|
|
|
|
|
|
alloc = widget.allocation
|
|
|
|
rect = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height)
|
|
|
|
|
|
|
|
if self.config['use_theme_colors']:
|
|
|
|
color = self.vte.get_style().text[gtk.STATE_NORMAL]
|
|
|
|
else:
|
|
|
|
color = gtk.gdk.color_parse(self.config['foreground_color'])
|
|
|
|
|
|
|
|
pos = self.get_location(widget, x, y)
|
2010-01-23 00:50:28 +00:00
|
|
|
topleft = (0, 0)
|
|
|
|
topright = (alloc.width, 0)
|
|
|
|
topmiddle = (alloc.width/2, 0)
|
2009-10-27 23:05:12 +00:00
|
|
|
bottomleft = (0, alloc.height)
|
2010-01-23 00:50:28 +00:00
|
|
|
bottomright = (alloc.width, alloc.height)
|
2009-10-27 23:05:12 +00:00
|
|
|
bottommiddle = (alloc.width/2, alloc.height)
|
|
|
|
middleleft = (0, alloc.height/2)
|
|
|
|
middleright = (alloc.width, alloc.height/2)
|
|
|
|
#print "%f %f %d %d" %(coef1, coef2, b1,b2)
|
|
|
|
coord = ()
|
|
|
|
if pos == "right":
|
|
|
|
coord = (topright, topmiddle, bottommiddle, bottomright)
|
|
|
|
elif pos == "top":
|
|
|
|
coord = (topleft, topright, middleright , middleleft)
|
|
|
|
elif pos == "left":
|
|
|
|
coord = (topleft, topmiddle, bottommiddle, bottomleft)
|
|
|
|
elif pos == "bottom":
|
|
|
|
coord = (bottomleft, bottomright, middleright , middleleft)
|
|
|
|
|
|
|
|
#here, we define some widget internal values
|
|
|
|
widget._expose_data = { 'color': color, 'coord' : coord }
|
|
|
|
#redraw by forcing an event
|
|
|
|
connec = widget.connect_after('expose-event', self.on_expose_event)
|
|
|
|
widget.window.invalidate_rect(rect, True)
|
|
|
|
widget.window.process_updates(True)
|
|
|
|
#finaly reset the values
|
|
|
|
widget.disconnect(connec)
|
|
|
|
widget._expose_data = None
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_expose_event(self, widget, _event):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""Handle an expose event while dragging"""
|
|
|
|
if not widget._expose_data:
|
|
|
|
return(False)
|
|
|
|
|
|
|
|
color = widget._expose_data['color']
|
|
|
|
coord = widget._expose_data['coord']
|
|
|
|
|
|
|
|
context = widget.window.cairo_create()
|
|
|
|
context.set_source_rgba(color.red, color.green, color.blue, 0.5)
|
|
|
|
if len(coord) > 0 :
|
2010-01-23 00:50:28 +00:00
|
|
|
context.move_to(coord[len(coord)-1][0], coord[len(coord)-1][1])
|
2009-10-27 23:05:12 +00:00
|
|
|
for i in coord:
|
2010-01-23 00:50:28 +00:00
|
|
|
context.line_to(i[0], i[1])
|
2009-10-27 23:05:12 +00:00
|
|
|
|
|
|
|
context.fill()
|
|
|
|
return(False)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
|
2010-01-23 00:50:28 +00:00
|
|
|
_info, _time, data):
|
|
|
|
"""Something has been dragged into the terminal. Handle it as either a
|
|
|
|
URL or another terminal."""
|
2009-10-27 23:05:12 +00:00
|
|
|
if selection_data.type == 'text/plain':
|
|
|
|
# copy text to destination
|
|
|
|
txt = selection_data.data.strip()
|
|
|
|
if txt[0:7] == 'file://':
|
2010-01-23 00:50:28 +00:00
|
|
|
txt = "'%s'" % urllib.unquote(txt[7:])
|
2010-01-20 12:11:02 +00:00
|
|
|
for term in self.terminator.get_target_terms(self):
|
2009-10-27 23:05:12 +00:00
|
|
|
term.feed(txt)
|
|
|
|
return
|
|
|
|
|
|
|
|
widgetsrc = data.terminator.terminals[int(selection_data.data)]
|
|
|
|
srcvte = drag_context.get_source_widget()
|
|
|
|
#check if computation requireds
|
|
|
|
if (isinstance(srcvte, gtk.EventBox) and
|
|
|
|
srcvte == self.titlebar) or srcvte == widget:
|
|
|
|
return
|
|
|
|
|
|
|
|
srchbox = widgetsrc
|
|
|
|
dsthbox = widget.get_parent().get_parent()
|
|
|
|
|
|
|
|
dstpaned = dsthbox.get_parent()
|
|
|
|
srcpaned = srchbox.get_parent()
|
2009-12-10 11:52:26 +00:00
|
|
|
if isinstance(dstpaned, gtk.Window) and \
|
|
|
|
isinstance(srcpaned, gtk.Window):
|
2009-10-27 23:05:12 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
pos = self.get_location(widget, x, y)
|
|
|
|
|
2009-11-17 04:56:55 +00:00
|
|
|
srcpaned.remove(widgetsrc)
|
|
|
|
dstpaned.split_axis(dsthbox, pos in ['top', 'bottom'], widgetsrc)
|
2009-11-20 15:31:07 +00:00
|
|
|
srcpaned.hoover()
|
2009-10-27 23:05:12 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def get_location(self, term, x, y):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""Get our location within the terminal"""
|
|
|
|
pos = ''
|
|
|
|
#get the diagonales function for the receiving widget
|
2010-01-23 00:50:28 +00:00
|
|
|
coef1 = float(term.allocation.height)/float(term.allocation.width)
|
|
|
|
coef2 = -float(term.allocation.height)/float(term.allocation.width)
|
2009-10-27 23:05:12 +00:00
|
|
|
b1 = 0
|
2010-01-23 00:50:28 +00:00
|
|
|
b2 = term.allocation.height
|
2009-10-27 23:05:12 +00:00
|
|
|
#determine position in rectangle
|
2010-01-23 00:50:28 +00:00
|
|
|
#--------
|
|
|
|
#|\ /|
|
|
|
|
#| \ / |
|
|
|
|
#| \/ |
|
|
|
|
#| /\ |
|
|
|
|
#| / \ |
|
|
|
|
#|/ \|
|
|
|
|
#--------
|
2009-10-27 23:05:12 +00:00
|
|
|
if (x*coef1 + b1 > y ) and (x*coef2 + b2 < y ):
|
2009-12-10 11:52:26 +00:00
|
|
|
pos = "right"
|
2009-10-27 23:05:12 +00:00
|
|
|
if (x*coef1 + b1 > y ) and (x*coef2 + b2 > y ):
|
2009-12-10 11:52:26 +00:00
|
|
|
pos = "top"
|
2009-10-27 23:05:12 +00:00
|
|
|
if (x*coef1 + b1 < y ) and (x*coef2 + b2 > y ):
|
2009-12-10 11:52:26 +00:00
|
|
|
pos = "left"
|
2009-10-27 23:05:12 +00:00
|
|
|
if (x*coef1 + b1 < y ) and (x*coef2 + b2 < y ):
|
2009-12-10 11:52:26 +00:00
|
|
|
pos = "bottom"
|
2009-10-27 23:05:12 +00:00
|
|
|
return pos
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-11-09 22:35:55 +00:00
|
|
|
def grab_focus(self):
|
2010-01-23 00:50:28 +00:00
|
|
|
"""Steal focus for this terminal"""
|
2009-11-09 22:35:55 +00:00
|
|
|
self.vte.grab_focus()
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_vte_focus(self, _widget):
|
|
|
|
"""Update our UI when we get focus"""
|
2009-10-27 23:05:12 +00:00
|
|
|
self.emit('title-change', self.get_window_title())
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_vte_focus_in(self, _widget, _event):
|
|
|
|
"""Inform other parts of the application when focus is received"""
|
2009-10-08 23:22:01 +00:00
|
|
|
self.emit('focus-in')
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-11-04 18:06:34 +00:00
|
|
|
def scrollbar_jump(self, position):
|
|
|
|
"""Move the scrollbar to a particular row"""
|
|
|
|
self.scrollbar.set_value(position)
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_search_done(self, _widget):
|
2009-11-04 18:06:34 +00:00
|
|
|
"""We've finished searching, so clean up"""
|
|
|
|
self.searchbar.hide()
|
|
|
|
self.scrollbar.set_value(self.vte.get_cursor_position()[1])
|
|
|
|
self.vte.grab_focus()
|
|
|
|
|
2010-01-23 00:50:28 +00:00
|
|
|
def on_edit_done(self, _widget):
|
2009-09-02 23:52:36 +00:00
|
|
|
"""A child widget is done editing a label, return focus to VTE"""
|
|
|
|
self.vte.grab_focus()
|
|
|
|
|
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())
|
2010-01-20 23:36:11 +00:00
|
|
|
if self.vte.window and self.config['geometry_hinting']:
|
|
|
|
window = util.get_top_window(self)
|
|
|
|
window.set_rough_geometry_hints()
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-08-19 18:02:33 +00:00
|
|
|
def on_vte_notify_enter(self, term, event):
|
2009-10-27 23:05:12 +00:00
|
|
|
"""Handle the mouse entering this terminal"""
|
2010-01-21 21:39:05 +00:00
|
|
|
sloppy = False
|
|
|
|
if self.config['focus'] == 'system':
|
|
|
|
sloppy = self.config.get_system_focus() == 'sloppy'
|
|
|
|
elif self.config['focus'] in ['sloppy', 'mouse']:
|
|
|
|
sloppy = True
|
|
|
|
if sloppy == True and self.titlebar.editing() == False:
|
|
|
|
term.grab_focus()
|
|
|
|
return(False)
|
2009-08-19 00:06:38 +00:00
|
|
|
|
2009-11-14 18:55:51 +00:00
|
|
|
def get_zoom_data(self):
|
|
|
|
"""Return a dict of information for Window"""
|
|
|
|
data = {}
|
|
|
|
data['old_font'] = self.vte.get_font()
|
|
|
|
data['old_char_height'] = self.vte.get_char_height()
|
|
|
|
data['old_char_width'] = self.vte.get_char_width()
|
|
|
|
data['old_allocation'] = self.vte.get_allocation()
|
|
|
|
data['old_padding'] = self.vte.get_padding()
|
|
|
|
data['old_columns'] = self.vte.get_column_count()
|
|
|
|
data['old_rows'] = self.vte.get_row_count()
|
|
|
|
data['old_parent'] = self.get_parent()
|
|
|
|
|
|
|
|
return(data)
|
|
|
|
|
|
|
|
def zoom_scale(self, widget, allocation, old_data):
|
|
|
|
"""Scale our font correctly based on how big we are not vs before"""
|
2010-01-18 19:48:24 +00:00
|
|
|
self.cnxids.remove_signal(self, 'zoom')
|
2009-11-14 18:55:51 +00:00
|
|
|
|
|
|
|
new_columns = self.vte.get_column_count()
|
|
|
|
new_rows = self.vte.get_row_count()
|
|
|
|
new_font = self.vte.get_font()
|
|
|
|
new_allocation = self.vte.get_allocation()
|
|
|
|
|
|
|
|
old_alloc = {'x': old_data['old_allocation'].width - \
|
|
|
|
old_data['old_padding'][0],
|
|
|
|
'y': old_data['old_allocation'].height - \
|
|
|
|
old_data['old_padding'][1]
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg('Terminal::zoom_scale: Resized from %dx%d to %dx%d' % (
|
|
|
|
old_data['old_columns'],
|
|
|
|
old_data['old_rows'],
|
|
|
|
new_columns,
|
|
|
|
new_rows))
|
|
|
|
|
2009-12-10 11:52:26 +00:00
|
|
|
if new_rows == old_data['old_rows'] or \
|
|
|
|
new_columns == old_data['old_columns']:
|
2009-11-14 18:55:51 +00:00
|
|
|
dbg('Terminal::zoom_scale: One axis unchanged, not scaling')
|
|
|
|
return
|
|
|
|
|
|
|
|
old_area = old_data['old_columns'] * old_data['old_rows']
|
|
|
|
new_area = new_columns * new_rows
|
|
|
|
area_factor = (new_area / old_area) / 2
|
|
|
|
|
2010-02-01 20:15:53 +00:00
|
|
|
new_size = int(old_data['old_font'].get_size() * area_factor)
|
|
|
|
if new_size == 0:
|
|
|
|
dbg('refusing to set a zero sized font')
|
|
|
|
return
|
|
|
|
new_font.set_size(new_size)
|
|
|
|
dbg('setting new font: %s' % new_font)
|
2009-11-14 18:55:51 +00:00
|
|
|
self.vte.set_font(new_font)
|
|
|
|
|
2009-10-06 23:08:13 +00:00
|
|
|
def is_zoomed(self):
|
|
|
|
"""Determine if we are a zoomed terminal"""
|
2009-11-14 18:55:51 +00:00
|
|
|
prop = None
|
|
|
|
parent = self.get_parent()
|
2009-11-20 22:53:06 +00:00
|
|
|
window = get_top_window(self)
|
2009-10-06 23:08:13 +00:00
|
|
|
|
|
|
|
try:
|
2009-11-14 18:55:51 +00:00
|
|
|
prop = window.get_property('term-zoomed')
|
2009-10-06 23:08:13 +00:00
|
|
|
except TypeError:
|
|
|
|
prop = False
|
|
|
|
|
|
|
|
return(prop)
|
|
|
|
|
2009-11-14 18:55:51 +00:00
|
|
|
def zoom(self, widget=None):
|
2009-10-06 23:08:13 +00:00
|
|
|
"""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
|
|
|
|
2009-11-14 18:55:51 +00:00
|
|
|
def maximise(self, widget=None):
|
2009-10-06 23:08:13 +00:00
|
|
|
"""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-11-14 18:55:51 +00:00
|
|
|
def unzoom(self, widget=None):
|
|
|
|
"""Restore normal layout"""
|
|
|
|
self.emit('unzoom')
|
|
|
|
|
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
|
|
|
|
|
2009-11-08 23:06:26 +00:00
|
|
|
self.vte.grab_focus()
|
|
|
|
|
2010-01-18 22:56:43 +00:00
|
|
|
options = self.config.options_get()
|
|
|
|
if options.command:
|
|
|
|
command = options.command
|
|
|
|
options.command = None
|
|
|
|
elif options.execute:
|
|
|
|
command = options.execute
|
|
|
|
options.execute = None
|
|
|
|
elif self.config['use_custom_command']:
|
2009-08-19 18:02:33 +00:00
|
|
|
command = self.config['custom_command']
|
|
|
|
|
2010-01-18 22:56:43 +00:00
|
|
|
if type(command) is list:
|
|
|
|
shell = util.path_lookup(command[0])
|
|
|
|
args = command
|
2009-08-19 18:02:33 +00:00
|
|
|
else:
|
2010-01-18 22:56:43 +00:00
|
|
|
shell = util.shell_lookup()
|
|
|
|
|
|
|
|
if self.config['login_shell']:
|
|
|
|
args.insert(0, "-%s" % shell)
|
|
|
|
else:
|
|
|
|
args.insert(0, shell)
|
2009-08-19 18:02:33 +00:00
|
|
|
|
2010-01-18 22:56:43 +00:00
|
|
|
if command is not None:
|
|
|
|
args += ['-c', command]
|
2009-08-19 18:02:33 +00:00
|
|
|
|
|
|
|
if shell is None:
|
|
|
|
self.vte.feed(_('Unable to find a shell'))
|
|
|
|
return(-1)
|
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
try:
|
|
|
|
os.putenv('WINDOWID', '%s' % self.vte.get_parent_window().xid)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2009-08-19 18:02:33 +00:00
|
|
|
|
2010-01-18 22:56:43 +00:00
|
|
|
dbg('Forking shell: "%s" with args: %s' % (shell, args))
|
2009-08-19 18:02:33 +00:00
|
|
|
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-12-17 23:17:32 +00:00
|
|
|
elif match in self.matches.values():
|
|
|
|
# We have a match, but it's not a hard coded one, so it's a plugin
|
|
|
|
try:
|
|
|
|
registry = plugin.PluginRegistry()
|
|
|
|
registry.load_plugins()
|
|
|
|
plugins = registry.get_plugins_by_capability('url_handler')
|
|
|
|
|
|
|
|
for urlplugin in plugins:
|
|
|
|
if match == self.matches[urlplugin.handler_name]:
|
|
|
|
newurl = urlplugin.callback(url)
|
|
|
|
if newurl is not None:
|
2009-12-30 01:05:51 +00:00
|
|
|
dbg('Terminal::prepare_url: URL prepared by \
|
|
|
|
%s plugin' % urlplugin.handler_name)
|
2009-12-17 23:17:32 +00:00
|
|
|
url = newurl
|
2010-01-23 00:50:28 +00:00
|
|
|
break
|
2009-12-30 01:50:47 +00:00
|
|
|
except Exception, ex:
|
2009-12-17 23:17:32 +00:00
|
|
|
err('Terminal::prepare_url: %s' % ex)
|
|
|
|
|
|
|
|
return(url)
|
2009-09-04 19:12:35 +00:00
|
|
|
|
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-11-04 18:06:34 +00:00
|
|
|
for term in self.terminator.get_target_terms(self):
|
2009-09-04 21:48:35 +00:00
|
|
|
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-10-28 23:07:42 +00:00
|
|
|
def zoom_in(self):
|
|
|
|
"""Increase the font size"""
|
|
|
|
self.zoom_font(True)
|
|
|
|
|
|
|
|
def zoom_out(self):
|
|
|
|
"""Decrease the font size"""
|
|
|
|
self.zoom_font(False)
|
|
|
|
|
|
|
|
def zoom_font(self, zoom_in):
|
|
|
|
"""Change the font size"""
|
|
|
|
pangodesc = self.vte.get_font()
|
|
|
|
fontsize = pangodesc.get_size()
|
|
|
|
|
|
|
|
if fontsize > pango.SCALE and not zoom_in:
|
|
|
|
fontsize -= pango.SCALE
|
|
|
|
elif zoom_in:
|
|
|
|
fontsize += pango.SCALE
|
|
|
|
|
|
|
|
pangodesc.set_size(fontsize)
|
|
|
|
self.vte.set_font(pangodesc)
|
2010-01-10 23:47:55 +00:00
|
|
|
self.custom_font_size = fontsize
|
2009-10-28 23:07:42 +00:00
|
|
|
|
|
|
|
def zoom_orig(self):
|
|
|
|
"""Restore original font size"""
|
2010-01-21 21:39:05 +00:00
|
|
|
if self.config['use_system_font'] == True:
|
|
|
|
font = self.config.get_system_font()
|
|
|
|
else:
|
|
|
|
font = self.config['font']
|
|
|
|
dbg("Terminal::zoom_orig: restoring font to: %s" % font)
|
|
|
|
self.vte.set_font(pango.FontDescription(font))
|
2010-01-10 23:47:55 +00:00
|
|
|
self.custom_font_size = None
|
2009-10-28 23:07:42 +00:00
|
|
|
|
2010-01-20 00:54:35 +00:00
|
|
|
def get_cursor_position(self):
|
|
|
|
"""Return the co-ordinates of our cursor"""
|
|
|
|
col, row = self.vte.get_cursor_position()
|
|
|
|
width = self.vte.get_char_width()
|
|
|
|
height = self.vte.get_char_height()
|
|
|
|
return((col * width, row * height))
|
|
|
|
|
2010-01-20 23:36:11 +00:00
|
|
|
def get_font_size(self):
|
|
|
|
"""Return the width/height of our font"""
|
|
|
|
return((self.vte.get_char_width(), self.vte.get_char_height()))
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
"""Return the column/rows of the terminal"""
|
|
|
|
return((self.vte.get_column_count(), self.vte.get_row_count()))
|
|
|
|
|
2010-01-21 00:13:56 +00:00
|
|
|
def on_beep(self, widget):
|
|
|
|
"""Set the urgency hint for our window"""
|
|
|
|
window = util.get_top_window(self)
|
|
|
|
window.set_urgency_hint(True)
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
def describe_layout(self, count, parent, global_layout):
|
2010-02-01 12:11:44 +00:00
|
|
|
"""Describe our layout"""
|
|
|
|
layout = {}
|
|
|
|
layout['type'] = 'Terminal'
|
2010-02-02 00:39:41 +00:00
|
|
|
layout['parent'] = parent
|
|
|
|
name = 'terminal%d' % count
|
|
|
|
count = count + 1
|
|
|
|
global_layout[name] = layout
|
|
|
|
return(count)
|
2010-02-01 12:11:44 +00:00
|
|
|
|
|
|
|
def create_layout(self, layout):
|
|
|
|
"""Apply our layout"""
|
|
|
|
print "Terminal::create_layout: Unimplemented. %s" % layout
|
|
|
|
|
2009-10-28 12:53:18 +00:00
|
|
|
# There now begins a great list of keyboard event handlers
|
|
|
|
def key_zoom_in(self):
|
2009-10-28 23:07:42 +00:00
|
|
|
self.zoom_in()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_zoom_out(self):
|
2009-10-28 23:07:42 +00:00
|
|
|
self.zoom_out()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_copy(self):
|
|
|
|
self.vte.copy_clipboard()
|
|
|
|
|
|
|
|
def key_paste(self):
|
2009-11-04 18:06:34 +00:00
|
|
|
self.vte.paste_clipboard()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_toggle_scrollbar(self):
|
|
|
|
self.do_scrollbar_toggle()
|
|
|
|
|
|
|
|
def key_zoom_normal(self):
|
|
|
|
self.zoom_orig ()
|
|
|
|
|
|
|
|
def key_search(self):
|
2009-11-04 18:06:34 +00:00
|
|
|
self.searchbar.start_search()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
# bindings that should be moved to Terminator as they all just call
|
|
|
|
# a function of Terminator. It would be cleaner if TerminatorTerm
|
|
|
|
# has absolutely no reference to Terminator.
|
|
|
|
# N (next) - P (previous) - O (horizontal) - E (vertical) - W (close)
|
2010-01-18 20:39:46 +00:00
|
|
|
def key_cycle_next(self):
|
|
|
|
self.key_go_next()
|
|
|
|
|
|
|
|
def key_cycle_prev(self):
|
|
|
|
self.key_go_prev()
|
|
|
|
|
2009-10-28 12:53:18 +00:00
|
|
|
def key_go_next(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'next')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_go_prev(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'prev')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_go_up(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'up')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_go_down(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'down')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_go_left(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'left')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_go_right(self):
|
2009-11-09 22:33:17 +00:00
|
|
|
self.emit('navigate', 'right')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_split_horiz(self):
|
|
|
|
self.emit('split-horiz')
|
|
|
|
|
|
|
|
def key_split_vert(self):
|
|
|
|
self.emit('split-vert')
|
|
|
|
|
|
|
|
def key_close_term(self):
|
2009-11-21 18:11:50 +00:00
|
|
|
self.close()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_resize_up(self):
|
2009-11-08 23:06:26 +00:00
|
|
|
self.emit('resize-term', 'up')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_resize_down(self):
|
2009-11-08 23:06:26 +00:00
|
|
|
self.emit('resize-term', 'down')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_resize_left(self):
|
2009-11-08 23:06:26 +00:00
|
|
|
self.emit('resize-term', 'left')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_resize_right(self):
|
2009-11-08 23:06:26 +00:00
|
|
|
self.emit('resize-term', 'right')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_move_tab_right(self):
|
2010-01-21 13:02:37 +00:00
|
|
|
self.emit('move-tab', 'right')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_move_tab_left(self):
|
2010-01-21 13:02:37 +00:00
|
|
|
self.emit('move-tab', 'left')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_toggle_zoom(self):
|
2009-11-14 18:55:51 +00:00
|
|
|
if self.is_zoomed():
|
|
|
|
self.unzoom()
|
|
|
|
else:
|
|
|
|
self.maximise()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_scaled_zoom(self):
|
2009-11-14 18:55:51 +00:00
|
|
|
if self.is_zoomed():
|
|
|
|
self.unzoom()
|
|
|
|
else:
|
|
|
|
self.zoom()
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_next_tab(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', -1)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_prev_tab(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', -2)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_1(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 0)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_2(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 1)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_3(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 2)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_4(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 3)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_5(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 4)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_6(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 5)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_7(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 6)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_8(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 7)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_9(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 8)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_switch_to_tab_10(self):
|
2010-01-21 12:33:42 +00:00
|
|
|
self.emit('tab-change', 9)
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_reset(self):
|
|
|
|
self.vte.reset (True, False)
|
|
|
|
|
|
|
|
def key_reset_clear(self):
|
|
|
|
self.vte.reset (True, True)
|
|
|
|
|
|
|
|
def key_group_all(self):
|
2010-01-21 12:55:57 +00:00
|
|
|
self.emit('group-all')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_ungroup_all(self):
|
2010-01-21 12:55:57 +00:00
|
|
|
self.emit('ungroup-all')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_group_tab(self):
|
2010-01-21 12:55:57 +00:00
|
|
|
self.emit('group-tab')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_ungroup_tab(self):
|
2010-01-21 12:55:57 +00:00
|
|
|
self.emit('ungroup-tab')
|
2009-10-28 12:53:18 +00:00
|
|
|
|
|
|
|
def key_new_window(self):
|
2010-01-29 23:52:21 +00:00
|
|
|
self.terminator.new_window()
|
|
|
|
|
|
|
|
def key_new_terminator(self):
|
2009-10-28 12:53:18 +00:00
|
|
|
cmd = sys.argv[0]
|
|
|
|
|
|
|
|
if not os.path.isabs(cmd):
|
|
|
|
# Command is not an absolute path. Figure out where we are
|
2010-01-29 23:52:21 +00:00
|
|
|
cmd = os.path.join (self.origcwd, sys.argv[0])
|
2009-10-28 12:53:18 +00:00
|
|
|
if not os.path.isfile(cmd):
|
|
|
|
# we weren't started as ./terminator in a path. Give up
|
2009-12-16 09:15:53 +00:00
|
|
|
err('Terminal::key_new_window: Unable to locate Terminator')
|
2009-10-28 12:53:18 +00:00
|
|
|
return False
|
|
|
|
|
2009-12-16 09:15:53 +00:00
|
|
|
dbg("Terminal::key_new_window: Spawning: %s" % cmd)
|
2010-01-23 00:50:28 +00:00
|
|
|
subprocess.Popen([cmd, ])
|
2009-10-28 12:53:18 +00:00
|
|
|
# End key events
|
|
|
|
|
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:
|