1 ############################################################################
2 # Copyright (C) 2005 by Reithinger GmbH
5 # This file is part of metapie.
7 # metapie is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # pyplan is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the
19 # Free Software Foundation, Inc.,
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ############################################################################
29 ##class _MetaBrowser(dblayout._MetaModel):
30 ## def __init__(cls, name, bases, dict_):
31 ## if cls._contained_:
32 ## dblayout.Relation("",
33 ## dblayout.End(cls._contained_, "objects", multi='*'),
35 ## metapie._browsers_.append(cls)
37 ## super(_MetaBrowser, cls).__init__(name, bases, dict_)
38 ## cls.set_instance(cls())
41 ##class Browser(dblayout.Model):
42 ## __metaclass__ = _MetaBrowser
43 ## __bitmap__ = "browse.gif"
44 ## _contained_ = None # the contained class (to be set by subclass)
45 ## _keys_ = None # keys of _contained_ (to be set by subclass)
49 ## #return self._contained_.__name__
50 ## return self.__class__.__name__
53 ## def insert(self, obj):
54 ## self.objects.insert(obj)
57 ## def search(self, query, sort=None):
58 ## return self.objects.search(query, sort)
61 ## def __len__(self): return len(self.objects)
62 ## def __iter__(self): return iter(self.objects)
63 ## def __contains__(self, y): return y in self.objects
64 ## def __iter__(self): return iter(self.objects)
65 ## def __getitem__(self, idx): return self.objects[idx]
66 ## def __delitem__(self, obj): del self.objects[obj]
68 ## def set_instance(cls, instance):
69 ## cls.instance = instance
71 ## set_instance = classmethod(set_instance)
74 class Browsers(navigator
.Model
):
76 for b
in metapie
._browsers
_:
77 setattr(self
, b
.__name
__, b
.instance
)
85 ctrl
= metapie
.controller()
87 for b
in metapie
._browsers
_:
90 ctrl
.register_view(self
,
91 navigator
.get_title(browser
),
92 browser
.constitute("BrowserView"),
93 navigator
.get_bitmap(browser
))
96 def accept_sibling(self
, sibling
):
97 return navigator
.SIBLING_BELOW
100 class _MetaBrowser(type):
101 def __init__(cls
, name
, bases
, dict_
):
102 super(_MetaBrowser
, cls
).__init
__(name
, bases
, dict_
)
105 class _Browser(dblayout
.Model
):
106 def insert(self
, obj
): self
.objects
.insert(obj
)
107 def search(self
, query
, sort
=None):
108 return self
.objects
.search(query
, sort
)
110 def __len__(self
): return len(self
.objects
)
111 def __iter__(self
): return iter(self
.objects
)
112 def __contains__(self
, y
): return y
in self
.objects
113 def __iter__(self
): return iter(self
.objects
)
114 def __getitem__(self
, key
): return self
.objects
[key
]
115 def __delitem__(self
, obj
): del self
.objects
[obj
]
118 #convert to a top level class that can be pickled
119 _Browser
.__name
__ = name
+ "_browser_"
120 setattr(sys
.modules
[cls
.__module
__], _Browser
.__name
__, _Browser
)
122 dblayout
.Relation("",
123 dblayout
.End(cls
._contained
_, "objects", multi
='*'),
124 dblayout
.End(_Browser
))
125 metapie
._browsers
_.append(cls
)
126 cls
.set_instance(_Browser())
129 def set_instance(cls
, instance
):
130 cls
.instance
= instance
133 def __getattr__(cls
, name
):
134 return getattr(cls
.instance
, name
)
141 def __len__(cls
): return len(cls
.instance
)
142 def __iter__(cls
): return iter(cls
.instance
)
143 def __contains__(cls
, y
): return y
in cls
.instance
144 def __iter__(cls
): return iter(cls
.instance
)
145 def __getitem__(cls
, key
): return cls
.instance
[key
]
146 def __delitem__(cls
, obj
): del cls
.instance
[obj
]
150 __metaclass__
= _MetaBrowser
151 __bitmap__
= "browse.gif"
152 _contained_
= None # the contained class (to be set by subclass)
153 _keys_
= None # keys of _contained_ (to be set by subclass)