stop creating factories all the time and cache one
This commit is contained in:
parent
0ba791f9cb
commit
7a49cd47bc
|
@ -18,10 +18,12 @@ class Paned(Container):
|
||||||
"""Base class for Paned Containers"""
|
"""Base class for Paned Containers"""
|
||||||
|
|
||||||
position = None
|
position = None
|
||||||
|
maker = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Class initialiser"""
|
"""Class initialiser"""
|
||||||
self.terminator = Terminator()
|
self.terminator = Terminator()
|
||||||
|
self.maker = Factory()
|
||||||
Container.__init__(self)
|
Container.__init__(self)
|
||||||
self.signals.append({'name': 'resize-term',
|
self.signals.append({'name': 'resize-term',
|
||||||
'flags': gobject.SIGNAL_RUN_LAST,
|
'flags': gobject.SIGNAL_RUN_LAST,
|
||||||
|
@ -48,8 +50,6 @@ class Paned(Container):
|
||||||
"""Default axis splitter. This should be implemented by subclasses"""
|
"""Default axis splitter. This should be implemented by subclasses"""
|
||||||
order = None
|
order = None
|
||||||
|
|
||||||
maker = Factory()
|
|
||||||
|
|
||||||
self.remove(widget)
|
self.remove(widget)
|
||||||
if vertical:
|
if vertical:
|
||||||
container = VPaned()
|
container = VPaned()
|
||||||
|
@ -57,7 +57,7 @@ class Paned(Container):
|
||||||
container = HPaned()
|
container = HPaned()
|
||||||
|
|
||||||
if not sibling:
|
if not sibling:
|
||||||
sibling = maker.make('terminal')
|
sibling = self.maker.make('terminal')
|
||||||
sibling.set_cwd(cwd)
|
sibling.set_cwd(cwd)
|
||||||
sibling.spawn_child()
|
sibling.spawn_child()
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ class Paned(Container):
|
||||||
|
|
||||||
def add(self, widget):
|
def add(self, widget):
|
||||||
"""Add a widget to the container"""
|
"""Add a widget to the container"""
|
||||||
maker = Factory()
|
|
||||||
if len(self.children) == 0:
|
if len(self.children) == 0:
|
||||||
self.pack1(widget, True, True)
|
self.pack1(widget, True, True)
|
||||||
self.children.append(widget)
|
self.children.append(widget)
|
||||||
|
@ -88,7 +87,7 @@ class Paned(Container):
|
||||||
else:
|
else:
|
||||||
raise ValueError('Paned widgets can only have two children')
|
raise ValueError('Paned widgets can only have two children')
|
||||||
|
|
||||||
if maker.isinstance(widget, 'Terminal'):
|
if self.maker.isinstance(widget, 'Terminal'):
|
||||||
top_window = self.get_toplevel()
|
top_window = self.get_toplevel()
|
||||||
signals = {'close-term': self.wrapcloseterm,
|
signals = {'close-term': self.wrapcloseterm,
|
||||||
'split-horiz': self.split_horiz,
|
'split-horiz': self.split_horiz,
|
||||||
|
@ -165,12 +164,11 @@ class Paned(Container):
|
||||||
|
|
||||||
def resizeterm(self, widget, keyname):
|
def resizeterm(self, widget, keyname):
|
||||||
"""Handle a keyboard event requesting a terminal resize"""
|
"""Handle a keyboard event requesting a terminal resize"""
|
||||||
maker = Factory()
|
|
||||||
if keyname in ['up', 'down'] and isinstance(self, gtk.VPaned):
|
if keyname in ['up', 'down'] and isinstance(self, gtk.VPaned):
|
||||||
# This is a key we can handle
|
# This is a key we can handle
|
||||||
position = self.get_position()
|
position = self.get_position()
|
||||||
|
|
||||||
if maker.isinstance(widget, 'Terminal'):
|
if self.maker.isinstance(widget, 'Terminal'):
|
||||||
fontheight = widget.vte.get_char_height()
|
fontheight = widget.vte.get_char_height()
|
||||||
else:
|
else:
|
||||||
fontheight = 10
|
fontheight = 10
|
||||||
|
@ -183,7 +181,7 @@ class Paned(Container):
|
||||||
# This is a key we can handle
|
# This is a key we can handle
|
||||||
position = self.get_position()
|
position = self.get_position()
|
||||||
|
|
||||||
if maker.isinstance(widget, 'Terminal'):
|
if self.maker.isinstance(widget, 'Terminal'):
|
||||||
fontwidth = widget.vte.get_char_width()
|
fontwidth = widget.vte.get_char_width()
|
||||||
else:
|
else:
|
||||||
fontwidth = 10
|
fontwidth = 10
|
||||||
|
|
Loading…
Reference in New Issue