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

Contents of /trunk/pygtk/properties.py

Parent Directory Parent Directory | Revision Log Revision Log


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

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