class GraphWindow(Toplevel): def __init__(self, parent=None, title=None, **kwargs): Toplevel.__init__(self, parent) if title != None: self.title(title) self.parent = parent self.paned_parent = PanedWindow(self) self.graph_frame = None if 'plot' in kwargs: if 'df' in kwargs: if 'plot_title' in kwargs: if 'y_label' in kwargs: self.graph_frame = GraphFrame(self, self.paned_parent, plot=kwargs['plot'], df=kwargs['df'], plot_title=kwargs['plot_title'], y_label=kwargs['y_label'], log_filename=kwargs['log_filename']) else: self.graph_frame = GraphFrame(self, self.paned_parent, plot=kwargs['plot'], df=kwargs['df'], plot_title=kwargs['plot_title'], log_filename=kwargs['log_filename']) else: self.graph_frame = GraphFrame(self, self.paned_parent, plot=kwargs['plot'], df=kwargs['df'], log_filename=kwargs['log_filename']) self.protocol('WM_DELETE_WINDOW', self.on_close) # NOTE: Keep the window from being resized because child widgets don't seem to fit properly #self.resizable(width=False, height=False) self.bind('<Configure>', self.on_resize) def set_grid(self): #self.grid() self.paned_parent.pack(expand=True, fill=Tkinter.BOTH) if self.graph_frame != None: self.graph_frame.set_grid() def unset_grid(self): #self.grid_forget() self.paned_parent.pack_forget() if self.graph_frame != None: self.graph_frame.unset_grid() def on_close(self): self.parent.notify_of_close(self) self.withdraw() self.destroy() def on_resize(self, event): #print 'In on_resize' if isinstance(event.widget, Toplevel): #print 'Resizing window' self.unset_grid() self.set_grid() self.update()
def initUI(self): self.parent.title("Simple") self.pack(fill=BOTH, expand=True) self.centerWindow() sw = self.parent.winfo_screenwidth() sh = self.parent.winfo_screenheight() frame1 = Frame(self, relief=RAISED, borderwidth=1) frame1.pack(fill=X) button1 = Button(frame1, text=u"<", command=self.prevDocument) button1.pack(side=LEFT, padx=5, pady=5) button2 = Button(frame1, text=u">", command=self.nextDocument) button2.pack(side=LEFT, padx=5, pady=5) self.selCategory = StringVar(self) self.categoryOption = OptionMenu(frame1, self.selCategory, *["Categories"], command=self.changeCategory) self.categoryOption.pack(side=LEFT, padx=5, pady=5) self.entry1 = Entry(frame1) self.entry1.pack(side=LEFT, padx=5, pady=5) self.ignoreActualDocVar = IntVar(self) checkButton1 = Checkbutton(frame1, text="Ignored", variable=self.ignoreActualDocVar) checkButton1.pack(side=LEFT, padx=5, pady=5) button3 = Button(frame1, text=u"Save document", command=self.prevDocument) button3.pack(side=LEFT, padx=5, pady=5) #entry1 = Entry(frame1) #entry1.pack(fill=X, padx=5, expand=True) frame2 = PanedWindow(self, orient=HORIZONTAL) frame2.pack(fill=BOTH, expand=1) self.txt1 = Text(frame2, width=sw/22) frame2.add(self.txt1) self.txt2 = Text(frame2) self.txt2.bind("<Button-3>", self.popup) frame2.add(self.txt2) frame3 = Frame(self, relief=RAISED, borderwidth=1) frame3.pack(fill=X) #lbl3 = Label(frame3, text="Author", width=6) #lbl3.pack(side=LEFT, padx=5, pady=5) #entry3 = Entry(frame3) #entry3.pack(fill=X, padx=5, expand=True) self.swVar = IntVar(self) checkButton1 = Checkbutton(frame3, text="Remove stop words", variable=self.swVar) checkButton1.pack(side=LEFT, padx=5, pady=5) self.lowerVar = IntVar(self) checkButton1 = Checkbutton(frame3, text="Convert to lower case", variable=self.lowerVar) checkButton1.pack(side=LEFT, padx=5, pady=5) button3 = Button(frame3, text=u"Apply", command=self.applyProcessing) button3.pack(side=LEFT, padx=5, pady=5) #self.readCorpus() # create a toplevel menu menubar = Menu(self) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label="Quit", command=self.parent.quit) filemenu.add_command(label="Open corpus", command=self.loadCorpus) menubar.add_cascade(label="Project", menu=filemenu) #menubar.add_command(label="Quit!") # , command=root.quit # display the menu self.parent.config(menu=menubar) self.popupmenu = Menu(self.parent, tearoff=0) self.popupmenu.add_command(label="Undo", command=self.hello) self.popupmenu.add_command(label="Redo", command=self.hello)