Commits

Matthew Turk committed bef0c4c

Some refactoring, made it work with multiple parameter files at once. Still
only slices along x, and some UI stuff still needs work.

Comments (0)

Files changed (2)

fisheye/main_window.py

-from numpy import arange, sin, pi
-from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
-from matplotlib.figure import Figure
-import matplotlib.colors
-
 import Tkinter as Tk
 import tkFileDialog
 import sys
 from yt.mods import *
 from yt.funcs import *
 
-import yt.extensions.image_panner as ip
+from vm_window import SliceFrame
 
 class MainWindow(object):
-    image = None
-    pf = None
-    pan_n_scan = 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)
+    def __init__(self, master):
+        self.pfs = []
 
-        self.button = Tk.Button(frame, text="Open", fg="red", command=self.setup_pf)
-        self.button.grid(row=0, column=1)
+        left_frame = Tk.Frame(master)
+        left_frame.grid(column = 0, row = 0)
+        right_frame = Tk.Frame(master)
+        right_frame.grid(column = 1, row = 0, columnspan = 2)
+        self.left_frame = left_frame
+        self.right_frame = right_frame
 
-        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.setup_scale_slider(master)
+        self.listbox = Tk.Listbox(left_frame, selectmode = Tk.SINGLE)
+        self.listbox.grid(row=0)
+        self.listbox.bind("<Double-Button-1>", self.click_on_listbox)
+        self.textarea = Tk.Text(left_frame, width=40)
+        self.textarea.grid(row=1)
+        self.image_frames = []
+        self.image_frame_widgets = []
 
-        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=1)
+        button_frame = Tk.Frame(self.left_frame)
+        button_frame.grid(row=2)
 
-        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=1)
+        button = Tk.Button(button_frame, text="Quit", fg="red", command=master.quit)
+        button.grid(row=0, column=0)
 
+        button = Tk.Button(button_frame, text="Open", fg="red", command=self.open_pf)
+        button.grid(row=0, column=1)
 
-        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.figure.canvas.mpl_connect("button_press_event", self.pick_event)
-        
-        self.canvas.draw()
-        self.full_domain()
-
-    def setup_scale_slider(self, master):
-        # This should use the controlvar
-        self.slider = Tk.Scale(from_ =-3.0, to = 0.0, command = self.set_zoom,
-                               orient = Tk.HORIZONTAL, resolution = 0.01,
-                               )
-        self.slider.set(0.0)
-        self.slider.grid(row=1, column=1, sticky = Tk.W + Tk.E + Tk.N + Tk.S)
-
-    def pick_event(self, event):
-        if event.inaxes is self.axes and event.key == "c":
-            # Now we re-center
-            xbounds = self.pan_n_scan.xlim
-            ybounds = self.pan_n_scan.ylim
-            width = self.pan_n_scan.width
-            size = self.pan_n_scan.size
-            dx, dy = (width[0] / size[0], width[1] / size[1])
-            px, py = event.xdata, event.ydata
-            # Our new center ...
-            ax = self.pan_n_scan.source.axis
-            self.center[x_dict[ax]] = px * dx + xbounds[0]
-            self.center[y_dict[ax]] = py * dy + ybounds[0]
-            print "Re-centering at %s" % (self.center)
-            self.recenter()
-
-    def recenter(self):
-        self.pan_n_scan.set_center(self.center)
-        self._update_from_pns()
-
-    @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
-
-    def setup_pf(self, pf = None):
+    def open_pf(self, pf = None):
         if pf is None:
             pf = tkFileDialog.askopenfilename(filetypes = [('enzo files', '.hierarchy'), ('all files', '.*')])
         if isinstance(pf, types.StringTypes):
             if pf.endswith(".hierarchy"): pf = pf[:-10]
             pf = load(pf)
             if pf is None: raise RuntimeError
-        self.pf = pf
-        v, c = pf.h.find_max("Density")
-        self.center = c
-        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.slider["from_"] = na.log10(self.pf.h.get_smallest_dx()*128)
-        if self.image is not None:
-            self._update_from_pns()
+        self.pfs.append(pf)
+        self.listbox.insert(Tk.END, str(pf))
+        new_frame = Tk.Frame(self.right_frame)
+        new_frame.grid(column = 0, row = 0)
+        self.image_frames.append(SliceFrame(new_frame, pf))
+        self.image_frame_widgets.append(new_frame)
+        new_frame.lift()
+        ns = len(self.pfs) - 1
+        self.listbox.selection_set(ns, ns)
+        
+    def click_on_listbox(self, event):
+        ii = int(self.listbox.curselection()[0])
+        print event, ii
+        self.image_frame_widgets[ii].lift()
 
-    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 set_zoom(self, val):
-        if self.pan_n_scan is None: return
-        self.pan_n_scan.set_width(10**float(val))
-        self._update_from_pns()
-
-    def zoom_2x(self):
-        self.pan_n_scan.zoom(2)
-        self._update_from_pns()
-
-    def zoom_2x_out(self):
-        self.pan_n_scan.zoom(0.5)
-        self._update_from_pns()
-
-    def zoom_10x(self):
-        self.pan_n_scan.zoom(10)
-        self._update_from_pns()
-
-    def zoom_10x_out(self):
-        self.pan_n_scan.zoom(.1)
-        self._update_from_pns()
-
-    def _update_from_pns(self):
-        buf = self.pan_n_scan.buffer
-        self.image.set_data(buf)
-        self.update_textarea(self.pan_n_scan.width, buf)
-        self.slider.set(na.log10(self.pan_n_scan.width[0]))
-        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()
-
-    def update_textarea(self, width, buf):
-        self.textarea.delete(1.0, Tk.END)
-        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()))
-        
 if __name__ == "__main__":
     root = Tk.Tk()
     root.wm_title("Fisheye")
+    print "Hi there"
     app = MainWindow(root)
     Tk.mainloop()

fisheye/vm_window.py

+from numpy import arange, sin, pi
+from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
+from matplotlib.figure import Figure
+import matplotlib.colors
+
+import Tkinter as Tk
+import tkFileDialog
+import sys
+
+from yt.mods import *
+from yt.funcs import *
+
+import yt.extensions.image_panner as ip
+
+class SliceFrame(object):
+    image = None
+    pf = None
+    pan_n_scan = None
+    def __init__(self, master, pf = None):
+        self.log_field = True
+        frame = Tk.Frame(master)
+        frame.grid(row=0, column=0)
+
+        # Set up our initial matplotlib figure
+
+        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.setup_scale_slider(master)
+
+        # Now our zoom buttons for navigation
+
+        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=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=1)
+
+
+        self.full_domain_button = Tk.Button(frame, text="Full Domain",
+                                             command=self.full_domain)
+        self.full_domain_button.grid(row=3, column=0)
+
+        # Status area
+
+        self.textarea = Tk.Text(frame, width=40)
+        self.textarea.grid(row=4, columnspan=2)
+
+        # At this point we need a parameter file to deal with
+
+        self.pf = pf
+        self.setup_slice()
+
+        # Create our MPL figure and set up an initial entry for it
+
+        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)
+
+        # Bind our 'pick' event
+        self.figure.canvas.mpl_connect("button_press_event", self.pick_event)
+        
+        self.canvas.draw()
+        self.full_domain()
+
+    def setup_scale_slider(self, master):
+        # This should use the controlvar
+        self.slider = Tk.Scale(master,
+                               from_ =-3.0, to = 0.0, command = self.set_zoom,
+                               orient = Tk.HORIZONTAL, resolution = 0.01,
+                               )
+        self.slider.set(0.0)
+        self.slider.grid(row=1, column=1, sticky = Tk.W + Tk.E + Tk.N + Tk.S)
+
+    def pick_event(self, event):
+        if event.inaxes is self.axes and event.key == "c":
+            # Now we re-center
+            xbounds = self.pan_n_scan.xlim
+            ybounds = self.pan_n_scan.ylim
+            width = self.pan_n_scan.width
+            size = self.pan_n_scan.size
+            dx, dy = (width[0] / size[0], width[1] / size[1])
+            px, py = event.xdata, event.ydata
+            # Our new center ...
+            ax = self.pan_n_scan.source.axis
+            self.center[x_dict[ax]] = px * dx + xbounds[0]
+            self.center[y_dict[ax]] = py * dy + ybounds[0]
+            print "Re-centering at %s" % (self.center)
+            self.recenter()
+
+    def recenter(self):
+        self.pan_n_scan.set_center(self.center)
+        self._update_from_pns()
+
+    @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
+
+    def setup_slice(self):
+        v, c = self.pf.h.find_max("Density")
+        self.center = c
+        sl = self.pf.h.slice(0, c[0], "Density", center=c)
+        self.pan_n_scan = self.pf.h.image_panner(sl, (512,512), "Density")
+        self.pan_n_scan.set_center(c)
+        self.slider["from_"] = na.log10(self.pf.h.get_smallest_dx()*128)
+        if self.image is not None:
+            self._update_from_pns()
+
+    def setup_proj(self):
+        pass
+
+    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 set_zoom(self, val):
+        if self.pan_n_scan is None: return
+        self.pan_n_scan.set_width(10**float(val))
+        self._update_from_pns()
+
+    def zoom_2x(self):
+        self.pan_n_scan.zoom(2)
+        self._update_from_pns()
+
+    def zoom_2x_out(self):
+        self.pan_n_scan.zoom(0.5)
+        self._update_from_pns()
+
+    def zoom_10x(self):
+        self.pan_n_scan.zoom(10)
+        self._update_from_pns()
+
+    def zoom_10x_out(self):
+        self.pan_n_scan.zoom(.1)
+        self._update_from_pns()
+
+    def _update_from_pns(self):
+        buf = self.pan_n_scan.buffer
+        self.image.set_data(buf)
+        self.update_textarea(self.pan_n_scan.width, buf)
+        self.slider.set(na.log10(self.pan_n_scan.width[0]))
+        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()
+
+    def update_textarea(self, width, buf):
+        self.textarea.delete(1.0, Tk.END)
+        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()))
+        
+if __name__ == "__main__":
+    root = Tk.Tk()
+    root.wm_title("Fisheye")
+    app = MainWindow(root)
+    Tk.mainloop()