From fe37448440fc7299c44d5c1690b9d38d90bf57a6 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 11 Aug 2009 23:19:06 +0100 Subject: [PATCH] switch from a singleton to a borg, and don't do circular imports --- terminatorlib/borg.py | 11 +++++++++++ terminatorlib/newterminator.py | 20 ++++++++++++-------- terminatorlib/terminal.py | 2 -- 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100755 terminatorlib/borg.py diff --git a/terminatorlib/borg.py b/terminatorlib/borg.py new file mode 100755 index 00000000..622c9af6 --- /dev/null +++ b/terminatorlib/borg.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +# Terminator by Chris Jones +# GPL v2 only +"""borg.py - We are the borg. Resistance is futile. + http://code.activestate.com/recipes/66531/""" + +class Borg: + __shared_state = {} + def __init__(self): + self.__dict__ = self.__shared_state + diff --git a/terminatorlib/newterminator.py b/terminatorlib/newterminator.py index f9bb1330..4287abd1 100755 --- a/terminatorlib/newterminator.py +++ b/terminatorlib/newterminator.py @@ -3,9 +3,10 @@ # GPL v2 only """terminator.py - class for the master Terminator singleton""" +from borg import Borg from terminal import Terminal -class _Terminator(object): +class Terminator(Borg): """master object for the application""" window = None @@ -17,8 +18,16 @@ class _Terminator(object): def __init__(self): """Class initialiser""" - self.terminals = [] - self.groups = [] + Borg.__init__(self) + self.prepare_attributes() + + def prepare_attributes(self): + """Initialise anything that isn't alread""" + + if not self.terminals: + self.terminals = [] + if not self.groups: + self.groups = [] def new_terminal(self): """Create and register a new terminal widget""" @@ -50,9 +59,4 @@ class _Terminator(object): for group in todestroy: self.groups.remove(group) -TERMINATOR = _Terminator() -def Terminator(): - """Return the instance""" - return(TERMINATOR) - # vim: set expandtab ts=4 sw=4: diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 577aa106..46aba4a4 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -22,8 +22,6 @@ except ImportError: error.run() sys.exit(1) -from terminator import Terminator - class Terminal(gtk.VBox): """Class implementing the VTE widget and its wrappings"""