summaryrefslogtreecommitdiff
path: root/src/singleton.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-03-05 21:42:56 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-03-05 21:42:56 +0100
commitfb40ac54fc6e9fe79f29fd99e836187e95bb0509 (patch)
tree19bced4c4e2fb557b150553b66335b14bdc1ab85 /src/singleton.py
parent9c291d1368f004828b123edca65f11c4f6e96dfc (diff)
downloadpoezio-fb40ac54fc6e9fe79f29fd99e836187e95bb0509.tar.gz
poezio-fb40ac54fc6e9fe79f29fd99e836187e95bb0509.tar.bz2
poezio-fb40ac54fc6e9fe79f29fd99e836187e95bb0509.tar.xz
poezio-fb40ac54fc6e9fe79f29fd99e836187e95bb0509.zip
Kind of big cleanup.
Core and Connection classes are now used as singletons, we do not need to pass them to each Tab and Win. This remove a lot of arguments to varius methods.
Diffstat (limited to 'src/singleton.py')
-rw-r--r--src/singleton.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/singleton.py b/src/singleton.py
new file mode 100644
index 00000000..c47fb269
--- /dev/null
+++ b/src/singleton.py
@@ -0,0 +1,29 @@
+# Copyright 2010-2011 Le Coz Florent <louiz@louiz.org>
+#
+# This file is part of Poezio.
+#
+# Poezio is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# Poezio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Defines a Singleton function that initialize an object
+of the given class if it was never instantiated yet. Else, returns
+the previously instantiated object.
+This method is the only one that I can come up with that do not call
+__init__() each time.
+"""
+
+instances = {}
+def Singleton(cls, *args, **kwargs):
+ if not cls in instances:
+ instances[cls] = cls(*args, **kwargs)
+ return instances[cls]