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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (show annotations) (download) (as text)
Wed Feb 1 03:22:11 2006 UTC (14 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 3691 byte(s)
Working (read-only) observer thing. Observer instances are updated in the table
and if you click 'add' on the observer tab, the current values are kept and a new
row is added.
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 = gtk.Image()
14 #self.activeimg.set_from_file("icons/active.png")
15 self.activeimg = None
16 self.keptimg = None
17
18 # no instances yet in the observer:
19 self.columninstances = []
20
21 self.columns = [gtk.gdk.Pixbuf]
22 self.titles = ["T"]
23 _store = gtk.TreeStore(*self.columns)
24 self.rows = []
25
26 # add an empty first row
27 self.rows.append([])
28
29 # work towards having multiple observers for multiple simulations
30 self.name = name
31 self.browser = browser
32
33 # create the 'active' pixvuf columns
34 _renderer = gtk.CellRendererPixbuf()
35 _col = gtk.TreeViewColumn()
36 _col.set_title(self.titles[0])
37 _col.pack_start(_renderer,False)
38 _col.add_attribute(_renderer, 'pixbuf', 0)
39 self.view.append_column(_col);
40
41 # create the first row
42 print "Adding row",self.rows[0],"to store"
43 _store.append(None, self.make_row(self.activeimg, self.rows[0]) )
44
45 self.view.set_model(_store)
46
47 self.browser.reporter.reportNote("Created OBSERVER")
48
49 def on_add_clicked(self,*args):
50 _rownum = len(self.rows)
51
52 # add a copy of the last row
53 self.rows.append(self.rows[_rownum-1])
54 self.activerow = _rownum
55
56 self.view.get_model().set(self.activeiter,0,self.keptimg)
57 self.activeiter = self.view.get_model().append(None,self.make_row(self.activeimg,self.rows[_rownum]))
58
59 def on_clear_clicked(self,*args):
60 print "CLEAR"
61 pass
62
63 def sync(self):
64 print "SYNCHING ROW",self.activerow
65
66 #new row data
67 _r = [_i.getRealValue() for _i in self.columninstances]
68
69 # stick the row data into the TreeStore
70 _m = self.view.get_model()
71 _i = 1
72 for _c in _r:
73 _m.set(self.activeiter, _i, _c)
74 _i = _i + 1
75 print "REPLACEMENT DATA IS",_r
76
77 # keep the data in self.rows as well
78 self.rows[self.activerow] = _r;
79
80 def make_row(self,img,row):
81 _r = [img]
82 for _c in row:
83 _r.append(_c)
84 print "MADE KEPT ROW:",_r
85 return _r
86
87 def add_instance(self, inst):
88 if not inst.getType().isRefinedSolverVar():
89 self.browser.reporter.reportError("Instance is not a refined solver variable: can't 'observe'.");
90 return
91
92 _colnum = len(self.columns)
93 _colname = inst.getName().toString()
94 _value = float(inst.getRealValue())
95 _rownum = len(self.rows)-1
96
97 # store the instances in self.columninstances for sync purposes
98 self.columninstances.append(inst)
99
100 print "ROWS IN self.rows",len(self.rows)
101 print "LAST ROW: ",repr(self.rows[_rownum])
102
103 print "COLNUM =",_colnum
104
105 print "ADDING TO OBSERVER '"+self.name+"' COLUMN '"+_colname+"', CURRENT VALUE = ",_value
106
107 # create new TreeStore, copy of old, plus one columm
108 self.columns.append(float)
109 self.titles.append(_colname);
110 print "NEW COLUMNS WILL BE",str(self.columns)
111
112 _store = gtk.TreeStore(*(self.columns))
113
114 _iter = None
115 _i = 0
116 for _r in self.rows:
117 print "ROW",_i
118 _r.append(0)
119 _iter = _store.append(None, self.make_row(self.keptimg,_r) )
120 _i = _i + 1
121
122 self.activeiter = _iter
123
124 # add newest data point in bottom-right
125 self.rows[_rownum][_colnum-1] = _value
126 _store.set_value(self.activeiter, _colnum, _value)
127
128 # re-assign store to TreeView
129 self.view.set_model(_store) #self.store.set(_currentrow, _colnum, _value)
130
131 # add value to current column
132 #self.store.set(_currentrow, _colnum, _value)
133
134 _renderer = gtk.CellRendererText()
135 _col = gtk.TreeViewColumn(_colname, _renderer)
136 _col.add_attribute(_renderer, 'text', _colnum)
137 _col.set_alignment(0.0)
138 #_col.set_reorderable(True)
139 #_col.set_sort_column_id(_colnum)
140
141 self.view.append_column(_col);
142

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