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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 251 - (show annotations) (download) (as text)
Wed Feb 1 04:33:46 2006 UTC (14 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 3951 byte(s)
Fixed observer copy crash, bug #214.
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(True, 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 self.do_add_row()
51
52 def do_add_row(self):
53 _rownum = len(self.rows)
54
55 # add a copy of the last row
56 self.rows.append(self.rows[_rownum-1])
57 self.activerow = _rownum
58
59 self.view.get_model().set(self.activeiter,0,self.keptimg)
60 self.activeiter = self.view.get_model().append(None,self.make_row(True,self.rows[_rownum]))
61
62 def on_clear_clicked(self,*args):
63 print "CLEAR"
64 pass
65
66 def sync(self):
67 print "SYNCHING ROW",self.activerow
68
69 #new row data
70 _r = [_i.getRealValue() for _i in self.columninstances]
71
72 # stick the row data into the TreeStore
73 _m = self.view.get_model()
74 _i = 1
75 for _c in _r:
76 _m.set(self.activeiter, _i, _c)
77 _i = _i + 1
78 print "REPLACEMENT DATA IS",_r
79
80 # keep the data in self.rows as well
81 self.rows[self.activerow] = _r;
82
83 def copy_to_clipboard(self,clip):
84 _t = ""
85 for _r in self.rows:
86 _t += '\t'.join([`_c` for _c in _r]) + '\n'
87 clip.set_text(_t,len(_t))
88 print "TEXT ON CLIPBOARD IS",_t
89
90 def make_row(self,isactive,row):
91 if isactive:
92 _r = [self.activeimg]
93 else:
94 _r = [self.keptimg]
95
96 for _c in row:
97 _r.append(_c)
98 print "MADE KEPT ROW:",_r
99 return _r
100
101 def add_instance(self, inst):
102 if not inst.getType().isRefinedSolverVar():
103 self.browser.reporter.reportError("Instance is not a refined solver variable: can't 'observe'.");
104 return
105
106 _colnum = len(self.columns)
107 _colname = inst.getName().toString()
108 _value = float(inst.getRealValue())
109 _rownum = len(self.rows)-1
110
111 # store the instances in self.columninstances for sync purposes
112 self.columninstances.append(inst)
113
114 print "ROWS IN self.rows",len(self.rows)
115 print "LAST ROW: ",repr(self.rows[_rownum])
116
117 print "COLNUM =",_colnum
118
119 print "ADDING TO OBSERVER '"+self.name+"' COLUMN '"+_colname+"', CURRENT VALUE = ",_value
120
121 # create new TreeStore, copy of old, plus one columm
122 self.columns.append(float)
123 self.titles.append(_colname);
124 print "NEW COLUMNS WILL BE",str(self.columns)
125
126 _store = gtk.TreeStore(*(self.columns))
127
128 _iter = None
129 _i = 0
130 for _r in self.rows:
131 print "ROW",_i
132 _r.append(0)
133 _iter = _store.append(None, self.make_row(False,_r) )
134 _i = _i + 1
135
136 self.activeiter = _iter
137
138 # add newest data point in bottom-right
139 self.rows[_rownum][_colnum-1] = _value
140 _store.set_value(self.activeiter, _colnum, _value)
141
142 # re-assign store to TreeView
143 self.view.set_model(_store) #self.store.set(_currentrow, _colnum, _value)
144
145 # add value to current column
146 #self.store.set(_currentrow, _colnum, _value)
147
148 _renderer = gtk.CellRendererText()
149 _col = gtk.TreeViewColumn(_colname, _renderer)
150 _col.add_attribute(_renderer, 'text', _colnum)
151 _col.set_alignment(0.0)
152 #_col.set_reorderable(True)
153 #_col.set_sort_column_id(_colnum)
154
155 self.view.append_column(_col);
156

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