Package Camelot :: Package camelot :: Package container
[frames] | no frames]

Source Code for Package Camelot.camelot.container

 1  #  ============================================================================ 
 2  # 
 3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
 4  #  www.conceptive.be / project-camelot@conceptive.be 
 5  # 
 6  #  This file is part of the Camelot Library. 
 7  # 
 8  #  This file may be used under the terms of the GNU General Public 
 9  #  License version 2.0 as published by the Free Software Foundation 
10  #  and appearing in the file LICENSE.GPL included in the packaging of 
11  #  this file.  Please review the following information to ensure GNU 
12  #  General Public Licensing requirements will be met: 
13  #  http://www.trolltech.com/products/qt/opensource.html 
14  # 
15  #  If you are unsure which license is appropriate for your use, please 
16  #  review the following information: 
17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
18  #  project-camelot@conceptive.be. 
19  # 
20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
22  # 
23  #  For use of this library in commercial applications, please contact 
24  #  project-camelot@conceptive.be 
25  # 
26  #  ============================================================================ 
27   
28  """Container classes are classes that are used to transport data between the 
29  model thread and the GUI thread. 
30   
31  When complex data sets need to be visualized (eg.: charts, intervals), built-in 
32  python types don't contain enough information, while dictionary like structures 
33  are not self documented.  Hence the need of specialized container classes to 
34  transport this data between the model and the GUI. 
35   
36  To use this classes : 
37   
38  1. On your model class, define properties returning a container class 
39  2. In the admin class, add the property to the list of fields to visualize, and 
40     specify its delegate 
41   
42  eg: 
43   
44  class MyEntity(Entity): 
45   
46    @property 
47    def my_interval(self): 
48      return IntervalsContainer() 
49   
50    class Admin(EntityAdmin): 
51      form_display = ['my_interval'] 
52      field_attributes = dict(my_interval=dict(delegate=IntervalsDelegate)) 
53   
54  """ 
55   
56 -class Container(object):
57 """Top level class for all container classes""" 58 pass
59
60 -class Interval(object):
61 """Helper class for IntervalsContainer, specifications for one interval""" 62
63 - def __init__(self, begin, end, name, color):
64 self.begin = begin 65 self.end = end 66 self.name = name 67 self.color = color
68
69 - def __unicode__(self):
70 return u'[%s,%s]'%(self.begin, self.end)
71
72 -class IntervalsContainer(Container):
73 """Containter to hold interval data 74 75 eg : representing the time frame of 8pm till 6am that someone was at work using an hourly 76 precision : 77 78 intervals = IntervalsContainer(0, 24, [Interval(8, 18, 'work')]) 79 """ 80
81 - def __init__(self, min, max, intervals):
82 """ 83 @param min: minimum value that the begin value of an interval is allowed to have 84 @param max: maximum ... 85 @param intervals: list of Interval classes 86 """ 87 self.min = min 88 self.max = max 89 self.intervals = intervals
90
91 - def __unicode__(self):
92 return u', '.join(unicode(i) for i in self.intervals)
93