/[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 437 by johnpye, Tue Apr 4 11:08:15 2006 UTC trunk/pygtk/diagnose.py revision 736 by johnpye, Wed Jul 5 04:56:26 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  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
# Line 22  class DiagnoseWindow: Line 23  class DiagnoseWindow:
23          self.window = _xml.get_widget("diagnosewin")          self.window = _xml.get_widget("diagnosewin")
24          self.window.set_transient_for(self.browser.window)          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")
39          self.zoomentry = _xml.get_widget("zoomentry")          self.zoomentry = _xml.get_widget("zoomentry")
40    
41          self.varname = _xml.get_widget("varname");          self.var = None; self.rel = None
42          self.varval = _xml.get_widget("varval");          self.varname = _xml.get_widget("varname")
43          self.relname = _xml.get_widget("relname");          self.varval = _xml.get_widget("varval")
44          self.relresid = _xml.get_widget("relresid");          self.varinfobutton = _xml.get_widget("varinfobutton")
45            self.relname = _xml.get_widget("relname")
46            self.relresid = _xml.get_widget("relresid")
47            self.relinfobutton = _xml.get_widget("relinfobutton")
48    
49          self.varview = _xml.get_widget("varview")          self.varview = _xml.get_widget("varview")
50          self.varbuf = gtk.TextBuffer()          self.varbuf = gtk.TextBuffer()
# Line 75  class DiagnoseWindow: Line 89  class DiagnoseWindow:
89      def fill_values(self, block):      def fill_values(self, block):
90                    
91          try:          try:
92                if self.im.getNumBlocks()==0:
93                    print "NO BLOCKS!"
94                    self.image.set_from_stock(gtk.STOCK_DIALOG_ERROR
95                        ,gtk.ICON_SIZE_DIALOG
96                    )
97                    self.browser.reporter.reportError(
98                        "Can't 'Diagnose blocks' until solver has been used."
99                    )
100                    return;
101              rl,cl,rh,ch = self.im.getBlockLocation(block)              rl,cl,rh,ch = self.im.getBlockLocation(block)
102          except IndexError:          except IndexError:
103              if block >= self.im.getNumBlocks():              if block >= self.im.getNumBlocks():
# Line 100  class DiagnoseWindow: Line 123  class DiagnoseWindow:
123          nr = int(rh-rl+1);          nr = int(rh-rl+1);
124          nc = int(ch-cl+1);          nc = int(ch-cl+1);
125    
126          #print "STARTING IMAGE CREATION"          print "STARTING IMAGE CREATION"
127          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html
128          c = chr(255)          c = chr(255)
129          b = nr*nc*3*[c]          b = nr*nc*3*[c]
# Line 152  class DiagnoseWindow: Line 175  class DiagnoseWindow:
175    
176          d = ''.join(b)          d = ''.join(b)
177    
178          #print "DONE IMAGE CREATION"          print "DONE IMAGE CREATION"
179            
180          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 \
181                  , nc, nr, rowstride);                  , nc, nr, rowstride);
# Line 162  class DiagnoseWindow: Line 185  class DiagnoseWindow:
185          self.zoom = -1 # to fit, up to max 16x          self.zoom = -1 # to fit, up to max 16x
186          self.do_zoom()          self.do_zoom()
187    
188          #print "DONE IMAGE TRANSFER TO SERVER"          print "DONE IMAGE TRANSFER TO SERVER"
189    
190          self.fill_var_names()          self.fill_var_names()
191          self.fill_rel_names()          self.fill_rel_names()
192            
193          self.varname.set_text("");          self.fill_selection_info()
         self.varval.set_text("");  
         self.relname.set_text("");  
         self.relresid.set_text("");  
194    
195            print "DONE FILL VALUES"
196    
197        def fill_selection_info(self):
198            if self.var:
199                self.varname.set_text(self.var.getName())
200                self.varval.set_text(str(self.var.getValue()))
201                self.varinfobutton.set_sensitive(True)
202            else:
203                self.varname.set_text("")
204                self.varval.set_text("")
205                self.varinfobutton.set_sensitive(False)
206    
207            if self.rel:
208                self.relname.set_text(self.rel.getName())
209                self.relresid.set_text(str(self.rel.getResidual()))
210                self.relinfobutton.set_sensitive(True)
211            else:
212                self.relname.set_text("")
213                self.relresid.set_text("")
214                self.relinfobutton.set_sensitive(False)
215    
216      def do_zoom(self):      def do_zoom(self):
217          if self.zoom == -1:          if self.zoom == -1:
# Line 202  class DiagnoseWindow: Line 242  class DiagnoseWindow:
242          self.image.set_from_pixbuf(pb1)          self.image.set_from_pixbuf(pb1)
243    
244      def fill_var_names(self):      def fill_var_names(self):
245            print "FILL VAR NAMES"
246    
247          names = [str(i) for i in self.im.getBlockVars(self.block)]          names = [str(i) for i in self.im.getBlockVars(self.block)]
248    
249            print "NAMES:",names
250    
251          if self.varcollapsed.get_active():          if self.varcollapsed.get_active():
252              res = reduce(names)              res = reduce(names)
253              rows = []              rows = []
# Line 217  class DiagnoseWindow: Line 262  class DiagnoseWindow:
262              text = "\n".join(names)              text = "\n".join(names)
263          self.varbuf.set_text(text)          self.varbuf.set_text(text)
264    
265            print "DONE VAR NAMES"
266    
267      def fill_rel_names(self):      def fill_rel_names(self):
268          names = [str(i) for i in self.im.getBlockRels(self.block)]          print "REL NAMES"
269    
270            rels = self.im.getBlockRels(self.block)
271    
272            print "GOT RELS, NOW GETTING NAMES"
273    
274            names = [str(i) for i in rels]
275    
276            print "NAMES =",names
277    
278          if self.relcollapsed.get_active():          if self.relcollapsed.get_active():
279              res = reduce(names)              res = reduce(names)
280              rows = []              rows = []
# Line 233  class DiagnoseWindow: Line 289  class DiagnoseWindow:
289              text = "\n".join(names)              text = "\n".join(names)
290          self.relbuf.set_text(text)          self.relbuf.set_text(text)
291    
292            print "DONE REL NAMES"
293    
294      def set_block(self, block):      def set_block(self, block):
295          self.fill_values(block)          self.fill_values(block)
296    
# Line 246  class DiagnoseWindow: Line 304  class DiagnoseWindow:
304          if c > self.ch or r > self.rh:          if c > self.ch or r > self.rh:
305              #print "OUT OF RANGE"              #print "OUT OF RANGE"
306              return              return
307          var = self.im.getVariable(c)          self.var = self.im.getVariable(c)
308          self.varname.set_text(var.getName())          self.rel = self.im.getRelation(r)
309          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()))  
310    
311      # GUI EVENT HOOKS-----------------------------------------------------------      # GUI EVENT HOOKS-----------------------------------------------------------
312    
313        def on_diagnosewin_close(self,*args):
314            self.window.response(gtk.RESPONSE_CLOSE);
315    
316        # incidence data view
317    
318      def on_varcollapsed_toggled(self,*args):      def on_varcollapsed_toggled(self,*args):
319          vc = self.varcollapsed.get_active()          vc = self.varcollapsed.get_active()
320          self.browser.prefs.setBoolPref("Diagnose","varcollapsed",vc)              self.browser.prefs.setBoolPref("Diagnose","varcollapsed",vc)    
# Line 267  class DiagnoseWindow: Line 327  class DiagnoseWindow:
327          if self.im:          if self.im:
328              self.fill_rel_names()              self.fill_rel_names()
329    
330        # detailed information about vars and rels (solver-side information!)
331    
332        def on_varinfobutton_clicked(self,*args):
333            title = "Variable '%s'" % self.var
334            text = "%s\n%s\n" % (title,"(from the solver's view)")
335    
336            _rows = {
337                "Value": self.var.getValue()
338                ,"Nominal": self.var.getNominal()
339                ,"Lower bound": self.var.getLowerBound()
340                ,"Upper bound": self.var.getUpperBound()
341            }
342            for k,v in _rows.iteritems():
343                if v!=0:
344                    l = math.log10(abs(v))
345                else:
346                    l = 0;
347                if l > 8 or l < -8:
348                    text += "\n  %-30s%15e" % (k,v)
349                else:
350                    text += "\n  %-30s%15f" % (k,v)
351            
352            text += "\n\nIncidence with %d relations:" % self.var.getNumIncidentRelations()
353            for r in self.var.getIncidentRelations():
354                text += "\n  %s" % r.getName()
355    
356            _dialog = InfoDialog(self.browser,self.window,text,title)
357            _dialog.run()
358    
359        def on_relinfobutton_clicked(self,*args):
360            title = "Relation '%s'" % self.rel
361            text = "%s\n%s\n" % (title,"(from the solver's view)")
362            text += "\n  %-30s%15f" % ("Residual", self.rel.getResidual())
363    
364            text += "\n\nRelation expression:\n"
365            text += self.rel.getRelationAsString()
366    
367            _dialog = InfoDialog(self.browser,self.window,text,title)
368            _dialog.run()
369            
370    
371        # block navigation
372    
373      def on_nextbutton_clicked(self,*args):      def on_nextbutton_clicked(self,*args):
374          self.set_block(self.block + 1)          self.set_block(self.block + 1)
375    
# Line 298  class DiagnoseWindow: Line 401  class DiagnoseWindow:
401          if keyname=="Return":          if keyname=="Return":
402              self.set_block( int(self.blockentry.get_text()) )              self.set_block( int(self.blockentry.get_text()) )
403    
404        # zoom in and out
405    
406      def on_zoominbutton_clicked(self,*args):      def on_zoominbutton_clicked(self,*args):
407          z = int( math.log(self.zoom)/math.log(2) )          z = int( math.log(self.zoom)/math.log(2) )
408          z = pow(2,z + 1);          z = pow(2,z + 1);
# Line 320  class DiagnoseWindow: Line 425  class DiagnoseWindow:
425                  print m                  print m
426              self.set_zoom( int(self.zoomentry.get_text()) )              self.set_zoom( int(self.zoomentry.get_text()) )
427    
428        # clicking in incidence matrix to get updated information at RHS
429    
430      def on_imageevent_motion_notify_event(self,widget,event):      def on_imageevent_motion_notify_event(self,widget,event):
431          self.show_cursor(event.x, event.y)          self.show_cursor(event.x, event.y)
432    

Legend:
Removed from v.437  
changed lines
  Added in v.736

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