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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (hide annotations) (download) (as text)
Sat Feb 4 09:08:54 2006 UTC (18 years, 5 months ago) by johnpye
File MIME type: text/x-python
File size: 4004 byte(s)
Working on adding support for listing cliques
1 johnpye 268 # 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     # GUI config
13     _xml = gtk.glade.XML(GLADE_FILE,"varpropswin")
14     self.varpropswin = _xml.get_widget("varpropswin")
15    
16     self.varname = _xml.get_widget("varname")
17     self.valueentry= _xml.get_widget("valueentry");
18     self.lowerentry = _xml.get_widget("lowerentry");
19     self.upperentry = _xml.get_widget("upperentry");
20     self.nominalentry = _xml.get_widget("nominalentry");
21 johnpye 271 self.fixed = _xml.get_widget("fixed");
22     self.free = _xml.get_widget("free");
23    
24 johnpye 268 self.statusimg = _xml.get_widget("statusimg"); self.statusimg = None
25    
26 johnpye 271 self.othernames = _xml.get_widget("othernames");
27 johnpye 268
28     self.fill_values()
29    
30     _xml.signal_autoconnect(self)
31    
32     def fill_values(self):
33     # all the values here use the same preferred units for this instance type
34    
35     _u = self.instance.getType().getPreferredUnits();
36     if _u == None:
37     _conversion = 1
38     _u = self.getDimensions().getDefaultUnits().getName().toString()
39     else:
40     _conversion = _u.getConversion() # displayvalue x conversion = SI
41     _u = _u.getName().toString()
42    
43     _arr = {
44     self.valueentry: self.instance.getRealValue()
45     ,self.lowerentry: self.instance.getLowerBound()
46     ,self.upperentry: self.instance.getUpperBound()
47     ,self.nominalentry: self.instance.getNominal()
48     }
49     for _k,_v in _arr.iteritems():
50     _t = str(_v / _conversion)+" "+_u
51     _k.set_text(_t)
52    
53     self.varname.set_text(self.browser.sim.getInstanceName(self.instance));
54    
55     if self.instance.isFixed():
56 johnpye 271 self.fixed.set_active(True);
57     else:
58     self.free.set_active(True);
59 johnpye 268
60 johnpye 271 self.clique = self.instance.getClique()
61     print "CLIQUE:",self.clique
62    
63     if len(self.clique) > 1:
64     self.othernames.set_label("%d other names..." % len(self.clique));
65     self.othernames.set_sensitive(True)
66     else:
67     self.othernames.set_label("No other names");
68     self.othernames.set_sensitive(False)
69    
70 johnpye 268 def apply_changes(self):
71     print "APPLY"
72     # check the units of the entered values are acceptable
73    
74     _arr = {
75     self.valueentry: self.instance.setRealValue
76     ,self.lowerentry: self.instance.setLowerBound
77     ,self.upperentry: self.instance.setUpperBound
78     ,self.nominalentry: self.instance.setNominal
79     }
80 johnpye 269 failed = False;
81 johnpye 268 for _k,_v in _arr.iteritems():
82     i = RealAtomEntry(self.instance, _k.get_text())
83     try:
84     i.checkEntry()
85     _v(i.getValue())
86     except InputError, e:
87     print "INPUT ERROR: ",str(e)
88 johnpye 269 self.color_entry(_k,"#FFBBBB");
89     failed = True;
90 johnpye 268
91 johnpye 271 self.instance.setFixed(self.fixed.get_active())
92    
93 johnpye 269 if failed:
94 johnpye 271 raise InputError(None) # no message
95 johnpye 269
96 johnpye 271 self.browser.do_solve_if_auto()
97 johnpye 268
98 johnpye 269 def color_entry(self,entry,color):
99     entry.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
100     entry.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
101     entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
102     entry.modify_base(gtk.STATE_ACTIVE, gtk.gdk.color_parse(color))
103    
104     def on_varpropswin_close(self,*args):
105 johnpye 270 self.varpropswin.response(gtk.RESPONSE_CANCEL)
106 johnpye 269
107     def on_entry_key_press_event(self,widget,event):
108     keyname = gtk.gdk.keyval_name(event.keyval)
109     if keyname=="Return":
110     self.varpropswin.response(gtk.RESPONSE_OK)
111     return True
112     elif keyname=="Escape":
113     self.varpropswin.response(gtk.RESPONSE_CANCEL)
114     return True;
115     return False;
116    
117 johnpye 271 def on_othernames_clicked(self,*args):
118     print "OTHER NAMES..."
119     s = self.instance.getClique();
120     for i in s:
121     print self.browser.sim.getInstanceName(i)
122    
123 johnpye 268 def run(self):
124 johnpye 271 self.valueentry.grab_focus()
125 johnpye 268 _continue = True;
126     while _continue:
127     _res = self.varpropswin.run();
128     try:
129     if _res == gtk.RESPONSE_APPLY or _res == gtk.RESPONSE_OK:
130     self.apply_changes();
131     except InputError:
132     # if input error, assume that the gui has been updated appropriately
133     continue;
134    
135     if _res == gtk.RESPONSE_OK or _res==gtk.RESPONSE_CANCEL:
136     _continue = False;
137    
138 johnpye 269 self.varpropswin.destroy();
139 johnpye 268
140    
141    

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