2009-08-07 23:31:44 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""window.py - class for the main Terminator window"""
|
|
|
|
|
2010-02-14 22:03:06 +00:00
|
|
|
import copy
|
2010-07-14 13:31:13 +00:00
|
|
|
import time
|
2009-08-07 23:31:44 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
|
2009-08-09 23:11:31 +00:00
|
|
|
from util import dbg, err
|
2010-01-29 13:12:33 +00:00
|
|
|
import util
|
2009-11-21 18:47:38 +00:00
|
|
|
from translation import _
|
2009-08-10 22:09:49 +00:00
|
|
|
from version import APP_NAME
|
2009-08-07 23:31:44 +00:00
|
|
|
from container import Container
|
2009-11-25 00:37:29 +00:00
|
|
|
from factory import Factory
|
2010-01-11 20:06:53 +00:00
|
|
|
from terminator import Terminator
|
2009-08-07 23:31:44 +00:00
|
|
|
|
|
|
|
try:
|
2010-04-02 16:06:39 +00:00
|
|
|
import keybinder
|
2009-08-07 23:31:44 +00:00
|
|
|
except ImportError:
|
2010-04-02 16:06:39 +00:00
|
|
|
err('Warning: python-keybinder is not installed. This means the \
|
|
|
|
hide_window shortcut will be unavailable')
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2009-08-18 12:57:35 +00:00
|
|
|
# pylint: disable-msg=R0904
|
2009-08-07 23:31:44 +00:00
|
|
|
class Window(Container, gtk.Window):
|
|
|
|
"""Class implementing a top-level Terminator window"""
|
|
|
|
|
2009-08-10 23:15:31 +00:00
|
|
|
terminator = None
|
2009-08-07 23:31:44 +00:00
|
|
|
title = None
|
|
|
|
isfullscreen = None
|
2009-08-09 23:07:40 +00:00
|
|
|
ismaximised = None
|
2009-08-07 23:31:44 +00:00
|
|
|
hidebound = None
|
2009-08-09 22:25:53 +00:00
|
|
|
hidefunc = None
|
2010-07-14 13:31:13 +00:00
|
|
|
losefocus_time = 0
|
2010-05-15 18:07:07 +00:00
|
|
|
position = None
|
|
|
|
ignore_startup_show = None
|
2012-06-25 17:05:43 +00:00
|
|
|
set_pos_by_ratio = None
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2009-11-14 18:56:50 +00:00
|
|
|
zoom_data = None
|
2010-06-30 10:33:34 +00:00
|
|
|
|
|
|
|
term_zoomed = False
|
|
|
|
__gproperties__ = {
|
|
|
|
'term_zoomed': (gobject.TYPE_BOOLEAN,
|
|
|
|
'terminal zoomed',
|
|
|
|
'whether the terminal is zoomed',
|
|
|
|
False,
|
|
|
|
gobject.PARAM_READWRITE)
|
|
|
|
}
|
2009-10-06 23:08:13 +00:00
|
|
|
|
2010-01-11 20:56:30 +00:00
|
|
|
def __init__(self):
|
2009-08-07 23:31:44 +00:00
|
|
|
"""Class initialiser"""
|
2009-08-10 23:15:31 +00:00
|
|
|
self.terminator = Terminator()
|
2009-11-17 03:58:12 +00:00
|
|
|
self.terminator.register_window(self)
|
2009-08-10 23:15:31 +00:00
|
|
|
|
2009-08-19 00:06:07 +00:00
|
|
|
Container.__init__(self)
|
2009-08-07 23:31:44 +00:00
|
|
|
gtk.Window.__init__(self)
|
2009-08-09 21:00:43 +00:00
|
|
|
gobject.type_register(Window)
|
|
|
|
self.register_signals(Window)
|
2009-08-07 23:31:44 +00:00
|
|
|
|
|
|
|
self.set_property('allow-shrink', True)
|
2012-06-28 16:07:00 +00:00
|
|
|
icon_to_apply=''
|
2009-08-10 22:09:49 +00:00
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
self.register_callbacks()
|
|
|
|
self.apply_config()
|
|
|
|
|
2009-09-02 20:10:28 +00:00
|
|
|
self.title = WindowTitle(self)
|
|
|
|
self.title.update()
|
|
|
|
|
2010-01-11 20:56:30 +00:00
|
|
|
options = self.config.options_get()
|
|
|
|
if options:
|
2011-12-29 20:39:09 +00:00
|
|
|
if options.forcedtitle:
|
2010-01-11 20:56:30 +00:00
|
|
|
self.title.force_title(options.forcedtitle)
|
2010-01-05 12:55:05 +00:00
|
|
|
|
2011-12-29 20:39:09 +00:00
|
|
|
if options.role:
|
2010-01-11 20:56:30 +00:00
|
|
|
self.set_role(options.role)
|
2012-06-28 13:38:01 +00:00
|
|
|
|
|
|
|
if options.classname is not None:
|
|
|
|
self.set_wmclass(options.classname, self.wmclass_class)
|
2012-06-28 16:07:00 +00:00
|
|
|
|
|
|
|
if options.forcedicon is not None:
|
|
|
|
icon_to_apply = options.forcedicon
|
2010-01-11 20:56:30 +00:00
|
|
|
|
2011-12-29 20:39:09 +00:00
|
|
|
if options.geometry:
|
2010-01-11 20:56:30 +00:00
|
|
|
if not self.parse_geometry(options.geometry):
|
|
|
|
err('Window::__init__: Unable to parse geometry: %s' %
|
|
|
|
options.geometry)
|
2010-01-05 12:58:05 +00:00
|
|
|
|
2012-06-28 16:07:00 +00:00
|
|
|
self.apply_icon(icon_to_apply)
|
2011-02-23 21:46:55 +00:00
|
|
|
self.pending_set_rough_geometry_hint = False
|
|
|
|
|
2010-06-30 10:33:34 +00:00
|
|
|
def do_get_property(self, prop):
|
|
|
|
"""Handle gobject getting a property"""
|
|
|
|
if prop.name in ['term_zoomed', 'term-zoomed']:
|
|
|
|
return(self.term_zoomed)
|
|
|
|
else:
|
|
|
|
raise AttributeError('unknown property %s' % prop.name)
|
|
|
|
|
|
|
|
def do_set_property(self, prop, value):
|
|
|
|
"""Handle gobject setting a property"""
|
|
|
|
if prop.name in ['term_zoomed', 'term-zoomed']:
|
|
|
|
self.term_zoomed = value
|
|
|
|
else:
|
|
|
|
raise AttributeError('unknown property %s' % prop.name)
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
def register_callbacks(self):
|
|
|
|
"""Connect the GTK+ signals we care about"""
|
|
|
|
self.connect('key-press-event', self.on_key_press)
|
2010-07-03 17:14:37 +00:00
|
|
|
self.connect('button-press-event', self.on_button_press)
|
2009-08-07 23:31:44 +00:00
|
|
|
self.connect('delete_event', self.on_delete_event)
|
|
|
|
self.connect('destroy', self.on_destroy_event)
|
|
|
|
self.connect('window-state-event', self.on_window_state_changed)
|
2010-07-03 17:22:59 +00:00
|
|
|
self.connect('focus-out-event', self.on_focus_out)
|
|
|
|
self.connect('focus-in-event', self.on_focus_in)
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2009-08-09 22:25:53 +00:00
|
|
|
# Attempt to grab a global hotkey for hiding the window.
|
|
|
|
# If we fail, we'll never hide the window, iconifying instead.
|
2013-01-30 13:37:14 +00:00
|
|
|
if self.config['keybindings']['hide_window'] != None:
|
|
|
|
try:
|
|
|
|
self.hidebound = keybinder.bind(
|
|
|
|
self.config['keybindings']['hide_window'],
|
|
|
|
self.on_hide_window)
|
|
|
|
except (KeyError, NameError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not self.hidebound:
|
|
|
|
err('Unable to bind hide_window key, another instance/window has it.')
|
|
|
|
self.hidefunc = self.iconify
|
|
|
|
else:
|
|
|
|
self.hidefunc = self.hide
|
2009-08-07 23:31:44 +00:00
|
|
|
|
|
|
|
def apply_config(self):
|
|
|
|
"""Apply various configuration options"""
|
2010-01-11 20:56:30 +00:00
|
|
|
options = self.config.options_get()
|
|
|
|
maximise = self.config['window_state'] == 'maximise'
|
|
|
|
fullscreen = self.config['window_state'] == 'fullscreen'
|
|
|
|
hidden = self.config['window_state'] == 'hidden'
|
|
|
|
borderless = self.config['borderless']
|
2010-05-15 18:07:07 +00:00
|
|
|
skiptaskbar = self.config['hide_from_taskbar']
|
|
|
|
alwaysontop = self.config['always_on_top']
|
|
|
|
sticky = self.config['sticky']
|
2010-01-11 20:56:30 +00:00
|
|
|
|
|
|
|
if options:
|
|
|
|
if options.maximise:
|
|
|
|
maximise = True
|
|
|
|
if options.fullscreen:
|
|
|
|
fullscreen = True
|
|
|
|
if options.hidden:
|
|
|
|
hidden = True
|
|
|
|
if options.borderless:
|
|
|
|
borderless = True
|
|
|
|
|
|
|
|
self.set_fullscreen(fullscreen)
|
|
|
|
self.set_maximised(maximise)
|
|
|
|
self.set_borderless(borderless)
|
2010-05-15 18:07:07 +00:00
|
|
|
self.set_always_on_top(alwaysontop)
|
2009-11-21 18:47:38 +00:00
|
|
|
self.set_real_transparency()
|
2010-05-15 18:07:07 +00:00
|
|
|
self.set_sticky(sticky)
|
2009-08-07 23:31:44 +00:00
|
|
|
if self.hidebound:
|
2010-01-11 20:56:30 +00:00
|
|
|
self.set_hidden(hidden)
|
2010-05-15 18:07:07 +00:00
|
|
|
self.set_skip_taskbar_hint(skiptaskbar)
|
2009-08-07 23:31:44 +00:00
|
|
|
else:
|
2010-01-11 20:56:30 +00:00
|
|
|
self.set_iconified(hidden)
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2012-06-28 16:07:00 +00:00
|
|
|
def apply_icon(self, requested_icon):
|
2009-08-10 22:09:49 +00:00
|
|
|
"""Set the window icon"""
|
|
|
|
icon_theme = gtk.IconTheme()
|
2012-06-28 16:07:00 +00:00
|
|
|
icon = None
|
|
|
|
|
|
|
|
if requested_icon:
|
|
|
|
try:
|
|
|
|
self.set_icon_from_file(requested_icon)
|
|
|
|
icon = self.get_icon()
|
|
|
|
except (NameError, gobject.GError):
|
|
|
|
dbg('Unable to load 48px %s icon as file' % (repr(requested_icon)))
|
|
|
|
|
|
|
|
if requested_icon and icon is None:
|
|
|
|
try:
|
|
|
|
icon = icon_theme.load_icon(requested_icon, 48, 0)
|
|
|
|
except (NameError, gobject.GError):
|
|
|
|
dbg('Unable to load 48px %s icon' % (repr(requested_icon)))
|
|
|
|
|
|
|
|
if icon is None:
|
|
|
|
try:
|
|
|
|
icon = icon_theme.load_icon(self.wmclass_name, 48, 0)
|
|
|
|
except (NameError, gobject.GError):
|
|
|
|
dbg('Unable to load 48px %s icon' % (self.wmclass_name))
|
|
|
|
|
|
|
|
if icon is None:
|
|
|
|
try:
|
|
|
|
icon = icon_theme.load_icon(APP_NAME, 48, 0)
|
|
|
|
except (NameError, gobject.GError):
|
|
|
|
dbg('Unable to load 48px Terminator icon')
|
|
|
|
icon = self.render_icon(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_BUTTON)
|
2009-08-10 22:09:49 +00:00
|
|
|
|
|
|
|
self.set_icon(icon)
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
def on_key_press(self, window, event):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Handle a keyboard event"""
|
2009-11-25 00:37:29 +00:00
|
|
|
maker = Factory()
|
2010-01-21 00:13:56 +00:00
|
|
|
|
|
|
|
self.set_urgency_hint(False)
|
2009-11-21 18:47:38 +00:00
|
|
|
|
|
|
|
mapping = self.terminator.keybindings.lookup(event)
|
|
|
|
|
|
|
|
if mapping:
|
|
|
|
dbg('Window::on_key_press: looked up %r' % mapping)
|
|
|
|
if mapping == 'full_screen':
|
|
|
|
self.set_fullscreen(not self.isfullscreen)
|
|
|
|
elif mapping == 'close_window':
|
|
|
|
if not self.on_delete_event(window,
|
|
|
|
gtk.gdk.Event(gtk.gdk.DELETE)):
|
|
|
|
self.on_destroy_event(window,
|
|
|
|
gtk.gdk.Event(gtk.gdk.DESTROY))
|
2009-11-22 04:28:39 +00:00
|
|
|
elif mapping == 'new_tab':
|
2010-04-02 15:45:32 +00:00
|
|
|
self.tab_new(self.get_focussed_terminal())
|
2009-11-21 18:47:38 +00:00
|
|
|
else:
|
|
|
|
return(False)
|
|
|
|
return(True)
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2010-07-03 17:14:37 +00:00
|
|
|
def on_button_press(self, window, event):
|
|
|
|
"""Handle a mouse button event. Mainly this is just a clean way to
|
|
|
|
cancel any urgency hints that are set."""
|
|
|
|
self.set_urgency_hint(False)
|
|
|
|
return(False)
|
|
|
|
|
2010-07-03 17:22:59 +00:00
|
|
|
def on_focus_out(self, window, event):
|
|
|
|
"""Focus has left the window"""
|
2010-07-03 19:00:04 +00:00
|
|
|
for terminal in self.get_visible_terminals():
|
|
|
|
terminal.on_window_focus_out()
|
2010-07-03 17:22:59 +00:00
|
|
|
|
2010-07-14 13:31:13 +00:00
|
|
|
self.losefocus_time = time.time()
|
|
|
|
if self.config['hide_on_lose_focus'] and self.get_property('visible'):
|
|
|
|
self.position = self.get_position()
|
|
|
|
self.hidefunc()
|
|
|
|
|
2010-07-03 17:22:59 +00:00
|
|
|
def on_focus_in(self, window, event):
|
|
|
|
"""Focus has entered the window"""
|
|
|
|
self.set_urgency_hint(False)
|
2013-10-31 17:50:21 +00:00
|
|
|
self.terminator.last_active_window = self.uuid
|
2010-07-03 17:22:59 +00:00
|
|
|
# FIXME: Cause the terminal titlebars to update here
|
|
|
|
|
2010-01-24 12:55:03 +00:00
|
|
|
def is_child_notebook(self):
|
|
|
|
"""Returns True if this Window's child is a Notebook"""
|
|
|
|
maker = Factory()
|
|
|
|
return(maker.isinstance(self.get_child(), 'Notebook'))
|
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
def tab_new(self, widget=None, debugtab=False, _param1=None, _param2=None):
|
2009-12-08 13:01:13 +00:00
|
|
|
"""Make a new tab"""
|
2010-04-02 15:45:32 +00:00
|
|
|
cwd = None
|
2011-11-05 15:49:01 +00:00
|
|
|
profile = None
|
2010-04-02 15:45:32 +00:00
|
|
|
|
2010-04-15 19:32:25 +00:00
|
|
|
if self.get_property('term_zoomed') == True:
|
|
|
|
err("You can't create a tab while a terminal is maximised/zoomed")
|
|
|
|
return
|
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
if widget:
|
|
|
|
cwd = widget.get_cwd()
|
2011-11-05 15:49:01 +00:00
|
|
|
profile = widget.get_profile()
|
|
|
|
|
2009-12-08 13:01:13 +00:00
|
|
|
maker = Factory()
|
2010-01-24 12:55:03 +00:00
|
|
|
if not self.is_child_notebook():
|
2011-08-20 23:38:50 +00:00
|
|
|
dbg('Making a new Notebook')
|
2010-01-05 12:49:57 +00:00
|
|
|
notebook = maker.make('Notebook', window=self)
|
2012-10-30 00:11:24 +00:00
|
|
|
return self.get_child().newtab(debugtab, cwd=cwd, profile=profile)
|
2009-12-08 13:01:13 +00:00
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
def on_delete_event(self, window, event, data=None):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Handle a window close request"""
|
2009-11-25 00:37:29 +00:00
|
|
|
maker = Factory()
|
|
|
|
if maker.isinstance(self.get_child(), 'Terminal'):
|
2009-11-21 18:47:38 +00:00
|
|
|
dbg('Window::on_delete_event: Only one child, closing is fine')
|
|
|
|
return(False)
|
2010-01-29 23:37:25 +00:00
|
|
|
elif maker.isinstance(self.get_child(), 'Container'):
|
|
|
|
return(self.confirm_close(window, _('window')))
|
|
|
|
else:
|
|
|
|
dbg('unknown child: %s' % self.get_child())
|
2009-11-21 18:47:38 +00:00
|
|
|
|
|
|
|
def confirm_close(self, window, type):
|
|
|
|
"""Display a confirmation dialog when the user is closing multiple
|
|
|
|
terminals in one window"""
|
2011-12-08 13:12:29 +00:00
|
|
|
|
|
|
|
return(not (self.construct_confirm_close(window, type) == gtk.RESPONSE_ACCEPT))
|
2009-08-07 23:31:44 +00:00
|
|
|
|
|
|
|
def on_destroy_event(self, widget, data=None):
|
2010-07-03 17:08:46 +00:00
|
|
|
"""Handle window destruction"""
|
2010-01-29 23:37:25 +00:00
|
|
|
dbg('destroying self')
|
2010-07-03 17:08:46 +00:00
|
|
|
for terminal in self.get_visible_terminals():
|
|
|
|
terminal.close()
|
2010-01-25 12:55:38 +00:00
|
|
|
self.cnxids.remove_all()
|
2009-11-17 03:58:12 +00:00
|
|
|
self.terminator.deregister_window(self)
|
2009-11-21 18:47:38 +00:00
|
|
|
self.destroy()
|
|
|
|
del(self)
|
2009-08-09 23:07:40 +00:00
|
|
|
|
2010-04-09 11:30:47 +00:00
|
|
|
def on_hide_window(self, data=None):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Handle a request to hide/show the window"""
|
2010-07-14 13:31:13 +00:00
|
|
|
|
|
|
|
if not self.get_property('visible'):
|
|
|
|
#Don't show if window has just been hidden because of
|
2010-07-15 14:42:31 +00:00
|
|
|
#lost focus
|
|
|
|
if (time.time() - self.losefocus_time < 0.1) and \
|
|
|
|
self.config['hide_on_lose_focus']:
|
2010-07-14 13:31:13 +00:00
|
|
|
return
|
2010-05-15 18:07:07 +00:00
|
|
|
if self.position:
|
|
|
|
self.move(self.position[0], self.position[1])
|
2010-07-13 13:07:40 +00:00
|
|
|
self.show()
|
2013-09-04 21:02:24 +00:00
|
|
|
self.grab_focus()
|
|
|
|
try:
|
|
|
|
t = gtk.gdk.x11_get_server_time(self.window)
|
|
|
|
except AttributeError:
|
|
|
|
t = 0
|
|
|
|
self.window.focus(t)
|
2010-05-15 18:07:07 +00:00
|
|
|
else:
|
|
|
|
self.position = self.get_position()
|
|
|
|
self.hidefunc()
|
|
|
|
|
2009-08-18 12:57:35 +00:00
|
|
|
# pylint: disable-msg=W0613
|
2009-08-07 23:31:44 +00:00
|
|
|
def on_window_state_changed(self, window, event):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Handle the state of the window changing"""
|
2009-08-07 23:31:44 +00:00
|
|
|
self.isfullscreen = bool(event.new_window_state &
|
|
|
|
gtk.gdk.WINDOW_STATE_FULLSCREEN)
|
|
|
|
self.ismaximised = bool(event.new_window_state &
|
|
|
|
gtk.gdk.WINDOW_STATE_MAXIMIZED)
|
2010-07-14 13:31:13 +00:00
|
|
|
dbg('Window::on_window_state_changed: fullscreen=%s, maximised=%s' \
|
|
|
|
% (self.isfullscreen, self.ismaximised))
|
2009-08-09 23:07:40 +00:00
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
return(False)
|
|
|
|
|
|
|
|
def set_maximised(self, value):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Set the maximised state of the window from the supplied value"""
|
2009-08-07 23:31:44 +00:00
|
|
|
if value == True:
|
|
|
|
self.maximize()
|
|
|
|
else:
|
|
|
|
self.unmaximize()
|
|
|
|
|
|
|
|
def set_fullscreen(self, value):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Set the fullscreen state of the window from the supplied value"""
|
2009-08-07 23:31:44 +00:00
|
|
|
if value == True:
|
|
|
|
self.fullscreen()
|
|
|
|
else:
|
|
|
|
self.unfullscreen()
|
|
|
|
|
|
|
|
def set_borderless(self, value):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Set the state of the window border from the supplied value"""
|
2009-08-07 23:31:44 +00:00
|
|
|
self.set_decorated (not value)
|
|
|
|
|
|
|
|
def set_hidden(self, value):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Set the visibility of the window from the supplied value"""
|
2010-05-15 18:07:07 +00:00
|
|
|
if value == True:
|
|
|
|
self.ignore_startup_show = True
|
|
|
|
else:
|
|
|
|
self.ignore_startup_show = False
|
2009-08-07 23:31:44 +00:00
|
|
|
|
|
|
|
def set_iconified(self, value):
|
2010-05-15 18:07:07 +00:00
|
|
|
"""Set the minimised state of the window from the supplied value"""
|
|
|
|
if value == True:
|
|
|
|
self.iconify()
|
|
|
|
|
|
|
|
def set_always_on_top(self, value):
|
|
|
|
"""Set the always on top window hint from the supplied value"""
|
|
|
|
self.set_keep_above(value)
|
|
|
|
|
|
|
|
def set_sticky(self, value):
|
|
|
|
"""Set the sticky hint from the supplied value"""
|
|
|
|
if value == True:
|
|
|
|
self.stick()
|
|
|
|
|
2009-11-21 18:47:38 +00:00
|
|
|
def set_real_transparency(self, value=True):
|
2009-08-09 23:07:40 +00:00
|
|
|
"""Enable RGBA if supported on the current screen"""
|
2010-04-06 19:51:29 +00:00
|
|
|
if self.is_composited() == False:
|
|
|
|
value = False
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
screen = self.get_screen()
|
|
|
|
if value:
|
2010-01-21 20:36:02 +00:00
|
|
|
dbg('setting rgba colormap')
|
2009-08-07 23:31:44 +00:00
|
|
|
colormap = screen.get_rgba_colormap()
|
|
|
|
else:
|
2010-01-21 20:36:02 +00:00
|
|
|
dbg('setting rgb colormap')
|
2009-08-07 23:31:44 +00:00
|
|
|
colormap = screen.get_rgb_colormap()
|
|
|
|
|
|
|
|
if colormap:
|
|
|
|
self.set_colormap(colormap)
|
2010-05-15 18:07:07 +00:00
|
|
|
|
|
|
|
def show(self, startup=False):
|
|
|
|
"""Undo the startup show request if started in hidden mode"""
|
2012-10-10 16:37:30 +00:00
|
|
|
#Present is necessary to grab focus when window is hidden from taskbar.
|
|
|
|
#It is important to call present() before show(), otherwise the window
|
|
|
|
#won't be brought to front if an another application has the focus.
|
|
|
|
#Last note: present() will implicitly call gtk.Window.show()
|
2010-07-13 13:07:40 +00:00
|
|
|
self.present()
|
|
|
|
|
2010-05-15 18:07:07 +00:00
|
|
|
#Window must be shown, then hidden for the hotkeys to be registered
|
|
|
|
if (self.ignore_startup_show and startup == True):
|
2013-09-03 14:10:09 +00:00
|
|
|
self.position = self.get_position()
|
2010-05-15 18:07:07 +00:00
|
|
|
self.hide()
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
|
2011-08-22 20:05:38 +00:00
|
|
|
def add(self, widget, metadata=None):
|
2009-08-27 23:20:22 +00:00
|
|
|
"""Add a widget to the window by way of gtk.Window.add()"""
|
2009-11-25 00:37:29 +00:00
|
|
|
maker = Factory()
|
2009-11-14 23:04:15 +00:00
|
|
|
gtk.Window.add(self, widget)
|
2009-11-25 00:37:29 +00:00
|
|
|
if maker.isinstance(widget, 'Terminal'):
|
2009-11-14 22:58:42 +00:00
|
|
|
signals = {'close-term': self.closeterm,
|
|
|
|
'title-change': self.title.set_title,
|
|
|
|
'split-horiz': self.split_horiz,
|
|
|
|
'split-vert': self.split_vert,
|
2010-01-24 12:55:03 +00:00
|
|
|
'unzoom': self.unzoom,
|
|
|
|
'tab-change': self.tab_change,
|
|
|
|
'group-all': self.group_all,
|
|
|
|
'ungroup-all': self.ungroup_all,
|
|
|
|
'group-tab': self.group_tab,
|
2010-01-24 22:15:54 +00:00
|
|
|
'ungroup-tab': self.ungroup_tab,
|
2010-01-28 12:49:38 +00:00
|
|
|
'move-tab': self.move_tab,
|
2010-04-02 15:45:32 +00:00
|
|
|
'tab-new': [self.tab_new, widget],
|
2010-01-29 13:12:33 +00:00
|
|
|
'navigate': self.navigate_terminal}
|
2009-11-14 22:58:42 +00:00
|
|
|
|
|
|
|
for signal in signals:
|
2010-04-02 15:45:32 +00:00
|
|
|
args = []
|
|
|
|
handler = signals[signal]
|
|
|
|
if isinstance(handler, list):
|
|
|
|
args = handler[1:]
|
|
|
|
handler = handler[0]
|
|
|
|
self.connect_child(widget, signal, handler, *args)
|
2009-11-14 22:58:42 +00:00
|
|
|
|
2009-11-14 23:04:15 +00:00
|
|
|
widget.grab_focus()
|
2009-08-27 23:20:22 +00:00
|
|
|
|
|
|
|
def remove(self, widget):
|
|
|
|
"""Remove our child widget by way of gtk.Window.remove()"""
|
|
|
|
gtk.Window.remove(self, widget)
|
2009-11-14 22:58:42 +00:00
|
|
|
self.disconnect_child(widget)
|
|
|
|
return(True)
|
2009-10-05 21:16:28 +00:00
|
|
|
|
2010-03-10 22:51:33 +00:00
|
|
|
def get_children(self):
|
|
|
|
"""Return a single list of our child"""
|
|
|
|
children = []
|
|
|
|
children.append(self.get_child())
|
|
|
|
return(children)
|
|
|
|
|
2010-03-02 12:39:47 +00:00
|
|
|
def hoover(self):
|
|
|
|
"""Ensure we still have a reason to exist"""
|
2010-03-02 21:01:20 +00:00
|
|
|
if not self.get_child():
|
2010-03-02 12:39:47 +00:00
|
|
|
self.emit('destroy')
|
|
|
|
|
2010-01-29 23:37:25 +00:00
|
|
|
def closeterm(self, widget):
|
|
|
|
"""Handle a terminal closing"""
|
|
|
|
Container.closeterm(self, widget)
|
2010-03-02 12:39:47 +00:00
|
|
|
self.hoover()
|
2010-01-29 23:37:25 +00:00
|
|
|
|
2010-03-05 22:44:38 +00:00
|
|
|
def split_axis(self, widget, vertical=True, cwd=None, sibling=None, widgetfirst=True):
|
2009-10-05 21:16:28 +00:00
|
|
|
"""Split the window"""
|
2010-04-09 11:38:33 +00:00
|
|
|
if self.get_property('term_zoomed') == True:
|
|
|
|
err("You can't split while a terminal is maximised/zoomed")
|
|
|
|
return
|
|
|
|
|
2010-02-27 12:30:38 +00:00
|
|
|
order = None
|
2009-11-25 00:37:29 +00:00
|
|
|
maker = Factory()
|
2009-10-05 21:16:28 +00:00
|
|
|
self.remove(widget)
|
|
|
|
|
|
|
|
if vertical:
|
2009-11-25 00:37:29 +00:00
|
|
|
container = maker.make('VPaned')
|
2009-10-05 21:16:28 +00:00
|
|
|
else:
|
2009-11-25 00:37:29 +00:00
|
|
|
container = maker.make('HPaned')
|
2012-06-25 18:01:35 +00:00
|
|
|
|
|
|
|
self.set_pos_by_ratio = True
|
2009-10-05 21:16:28 +00:00
|
|
|
|
2009-11-17 04:56:55 +00:00
|
|
|
if not sibling:
|
2009-11-25 00:37:29 +00:00
|
|
|
sibling = maker.make('Terminal')
|
2010-03-05 22:44:38 +00:00
|
|
|
sibling.set_cwd(cwd)
|
2010-02-04 00:59:11 +00:00
|
|
|
sibling.spawn_child()
|
2012-10-19 16:57:23 +00:00
|
|
|
if widget.group and self.config['split_to_group']:
|
|
|
|
sibling.set_group(None, widget.group)
|
2012-10-18 23:56:34 +00:00
|
|
|
if self.config['always_split_with_profile']:
|
2011-11-05 15:49:01 +00:00
|
|
|
sibling.force_set_profile(None, widget.get_profile())
|
|
|
|
|
2009-11-14 18:56:50 +00:00
|
|
|
self.add(container)
|
|
|
|
container.show_all()
|
2009-10-05 21:16:28 +00:00
|
|
|
|
2010-03-02 20:38:28 +00:00
|
|
|
order = [widget, sibling]
|
|
|
|
if widgetfirst is False:
|
2010-02-27 12:30:38 +00:00
|
|
|
order.reverse()
|
|
|
|
|
|
|
|
for term in order:
|
2009-11-07 01:40:43 +00:00
|
|
|
container.add(term)
|
|
|
|
container.show_all()
|
2013-02-10 15:58:06 +00:00
|
|
|
sibling.grab_focus()
|
2012-06-25 18:01:35 +00:00
|
|
|
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration_do(False)
|
|
|
|
self.set_pos_by_ratio = False
|
|
|
|
|
2009-10-05 21:16:28 +00:00
|
|
|
|
2009-11-20 05:16:20 +00:00
|
|
|
def zoom(self, widget, font_scale=True):
|
2009-11-14 18:56:50 +00:00
|
|
|
"""Zoom a terminal widget"""
|
|
|
|
children = self.get_children()
|
|
|
|
|
|
|
|
if widget in children:
|
|
|
|
# This widget is a direct child of ours and we're a Window
|
|
|
|
# so zooming is a no-op
|
|
|
|
return
|
|
|
|
|
|
|
|
self.zoom_data = widget.get_zoom_data()
|
|
|
|
self.zoom_data['widget'] = widget
|
|
|
|
self.zoom_data['old_child'] = children[0]
|
|
|
|
self.zoom_data['font_scale'] = font_scale
|
|
|
|
|
|
|
|
self.remove(self.zoom_data['old_child'])
|
|
|
|
self.zoom_data['old_parent'].remove(widget)
|
|
|
|
self.add(widget)
|
|
|
|
self.set_property('term_zoomed', True)
|
|
|
|
|
|
|
|
if font_scale:
|
2010-01-18 19:48:24 +00:00
|
|
|
widget.cnxids.new(widget, 'size-allocate',
|
2009-11-14 18:56:50 +00:00
|
|
|
widget.zoom_scale, self.zoom_data)
|
|
|
|
|
|
|
|
widget.grab_focus()
|
|
|
|
|
2009-11-20 05:16:20 +00:00
|
|
|
def unzoom(self, widget):
|
2009-11-14 18:56:50 +00:00
|
|
|
"""Restore normal terminal layout"""
|
|
|
|
if not self.get_property('term_zoomed'):
|
|
|
|
# We're not zoomed anyway
|
2009-11-20 05:16:20 +00:00
|
|
|
dbg('Window::unzoom: not zoomed, no-op')
|
2009-11-14 18:56:50 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
widget = self.zoom_data['widget']
|
|
|
|
if self.zoom_data['font_scale']:
|
|
|
|
widget.vte.set_font(self.zoom_data['old_font'])
|
|
|
|
|
|
|
|
self.remove(widget)
|
|
|
|
self.add(self.zoom_data['old_child'])
|
|
|
|
self.zoom_data['old_parent'].add(widget)
|
|
|
|
widget.grab_focus()
|
|
|
|
self.zoom_data = None
|
|
|
|
self.set_property('term_zoomed', False)
|
|
|
|
|
2012-04-04 15:48:29 +00:00
|
|
|
def rotate(self, widget, clockwise):
|
|
|
|
"""Rotate children in this window"""
|
2012-06-25 17:05:43 +00:00
|
|
|
self.set_pos_by_ratio = True
|
2012-04-04 15:48:29 +00:00
|
|
|
maker = Factory()
|
|
|
|
# collect all paned children in breadth-first order
|
|
|
|
paned = []
|
|
|
|
for child in self.get_children():
|
|
|
|
if maker.isinstance(child, 'Paned'):
|
|
|
|
paned.append(child)
|
|
|
|
for p in paned:
|
|
|
|
for child in p.get_children():
|
|
|
|
if child not in paned and maker.isinstance(child, 'Paned'):
|
|
|
|
paned.append(child)
|
|
|
|
# then propagate the rotation
|
|
|
|
for p in paned:
|
|
|
|
p.rotate(widget, clockwise)
|
|
|
|
self.show_all()
|
|
|
|
widget.grab_focus()
|
2012-06-25 17:05:43 +00:00
|
|
|
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration_do(False)
|
|
|
|
self.set_pos_by_ratio = False
|
2012-04-04 15:48:29 +00:00
|
|
|
|
2010-01-19 13:06:09 +00:00
|
|
|
def get_visible_terminals(self):
|
|
|
|
"""Walk down the widget tree to find all of the visible terminals.
|
|
|
|
Mostly using Container::get_visible_terminals()"""
|
2010-07-03 19:42:33 +00:00
|
|
|
terminals = {}
|
2011-02-17 01:57:30 +00:00
|
|
|
if not hasattr(self, 'cached_maker'):
|
|
|
|
self.cached_maker = Factory()
|
|
|
|
maker = self.cached_maker
|
2010-01-19 13:06:09 +00:00
|
|
|
child = self.get_child()
|
2010-07-03 19:42:33 +00:00
|
|
|
|
|
|
|
if not child:
|
|
|
|
return([])
|
2010-01-19 13:06:09 +00:00
|
|
|
|
|
|
|
# If our child is a Notebook, reset to work from its visible child
|
|
|
|
if maker.isinstance(child, 'Notebook'):
|
|
|
|
pagenum = child.get_current_page()
|
|
|
|
child = child.get_nth_page(pagenum)
|
|
|
|
|
|
|
|
if maker.isinstance(child, 'Container'):
|
|
|
|
terminals.update(child.get_visible_terminals())
|
2010-01-20 23:36:11 +00:00
|
|
|
elif maker.isinstance(child, 'Terminal'):
|
2010-01-19 13:06:09 +00:00
|
|
|
terminals[child] = child.get_allocation()
|
|
|
|
else:
|
|
|
|
err('Unknown child type %s' % type(child))
|
|
|
|
|
|
|
|
return(terminals)
|
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
def get_focussed_terminal(self):
|
|
|
|
"""Find which terminal we want to have focus"""
|
|
|
|
terminals = self.get_visible_terminals()
|
|
|
|
for terminal in terminals:
|
|
|
|
if terminal.vte.is_focus():
|
|
|
|
return(terminal)
|
|
|
|
return(None)
|
|
|
|
|
2011-02-23 21:46:55 +00:00
|
|
|
def deferred_set_rough_geometry_hints(self):
|
|
|
|
# no parameters are used in set_rough_geometry_hints, so we can
|
|
|
|
# use the set_rough_geometry_hints
|
|
|
|
if self.pending_set_rough_geometry_hint == True:
|
|
|
|
return
|
|
|
|
self.pending_set_rough_geometry_hint = True
|
|
|
|
gobject.idle_add(self.do_deferred_set_rough_geometry_hints)
|
|
|
|
|
|
|
|
def do_deferred_set_rough_geometry_hints(self):
|
|
|
|
self.pending_set_rough_geometry_hint = False
|
|
|
|
self.set_rough_geometry_hints()
|
|
|
|
|
2010-01-20 23:36:11 +00:00
|
|
|
def set_rough_geometry_hints(self):
|
|
|
|
"""Walk all the terminals along the top and left edges to fake up how
|
|
|
|
many columns/rows we sort of have"""
|
2013-09-03 11:38:09 +00:00
|
|
|
if self.ismaximised == True:
|
|
|
|
return
|
2011-02-17 01:57:30 +00:00
|
|
|
if not hasattr(self, 'cached_maker'):
|
|
|
|
self.cached_maker = Factory()
|
|
|
|
maker = self.cached_maker
|
2010-04-07 11:14:31 +00:00
|
|
|
if maker.isinstance(self.get_child(), 'Notebook'):
|
|
|
|
dbg("We don't currently support geometry hinting with tabs")
|
|
|
|
return
|
|
|
|
|
2010-01-20 23:36:11 +00:00
|
|
|
terminals = self.get_visible_terminals()
|
|
|
|
column_sum = 0
|
|
|
|
row_sum = 0
|
|
|
|
|
|
|
|
for terminal in terminals:
|
|
|
|
rect = terminal.get_allocation()
|
|
|
|
if rect.x == 0:
|
|
|
|
cols, rows = terminal.get_size()
|
|
|
|
row_sum = row_sum + rows
|
|
|
|
if rect.y == 0:
|
|
|
|
cols, rows = terminal.get_size()
|
|
|
|
column_sum = column_sum + cols
|
|
|
|
|
2010-04-07 11:17:11 +00:00
|
|
|
if column_sum == 0 or row_sum == 0:
|
|
|
|
dbg('column_sum=%s,row_sum=%s. No terminals found in >=1 axis' %
|
|
|
|
(column_sum, row_sum))
|
|
|
|
return
|
|
|
|
|
2010-01-20 23:36:11 +00:00
|
|
|
# FIXME: I don't think we should just use whatever font size info is on
|
|
|
|
# the last terminal we inspected. Looking up the default profile font
|
|
|
|
# size and calculating its character sizes would be rather expensive
|
|
|
|
# though.
|
|
|
|
font_width, font_height = terminal.get_font_size()
|
|
|
|
total_font_width = font_width * column_sum
|
|
|
|
total_font_height = font_height * row_sum
|
|
|
|
|
|
|
|
win_width, win_height = self.get_size()
|
|
|
|
extra_width = win_width - total_font_width
|
|
|
|
extra_height = win_height - total_font_height
|
|
|
|
|
2010-04-07 11:14:31 +00:00
|
|
|
dbg('setting geometry hints: (ewidth:%s)(eheight:%s),\
|
|
|
|
(fwidth:%s)(fheight:%s)' % (extra_width, extra_height,
|
|
|
|
font_width, font_height))
|
2010-01-20 23:36:11 +00:00
|
|
|
self.set_geometry_hints(self, -1, -1, -1, -1, extra_width,
|
|
|
|
extra_height, font_width, font_height, -1.0, -1.0)
|
|
|
|
|
2010-01-21 12:33:42 +00:00
|
|
|
def tab_change(self, widget, num=None):
|
|
|
|
"""Change to a specific tab"""
|
|
|
|
if num is None:
|
|
|
|
err('must specify a tab to change to')
|
|
|
|
|
|
|
|
maker = Factory()
|
|
|
|
child = self.get_child()
|
|
|
|
|
|
|
|
if not maker.isinstance(child, 'Notebook'):
|
|
|
|
dbg('child is not a notebook, nothing to change to')
|
|
|
|
return
|
|
|
|
|
|
|
|
if num == -1:
|
|
|
|
# Go to the next tab
|
|
|
|
cur = child.get_current_page()
|
|
|
|
pages = child.get_n_pages()
|
|
|
|
if cur == pages - 1:
|
|
|
|
num = 0
|
2010-01-24 22:15:54 +00:00
|
|
|
else:
|
|
|
|
num = cur + 1
|
2010-01-21 12:33:42 +00:00
|
|
|
elif num == -2:
|
|
|
|
# Go to the previous tab
|
|
|
|
cur = child.get_current_page()
|
|
|
|
if cur > 0:
|
|
|
|
num = cur - 1
|
|
|
|
else:
|
|
|
|
num = child.get_n_pages() - 1
|
|
|
|
|
|
|
|
child.set_current_page(num)
|
|
|
|
# Work around strange bug in gtk-2.12.11 and pygtk-2.12.1
|
|
|
|
# Without it, the selection changes, but the displayed page doesn't
|
|
|
|
# change
|
|
|
|
child.set_current_page(child.get_current_page())
|
|
|
|
|
2010-01-21 12:55:57 +00:00
|
|
|
# FIXME: All of these (un)group_(all|tab) methods need refactoring work
|
|
|
|
def group_all(self, widget):
|
|
|
|
"""Group all terminals"""
|
|
|
|
# FIXME: Why isn't this being done by Terminator() ?
|
|
|
|
group = _('All')
|
|
|
|
self.terminator.create_group(group)
|
|
|
|
for terminal in self.terminator.terminals:
|
|
|
|
terminal.set_group(None, group)
|
2013-10-25 14:57:14 +00:00
|
|
|
self.terminator.focus_changed(self.terminator.last_focused_term)
|
2010-01-21 12:55:57 +00:00
|
|
|
|
|
|
|
def ungroup_all(self, widget):
|
|
|
|
"""Ungroup all terminals"""
|
|
|
|
for terminal in self.terminator.terminals:
|
|
|
|
terminal.set_group(None, None)
|
2013-10-25 14:57:14 +00:00
|
|
|
self.terminator.focus_changed(self.terminator.last_focused_term)
|
2010-01-21 12:55:57 +00:00
|
|
|
|
|
|
|
def group_tab(self, widget):
|
|
|
|
"""Group all terminals in the current tab"""
|
|
|
|
maker = Factory()
|
|
|
|
notebook = self.get_child()
|
|
|
|
|
|
|
|
if not maker.isinstance(notebook, 'Notebook'):
|
|
|
|
dbg('not in a notebook, refusing to group tab')
|
|
|
|
return
|
|
|
|
|
|
|
|
pagenum = notebook.get_current_page()
|
|
|
|
while True:
|
|
|
|
group = _('Tab %d') % pagenum
|
|
|
|
if group not in self.terminator.groups:
|
|
|
|
break
|
|
|
|
pagenum += 1
|
|
|
|
for terminal in self.get_visible_terminals():
|
|
|
|
terminal.set_group(None, group)
|
2013-10-25 14:57:14 +00:00
|
|
|
self.terminator.focus_changed(self.terminator.last_focused_term)
|
2010-01-21 12:55:57 +00:00
|
|
|
|
|
|
|
def ungroup_tab(self, widget):
|
|
|
|
"""Ungroup all terminals in the current tab"""
|
|
|
|
maker = Factory()
|
|
|
|
notebook = self.get_child()
|
|
|
|
|
|
|
|
if not maker.isinstance(notebook, 'Notebook'):
|
|
|
|
dbg('note in a notebook, refusing to ungroup tab')
|
|
|
|
return
|
|
|
|
|
|
|
|
for terminal in self.get_visible_terminals():
|
|
|
|
terminal.set_group(None, None)
|
2013-10-25 14:57:14 +00:00
|
|
|
self.terminator.focus_changed(self.terminator.last_focused_term)
|
2010-01-21 12:55:57 +00:00
|
|
|
|
2010-01-24 22:15:54 +00:00
|
|
|
def move_tab(self, widget, direction):
|
|
|
|
"""Handle a keyboard shortcut for moving tab positions"""
|
|
|
|
maker = Factory()
|
|
|
|
notebook = self.get_child()
|
|
|
|
|
|
|
|
if not maker.isinstance(notebook, 'Notebook'):
|
|
|
|
dbg('not in a notebook, refusing to move tab %s' % direction)
|
|
|
|
return
|
|
|
|
|
|
|
|
dbg('moving tab %s' % direction)
|
|
|
|
numpages = notebook.get_n_pages()
|
|
|
|
page = notebook.get_current_page()
|
|
|
|
child = notebook.get_nth_page(page)
|
|
|
|
|
|
|
|
if direction == 'left':
|
|
|
|
if page == 0:
|
|
|
|
page = numpages
|
|
|
|
else:
|
|
|
|
page = page - 1
|
|
|
|
elif direction == 'right':
|
|
|
|
if page == numpages - 1:
|
|
|
|
page = 0
|
|
|
|
else:
|
|
|
|
page = page + 1
|
|
|
|
else:
|
|
|
|
err('unknown direction: %s' % direction)
|
|
|
|
return
|
|
|
|
|
|
|
|
notebook.reorder_child(child, page)
|
|
|
|
|
2010-01-29 13:12:33 +00:00
|
|
|
def navigate_terminal(self, terminal, direction):
|
|
|
|
"""Navigate around terminals"""
|
|
|
|
_containers, terminals = util.enumerate_descendants(self)
|
2010-02-14 22:03:06 +00:00
|
|
|
visibles = self.get_visible_terminals()
|
2010-01-29 13:12:33 +00:00
|
|
|
current = terminals.index(terminal)
|
|
|
|
length = len(terminals)
|
|
|
|
next = None
|
|
|
|
|
2010-02-14 22:03:06 +00:00
|
|
|
if length <= 1 or len(visibles) <= 1:
|
2010-01-29 13:12:33 +00:00
|
|
|
return
|
|
|
|
|
2010-02-14 22:03:06 +00:00
|
|
|
if direction in ['next', 'prev']:
|
|
|
|
tmpterms = copy.copy(terminals)
|
|
|
|
tmpterms = tmpterms[current+1:]
|
|
|
|
tmpterms.extend(terminals[0:current])
|
|
|
|
|
|
|
|
if direction == 'next':
|
|
|
|
tmpterms.reverse()
|
|
|
|
|
|
|
|
next = 0
|
|
|
|
while len(tmpterms) > 0:
|
|
|
|
tmpitem = tmpterms.pop()
|
|
|
|
if tmpitem in visibles:
|
|
|
|
next = terminals.index(tmpitem)
|
|
|
|
break
|
2010-01-29 13:12:33 +00:00
|
|
|
elif direction in ['left', 'right', 'up', 'down']:
|
|
|
|
layout = self.get_visible_terminals()
|
|
|
|
allocation = terminal.get_allocation()
|
|
|
|
possibles = []
|
|
|
|
|
|
|
|
# Get the co-ordinate of the appropriate edge for this direction
|
|
|
|
edge = util.get_edge(allocation, direction)
|
|
|
|
# Find all visible terminals which are, in their entirity, in the
|
|
|
|
# direction we want to move
|
|
|
|
for term in layout:
|
|
|
|
rect = layout[term]
|
|
|
|
if util.get_nav_possible(edge, rect, direction):
|
|
|
|
possibles.append(term)
|
|
|
|
|
|
|
|
if len(possibles) == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Find out how far away each of the possible terminals is, then
|
|
|
|
# find the smallest distance. The winning terminals are all of
|
|
|
|
# those who are that distance away.
|
|
|
|
offsets = {}
|
|
|
|
for term in possibles:
|
|
|
|
rect = layout[term]
|
|
|
|
offsets[term] = util.get_nav_offset(edge, rect, direction)
|
|
|
|
keys = offsets.values()
|
|
|
|
keys.sort()
|
|
|
|
winners = [k for k, v in offsets.iteritems() if v == keys[0]]
|
|
|
|
next = terminals.index(winners[0])
|
|
|
|
|
|
|
|
if len(winners) > 1:
|
|
|
|
# Break an n-way tie using the cursor position
|
2010-05-05 08:44:55 +00:00
|
|
|
term_alloc = terminal.allocation
|
|
|
|
cursor_x = term_alloc.x + term_alloc.width / 2
|
|
|
|
cursor_y = term_alloc.y + term_alloc.height / 2
|
|
|
|
|
2010-01-29 13:12:33 +00:00
|
|
|
for term in winners:
|
|
|
|
rect = layout[term]
|
|
|
|
if util.get_nav_tiebreak(direction, cursor_x, cursor_y,
|
|
|
|
rect):
|
|
|
|
next = terminals.index(term)
|
|
|
|
break;
|
|
|
|
else:
|
|
|
|
err('Unknown navigation direction: %s' % direction)
|
|
|
|
|
|
|
|
if next is not None:
|
|
|
|
terminals[next].grab_focus()
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def create_layout(self, layout):
|
|
|
|
"""Apply any config items from our layout"""
|
|
|
|
if not layout.has_key('children'):
|
|
|
|
err('layout describes no children: %s' % layout)
|
|
|
|
return
|
|
|
|
children = layout['children']
|
2010-02-02 00:39:41 +00:00
|
|
|
if len(children) != 1:
|
2010-02-01 12:11:44 +00:00
|
|
|
# We're a Window, we can only have one child
|
|
|
|
err('incorrect number of children for Window: %s' % layout)
|
|
|
|
return
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
child = children[children.keys()[0]]
|
2010-02-01 12:11:44 +00:00
|
|
|
terminal = self.get_children()[0]
|
2010-06-15 14:19:05 +00:00
|
|
|
dbg('Making a child of type: %s' % child['type'])
|
2010-02-01 12:11:44 +00:00
|
|
|
if child['type'] == 'VPaned':
|
|
|
|
self.split_axis(terminal, True)
|
|
|
|
elif child['type'] == 'HPaned':
|
|
|
|
self.split_axis(terminal, False)
|
|
|
|
elif child['type'] == 'Notebook':
|
|
|
|
self.tab_new()
|
2011-08-20 23:38:50 +00:00
|
|
|
i = 2
|
|
|
|
while i < len(child['children']):
|
|
|
|
self.tab_new()
|
|
|
|
i = i + 1
|
2010-02-01 12:11:44 +00:00
|
|
|
elif child['type'] == 'Terminal':
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
err('unknown child type: %s' % child['type'])
|
|
|
|
return
|
|
|
|
|
|
|
|
self.get_children()[0].create_layout(child)
|
|
|
|
|
2013-10-31 17:50:21 +00:00
|
|
|
if layout.has_key('last_active_window') and layout['last_active_window'] == 'True':
|
|
|
|
self.terminator.last_active_window = self.uuid
|
|
|
|
|
2009-08-10 22:04:39 +00:00
|
|
|
class WindowTitle(object):
|
|
|
|
"""Class to handle the setting of the window title"""
|
|
|
|
|
|
|
|
window = None
|
|
|
|
text = None
|
|
|
|
forced = None
|
|
|
|
|
|
|
|
def __init__(self, window):
|
|
|
|
"""Class initialiser"""
|
|
|
|
self.window = window
|
|
|
|
self.forced = False
|
|
|
|
|
2009-09-02 20:10:28 +00:00
|
|
|
def set_title(self, widget, text):
|
2009-08-10 22:04:39 +00:00
|
|
|
"""Set the title"""
|
|
|
|
if not self.forced:
|
2009-09-02 20:10:28 +00:00
|
|
|
self.text = text
|
2009-08-10 22:04:39 +00:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def force_title(self, newtext):
|
|
|
|
"""Force a specific title"""
|
|
|
|
if newtext:
|
2010-01-05 12:49:57 +00:00
|
|
|
self.set_title(None, newtext)
|
2009-08-10 22:04:39 +00:00
|
|
|
self.forced = True
|
|
|
|
else:
|
|
|
|
self.forced = False
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the title automatically"""
|
|
|
|
title = None
|
|
|
|
|
|
|
|
# FIXME: What the hell is this for?!
|
|
|
|
if self.forced:
|
|
|
|
title = self.text
|
|
|
|
else:
|
|
|
|
title = "%s" % self.text
|
|
|
|
|
|
|
|
self.window.set_title(title)
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|