def _setup_stack_frame_list(self): self.stack_frame = Frame(self.content) self.stack_frame.grid(column=0, row=0, sticky=(N, S, E, W)) self.file_notebook.add(self.stack_frame, text='Stack') self.stack = StackView(self.stack_frame, normalizer=self.filename_normalizer) self.stack.grid(column=0, row=0, sticky=(N, S, E, W)) # # The tree's vertical scrollbar self.stack_scrollbar = Scrollbar(self.stack_frame, orient=VERTICAL) self.stack_scrollbar.grid(column=1, row=0, sticky=(N, S)) # # Tie the scrollbar to the text views, and the text views # # to each other. self.stack.config(yscrollcommand=self.stack_scrollbar.set) self.stack_scrollbar.config(command=self.stack.yview) # Setup weights for the "stack" tree self.stack_frame.columnconfigure(0, weight=1) self.stack_frame.columnconfigure(1, weight=0) self.stack_frame.rowconfigure(0, weight=1) # Handlers for GUI events self.stack.bind('<<TreeviewSelect>>', self.on_stack_frame_selected)
def initUI(self): self.entries_found = [] self.parent.title("Search your command cards") self.style = Style() self.style.theme_use("default") self.pack() self.input_title = Label(self, text="Enter your command below") self.input_title.grid(row=0, columnspan=2) self.input_box = Entry(self, width=90) self.input_box.grid(row=1, column=0) self.input_box.focus() self.input_box.bind("<Key>", self.onUpdateSearch) self.search_btn = Button(self, text="Search", command=self.onSearch) self.search_btn.grid(row=1, column=1) self.output_box = Treeview(self, columns=("Example")) ysb = Scrollbar(self, orient='vertical', command=self.output_box.yview) xsb = Scrollbar(self, orient='horizontal', command=self.output_box.xview) self.output_box.configure(yscroll=ysb.set, xscroll=xsb.set) self.output_box.heading('Example', text='Example', anchor='w') self.output_box.column("#0", minwidth=0, width=0, stretch=NO) self.output_box.column("Example", minwidth=0, width=785) self.output_box.bind("<Button-1>", self.OnEntryClick) self.output_box.grid(row=3, columnspan=2) self.selected_box = Text(self, width=110, height=19) self.selected_box.grid(row=4, columnspan=2) self.gotoadd_btn = Button(self, text="Go to Add", command=self.onGoToAdd) self.gotoadd_btn.grid(row=5)
def __init__(self, master, **kwargs): Frame.__init__(self, master) textarea_frame = Frame(self, bd=1, relief=SOLID,**kwargs) textarea_frame.pack(fill=X) textarea_frame.pack_propagate(False) self.textarea = Text(textarea_frame, height=1, pady=self.TAG_ENTRY_PADY, padx=self.TAG_ENTRY_PADX, highlightthickness =0, spacing1=0, spacing2=0, spacing3=0, borderwidth=0, wrap="none") self.textarea.pack(expand=True, fill=BOTH, padx=2) scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.textarea.xview) scrollbar.pack(fill=X) self.textarea.configure(xscrollcommand=scrollbar.set) self.textarea.bind("<KeyPress>",self._on_keypress) tag = Tag(self.textarea, "") self.textarea.window_create("1.0", window=tag) self.update_idletasks() tag_reqheight = tag.winfo_reqheight() textarea_frame.configure(height=tag_reqheight + 2*self.TAG_ENTRY_PADY+2*self.textarea["borderwidth"]) # I add a hidden frame because I want the cursor centered including when there is no tag self.textarea.window_create("1.0", window=Frame(self.textarea, height=tag_reqheight, width=0, borderwidth=0)) tag.destroy()
def _setup_breakpoint_list(self): self.breakpoints_frame = Frame(self.content) self.breakpoints_frame.grid(column=0, row=0, sticky=(N, S, E, W)) self.file_notebook.add(self.breakpoints_frame, text='Breakpoints') self.breakpoints = BreakpointView(self.breakpoints_frame, normalizer=self.filename_normalizer) self.breakpoints.grid(column=0, row=0, sticky=(N, S, E, W)) # The tree's vertical scrollbar self.breakpoints_scrollbar = Scrollbar(self.breakpoints_frame, orient=VERTICAL) self.breakpoints_scrollbar.grid(column=1, row=0, sticky=(N, S)) # Tie the scrollbar to the text views, and the text views # to each other. self.breakpoints.config(yscrollcommand=self.breakpoints_scrollbar.set) self.breakpoints_scrollbar.config(command=self.breakpoints.yview) # Setup weights for the "breakpoint list" tree self.breakpoints_frame.columnconfigure(0, weight=1) self.breakpoints_frame.columnconfigure(1, weight=0) self.breakpoints_frame.rowconfigure(0, weight=1) # Handlers for GUI events self.breakpoints.tag_bind('breakpoint', '<Double-Button-1>', self.on_breakpoint_double_clicked) self.breakpoints.tag_bind('breakpoint', '<<TreeviewSelect>>', self.on_breakpoint_selected) self.breakpoints.tag_bind('file', '<<TreeviewSelect>>', self.on_breakpoint_file_selected)
def _make_rcv_log(self): # make receive log recvLogFrame = Frame(self, width=400, height=200) recvLogFrame.style = self.style recvLogFrame.grid(row=2, column=0, padx=2, pady=2, sticky=N + S + E + W) self.start_stop_button = Button(self, text="Stop", command=self.start_stop_clicked) self.start_stop_button.style = self.style self.start_stop_button.grid(row=2, column=1, padx=2, pady=2, sticky=N + S + E + W) # make a scrollbar self.scrollbar = Scrollbar(recvLogFrame) self.scrollbar.pack(side=RIGHT, fill=Y) # make a text box to put the serial output self.log = Text(recvLogFrame, width=50, height=30, takefocus=0, borderwidth=1, relief='ridge') self.log.pack(fill=BOTH, expand=True) # attach text box to scrollbar self.log.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.log.yview)
class ScrolledCanvas(Frame): """ A scrolling canvas of frames with checkboxes. """ def __init__(self, master, name=None, scrollregion=(0, 0, '5i', '5i'), items=[], window_size=[160, 30], **canvaskw): Frame.__init__(self, master, name=name) self.scrollcanvas = Canvas(self, name='scrollcanvas', scrollregion=scrollregion, **canvaskw) self.yscroll = Scrollbar(self, name='yscroll', command=self.scrollcanvas.yview) self.scrollcanvas['yscrollcommand'] = self.yscroll.set self.yscroll.pack(side=RIGHT, fill=Y) self.scrollcanvas.pack(side=LEFT, fill=BOTH, expand=YES) self.items = dict.fromkeys(items) for n, i in enumerate(items): self.items[i] = {'frame': Frame(self, name=(i.lower() + '_frame'))} self.items[i]['frame'].config(relief=GROOVE, padding=5) self.items[i]['chbx'] = Checkbutton(self.items[i]['frame'], name=(i.lower() + '_chbx')) self.items[i]['chbx']['text'] = i self.items[i]['chbx'].pack(side=LEFT, fill=X) y = window_size[1] / 2 + window_size[1] * n self.items[i]['window'] = self.scrollcanvas.create_window(0, y) self.scrollcanvas.itemconfigure(self.items[i]['window'], window=self.items[i]['frame'], anchor=W, width=window_size[0], height=window_size[1])
def _scrolled_text_display(title='Diagnil Text Display', intro=None, button_proc=null_proc, tab_stops=(), return_frame=0): fr = Toplevel() fr.geometry(newGeometry='-0+50') if intro: Label(fr, text=intro).pack(padx=10, pady=10) txt_fr = Frame(fr) if on_win: txt = Text(txt_fr, width=70, padx=10, pady=5, wrap=WORD, tabs=tab_stops) else: txt = Text(txt_fr, width=70, padx=10, pady=5, wrap=WORD, background=text_bg_color, tabs=tab_stops) scroll = Scrollbar(txt_fr, command=txt.yview) txt.configure(yscrollcommand=scroll.set) wrapped_bind(fr, '<Key-Prior>', lambda event: txt.yview_scroll(-1, PAGES)) wrapped_bind(fr, '<Key-Next>', lambda event: txt.yview_scroll(1, PAGES)) wrapped_bind(fr, '<Enter>', lambda event: fr.focus_set()) txt.pack(side=LEFT, fill=BOTH, expand=YES) scroll.pack(side=LEFT, fill=Y) txt_fr.pack(padx=5, pady=5, fill=BOTH, expand=YES) button_proc(fr) fr.title(string=title) if return_frame: return fr, txt else: return txt
def __init__(self, master, widget_class, attributes=None, scrollbar=None): """ master is the parent widget widget_class is the class, like Text or Listbox attributes are attributes for the widget scrollbar are attributes for the scrollbar """ if attributes is None: attributes = [] if scrollbar is None: scrollbar = [] self.master = master # Parent frame to hold the widget + scrollbar self.frame = Frame(master) # The scrollbar self.scrollbar = Scrollbar(self.frame, **scrollbar) # The widget itself self.widget = widget_class(self.frame, yscrollcommand=self.scrollbar.set, **attributes) self.scrollbar.configure(command=self.widget.yview) self.scrollbar.pack(side="right", fill="y") self.widget.pack(side="right", fill="both", expand=1)
def __init__(self, master, **kwargs): Frame.__init__(self, master) textarea_frame = Frame(self, bd=1, relief=SOLID, **kwargs) textarea_frame.pack(fill=X) textarea_frame.pack_propagate(False) self.textarea = Text(textarea_frame, height=1, pady=self.TAG_ENTRY_PADY, padx=self.TAG_ENTRY_PADX, highlightthickness=0, spacing1=0, spacing2=0, spacing3=0, borderwidth=0, wrap="none") self.textarea.pack(expand=True, fill=BOTH, padx=2) scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.textarea.xview) scrollbar.pack(fill=X) self.textarea.configure(xscrollcommand=scrollbar.set) self.textarea.bind("<KeyPress>", self._on_keypress) tag = Tag(self.textarea, "") self.textarea.window_create("1.0", window=tag) self.update_idletasks() tag_reqheight = tag.winfo_reqheight() textarea_frame.configure(height=tag_reqheight + 2 * self.TAG_ENTRY_PADY + 2 * self.textarea["borderwidth"]) # I add a hidden frame because I want the cursor centered including when there is no tag self.textarea.window_create("1.0", window=Frame(self.textarea, height=tag_reqheight, width=0, borderwidth=0)) tag.destroy()
def __init__(self, master, data=None, ascending_order=True, ignore_case=False, autoscroll=False, vscrollbar=True, hscrollbar=False, scrollbar_background=None, scrollbar_troughcolor=None, **kwargs): Frame.__init__(self, master) self._ignore_case = ignore_case self._ascending_order = ascending_order master.grid_rowconfigure(0, weight=1) master.grid_columnconfigure(0, weight=1) self._listbox = Listbox(self, *kwargs) self._listbox.grid(row=0, column=0, sticky=N + E + W + S) scrollbar_kwargs = {} if scrollbar_background is not None: scrollbar_kwargs["background"] = scrollbar_background if scrollbar_troughcolor is not None: scrollbar_kwargs["throughcolor"] = scrollbar_troughcolor if vscrollbar: self._vbar = Scrollbar(self, takefocus=0, command=self._listbox.yview, **scrollbar_kwargs) self._vbar.grid(row=0, column=1, sticky=N + S) if autoscroll: self._listbox.config(yscrollcommand=lambda f, l: make_autoscroll(self._vbar, f, l)) else: self._listbox.config(yscrollcommand=self._vbar.set) if hscrollbar: self._hbar = Scrollbar(self, takefocus=0, command=self._listbox.xview, **scrollbar_kwargs) self._hbar.grid(row=0, column=1, sticky=E + W) if autoscroll: self._listbox.config(xscrollcommand=lambda f, l: make_autoscroll(self._hbar, f, l)) else: self._listbox.config(xscrollcommand=self._hbar.set) if data is not None: for item in data: self.add_item(item)
def __init__(self, parent, **kwargs): """! A constructor for the class @param self The pointer for the object @param parent The parent object for the frame @param **kwargs Other arguments as accepted by ttk.Scrollbar """ #Initialise the inherited class Scrollbar.__init__(self, parent, **kwargs)
def __init__(self, master, width=None, height=None, mousewheel_speed=2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw): super(Scrolling_Area, self).__init__(master, **kw) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._clipper = Frame(self, background=outer_background, width=width, height=height) self._clipper.grid(row=0, column=0, sticky=N + E + W + S) self._width = width self._height = height self.innerframe = inner_frame(self._clipper, padx=0, pady=0, highlightthickness=0) self.innerframe.place(in_=self._clipper, x=0, y=0) if scroll_vertically: if yscrollbar is not None: self.yscrollbar = yscrollbar else: self.yscrollbar = Scrollbar(self, orient=VERTICAL) self.yscrollbar.grid(row=0, column=1, sticky=N + S) self.yscrollbar.set(0.0, 1.0) self.yscrollbar.config(command=self.yview) else: self.yscrollbar = None self._scroll_vertically = scroll_vertically if scroll_horizontally: if xscrollbar is not None: self.xscrollbar = xscrollbar else: self.xscrollbar = Scrollbar(self, orient=HORIZONTAL) self.xscrollbar.grid(row=1, column=0, sticky=E + W) self.xscrollbar.set(0.0, 1.0) self.xscrollbar.config(command=self.xview) else: self.xscrollbar = None self._scroll_horizontally = scroll_horizontally self._jfraction = 0.05 self._startX = 0 self._startY = 0 # Whenever the clipping window or scrolled frame change size, # update the scrollbars. self.innerframe.bind('<Configure>', self._on_configure) self._clipper.bind('<Configure>', self._on_configure) self.innerframe.xview = self.xview self.innerframe.yview = self.yview Mousewheel_Support(self).add_support_to(self.innerframe, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
def consolePanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth=5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column=0, row=1) self.scrollbar = Scrollbar(tmpFrm) self.scrollbar.pack(side=RIGHT, fill=Y) self.log = Text(tmpFrm, wrap=WORD, yscrollcommand=self.scrollbar.set) self.log.pack() self.scrollbar.config(command=self.log.yview)
def __init__(self, master, width=None, height=None, mousewheel_speed = 2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw): super(Scrolling_Area, self).__init__(master, **kw) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._clipper = Frame(self, background=outer_background, width=width, height=height) self._clipper.grid(row=0, column=0, sticky=N+E+W+S) self._width = width self._height = height self.innerframe = inner_frame(self._clipper, padx=0, pady=0, highlightthickness=0) self.innerframe.place(in_=self._clipper, x=0, y=0) if scroll_vertically: if yscrollbar is not None: self.yscrollbar = yscrollbar else: self.yscrollbar = Scrollbar(self, orient=VERTICAL) self.yscrollbar.grid(row=0, column=1,sticky=N+S) self.yscrollbar.set(0.0, 1.0) self.yscrollbar.config(command=self.yview) else: self.yscrollbar = None self._scroll_vertically = scroll_vertically if scroll_horizontally: if xscrollbar is not None: self.xscrollbar = xscrollbar else: self.xscrollbar = Scrollbar(self, orient=HORIZONTAL) self.xscrollbar.grid(row=1, column=0, sticky=E+W) self.xscrollbar.set(0.0, 1.0) self.xscrollbar.config(command=self.xview) else: self.xscrollbar = None self._scroll_horizontally = scroll_horizontally self._jfraction=0.05 self._startX = 0 self._startY = 0 # Whenever the clipping window or scrolled frame change size, # update the scrollbars. self.innerframe.bind('<Configure>', self._on_configure) self._clipper.bind('<Configure>', self._on_configure) self.innerframe.xview = self.xview self.innerframe.yview = self.yview Mousewheel_Support(self).add_support_to(self.innerframe, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
def set(self, lo, hi): if float(lo) <= 0.0 and float(hi) >= 1.0: # grid_remove is currently missing from Tkinter! # self.tk.call("grid", "remove", self) # print('removed') self.grid_remove() else: # print('added') self.grid() Scrollbar.set(self, lo, hi)
def __init__(self, master): Frame.__init__(self, master) scrollbar = Scrollbar(self, orient=VERTICAL) scrollbar.pack(side=RIGHT, fill=Y) self.canvas = Canvas(self, bd=0, highlightthickness=0, yscrollcommand=scrollbar.set) self.canvas.pack(side=LEFT, fill=BOTH, expand=1) scrollbar.config(command=self.canvas.yview) self.mainframe = Frame(self.canvas) self.mainframe_id = self.canvas.create_window((0, 0), window=self.mainframe, anchor=NW) self.mainframe.bind('<Configure>', self.config_mainframe) self.canvas.bind('<Configure>', self.config_canvas)
def __init__(self, root): Frame.__init__(self, root) self.canvas = ResizingCanvas(self, borderwidth=0) self.frame = Frame(self.canvas) self.vsb = Scrollbar( self, orient="vertical", command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y") self.canvas.pack(side="left", fill="both", expand=True) self.canvas.create_window( (4, 4), window=self.frame, anchor="nw", tags="self.frame") self.frame.bind("<Configure>", self.OnFrameConfigure)
def __init__(self, master, width=None, anchor=N, height=None, mousewheel_speed=2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw): Frame.__init__(self, master, class_=self.__class__) if outer_background: self.configure(background=outer_background) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._width = width self._height = height self.canvas = Canvas(self, background=outer_background, highlightthickness=0, width=width, height=height) self.canvas.grid(row=0, column=0, sticky=N + E + W + S) if scroll_vertically: if yscrollbar is not None: self.yscrollbar = yscrollbar else: self.yscrollbar = Scrollbar(self, orient=VERTICAL) self.yscrollbar.grid(row=0, column=1, sticky=N + S) self.canvas.configure(yscrollcommand=self.yscrollbar.set) self.yscrollbar['command'] = self.canvas.yview else: self.yscrollbar = None if scroll_horizontally: if xscrollbar is not None: self.xscrollbar = xscrollbar else: self.xscrollbar = Scrollbar(self, orient=HORIZONTAL) self.xscrollbar.grid(row=1, column=0, sticky=E + W) self.canvas.configure(xscrollcommand=self.xscrollbar.set) self.xscrollbar['command'] = self.canvas.xview else: self.xscrollbar = None self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.innerframe = inner_frame(self.canvas, **kw) self.innerframe.pack(anchor=anchor) self.canvas.create_window(0, 0, window=self.innerframe, anchor='nw', tags="inner_frame") self.canvas.bind('<Configure>', self._on_canvas_configure) Mousewheel_Support(self).add_support_to(self.canvas, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
def __init__(self, master, xml=None, heading_text=None, heading_anchor=None, padding=None, cursor=None, takefocus=None, style=None): Frame.__init__(self, master, class_="XML_Viwer") self._vsb = Scrollbar(self, orient=VERTICAL) self._hsb = Scrollbar(self, orient=HORIZONTAL) kwargs = {} kwargs["yscrollcommand"] = lambda f, l: autoscroll(self._vsb, f, l) kwargs["xscrollcommand"] = lambda f, l: autoscroll(self._hsb, f, l) if style is not None: kwargs["style"] = style if padding is not None: kwargs["padding"] = padding if cursor is not None: kwargs["cursor"] = cursor if takefocus is not None: kwargs["takefocus"] = takefocus self._treeview = Treeview(self, **kwargs) if heading_text is not None: if heading_anchor is not None: self._treeview.heading("#0", text=heading_text, anchor=heading_anchor) else: self._treeview.heading("#0", text=heading_text) self._treeview.bind("<<TreeviewOpen>>", self._on_open) self._treeview.bind("<<TreeviewClose>>", self._on_close) # Without this line, horizontal scrolling doesn't work properly. self._treeview.column("#0", stretch= False) self._vsb['command'] = self._treeview.yview self._hsb['command'] = self._treeview.xview self._treeview.grid(column=0, row=0, sticky=N+S+W+E) self._vsb.grid(column=1, row=0, sticky=N+S) self._hsb.grid(column=0, row=1, sticky=E+W) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._element_tree = None self._item_ID_to_element = {} if xml is not None: self.parse_xml(xml)
class Scrolled(object): """My own implementation for adding a scrollbar to a widget. Similar in principal to Python's ScrolledText module, but it works on other widgets too (this script uses it on Listbox too). So it's more like the Perl/Tk module Tk::Scrolled in that it can wrap any widget, in theory.""" def __init__(self, master, widget_class, attributes=None, scrollbar=None): """ master is the parent widget widget_class is the class, like Text or Listbox attributes are attributes for the widget scrollbar are attributes for the scrollbar """ if attributes is None: attributes = [] if scrollbar is None: scrollbar = [] self.master = master # Parent frame to hold the widget + scrollbar self.frame = Frame(master) # The scrollbar self.scrollbar = Scrollbar(self.frame, **scrollbar) # The widget itself self.widget = widget_class(self.frame, yscrollcommand=self.scrollbar.set, **attributes) self.scrollbar.configure(command=self.widget.yview) self.scrollbar.pack(side="right", fill="y") self.widget.pack(side="right", fill="both", expand=1) def widget(self): """Get at the inner widget.""" return self.widget def scrollbar(self): """Get at the scrollbar widget.""" return self.scrollbar def getSelectedIndex(self): return self.widget.curselection() def get(self, index): return str((self.widget.get(index))) def pack(self, **kwargs): """Wrapper so that pack() works as you'd expect.""" self.frame.pack(**kwargs)
def init_ui(self): self.rowconfigure(3, weight=1) self.columnconfigure(0, weight=1) self.button_load_type = Button(self, text="Load Type JSON", command=lambda: browse_file(self, 1, )) self.button_load_type.grid( row=0, columnspan=2, sticky=W + E, pady=4, padx=5) self.button_load_color = Button( self, text="Load Color JSON", command=lambda: browse_file(self, 2)) self.button_load_color.grid( row=1, columnspan=2, sticky=W + E, pady=4, padx=5) button_load = Button( self, text="Load Images", command=lambda: browse_images(self)) button_load.grid(row=2, columnspan=2, sticky=W + E, pady=4, padx=5) button_learn = Button( self, text="Test", command= lambda: start_testing(self.dtype, self.dcolor, self.picture_frames) ) button_learn.grid(row=4, columnspan=2, sticky=W + E, pady=4, padx=5) canvas = Canvas(self) canvas.grid(row=3, sticky=W + E + N + S, column=0, pady=4, padx=5) frame = self.picture_frame = Frame(canvas) canvas.create_window(0, 0, window=frame, anchor='nw') scroll_bar = Scrollbar(self, orient="vertical", command=canvas.yview) scroll_bar.grid(sticky=E + N + S, padx=5, row=3, column=1) canvas.configure(yscrollcommand=scroll_bar.set) # track changes to the canvas and frame width and sync them, # also updating the scrollbar def _configure_interior(event): # update the scrollbars to match the size of the inner frame size = (frame.winfo_reqwidth(), frame.winfo_reqheight()) canvas.config(scrollregion="0 0 %s %s" % size) if frame.winfo_reqwidth() != canvas.winfo_width(): # update the canvas's width to fit the inner frame canvas.config(width=frame.winfo_reqwidth()) frame.bind('<Configure>', _configure_interior) def _configure_canvas(event): if frame.winfo_reqwidth() != canvas.winfo_width(): # update the inner frame's width to fill the canvas canvas.itemconfigure(frame, width=canvas.winfo_width()) canvas.bind('<Configure>', _configure_canvas)
def __init__(self, master, width=None, anchor=N, height=None, mousewheel_speed = 2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw): Frame.__init__(self, master, class_=self.__class__) if outer_background: self.configure(background=outer_background) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._width = width self._height = height self.canvas = Canvas(self, background=outer_background, highlightthickness=0, width=width, height=height) self.canvas.grid(row=0, column=0, sticky=N+E+W+S) if scroll_vertically: if yscrollbar is not None: self.yscrollbar = yscrollbar else: self.yscrollbar = Scrollbar(self, orient=VERTICAL) self.yscrollbar.grid(row=0, column=1,sticky=N+S) self.canvas.configure(yscrollcommand=self.yscrollbar.set) self.yscrollbar['command']=self.canvas.yview else: self.yscrollbar = None if scroll_horizontally: if xscrollbar is not None: self.xscrollbar = xscrollbar else: self.xscrollbar = Scrollbar(self, orient=HORIZONTAL) self.xscrollbar.grid(row=1, column=0, sticky=E+W) self.canvas.configure(xscrollcommand=self.xscrollbar.set) self.xscrollbar['command']=self.canvas.xview else: self.xscrollbar = None self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.innerframe = inner_frame(self.canvas, **kw) self.innerframe.pack(anchor=anchor) self.canvas.create_window(0, 0, window=self.innerframe, anchor='nw', tags="inner_frame") self.canvas.bind('<Configure>', self._on_canvas_configure) Mousewheel_Support(self).add_support_to(self.canvas, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
def __init__(self, master, headers, data, name=None): Frame.__init__(self, master, name=name) #: column headers self.headers = headers #: table data self.data = data #: :class:`~ttk.Treeview` that only shows "headings" not "tree columns" self.tree = Treeview(self, columns=self.headers, show="headings", name='tabletree') #: vertical scrollbar self.yscroll = Scrollbar(self, orient="vertical", command=self.tree.yview, name='table_yscroll') #: horizontal scrollbar self.xscroll = Scrollbar(self, orient="horizontal", command=self.tree.xview, name='table_xscroll') self.tree['yscrollcommand'] = self.yscroll.set # bind to scrollbars self.tree['xscrollcommand'] = self.xscroll.set # position widgets and set resize behavior self.tree.grid(column=0, row=0, sticky=(N + E + W + S)) self.yscroll.grid(column=1, row=0, sticky=(N + S)) self.xscroll.grid(column=0, row=1, sticky=(E + W)) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) # build tree for col in self.headers: # NOTE: Use col as column identifiers, crafty! # NOTE: Also change col to title case using str.title() # NOTE: make lambda behave nicely in a loop using default arg! callback = lambda c=col: self.sortby(c, False) self.tree.heading(col, text=col.title(), command=callback) # adjust the column's width to the header string self.tree.column(col, width=tkFont.Font().measure(col.title())) # insert a new top-level treeview item by suing an empty string for item in self.data: self.tree.insert('', END, values=item) # adjust column's width if necessary to fit each value for idx, val in enumerate(item): col_width = tkFont.Font().measure(val) # option can be specified at least 3 ways: as (a) width=None, # (b) option='width' or (c) 'width', where 'width' can be any # valid column option. if self.tree.column(self.headers[idx], 'width') < col_width: self.tree.column(self.headers[idx], width=col_width)
class Panle: def __init__(self, master): self.frame = Frame(master) self.frame.pack(side=TOP) self.label = Tkinter.Label(self.frame, text='wordEcho') self.label.pack() self.input = Entry(self.frame, width=45) self.input.pack(side=LEFT) self.button = Button(self.frame, text='翻译') self.button.pack(side=RIGHT) self.frame2 = Scrollbar(master) self.frame2.pack(side=TOP) self.ms = Message(self.frame2, anchor='w', width=150) self.ms.pack()
def whois(self, addr=None): if not addr: addr = self._remote_addr addr = addr.split(':') try: reverse = subprocess.check_output(['dig', '+short', '-x', addr[0]]) except: reverse = None try: out = subprocess.check_output(['whois', addr[0]]) except: out = 'No info for this host.' self.whois_popup = {} self.whois_popup['window'] = tk.Toplevel(self) self.whois_popup['window'].title('Whois %s' % addr[0]) self.whois_popup['frame'] = tk.Frame(self.whois_popup['window']) self.whois_popup['frame'].pack(fill=tk.BOTH, expand=tk.Y) self.whois_popup['text'] = tk.Text(self.whois_popup['frame'], wrap=tk.WORD, height=32, width=96) self.whois_popup['text'].pack(fill=tk.BOTH, expand=tk.Y, side=tk.LEFT) self.whois_popup['scrollbar_y'] = Scrollbar(self.whois_popup['frame']) self.whois_popup['scrollbar_y'].config(command=self.whois_popup['text'].yview) self.whois_popup['scrollbar_y'].pack(side=tk.RIGHT, fill=tk.Y) self.whois_popup['text'].config(yscrollcommand=self.whois_popup['scrollbar_y'].set) if reverse: reverse = 'Reverse lookup: %s\n' % reverse self.whois_popup['text'].insert(tk.END, reverse) self.whois_popup['text'].insert(tk.END, out) tk.Button(self.whois_popup['window'], text='Ok', command=self.whois_popup['window'].destroy).pack()
def initUI(self): self.columnconfigure(0, weight=0) self.columnconfigure(1, weight=0) self.columnconfigure(2, weight=1) self.columnconfigure(3, weight=1) self.rowconfigure(0, weight=1) self.commandFrame = Frame(self, background="white") self.commandFrame.grid(row=0, column=0, columnspan=5, sticky=W+E) self.commandFrame.columnconfigure(1, weight=1) self.btnCommand = Button(self.commandFrame, text="Run") self.btnCommand.grid(row=0, column=0) self.strCommand = StringVar() self.entCommand = Entry(self.commandFrame, textvariable=self.strCommand) self.entCommand.grid(row=0, column=1, sticky=W+E) self.lstMacro = Listbox(self) self.lstMacro.grid(row=1, column=0, sticky=N+S+W+E) self.treeview = Treeview(self, columns=("Angle"), displaycolumns="#all", selectmode="browse") self.treeview.grid(row=1, column=1, columnspan=4, sticky=N+S+W+E) self.treeScrollbar = Scrollbar(self) self.treeScrollbar.grid(row=1, column=5, sticky=N+S) self.treeview.config(yscrollcommand=self.treeScrollbar.set) self.treeScrollbar.config(command=self.treeview.yview) self.btnFrame = Frame(self, background="white") self.btnFrame.grid(row=2, column=0, columnspan=5, sticky=W+E) self.btnRun = Button(self.btnFrame, text="Run", command=self.runMacro) self.btnRun.grid(row=0, column=0) self.btnStop = Button(self.btnFrame, text="Stop") self.btnStop.grid(row=0, column=1) self.btnSaveMacro = Button(self.btnFrame, text="Save Macro", command=self.saveMacro) self.btnSaveMacro.grid(row=0, column=2) self.btnDeleteMacro = Button(self.btnFrame, text="Delete Macro") self.btnDeleteMacro.grid(row=0, column=3) self.btnDeleteState = Button(self.btnFrame, text="Delete State") self.btnDeleteState.grid(row=0, column=4)
def consolePanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth = 5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column = 0, row = 1) self.scrollbar = Scrollbar(tmpFrm) self.scrollbar.pack(side=RIGHT, fill=Y) self.log = Text(tmpFrm, wrap=WORD, yscrollcommand=self.scrollbar.set) self.log.pack() self.scrollbar.config(command=self.log.yview)
def initUI(self): self.parent.title("Text Field") self.pack(fill=BOTH, expand=True) frame1 = Frame(self, width=50, height=25) frame1.pack(fill=X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side="right", fill=Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2, text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X)
def __init__(self,parent,caller,**args): Frame.__init__(self,parent,**args) self.pack(side=TOP) self.canvas = Canvas(self,scrollregion=(0,0,1000,1000) ,background='white',cursor='pencil') self.canvas.bind("<Button-1>",lambda event:caller.clickCell(event,1)) self.canvas.bind("<B1-Motion>",lambda event:caller.clickCell(event,1)) self.canvas.bind("<Control-Button-1>",lambda event:caller.clickCell(event,-1)) self.canvas.bind("<Control-B1-Motion>",lambda event:caller.clickCell(event,-1)) vScroll = Scrollbar(self, orient = VERTICAL) vScroll.pack(side = RIGHT, fill=Y) vScroll.config(command = self.canvas.yview) hScroll = Scrollbar(self, orient = HORIZONTAL) hScroll.pack(side = BOTTOM, fill=X) hScroll.config(command = self.canvas.xview) self.canvas.config(xscrollcommand = hScroll.set, yscrollcommand = vScroll.set) self.canvas.pack(side=LEFT)
def __init__(self, parent=None, **kwargs): Frame.__init__(self, parent) self.parent = parent self.job_list_yscroll = Scrollbar(self, orient=Tkinter.VERTICAL) self.job_list_xscroll = Scrollbar(self, orient=Tkinter.HORIZONTAL) self.job_list = Listbox(self, xscrollcommand=self.job_list_xscroll, yscrollcommand=self.job_list_yscroll) self.job_list_xscroll['command'] = self.job_list.xview self.job_list_yscroll['command'] = self.job_list.yview self.new_job_frame = Frame(self) add_icon_filename = kwargs['add_icon_filename'] if 'add_icon_filename' in kwargs else None if add_icon_filename == None: self.add_job_button = Button(self.new_job_frame, text='Add Job', command=self.on_add) else: add_icon = PhotoImage(file=add_icon_filename) self.add_job_button = Button(self.new_job_frame, text='Add Job', compound='bottom', image=add_icon, command=self.on_add) self.remove_job_button = Button(self.new_job_frame, text='Remove Job', command=self.on_remove) self.progress_frame = Frame(self) self.progress_value = Tkinter.IntVar() self.progress_bar = Progressbar(self.progress_frame, variable=self.progress_value) self.button_frame = Frame(self) self.process_button = ProcessButton(parent=self.button_frame, start_jobs=self.start_jobs) self.quit_button = QuitButton(parent=self.button_frame, close_other_windows=self.close_top_level_windows) self.run_job = kwargs['run_job'] if 'run_job' in kwargs else None self.create_plots = kwargs['create_plots'] if 'create_plots' in kwargs else None self.log_filename = kwargs['log_filename'] if 'log_filename' in kwargs else None self.bind('<<AskToClearJobs>>', self.ask_to_clear_jobs) self.bind('<<AskToPlotGraphs>>', self.ask_to_plot_graphs) self.bind('<<CreatePlotGUI>>', self.create_plot_gui) self.parent.bind('<ButtonPress>', self.on_press) self.parent.bind('<Configure>', self.on_resize) self.reinit_variables() self.top_level_windows = list() # NOTE: Because there seems to be an issue resizing child widgets when the top level (Tk) widget is being resized, # the resize option will be disabled for this window self.parent.resizable(width=False, height=False) self.lift()
class ScrollableFrame(Frame): def __init__(self, root): Frame.__init__(self, root) self.canvas = ResizingCanvas(self, borderwidth=0) self.frame = Frame(self.canvas) self.vsb = Scrollbar( self, orient="vertical", command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y") self.canvas.pack(side="left", fill="both", expand=True) self.canvas.create_window( (4, 4), window=self.frame, anchor="nw", tags="self.frame") self.frame.bind("<Configure>", self.OnFrameConfigure) def OnFrameConfigure(self, event): '''Reset the scroll region to encompass the inner frame''' # print "OnFrameConfigure" self.canvas.configure(scrollregion=self.canvas.bbox("all"))
def _init_ui(self): """ Composes the UI and associates the appropriate handler for the actions to catch. """ self._parent.title("Events") self._style = Style() self._style.theme_use("default") self.pack(fill=BOTH, expand=1) self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) label = Label(self, text="Actions") label.grid(sticky=W, pady=4, padx=5) self._text_area = self.ReadOnlyText(self) self._text_area.grid(row=1, column=0, columnspan=2, rowspan=4, padx=5, sticky=E + W + S + N) scrollbar = Scrollbar(self, command=self._text_area.yview) scrollbar.grid(row=1, column=2, rowspan=4, sticky=N + S) self._text_area['yscrollcommand'] = scrollbar.set start_button = Button(self, text="Start", command=self._rec_start) start_button.grid(row=1, column=3) stop_button = Button(self, text="Stop", command=self._rec_stop) stop_button.grid(row=2, column=3, pady=4) save_button = Button( self, text="Save", ) save_button.grid(row=5, column=3) quit_button = Button(self, text="Quit", command=self._exit) quit_button.grid(row=5, column=0, padx=5)
def __init__(self, master, data=None, ascending_order = True, ignore_case=False, autoscroll=False, vscrollbar=True, hscrollbar=False, scrollbar_background=None, scrollbar_troughcolor=None, **kwargs): Frame.__init__(self, master) self._ignore_case = ignore_case self._ascending_order = ascending_order master.grid_rowconfigure(0, weight=1) master.grid_columnconfigure(0, weight=1) self._listbox = Listbox(self, *kwargs) self._listbox.grid(row=0, column=0, sticky= N+E+W+S) scrollbar_kwargs = {} if scrollbar_background is not None: scrollbar_kwargs["background"] = scrollbar_background if scrollbar_troughcolor is not None: scrollbar_kwargs["throughcolor"] = scrollbar_troughcolor if vscrollbar: self._vbar=Scrollbar(self,takefocus=0, command=self._listbox.yview, **scrollbar_kwargs) self._vbar.grid(row=0, column=1, sticky= N+S) if autoscroll: self._listbox.config(yscrollcommand=lambda f, l: make_autoscroll(self._vbar, f, l)) else: self._listbox.config(yscrollcommand=self._vbar.set) if hscrollbar: self._hbar=Scrollbar(self,takefocus=0, command=self._listbox.xview, **scrollbar_kwargs) self._hbar.grid(row=0, column=1, sticky= E+W) if autoscroll: self._listbox.config(xscrollcommand=lambda f, l: make_autoscroll(self._hbar, f, l)) else: self._listbox.config(xscrollcommand=self._hbar.set) if data is not None: for item in data: self.add_item(item)
class TypingField(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.submit_tog = True self.initUI() self.text.bind_class("Text","<Control-a>", self.selectall) def initUI(self): self.parent.title("Text Field") self.pack(fill = BOTH, expand=True) frame1 = Frame(self, width = 50, height =25) frame1.pack(fill = X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side = "right", fill = Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2,text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X) def startPause(self, event): self.text.focus_set() if self.submit_tog: self.submit.configure(text = "Pause") else: self.submit.configure(text = "Start Test") self.submit_tog = not self.submit_tog def selectall(self, event): event.widget.tag_add("sel","1.0","end")
def __init__(self, master): """ Make a scrollable, resizeable text """ Frame.__init__(self, master) # Add a horizontal and vertical scroller self.hscroller = Scrollbar(self, orient=HORIZONTAL) self.vscroller = Scrollbar(self, orient=VERTICAL) # Make the text box self.text = Text(self, width=90, state=DISABLED, height=15, wrap=NONE, xscrollcommand=self.hscroller.set, yscrollcommand=self.vscroller.set) # Pack everything in there, nice and tight. Let the text expand and the # scroll bars lengthen, but do not let the scroll bars thicken. self.text.grid(column=0, row=0, sticky=N+S+E+W) self.hscroller.grid(column=0, row=1, sticky=N+S+E+W) self.vscroller.grid(column=1, row=0, sticky=N+S+E+W) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=0) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=0) # Now make the scroll bars actually work self.hscroller.configure(command=self.text.xview) self.vscroller.configure(command=self.text.yview)
class TypingField(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.submit_tog = True self.initUI() self.text.bind_class("Text", "<Control-a>", self.selectall) def initUI(self): self.parent.title("Text Field") self.pack(fill=BOTH, expand=True) frame1 = Frame(self, width=50, height=25) frame1.pack(fill=X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side="right", fill=Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2, text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X) def startPause(self, event): self.text.focus_set() if self.submit_tog: self.submit.configure(text="Pause") else: self.submit.configure(text="Start Test") self.submit_tog = not self.submit_tog def selectall(self, event): event.widget.tag_add("sel", "1.0", "end")
def __init__(self, master, mixer): Frame.__init__(self, master) scrollbar_h = Scrollbar(self, orient='horizontal') scrollbar_v = Scrollbar(self, orient='vertical') self.canvas = Canvas(self, background='gray', scrollregion=(0, 0, (3 + len(mixer) * FADER_WIDTH), FADER_HEIGHT), yscrollcommand=scrollbar_v.set, xscrollcommand=scrollbar_h.set) scrollbar_v.config(command=self.canvas.yview) scrollbar_h.config(command=self.canvas.xview) master.bind("<MouseWheel>", lambda e: self.canvas.yview_scroll(-e.delta, 'units')) master.bind("<Shift-MouseWheel>", lambda e: self.canvas.xview_scroll(-e.delta, 'units')) Sizegrip(self).grid(column=2, row=1, sticky='se') self.canvas.grid(column=0, row=0, sticky='nwes') scrollbar_h.grid(column=0, row=1, sticky='we') scrollbar_v.grid(column=1, row=0, sticky='sn') master_fader = AudioFader(self, mixer.getVolume, mixer.setVolume, "Master") master_fader.grid(column=2, row=0, sticky='nwes') self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) for i, channel in enumerate(mixer): if channel.device.id_variable is not None: name = channel.device.id_variable else: name = channel.device.name_id fader = AudioFader(self.canvas, channel.get_gain, channel.set_gain, name) self.canvas.create_window(i * FADER_WIDTH, 0, anchor='nw', window=fader)
def init_interface(self,root): #widget declarations self.searchbar = Entry(root,font=self.font,bg=self.col_bg,foreground=self.col_text) self.execute = Button(root,text="Get Trends",command=self.query) self.scrolltime = Scrollbar(root,orient=HORIZONTAL,command=self.temp) #self.scrolltime.config(command=self.output.yview) #gridding of widgets self.space = Canvas(root,width=self.width,height=self.height,bg=self.col_bg) self.space.grid(row=2,column=2,rowspan=4,columnspan=4,sticky=W+E+N+S) self.searchbar.grid(row=1,column=2,columnspan=3,sticky=W+E+N+S,padx=20,pady=20) self.execute.grid(row=1,column=5,sticky=W)#,sticky=W+E+N+S) self.scrolltime.grid(row=6,column=2,columnspan=4,sticky=W+E+N+S) self.draw_map()
class ScrolledText(Text): def __init__(self, master=None, **kw): self.frame = Frame(master) self.vbar = Scrollbar(self.frame) self.vbar.pack(side=RIGHT, fill=Y) kw.update({'yscrollcommand': self.vbar.set}) Text.__init__(self, self.frame, **kw) self.pack(side=LEFT, fill=BOTH, expand=True) self.vbar['command'] = self.yview # Copy geometry methods of self.frame without overriding Text # methods -- hack! text_meths = vars(Text).keys() methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys() methods = set(methods).difference(text_meths) for m in methods: if m[0] != '_' and m != 'config' and m != 'configure': setattr(self, m, getattr(self.frame, m)) def __str__(self): return str(self.frame)
def _setup_inspector(self): self.inspector_frame = Frame(self.content) self.inspector_frame.grid(column=2, row=0, sticky=(N, S, E, W)) self.inspector = InspectorView(self.inspector_frame) self.inspector.grid(column=0, row=0, sticky=(N, S, E, W)) # The tree's vertical scrollbar self.inspector_scrollbar = Scrollbar(self.inspector_frame, orient=VERTICAL) self.inspector_scrollbar.grid(column=1, row=0, sticky=(N, S)) # Tie the scrollbar to the text views, and the text views # to each other. self.inspector.config(yscrollcommand=self.inspector_scrollbar.set) self.inspector_scrollbar.config(command=self.inspector.yview) # Setup weights for the "breakpoint list" tree self.inspector_frame.columnconfigure(0, weight=1) self.inspector_frame.columnconfigure(1, weight=0) self.inspector_frame.rowconfigure(0, weight=1) self.content.add(self.inspector_frame)
def _init_ui(self): """ Composes the UI and associates the appropriate handler for the actions to catch. """ self._parent.title("Events") self._style = Style() self._style.theme_use("default") self.pack(fill=BOTH, expand=1) self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) label = Label(self, text="Actions") label.grid(sticky=W, pady=4, padx=5) self._text_area = self.ReadOnlyText(self) self._text_area.grid(row=1, column=0, columnspan=2, rowspan=4, padx=5, sticky=E+W+S+N) scrollbar = Scrollbar(self, command=self._text_area.yview) scrollbar.grid(row=1, column=2, rowspan=4, sticky=N+S) self._text_area['yscrollcommand'] = scrollbar.set start_button = Button(self, text="Start", command=self._rec_start) start_button.grid(row=1, column=3) stop_button = Button(self, text="Stop", command=self._rec_stop) stop_button.grid(row=2, column=3, pady=4) save_button = Button(self, text="Save",) save_button.grid(row=5, column=3) quit_button = Button(self, text="Quit", command=self._exit) quit_button.grid(row=5, column=0, padx=5)
def initUI(self): self.columnconfigure(0, weight=0) self.columnconfigure(1, weight=0) self.columnconfigure(2, weight=1) self.columnconfigure(3, weight=1) self.rowconfigure(0, weight=1) self.commandFrame = Frame(self, background="white") self.commandFrame.grid(row=0, column=0, columnspan=5, sticky=W + E) self.commandFrame.columnconfigure(1, weight=1) self.btnCommand = Button(self.commandFrame, text="Run") self.btnCommand.grid(row=0, column=0) self.strCommand = StringVar() self.entCommand = Entry(self.commandFrame, textvariable=self.strCommand) self.entCommand.grid(row=0, column=1, sticky=W + E) self.lstMacro = Listbox(self) self.lstMacro.grid(row=1, column=0, sticky=N + S + W + E) self.treeview = Treeview(self, columns=("Angle"), displaycolumns="#all", selectmode="browse") self.treeview.grid(row=1, column=1, columnspan=4, sticky=N + S + W + E) self.treeScrollbar = Scrollbar(self) self.treeScrollbar.grid(row=1, column=5, sticky=N + S) self.treeview.config(yscrollcommand=self.treeScrollbar.set) self.treeScrollbar.config(command=self.treeview.yview) self.btnFrame = Frame(self, background="white") self.btnFrame.grid(row=2, column=0, columnspan=5, sticky=W + E) self.btnRun = Button(self.btnFrame, text="Run", command=self.runMacro) self.btnRun.grid(row=0, column=0) self.btnStop = Button(self.btnFrame, text="Stop") self.btnStop.grid(row=0, column=1) self.btnSaveMacro = Button(self.btnFrame, text="Save Macro", command=self.saveMacro) self.btnSaveMacro.grid(row=0, column=2) self.btnDeleteMacro = Button(self.btnFrame, text="Delete Macro") self.btnDeleteMacro.grid(row=0, column=3) self.btnDeleteState = Button(self.btnFrame, text="Delete State") self.btnDeleteState.grid(row=0, column=4)
def _init_ui(self): # Load an image self.img = ImageTk.PhotoImage(Image.open(r"images\dna5.png")) # Define a canvas in a frame frame = Frame(self) c = Canvas(frame, bg="white", height=475, width=475) # Display the image in the canvas c.create_image(0, 0, image=self.img, anchor=NW) # Y-scrollbar yscrollbar = Scrollbar(frame, command=c.yview) c.configure(yscrollcommand=yscrollbar.set) # X-scrollbar xscrollbar = Scrollbar(frame, orient=HORIZONTAL, command=c.xview) c.configure(xscrollcommand=xscrollbar.set) # Display widgets using grid layout. frame.grid(row=0, column=0) yscrollbar.grid(row=0, column=2, sticky=S + N) xscrollbar.grid(row=2, column=0, sticky=W + E) c.grid(row=0, column=0) self.pack(fill=BOTH, expand=1)
def initUI(self): self.parent.title("Text Field") self.pack(fill = BOTH, expand=True) frame1 = Frame(self, width = 50, height =25) frame1.pack(fill = X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side = "right", fill = Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2,text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X)
class TextWindow(Frame): """ A basic, scrollable text window that can either be editable or not """ def __init__(self, master): """ Make a scrollable, resizeable text """ Frame.__init__(self, master) # Add a horizontal and vertical scroller self.hscroller = Scrollbar(self, orient=HORIZONTAL) self.vscroller = Scrollbar(self, orient=VERTICAL) # Make the text box self.text = Text(self, width=90, state=DISABLED, height=15, wrap=NONE, xscrollcommand=self.hscroller.set, yscrollcommand=self.vscroller.set) # Pack everything in there, nice and tight. Let the text expand and the # scroll bars lengthen, but do not let the scroll bars thicken. self.text.grid(column=0, row=0, sticky=N+S+E+W) self.hscroller.grid(column=0, row=1, sticky=N+S+E+W) self.vscroller.grid(column=1, row=0, sticky=N+S+E+W) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=0) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=0) # Now make the scroll bars actually work self.hscroller.configure(command=self.text.xview) self.vscroller.configure(command=self.text.yview) def write(self, s): """ Writes 's' to the window, such that it will emulate a file. We have to change the state to ACTIVE in order to add text, but then change it back to the original state afterwards """ self.text.configure(state=NORMAL) self.text.insert(END, s) self.text.configure(state=DISABLED) def clear(self, event=None): """ Clears all text from this window """ self.text.config(state=NORMAL) self.text.delete('0.0', END) self.text.config(state=DISABLED)
class Scrolling_Area(Frame, object): def __init__(self, master, width=None, height=None, mousewheel_speed=2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw): super(Scrolling_Area, self).__init__(master, **kw) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._clipper = Frame(self, background=outer_background, width=width, height=height) self._clipper.grid(row=0, column=0, sticky=N + E + W + S) self._width = width self._height = height self.innerframe = inner_frame(self._clipper, padx=0, pady=0, highlightthickness=0) self.innerframe.place(in_=self._clipper, x=0, y=0) if scroll_vertically: if yscrollbar is not None: self.yscrollbar = yscrollbar else: self.yscrollbar = Scrollbar(self, orient=VERTICAL) self.yscrollbar.grid(row=0, column=1, sticky=N + S) self.yscrollbar.set(0.0, 1.0) self.yscrollbar.config(command=self.yview) else: self.yscrollbar = None self._scroll_vertically = scroll_vertically if scroll_horizontally: if xscrollbar is not None: self.xscrollbar = xscrollbar else: self.xscrollbar = Scrollbar(self, orient=HORIZONTAL) self.xscrollbar.grid(row=1, column=0, sticky=E + W) self.xscrollbar.set(0.0, 1.0) self.xscrollbar.config(command=self.xview) else: self.xscrollbar = None self._scroll_horizontally = scroll_horizontally self._jfraction = 0.05 self._startX = 0 self._startY = 0 # Whenever the clipping window or scrolled frame change size, # update the scrollbars. self.innerframe.bind('<Configure>', self._on_configure) self._clipper.bind('<Configure>', self._on_configure) self.innerframe.xview = self.xview self.innerframe.yview = self.yview Mousewheel_Support(self).add_support_to(self.innerframe, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar) def update_viewport(self): # compute new height and width self.update() frameHeight = float(self.innerframe.winfo_reqheight()) frameWidth = float(self.innerframe.winfo_reqwidth()) if self._width is not None: width = min(self._width, frameWidth) else: width = self._frameWidth if self._height is not None: height = min(self._height, frameHeight) else: height = self._frameHeight self._clipper.configure(width=width, height=height) def _on_configure(self, event): self._frameHeight = float(self.innerframe.winfo_reqheight()) self._frameWidth = float(self.innerframe.winfo_reqwidth()) # resize the visible part if self._scroll_horizontally: self.xview("scroll", 0, "unit") if self._scroll_vertically: self.yview("scroll", 0, "unit") def xview(self, mode=None, value=None, units=None): value = float(value) clipperWidth = self._clipper.winfo_width() frameWidth = self._frameWidth _startX = self._startX if mode is None: return self.xscrollbar.get() elif mode == 'moveto': # absolute movement self._startX = int(value * frameWidth) else: # mode == 'scroll' # relative movement if units == 'units': jump = int(clipperWidth * self._jfraction) else: jump = clipperWidth self._startX = self._startX + value * jump if frameWidth <= clipperWidth: # The scrolled frame is smaller than the clipping window. self._startX = 0 hi = 1.0 #use expand by default relwidth = 1 else: # The scrolled frame is larger than the clipping window. #use expand by default if self._startX + clipperWidth > frameWidth: self._startX = frameWidth - clipperWidth hi = 1.0 else: if self._startX < 0: self._startX = 0 hi = (self._startX + clipperWidth) / frameWidth relwidth = '' if self._startX != _startX: # Position frame relative to clipper. self.innerframe.place(x=-self._startX, relwidth=relwidth) lo = self._startX / frameWidth self.xscrollbar.set(lo, hi) def yview(self, mode=None, value=None, units=None): value = float(value) clipperHeight = self._clipper.winfo_height() frameHeight = self._frameHeight _startY = self._startY if mode is None: return self.yscrollbar.get() elif mode == 'moveto': self._startY = value * frameHeight else: # mode == 'scroll' if units == 'units': jump = int(clipperHeight * self._jfraction) else: jump = clipperHeight self._startY = self._startY + value * jump if frameHeight <= clipperHeight: # The scrolled frame is smaller than the clipping window. self._startY = 0 hi = 1.0 # use expand by default relheight = 1 else: # The scrolled frame is larger than the clipping window. # use expand by default if self._startY + clipperHeight > frameHeight: self._startY = frameHeight - clipperHeight hi = 1.0 else: if self._startY < 0: self._startY = 0 hi = (self._startY + clipperHeight) / frameHeight relheight = '' if self._startY != _startY: # Position frame relative to clipper. self.innerframe.place(y=-self._startY, relheight=relheight) lo = self._startY / frameHeight self.yscrollbar.set(lo, hi)
def __init__(self, master, xml=None, heading_text=None, heading_anchor=None, padding=None, cursor=None, takefocus=None, style=None): Frame.__init__(self, master, class_="XML_Viwer") self._vsb = Scrollbar(self, orient=VERTICAL) self._hsb = Scrollbar(self, orient=HORIZONTAL) kwargs = {} kwargs["yscrollcommand"] = lambda f, l: autoscroll(self._vsb, f, l) kwargs["xscrollcommand"] = lambda f, l: autoscroll(self._hsb, f, l) if style is not None: kwargs["style"] = style if padding is not None: kwargs["padding"] = padding if cursor is not None: kwargs["cursor"] = cursor if takefocus is not None: kwargs["takefocus"] = takefocus self._treeview = Treeview(self, **kwargs) if heading_text is not None: if heading_anchor is not None: self._treeview.heading("#0", text=heading_text, anchor=heading_anchor) else: self._treeview.heading("#0", text=heading_text) self._treeview.bind("<<TreeviewOpen>>", self._on_open) self._treeview.bind("<<TreeviewClose>>", self._on_close) # Without this line, horizontal scrolling doesn't work properly. self._treeview.column("#0", stretch=False) self._vsb['command'] = self._treeview.yview self._hsb['command'] = self._treeview.xview self._treeview.grid(column=0, row=0, sticky=N + S + W + E) self._vsb.grid(column=1, row=0, sticky=N + S) self._hsb.grid(column=0, row=1, sticky=E + W) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._element_tree = None self._item_ID_to_element = {} if xml is not None: self.parse_xml(xml)
class XML_Viwer(Frame): def __init__(self, master, xml=None, heading_text=None, heading_anchor=None, padding=None, cursor=None, takefocus=None, style=None): Frame.__init__(self, master, class_="XML_Viwer") self._vsb = Scrollbar(self, orient=VERTICAL) self._hsb = Scrollbar(self, orient=HORIZONTAL) kwargs = {} kwargs["yscrollcommand"] = lambda f, l: autoscroll(self._vsb, f, l) kwargs["xscrollcommand"] = lambda f, l: autoscroll(self._hsb, f, l) if style is not None: kwargs["style"] = style if padding is not None: kwargs["padding"] = padding if cursor is not None: kwargs["cursor"] = cursor if takefocus is not None: kwargs["takefocus"] = takefocus self._treeview = Treeview(self, **kwargs) if heading_text is not None: if heading_anchor is not None: self._treeview.heading("#0", text=heading_text, anchor=heading_anchor) else: self._treeview.heading("#0", text=heading_text) self._treeview.bind("<<TreeviewOpen>>", self._on_open) self._treeview.bind("<<TreeviewClose>>", self._on_close) # Without this line, horizontal scrolling doesn't work properly. self._treeview.column("#0", stretch=False) self._vsb['command'] = self._treeview.yview self._hsb['command'] = self._treeview.xview self._treeview.grid(column=0, row=0, sticky=N + S + W + E) self._vsb.grid(column=1, row=0, sticky=N + S) self._hsb.grid(column=0, row=1, sticky=E + W) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self._element_tree = None self._item_ID_to_element = {} if xml is not None: self.parse_xml(xml) def _on_open(self, event): item_ID = self._treeview.focus() if item_ID not in self._item_ID_to_element: return node = self._item_ID_to_element[item_ID] self._treeview.item(item_ID, text=self._repr_of_openning_tag(node)) def _on_close(self, event): item_ID = self._treeview.focus() if item_ID not in self._item_ID_to_element: return node = self._item_ID_to_element[item_ID] text = self._repr_of_openning_tag(node) + self._repr_of_closing_tag( node) self._treeview.item(item_ID, text=text) def parse_xml(self, xml): self._element_tree = ET.ElementTree(ET.fromstring(xml)) self.clear() self._walk_xml(self._element_tree.getroot()) @property def element_tree(self): return self._element_tree @element_tree.setter def element_tree(self, element_tree): self._element_tree = element_tree self.clear() self._walk_xml(element_tree.getroot()) def clear(self): self._item_ID_to_element = {} self._treeview.delete(*self._treeview.get_children()) def _repr_of_openning_tag(self, node): text = "<" + node.tag attrs = node.attrib # list function is here necessary to provide support to Python 3 a_names = list(attrs.keys()) a_names.sort() for a_name in a_names: text += ' %s="' % a_name text += attrs[a_name] text += '"' text += ">" return text def _repr_of_closing_tag(self, node): return "</%s>" % node.tag def _walk_xml(self, node, depth=0, parent=""): text = self._repr_of_openning_tag(node) + self._repr_of_closing_tag( node) item = self._treeview.insert(parent, END, text=text) self._item_ID_to_element[item] = node if node.text: text = node.text.strip() if text != "": for line in text.splitlines(): self._treeview.insert(item, END, text=line) child_nodes = sorted(list(node), key=attrgetter('tag')) for child_node in node: self._walk_xml(child_node, depth + 1, parent=item) if node.tail: tail = node.tail.strip() if tail != "": for line in tail.splitlines(): self._treeview.insert(parent, END, text=line)
class MainWindow(object): def __init__(self, root, debugger): ''' ----------------------------------------------------- | main button toolbar | ----------------------------------------------------- | < ma | in content area > | | | | | | | File list | File name | Inspector | | (stack/ | Code area | | | breakpnts) | | | | | | | | | | | ----------------------------------------------------- | status bar area | ----------------------------------------------------- ''' # Obtain and expand the current working directory. base_path = os.path.abspath(os.getcwd()) base_path = os.path.normcase(base_path) + '/' # Create a filename normalizer based on the CWD. self.filename_normalizer = filename_normalizer(base_path) self.debugger = debugger # Associate the debugger with this view. self.debugger.view = self # Root window self.root = root self.root.title('Bugjar') self.root.geometry('1024x768') # Prevent the menus from having the empty tearoff entry self.root.option_add('*tearOff', False) # Catch the close button self.root.protocol("WM_DELETE_WINDOW", self.cmd_quit) # Catch the "quit" event. self.root.createcommand('exit', self.cmd_quit) # Setup the menu self._setup_menubar() # Set up the main content for the window. self._setup_button_toolbar() self._setup_main_content() self._setup_status_bar() # Now configure the weights for the root frame self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=0) self.root.rowconfigure(1, weight=1) self.root.rowconfigure(2, weight=0) debugger.start() ###################################################### # Internal GUI layout methods. ###################################################### def _setup_menubar(self): # Menubar self.menubar = Menu(self.root) # self.menu_Apple = Menu(self.menubar, name='Apple') # self.menubar.add_cascade(menu=self.menu_Apple) self.menu_file = Menu(self.menubar) self.menubar.add_cascade(menu=self.menu_file, label='File') self.menu_program = Menu(self.menubar) self.menubar.add_cascade(menu=self.menu_program, label='Program') self.menu_help = Menu(self.menubar) self.menubar.add_cascade(menu=self.menu_help, label='Help') # self.menu_Apple.add_command(label='Test', command=self.cmd_dummy) # self.menu_file.add_command(label='New', command=self.cmd_dummy, accelerator="Command-N") self.menu_file.add_command(label='Open...', command=self.cmd_open_file, accelerator="Command-O") self.root.bind('<Command-o>', self.cmd_open_file) # self.menu_file.add_command(label='Close', command=self.cmd_dummy) self.menu_program.add_command(label='Run', command=self.cmd_run, accelerator="R") self.root.bind('<r>', self.cmd_run) self.menu_program.add_command(label='Step', command=self.cmd_step, accelerator="S") self.root.bind('<s>', self.cmd_step) self.menu_program.add_command(label='Next', command=self.cmd_next, accelerator="N") self.root.bind('<n>', self.cmd_next) self.menu_program.add_command(label='Return', command=self.cmd_return, accelerator="BackSpace") self.root.bind('<BackSpace>', self.cmd_return) self.menu_help.add_command(label='Open Documentation', command=self.cmd_bugjar_docs) self.menu_help.add_command(label='Open Bugjar project page', command=self.cmd_bugjar_page) self.menu_help.add_command(label='Open Bugjar on GitHub', command=self.cmd_bugjar_github) self.menu_help.add_command(label='Open BeeWare project page', command=self.cmd_beeware_page) # last step - configure the menubar self.root['menu'] = self.menubar def _setup_button_toolbar(self): ''' The button toolbar runs as a horizontal area at the top of the GUI. It is a persistent GUI component ''' # Main toolbar self.toolbar = Frame(self.root) self.toolbar.grid(column=0, row=0, sticky=(W, E)) # Buttons on the toolbar self.run_button = Button(self.toolbar, text='Run', command=self.cmd_run) self.run_button.grid(column=0, row=0) self.step_button = Button(self.toolbar, text='Step', command=self.cmd_step) self.step_button.grid(column=1, row=0) self.next_button = Button(self.toolbar, text='Next', command=self.cmd_next) self.next_button.grid(column=2, row=0) self.return_button = Button(self.toolbar, text='Return', command=self.cmd_return) self.return_button.grid(column=3, row=0) self.toolbar.columnconfigure(0, weight=0) self.toolbar.rowconfigure(0, weight=0) def _setup_main_content(self): ''' Sets up the main content area. It is a persistent GUI component ''' # Main content area self.content = PanedWindow(self.root, orient=HORIZONTAL) self.content.grid(column=0, row=1, sticky=(N, S, E, W)) # Create subregions of the content self._setup_file_lists() self._setup_code_area() self._setup_inspector() # Set up weights for the left frame's content self.content.columnconfigure(0, weight=1) self.content.rowconfigure(0, weight=1) self.content.pane(0, weight=1) self.content.pane(1, weight=2) self.content.pane(2, weight=1) def _setup_file_lists(self): self.file_notebook = Notebook(self.content, padding=(0, 5, 0, 5)) self.content.add(self.file_notebook) self._setup_stack_frame_list() self._setup_breakpoint_list() def _setup_stack_frame_list(self): self.stack_frame = Frame(self.content) self.stack_frame.grid(column=0, row=0, sticky=(N, S, E, W)) self.file_notebook.add(self.stack_frame, text='Stack') self.stack = StackView(self.stack_frame, normalizer=self.filename_normalizer) self.stack.grid(column=0, row=0, sticky=(N, S, E, W)) # # The tree's vertical scrollbar self.stack_scrollbar = Scrollbar(self.stack_frame, orient=VERTICAL) self.stack_scrollbar.grid(column=1, row=0, sticky=(N, S)) # # Tie the scrollbar to the text views, and the text views # # to each other. self.stack.config(yscrollcommand=self.stack_scrollbar.set) self.stack_scrollbar.config(command=self.stack.yview) # Setup weights for the "stack" tree self.stack_frame.columnconfigure(0, weight=1) self.stack_frame.columnconfigure(1, weight=0) self.stack_frame.rowconfigure(0, weight=1) # Handlers for GUI events self.stack.bind('<<TreeviewSelect>>', self.on_stack_frame_selected) def _setup_breakpoint_list(self): self.breakpoints_frame = Frame(self.content) self.breakpoints_frame.grid(column=0, row=0, sticky=(N, S, E, W)) self.file_notebook.add(self.breakpoints_frame, text='Breakpoints') self.breakpoints = BreakpointView(self.breakpoints_frame, normalizer=self.filename_normalizer) self.breakpoints.grid(column=0, row=0, sticky=(N, S, E, W)) # The tree's vertical scrollbar self.breakpoints_scrollbar = Scrollbar(self.breakpoints_frame, orient=VERTICAL) self.breakpoints_scrollbar.grid(column=1, row=0, sticky=(N, S)) # Tie the scrollbar to the text views, and the text views # to each other. self.breakpoints.config(yscrollcommand=self.breakpoints_scrollbar.set) self.breakpoints_scrollbar.config(command=self.breakpoints.yview) # Setup weights for the "breakpoint list" tree self.breakpoints_frame.columnconfigure(0, weight=1) self.breakpoints_frame.columnconfigure(1, weight=0) self.breakpoints_frame.rowconfigure(0, weight=1) # Handlers for GUI events self.breakpoints.tag_bind('breakpoint', '<Double-Button-1>', self.on_breakpoint_double_clicked) self.breakpoints.tag_bind('breakpoint', '<<TreeviewSelect>>', self.on_breakpoint_selected) self.breakpoints.tag_bind('file', '<<TreeviewSelect>>', self.on_breakpoint_file_selected) def _setup_code_area(self): self.code_frame = Frame(self.content) self.code_frame.grid(column=1, row=0, sticky=(N, S, E, W)) # Label for current file self.current_file = StringVar() self.current_file_label = Label(self.code_frame, textvariable=self.current_file) self.current_file_label.grid(column=0, row=0, sticky=(W, E)) # Code display area self.code = DebuggerCode(self.code_frame, debugger=self.debugger) self.code.grid(column=0, row=1, sticky=(N, S, E, W)) # Set up weights for the code frame's content self.code_frame.columnconfigure(0, weight=1) self.code_frame.rowconfigure(0, weight=0) self.code_frame.rowconfigure(1, weight=1) self.content.add(self.code_frame) def _setup_inspector(self): self.inspector_frame = Frame(self.content) self.inspector_frame.grid(column=2, row=0, sticky=(N, S, E, W)) self.inspector = InspectorView(self.inspector_frame) self.inspector.grid(column=0, row=0, sticky=(N, S, E, W)) # The tree's vertical scrollbar self.inspector_scrollbar = Scrollbar(self.inspector_frame, orient=VERTICAL) self.inspector_scrollbar.grid(column=1, row=0, sticky=(N, S)) # Tie the scrollbar to the text views, and the text views # to each other. self.inspector.config(yscrollcommand=self.inspector_scrollbar.set) self.inspector_scrollbar.config(command=self.inspector.yview) # Setup weights for the "breakpoint list" tree self.inspector_frame.columnconfigure(0, weight=1) self.inspector_frame.columnconfigure(1, weight=0) self.inspector_frame.rowconfigure(0, weight=1) self.content.add(self.inspector_frame) def _setup_status_bar(self): # Status bar self.statusbar = Frame(self.root) self.statusbar.grid(column=0, row=2, sticky=(W, E)) # Current status self.run_status = StringVar() self.run_status_label = Label(self.statusbar, textvariable=self.run_status) self.run_status_label.grid(column=0, row=0, sticky=(W, E)) self.run_status.set('Not running') # Main window resize handle self.grip = Sizegrip(self.statusbar) self.grip.grid(column=1, row=0, sticky=(S, E)) # Set up weights for status bar frame self.statusbar.columnconfigure(0, weight=1) self.statusbar.columnconfigure(1, weight=0) self.statusbar.rowconfigure(0, weight=0) ###################################################### # Utility methods for controlling content ###################################################### def show_file(self, filename, line=None, breakpoints=None): """Show the content of the nominated file. If specified, line is the current line number to highlight. If the line isn't currently visible, the window will be scrolled until it is. breakpoints is a list of line numbers that have current breakpoints. If refresh is true, the file will be reloaded and redrawn. """ # Set the filename label for the current file self.current_file.set(self.filename_normalizer(filename)) # Update the code view; this means changing the displayed file # if necessary, and updating the current line. if filename != self.code.filename: self.code.filename = filename for bp in self.debugger.breakpoints(filename).values(): if bp.enabled: self.code.enable_breakpoint(bp.line) else: self.code.disable_breakpoint(bp.line) self.code.line = line ###################################################### # TK Main loop ###################################################### def mainloop(self): self.root.mainloop() ###################################################### # TK Command handlers ###################################################### def cmd_quit(self): "Quit the debugger" self.debugger.stop() self.root.quit() def cmd_run(self, event=None): "Run until the next breakpoint, or end of execution" self.debugger.do_run() def cmd_step(self, event=None): "Step into the next line of code" self.debugger.do_step() def cmd_next(self, event=None): "Run the next line of code in the current frame" self.debugger.do_next() def cmd_return(self, event=None): "Return to the previous frame" self.debugger.do_return() def cmd_open_file(self, event=None): "Open a file in the breakpoint pane" filename = tkFileDialog.askopenfilename( initialdir=os.path.abspath(os.getcwd())) if filename: # Convert to canonical form filename = os.path.abspath(filename) filename = os.path.normcase(filename) # Show the file contents self.code.filename = filename # Ensure the file appears on the breakpoint list self.breakpoints.insert_filename(filename) # Show the breakpoint panel self.file_notebook.select(self.breakpoints_frame) # ... select the new filename self.breakpoints.selection_set(filename) # .. and clear any currently selected item on the stack tree self.stack.selection_remove(self.stack.selection()) def cmd_bugjar_page(self): "Show the Bugjar project page" webbrowser.open_new('http://pybee.org/bugjar') def cmd_bugjar_github(self): "Show the Bugjar GitHub repo" webbrowser.open_new('http://github.com/pybee/bugjar') def cmd_bugjar_docs(self): "Show the Bugjar documentation" # If this is a formal release, show the docs for that # version. otherwise, just show the head docs. if len(NUM_VERSION) == 3: webbrowser.open_new('http://bugjar.readthedocs.org/en/v%s/' % VERSION) else: webbrowser.open_new('http://bugjar.readthedocs.org/') def cmd_beeware_page(self): "Show the BeeWare project page" webbrowser.open_new('http://pybee.org/') ###################################################### # Handlers for GUI actions ###################################################### def on_stack_frame_selected(self, event): "When a stack frame is selected, highlight the file and line" if event.widget.selection(): _, index = event.widget.selection()[0].split(':') line, frame = self.debugger.stack[int(index)] # Display the file in the code view self.show_file(filename=frame['filename'], line=line) # Display the contents of the selected frame in the inspector self.inspector.show_frame(frame) # Clear any currently selected item on the breakpoint tree self.breakpoints.selection_remove(self.breakpoints.selection()) def on_breakpoint_selected(self, event): "When a breakpoint on the tree has been selected, show the breakpoint" if event.widget.selection(): parts = event.widget.focus().split(':') bp = self.debugger.breakpoint((parts[0], int(parts[1]))) self.show_file(filename=bp.filename, line=bp.line) # Clear any currently selected item on the stack tree self.stack.selection_remove(self.stack.selection()) def on_breakpoint_file_selected(self, event): "When a file is selected on the breakpoint tree, show the file" if event.widget.selection(): filename = event.widget.focus() self.show_file(filename=filename) # Clear any currently selected item on the stack tree self.stack.selection_remove(self.stack.selection()) def on_breakpoint_double_clicked(self, event): "When a breakpoint on the tree is double clicked, toggle it's status" if event.widget.selection(): parts = event.widget.focus().split(':') bp = self.debugger.breakpoint((parts[0], int(parts[1]))) if bp.enabled: self.debugger.disable_breakpoint(bp) else: self.debugger.enable_breakpoint(bp) # Clear any currently selected item on the stack tree self.stack.selection_remove(self.stack.selection()) ###################################################### # Handlers for debugger responses ###################################################### def on_stack(self, stack): "A report of a new stack" # Make sure the stack frame list is displayed self.file_notebook.select(self.stack_frame) # Update the stack list self.stack.update_stack(stack) if len(stack) > 0: # Update the display of the current file line = stack[-1][0] filename = stack[-1][1]['filename'] self.show_file(filename=filename, line=line) # Select the current stack frame in the frame list self.stack.selection_set('frame:%s' % (len(stack) - 1)) else: # No current frame (probably end of execution), # so clear the current line marker self.code.line = None def on_line(self, filename, line): "A single line of code has been executed" self.run_status.set('Line (%s:%s)' % (filename, line)) def on_call(self, args): "A callable has been invoked" self.run_status.set('Call: %s' % args) def on_return(self, retval): "A callable has returned" self.run_status.set('Return: %s' % retval) def on_exception(self, name, value): "An exception has been raised" self.run_status.set('Exception: %s - %s' % (name, value)) tkMessageBox.showwarning(message='%s: %s' % (name, value)) def on_postmortem(self): "An exception has been raised" self.run_status.set('Post mortem mode') tkMessageBox.showerror( message='Entering post mortem mode. Step/Next will restart') def on_restart(self): "The code has finished running, and will start again" self.run_status.set('Not running') tkMessageBox.showinfo( message='Program has finished, and will restart.') def on_info(self, message): "The debugger needs to inform the user of something" tkMessageBox.showinfo(message=message) def on_warning(self, message): "The debugger needs to warn the user of something" tkMessageBox.showwarning(message=message) def on_error(self, message): "The debugger needs to report an error" tkMessageBox.showerror(message=message) def on_breakpoint_enable(self, bp): "A breakpoint has been enabled in the debugger" # If the breakpoint is in the currently displayed file, updated # the display of the breakpoint. if bp.filename == self.code.filename: self.code.enable_breakpoint(bp.line, temporary=bp.temporary) # ... then update the display of the breakpoint on the tree self.breakpoints.update_breakpoint(bp) def on_breakpoint_disable(self, bp): "A breakpoint has been disabled in the debugger" # If the breakpoint is in the currently displayed file, updated # the display of the breakpoint. if bp.filename == self.code.filename: self.code.disable_breakpoint(bp.line) # ... then update the display of the breakpoint on the tree self.breakpoints.update_breakpoint(bp) def on_breakpoint_ignore(self, bp, count): "A breakpoint has been ignored by the debugger" # If the breakpoint is in the currently displayed file, updated # the display of the breakpoint. if bp.filename == self.code.filename: self.code.ignore_breakpoint(bp.line) # ... then update the display of the breakpoint on the tree self.breakpoints.update_breakpoint(bp) def on_breakpoint_clear(self, bp): "A breakpoint has been cleared in the debugger" # If the breakpoint is in the currently displayed file, updated # the display of the breakpoint. if bp.filename == self.code.filename: self.code.clear_breakpoint(bp.line) # ... then update the display of the breakpoint on the tree self.breakpoints.update_breakpoint(bp)
class JobList(Frame): # NOTE: job_params contains information about a Job in the Joblist # NOTE: plot_args contains information about plotting information, which occurs after the jobs have been and the data files have been created def __init__(self, parent=None, **kwargs): Frame.__init__(self, parent) self.parent = parent self.job_list_yscroll = Scrollbar(self, orient=Tkinter.VERTICAL) self.job_list_xscroll = Scrollbar(self, orient=Tkinter.HORIZONTAL) self.job_list = Listbox(self, xscrollcommand=self.job_list_xscroll, yscrollcommand=self.job_list_yscroll) self.job_list_xscroll['command'] = self.job_list.xview self.job_list_yscroll['command'] = self.job_list.yview self.new_job_frame = Frame(self) add_icon_filename = kwargs['add_icon_filename'] if 'add_icon_filename' in kwargs else None if add_icon_filename == None: self.add_job_button = Button(self.new_job_frame, text='Add Job', command=self.on_add) else: add_icon = PhotoImage(file=add_icon_filename) self.add_job_button = Button(self.new_job_frame, text='Add Job', compound='bottom', image=add_icon, command=self.on_add) self.remove_job_button = Button(self.new_job_frame, text='Remove Job', command=self.on_remove) self.progress_frame = Frame(self) self.progress_value = Tkinter.IntVar() self.progress_bar = Progressbar(self.progress_frame, variable=self.progress_value) self.button_frame = Frame(self) self.process_button = ProcessButton(parent=self.button_frame, start_jobs=self.start_jobs) self.quit_button = QuitButton(parent=self.button_frame, close_other_windows=self.close_top_level_windows) self.run_job = kwargs['run_job'] if 'run_job' in kwargs else None self.create_plots = kwargs['create_plots'] if 'create_plots' in kwargs else None self.log_filename = kwargs['log_filename'] if 'log_filename' in kwargs else None self.bind('<<AskToClearJobs>>', self.ask_to_clear_jobs) self.bind('<<AskToPlotGraphs>>', self.ask_to_plot_graphs) self.bind('<<CreatePlotGUI>>', self.create_plot_gui) self.parent.bind('<ButtonPress>', self.on_press) self.parent.bind('<Configure>', self.on_resize) self.reinit_variables() self.top_level_windows = list() # NOTE: Because there seems to be an issue resizing child widgets when the top level (Tk) widget is being resized, # the resize option will be disabled for this window self.parent.resizable(width=False, height=False) self.lift() def reinit_variables(self): self.job_params = dict() self.last_job_id = -1 self.job_outcomes = list() self.plot_args = list() self.on_button = False def add_job_params(self, input_args): self.job_params = input_args # Add each element to the job list for job in self.job_params: self.add_job(job) def add_job(self, job): try: index_end = job['input_directory'].rindex('/') index_start = job['input_directory'].rindex('/', 0, index_end) input_directory_text = job['input_directory'] list_text = 'Job ' + str(job['job_id']) + ' \'' + input_directory_text + '\'' if job['start'] != None: list_text += ' ' + str(job['start']) if job['end'] != None: list_text += ' to' if job['end'] != None: list_text += ' ' + str(job['end']) if job['job_id'] > self.last_job_id: self.last_job_id = job['job_id'] self.job_list.insert(Tkinter.END, list_text) # Add the list text to the job params as an optional parameter to read later to display in a future Graph GUI (or for any other useful purpose) job['list_text'] = list_text # The line number is used wrt the GUI to indicate which job in the job list is being currently executed. job['line_number'] = self.job_list.size() - 1 #print str(job['line_number']) self.job_params[job['job_id']] = job except KeyError as ke: # Should show some error message indicating that there is a problem. pass #print str(self.job_params) #print 'Added Job ' + str(job['job_id']) def ask_to_clear_jobs(self, event): for job in self.job_params.itervalues(): line_number = job['line_number'] self.job_list.itemconfig(line_number, foreground='black') # Update parent to refresh widget appearance self.parent.update() # Reactivate process button self.process_button.config(state = Tkinter.NORMAL) # Note: Display a pop-up that tells the user that the job is done and asks if the job list should be cleared. clearList = msg.askyesno(title='Jobs Finished', message='All jobs have been completed. Would you like to clear the job list?', master=self) if clearList: self.clear_list() def ask_to_plot_graphs(self, event): # TODO: Add a dialog that also asks to create a graph of the 'Other Type Of Plot' plotGraphs = msg.askyesno(title='Plot Graphs', message='Create plots of data?', master=self) if not plotGraphs: return # TODO: Iterate through the jobs to display to the user an interface that asks if they want to graphs of the outputs if self.create_plots != None: output_files_list = list() for job_outcome in self.job_outcomes: for output_outcomes in job_outcome[2]: (station, output_directory, output_files) = output_outcomes for output_files_tuple in output_files: for output_file_tuple in output_files_tuple: (output_file, output_file_success) = output_file_tuple if output_file_success: # If there is a list text variable (the 4th (or 3rd by 0 based index) variable), then add it to our output list if len(job_outcome) == 4: output_files_list.append([output_file, job_outcome[3]]) else: output_files_list.append([output_file]) plots_thread = PlotsThread(self.create_plots, output_files_list, self) plots_thread.start() def add_plot(self, args=dict()): self.plot_args.append(args) def finished_adding_plots(self): self.event_generate('<<CreatePlotGUI>>', when='tail') def create_plot_gui(self, event): # TODO: This should be replaced with a new window that allows the user to drag and drop the icons from one frame to another graph_names = list() for args in self.plot_args: graph_name = args['output_file'] graph_names.append(graph_name) dnd_graphs_frame = Dnd.createFrame(self, 'Drag and Drop Output Plots', graph_names, self.finish_creating_plot_gui) # This is the entry point for the def finish_creating_plot_gui(self, plot_labels): graph_count = 1 for plot_label in plot_labels: for args in self.plot_args: #print 'Looking in ' + args['plot_title'] + ' for ' + plot_label #print 'The plot label is: ' + plot_label #print 'The output file is: ' + args['output_file'] if plot_label == args['output_file']: #print 'Creating graph ' + str(graph_count) graph_count += 1 graph_window = ModelRunnerGraphGUI.GraphWindow(parent=self, title=args['window_title'], df=args['df'], plot=args['plot'], plot_title=args['plot_title'], y_label=args['y_label'], log_filename=self.log_filename) graph_window.set_grid() self.top_level_windows.append(graph_window) #print 'Creating plot GUI # Have to clear out list here instead of clear_list because clear_list() removes plot_args before this method has a chance to read # them and create the appropriate plot graph windows self.reinit_variables() # Clear all the elements in the list def clear_list(self): # Save plot args because they are need later in this run plot_args = self.plot_args self.reinit_variables() # Restore the plot args self.plot_args = plot_args self.job_list.delete(0, self.job_list.size()) self.progress_value.set(0) # Update parent to refresh widget appearance self.parent.update() def on_add(self): single_job = JobParameters(parent=self.parent, beginning_year=1950, ending_year=2100, job_id=self.last_job_id + 1, entry=self) single_job.set_grid() def on_remove(self): selection = self.job_list.curselection() for line_number in selection: line_text = self.job_list.get(line_number) job_id = int(line_text[4:line_text.index(' ', 4)]) job = self.job_params.pop(job_id) self.job_list.delete(line_number) print 'Removed Job ' + str(job['job_id']) # Fix line number for line_number in range(self.job_list.size()): line_text = self.job_list.get(line_number) job_id = int(line_text[4:line_text.index(' ', 4)]) #print 'Job ' + str(job_id) + ' is now on line ' + str(line_number) self.job_params[job_id]['line_number'] = line_number def set_grid(self): self.grid(sticky=Tkinter.N + Tkinter.S + Tkinter.W + Tkinter.E, padx=4, pady=4) self.columnconfigure(0, minsize=600) self.rowconfigure(0, minsize=300) self.job_list.grid(row=0, column=0, sticky=Tkinter.N + Tkinter.S + Tkinter.E + Tkinter.W) self.job_list_yscroll.grid(row=0, column=1, sticky=Tkinter.N + Tkinter.S + Tkinter.W) self.job_list_xscroll.grid(row=1, column=0, sticky=Tkinter.E + Tkinter.W + Tkinter.N) self.new_job_frame.grid(row=2, column=0, pady=3, sticky=Tkinter.W) self.remove_job_button.grid(row=0, column=0) self.add_job_button.grid(row=0, column=1) self.progress_frame.grid(row=3, column=0, pady=3) self.progress_frame.columnconfigure(0, minsize=600) self.progress_bar.grid(row=0, column=0, sticky=Tkinter.E + Tkinter.W + Tkinter.N + Tkinter.S) self.button_frame.grid(row=4, column=0, sticky=Tkinter.E + Tkinter.W + Tkinter.N + Tkinter.S) self.button_frame.columnconfigure(0, minsize=300) self.button_frame.columnconfigure(1, minsize=300) self.process_button.pack(side=Tkinter.RIGHT) self.quit_button.pack(side=Tkinter.RIGHT) def start_jobs(self): # If there are no queued jobs then simply return if len(self.job_params) == 0 or len(self.job_list.get(0)) == 0: return # Deactivate the process button self.process_button.config(state = Tkinter.DISABLED) # Initialize the progress bar self.progress_value.set(0) # Update parent to refresh widget appearance self.parent.update() # Start process thread jobs_thread = JobsThread(self.job_params, self.run_job, self.on_update, self.on_resume) jobs_thread.start() self['cursor'] = 'wait' def on_update(self, status, line_number, step): if status == 'init': self.job_list.itemconfig(line_number, foreground='green') self.job_list.activate(line_number) elif status == 'success': self.job_list.itemconfig(line_number, foreground='blue') elif status == 'fail': self.job_list.itemconfig(line_number, foreground='red') self.progress_value.set(step) # Update parent to refresh widget appearance self.parent.update() def on_resume(self, job_outcomes=list()): self.progress_value.set(100) self.job_outcomes = job_outcomes self.event_generate('<<AskToClearJobs>>', when='tail') self.event_generate('<<AskToPlotGraphs>>', when='tail') self['cursor'] = 'arrow' def close_top_level_windows(self): #print 'Closing other top level windows' for top_level_window in self.top_level_windows: if top_level_window: top_level_window.withdraw() top_level_window.destroy() def notify_of_close(self, top_level_window): if top_level_window in self.top_level_windows: #print 'Removing top level window' self.top_level_windows.remove(top_level_window) def on_press(self, event): self.on_button = True self.release_pattern = "<B%d-ButtonRelease-%d>" % (event.num, event.num) self.parent.bind(self.release_pattern, self.on_release) def on_release(self, event): self.on_button = False def on_resize(self, event): self.parent.lift() if self.on_button: self.set_grid() def on_close(self): self.plot_args = list() self.withdraw() self.destroy()
def __init__(self, master, columns, column_weights=None, column_minwidths=None, height=500, minwidth=20, minheight=20, padx=5, pady=5, cell_font=None, cell_foreground="black", cell_background="white", cell_anchor=W, header_font=None, header_background="white", header_foreground="black", header_anchor=CENTER, bordercolor = "#999999", innerborder=True, outerborder=True, stripped_rows=("#EEEEEE", "white"), on_change_data=None, mousewheel_speed = 2, scroll_horizontally=True, scroll_vertically=True): outerborder_width = 1 if outerborder else 0 Frame.__init__(self,master, bd= 0) self._cell_background = cell_background self._cell_foreground = cell_foreground self._cell_font = cell_font self._cell_anchor = cell_anchor self._stripped_rows = stripped_rows self._padx = padx self._pady = pady self._bordercolor = bordercolor self._innerborder_width = 1 if innerborder else 0 self._data_vars = [] self._columns = columns self._number_of_rows = 0 self._number_of_columns = len(columns) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) self._head = Frame(self, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0) self._head.grid(row=0, column=0, sticky=E+W) header_separator = False if outerborder else True for j in range(len(columns)): column_name = columns[j] header_cell = Header_Cell(self._head, text=column_name, borderwidth=self._innerborder_width, font=header_font, background=header_background, foreground=header_foreground, padx=padx, pady=pady, bordercolor=bordercolor, anchor=header_anchor, separator=header_separator) header_cell.grid(row=0, column=j, sticky=N+E+W+S) add_scrollbars = scroll_horizontally or scroll_vertically if add_scrollbars: if scroll_horizontally: xscrollbar = Scrollbar(self, orient=HORIZONTAL) xscrollbar.grid(row=2, column=0, sticky=E+W) else: xscrollbar = None if scroll_vertically: yscrollbar = Scrollbar(self, orient=VERTICAL) yscrollbar.grid(row=1, column=1, sticky=N+S) else: yscrollbar = None scrolling_area = Scrolling_Area(self, width=self._head.winfo_reqwidth(), height=height, scroll_horizontally=scroll_horizontally, xscrollbar=xscrollbar, scroll_vertically=scroll_vertically, yscrollbar=yscrollbar) scrolling_area.grid(row=1, column=0, sticky=E+W) self._body = Frame(scrolling_area.innerframe, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0) self._body.pack() def on_change_data(): scrolling_area.update_viewport() else: self._body = Frame(self, height=height, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0) self._body.grid(row=1, column=0, sticky=N+E+W+S) if column_weights is None: for j in range(len(columns)): self._body.grid_columnconfigure(j, weight=1) else: for j, weight in enumerate(column_weights): self._body.grid_columnconfigure(j, weight=weight) if column_minwidths is not None: for j, minwidth in enumerate(column_minwidths): if minwidth is None: header_cell = self._head.grid_slaves(row=0, column=j)[0] minwidth = header_cell.winfo_reqwidth() self._body.grid_columnconfigure(j, minsize=minwidth) else: for j in range(len(columns)): header_cell = self._head.grid_slaves(row=0, column=j)[0] minwidth = header_cell.winfo_reqwidth() self._body.grid_columnconfigure(j, minsize=minwidth) self._on_change_data = on_change_data