Commits

Matthew Turk committed aef8ed0

Adding full domain button, re-arranged some autoscale info, moved some buttons around, made it work better for switching between outputs, and made the text area widget a bit smaller.

Comments (0)

Files changed (1)

simple_pan_scan.py

 import yt.extensions.image_panner as ip
 
 class SimpleWindow(object):
+    image = None
     def __init__(self, master, pf = None):
+        self.log_field = True
         frame = Tk.Frame(master)
         frame.grid(row=0, column=0)
 
+        self.button = Tk.Button(frame, text="Quit", fg="red", command=frame.quit)
+        self.button.grid(row=0, column=0)
+
+        self.button = Tk.Button(frame, text="Open", fg="red", command=self.setup_pf)
+        self.button.grid(row=0, column=1)
+
         self.figure = Figure(figsize=(5,4), dpi=100)
+        self.figure.subplots_adjust(hspace=0, wspace=0, bottom=0.0,
+                                    top=1.0, left=0.0, right=1.0)
         self.canvas = FigureCanvasTkAgg(self.figure, master=master)
         self.canvas.show()
         self.canvas.get_tk_widget().grid(row=0, column=1)
 
+        self.zoom_10x_button = Tk.Button(frame, text="Zoom2x", command=self.zoom_2x)
+        self.zoom_10x_button.grid(row=1, column=0)
         self.zoom_10x_out_button = Tk.Button(frame, text="ZoomOut2x",
                                              command=self.zoom_2x_out)
-        self.zoom_10x_out_button.grid(row=1, column=0)
-        self.zoom_10x_button = Tk.Button(frame, text="Zoom2x", command=self.zoom_2x)
-        self.zoom_10x_button.grid(row=1, column=1)
+        self.zoom_10x_out_button.grid(row=1, column=1)
 
+        self.zoom_10x_button = Tk.Button(frame, text="Zoom10x", command=self.zoom_10x)
+        self.zoom_10x_button.grid(row=2, column=0)
         self.zoom_10x_out_button = Tk.Button(frame, text="ZoomOut10x",
                                              command=self.zoom_10x_out)
-        self.zoom_10x_out_button.grid(row=2, column=0)
-        self.zoom_10x_button = Tk.Button(frame, text="Zoom10x", command=self.zoom_10x)
-        self.zoom_10x_button.grid(row=2, column=1)
+        self.zoom_10x_out_button.grid(row=2, column=1)
 
-        self.textarea = Tk.Text(frame)
-        self.textarea.grid(row=3, columnspan=2)
+
+        self.full_domain_button = Tk.Button(frame, text="Full Domain",
+                                             command=self.full_domain)
+        self.full_domain_button.grid(row=3, column=0)
+
+        self.textarea = Tk.Text(frame, width=40)
+        self.textarea.grid(row=4, columnspan=2)
 
         self.setup_pf(pf)
 
         self.axes = self.figure.add_subplot(111)
         self.norm = matplotlib.colors.LogNorm()
+        self.norm.autoscale(self.current_limits)
         self.image = self.axes.imshow(self.pan_n_scan.buffer, interpolation='nearest',
                               origin='lower', norm = self.norm)
+        self.axes.set_xticks(())
+        self.axes.set_yticks(())
+        self.axes.set_ylabel("")
+        self.axes.set_xlabel("")
         self.colorbar = self.figure.colorbar(self.image)
         
-        self.button = Tk.Button(frame, text="QUIT", fg="red", command=frame.quit)
-        self.button.grid(row=0, columnspan=2)
+        self.canvas.draw()
+        self.full_domain()
 
-        self.canvas.draw()
+    @property
+    def current_limits(self):
+        buf = self.pan_n_scan.buffer
+        if self.log_field:
+            mi = buf[buf > 0.0].min()
+            ma = buf[buf > 0.0].max()
+        else:
+            mi, ma = buf.min(), buf.max()
+        return mi, ma
 
-        # a tk.DrawingArea
-
-    def setup_pf(self, pf):
+    def setup_pf(self, pf = None):
         if pf is None:
             pf = tkFileDialog.askopenfilename(filetypes = [('enzo files', '.hierarchy'), ('all files', '.*')])
         if isinstance(pf, types.StringTypes):
         sl = pf.h.slice(0, c[0], "Density", center=c)
         self.pan_n_scan = pf.h.image_panner(sl, (512,512), "Density")
         self.pan_n_scan.set_center(c)
-        self.pan_n_scan.zoom(2.0)
+        if self.image is not None:
+            self._update_from_pns()
+
+    def full_domain(self):
+        DLE, DRE = self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]
+        ax = self.pan_n_scan.source.axis
+        xlim = DLE[x_dict[ax]], DRE[x_dict[ax]]
+        ylim = DLE[y_dict[ax]], DRE[y_dict[ax]]
+        self.pan_n_scan.set_limits(xlim, ylim)
+        self.pan_n_scan.set_center(self.center)
+        self._update_from_pns()
 
     def zoom_2x(self):
         self.pan_n_scan.zoom(2)
         buf = self.pan_n_scan.buffer
         self.image.set_data(buf)
         self.update_textarea(self.pan_n_scan.width, buf)
-        print "Autoscaling:", buf.min(), buf.max()
-        self.norm.autoscale((buf.min(), buf.max()))
+        mi, ma = self.current_limits
+        print "Autoscaling:", mi, ma
+        self.norm.autoscale((mi, ma))
         self.image.set_norm(self.norm)
         self.colorbar.update_bruteforce(self.image)
         self.canvas.draw()
         self.textarea.insert(Tk.END, "Width set to %0.3e by %0.3e\n" % (width))
         self.textarea.insert(Tk.END, "Limits:      %0.3e to %0.3e\n" % (buf.min(), buf.max()))
         
-
-def destroy(e): sys.exit()
-
-pf = load("/Users/matthewturk/Research/data/DataDump0155.dir/DataDump0155")
-
 root = Tk.Tk()
-#root.wm_title("Embedding in TK")
+root.wm_title("Fisheye")
 app = SimpleWindow(root)
 Tk.mainloop()