/[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 222 by johnpye, Fri Jan 27 03:05:38 2006 UTC revision 223 by johnpye, Fri Jan 27 08:18:43 2006 UTC
# Line 24  import ascend Line 24  import ascend
24    
25  GLADE_FILE = "/home/john/src/ascend/trunk/pygtk/interface/ascend.glade"  GLADE_FILE = "/home/john/src/ascend/trunk/pygtk/interface/ascend.glade"
26    
27    #======================================
28    # Browser is the main ASCEND library/model browser window
29    
30  class Browser:  class Browser:
31    
32  #   ---------------------------------  #   ---------------------------------
# Line 280  class Browser: Line 283  class Browser:
283                  except RuntimeError, e:                  except RuntimeError, e:
284                      self.reporter.reportError("Failed to create instance of '%s': %s" %(options.model, str(e)));                      self.reporter.reportError("Failed to create instance of '%s': %s" %(options.model, str(e)));
285                    
286    
287      def run(self):      def run(self):
288          self.window.show()          self.window.show()
289          gtk.main()          gtk.main()
# Line 362  class Browser: Line 366  class Browser:
366          print "DONE BUILDING"          print "DONE BUILDING"
367          self.stop_waiting()          self.stop_waiting()
368    
369            self.sim.setSolver(ascend.Solver("QRSlv"))
370    
371          # empty things out first          # empty things out first
372          self.methodstore.clear()          self.methodstore.clear()
373          self.treestore.clear()          self.treestore.clear()
# Line 723  class Browser: Line 729  class Browser:
729          if not self.sim:          if not self.sim:
730              self.reporter.reportError("No simulation created yet!");              self.reporter.reportError("No simulation created yet!");
731                    
732          _params = self.sim.getSolverParameters();          _paramswin = SolverParametersWindow(self.sim, self.reporter)
733          for i in _params:          _paramswin.show()
             if i.isStr():  
                 print "STR:",i.getLabel(),"["+i.getDescription()+"]:",i.getStrValue();  
   
         self.reporter.reportSuccess("Check console for solver parameter output")  
734    
735      def methodrun_click(self,*args):      def methodrun_click(self,*args):
736          _sel = self.methodsel.get_active_text()          _sel = self.methodsel.get_active_text()
# Line 866  class Browser: Line 868  class Browser:
868          print "GTK QUIT"          print "GTK QUIT"
869          return False          return False
870    
871    #======================================================
872    # SOLVER PARAMETERS WINDOW
873    
874    class SolverParametersWindow:
875        def __init__(self,sim,reporter):
876            self.sim = sim
877            self.params = self.sim.getSolverParameters();
878            
879            self.reporter = reporter
880    
881            _xml = gtk.glade.XML(GLADE_FILE,"paramswin")
882            self.window = _xml.get_widget("paramswin")
883            _xml.signal_autoconnect(self)
884            
885            self.paramsview = _xml.get_widget("paramsview")
886            self.otank = {}
887            self.paramstore = gtk.TreeStore(str,str,str,bool)
888            self.paramsview.set_model(self.paramstore)
889    
890            # name column
891            _renderer0 = gtk.CellRendererText()
892            _col0 = gtk.TreeViewColumn("Name", _renderer0, text=0)
893            self.paramsview.append_column(_col0)
894    
895            # value column: 'editable' set by column 3 of the model data.
896            _renderer1 = gtk.CellRendererText()
897            _col1 = gtk.TreeViewColumn("Value", _renderer1, text=1, editable=3)
898            self.paramsview.append_column(_col1)
899    
900            # range column
901            _renderer2 = gtk.CellRendererText()
902            _col2 = gtk.TreeViewColumn("Range", _renderer2, text=2)
903            self.paramsview.append_column(_col2)
904    
905            self.populate()
906    
907        def create_row_data(self,p):
908            _row = [p.getLabel()];
909            if p.isStr():
910                _row.extend([p.getStrValue(), str(len(p.getStrOptions()))+" options", True]);
911            elif p.isBool():
912                if p.getBoolValue():
913                    _val = 'True'
914                else:
915                    _val = 'False'
916                _row.extend([_val,"",False])
917            elif p.isReal():
918                if p.getRealLowerBound()==0 and p.getRealUpperBound():
919                    _row.extend([str(p.getRealValue()), "",True])
920                else:
921                    _row.extend([str(p.getRealValue()), "[ "+str(p.getRealLowerBound())+", "+str(p.getRealUpperBound())+" ]",True])
922            elif p.isInt():
923                if p.getIntLowerBound()==0 and p.getIntUpperBound():
924                    _row.extend([str(p.getIntValue()), "", True])
925                else:
926                    _row.extend([str(p.getIntValue()), "[ "+str(p.getIntLowerBound())+", "+str(p.getIntLowerBound())+" ]", True])
927    
928            else:
929                raise RuntimeError("invalid type")
930            return _row;
931            
932        def populate(self):
933            # Fill the paramstore with data
934            
935            for i in self.params:
936                _piter = self.paramstore.append( None, self.create_row_data(i) )
937    
938                _path = self.paramstore.get_path(_piter)
939                self.otank[ _path ] = i
940    
941        def on_paramsview_row_activated(self,*args,**kwargs):
942            print "EDITED"
943    
944        def show(self):
945            self.window.show()
946        
947        def on_paramscancel_activate(self,*args,**kwargs):
948            self.do_destroy()
949    
950        def on_paramsapply_activate(self,*args,**kwargs):
951            print "SAVE"
952    
953        def on_paramswin_destroy(self,*args,**kwargs):
954            self.do_destroy()
955    
956        def do_destroy(self):
957            print "DESTROY PARAMS WIN"
958            self.window.hide()
959            del(self.window)
960            del(self.params)
961    
962  def test():  def test():
963      import ascend      import ascend
964      b = Browser();      b = Browser();

Legend:
Removed from v.222  
changed lines
  Added in v.223

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