Matthew Turk committed e826414

Adding Scale bar for sliding and zooming

Comments (0)

Files changed (1)

 import Tkinter as Tk
 import tkFileDialog
 import sys
 from yt.mods import *
+from yt.funcs import *
 import yt.extensions.image_panner as ip
 class SimpleWindow(object):
     image = None
+    pf = None
+    pan_n_scan = None
     def __init__(self, master, pf = None):
         self.log_field = True
         frame = Tk.Frame(master)
         self.canvas = FigureCanvasTkAgg(self.figure, master=master)
         self.canvas.get_tk_widget().grid(row=0, column=1)
+        self.setup_scale_slider(master)
         self.zoom_10x_button = Tk.Button(frame, text="Zoom2x", command=self.zoom_2x)
         self.zoom_10x_button.grid(row=1, column=0)
+    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
         sl = pf.h.slice(0, c[0], "Density", center=c)
         self.pan_n_scan = pf.h.image_panner(sl, (512,512), "Density")
+        self.slider["from_"] = na.log10(*128)
         if self.image is not None:
+    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):
         buf = self.pan_n_scan.buffer
         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))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.