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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 248 by johnpye, Tue Jan 31 16:24:27 2006 UTC revision 249 by johnpye, Wed Feb 1 03:22:11 2006 UTC
# Line 10  class ObserverTab: Line 10  class ObserverTab:
10    
11          self.view = xml.get_widget('observerview')          self.view = xml.get_widget('observerview')
12    
13          self.activeimg = self.view.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)          #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]          self.columns = [gtk.gdk.Pixbuf]
22          self.titles = ["T"]          self.titles = ["T"]
23          self.store = gtk.TreeStore(*self.columns)          _store = gtk.TreeStore(*self.columns)
24          self.rows = []          self.rows = []
         self.rows.append([self.activeimg])  
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          self.name = name
31          self.browser = browser          self.browser = browser
32    
   
33          # create the 'active' pixvuf columns              # create the 'active' pixvuf columns    
34            _renderer = gtk.CellRendererPixbuf()
35          _col = gtk.TreeViewColumn()          _col = gtk.TreeViewColumn()
36          _col.set_title(self.titles[0])          _col.set_title(self.titles[0])
         self.view.append_column(_col);  
         _renderer = gtk.CellRendererPixbuf()  
37          _col.pack_start(_renderer,False)          _col.pack_start(_renderer,False)
38          _col.add_attribute(_renderer, 'pixbuf', int(0))          _col.add_attribute(_renderer, 'pixbuf', 0)
39            self.view.append_column(_col);
40    
41          # create the first row          # create the first row
42          print "Adding row",self.rows[0],"to store"          print "Adding row",self.rows[0],"to store"
43          self.store.append(None, self.rows[0])          _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")          self.browser.reporter.reportNote("Created OBSERVER")
48    
49      def on_add_click(self,*args):      def on_add_clicked(self,*args):
50          print "ADD"          _rownum = len(self.rows)
51          pass  
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_click(self,*args):      def on_clear_clicked(self,*args):
60          print "CLEAR"          print "CLEAR"
61          pass          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):      def add_instance(self, inst):
88          if not inst.getType().isRefinedSolverVar():          if not inst.getType().isRefinedSolverVar():
89              self.browser.reporter.reportError("Instance is not a refined solver variable: can't 'observe'.");              self.browser.reporter.reportError("Instance is not a refined solver variable: can't 'observe'.");
# Line 54  class ObserverTab: Line 94  class ObserverTab:
94          _value = float(inst.getRealValue())          _value = float(inst.getRealValue())
95          _rownum = len(self.rows)-1          _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          print "COLNUM =",_colnum
104    
105          print "ADDING TO OBSERVER '"+self.name+"' COLUMN '"+_colname+"', CURRENT VALUE = ",_value          print "ADDING TO OBSERVER '"+self.name+"' COLUMN '"+_colname+"', CURRENT VALUE = ",_value
# Line 62  class ObserverTab: Line 108  class ObserverTab:
108          self.columns.append(float)          self.columns.append(float)
109          self.titles.append(_colname);          self.titles.append(_colname);
110          print "NEW COLUMNS WILL BE",str(self.columns)          print "NEW COLUMNS WILL BE",str(self.columns)
111    
112          _store = gtk.TreeStore(*(self.columns))          _store = gtk.TreeStore(*(self.columns))
113          _currentrow = None  
114            _iter = None
115            _i = 0
116          for _r in self.rows:          for _r in self.rows:
117              print "OLD ROW DATA:",repr(_r)              print "ROW",_i
118              _newrowdata = _r.append(None)              _r.append(0)
119              print "NEW ROW DATA:",repr(_r)              _iter = _store.append(None, self.make_row(self.keptimg,_r) )
120              _currentrow = _store.append(None,_newrowdata)              _i = _i + 1
121        
122            self.activeiter = _iter
123    
124          # add newest data point in bottom-right          # add newest data point in bottom-right
125          self.rows[_rownum][_colnum] = _value          self.rows[_rownum][_colnum-1] = _value
126          _store.set_value(_currentrow, _colnum, _value)          _store.set_value(self.activeiter, _colnum, _value)
   
         # kill old self.store  
         del(self.store)  
         self.store = _store  
127    
128          # re-assign store to TreeView          # re-assign store to TreeView
129          self.view.set_model(self.store)     #self.store.set(_currentrow, _colnum, _value)          self.view.set_model(_store)     #self.store.set(_currentrow, _colnum, _value)
130    
131          # add value to current column          # add value to current column
132          #self.store.set(_currentrow, _colnum, _value)          #self.store.set(_currentrow, _colnum, _value)
133    
134          _renderer = gtk.CellRendererText()          _renderer = gtk.CellRendererText()
135          _col = gtk.TreeViewColumn(_colname, _renderer)          _col = gtk.TreeViewColumn(_colname, _renderer)
136          _col.set_alignment(1.0)          _col.add_attribute(_renderer, 'text', _colnum)
137          _col.set_reorderable(True)          _col.set_alignment(0.0)
138          _col.set_sort_column_id(_colnum)          #_col.set_reorderable(True)
139            #_col.set_sort_column_id(_colnum)
140    
141          self.view.append_column(_col);          self.view.append_column(_col);
142    
         print "SELF.STORE: COLUMNS =",self.store.get_n_columns()," ROWS =",self.store.iter_n_children(None)  
   
   
         print "LAST ROW DATA:",repr(self.rows[_rownum])  
   
         _rn = 0  
         _r = self.store.iter_children(None)  
         while _r != None:  
             for _i in range(0, self.store.get_n_columns()):  
                 print "ROW",_rn,"COL",_i,":",self.store.get(_r,_i)  
             _r = self.store.iter_next(_r)  
             _rn = _rn + 1  
   

Legend:
Removed from v.248  
changed lines
  Added in v.249

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