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

Diff of /trunk/pygtk/diagnose.py

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

revision 282 by johnpye, Wed Feb 8 13:51:04 2006 UTC revision 283 by johnpye, Wed Feb 8 15:30:50 2006 UTC
# Line 1  Line 1 
1  import gtk  import gtk
2  import gtk.glade  import gtk.glade
3  import ascend  import ascend
 import pylab;  
 import matplotlib  
 matplotlib.use('GTK')  
 from matplotlib.figure import Figure  
 from matplotlib.axes import Subplot  
 from matplotlib.colors import LinearSegmentedColormap  
 from matplotlib.backends.backend_gtk import FigureCanvasGTK, NavigationToolbar  
4  from itertools import groupby  from itertools import groupby
5  from operator import itemgetter  from operator import itemgetter
6    import math
7    
8  class DiagnoseWindow:  class DiagnoseWindow:
9      def __init__(self,GLADE_FILE,browser):      def __init__(self,GLADE_FILE,browser):
# Line 52  class DiagnoseWindow: Line 46  class DiagnoseWindow:
46            
47      def fill_values(self, block):      def fill_values(self, block):
48          print "FILL VALUES %d" % block          print "FILL VALUES %d" % block
49            try:
50                rl,cl,rh,ch = self.im.getBlockLocation(block)
51            except IndexError:
52                print "invalid block"
53                return
54          self.block = block          self.block = block
55          self.blockentry.set_text(str(block))          self.blockentry.set_text(str(block))
56            
57            nr = int(rh-rl+1);
58            nc = int(ch-cl+1);
59    
60            print "STARTING IMAGE CREATION"
61          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html          # refer http://pygtk.org/pygtk2tutorial/sec-DrawingMethods.html
62          c = chr(255)          c = chr(255)
63          b = self.im.getNumRows()*self.im.getNumCols()*3*[c]          b = nr*nc*3*[c]
64          rowstride = 3 * self.im.getNumCols()          rowstride = 3 * nc
65          for i in self.data:          
66              pos = rowstride*i.row + 3*i.col          blackdot = [chr(0)]*3;
67              b[pos], b[pos+1], b[pos+2] = [chr(0)]*3          reddot = [chr(255), chr(0), chr(0)]
68            pinkdot = [chr(255), chr(127), chr(127)]
69            skydot = [chr(127), chr(127), chr(255)]
70            bluedot = [chr(0), chr(0), chr(255)]
71                    
72            for i in self.data:
73                if i.row < rl or i.row > rh or i.col < cl or i.col > ch:
74                    continue
75                r = i.row - rl;
76                c = i.col - cl;
77                pos = rowstride*r + 3*c
78                dot = blackdot;
79                var = self.im.getVariable(i.col);
80                try:
81                    rat = var.getValue() / var.getNominal()
82                    print "SCALE i.col =",rat
83                    val = math.log(rat);
84                    print "LOG i.col =",val
85                    if val > 1:
86                        dot = reddot;
87                    elif var < -1:
88                        dot = bluedot;
89                    elif var > 0:
90                        dot = pinkdot;
91                    elif var < 0:
92                        dot = skydot;
93                except ValueError, e:
94                    pass
95                print "DOT: ",dot
96                b[pos], b[pos+1], b[pos+2] = dot
97    
98          d = ''.join(b)          d = ''.join(b)
99    
100            print "DONE IMAGE CREATION"
101    
102          pb = gtk.gdk.pixbuf_new_from_data(d, gtk.gdk.COLORSPACE_RGB, False, 8 \          pb = gtk.gdk.pixbuf_new_from_data(d, gtk.gdk.COLORSPACE_RGB, False, 8 \
103                  , self.im.getNumCols(), self.im.getNumRows(), rowstride)                  , nc, nr, rowstride)
104            
105          pb1 = pb.scale_simple(400,400,gtk.gdk.INTERP_BILINEAR)  
106            if nc > nr:
107                w = 400
108                h = 400 * nr / nc;
109            else:
110                h = 400
111                w = 400 * nr / nc;
112    
113            if h/nr > 16 or w/nc > 16:
114                h= nr*16
115                w= nc*16
116    
117            if nc < 200 and nr < 200:
118                pb1 = pb.scale_simple(w,h,gtk.gdk.INTERP_NEAREST)
119            else:
120                pb1 = pb.scale_simple(w,h,gtk.gdk.INTERP_BILINEAR)
121            
122          del pb;          del pb;
123    
124            print "DONE IMAGE PREPARATION"
125    
126          self.image.set_from_pixbuf(pb1)          self.image.set_from_pixbuf(pb1)
127    
128            print "DONE IMAGE TRANSFER TO SERVER"
129    
130          self.fill_var_names()          self.fill_var_names()
131          self.fill_rel_names()          self.fill_rel_names()
132    
# Line 117  class DiagnoseWindow: Line 172  class DiagnoseWindow:
172      def on_prevbutton_clicked(self,*args):      def on_prevbutton_clicked(self,*args):
173          self.set_block(self.block - 1)                self.set_block(self.block - 1)      
174    
175      def on_blockentry_changed(self,*args):      def on_blockentry_key_press_event(self,widget,event):
176          self.set_block( int(self.blockentry.get_text()) )          keyname = gtk.gdk.keyval_name(event.keyval)
177            print "KEY ",keyname
178            if keyname=="Return":
179                self.set_block( int(self.blockentry.get_text()) )
180    
181  # The following is from  # The following is from
182  # http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21719649.html  # http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21719649.html

Legend:
Removed from v.282  
changed lines
  Added in v.283

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