Parent Directory
|
Revision Log
Revision 1.37 - (view) (download) (as text)
1 : | efrank | 1.37 | |
2 : | efrank | 1.24 | from wxPython.wx import * |
3 : | efrank | 1.28 | from KahOM.RecoElem import RecoElem |
4 : | from PyGUI.RecoElempanel import RecoElempanel | ||
5 : | efrank | 1.24 | from CatalogServices.Catalog import Catalog |
6 : | efrank | 1.12 | |
7 : | |||
8 : | hwang | 1.21 | class Catalogpanel: |
9 : | efrank | 1.4 | #------------------------------------------------------------------------ |
10 : | hwang | 1.1 | def __init__(self, parent): |
11 : | efrank | 1.4 | #------------------------------------------------------------------------ |
12 : | efrank | 1.13 | self.parent = parent |
13 : | |||
14 : | efrank | 1.2 | self.selected = None #remember last selected catalog entry |
15 : | #..is used when LOAD button is hit. | ||
16 : | efrank | 1.4 | |
17 : | efrank | 1.14 | # seedItemId is the wxPython id for the "Seed" node |
18 : | # in the catalog tree under which all specific Seed servers | ||
19 : | # are listed | ||
20 : | |||
21 : | self.seedItemId = None | ||
22 : | |||
23 : | efrank | 1.4 | self.initCatEvents() |
24 : | self.initCatData() | ||
25 : | efrank | 1.14 | |
26 : | |||
27 : | efrank | 1.25 | # setup catalog editing menu (right click) |
28 : | |||
29 : | self.catEditMenu = wxMenu() | ||
30 : | self.catEditMkItemId = wxNewId() | ||
31 : | self.catEditMkDirId = wxNewId() | ||
32 : | self.setupCatEditMenu() | ||
33 : | efrank | 1.14 | |
34 : | efrank | 1.4 | return |
35 : | |||
36 : | |||
37 : | #------------------------------------------------------------------------ | ||
38 : | hwang | 1.30 | def initCatEvents(self): |
39 : | efrank | 1.4 | #------------------------------------------------------------------------ |
40 : | hwang | 1.22 | |
41 : | efrank | 1.6 | EVT_TREE_SEL_CHANGED(self.parent.catalog_tree, |
42 : | self.parent.catalog_treeId, | ||
43 : | self.onLeftClick) | ||
44 : | efrank | 1.14 | |
45 : | # Right click on List item for Seed will let you connect to | ||
46 : | # another Seed server | ||
47 : | |||
48 : | EVT_RIGHT_DOWN(self.parent.catalog_tree, self.onRightClickCatalogTree) | ||
49 : | |||
50 : | hwang | 1.20 | |
51 : | hwang | 1.22 | EVT_LEFT_DCLICK (self.parent.catalog_tree, self.onLeftDClick) |
52 : | efrank | 1.6 | |
53 : | efrank | 1.25 | EVT_COMBOBOX(self.parent.catVersionValueComboBox, |
54 : | self.parent.catVersionValueComboBox.GetId(), | ||
55 : | self.onCatVersionValueComboBox) | ||
56 : | |||
57 : | efrank | 1.4 | return |
58 : | |||
59 : | #------------------------------------------------------------------------ | ||
60 : | def initCatData( self ): | ||
61 : | #------------------------------------------------------------------------ | ||
62 : | efrank | 1.25 | |
63 : | efrank | 1.26 | self.parent.catalogRootId = self.parent.catalog_tree.AddRoot("/") |
64 : | efrank | 1.25 | self.loadCatalog() |
65 : | efrank | 1.13 | |
66 : | efrank | 1.6 | self.parent.catalog_tree.Expand( self.parent.catalogRootId) |
67 : | efrank | 1.2 | return |
68 : | efrank | 1.4 | |
69 : | efrank | 1.14 | #------------------------------------------------------------------ |
70 : | efrank | 1.25 | def setupCatEditMenu(self): |
71 : | efrank | 1.14 | #------------------------------------------------------------------ |
72 : | |||
73 : | efrank | 1.25 | self.catEditMenu.Append( self.catEditMkDirId, |
74 : | "New Directory", "NewDirectory" ) | ||
75 : | EVT_MENU(self.parent, self.catEditMkDirId, self.doCatEditMkDir) | ||
76 : | |||
77 : | self.catEditMenu.Append( self.catEditMkItemId, | ||
78 : | "New Item", "NewDirectory" ) | ||
79 : | EVT_MENU(self.parent, self.catEditMkItemId, self.doCatEditMkItem) | ||
80 : | |||
81 : | return | ||
82 : | efrank | 1.14 | |
83 : | efrank | 1.4 | #------------------------------------------------------------------------ |
84 : | efrank | 1.25 | def loadCatalog(self): |
85 : | #------------------------------------------------------------------------ | ||
86 : | wxBeginBusyCursor() | ||
87 : | |||
88 : | sheradon | 1.32 | #localSeedServer = "http://localhost/FIG" |
89 : | #seedFactory = SeedDataFactory( localSeedServer ) | ||
90 : | efrank | 1.33 | |
91 : | efrank | 1.34 | ## |
92 : | # DO NOT CREATE BssFactory() HERE ANY LONGER | ||
93 : | # See main progam, ModelEditor | ||
94 : | ## | ||
95 : | efrank | 1.25 | |
96 : | efrank | 1.26 | ## |
97 : | # Handle top/root of catalog/tree specially to avoid "two root" | ||
98 : | # on display problem | ||
99 : | ## | ||
100 : | |||
101 : | efrank | 1.25 | top = Catalog.instance().getCatalogTop() |
102 : | efrank | 1.26 | parentTree = self.parent.catalog_tree |
103 : | parentTree.SetPyData( self.parent.catalogRootId, | ||
104 : | (self.recoElemLoader, top, self.parent.catalogRootId) ) | ||
105 : | |||
106 : | for e in top.entries(): | ||
107 : | self.recurseCatalog( e, parentTree, self.parent.catalogRootId) | ||
108 : | |||
109 : | parentTree.SortChildren( self.parent.catalogRootId) | ||
110 : | efrank | 1.25 | |
111 : | wxEndBusyCursor() | ||
112 : | |||
113 : | return | ||
114 : | |||
115 : | #------------------------------------------------------------------------ | ||
116 : | efrank | 1.26 | def recurseCatalog( self, catEntry, parentTree, parentItemId): |
117 : | #------------------------------------------------------------------------ | ||
118 : | """ | ||
119 : | Create a new item under parentItemId in wxTree, parentTree. Associate | ||
120 : | catEntry with it. If catEntry has entries, recurse on them. | ||
121 : | """ | ||
122 : | |||
123 : | if ( catEntry.isTerminal() ): | ||
124 : | displayedName = catEntry.name() | ||
125 : | else: | ||
126 : | displayedName = catEntry.name() + "/" | ||
127 : | |||
128 : | newItemId=parentTree.AppendItem(parentItemId, displayedName ) | ||
129 : | |||
130 : | # associate data needed to manipulate the catEntry | ||
131 : | |||
132 : | parentTree.SetPyData( newItemId, | ||
133 : | (self.recoElemLoader, catEntry, newItemId ) ) | ||
134 : | |||
135 : | if ( not catEntry.isTerminal() ): | ||
136 : | for e in catEntry.entries(): | ||
137 : | self.recurseCatalog( e, parentTree, newItemId) | ||
138 : | |||
139 : | parentTree.SortChildren( newItemId ) | ||
140 : | |||
141 : | return | ||
142 : | |||
143 : | #------------------------------------------------------------------------ | ||
144 : | sheradon | 1.32 | def DOOMloadSeedCatalog(self, seedServer ): |
145 : | efrank | 1.12 | #------------------------------------------------------------------------ |
146 : | efrank | 1.27 | """ |
147 : | This adds a Seed instance to the catalog. It is called from the | ||
148 : | MainMenuBar when Data->Add Seed Instance is called, for example. | ||
149 : | """ | ||
150 : | |||
151 : | efrank | 1.14 | wxBeginBusyCursor() |
152 : | |||
153 : | efrank | 1.27 | # The SeedDataFactory ctor is slow and actually reads a bunch of |
154 : | # data from the server | ||
155 : | |||
156 : | efrank | 1.25 | seedFactory = SeedDataFactory( seedServer ) |
157 : | |||
158 : | # add it to the list in the catalog | ||
159 : | try: | ||
160 : | Catalog.instance().addDataFactory( seedFactory ) | ||
161 : | except: | ||
162 : | self.parent.error("loadSeedCatalog: %s already in foundry list." % seedServer) | ||
163 : | wxEndBusyCursor() | ||
164 : | return | ||
165 : | |||
166 : | top = seedFactory.getCatalogTop() | ||
167 : | self.recurseCatalog( top, self.parent.catalog_tree, self.parent.catalogRootId) | ||
168 : | |||
169 : | wxEndBusyCursor() | ||
170 : | |||
171 : | return | ||
172 : | |||
173 : | #------------------------------------------------------------------------ | ||
174 : | efrank | 1.6 | def onLeftClick(self,treeEvent): |
175 : | efrank | 1.4 | #------------------------------------------------------------------------ |
176 : | efrank | 1.5 | item = treeEvent.GetItem() |
177 : | hwang | 1.11 | |
178 : | efrank | 1.4 | catEntryTuple = self.parent.tree_ctr.GetPyData(item) |
179 : | efrank | 1.5 | if (catEntryTuple == None ): |
180 : | return | ||
181 : | efrank | 1.6 | self.selected = catEntryTuple |
182 : | efrank | 1.25 | catEntry = catEntryTuple[1] |
183 : | efrank | 1.4 | |
184 : | efrank | 1.25 | ## |
185 : | # update the history information display | ||
186 : | ## | ||
187 : | |||
188 : | theBox = self.parent.catVersionValueComboBox | ||
189 : | theBox.Clear() | ||
190 : | |||
191 : | if ( not catEntry.isTerminal() ): | ||
192 : | hwang | 1.31 | |
193 : | self.parent.catPathValue.SetValue( catEntry.path() + "/" ) | ||
194 : | efrank | 1.25 | self.parent.catVersionValueComboBox.SetLabel( "") |
195 : | self.parent.catHistoryDateValue.SetLabel( "" ) | ||
196 : | self.parent.catHistoryUserValue.SetLabel( "" ) | ||
197 : | self.parent.catHistoryCreatedFromValue.SetLabel( "") | ||
198 : | efrank | 1.26 | theBox.SetValue( "" ) |
199 : | efrank | 1.25 | else: |
200 : | versions = catEntry.versions() | ||
201 : | if ( [] == versions ): | ||
202 : | efrank | 1.36 | self.parent.catPathValue.SetValue( catEntry.path()+";[None]" ) |
203 : | efrank | 1.26 | theBox.SetValue( "None" ) |
204 : | efrank | 1.25 | else: |
205 : | maxVersion = max( versions ) | ||
206 : | for v in versions: | ||
207 : | theBox.Append( "%s" % (v ) ) | ||
208 : | theBox.SetValue( "%s" % (maxVersion) ) | ||
209 : | efrank | 1.36 | self.parent.catPathValue.SetValue(catEntry.path()+";[%s]" % (maxVersion)) |
210 : | efrank | 1.25 | # |
211 : | self.parent.catHistoryDateValue.SetLabel( "no date info yet" ) | ||
212 : | self.parent.catHistoryUserValue.SetLabel( "no user info yet" ) | ||
213 : | self.parent.catHistoryCreatedFromValue.SetLabel( "no history info yet" ) | ||
214 : | |||
215 : | efrank | 1.4 | return |
216 : | efrank | 1.14 | |
217 : | efrank | 1.25 | |
218 : | #------------------------------------------------------------------------ | ||
219 : | def onCatVersionValueComboBox(self, event): | ||
220 : | #------------------------------------------------------------------------ | ||
221 : | """ | ||
222 : | Handles activity in combo box where user sets Verion to use | ||
223 : | """ | ||
224 : | hwang | 1.30 | |
225 : | efrank | 1.25 | # get the value selected in the combo box. |
226 : | choice = event.GetString() | ||
227 : | efrank | 1.26 | self.parent.catVersionValueComboBox.SetValue( "%s" % (choice) ) |
228 : | efrank | 1.25 | |
229 : | # the operation is interpreted relative to the currently selected | ||
230 : | # catalogEntry. find what that is. | ||
231 : | |||
232 : | catEntry = self.selected[1] | ||
233 : | |||
234 : | # update stuff | ||
235 : | #version = self.parent.catVersionValueComboBox.GetValue() | ||
236 : | self.parent.catPathValue.SetLabel( catEntry.path()+";[%s]" % (choice) ) | ||
237 : | |||
238 : | return | ||
239 : | |||
240 : | |||
241 : | efrank | 1.14 | #------------------------------------------------------------------------ |
242 : | def onRightClickCatalogTree(self, event): | ||
243 : | #------------------------------------------------------------------------ | ||
244 : | efrank | 1.27 | """ Fires off the pop-up menu to handle right click events. """ |
245 : | efrank | 1.14 | |
246 : | efrank | 1.27 | event.GetEventObject().PopupMenu(self.catEditMenu, event.GetPosition()) |
247 : | efrank | 1.14 | return |
248 : | |||
249 : | #------------------------------------------------------------------------ | ||
250 : | efrank | 1.25 | def doCatEditMkDir( self, event ): |
251 : | #------------------------------------------------------------------------ | ||
252 : | if (None == self.selected): | ||
253 : | self.parent.error( "A selection is required first.") | ||
254 : | return | ||
255 : | |||
256 : | catEntryTuple = self.selected | ||
257 : | catEntry = catEntryTuple[1] | ||
258 : | treeItemId = catEntryTuple[2] | ||
259 : | |||
260 : | if (catEntry.isTerminal()): | ||
261 : | self.parent.error("Directories can not be added to items.") | ||
262 : | return | ||
263 : | |||
264 : | prompt = "New catalog directory name:" | ||
265 : | dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK) | ||
266 : | |||
267 : | if ( dlg.ShowModal() == wxID_OK): | ||
268 : | theName = dlg.GetValue() | ||
269 : | if ( theName=="" ): return | ||
270 : | dlg.Destroy() | ||
271 : | else: | ||
272 : | #didn't get a kid name | ||
273 : | dlg.Destroy() | ||
274 : | return | ||
275 : | |||
276 : | efrank | 1.35 | #try: |
277 : | if (1): | ||
278 : | efrank | 1.25 | newCatEntry=catEntry.mkDir( theName ) |
279 : | parentTree=self.parent.catalog_tree | ||
280 : | newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() ) | ||
281 : | parentTree.SetPyData( newItemId, | ||
282 : | (self.recoElemLoader, newCatEntry, newItemId ) ) | ||
283 : | |||
284 : | parentTree.SortChildren( treeItemId ) | ||
285 : | efrank | 1.35 | else: |
286 : | #except: | ||
287 : | efrank | 1.25 | self.parent.error( "Operation refused." ) |
288 : | |||
289 : | |||
290 : | return | ||
291 : | |||
292 : | #------------------------------------------------------------------------ | ||
293 : | def doCatEditMkItem( self, event ): | ||
294 : | efrank | 1.14 | #------------------------------------------------------------------------ |
295 : | efrank | 1.25 | if (None == self.selected): |
296 : | self.parent.error( "A selection is required first.") | ||
297 : | return | ||
298 : | |||
299 : | catEntryTuple = self.selected | ||
300 : | catEntry = catEntryTuple[1] | ||
301 : | treeItemId = catEntryTuple[2] | ||
302 : | |||
303 : | if (catEntry.isTerminal()): | ||
304 : | self.parent.error("Items can not be added to items. Add to a directory.") | ||
305 : | return | ||
306 : | |||
307 : | prompt = "New catalog entry name:" | ||
308 : | efrank | 1.14 | dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK) |
309 : | |||
310 : | if ( dlg.ShowModal() == wxID_OK): | ||
311 : | efrank | 1.25 | theName = dlg.GetValue() |
312 : | if ( theName=="" ): return | ||
313 : | efrank | 1.14 | dlg.Destroy() |
314 : | else: | ||
315 : | #didn't get a kid name | ||
316 : | dlg.Destroy() | ||
317 : | return | ||
318 : | |||
319 : | efrank | 1.25 | try: |
320 : | newCatEntry = catEntry.mkItem( theName ) | ||
321 : | parentTree=self.parent.catalog_tree | ||
322 : | newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() ) | ||
323 : | parentTree.SetPyData( newItemId, | ||
324 : | (self.recoElemLoader, newCatEntry, newItemId ) ) | ||
325 : | |||
326 : | parentTree.SortChildren( treeItemId ) | ||
327 : | except: | ||
328 : | self.parent.error( "Operation refused." ) | ||
329 : | |||
330 : | efrank | 1.14 | |
331 : | return | ||
332 : | |||
333 : | efrank | 1.4 | |
334 : | #------------------------------------------------------------------------ | ||
335 : | hwang | 1.22 | def onLeftDClick(self, event): |
336 : | efrank | 1.4 | #------------------------------------------------------------------------ |
337 : | efrank | 1.27 | """ Double left-click means, "Load the currently selected item." """ |
338 : | |||
339 : | efrank | 1.6 | if ( self.selected == None ): |
340 : | efrank | 1.27 | self.parent.error( "You must select a catalog entry before requesting load.") |
341 : | efrank | 1.6 | return |
342 : | |||
343 : | efrank | 1.27 | # We store a loader to actually load the selected item. This dates |
344 : | # back to a time before a single loader could handle all the various | ||
345 : | # data factory kinds. | ||
346 : | |||
347 : | efrank | 1.6 | catEntryTuple = self.selected |
348 : | apply( catEntryTuple[0], [catEntryTuple[1]] ) | ||
349 : | |||
350 : | return | ||
351 : | |||
352 : | #------------------------------------------------------------------------ | ||
353 : | efrank | 1.25 | def recoElemLoader(self, argList ): |
354 : | #------------------------------------------------------------------------ | ||
355 : | wxBeginBusyCursor() | ||
356 : | |||
357 : | (catalogEntry) = argList | ||
358 : | |||
359 : | if (catalogEntry.isTerminal() ): | ||
360 : | efrank | 1.26 | ver = self.parent.catVersionValueComboBox.GetValue() |
361 : | if ( ver == "None" ): | ||
362 : | efrank | 1.27 | top = RecoElem( catalogEntry.name() ) |
363 : | efrank | 1.26 | else: |
364 : | top = catalogEntry.read( int( ver ) ) | ||
365 : | |||
366 : | efrank | 1.37 | self.parent.re.addRecoElemTree(self.parent.rootId, top, catalogEntry) |
367 : | efrank | 1.25 | else: |
368 : | # current selection is directory. can't load that! | ||
369 : | wxEndBusyCursor() | ||
370 : | return | ||
371 : | |||
372 : | |||
373 : | wxEndBusyCursor() | ||
374 : | return |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |