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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations) (download) (as text)
Sat Feb 4 09:08:54 2006 UTC (18 years, 4 months ago) by johnpye
File MIME type: text/x-python
File size: 4004 byte(s)
Working on adding support for listing cliques
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 # 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 self.fixed = _xml.get_widget("fixed");
22 self.free = _xml.get_widget("free");
23
24 self.statusimg = _xml.get_widget("statusimg"); self.statusimg = None
25
26 self.othernames = _xml.get_widget("othernames");
27
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 self.fixed.set_active(True);
57 else:
58 self.free.set_active(True);
59
60 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 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 failed = False;
81 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 self.color_entry(_k,"#FFBBBB");
89 failed = True;
90
91 self.instance.setFixed(self.fixed.get_active())
92
93 if failed:
94 raise InputError(None) # no message
95
96 self.browser.do_solve_if_auto()
97
98 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 self.varpropswin.response(gtk.RESPONSE_CANCEL)
106
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 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 def run(self):
124 self.valueentry.grab_focus()
125 _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 self.varpropswin.destroy();
139
140
141

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