/[ascend]/trunk/pygtk/interface/observer.py
ViewVC logotype

Contents of /trunk/pygtk/interface/observer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 246 - (show annotations) (download) (as text)
Tue Jan 31 16:24:27 2006 UTC (18 years, 4 months ago) by johnpye
File MIME type: text/x-python
File size: 2858 byte(s)
Some more work on the 'Observer' feature
1 import pygtk
2 pygtk.require('2.0')
3 import gtk
4 import gtk.glade
5 import pango
6
7 class ObserverTab:
8 def __init__(self,xml,name,browser):
9 xml.signal_autoconnect(self);
10
11 self.view = xml.get_widget('observerview')
12
13 self.activeimg = self.view.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)
14
15 self.columns = [gtk.gdk.Pixbuf]
16 self.titles = ["T"]
17 self.store = gtk.TreeStore(*self.columns)
18 self.rows = []
19 self.rows.append([self.activeimg])
20
21 self.name = name
22 self.browser = browser
23
24
25 # create the 'active' pixvuf columns
26 _col = gtk.TreeViewColumn()
27 _col.set_title(self.titles[0])
28 self.view.append_column(_col);
29 _renderer = gtk.CellRendererPixbuf()
30 _col.pack_start(_renderer,False)
31 _col.add_attribute(_renderer, 'pixbuf', int(0))
32
33 # create the first row
34 print "Adding row",self.rows[0],"to store"
35 self.store.append(None, self.rows[0])
36
37 self.browser.reporter.reportNote("Created OBSERVER")
38
39 def on_add_click(self,*args):
40 print "ADD"
41 pass
42
43 def on_clear_click(self,*args):
44 print "CLEAR"
45 pass
46
47 def add_instance(self, inst):
48 if not inst.getType().isRefinedSolverVar():
49 self.browser.reporter.reportError("Instance is not a refined solver variable: can't 'observe'.");
50 return
51
52 _colnum = len(self.columns)
53 _colname = inst.getName().toString()
54 _value = float(inst.getRealValue())
55 _rownum = len(self.rows)-1
56
57 print "COLNUM =",_colnum
58
59 print "ADDING TO OBSERVER '"+self.name+"' COLUMN '"+_colname+"', CURRENT VALUE = ",_value
60
61 # create new TreeStore, copy of old, plus one columm
62 self.columns.append(float)
63 self.titles.append(_colname);
64 print "NEW COLUMNS WILL BE",str(self.columns)
65 _store = gtk.TreeStore(*(self.columns))
66 _currentrow = None
67 for _r in self.rows:
68 print "OLD ROW DATA:",repr(_r)
69 _newrowdata = _r.append(None)
70 print "NEW ROW DATA:",repr(_r)
71 _currentrow = _store.append(None,_newrowdata)
72
73 # add newest data point in bottom-right
74 self.rows[_rownum][_colnum] = _value
75 _store.set_value(_currentrow, _colnum, _value)
76
77 # kill old self.store
78 del(self.store)
79 self.store = _store
80
81 # re-assign store to TreeView
82 self.view.set_model(self.store) #self.store.set(_currentrow, _colnum, _value)
83
84 # add value to current column
85 #self.store.set(_currentrow, _colnum, _value)
86
87 _renderer = gtk.CellRendererText()
88 _col = gtk.TreeViewColumn(_colname, _renderer)
89 _col.set_alignment(1.0)
90 _col.set_reorderable(True)
91 _col.set_sort_column_id(_colnum)
92
93 self.view.append_column(_col);
94
95 print "SELF.STORE: COLUMNS =",self.store.get_n_columns()," ROWS =",self.store.iter_n_children(None)
96
97
98 print "LAST ROW DATA:",repr(self.rows[_rownum])
99
100 _rn = 0
101 _r = self.store.iter_children(None)
102 while _r != None:
103 for _i in range(0, self.store.get_n_columns()):
104 print "ROW",_rn,"COL",_i,":",self.store.get(_r,_i)
105 _r = self.store.iter_next(_r)
106 _rn = _rn + 1
107

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