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

Diff of /trunk/pygtk/diagnose.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/pygtk/interface/diagnose.py revision 319 by johnpye, Thu Feb 23 12:30:40 2006 UTC trunk/pygtk/diagnose.py revision 735 by johnpye, Wed Jul 5 02:42:19 2006 UTC
# Line 1  Line 1 
1  import gtk  import gtk
2  import gtk.glade  import gtk.glade
3  import ascend  import ascpy
4  from itertools import groupby  from itertools import groupby
5  from operator import itemgetter  from operator import itemgetter
6  import math  import math
7  import re  import re
8    
9    import config
10    from infodialog import *
11    
12  ZOOM_RE = re.compile(r"([0-9]+)\s*%?")  ZOOM_RE = re.compile(r"([0-9]+)\s*%?")
13  MAX_ZOOM_SIZE = 2000  MAX_ZOOM_SIZE = 2000
14  MAX_ZOOM_RATIO = 16  MAX_ZOOM_RATIO = 16
15  AT_BOUND_TOL = 0.0001;  AT_BOUND_TOL = 0.0001;
16    
17  class DiagnoseWindow:  class DiagnoseWindow:
18      def __init__(self,GLADE_FILE,browser,block=0):      def __init__(self,browser,block=0):
19          self.browser=browser          self.browser=browser
20          _xml = gtk.glade.XML(GLADE_FILE,"diagnosewin")          _xml = gtk.glade.XML(browser.glade_file,"diagnosewin")
21          _xml.signal_autoconnect(self)            _xml.signal_autoconnect(self)  
22    
23          self.window = _xml.get_widget("diagnosewin")          self.window = _xml.get_widget("diagnosewin")
24            self.window.set_transient_for(self.browser.window)
25    
26            try:
27                _icon = gtk.Image()
28                _iconpath = browser.assets_dir+'diagnose'+config.ICON_EXTENSION
29                print "ICON PATH =",_iconpath
30                _icon.set_from_file(_iconpath)
31                print "ICON = ",_icon
32                self.window.set_icon(_icon)
33            except:
34                pass
35            
36          self.imagescroll = _xml.get_widget("imagescroll")          self.imagescroll = _xml.get_widget("imagescroll")
37          self.image = _xml.get_widget("image")          self.image = _xml.get_widget("image")
38          self.blockentry = _xml.get_widget("blockentry")          self.blockentry = _xml.get_widget("blockentry")
# Line 25  class DiagnoseWindow: Line 40  class DiagnoseWindow:
40    
41          self.varname = _xml.get_widget("varname");          self.varname = _xml.get_widget("varname");
42          self.varval = _xml.get_widget("varval");          self.varval = _xml.get_widget("varval");
43            self.varinfobutton = _xml.get_widget("varinfobutton");
44          self.relname = _xml.get_widget("relname");          self.relname = _xml.get_widget("relname");
45          self.relresid = _xml.get_widget("relresid");          self.relresid = _xml.get_widget("relresid");
46            self.relinfobutton = _xml.get_widget("relinfobutton")
47    
48          self.varview = _xml.get_widget("varview")          self.varview = _xml.get_widget("varview")
49          self.varbuf = gtk.TextBuffer()          self.varbuf = gtk.TextBuffer()
# Line 96  class DiagnoseWindow: Line 113  class DiagnoseWindow:
113          nr = int(rh-rl+1);          nr = int(rh-rl+1);
114          nc = int(ch-cl+1);          nc = int(ch-cl+1);
115    
116          #print "STARTING IMAGE CREATION"          print "STARTING IMAGE CREATION"
117          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html
118          c = chr(255)          c = chr(255)
119          b = nr*nc*3*[c]          b = nr*nc*3*[c]
# Line 148  class DiagnoseWindow: Line 165  class DiagnoseWindow:
165    
166          d = ''.join(b)          d = ''.join(b)
167    
168          #print "DONE IMAGE CREATION"          print "DONE IMAGE CREATION"
169            
170          self.pixbuf = gtk.gdk.pixbuf_new_from_data(d, gtk.gdk.COLORSPACE_RGB, False, 8 \          self.pixbuf = gtk.gdk.pixbuf_new_from_data(d, gtk.gdk.COLORSPACE_RGB, False, 8 \
171                  , nc, nr, rowstride);                  , nc, nr, rowstride);
# Line 158  class DiagnoseWindow: Line 175  class DiagnoseWindow:
175          self.zoom = -1 # to fit, up to max 16x          self.zoom = -1 # to fit, up to max 16x
176          self.do_zoom()          self.do_zoom()
177    
178          #print "DONE IMAGE TRANSFER TO SERVER"          print "DONE IMAGE TRANSFER TO SERVER"
179    
180          self.fill_var_names()          self.fill_var_names()
181          self.fill_rel_names()          self.fill_rel_names()
182            
183          self.varname.set_text("");          self.fill_selection_info()
         self.varval.set_text("");  
         self.relname.set_text("");  
         self.relresid.set_text("");  
184    
185            print "DONE FILL VALUES"
186    
187        def fill_selection_info(self):
188            if self.var:
189                self.varname.set_text(self.var.getName())
190                self.varval.set_text(str(self.var.getValue()))
191                self.varinfobutton.set_sensitive(True)
192            else:
193                self.varname.set_text("")
194                self.varval.set_text("")
195                self.varinfobutton.set_sensitive(False)
196    
197            if self.rel:
198                self.relname.set_text(self.rel.getName())
199                self.relresid.set_text(str(self.rel.getResidual()))
200                self.relinfobutton.set_sensitive(True)
201            else:
202                self.relname.set_text("")
203                self.relresid.set_text("")
204                self.relinfobutton.set_sensitive(False)
205    
206      def do_zoom(self):      def do_zoom(self):
207          if self.zoom == -1:          if self.zoom == -1:
# Line 198  class DiagnoseWindow: Line 232  class DiagnoseWindow:
232          self.image.set_from_pixbuf(pb1)          self.image.set_from_pixbuf(pb1)
233    
234      def fill_var_names(self):      def fill_var_names(self):
235            print "FILL VAR NAMES"
236    
237          names = [str(i) for i in self.im.getBlockVars(self.block)]          names = [str(i) for i in self.im.getBlockVars(self.block)]
238    
239            print "NAMES:",names
240    
241          if self.varcollapsed.get_active():          if self.varcollapsed.get_active():
242              res = reduce(names)              res = reduce(names)
243              rows = []              rows = []
# Line 213  class DiagnoseWindow: Line 252  class DiagnoseWindow:
252              text = "\n".join(names)              text = "\n".join(names)
253          self.varbuf.set_text(text)          self.varbuf.set_text(text)
254    
255            print "DONE VAR NAMES"
256    
257      def fill_rel_names(self):      def fill_rel_names(self):
258          names = [str(i) for i in self.im.getBlockRels(self.block)]          print "REL NAMES"
259    
260            rels = self.im.getBlockRels(self.block)
261    
262            print "GOT RELS, NOW GETTING NAMES"
263    
264            names = [str(i) for i in rels]
265    
266            print "NAMES =",names
267    
268          if self.relcollapsed.get_active():          if self.relcollapsed.get_active():
269              res = reduce(names)              res = reduce(names)
270              rows = []              rows = []
# Line 229  class DiagnoseWindow: Line 279  class DiagnoseWindow:
279              text = "\n".join(names)              text = "\n".join(names)
280          self.relbuf.set_text(text)          self.relbuf.set_text(text)
281    
282            print "DONE REL NAMES"
283    
284      def set_block(self, block):      def set_block(self, block):
285          self.fill_values(block)          self.fill_values(block)
286    
# Line 242  class DiagnoseWindow: Line 294  class DiagnoseWindow:
294          if c > self.ch or r > self.rh:          if c > self.ch or r > self.rh:
295              #print "OUT OF RANGE"              #print "OUT OF RANGE"
296              return              return
297          var = self.im.getVariable(c)          self.var = self.im.getVariable(c)
298          self.varname.set_text(var.getName())          self.rel = self.im.getRelation(r)
299          self.varval.set_text(str(var.getValue()))          self.fill_selection_info()
         rel = self.im.getRelation(r)  
         self.relname.set_text(rel.getName())  
         self.relresid.set_text(str(rel.getResidual()))  
300    
301      # GUI EVENT HOOKS-----------------------------------------------------------      # GUI EVENT HOOKS-----------------------------------------------------------
302    
303        def on_diagnosewin_close(self,*args):
304            self.window.response(gtk.RESPONSE_CLOSE);
305    
306        # incidence data view
307    
308      def on_varcollapsed_toggled(self,*args):      def on_varcollapsed_toggled(self,*args):
309          vc = self.varcollapsed.get_active()          vc = self.varcollapsed.get_active()
310          self.browser.prefs.setBoolPref("Diagnose","varcollapsed",vc)              self.browser.prefs.setBoolPref("Diagnose","varcollapsed",vc)    
# Line 263  class DiagnoseWindow: Line 317  class DiagnoseWindow:
317          if self.im:          if self.im:
318              self.fill_rel_names()              self.fill_rel_names()
319    
320        # detailed information about vars and rels (solver-side information!)
321    
322        def on_varinfobutton_clicked(self,*args):
323            title = "Variable '%s'" % self.var
324            text = "%s\n%s\n" % (title,"(from the solver's view)")
325            text += "\n%-30s%15f" % ("Value", self.var.getValue())
326            text += "\n%-30s%15f" % ("Nominal", self.var.getNominal())
327            text += "\n%-30s%15f" % ("Lower bound", self.var.getLowerBound())
328            text += "\n%-30s%15f" % ("Upper bound", self.var.getUpperBound())
329            
330            text += "\n\nIncidence with %d relations:" % self.var.getNumIncidentRelations()
331            for r in self.var.getIncidentRelations():
332                text += "\n%s" % r.getName()
333    
334            _dialog = InfoDialog(self.browser,self.window,text,title)
335            _dialog.run()
336    
337        def on_relinfobutton_clicked(self,*args):
338            title = "Relation '%s'" % self.rel
339            text = "%s\n%s\n" % (title,"(from the solver's view)")
340            text += "\n%-30s%15f" % ("Residual", self.rel.getResidual())
341    
342            _dialog = InfoDialog(self.browser,self.window,text,title)
343            _dialog.run()
344            
345    
346        # block navigation
347    
348      def on_nextbutton_clicked(self,*args):      def on_nextbutton_clicked(self,*args):
349          self.set_block(self.block + 1)          self.set_block(self.block + 1)
350    
# Line 294  class DiagnoseWindow: Line 376  class DiagnoseWindow:
376          if keyname=="Return":          if keyname=="Return":
377              self.set_block( int(self.blockentry.get_text()) )              self.set_block( int(self.blockentry.get_text()) )
378    
379        # zoom in and out
380    
381      def on_zoominbutton_clicked(self,*args):      def on_zoominbutton_clicked(self,*args):
382          z = int( math.log(self.zoom)/math.log(2) )          z = int( math.log(self.zoom)/math.log(2) )
383          z = pow(2,z + 1);          z = pow(2,z + 1);
# Line 316  class DiagnoseWindow: Line 400  class DiagnoseWindow:
400                  print m                  print m
401              self.set_zoom( int(self.zoomentry.get_text()) )              self.set_zoom( int(self.zoomentry.get_text()) )
402    
403        # clicking in incidence matrix to get updated information at RHS
404    
405      def on_imageevent_motion_notify_event(self,widget,event):      def on_imageevent_motion_notify_event(self,widget,event):
406          self.show_cursor(event.x, event.y)          self.show_cursor(event.x, event.y)
407    

Legend:
Removed from v.319  
changed lines
  Added in v.735

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