Source

fisheye / fisheye / main_window.py

Full commit
import Tkinter as Tk
import tkFileDialog
import sys

from yt.mods import *
from yt.funcs import *

from parameter_file_frame import ParameterFileFrame

class MainWindow(object):

    def __init__(self, master):
        self.pfs = []

        left_frame = Tk.Frame(master, bd=2, relief=Tk.GROOVE)
        left_frame.grid(column = 0, row = 0)
        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 = 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.pf_frames = []
        self.pf_frame_widgets = []

        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)
        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)

    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.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.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.pf_frame_widgets[ii].lift()
        self.pf_frames[ii]._update_from_pns()

if __name__ == "__main__":
    root = Tk.Tk()
    root.wm_title("Fisheye")
    app = MainWindow(root)
    Tk.mainloop()