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

Diff of /trunk/pygtk/observer.py

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

revision 853 by johnpye, Tue Sep 19 15:02:04 2006 UTC revision 854 by johnpye, Wed Sep 20 13:36:40 2006 UTC
# Line 8  OBSERVER_EDIT_COLOR = "#008800" Line 8  OBSERVER_EDIT_COLOR = "#008800"
8  OBSERVER_NOEDIT_COLOR = "#000088"  OBSERVER_NOEDIT_COLOR = "#000088"
9  OBSERVER_NORMAL_COLOR = "black"  OBSERVER_NORMAL_COLOR = "black"
10    
11  OBSERVER_INITIAL_COLS = 3 # how many cells are at the start of the table?  # This code uses the technique described in
 OBSERVER_ICON, OBSERVER_WEIGHT, OBSERVER_EDIT = range(0,OBSERVER_INITIAL_COLS) # column indices for the start of the TreeStore  
 OBSERVER_NULL = 0 # value that gets added to empty cells in a new column  
   
 # This is messy code since it doesn't observe the convention of keeping your model  
 # separate from your view. It's all mixed up together. Yuck. Part of the  
 # difficulty with that was the fact that TreeStores don't support the adding of  
 # columns.  
   
 # Update: there is a technique for doing this, in fact:  
12  # http://www.daa.com.au/pipermail/pygtk/2006-February/011777.html  # http://www.daa.com.au/pipermail/pygtk/2006-February/011777.html
13    
14  OBSERVER_NUM=0  OBSERVER_NUM=0
# Line 93  class ObserverRow: Line 84  class ObserverRow:
84      """      """
85      def __init__(self,values=None,active=True):      def __init__(self,values=None,active=True):
86          if values==None:              if values==None:    
87              values={}              values=[]
88    
89          self.values = values          self.values = values
90          self.active = active          self.active = active
# Line 107  class ObserverRow: Line 98  class ObserverRow:
98              print "ROW",r,"; INDEX: ",index,"; COL: ",col              print "ROW",r,"; INDEX: ",index,"; COL: ",col
99              try:              try:
100                  self.values[index] = col.instance.getRealValue()                  self.values[index] = col.instance.getRealValue()
101              except KeyError,e:              except IndexError,e:
102                  print "Key error: e=",str(e)                  print "Index error: e=",str(e)
103                  self.values[index] = None                  self.values[index] = None
104              r=r+1              r=r+1
105          print "Made static, values:",self.values          print "Made static, values:",self.values
# Line 183  class ObserverTab: Line 174  class ObserverTab:
174          self.rows = {}          self.rows = {}
175          self.activeiter = _store.append(None, [ObserverRow()] )          self.activeiter = _store.append(None, [ObserverRow()] )
176    
177      def do_add_row(self):      def do_add_row(self,values=None):
178            _store = self.view.get_model()
179          if self.alive:          if self.alive:
180              _row = ObserverRow()              _row = ObserverRow()
181              self.rows.append(_row)              self.rows.append(_row)
             _store = self.view.get_model()  
182              _oldrow = _store.get_value(self.activeiter,0)              _oldrow = _store.get_value(self.activeiter,0)
183              _oldrow.make_static(self)              _oldrow.make_static(self)
184              self.activeiter = _store.append(None,[_row])              self.activeiter = _store.append(None,[_row])
# Line 195  class ObserverTab: Line 186  class ObserverTab:
186              _oldpath,_oldcol = self.view.get_cursor()              _oldpath,_oldcol = self.view.get_cursor()
187              self.view.set_cursor(_path, _oldcol)              self.view.set_cursor(_path, _oldcol)
188          else:          else:
189              self.browser.reporter.reportError("Can't add row: incorrect observer type")              _row = ObserverRow(values=values,active=False)
190                self.rows.append(_row)
191                _store.append(None,[_row])          
192                self.browser.reporter.reportNote("Added data row")
193    
194      def on_view_cell_edited(self, renderer, path, newtext, col):      def on_view_cell_edited(self, renderer, path, newtext, col):
195          # we can assume it's always the self.activeiter that is edited...          # we can assume it's always the self.activeiter that is edited...

Legend:
Removed from v.853  
changed lines
  Added in v.854

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