Commits

Matthew Turk committed 7a2c2d5

Initial pass at separating plot creation from parameter file selection. Still
needs axis support and correct OptionMenu implementation.

Comments (0)

Files changed (3)

fisheye/main_window.py

 from yt.mods import *
 from yt.funcs import *
 
-from vm_window import SliceFrame
+from parameter_file_frame import ParameterFileFrame
 
 class MainWindow(object):
 
     def __init__(self, master):
         self.pfs = []
 
-        left_frame = Tk.Frame(master)
+        left_frame = Tk.Frame(master, bd=2, relief=Tk.GROOVE)
         left_frame.grid(column = 0, row = 0)
-        right_frame = Tk.Frame(master)
+        right_frame = Tk.Frame(master, bd=2, relief=Tk.GROOVE)
         right_frame.grid(column = 1, row = 0, columnspan = 2)
         self.left_frame = left_frame
         self.right_frame = right_frame
         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.pf_frames = []
+        self.pf_frame_widgets = []
 
-        button_frame = Tk.Frame(self.left_frame)
+        button_frame = Tk.Frame(self.left_frame, bd=2, relief=Tk.GROOVE)
         button_frame.grid(row=2)
 
         button = Tk.Button(button_frame, text="Quit", fg="red", command=master.quit)
         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)
+        self.pf_frames.append(ParameterFileFrame(new_frame, pf, self.textarea))
+        self.pf_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):
+        print self.listbox.curselection(),
         ii = int(self.listbox.curselection()[0])
         print event, ii
         self.image_frame_widgets[ii].lift()
+        self.image_frames[ii]._update_from_pns()
 
 if __name__ == "__main__":
     root = Tk.Tk()
     root.wm_title("Fisheye")
-    print "Hi there"
     app = MainWindow(root)
     Tk.mainloop()

fisheye/parameter_file_frame.py

+import Tkinter as Tk
+import tkFileDialog
+import sys, types
+
+from yt.mods import *
+from yt.funcs import *
+
+import yt.extensions.image_panner as ip
+
+from vm_window import SliceFrame
+
+class ActivePlot(Tk.StringVar):
+    def __init__(self, *args, **kwargs):
+        self.pf_frame = kwargs.pop("pf_frame")
+        Tk.StringVar.__init__(self, *args, **kwargs)
+
+    def set(self, *args, **kwargs):
+        Tk.StringVar(self, *args, **kwargs)
+        self.pf_frame.set_plot(self.get())
+
+class ParameterFileFrame(object):
+    plot_list = None
+    def __init__(self, master, pf, textarea):
+        self.pf = pf
+        self.textarea = textarea
+        frame = Tk.Frame(master, bd = 2, relief=Tk.GROOVE)
+        frame.grid(column = 0, row = 0)
+        self.plot_frames = []
+        self.plot_frame_widgets = []
+        # Add our buttons
+        button_frame = Tk.Frame(frame, bd=2, relief=Tk.GROOVE)
+        button_frame.grid(row=0)
+        self.plot_frame = Tk.Frame(frame, bd=2, relief=Tk.GROOVE)
+        self.plot_frame.grid(row=1)
+
+        slice_x = Tk.Button(button_frame, text = "Slice X",
+                            command = self.slice_x)
+        slice_y = Tk.Button(button_frame, text = "Slice Y",
+                            command = self.slice_y)
+        slice_z = Tk.Button(button_frame, text = "Slice Z",
+                            command = self.slice_z)
+        for i,b in enumerate([slice_x, slice_y, slice_z]):
+            b.grid(row = 0, column = i)
+
+        proj_x = Tk.Button(button_frame, text = "Proj X",
+                            command = self.proj_x)
+        proj_y = Tk.Button(button_frame, text = "Proj Y",
+                            command = self.proj_y)
+        proj_z = Tk.Button(button_frame, text = "Proj Z",
+                            command = self.proj_z)
+        for i,b in enumerate([proj_x, proj_y, proj_z]):
+            b.grid(row = 1, column = i)
+
+    def recreate_plot_list(self):
+        if self.plot_list is not None: self.plot_list.destroy()
+        option_list = ["%s - %s" % (i, plot) for i, plot in
+                        enumerate(self.plot_frames)]
+        self.current_plot = Tk.StringVar()
+        if self.active_plot >= 0:
+            self.current_plot.set(option_list[self.active_plot])
+        self.plot_list = Tk.OptionMenu()
+
+    def set_plot(self, plot_id):
+        if isinstance(plot_id, types.StringTypes):
+            plot_id = int(plot_id.split(" - ", 1)[0])
+        self.plot_frames[plot_id].lift()
+
+    def add_plot_frame(self, plot_frame):
+        self.plot_frames.append(plot_frame)
+        self.active_plot = len(self.plot_frames) - 1
+        self.recreate_plot_list()
+        # Now we just need to bring our plot to the front
+
+    def slice_x(self):
+        print "slice x"
+        # Make the widget, add the frame
+        new_frame = Tk.Frame(self.plot_frame)
+        self.plot_frame_widgets.append(new_frame)
+        new_frame.grid(column = 0, row = 0)
+        new_plot = SliceFrame(new_frame, self.pf, self.textarea)
+        self.add_plot_frame(new_plot)
+        
+    def slice_y(self):
+        print "slice y"
+
+    def slice_z(self):
+        print "slice z"
+
+    def proj_x(self):
+        print "proj x"
+
+    def proj_y(self):
+        print "proj y"
+
+    def proj_z(self):
+        print "proj z"

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
     image = None
     pf = None
     pan_n_scan = None
-    def __init__(self, master, pf = None):
+    name = "Slice - x"
+    def __init__(self, master, pf, textarea):
         self.log_field = True
-        frame = Tk.Frame(master)
+        frame = Tk.Frame(master, bd = 2, relief=Tk.GROOVE)
         frame.grid(row=0, column=0)
 
         # Set up our initial matplotlib figure
 
         # Status area
 
-        self.textarea = Tk.Text(frame, width=40)
-        self.textarea.grid(row=4, columnspan=2)
+        self.textarea = textarea
 
         # At this point we need a parameter file to deal with
 
         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()