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

Contents of /trunk/pygtk/properties.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1361 - (show annotations) (download) (as text)
Tue Mar 27 00:47:08 2007 UTC (15 years, 3 months ago) by jpye
File MIME type: text/x-python
File size: 6603 byte(s)
Fixed text 'this relation has no'
1 # GUI for ASCEND solver_var properties
2
3 import gtk, gtk.glade
4 import ascpy
5 from varentry import *
6 from infodialog import *
7
8 class RelPropsWin:
9 def __init__(self,browser,instance):
10 self.instance = instance;
11 self.browser = browser;
12
13 # GUI config
14 _xml = gtk.glade.XML(browser.glade_file,"relpropswin")
15 self.window = _xml.get_widget("relpropswin")
16 self.window.set_transient_for(self.browser.window)
17
18 self.relname = _xml.get_widget("relname")
19 self.residual = _xml.get_widget("residual")
20 self.expr = _xml.get_widget("expr")
21 self.included = _xml.get_widget("included")
22 self.active = _xml.get_widget("active")
23 self.exprbuff = gtk.TextBuffer();
24 self.expr.set_buffer(self.exprbuff)
25 self.morepropsbutton = _xml.get_widget("morepropsbutton");
26
27 self.fill_values()
28 _xml.signal_autoconnect(self)
29
30 def fill_values(self):
31 self.relname.set_text( self.browser.sim.getInstanceName(self.instance) )
32 self.residual.set_text( str( self.instance.getResidual() ) )
33 self.exprbuff.set_text( self.instance.getRelationAsString(self.browser.sim.getModel() ) )
34 self.included.set_active( self.instance.isIncluded() )
35
36 def on_relpropswin_close(self,*args):
37 self.window.response(gtk.RESPONSE_CANCEL)
38
39 def on_entry_key_press_event(self,widget,event):
40 keyname = gtk.gdk.keyval_name(event.keyval)
41 if keyname=="Escape":
42 self.window.response(gtk.RESPONSE_CLOSE)
43 return True;
44 return False;
45
46 def run(self):
47 self.window.run()
48 self.window.hide()
49
50 def on_morepropsbutton_clicked(self,*args):
51 title = "All properties of '%s'" % self.browser.sim.getInstanceName(self.instance)
52 text = title + "\n\n"
53 c = self.instance.getChildren()
54 if c:
55 for i in c:
56 text += "%s = %s\n" % (self.browser.sim.getInstanceName(i), i.getValue())
57 else:
58 text += "This relation has no 'child' properties"
59 _dialog = InfoDialog(self.browser,self.window,text,title)
60 _dialog.run()
61
62 def on_included_toggled(self,widget,*args):
63 self.instance.setIncluded(widget.get_active())
64 self.browser.do_solve_if_auto()
65
66 class VarPropsWin:
67 def __init__(self,browser,instance):
68 self.instance = instance;
69 self.browser = browser;
70
71 # GUI config
72 _xml = gtk.glade.XML(browser.glade_file,"varpropswin")
73 self.window = _xml.get_widget("varpropswin")
74 self.window.set_transient_for(self.browser.window)
75
76 self.varname = _xml.get_widget("varname")
77 self.valueentry= _xml.get_widget("valueentry");
78 self.lowerentry = _xml.get_widget("lowerentry");
79 self.upperentry = _xml.get_widget("upperentry");
80 self.nominalentry = _xml.get_widget("nominalentry");
81 self.fixed = _xml.get_widget("fixed");
82 self.free = _xml.get_widget("free");
83
84 self.statusimg = _xml.get_widget("statusimg");
85 self.statusmessage = _xml.get_widget("statusmessage");
86
87 self.cliquebutton = _xml.get_widget("cliquebutton");
88 self.morepropsbutton = _xml.get_widget("morepropsbutton");
89
90 self.fill_values()
91
92 _xml.signal_autoconnect(self)
93
94 def fill_values(self):
95 # all the values here use the same preferred units for this instance type
96
97 _u = self.instance.getType().getPreferredUnits();
98 if _u == None:
99 _conversion = 1
100 _u = self.instance.getDimensions().getDefaultUnits().getName().toString()
101 else:
102 _conversion = _u.getConversion() # displayvalue x conversion = SI
103 _u = _u.getName().toString()
104
105 _arr = {
106 self.valueentry: self.instance.getRealValue()
107 ,self.lowerentry: self.instance.getLowerBound()
108 ,self.upperentry: self.instance.getUpperBound()
109 ,self.nominalentry: self.instance.getNominal()
110 }
111 for _k,_v in _arr.iteritems():
112 _t = str(_v / _conversion)+" "+_u
113 _k.set_text(_t)
114
115 self.varname.set_text(self.browser.sim.getInstanceName(self.instance));
116
117 if self.instance.isFixed():
118 self.fixed.set_active(True);
119 else:
120 self.free.set_active(True);
121
122 _status = self.instance.getVarStatus()
123
124 self.statusimg.set_from_pixbuf(self.browser.statusicons[_status]);
125 self.statusmessage.set_text(self.browser.statusmessages[_status]);
126
127 def apply_changes(self):
128 print "APPLY"
129 # check the units of the entered values are acceptable
130
131 _arr = {
132 self.valueentry: self.instance.setRealValue
133 ,self.lowerentry: self.instance.setLowerBound
134 ,self.upperentry: self.instance.setUpperBound
135 ,self.nominalentry: self.instance.setNominal
136 }
137 failed = False;
138 for _k,_v in _arr.iteritems():
139 i = RealAtomEntry(self.instance, _k.get_text())
140 try:
141 i.checkEntry()
142 self.color_entry(_k,"white");
143 _v(i.getValue())
144 except InputError, e:
145 print "INPUT ERROR: ",str(e)
146 self.color_entry(_k,"#FFBBBB");
147 failed = True;
148
149 self.instance.setFixed(self.fixed.get_active())
150
151 if failed:
152 raise InputError(None) # no message
153
154 self.browser.do_solve_if_auto()
155
156 def color_entry(self,entry,color):
157 entry.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
158 entry.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
159 entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
160 entry.modify_base(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
161
162 def on_varpropswin_close(self,*args):
163 self.window.response(gtk.RESPONSE_CANCEL)
164
165 def on_entry_key_press_event(self,widget,event):
166 keyname = gtk.gdk.keyval_name(event.keyval)
167 if keyname=="Return":
168 self.window.response(gtk.RESPONSE_OK)
169 return True
170 elif keyname=="Escape":
171 self.window.response(gtk.RESPONSE_CANCEL)
172 return True;
173 return False;
174
175 def on_cliquebutton_clicked(self,*args):
176 title = "Clique of '%s'"%self.browser.sim.getInstanceName(self.instance)
177 text = title + "\n\n"
178 s = self.instance.getClique();
179 if s:
180 for i in s:
181 text += "%s\n"%self.browser.sim.getInstanceName(i)
182 else:
183 text += "CLIQUE IS EMPTY"
184 _dialog = InfoDialog(self.browser,self.window,text,title)
185 _dialog.run()
186
187 def on_morepropsbutton_clicked(self,*args):
188 title = "All properties of '%s'" % self.browser.sim.getInstanceName(self.instance)
189 text = title + "\n\n"
190 c = self.instance.getChildren()
191 if c:
192 for i in c:
193 text += "%s = %s\n" % (self.browser.sim.getInstanceName(i), i.getValue())
194 else:
195 text += "This variable has no 'child' properties"
196 _dialog = InfoDialog(self.browser,self.window,text,title)
197 _dialog.run()
198
199 def run(self):
200 self.valueentry.grab_focus()
201 _continue = True;
202 while _continue:
203 _res = self.window.run();
204 try:
205 if _res == gtk.RESPONSE_APPLY or _res == gtk.RESPONSE_OK:
206 self.apply_changes();
207 except InputError:
208 # if input error, assume that the gui has been updated appropriately
209 continue;
210
211 if _res == gtk.RESPONSE_OK or _res==gtk.RESPONSE_CANCEL:
212 _continue = False;
213
214 self.window.destroy();
215
216
217

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