(trunk-1679) Fix flickering and intermittent failures to rebalance

This commit is contained in:
Stephen Boddy 2015-11-05 10:57:57 +01:00
parent fb8c35f259
commit 109e26161a
1 changed files with 17 additions and 7 deletions

View File

@ -4,6 +4,7 @@
"""paned.py - a base Paned container class and the vertical/horizontal
variants"""
import time
from gi.repository import GObject, Gtk, Gdk
from util import dbg, err
@ -19,6 +20,8 @@ class Paned(Container):
position = None
maker = None
ratio = 0.5
last_balance_time = 0
last_balance_args = None
def __init__(self):
"""Class initialiser"""
@ -141,17 +144,22 @@ class Paned(Container):
recurse_down=True
else:
recurse_down=False
# FIXME: These idle events are creating a lot of weird issues
for i in range(3):
while Gtk.events_pending():
Gtk.main_iteration_do(False)
self.do_redistribute(recurse_up, recurse_down)
self.last_balance_time = time.time()
self.last_balance_args = (recurse_up, recurse_down)
return True
else:
return False
def on_button_release(self, widget, event):
"""Handle button presses on a Pane"""
if event.button == 1:
if self.last_balance_time > (time.time() - 1):
while Gtk.events_pending():
Gtk.main_iteration_do(False)
self.do_redistribute(*self.last_balance_args)
return False
def do_redistribute(self, recurse_up=False, recurse_down=False):
"""Evenly divide available space between sibling panes"""
maker = Factory()
@ -416,6 +424,7 @@ class HPaned(Paned, Gtk.HPaned):
GObject.GObject.__init__(self)
self.register_signals(HPaned)
self.cnxids.new(self, 'button-press-event', self.on_button_press)
self.cnxids.new(self, 'button-release-event', self.on_button_release)
def get_length(self):
return(self.get_allocated_width())
@ -431,6 +440,7 @@ class VPaned(Paned, Gtk.VPaned):
GObject.GObject.__init__(self)
self.register_signals(VPaned)
self.cnxids.new(self, 'button-press-event', self.on_button_press)
self.cnxids.new(self, 'button-release-event', self.on_button_release)
def get_length(self):
return(self.get_allocated_height())