def __init__(self, root, container, title, window_type): if root: self.root = root else: if Tk_._default_root: self.root = Tk_._default_root else: self.root = IPythonTkRoot(window_type = window_type) self.root.withdraw() if container: self.window = container else: self.window = Tk_.Toplevel(master = root, class_='snappy') self.window.protocol("WM_DELETE_WINDOW", self.close) self.window.title(title)
def _get_root(window_type): if Tk_._default_root: return Tk_._default_root root = IPythonTkRoot(window_type = window_type) root.withdraw() return root
def __init__(self, manifold, root=None): if manifold.num_tetrahedra() == 0: raise ValueError('The empty Manifold cannot be browsed.') self.manifold = manifold #self.identifier = Identifier() self.aka_after_id = None self.main_window = main_window self.symmetry_group = None self.dirichlet = [] self.cusp_nbhd = None self.length_spectrum = [] self.recompute_invariants = True if Tk_._default_root: self.root = root = Tk_._default_root else: self.root = root = IPythonTkRoot(window_type='Browser') root.withdraw() self.style = style = SnapPyStyle() self.window = window = Tk_.Toplevel(root, class_='snappy') if isinstance(root, IPythonTkRoot): self.window.withdraw() # Avoid showing an empty root window on the screen. self.root.after(100, self.window.deiconify) window.title(manifold.name()) window.config(bg=style.groupBG) window.protocol("WM_DELETE_WINDOW", self.close) if sys.platform == 'darwin': window.bind_all('<Command-Key-w>', self.close) elif sys.platform == 'linux2' or sys.platform == 'linux': window.bind_all('<Alt-Key-F4>', self.close) self.side_panel = side_panel = self.build_side_panel() self.notebook = notebook = ttk.Notebook(window) self.invariants_tab = invariants_tab = self.build_invariants() self.dirichlet_viewer = DirichletTab(facedicts=[], root=window, parent=window) self.horoball_viewer = CuspNeighborhoodTab(nbhd=None, root=window, parent=window) self.fillings_changed_callback = None self.bottombar = bottombar = ttk.Frame(window, height=20) bg = self.style.ttk_style.lookup('TLable', 'background') fg = self.style.ttk_style.lookup('TLable', 'foreground') self.modeline = modeline = Tk_.Text(self.bottombar, height=1, relief=Tk_.FLAT, background=bg, foreground=fg, selectborderwidth=0, highlightbackground=bg, highlightcolor=bg, highlightthickness=0, takefocus=False, state=Tk_.DISABLED) self.modeline.tag_config('alert', foreground='red') self.inside_view = None self.symmetry_tab = symmetry_tab = self.build_symmetry() self.link_tab = link_tab = self.build_link() notebook.add(invariants_tab, text='Invariants', padding=[0]) notebook.add(self.dirichlet_viewer.container, text='Dirichlet') notebook.add(self.horoball_viewer.container, text='Cusp Nbhds') notebook.add(self.build_inside_view(), text='Inside view') notebook.add(symmetry_tab, text='Symmetry', padding=[0]) if link_tab: notebook.add(link_tab.canvas, text='Link') notebook.bind('<<NotebookTabChanged>>', self.update_current_tab) self.build_menus() self.window.config(menu=self.menubar) window.grid_columnconfigure(1, weight=1) window.grid_rowconfigure(0, weight=1) side_panel.grid(row=0, column=0, sticky=Tk_.NSEW, padx=0, pady=0) notebook.grid(row=0, column=1, sticky=Tk_.NSEW, padx=0, pady=0, ipady=5) bottombar.grid(row=1, columnspan=2, sticky=Tk_.NSEW) self.modeline.pack(fill=Tk_.BOTH, expand=True, padx=30) self.update_modeline()
def __init__(self, nbhd, which_cusp=0, cutoff=None, root=None, title='Horoball Viewer', prefs={'cusp_horoballs' : True, 'cusp_triangulation' : True, 'cusp_ford_domain' : True, 'cusp_labels' : True, 'cusp_parallelogram' : True, 'cusp_cutoff' : '0.1000'}, container=None, bgcolor=None): self.nbhd = nbhd self.empty = (self.nbhd is None) self.mouse_x = 0 self.mouse_y = 0 self.menubar = None if cutoff is None: self.cutoff = float(prefs['cusp_cutoff']) else: self.cutoff = float(cutoff) self.which_cusp = which_cusp self.moving_cusp = 0 self.cusp_moving = False self.last_slider_value = None self.busy_drawing = False self.title = title if root is None: if Tk_._default_root: self.root = root = Tk_._default_root else: self.root = root = IPythonTkRoot(window_type='HoroballViewer') root.withdraw() self.style = style = SnapPyStyle() self.bgcolor = bgcolor if bgcolor else style.groupBG if container: self.window = window = container else: self.window = window = Tk_.Toplevel(master=root, class_='snappy') window.withdraw() window.protocol("WM_DELETE_WINDOW", self.close) window.title(title) self.pgram_var = pgram_var = Tk_.IntVar( window, value=prefs['cusp_parallelogram']) self.Ford_var = Ford_var = Tk_.IntVar( window, value=prefs['cusp_ford_domain']) self.tri_var = tri_var = Tk_.IntVar( window, value=prefs['cusp_triangulation']) self.horo_var = horo_var = Tk_.IntVar( window, value=prefs['cusp_horoballs']) self.label_var = label_var = Tk_.IntVar( window, value=prefs['cusp_labels']) self.flip_var = flip_var = Tk_.BooleanVar(window) window.columnconfigure(0, weight=1) window.rowconfigure(1, weight=1) self.top_frame = top_frame = ttk.Frame(window) top_frame.columnconfigure(1, weight=1) self.bottomframe = bottomframe = ttk.Frame(window) self.widget = widget = OpenGLOrthoWidget(master=bottomframe, width=600, height=500, fovy=3.0, depth=1, double=True, swapinterval=0, help = """ Use the mouse to drag the scene relative to the fundamental parallelogram. Use the sliders to adjust the sizes of the horoballs. Color coding indicates who bumps whom. To change the cutoff size, enter a number in the box and hit return. Cusps which are "tied" change size in unison. To view the scene from outside of the upper half-space, check the "Flip" checkbutton. Use the View Options to select which components of the scene are drawn. """) widget.bind('<ButtonPress-1>', self.click) widget.bind('<B1-Motion>', self.translate) if self.horo_var.get(): widget.set_background(0.3, 0.3, 0.4) else: widget.set_background(1.0,1.0,1.0) widget.autospin_allowed = 0 cyglSetStandardLighting() option_frame= ttk.Frame(top_frame) view_button = ttk.Menubutton(option_frame, text='View Options') self.view_menu = view_menu = Tk_.Menu(view_button, tearoff=0) view_menu.add_checkbutton(label='parallelogram', command=self.view_check, variable=self.pgram_var) view_menu.add_checkbutton(label='Ford edges', command=self.view_check, variable=self.Ford_var) view_menu.add_checkbutton(label='triangulation', command=self.view_check, variable=self.tri_var) view_menu.add_checkbutton(label='horoballs', command=self.view_check, variable=self.horo_var) view_menu.add_checkbutton(label='labels', command=self.view_check, variable=self.label_var) view_button.config(menu=view_menu) view_button.grid(row=0, column=0, columnspan=2, sticky=Tk_.W, padx=0, pady=0) flip_button = ttk.Checkbutton(option_frame, text='Flip', variable = self.flip_var, takefocus=False, command=self.flip) flip_button.grid(row=1, column=0, sticky=Tk_.W, padx=0, pady=0) self.cutoff_label = ttk.Label(option_frame, text='Cutoff: ') self.cutoff_var = cutoff_var = Tk_.StringVar( window, value='%.4f'%self.cutoff) self.cutoff_entry = ttk.Entry(option_frame, width=6, takefocus=False, textvariable=cutoff_var) self.cutoff_entry.bind('<Return>', self.set_cutoff) self.cutoff_label.grid_forget() self.cutoff_entry.grid_forget() self.cutoff_label.grid(row=2, column=0, sticky=Tk_.EW) self.cutoff_entry.grid(row=2, column=1, sticky=Tk_.W, padx=(0,20), pady=2) self.slider_frame = slider_frame = ttk.Frame(top_frame) self.eye_label = ttk.Label(slider_frame, text='Eye') self.tie_label = ttk.Label(slider_frame, text='Tie') if self.nbhd and self.nbhd.num_cusps() > 1: self.eye_label.grid(row=0, column=0, sticky=Tk_.W, pady=0) self.tie_label.grid(row=0, column=1, sticky=Tk_.W, pady=0) ttk.Label(slider_frame, text='Cusp Position').grid( row=0, column=2, pady=0) ttk.Label(slider_frame, text='Volume').grid( row=0, column=3, pady=0, padx=0, sticky=Tk_.W) self.eye_var = Tk_.IntVar(self.window, value=self.which_cusp) self.cusp_sliders = [] self.slider_frames = [] self.tie_vars = [] self.tie_buttons = [] self.eye_buttons = [] self.volume_labels = [] slider_frame.grid_columnconfigure(0, weight=1) slider_frame.grid_columnconfigure(2, minsize=370, weight=0) self.build_sliders() option_frame.grid(row=0, column=0, padx=(10,5), pady=5) slider_frame.grid(row=0, column=1, padx=5, pady=(5,10)) top_frame.grid(row=0, column=0, sticky=Tk_.NSEW, padx=0, pady=0) zoomframe = ttk.Frame(bottomframe) self.zoom = zoom = ttk.Scale(zoomframe, from_=100, to=0, orient=Tk_.VERTICAL, command=self.set_zoom) zoom.set(30) zoom.pack(side=Tk_.TOP, expand=Tk_.YES, fill=Tk_.Y) bottomframe.columnconfigure(0, weight=1) bottomframe.rowconfigure(0, weight=1) widget.grid(row=0, column=0, sticky=Tk_.NSEW) zoomframe.grid(row=0, column=1, sticky=Tk_.NS) bottomframe.grid(row=1, column=0, sticky=Tk_.NSEW) self.build_menus() self.scene = HoroballScene(nbhd, pgram_var, Ford_var, tri_var, horo_var, label_var, flipped=self.flip_var.get(), cutoff=self.cutoff, which_cusp=self.which_cusp) self.widget.redraw_impl = self.scene.draw if container is None: window.config(menu=self.menubar) window.deiconify() # Keep IPython from displaying the window prematurely. window.after(20, self.configure_sliders) else: self.configure_sliders()
def __init__(self, facedicts, root=None, title='Polyhedron Viewer', container=None, bgcolor=None): self.empty = (len(facedicts) == 0) self.title = title if root is None: if Tk_._default_root: self.root = root = Tk_._default_root else: self.root = root = IPythonTkRoot( window_type='PolyhedronViewer') root.withdraw() self.style = style = SnapPyStyle() self.bgcolor = bgcolor if bgcolor else self.style.windowBG if container: self.window = window = container else: self.window = window = Tk_.Toplevel(master=root, class_='snappy') window.withdraw() window.title(title) window.protocol("WM_DELETE_WINDOW", self.close) self.menubar = None self.topframe = topframe = ttk.Frame(window) self.bottomframe = bottomframe = ttk.Frame(window) self.model_var = Tk_.StringVar(self.window, value='Klein') self.sphere_var = Tk_.IntVar(self.window, value=1) self.klein = ttk.Radiobutton(topframe, text='Klein', variable=self.model_var, value='Klein', command=self.new_model) self.poincare = ttk.Radiobutton(topframe, text='Poincaré', variable=self.model_var, value='Poincare', command=self.new_model) self.sphere = ttk.Checkbutton(topframe, text='', variable=self.sphere_var, command=self.new_model) self.spherelabel = spherelabel = Tk_.Text(topframe, height=1, width=3, relief=Tk_.FLAT, font=self.style.font, borderwidth=0, highlightthickness=0, background=self.bgcolor) spherelabel.tag_config("sub", offset=-4) spherelabel.insert(Tk_.END, 'S') spherelabel.insert(Tk_.END, '∞', 'sub') spherelabel.config(state=Tk_.DISABLED) if sys.platform == 'darwin': if container: spherelabel.configure(background=self.style.groupBG) else: spherelabel.configure(background=self.style.windowBG) self.klein.grid(row=0, column=0, sticky=Tk_.W, padx=20, pady=(2, 6)) self.poincare.grid(row=0, column=1, sticky=Tk_.W, padx=20, pady=(2, 6)) self.sphere.grid(row=0, column=2, sticky=Tk_.W, padx=0, pady=(2, 6)) spherelabel.grid(row=0, column=3, sticky=Tk_.NW) topframe.pack(side=Tk_.TOP, fill=Tk_.X) self.widget = widget = OpenGLPerspectiveWidget(master=bottomframe, width=600, height=500, double=1, depth=1, help=""" Use mouse button 1 to rotate the polyhedron. Releasing the button while moving will "throw" the polyhedron and make it keep spinning. The slider controls zooming. You will see inside the polyhedron if you zoom far enough. """) widget.set_eyepoint(5.0) cyglSetStandardLighting() self.polyhedron = HyperbolicPolyhedron(facedicts, self.model_var, self.sphere_var) widget.redraw_impl = self.polyhedron.draw widget.autospin_allowed = 1 widget.set_background(.2, .2, .2) widget.grid(row=0, column=0, sticky=Tk_.NSEW) zoomframe = ttk.Frame(bottomframe) self.zoom = zoom = ttk.Scale(zoomframe, from_=100, to=0, orient=Tk_.VERTICAL, command=self.set_zoom) zoom.set(50) zoom.pack(side=Tk_.TOP, expand=Tk_.YES, fill=Tk_.Y) bottomframe.columnconfigure(0, weight=1) bottomframe.rowconfigure(0, weight=1) zoomframe.grid(row=0, column=1, sticky=Tk_.NS) bottomframe.pack(side=Tk_.TOP, expand=Tk_.YES, fill=Tk_.BOTH) self.build_menus() if container is None: if self.menubar: self.window.config(menu=self.menubar) window.deiconify() self.add_help() # Added to avoid occasional missing faces in the browser. window.update_idletasks()