miscutil.py
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
###############################################################################
# Name: miscutil.py #
# Purpose: Various helper functions. #
# Author: Cody Precord <cprecord@editra.org> #
# Copyright: (c) 2009 Cody Precord <staff@editra.org> #
# Licence: wxWindows Licence #
###############################################################################
"""
Editra Business Model Library: MiscUtil
Various helper functions
"""
__author__ = "Cody Precord <cprecord@editra.org>"
__cvsid__ = "$Id: miscutil.py 67329 2011-03-28 23:40:48Z CJP $"
__revision__ = "$Revision: 67329 $"
__all__ = [ 'MinMax', 'Singleton']
#-----------------------------------------------------------------------------#
# Imports
#-----------------------------------------------------------------------------#
class Singleton(type):
"""Singleton metaclass for creating singleton classes
@note: class being applied to must have a SetupWindow method
"""
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls, *args, **kw):
if not cls.instance:
# Not created or has been Destroyed
obj = super(Singleton, cls).__call__(*args, **kw)
cls.instance = obj
return cls.instance
#-----------------------------------------------------------------------------#
def MinMax(arg1, arg2):
"""Return an ordered tuple of the minimum and maximum value
of the two args.
@return: tuple
"""
return min(arg1, arg2), max(arg1, arg2)