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

Contents of /trunk/pygtk/properties.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 732 - (show annotations) (download) (as text)
Tue Jul 4 14:40:17 2006 UTC (17 years, 11 months ago) by johnpye
File MIME type: text/x-python
File size: 5351 byte(s)
Added general-purpose text-information dialog to PyGTK interface.
Added reporting of clique of a variable to PyGTK GUI.
Changed 'fixable' and 'new bounds' to use the new dialog.
Removed 'set<...>' from ascpy.i (it wasn't working), changed to vector<...>.
Exported a couple of var incidences fns to the DLL/SO.
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.exprbuff = gtk.TextBuffer();
22 self.expr.set_buffer(self.exprbuff)
23
24 self.fill_values()
25 _xml.signal_autoconnect(self)
26
27 def fill_values(self):
28 self.relname.set_text( self.browser.sim.getInstanceName(self.instance) )
29 self.residual.set_text( str( self.instance.getResidual() ) )
30 self.exprbuff.set_text( self.instance.getRelationAsString(self.browser.sim.getModel() ) )
31
32 def on_relpropswin_close(self,*args):
33 self.window.response(gtk.RESPONSE_CANCEL)
34
35 def on_entry_key_press_event(self,widget,event):
36 keyname = gtk.gdk.keyval_name(event.keyval)
37 if keyname=="Escape":
38 self.window.response(gtk.RESPONSE_CLOSE)
39 return True;
40 return False;
41
42 def run(self):
43 self.window.run()
44 self.window.hide()
45
46 class VarPropsWin:
47 def __init__(self,browser,instance):
48 self.instance = instance;
49 self.browser = browser;
50
51 # GUI config
52 _xml = gtk.glade.XML(browser.glade_file,"varpropswin")
53 self.window = _xml.get_widget("varpropswin")
54 self.window.set_transient_for(self.browser.window)
55
56 self.varname = _xml.get_widget("varname")
57 self.valueentry= _xml.get_widget("valueentry");
58 self.lowerentry = _xml.get_widget("lowerentry");
59 self.upperentry = _xml.get_widget("upperentry");
60 self.nominalentry = _xml.get_widget("nominalentry");
61 self.fixed = _xml.get_widget("fixed");
62 self.free = _xml.get_widget("free");
63
64 self.statusimg = _xml.get_widget("statusimg");
65 self.statusmessage = _xml.get_widget("statusmessage");
66
67 self.cliquebutton = _xml.get_widget("cliquebutton");
68
69 self.fill_values()
70
71 _xml.signal_autoconnect(self)
72
73 def fill_values(self):
74 # all the values here use the same preferred units for this instance type
75
76 _u = self.instance.getType().getPreferredUnits();
77 if _u == None:
78 _conversion = 1
79 _u = self.instance.getDimensions().getDefaultUnits().getName().toString()
80 else:
81 _conversion = _u.getConversion() # displayvalue x conversion = SI
82 _u = _u.getName().toString()
83
84 _arr = {
85 self.valueentry: self.instance.getRealValue()
86 ,self.lowerentry: self.instance.getLowerBound()
87 ,self.upperentry: self.instance.getUpperBound()
88 ,self.nominalentry: self.instance.getNominal()
89 }
90 for _k,_v in _arr.iteritems():
91 _t = str(_v / _conversion)+" "+_u
92 _k.set_text(_t)
93
94 self.varname.set_text(self.browser.sim.getInstanceName(self.instance));
95
96 if self.instance.isFixed():
97 self.fixed.set_active(True);
98 else:
99 self.free.set_active(True);
100
101 _status = self.instance.getVarStatus()
102
103 self.statusimg.set_from_pixbuf(self.browser.statusicons[_status]);
104 self.statusmessage.set_text(self.browser.statusmessages[_status]);
105
106 def apply_changes(self):
107 print "APPLY"
108 # check the units of the entered values are acceptable
109
110 _arr = {
111 self.valueentry: self.instance.setRealValue
112 ,self.lowerentry: self.instance.setLowerBound
113 ,self.upperentry: self.instance.setUpperBound
114 ,self.nominalentry: self.instance.setNominal
115 }
116 failed = False;
117 for _k,_v in _arr.iteritems():
118 i = RealAtomEntry(self.instance, _k.get_text())
119 try:
120 i.checkEntry()
121 self.color_entry(_k,"white");
122 _v(i.getValue())
123 except InputError, e:
124 print "INPUT ERROR: ",str(e)
125 self.color_entry(_k,"#FFBBBB");
126 failed = True;
127
128 self.instance.setFixed(self.fixed.get_active())
129
130 if failed:
131 raise InputError(None) # no message
132
133 self.browser.do_solve_if_auto()
134
135 def color_entry(self,entry,color):
136 entry.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
137 entry.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
138 entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
139 entry.modify_base(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
140
141 def on_varpropswin_close(self,*args):
142 self.window.response(gtk.RESPONSE_CANCEL)
143
144 def on_entry_key_press_event(self,widget,event):
145 keyname = gtk.gdk.keyval_name(event.keyval)
146 if keyname=="Return":
147 self.window.response(gtk.RESPONSE_OK)
148 return True
149 elif keyname=="Escape":
150 self.window.response(gtk.RESPONSE_CANCEL)
151 return True;
152 return False;
153
154 def on_cliquebutton_clicked(self,*args):
155 title = "Clique of '%s'"%self.browser.sim.getInstanceName(self.instance)
156 text = title + "\n\n"
157 s = self.instance.getClique();
158 if s:
159 for i in s:
160 text += "%s\n"%self.browser.sim.getInstanceName(i)
161 else:
162 text += "CLIQUE IS EMPTY"
163 _dialog = InfoDialog(self.browser,self.window,text,title)
164 _dialog.run()
165
166 def run(self):
167 self.valueentry.grab_focus()
168 _continue = True;
169 while _continue:
170 _res = self.window.run();
171 try:
172 if _res == gtk.RESPONSE_APPLY or _res == gtk.RESPONSE_OK:
173 self.apply_changes();
174 except InputError:
175 # if input error, assume that the gui has been updated appropriately
176 continue;
177
178 if _res == gtk.RESPONSE_OK or _res==gtk.RESPONSE_CANCEL:
179 _continue = False;
180
181 self.window.destroy();
182
183
184

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