def _create_treeview(self, parent): f = Frame(parent) #f.pack(side=TOP, fill=BOTH, expand=Y) f.grid(row=0, column=0, sticky=NSEW, columnspan=3) # create the tree and scrollbars self.dataCols = ('fullpath', 'type', 'status') self.tree = Treeview(columns=self.dataCols, displaycolumns='status') ysb = Scrollbar(orient=VERTICAL, command= self.tree.yview) xsb = Scrollbar(orient=HORIZONTAL, command= self.tree.xview) self.tree['yscroll'] = ysb.set self.tree['xscroll'] = xsb.set # setup column headings self.tree.heading('#0', text='Directory Structure', anchor=W) self.tree.heading('status', text='Status', anchor=W) self.tree.column('status', stretch=0, width=100) # add tree and scrollbars to frame self.tree.grid(in_=f, row=0, column=0, sticky=NSEW) ysb.grid(in_=f, row=0, column=1, sticky=NS) xsb.grid(in_=f, row=1, column=0, sticky=EW) # set frame resizing priorities f.rowconfigure(0, weight=1) f.columnconfigure(0, weight=1) # action to perform when a node is expanded self.tree.bind('<<TreeviewOpen>>', self._update_tree) self.tree.bind("<Double-1>", self.OnDoubleClick)
class playar(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.filenm=None self.pack(fill=BOTH, expand=1) self.parent = parent self.initplayer() def initplayer(self): self.videoFrame = Frame(self, width=800, height=480) self.videoFrame.pack(side="top", fill="both", expand=True) self.buttonframe = Frame(self, padding="2 2 11 11") self.buttonframe.pack(side="bottom", fill="x", expand=True) self.selectbutton = Button(self.buttonframe, text="Select") self.selectbutton.grid(column=0, row=0, sticky=W) self.playbutton = Button(self.buttonframe, text="Play").grid(column=1, row=0, sticky=W) for child in self.buttonframe.winfo_children(): child.grid_configure(padx=5, pady=5) self.buttonframe.rowconfigure(0, weight=1) self.buttonframe.columnconfigure(0, weight=1) self.buttonframe.columnconfigure(1, weight=1) def setwh(self,w,h): self.videoFrame.configure(width=w, height=h) def quit(self): print "QUIT CALLED" pg.quit() self.destroy()
def __init__(self, master): self.master = master master.title("Convert SPC files") mf = Frame(master, padding="10") mf.grid(column=0, row=0, sticky=(N, W, E, S)) mf.columnconfigure(0, weight=1) mf.rowconfigure(0, weight=1) self.message = "Enter folder containing *.SPC files" self.label_text = StringVar() self.folder = StringVar() self.output_fmt = StringVar() self.label_text.set(self.message) self.label = Label(mf, textvariable=self.label_text) self.folder_label = Label(mf, text="Folder") self.output_fmt_label = Label(mf, text="Output Format") self.fmt_txt = Radiobutton(mf, text="TXT", variable=self.output_fmt, value='txt') self.fmt_csv = Radiobutton(mf, text="CSV", variable=self.output_fmt, value='csv') self.folder_entry = Entry(mf, textvariable=self.folder) self.sel_foler = Button(mf, text="Browse", command=self.ask_dir) self.convert_btn = Button(mf, text="Convert", command=self.convert) # map on grid self.label.grid(row=0, column=0, columnspan=4, sticky=W + E) self.folder_label.grid(row=1, column=0, sticky=E) self.output_fmt_label.grid(row=2, column=0, sticky=E) self.folder_entry.grid(row=1, column=1, columnspan=2, sticky=W + E) self.fmt_txt.grid(row=2, column=1, sticky=W) self.fmt_csv.grid(row=2, column=2, sticky=W) self.sel_foler.grid(row=1, column=3, sticky=W) self.convert_btn.grid(row=3, column=1, columnspan=2, sticky=W + E) for child in mf.winfo_children(): child.grid_configure(padx=5, pady=5)
####################### from Tkinter import Tk, W, E from ttk import Frame, Button, Label, Style from ttk import Entry the_window = tk.Tk() frame = Frame(the_window) Style().configure("TButton", padding=(0, 5, 0, 5), font='serif 10') frame.columnconfigure(0, pad=3) frame.columnconfigure(1, pad=3) frame.columnconfigure(2, pad=3) frame.columnconfigure(3, pad=3) frame.rowconfigure(0, pad=3) frame.rowconfigure(1, pad=3) ## ENTRY ### band1Label = Label(frame, text='Band 1') band1Label.grid(row=0, column=0) band1Entry = Entry(frame) band1Entry.grid(row=0, column=1) band2Label = Label(frame, text='Band 2') band2Label.grid(row=0, column=2) band2Entry = Entry(frame) band2Entry.grid(row=0, column=3) band3Label = Label(frame, text='Band 3') band3Label.grid(row=1, column=0) band3Entry = Entry(frame) band3Entry.grid(row=1, column=1) band4Label = Label(frame, text='Band 4')
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 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)
relationship_manager = RelationshipManager(dictionary, stop_list = ['authority', 'jurisdiction']) #Term dictionary and managers term_dictionary = RelevantTermsDictionary(RELEVANT_TERMS_FILE) term_manager = RelevantTermsManager(term_dictionary, stop_list = ['authority', 'jurisdiction']) #term_manager.set_current_threshold(99.0) print "num of terms", len(term_manager.get_current_dictionary()) print "num of relations", len(relationship_manager.get_usable_couples()) #main frame supermainframe = Frame(root, padding="3 3 12 12") supermainframe.grid(column=0, row=0, sticky=(N, W, E, S)) supermainframe.columnconfigure(0, weight=1) supermainframe.rowconfigure(0, weight=1) mainframe = Frame(supermainframe, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) suggested_term_a = StringVar() suggested_term_b = StringVar() suggested_term_single = StringVar() couple = relationship_manager.get_random_couple() couple = ['speed restrictions','application']
def StartGui(self): self.tkRoot = Tk(baseName="") self.tkRoot.geometry("350x300+0+0") self.tkRoot.title("Engine SAPI GUI") self.GUIVisible = True frame = Frame(self.tkRoot) frame.style = Style() frame.style.theme_use("alt") frame.pack(fill=BOTH, expand=1) frame.columnconfigure(1, weight=1) frame.columnconfigure(7, pad=7) frame.rowconfigure(13, weight=1) frame.rowconfigure(13, pad=7) Label(frame, text="Start:").grid(row = 0, column=0) self.labelStart = Label(frame, text="0") self.labelStart.grid(row = 1, column=0) Label(frame, text="Length:").grid(row = 0, column=1) self.labelLength = Label(frame, text="0") self.labelLength.grid(row = 1, column=1) Label(frame, text="Total:").grid(row = 0, column=2) self.labelTotal = Label(frame, text="0") self.labelTotal.grid(row = 1, column=2) self.labelSentenceLeft = Label(frame, text="...") self.labelSentenceLeft.grid(row = 2, column=0, sticky=E) self.labelSentenceSpoken = Label(frame, text="...", foreground="red") self.labelSentenceSpoken.grid(row = 2, column=1) self.labelSentenceRight = Label(frame, text="...") self.labelSentenceRight.grid(row = 2, column=2, sticky=W, columnspan=2) scrollbar = Scrollbar(frame, orient=VERTICAL) self.labelQueueToSpeak = Label(frame, text="Queue to speak:").grid(row = 3, column=0, pady=4, padx=5, sticky=W) self.listboxQueueToSpeak = Listbox(frame, width=50, height=3, yscrollcommand=scrollbar.set) scrollbar.config(command=self.listboxQueueToSpeak.yview) self.listboxQueueToSpeak.grid( sticky=N+S+E+W, row = 4, column = 0, columnspan = 2 ,rowspan = 3, padx=3) scrollbar.grid(sticky=N+S+W, row = 4, column = 2, rowspan = 3) self.buttonPauze = Button(frame, text="Pauze", command=self.communicationProtocal.handlePauze) self.buttonPauze.grid(row = 4, column=3) self.buttonStop = Button(frame, text="Stop", command=self.communicationProtocal.restartProcess) self.buttonStop.grid(row = 5, column=3) self.buttonResume = Button(frame, text="Resume", command=self.communicationProtocal.handleResume) self.buttonResume.grid(row = 6, column=3) Label(frame, text="Text to say:").grid(row = 7, column=0, padx=3, sticky=W) self.stringVarTextToSay = StringVar() self.entryTextToSay = Entry(frame, textvariable=self.stringVarTextToSay, width=500) self.entryTextToSay.grid(row=8, column=0, columnspan=3, padx=3, sticky=W) self.stringVarTextToSay.set("Hello SAPI Speak Engine") self.entryTextToSay.bind('<Return>', self.CallBackReturnSay) self.buttonSay = Button(frame, text="Say", command=self.CallBackButtonSay) self.buttonSay.grid(row = 8, column=3) Label(frame, text="Recover action:").grid(row = 9, column=0, padx=3, sticky=W) self.recoverActionLabelText = "None" self.labelRecoverAction = Label(frame, text=self.recoverActionLabelText, foreground="blue") self.labelRecoverAction.grid(row = 10, column=0) Label(frame, text="Voice speed:").grid(row = 9, column=1, sticky=W) self.buttonSpeedDown = Button(frame, text="Speed down", command=self.communicationProtocal.handleSpeedDown) self.buttonSpeedDown.grid(row = 10, column=1, padx=3, sticky=E) self.speedValue = 0 self.intVarSpeed = IntVar() vcmd = (self.tkRoot.register(self.OnValidateEntrySpeakSpeed), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.entrySpeakSpeed = Entry(frame, textvariable=self.intVarSpeed, validate="key", validatecommand=vcmd, width=5) self.entrySpeakSpeed.grid(row=10,column=2) self.entrySpeakSpeed.bind('<Return>', self.CallBackSetSpeed) self.buttonSpeedUp = Button(frame, text="Speed up", command=self.communicationProtocal.handleSpeedUp) self.buttonSpeedUp.grid(row = 10, column=3) Label(frame, text="voice:").grid(row = 11, column=0, padx=3, sticky=W) self.buttonPrevVoice = Button(frame, text="Prev voice", command=self.communicationProtocal.handlePrevVoice) self.buttonPrevVoice.grid(row = 12, column=0, padx=3, sticky=W) self.buttonNextVoice = Button(frame, text="Next voice", command=self.communicationProtocal.handleNextVoice) self.buttonNextVoice.grid(row = 12, column=3) self.currentVoice = StringVar(self.tkRoot) self.currentVoice.set(self.communicationProtocal.CurrentVoiceName) engine = pyttsx.init() voices = engine.getProperty("voices") voiceNames = list() for x in xrange(0, len(voices)): voiceNames.append(voices[x].name) self.optionMenuVoices = OptionMenu(frame, self.currentVoice, *tuple(voiceNames), command=self.CallBackOptionMenuVoices) self.optionMenuVoices.config(width=500) self.optionMenuVoices.grid(sticky=W, row = 12, column = 1) #hide if close button is clicked self.tkRoot.protocol("WM_DELETE_WINDOW", self.HideGui) self.tkRoot.after(1000/32, self.Update) self.tkRoot.mainloop()
def createSettings(self,frame,d): #name frame row = 0 col = 0 lblFrame = Frame(frame) lblFrame.grid(row=row,column=col,columnspan=5,sticky=W+E,pady=0,padx=5) frame.columnconfigure(col, weight=1) frame.rowconfigure(row, weight=0) row = 0 col = 0 Label(lblFrame, text="Script Name").grid(row=row,column=col,sticky=W) lblFrame.columnconfigure(col, weight=0) lblFrame.rowconfigure(row, weight=0) row = 0 col = 1 entryMain = Entry(lblFrame) entryMain.grid(row=row,column=col,sticky=W+E,columnspan=5) self.entryName = entryMain lblFrame.columnconfigure(col, weight=1) lblFrame.rowconfigure(row, weight=0) #python plugin script file row = 1 col = 0 mainGroup = LabelFrame(frame,text="Python Script File", padding="5 5 5 5") mainGroup.grid(row=row,column=col,columnspan=5,sticky=W+E+N,pady=5,padx=5) row = 0 col = 0 mainGroup.columnconfigure(col, weight=1) mainGroup.rowconfigure(row, weight=0) entryMain = Entry(mainGroup) entryMain.grid(row=row,column=col,columnspan=4,sticky=W+E) entryMain.bind("<Return>",self.entryFileEvent) self.entryFile = entryMain row = 0 col = 4 btnMainBrowse = Button(mainGroup,text="Browse") btnMainBrowse.grid(row=row,column=col,columnspan=1,sticky=W+E,padx=5,pady=2.5) self.btnBrowse = btnMainBrowse row = 1 col = 0 Label(mainGroup, text="Plugin Class").grid(row=row,column=col,sticky=E) self.cbPluginClass = comboBox([],mainGroup,col+1,row) mainGroup.columnconfigure(col, weight=0) row = 2 col = 0 Label(mainGroup, text="GUI Class").grid(row=row,column=col,sticky=E) self.cbGuiClass = comboBox([],mainGroup,col+1,row) col = 1 mainGroup.columnconfigure(1, weight=1) mainGroup.columnconfigure(2, weight=1) mainGroup.columnconfigure(3, weight=1) row=1 col=4 button = Button(mainGroup,text="Edit Script File") button.grid(row=row,column=col,sticky=W+E,padx=5,pady=2.5) self.btnEditScript = button row = 2 col = 4 button = Button(mainGroup,text="Open Contaning Folder") button.grid(row=row,column=col,sticky=W+E,padx=5,pady=2.5) self.btnOpenFolder = button
def initUI(self): self.width = 700 self.height = 350 self.left = 0 self.right = 0 self.parent = Tk() self.parent.attributes("-topmost", 1) self.getHWNDS() r = self.winPos(self.obshwnd) self.centerOverOBS(r) self.parent.geometry("%sx%s+%s+%s" % (self.width,self.height,int(self.left),int(self.top))) self.parent.focus() self.parent.wm_title("Python Script Manager") #title label frame row = 0 col = 0 self.parent.columnconfigure(col,weight=1) self.parent.rowconfigure(row,weight=0) titleFrame = Frame(self.parent) titleFrame.grid(row=row,column=col,sticky=W+E,pady=5,padx=10) row = 0 col = 0 labelfont = ('bold', 15) Label(titleFrame, text="Python Script Manager",font=labelfont).grid(row=row,column=col,sticky=W) titleFrame.columnconfigure(row,weight=1) titleFrame.rowconfigure(col,weight=0) #sidebyside frame row = 1 col = 0 self.parent.rowconfigure(row,weight=1) self.parent.columnconfigure(col,weight=1) sidebyside = Frame(self.parent) sidebyside.grid(row=row,column=col,sticky=W+E+N+S,pady=0,padx=5) #listbox frame row = 0 col = 0 sidebyside.rowconfigure(row,weight=1) sidebyside.columnconfigure(col,weight=1) leftFrame = Frame(sidebyside) leftFrame.grid(row=row,column=col,sticky=W+E+N+S,pady=5,padx=5) #listbox row = 0 col = 0 self.listbox = Listbox(leftFrame) self.listbox.grid(row=row,column=col,columnspan=5,sticky=W+E+N+S) listboxReload(self.listbox,getScriptNames(self.scriptDict)) self.listbox.bind('<<ListboxSelect>>',self.listboxSelectionEevent) leftFrame.columnconfigure(col,weight=1) leftFrame.rowconfigure(row,weight=1) row=1 col=0 buttonFrame = Frame(leftFrame) buttonFrame.grid(row=row,column=col,sticky=W,pady=0,padx=0) row=0 col=0 #btnAdd button = Button(buttonFrame,text="Add") button.grid(row=row,column=col,sticky=E) self.btnAdd = button self.btnAdd.config(command=self.btnAddEvent) #btnRemove button = Button(buttonFrame,text="Remove") button.grid(row=row,column=col+1,sticky=W) self.btnRemove = button self.btnRemove.config(command=self.btnRemoveEvent) #settings frame row = 0 col = 1 sidebyside.rowconfigure(row,weight=1) sidebyside.columnconfigure(col,weight=10) rightFrame = Frame(sidebyside) rightFrame.grid(row=row,column=col,sticky=W+E+N+S,pady=5,padx=5) row = 0 col = 0 rightFrame.columnconfigure(col,weight=1) rightFrame.rowconfigure(row,weight=1) self.frmSettings = LabelFrame(rightFrame,text="Settings", padding="5 5 5 5") self.frmSettings.grid(row=row,column=col,sticky=W+E+N+S,pady=0,padx=0) self.frmSettings.columnconfigure(col,weight=1) self.frmSettings.rowconfigure(row,weight=1) d = createScriptDict() createSettings(self,self.frmSettings,d) row=1 col=0 buttonFrame = Frame(rightFrame) buttonFrame.grid(row=row,column=col,sticky=W,pady=0,padx=0) row = 0 col = 0 button = Button(buttonFrame,text="Save") button.grid(row=row,column=col) self.btnSave = button self.btnSave.config(command=self.btnSaveEvent) #ok cancel buttons row = 2 col = 0 self.parent.columnconfigure(col,weight=1) self.parent.rowconfigure(row,weight=0) bottomframe = Frame(self.parent) bottomframe.grid(row=row,column=col,sticky=W+E,pady=5,padx=10) row = 0 col = 0 bottomframe.columnconfigure(col,weight=1) bottomframe.rowconfigure(row,weight=0) logFrame = Frame(bottomframe) logFrame.grid(row=row,column=col,sticky=W,pady=0,padx=0) logFrame.rowconfigure(row,weight=0) row=0 col=0 #btnOpenLogs button = Button(logFrame,text="Open Logs",command=self.btnOpenLogsEvent) button.grid(row=row,column=col,sticky=E,padx=0,pady=0) self.btnOpenLogs = button row = 0 col = 1 bottomframe.columnconfigure(col,weight=1) bottomframe.rowconfigure(row,weight=0) ccFrame = Frame(bottomframe) ccFrame.grid(row=row,column=col,sticky=E,pady=0,padx=5) ccFrame.rowconfigure(row,weight=0) row=0 col=0 button = Button(ccFrame,text="Create",command=self.btnCreateEvent) button.grid(row=row,column=col,sticky=E,padx=10,pady=0) self.btnCreate = button button = Button(ccFrame,text="Cancel",command=self.btnCancelEvent) button.grid(row=row,column=col+1,sticky=W,padx=0,pady=0) self.btnCancel = button self.clearSettings() self.parent.after(1,self.lockWindow) self.parent.mainloop() self.unlockWindow()
class mainframe(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.filenm=None self.streamnm = None self.pack(fill=BOTH, expand=1) self.parent = parent self.initplayer() self.player_process = None self.seekthread = None self.fstate = False self.paused = True self.trackmouse = True self.stdout_thread = None self.stream = False self.inhibit_slider_trigger = False self.q = LifoQueue() self.currtime = 0 self.endtime = -1 def initplayer(self): self.parentframe = Frame(self) self.parentframe.pack(fill=BOTH, expand=True) self.videoFrame = Frame(self.parentframe, width=800, height=480) self.videoFrame.pack(side="top", fill="both", expand=True) self.buttonframe = Frame(self.parentframe, padding="2 2 1 1") self.buttonframe.pack(side="bottom", fill="x", expand=False) self.seekbar = Scale(self.buttonframe, from_= 0, to=100, orient=HORIZONTAL) self.seekbar.grid(column=0, columnspan=4, row=0, sticky=[N, E, S, W]) self.seekbar.configure(command=self.seeked) self.selectbutton = Button(self.buttonframe, text="Select File") self.selectbutton.grid(column=0, row=1, sticky=[E,W]) self.streambutton = Button(self.buttonframe, text="Open HTTP", command=self.streamopen) self.streambutton.grid(column=1, row=1, sticky=[E,W]) self.playbutton = Button(self.buttonframe, text="Play") self.playbutton.config(command=self.playpause) self.playbutton.grid(column=2, row=1, sticky=[E,W]) self.fullscreenbutton = Button(self.buttonframe, text="Fullscreen", command=self.togglefullscreen) self.fullscreenbutton.grid(column=3, row=1, sticky=[E,W]) for child in self.buttonframe.winfo_children(): child.grid_configure(padx=5, pady=5) self.buttonframe.rowconfigure(0, weight=1) self.buttonframe.rowconfigure(1, weight=1) self.buttonframe.columnconfigure(0, weight=1) self.buttonframe.columnconfigure(1, weight=1) self.buttonframe.columnconfigure(2, weight=1) self.buttonframe.columnconfigure(3, weight=1) self.selectbutton.configure(command=self.fileopen) self.videoFrame.bind("<Button-1>",self.playpause) self.parent.bind("<F11>", self.togglefullscreen) self.parent.bind("<Motion>",self.mouseops) def mouseops(self,event=None): self.videoFrame.config(cursor="") self.videoFrame.after(5000,self.cursorhandler) if self.trackmouse: x, y = self.parent.winfo_pointerx(), self.parent.winfo_pointery() windowx, windowy = self.parent.winfo_width(), self.parent.winfo_height() if windowy - 30 <= y: if self.fstate: self.buttonframe.pack(side="bottom", fill="x", expand=False) self.trackmouse = False self.parent.after(5000, self.mousetracker) self.inhibit_slider_trigger = False elif self.fstate: self.buttonframe.pack_forget() self.inhibit_slider_trigger = True else: self.inhibit_slider_trigger = True def mousetracker(self): print 'Mouse Tracker' self.trackmouse = True self.videoFrame.after(0,self.mouseops) def cursorhandler(self): self.videoFrame.config(cursor="none") def togglefullscreen(self, event=None): self.fstate = not self.fstate self.parent.attributes("-fullscreen",self.fstate) if self.fstate: self.fullscreenbutton.config(text="Exit Fullscreen") self.buttonframe.pack_forget() self.videoFrame.config(cursor="none") else: self.fullscreenbutton.config(text="Fullscreen") self.buttonframe.pack(side="bottom", fill="x", expand=False) self.videoFrame.after(5000, self.cursorhandler) def fileopen(self): self.filenm = askopenfilename(filetypes=[("Supported Files","*.mp4;*.mkv;*.mpg;*.avi;*.mov"),("All Files","*.*")]) self.stream = False self.play() def streamopen(self): self.streamnm = Dlog(self.parent) if self.streamnm.result is not None: s = str(self.streamnm) else: return if s.startswith('http'): self.stream = True self.play() else: self.stream = False showerror("Error","Incorrect Entry") def play(self): global fifofilename if self.filenm is not None and self.filenm != "": winid = self.videoFrame.winfo_id() if self.mplayer_isrunning(): self.stop() try: self.paused = False self.playbutton.configure(text="Pause") if not self.stream: self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.filenm],stdin=PIPE, stdout=PIPE) else: self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.streamnm], stdin=PIPE, stdout=PIPE) self.stdout_thread = Thread(target=self.enqueue_pipe, args=(self.player_process.stdout, self.q)) self.stdout_thread.daemon = True self.stdout_thread.start() self.emptypipe() self.seekthread = Thread(target=self.seekbar_setup, args=()) self.seekthread.daemon = True self.seekthread.start() except: showerror("Error","".join(["Couldn't play video:\n",str(sys.exc_info()[:])])) def getvidtime(self): if self.mplayer_isrunning(): self.command_player("get_time_length") output = self.readpipe() while "ANS_LENGTH" not in output: output = self.readpipe() if "ANS_LENGTH" in output: return output.split('ANS_LENGTH=')[1] else: return 0 def playpause(self, event=None): if self.player_process is None: return self.paused = not self.paused if self.paused: print "VIDEO IS PAUSED /B/RO" self.playbutton.configure(text="Play") else: self.playbutton.configure(text="Pause") self.command_player("pause") def setwh(self,w,h): self.videoFrame.configure(width=w, height=h) def quit(self): print "QUIT CALLED" self.destroy() def mplayer_isrunning(self): if self.player_process is not None: return (self.player_process.poll() is None) else: return False def command_player(self, comd): global fifofilename if self.mplayer_isrunning(): try: self.player_process.stdin.flush() self.player_process.stdin.write("\r\n%s\r\n"%comd) # for _ in itertools.repeat(None,8192): # self.player_process.stdin.write("\n") self.player_process.stdin.flush() except: showerror("Error","Error passing command to mplayer\n%s"%sys.exc_info()[1]) def enqueue_pipe(self, out, q): print 'Working on reading mplayer pipe output...' for line in iter(out.readline, b''): q.put(line) out.close() def seekbar_setup(self): pos = '0' trial = 0 while float(pos)<1: trial += 1 pos = self.getvidtime() self.seekbar.config(to=int(float(pos))) self.endtime = int(float(pos)) Timer(1, self.seekbar_updater).start() def seekbar_updater(self): if not self.paused and self.inhibit_slider_trigger: self.currtime += 1 self.seekbar.set(self.currtime) else: self.currtime = self.seekbar.get() Timer(1, self.seekbar_updater).start() def seeked(self,e): pos = self.seekbar.get() print "We changed pos to :%d"% pos x, y = self.parent.winfo_pointerx(), self.parent.winfo_pointery() windowx, windowy = self.parent.winfo_width(), self.parent.winfo_height() if not self.inhibit_slider_trigger and windowy - 30 <= y: self.command_player("seek %d 2"%pos) if self.paused: self.command_player("pause") def startmousetrack(self): self.trackmouse = True def readpipe(self): line = "" try: line = self.q.get_nowait() except Empty: print "Empty PIPE" finally: return line def emptypipe(self): str = '' try: while not self.q.empty(): str += self.q.get_nowait() except Empty: print "Empty Pipe" finally: return str def stop(self): if self.mplayer_isrunning(): self.player_process.stdin.write("quit\n") self.player_process.stdin.flush() print self.emptypipe() self.player_process = None
def __init__(self, master): self.master = master self.screen1 = None master.title("RVD") #mf = Frame(master, padding="20") master.geometry('575x300') #self.menu=Menu(master) #file_item=Menu(self.menu) #self.menu.add_cascade(label='File', menu=file_item) #file_item.add_command(label='About', command=self.about) #file_item.add_separator() #file_item.add_command(label='Exit', command=self.master.quit) mf = Frame(master, padding="15") mf.grid(column=0, row=0, sticky=(N, W, E, S)) mf.columnconfigure(0, weight=1) mf.rowconfigure(0, weight=1) self.infomessage = "Raman spectra based RNA Virus Detection (RVD) program\n" self.developer = "\nDeveloped by Sanket Desai, Dutt laboratory, TMC-ACTREC" self.infolabel_text = StringVar() self.developer_text = StringVar() self.proname = StringVar() self.message = "Enter folder containing *.SPC files" self.label_text = StringVar() self.folder = StringVar() #self.output_fmt = StringVar() self.outputdir = StringVar() self.prolabel = Label(mf, text="Project name") self.infolabel_text.set(self.infomessage) self.developer_text.set(self.developer) self.label_text.set(self.message) self.ilabel = Label(mf, textvariable=self.infolabel_text) self.developerlabel = Label(mf, textvariable=self.developer_text) self.label = Label(mf, textvariable=self.label_text) self.folder_label = Label(mf, text="Input Directory") self.output_folder_label = Label(mf, text="Output Directory") #self.output_fmt_label = Label(mf, text="Output Format") #self.fmt_txt = Radiobutton(mf, text="TXT", variable=self.output_fmt, value='txt') #self.fmt_csv = Radiobutton(mf, text="CSV", variable=self.output_fmt, value='csv') self.proname_entry = Entry(mf, textvariable=self.proname) self.folder_entry = Entry(mf, textvariable=self.folder) self.sel_foler = Button(mf, text="Browse", command=self.ask_dir) self.folder_entry2 = Entry(mf, textvariable=self.outputdir) self.sel_foler2 = Button(mf, text="Browse", command=self.ask_odir) self.convert_btn = Button(mf, text="Submit", command=self.convert) # map on grid #self.menu.grid(row=0,column=0, sticky=E) self.ilabel.grid(row=0, column=2, sticky=E) self.prolabel.grid(row=2, column=1, sticky=E) self.proname_entry.grid(row=2, column=2, columnspan=2, sticky=W + E) self.label.grid(row=3, column=2, columnspan=4, sticky=W + E) self.folder_label.grid(row=4, column=1, sticky=E) #self.output_fmt_label.grid(row=3, column=0, sticky=E) self.folder_entry.grid(row=4, column=2, columnspan=2, sticky=W + E) #self.fmt_txt.grid(row=2, column=1, sticky=W) #self.fmt_csv.grid(row=2, column=2, sticky=W) self.sel_foler.grid(row=4, column=4, sticky=W) self.output_folder_label.grid(row=5, column=1, sticky=E) self.folder_entry2.grid(row=5, column=2, columnspan=2, sticky=W + E) self.sel_foler2.grid(row=5, column=4, sticky=W) self.convert_btn.grid(row=6, column=2, columnspan=2, sticky=W + E) self.developerlabel.grid(row=7, column=2, sticky=E) for child in mf.winfo_children(): child.grid_configure(padx=5, pady=5)