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

Contents of /trunk/pygtk/interface/properties.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 268 - (show annotations) (download) (as text)
Sat Feb 4 06:09:57 2006 UTC (14 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 2866 byte(s)
Adding ability to edit upper/lower bounds and nominal values
1 # GUI for ASCEND solver_var properties
2
3 import gtk, gtk.glade
4 import ascend
5 from varentry import *
6
7 class VarPropsWin:
8 def __init__(self,GLADE_FILE,browser,instance):
9 self.instance = instance;
10 self.browser = browser;
11
12 # values being edited:
13 self.lower = 0
14 self.upper = 1
15 self.nominal = 0.5
16 self.fixed = True
17 self.status = ascend.ASCXX_VAR_STATUS_UNKNOWN
18
19 # GUI config
20 _xml = gtk.glade.XML(GLADE_FILE,"varpropswin")
21 self.varpropswin = _xml.get_widget("varpropswin")
22
23 self.varname = _xml.get_widget("varname")
24 self.valueentry= _xml.get_widget("valueentry");
25 self.lowerentry = _xml.get_widget("lowerentry");
26 self.upperentry = _xml.get_widget("upperentry");
27 self.nominalentry = _xml.get_widget("nominalentry");
28
29 self.statusimg = _xml.get_widget("statusimg"); self.statusimg = None
30
31 self.othernamesbutton = _xml.get_widget("othernamesbutton"); self.othernamesbutton.set_label("100 other names...")
32
33 self.fill_values()
34
35 _xml.signal_autoconnect(self)
36
37 def fill_values(self):
38 # all the values here use the same preferred units for this instance type
39
40 _u = self.instance.getType().getPreferredUnits();
41 if _u == None:
42 _conversion = 1
43 _u = self.getDimensions().getDefaultUnits().getName().toString()
44 else:
45 _conversion = _u.getConversion() # displayvalue x conversion = SI
46 _u = _u.getName().toString()
47
48 _arr = {
49 self.valueentry: self.instance.getRealValue()
50 ,self.lowerentry: self.instance.getLowerBound()
51 ,self.upperentry: self.instance.getUpperBound()
52 ,self.nominalentry: self.instance.getNominal()
53 }
54 for _k,_v in _arr.iteritems():
55 _t = str(_v / _conversion)+" "+_u
56 _k.set_text(_t)
57
58 self.varname.set_text(self.browser.sim.getInstanceName(self.instance));
59
60 if self.instance.isFixed():
61 pass
62
63 def on_varpropswin_destroy_event(self,*args,**kwargs):
64 self.varpropswin.response(gtk.RESPONSE_CANCEL)
65
66 def apply_changes(self):
67 print "APPLY"
68 # check the units of the entered values are acceptable
69
70 _arr = {
71 self.valueentry: self.instance.setRealValue
72 ,self.lowerentry: self.instance.setLowerBound
73 ,self.upperentry: self.instance.setUpperBound
74 ,self.nominalentry: self.instance.setNominal
75 }
76 for _k,_v in _arr.iteritems():
77 i = RealAtomEntry(self.instance, _k.get_text())
78 try:
79 i.checkEntry()
80 _v(i.getValue())
81 except InputError, e:
82 _k.get_style().bg = "#FFBBBB"
83 print "INPUT ERROR: ",str(e)
84
85 self.browser.refreshtree()
86
87 def run(self):
88 _continue = True;
89 while _continue:
90 _res = self.varpropswin.run();
91 try:
92 if _res == gtk.RESPONSE_APPLY or _res == gtk.RESPONSE_OK:
93 self.apply_changes();
94 except InputError:
95 # if input error, assume that the gui has been updated appropriately
96 continue;
97
98 if _res == gtk.RESPONSE_OK or _res==gtk.RESPONSE_CANCEL:
99 _continue = False;
100
101 self.varpropswin.hide();
102
103
104

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