/[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 267 by johnpye, Thu Feb 2 14:50:05 2006 UTC revision 268 by johnpye, Sat Feb 4 06:09:57 2006 UTC
# Line 11  import urlparse Line 11  import urlparse
11  import optparse  import optparse
12    
13  from solverparameters import * # 'solver parameters' window  from solverparameters import * # 'solver parameters' window
14  from help import * # viewing help files  from help import *             # viewing help files
15  from incidencematrix import * # incidence/sparsity matrix matplotlib window  from incidencematrix import *  # incidence/sparsity matrix matplotlib window
16  from observer import * # observer tab support  from observer import *         # observer tab support
17    from properties import *       # solver_var properties dialog
18    from varentry import *         # for inputting of variables with units
19    
20  import sys, dl  import sys, dl
21  # This sets the flags for dlopen used by python so that the symbols in the  # This sets the flags for dlopen used by python so that the symbols in the
# Line 153  class Browser: Line 155  class Browser:
155          #--------------------          #--------------------
156          # pixbufs for solver_var status          # pixbufs for solver_var status
157    
158            self.fixedimg = gtk.Image()
159            self.fixedimg.set_from_file('icons/locked.png')
160    
161          self.iconstatusunknown = None          self.iconstatusunknown = None
162          self.iconfixed = None          self.iconfixed = self.fixedimg.get_pixbuf()
163          self.iconsolved = self.window.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)          self.iconsolved = self.window.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)
164          self.iconactive = self.window.render_icon(gtk.STOCK_NO,gtk.ICON_SIZE_MENU)          self.iconactive = self.window.render_icon(gtk.STOCK_NO,gtk.ICON_SIZE_MENU)
165          self.iconunsolved = None          self.iconunsolved = None
# Line 174  class Browser: Line 179  class Browser:
179    
180          self.treecontext = gtk.Menu();          self.treecontext = gtk.Menu();
181          self.fixmenuitem = gtk.ImageMenuItem("_Fix",True);          self.fixmenuitem = gtk.ImageMenuItem("_Fix",True);
182          _img = gtk.Image()          self.fixmenuitem.set_image(self.fixedimg)
         _img.set_from_file('icons/locked.png')  
         self.fixmenuitem.set_image(_img)  
183    
184          self.freemenuitem = gtk.ImageMenuItem("F_ree",True);          self.freemenuitem = gtk.ImageMenuItem("F_ree",True);
185          _img = gtk.Image()          _img = gtk.Image()
# Line 275  class Browser: Line 278  class Browser:
278              i = i + 1              i = i + 1
279          self.moduleview.connect("row-activated", self.module_activated )          self.moduleview.connect("row-activated", self.module_activated )
280            
         #-------------------  
         # RE for units matching  
         self.units_re = re.compile("([-+]?(\d+(\.\d*)?|\d*\.d+)([eE][-+]?\d+)?)\s*(.*)");  
   
281          #--------------------          #--------------------
282          # set up the methods combobox          # set up the methods combobox
283    
# Line 618  class Browser: Line 617  class Browser:
617          if _instance.isReal():          if _instance.isReal():
618              # only real-valued things can have units              # only real-valued things can have units
619                            
620                _e = RealAtomEntry(_instance,newtext);
621              try:              try:
622                  # match a float with option text afterwards, optionally separated by whitespace                  _e.checkEntry()
623                  _match = re.match(self.units_re,newtext)                  _e.setValue()
624                  if not _match:                  _e.exportPreferredUnits(self.prefs)
625                      self.reporter.reportError("Not a valid value-and-optional-units")              except InputError, e:
626                      return                  self.reporter.reportError(str(e))
627                    return;
                 _val = _match.group(1)  
                 _units = _match.group(5)  
                 #_val, _units = re.split("[ \t]+",newtext,2);  
             except RuntimeError:  
                 self.reporter.reportError("Unable to split value and units")  
                 return  
             print "val = ",_val  
             print "units = ",_units  
   
             # parse the units, throw an error if no good  
             try:  
                 _val = float(_val)  
             except RuntimeError:  
                 self.reporter.reportError("Unable to convert number part '%s' to float" % _val)  
   
             if _units.strip() == "":  
                 _u = _instance.getType().getPreferredUnits()  
                 if _u == None:  
                     _u = _instance.getDimensions().getDefaultUnits()  
                 self.reporter.reportNote("Assuming units '%s'" % _u.getName().toString() )  
             else:  
                 try:  
                     _u = ascend.Units(_units)  
                     self.reporter.reportNote("Parsed units %s" % _units)  
                 except RuntimeError:  
                     self.reporter.reportError("Unrecognisable units '%s'" % _units)  
                     return  
   
                 if _instance.getDimensions() != _u.getDimensions():  
   
                     if _u.getDimensions().isDimensionless():  
                         _units = "[dimensionless]"  
   
                     _my_dims = _instance.getDimensions().getDefaultUnits()  
                     if _instance.getDimensions().isDimensionless():  
                         _my_dims = "[dimensionless]"  
   
                     self.reporter.reportError("Incompatible units '%s' (must fit with '%s')"  
                             % (_units, _my_dims) )  
                     return  
628    
             if _units.strip() != "" and not _instance.getDimensions().isDimensionless():  
                 self.prefs.setPreferredUnits(str(_instance.getType().getName()), _units);  
           
             _conv = float(_u.getConversion())  
             # self.reporter.reportNote("Converting: multiplying '%s %s' by factor %s to get SI units" % (_val, _units, _conv) )  
             _val = _val * _conv;  
   
             self.reporter.reportNote("Setting '%s' to '%f'" % (_name, _val))  
               
             if _instance.getType().isRefinedSolverVar():  
                 # set the 'fixed' flag as well  
                 _instance.setFixedValue(float(_val))  
             else:  
                 _instance.setRealValue(float(_val))  
629          else:          else:
630              if _instance.isBool():              if _instance.isBool():
631                  _lower = newtext.lower();                  _lower = newtext.lower();
# Line 990  class Browser: Line 936  class Browser:
936          if _instance.isRelation():          if _instance.isRelation():
937              print "Relation '"+_instance.getName().toString()+"':", \              print "Relation '"+_instance.getName().toString()+"':", \
938                  _instance.getRelationAsString(self.sim.getModel())                  _instance.getRelationAsString(self.sim.getModel())
939            elif _instance.getType().isRefinedSolverVar():
940                _dia = VarPropsWin(GLADE_FILE,self,_instance);
941                _dia.run();
942          else:          else:
943              self.reporter.reportWarning("props_activate not implemented")              self.reporter.reportWarning("props_activate not implemented")
944    

Legend:
Removed from v.267  
changed lines
  Added in v.268

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