2009-11-07 01:40:43 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""paned.py - a base Paned container class and the vertical/horizontal
|
|
|
|
variants"""
|
|
|
|
|
2014-09-19 14:10:43 +00:00
|
|
|
from gi.repository import GObject, Gtk, Gdk
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2011-02-23 21:35:10 +00:00
|
|
|
from util import dbg, err
|
2010-01-11 20:06:53 +00:00
|
|
|
from terminator import Terminator
|
2009-11-25 00:37:29 +00:00
|
|
|
from factory import Factory
|
2009-11-07 01:40:43 +00:00
|
|
|
from container import Container
|
|
|
|
|
|
|
|
# pylint: disable-msg=R0921
|
2009-11-14 17:30:03 +00:00
|
|
|
# pylint: disable-msg=E1101
|
2009-11-07 01:40:43 +00:00
|
|
|
class Paned(Container):
|
|
|
|
"""Base class for Paned Containers"""
|
|
|
|
|
2011-08-21 00:25:34 +00:00
|
|
|
position = None
|
2011-08-22 19:20:46 +00:00
|
|
|
maker = None
|
2012-04-04 15:48:29 +00:00
|
|
|
ratio = 0.5
|
2011-08-21 00:25:34 +00:00
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
self.terminator = Terminator()
|
2011-08-22 19:20:46 +00:00
|
|
|
self.maker = Factory()
|
2009-11-14 22:58:22 +00:00
|
|
|
Container.__init__(self)
|
2009-11-08 23:06:26 +00:00
|
|
|
self.signals.append({'name': 'resize-term',
|
2014-09-19 14:08:08 +00:00
|
|
|
'flags': GObject.SignalFlags.RUN_LAST,
|
|
|
|
'return_type': None,
|
|
|
|
'param_types': (GObject.TYPE_STRING,)})
|
2009-11-07 01:40:43 +00:00
|
|
|
|
|
|
|
|
2009-11-14 17:30:03 +00:00
|
|
|
# pylint: disable-msg=W0613
|
2010-03-05 22:44:38 +00:00
|
|
|
def split_axis(self, widget, vertical=True, cwd=None, sibling=None,
|
2010-03-02 20:38:28 +00:00
|
|
|
widgetfirst=True):
|
2009-11-07 01:40:43 +00:00
|
|
|
"""Default axis splitter. This should be implemented by subclasses"""
|
2010-02-27 12:30:38 +00:00
|
|
|
order = None
|
2010-02-27 10:26:30 +00:00
|
|
|
|
2009-11-08 01:06:31 +00:00
|
|
|
self.remove(widget)
|
|
|
|
if vertical:
|
|
|
|
container = VPaned()
|
|
|
|
else:
|
|
|
|
container = HPaned()
|
2012-06-25 18:01:35 +00:00
|
|
|
|
|
|
|
self.get_toplevel().set_pos_by_ratio = True
|
2009-11-08 01:06:31 +00:00
|
|
|
|
2009-11-17 04:56:55 +00:00
|
|
|
if not sibling:
|
2011-08-22 19:20:46 +00:00
|
|
|
sibling = self.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-08 01:06:31 +00:00
|
|
|
|
2009-11-14 18:55:07 +00:00
|
|
|
self.add(container)
|
|
|
|
self.show_all()
|
|
|
|
|
2010-02-27 12:30:38 +00:00
|
|
|
order = [widget, sibling]
|
2010-03-02 20:38:28 +00:00
|
|
|
if widgetfirst is False:
|
2010-02-27 12:30:38 +00:00
|
|
|
order.reverse()
|
2010-02-27 10:26:30 +00:00
|
|
|
|
2010-02-27 12:30:38 +00:00
|
|
|
for terminal in order:
|
|
|
|
container.add(terminal)
|
2009-11-08 01:06:31 +00:00
|
|
|
|
|
|
|
self.show_all()
|
2013-02-10 15:58:06 +00:00
|
|
|
sibling.grab_focus()
|
2012-06-25 18:01:35 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
while Gtk.events_pending():
|
|
|
|
Gtk.main_iteration_do(False)
|
2012-06-25 18:01:35 +00:00
|
|
|
self.get_toplevel().set_pos_by_ratio = False
|
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2011-08-22 20:05:38 +00:00
|
|
|
def add(self, widget, metadata=None):
|
2009-11-07 01:40:43 +00:00
|
|
|
"""Add a widget to the container"""
|
|
|
|
if len(self.children) == 0:
|
2012-04-04 15:48:29 +00:00
|
|
|
self.pack1(widget, False, True)
|
2009-11-07 01:40:43 +00:00
|
|
|
self.children.append(widget)
|
|
|
|
elif len(self.children) == 1:
|
2009-11-08 01:06:31 +00:00
|
|
|
if self.get_child1():
|
2012-04-04 15:48:29 +00:00
|
|
|
self.pack2(widget, False, True)
|
2009-11-08 01:06:31 +00:00
|
|
|
else:
|
2012-04-04 15:48:29 +00:00
|
|
|
self.pack1(widget, False, True)
|
2009-11-07 01:40:43 +00:00
|
|
|
self.children.append(widget)
|
|
|
|
else:
|
2009-11-14 22:58:22 +00:00
|
|
|
raise ValueError('Paned widgets can only have two children')
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2011-08-22 19:20:46 +00:00
|
|
|
if self.maker.isinstance(widget, 'Terminal'):
|
2011-02-23 21:35:10 +00:00
|
|
|
top_window = self.get_toplevel()
|
2009-11-14 22:58:22 +00:00
|
|
|
signals = {'close-term': self.wrapcloseterm,
|
|
|
|
'split-horiz': self.split_horiz,
|
|
|
|
'split-vert': self.split_vert,
|
2009-12-10 13:20:03 +00:00
|
|
|
'title-change': self.propagate_title_change,
|
2009-11-14 22:58:22 +00:00
|
|
|
'resize-term': self.resizeterm,
|
2012-04-04 15:48:29 +00:00
|
|
|
'size-allocate': self.new_size,
|
2010-01-24 12:55:03 +00:00
|
|
|
'zoom': top_window.zoom,
|
|
|
|
'tab-change': top_window.tab_change,
|
|
|
|
'group-all': top_window.group_all,
|
2014-01-24 22:29:07 +00:00
|
|
|
'group-all-toggle': top_window.group_all_toggle,
|
2010-01-24 12:55:03 +00:00
|
|
|
'ungroup-all': top_window.ungroup_all,
|
|
|
|
'group-tab': top_window.group_tab,
|
2014-01-24 22:29:07 +00:00
|
|
|
'group-tab-toggle': top_window.group_tab_toggle,
|
2010-01-24 12:55:03 +00:00
|
|
|
'ungroup-tab': top_window.ungroup_tab,
|
2010-01-24 22:15:54 +00:00
|
|
|
'move-tab': top_window.move_tab,
|
2010-01-28 12:49:38 +00:00
|
|
|
'maximise': [top_window.zoom, False],
|
2010-04-02 15:45:32 +00:00
|
|
|
'tab-new': [top_window.tab_new, widget],
|
2012-04-04 15:48:29 +00:00
|
|
|
'navigate': top_window.navigate_terminal,
|
|
|
|
'rotate-cw': [top_window.rotate, True],
|
|
|
|
'rotate-ccw': [top_window.rotate, False]}
|
2009-11-14 22:58:22 +00:00
|
|
|
|
|
|
|
for signal in signals:
|
2010-01-24 12:55:03 +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:22 +00:00
|
|
|
|
2012-10-18 23:23:25 +00:00
|
|
|
if metadata and \
|
|
|
|
metadata.has_key('had_focus') and \
|
|
|
|
metadata['had_focus'] == True:
|
|
|
|
widget.grab_focus()
|
2009-11-14 23:04:15 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
elif isinstance(widget, Gtk.Paned):
|
2009-11-14 18:55:07 +00:00
|
|
|
try:
|
2009-11-14 22:58:22 +00:00
|
|
|
self.connect_child(widget, 'resize-term', self.resizeterm)
|
2012-04-04 15:48:29 +00:00
|
|
|
self.connect_child(widget, 'size-allocate', self.new_size)
|
2009-11-14 18:55:07 +00:00
|
|
|
except TypeError:
|
|
|
|
err('Paned::add: %s has no signal resize-term' % widget)
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2012-06-25 19:24:41 +00:00
|
|
|
def on_button_press(self, widget, event):
|
|
|
|
"""Handle button presses on a Pane"""
|
2014-09-19 14:10:43 +00:00
|
|
|
if event.button == 1 and event.type == Gdk.EventType._2BUTTON_PRESS:
|
2014-09-19 14:08:08 +00:00
|
|
|
if event.get_state() & Gdk.ModifierType.MOD4_MASK == Gdk.ModifierType.MOD4_MASK:
|
2012-06-25 19:24:41 +00:00
|
|
|
recurse_up=True
|
|
|
|
else:
|
|
|
|
recurse_up=False
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
if event.get_state() & Gdk.ModifierType.SHIFT_MASK == Gdk.ModifierType.SHIFT_MASK:
|
2012-06-25 19:24:41 +00:00
|
|
|
recurse_down=True
|
|
|
|
else:
|
|
|
|
recurse_down=False
|
|
|
|
|
2012-06-27 14:58:56 +00:00
|
|
|
# FIXME: These idle events are creating a lot of weird issues
|
|
|
|
for i in range(3):
|
2014-09-19 14:08:08 +00:00
|
|
|
while Gtk.events_pending():
|
|
|
|
Gtk.main_iteration_do(False)
|
2012-06-27 14:58:56 +00:00
|
|
|
self.do_redistribute(recurse_up, recurse_down)
|
|
|
|
|
2012-06-25 19:24:41 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def do_redistribute(self, recurse_up=False, recurse_down=False):
|
|
|
|
"""Evenly divide available space between sibling panes"""
|
|
|
|
#1 Find highest ancestor of the same type => ha
|
|
|
|
highest_ancestor = self
|
|
|
|
while type(highest_ancestor.get_parent()) == type(highest_ancestor):
|
|
|
|
highest_ancestor = highest_ancestor.get_parent()
|
|
|
|
|
|
|
|
# (1b) If Super modifier, redistribute higher sections too
|
|
|
|
if recurse_up:
|
|
|
|
grandfather=highest_ancestor.get_parent()
|
|
|
|
if grandfather != self.get_toplevel():
|
|
|
|
grandfather.do_redistribute(recurse_up, recurse_down)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.idle_add(highest_ancestor._do_redistribute, recurse_up, recurse_down)
|
|
|
|
while Gtk.events_pending():
|
|
|
|
Gtk.main_iteration_do(False)
|
|
|
|
GObject.idle_add(highest_ancestor._do_redistribute, recurse_up, recurse_down)
|
2012-06-25 19:24:41 +00:00
|
|
|
|
|
|
|
def _do_redistribute(self, recurse_up=False, recurse_down=False):
|
|
|
|
maker = Factory()
|
|
|
|
#2 Make a list of self + all children of same type
|
|
|
|
tree = [self, [], 0, None]
|
|
|
|
toproc = [tree]
|
|
|
|
number_splits = 1
|
|
|
|
while toproc:
|
|
|
|
curr = toproc.pop(0)
|
|
|
|
for child in curr[0].get_children():
|
|
|
|
if type(child) == type(curr[0]):
|
|
|
|
childset = [child, [], 0, curr]
|
|
|
|
curr[1].append(childset)
|
|
|
|
toproc.append(childset)
|
|
|
|
number_splits = number_splits+1
|
|
|
|
else:
|
|
|
|
curr[1].append([None,[], 1, None])
|
|
|
|
p = curr
|
|
|
|
while p:
|
|
|
|
p[2] = p[2] + 1
|
|
|
|
p = p[3]
|
|
|
|
# (1c) If Shift modifier, redistribute lower sections too
|
|
|
|
if recurse_down and \
|
|
|
|
(maker.isinstance(child, 'VPaned') or \
|
|
|
|
maker.isinstance(child, 'HPaned')):
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.idle_add(child.do_redistribute, False, True)
|
2012-06-25 19:24:41 +00:00
|
|
|
|
|
|
|
#3 Get ancestor x/y => a, and handle size => hs
|
|
|
|
avail_pixels=self.get_length()
|
2015-06-19 01:20:54 +00:00
|
|
|
value = GObject.Value(int)
|
|
|
|
self.style_get_property('handle-size', value)
|
|
|
|
handle_size = value.get_int()
|
2012-06-25 19:24:41 +00:00
|
|
|
#4 Math! eek (a - (n * hs)) / (n + 1) = single size => s
|
|
|
|
single_size = (avail_pixels - (number_splits * handle_size)) / (number_splits + 1)
|
|
|
|
arr_sizes = [single_size]*(number_splits+1)
|
|
|
|
for i in range(avail_pixels % (number_splits + 1)):
|
|
|
|
arr_sizes[i] = arr_sizes[i] + 1
|
|
|
|
#5 Descend down setting the handle position to s
|
|
|
|
# (Has to handle nesting properly)
|
|
|
|
toproc = [tree]
|
|
|
|
while toproc:
|
|
|
|
curr = toproc.pop(0)
|
|
|
|
for child in curr[1]:
|
|
|
|
toproc.append(child)
|
|
|
|
if curr[1].index(child) == 0:
|
|
|
|
curr[0].set_position((child[2]*single_size)+((child[2]-1)*handle_size))
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.idle_add(curr[0].set_position, child[2]*single_size)
|
2012-06-25 19:24:41 +00:00
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
def remove(self, widget):
|
|
|
|
"""Remove a widget from the container"""
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.Paned.remove(self, widget)
|
2009-11-14 22:58:22 +00:00
|
|
|
self.disconnect_child(widget)
|
2009-11-07 01:40:43 +00:00
|
|
|
self.children.remove(widget)
|
|
|
|
return(True)
|
|
|
|
|
2010-03-10 22:51:33 +00:00
|
|
|
def get_children(self):
|
|
|
|
"""Return an ordered list of our children"""
|
|
|
|
children = []
|
|
|
|
children.append(self.get_child1())
|
|
|
|
children.append(self.get_child2())
|
|
|
|
return(children)
|
|
|
|
|
2012-10-18 23:23:25 +00:00
|
|
|
def get_child_metadata(self, widget):
|
|
|
|
"""Return metadata about a child"""
|
|
|
|
metadata = {}
|
|
|
|
metadata['had_focus'] = widget.has_focus()
|
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
def wrapcloseterm(self, widget):
|
|
|
|
"""A child terminal has closed, so this container must die"""
|
2009-12-09 13:02:31 +00:00
|
|
|
dbg('Paned::wrapcloseterm: Called on %s' % widget)
|
2012-10-18 23:23:25 +00:00
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
if self.closeterm(widget):
|
|
|
|
# At this point we only have one child, which is the surviving term
|
|
|
|
sibling = self.children[0]
|
|
|
|
self.remove(sibling)
|
2009-11-25 00:37:29 +00:00
|
|
|
|
2011-08-22 20:05:38 +00:00
|
|
|
metadata = None
|
2009-11-25 00:37:29 +00:00
|
|
|
parent = self.get_parent()
|
2011-08-22 20:05:38 +00:00
|
|
|
metadata = parent.get_child_metadata(self)
|
|
|
|
dbg('metadata obtained for %s: %s' % (self, metadata))
|
2009-12-09 13:02:31 +00:00
|
|
|
parent.remove(self)
|
2010-01-25 12:55:38 +00:00
|
|
|
self.cnxids.remove_all()
|
2011-08-22 20:05:38 +00:00
|
|
|
parent.add(sibling, metadata)
|
2013-02-10 15:58:06 +00:00
|
|
|
sibling.grab_focus()
|
2009-11-07 01:40:43 +00:00
|
|
|
else:
|
2009-11-14 18:55:07 +00:00
|
|
|
dbg("Paned::wrapcloseterm: self.closeterm failed")
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2009-11-20 15:30:50 +00:00
|
|
|
def hoover(self):
|
|
|
|
"""Check that we still have a reason to exist"""
|
|
|
|
if len(self.children) == 1:
|
|
|
|
dbg('Paned::hoover: We only have one child, die')
|
|
|
|
parent = self.get_parent()
|
|
|
|
child = self.children[0]
|
|
|
|
self.remove(child)
|
2010-04-12 20:35:24 +00:00
|
|
|
parent.replace(self, child)
|
2009-11-20 15:30:50 +00:00
|
|
|
del(self)
|
|
|
|
|
2009-11-07 01:40:43 +00:00
|
|
|
def resizeterm(self, widget, keyname):
|
|
|
|
"""Handle a keyboard event requesting a terminal resize"""
|
2014-09-19 14:08:08 +00:00
|
|
|
if keyname in ['up', 'down'] and isinstance(self, Gtk.VPaned):
|
2009-11-08 23:06:26 +00:00
|
|
|
# This is a key we can handle
|
|
|
|
position = self.get_position()
|
|
|
|
|
2011-08-22 19:20:46 +00:00
|
|
|
if self.maker.isinstance(widget, 'Terminal'):
|
2009-11-08 23:06:26 +00:00
|
|
|
fontheight = widget.vte.get_char_height()
|
|
|
|
else:
|
|
|
|
fontheight = 10
|
|
|
|
|
|
|
|
if keyname == 'up':
|
|
|
|
self.set_position(position - fontheight)
|
|
|
|
else:
|
|
|
|
self.set_position(position + fontheight)
|
2014-09-19 14:08:08 +00:00
|
|
|
elif keyname in ['left', 'right'] and isinstance(self, Gtk.HPaned):
|
2009-11-08 23:06:26 +00:00
|
|
|
# This is a key we can handle
|
|
|
|
position = self.get_position()
|
|
|
|
|
2011-08-22 19:20:46 +00:00
|
|
|
if self.maker.isinstance(widget, 'Terminal'):
|
2009-11-08 23:06:26 +00:00
|
|
|
fontwidth = widget.vte.get_char_width()
|
|
|
|
else:
|
|
|
|
fontwidth = 10
|
|
|
|
|
|
|
|
if keyname == 'left':
|
|
|
|
self.set_position(position - fontwidth)
|
|
|
|
else:
|
|
|
|
self.set_position(position + fontwidth)
|
|
|
|
else:
|
|
|
|
# This is not a key we can handle
|
|
|
|
self.emit('resize-term', keyname)
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def create_layout(self, layout):
|
|
|
|
"""Apply layout configuration"""
|
|
|
|
if not layout.has_key('children'):
|
|
|
|
err('layout specifies no children: %s' % layout)
|
|
|
|
return
|
|
|
|
|
|
|
|
children = layout['children']
|
|
|
|
if len(children) != 2:
|
|
|
|
# Paned widgets can only have two children
|
|
|
|
err('incorrect number of children for Paned: %s' % layout)
|
|
|
|
return
|
|
|
|
|
2010-03-11 13:04:01 +00:00
|
|
|
keys = []
|
|
|
|
|
|
|
|
# FIXME: This seems kinda ugly. All we want here is to know the order
|
|
|
|
# of children based on child['order']
|
|
|
|
try:
|
|
|
|
child_order_map = {}
|
|
|
|
for child in children:
|
|
|
|
key = children[child]['order']
|
|
|
|
child_order_map[key] = child
|
|
|
|
map_keys = child_order_map.keys()
|
|
|
|
map_keys.sort()
|
|
|
|
for map_key in map_keys:
|
|
|
|
keys.append(child_order_map[map_key])
|
|
|
|
except KeyError:
|
|
|
|
# We've failed to figure out the order. At least give the terminals
|
|
|
|
# in the wrong order
|
|
|
|
keys = children.keys()
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
num = 0
|
2010-02-27 13:04:50 +00:00
|
|
|
for child_key in keys:
|
2010-02-02 00:39:41 +00:00
|
|
|
child = children[child_key]
|
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'] == 'Terminal':
|
2010-03-11 13:04:01 +00:00
|
|
|
pass
|
2010-02-01 12:11:44 +00:00
|
|
|
elif child['type'] == 'VPaned':
|
|
|
|
if num == 0:
|
|
|
|
terminal = self.get_child1()
|
|
|
|
else:
|
|
|
|
terminal = self.get_child2()
|
|
|
|
self.split_axis(terminal, True)
|
|
|
|
elif child['type'] == 'HPaned':
|
|
|
|
if num == 0:
|
|
|
|
terminal = self.get_child1()
|
|
|
|
else:
|
|
|
|
terminal = self.get_child2()
|
|
|
|
self.split_axis(terminal, False)
|
|
|
|
else:
|
|
|
|
err('unknown child type: %s' % child['type'])
|
2010-02-02 00:39:41 +00:00
|
|
|
num = num + 1
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
self.get_child1().create_layout(children[keys[0]])
|
|
|
|
self.get_child2().create_layout(children[keys[1]])
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2013-09-02 14:54:07 +00:00
|
|
|
# Set the position with ratio. For some reason more reliable than by pos.
|
|
|
|
if layout.has_key('ratio'):
|
|
|
|
self.ratio = float(layout['ratio'])
|
|
|
|
self.set_position_by_ratio()
|
2010-02-27 13:55:38 +00:00
|
|
|
|
2010-07-03 20:30:17 +00:00
|
|
|
def grab_focus(self):
|
|
|
|
"""We don't want focus, we want a Terminal to have it"""
|
|
|
|
self.get_child1().grab_focus()
|
|
|
|
|
2012-04-04 15:48:29 +00:00
|
|
|
def rotate(self, widget, clockwise):
|
|
|
|
"""Default rotation. This should be implemented by subclasses"""
|
|
|
|
if isinstance(self, HPaned):
|
|
|
|
container = VPaned()
|
|
|
|
reverse = not clockwise
|
|
|
|
else:
|
|
|
|
container = HPaned()
|
|
|
|
reverse = clockwise
|
|
|
|
|
|
|
|
container.ratio = self.ratio
|
|
|
|
|
|
|
|
self.get_parent().replace(self, container)
|
|
|
|
|
|
|
|
children = self.get_children()
|
|
|
|
if reverse:
|
|
|
|
container.ratio = 1 - container.ratio
|
|
|
|
children.reverse()
|
|
|
|
|
|
|
|
for child in children:
|
|
|
|
self.remove(child)
|
|
|
|
container.add(child)
|
|
|
|
|
|
|
|
def new_size(self, widget, allocation):
|
2012-06-25 17:05:43 +00:00
|
|
|
if self.get_toplevel().set_pos_by_ratio:
|
|
|
|
self.set_position_by_ratio()
|
|
|
|
else:
|
|
|
|
self.set_position(self.get_position())
|
|
|
|
|
|
|
|
def set_position_by_ratio(self):
|
2012-04-04 15:48:29 +00:00
|
|
|
self.set_pos(int(self.ratio*self.get_length()))
|
|
|
|
|
|
|
|
def set_position(self, pos):
|
|
|
|
self.ratio = float(pos) / self.get_length()
|
|
|
|
self.set_pos(pos)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
class HPaned(Paned, Gtk.HPaned):
|
|
|
|
"""Merge Gtk.HPaned into our base Paned Container"""
|
2009-11-07 01:40:43 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
Paned.__init__(self)
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.GObject.__init__(self)
|
2009-11-14 18:55:07 +00:00
|
|
|
self.register_signals(HPaned)
|
2012-06-25 19:24:41 +00:00
|
|
|
self.cnxids.new(self, 'button-press-event', self.on_button_press)
|
2012-04-04 15:48:29 +00:00
|
|
|
|
|
|
|
def get_length(self):
|
2014-09-19 14:10:43 +00:00
|
|
|
return(self.get_allocated_width())
|
2012-04-04 15:48:29 +00:00
|
|
|
|
|
|
|
def set_pos(self, pos):
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.HPaned.set_position(self, pos)
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
class VPaned(Paned, Gtk.VPaned):
|
|
|
|
"""Merge Gtk.VPaned into our base Paned Container"""
|
2009-11-07 01:40:43 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
Paned.__init__(self)
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.GObject.__init__(self)
|
2009-11-14 18:55:07 +00:00
|
|
|
self.register_signals(VPaned)
|
2012-06-25 19:24:41 +00:00
|
|
|
self.cnxids.new(self, 'button-press-event', self.on_button_press)
|
2012-04-04 15:48:29 +00:00
|
|
|
|
|
|
|
def get_length(self):
|
2014-09-19 14:10:43 +00:00
|
|
|
return(self.get_allocated_height())
|
2012-04-04 15:48:29 +00:00
|
|
|
|
|
|
|
def set_pos(self, pos):
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.VPaned.set_position(self, pos)
|
2009-11-07 01:40:43 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
GObject.type_register(HPaned)
|
|
|
|
GObject.type_register(VPaned)
|
2009-11-07 01:40:43 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|