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

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

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

revision 224 by johnpye, Fri Jan 27 08:18:43 2006 UTC revision 225 by johnpye, Fri Jan 27 14:55:43 2006 UTC
# Line 884  class SolverParametersWindow: Line 884  class SolverParametersWindow:
884                    
885          self.paramsview = _xml.get_widget("paramsview")          self.paramsview = _xml.get_widget("paramsview")
886          self.otank = {}          self.otank = {}
887          self.paramstore = gtk.TreeStore(str,str,str,bool)          self.paramstore = gtk.TreeStore(str,str,str,bool,str)
888          self.paramsview.set_model(self.paramstore)          self.paramsview.set_model(self.paramstore)
889    
890          # name column          # name column
891          _renderer0 = gtk.CellRendererText()          _renderer0 = gtk.CellRendererText()
892          _col0 = gtk.TreeViewColumn("Name", _renderer0, text=0)          _col0 = gtk.TreeViewColumn("Name", _renderer0, text=0, background=4)
893          self.paramsview.append_column(_col0)          self.paramsview.append_column(_col0)
894    
895          # value column: 'editable' set by column 3 of the model data.          # value column: 'editable' set by column 3 of the model data.
896          _renderer1 = gtk.CellRendererText()          _renderer1 = gtk.CellRendererText()
897          _col1 = gtk.TreeViewColumn("Value", _renderer1, text=1, editable=3)          _renderer1.connect('edited',self.on_paramsview_edited)
898            _col1 = gtk.TreeViewColumn("Value", _renderer1, text=1, editable=3, background=4)
899          self.paramsview.append_column(_col1)          self.paramsview.append_column(_col1)
900    
901          # range column          # range column
902          _renderer2 = gtk.CellRendererText()          _renderer2 = gtk.CellRendererText()
903          _col2 = gtk.TreeViewColumn("Range", _renderer2, text=2)          _col2 = gtk.TreeViewColumn("Range", _renderer2, text=2, background=4)
904          self.paramsview.append_column(_col2)          self.paramsview.append_column(_col2)
905    
906          self.populate()          self.populate()
907    
908        def on_paramsview_edited(self, renderer, path, newtext, **kwargs):
909            # get back the Instance object we just edited (having to use this seems like a bug)
910            path = tuple( map(int,path.split(":")) )
911    
912            if not self.otank.has_key(path):
913                raise RuntimeError("cell_edited_callback: invalid path '%s'" % path)
914                return
915            
916            _iter,_param = self.otank[path]
917            print "NEW VALUE OF ",_param.getLabel(),"=",newtext
918            # you can only edit real, int, str:
919    
920            _changed = False
921            if _param.isInt():
922                newvalue = int(newtext)
923                if _param.isBounded():
924                    if newvalue > _param.getIntUpperBound():
925                        self.doErrorDialog("The entered value '%d' is above the upper bound." % newvalue)
926                        return False
927                    if newvalue < _param.getIntLowerBound():
928                        self.doErrorDialog("The entered value '%d' is below the lower bound." % newvalue)
929                        return False
930                if _param.getIntValue() != newvalue:
931                    _param.setIntValue(newvalue)
932                    _changed = True
933            elif _param.isReal():
934                newvalue = float(newtext)
935                if _param.isBounded():
936                    if newvalue > _param.getRealUpperBound():
937                        self.doErrorDialog("The entered value '%f' is above the upper bound." % newvalue)
938                        return False
939                    if newvalue < _param.getRealLowerBound():
940                        self.doErrorDialog("The entered value '%f' is below the lower bound." % newvalue)
941                        return False
942                if _param.getRealValue() != newvalue:
943                    _param.setRealValue(newvalue)
944                    _changed = True
945            elif _param.isStr():
946                newvalue = str(newtext)
947                if _param.getStrValue() != newvalue:
948                    _param.setStrValue(newvalue)
949                    _changed = True
950    
951            if _changed:
952                self.paramstore.set_value(_iter, 1, newvalue)
953                self.paramstore.set_value(_iter, 4, "#FFFFAA")          
954                print "SET OK"
955            else:
956                print "NO CHANGE"
957    
958      def create_row_data(self,p):      def create_row_data(self,p):
959          _row = [p.getLabel()];          _row = [p.getLabel()];
960          if p.isStr():          if p.isStr():
# Line 927  class SolverParametersWindow: Line 978  class SolverParametersWindow:
978    
979          else:          else:
980              raise RuntimeError("invalid type")              raise RuntimeError("invalid type")
981    
982            _row.append("white")
983          return _row;          return _row;
984                    
985      def populate(self):      def populate(self):
# Line 936  class SolverParametersWindow: Line 989  class SolverParametersWindow:
989              _piter = self.paramstore.append( None, self.create_row_data(i) )              _piter = self.paramstore.append( None, self.create_row_data(i) )
990    
991              _path = self.paramstore.get_path(_piter)              _path = self.paramstore.get_path(_piter)
992              self.otank[ _path ] = i              self.otank[ _path ] = (_piter, i)
993    
994      def on_paramsview_row_activated(self,*args,**kwargs):      def on_paramsview_row_activated(self,*args,**kwargs):
995          print "EDITED"          print "EDITED"
# Line 948  class SolverParametersWindow: Line 1001  class SolverParametersWindow:
1001          self.do_destroy()          self.do_destroy()
1002    
1003      def on_paramsapply_activate(self,*args,**kwargs):      def on_paramsapply_activate(self,*args,**kwargs):
1004          print "SAVE"          self.sim.setSolverParameters(self.params);
1005            self.do_destroy()
1006    
1007      def on_paramswin_destroy(self,*args,**kwargs):      def on_paramswin_destroy(self,*args,**kwargs):
1008          self.do_destroy()          self.do_destroy()

Legend:
Removed from v.224  
changed lines
  Added in v.225

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