/[ascend]/trunk/pygtk/moduleview.py
ViewVC logotype

Contents of /trunk/pygtk/moduleview.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1727 - (show annotations) (download) (as text)
Tue Jan 15 23:03:20 2008 UTC (16 years, 5 months ago) by jpye
File MIME type: text/x-python
File size: 3421 byte(s)
Updated cavity to current CLFR design Stage 2.
Added 'singletube' model to tubebank.
Improved functionality of the Module view in PyGTK GUI (corrected highlighting of instantiable types, enabled doubleclick expansion of module type list).
Added reporting of inline notes via console output (TODO: incorporate this into the GUI).
Added Type::isModel and corrected Type::hasParameters (C++).
1 import gtk
2 import gtk.glade
3 import pango
4 import ascpy
5
6 class ModuleView:
7 def __init__(self,browser,glade, library):
8 """Set up the 'modules' tab, set up column types."""
9
10 self.browser = browser
11 self.library = library
12 self.moduleview = glade.get_widget('moduleview')
13
14 modulestorecoltypes = [str, str, int] # bool=can-be-instantiated
15 self.modulestore = gtk.TreeStore(*modulestorecoltypes)
16 moduleviewtitles = ["Module name", "Filename"]
17 self.moduleview.set_model(self.modulestore)
18 self.modcols = [ gtk.TreeViewColumn() for _type in modulestorecoltypes]
19 i = 0
20 for modcol in self.modcols[:len(moduleviewtitles)]:
21 modcol.set_title(moduleviewtitles[i])
22 self.moduleview.append_column(modcol)
23 _renderer = gtk.CellRendererText()
24 modcol.pack_start(_renderer, True)
25 modcol.add_attribute(_renderer, 'text', i)
26 modcol.add_attribute(_renderer,'weight',2)
27 i = i + 1
28 self.moduleview.connect("row-activated", self.module_activated )
29 self.modtank = {}
30
31 def refresh(self, library):
32 """Repopulate the 'modules' tab with the current (new) contents of the 'library'."""
33
34 self.modtank = {}
35 self.modulestore.clear()
36 self.library = library
37 modules = library.getModules()
38 try:
39 _lll=len(modules)
40 except:
41 _msg = "UNABLE TO ACCESS MODULES LIST. This is bad.\n"+\
42 "Check your SWIG configuration (check for warnings during build)."
43
44 self.browser.reporter.reportError(_msg)
45 raise RuntimeError(_msg)
46
47 firstpath = None
48 for m in reversed(modules):
49 _n = str( m.getName() )
50 _f = str( m.getFilename() )
51 #print "ADDING ROW name %s, file = %s" % (_n, _f)
52 _r = self.modulestore.append(None, [ _n, _f, pango.WEIGHT_NORMAL ])
53
54 if firstpath is None:
55 firstpath = self.modulestore.get_path(_r)
56
57 for t in library.getModuleTypes(m):
58 _n = t.getName()
59 if t.isModel() and not t.hasParameters():
60 _w = pango.WEIGHT_BOLD
61 else:
62 _w = pango.WEIGHT_NORMAL
63
64 #print "ADDING TYPE %s" % _n
65 _piter = self.modulestore.append(_r , [ _n, "", _w ])
66 _path = self.modulestore.get_path(_piter)
67 self.modtank[_path]=t
68
69 # open up the top-level module (ie the one we just openened)
70 if firstpath is not None:
71 print "EXPANDING PATH",firstpath
72 self.moduleview.expand_row(firstpath,False)
73
74 #print "DONE ADDING MODULES"
75
76 def module_activated(self, treeview, path, column, *args):
77 """You can't currently double-click a module to open it, but that is
78 something we might allow in the future."""
79
80 modules = self.library.getModules()
81 print "PATH",path
82 if len(path)==1:
83 if self.moduleview.row_expanded(path):
84 self.moduleview.collapse_row(path)
85 else:
86 self.moduleview.expand_row(path,False)
87 #self.browser.reporter.reportNote("Launching of external editor not yet implemented")
88 elif len(path)==2:
89 if self.modtank.has_key(path):
90 _type = self.modtank[path];
91 if not _type.isModel():
92 self.browser.reporter.reportError("Can't create simulation for type '%s': not a MODEL type" % str(_type.getName()))
93 return
94 if _type.hasParameters():
95 self.browser.reporter.reportError("Can't create simulation for MODEL '%s': requires parameters" % str(_type.getName()))
96 return
97 self.browser.reporter.reportNote("Creating simulation for type '%s'" % str(_type.getName()) )
98 self.browser.do_sim(_type)
99 else:
100 self.browser.reporter.reportError("Didn't find type corresponding to row")
101

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22