def insert_frame(self, name, parent_frame_name, idx, frame_type=None, **kwargs): parent_frame = self.frames[parent_frame_name] frame = Frame(parent_frame) # add frame to list of frames self.frames[name] = frame # pre-fill the frame if frame_type is None: pass elif frame_type == 'plot': # generate canvas dim = kwargs['shape'] f = Figure(figsize=dim, dpi=113 ) a = f.add_subplot(111) canvas = FigureCanvasTkAgg(f, master=frame) # Commit the canvas to the gui canvas.get_tk_widget().pack() # save canvas data for later access self.mpl_data[name] = {} self.frame_data['plot'] = {'mpl_canvas':canvas} # commit the frame to workspace frame.grid(row=idx[0], column=idx[1])
class RadioButtonList: # Widget class def __init__(self, frm, name, ch1, ch2, st, i): self.frame = Frame(frm.frame) self.frame.grid() self.ch1 = ch1 self.ch2 = ch2 self.i = i self.st = st v = IntVar() self.v = v self.shuu = name self.length = len(name) self.rb = {} r = 0 self.r = r for txt, val in name: self.rb[r] = Radiobutton(frm.frame, text=txt, padx=20, variable=v, value=val, command=self.onclick) self.rb[r].grid(row=i + r, column=0, sticky=W, pady=2) r = r + 1 self.r = r def onclick(self): if self.ch1 == 1: if self.v.get() == self.ch2: self.st.set_text("true") # v.add(self.st,self.i+self.r+1) else: self.st.set_text("false") # v.add(self.st,self.i+self.r+1) else: self.st.set_text("Your choice:" + self.shuu[self.v.get() - 1][0])
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)
def __init__(self, master, sequencer): Frame.__init__(self, master) self.sequencer = sequencer self.control_panel = MainControlFrame(self, sequencer) self.control_panel.grid(row=0, column=0, sticky='ns') self.instrument_panel = Frame(self) self.instrument_panel.grid(row=0, column=1) self.rythm_track_frames = [] for id, instrument in enumerate(sequencer.instruments): instrument_frame = get_instrument_frame(self.instrument_panel, instrument) instrument_frame.grid(row=id, column=0, sticky="NSEW") instrument_track_frame = Frame(self.instrument_panel) instrument_track_frame.grid(row=id, column=1, sticky="NSEW", padx=3, pady=3) tracks = [track for track in sequencer.tracks if track.instrument_id == id] for row, track in enumerate(tracks): rt_frame = RhythmTrackFrame(instrument_track_frame, track, sequencer) rt_frame.grid(row=row, column=0, sticky="EW") self.rythm_track_frames.append(rt_frame) self.events = [] sequencer.add_observer(self) self.running = True self.consume()
def startVid(self): gobject.threads_init() video = Frame(self, background='black') video.grid(row=0, column=0, columnspan=8, rowspan=4, padx=2, sticky=E+W+S+N) window_id = video.winfo_id() self.buf = gst.Buffer() self.bin = gst.Bin("my-bin") timeoverlay = gst.element_factory_make("timeoverlay", "overlay") self.bin.add(timeoverlay) pad = timeoverlay.get_pad("video_sink") ghostpad = gst.GhostPad("sink", pad) self.bin.add_pad(ghostpad) videosink = gst.element_factory_make("ximagesink") self.bin.add(videosink) gst.element_link_many(timeoverlay, videosink) self.player.set_property('video-sink', self.bin) self.player.set_property('uri', 'file://%s' % (os.path.abspath(self.project.videoPath))) bus = self.player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() bus.connect("message", self.on_message, window_id) bus.connect('sync-message::element', self.on_sync_message, window_id) self.play.configure(command=lambda: self.play_video()) self.back.configure(command=self.play_back)
def _add_filename(self, frame, index, name, mode, option): if option: self.function[-1] = lambda v: [option, v] else: self.function[-1] = lambda v: [v] self.variables[-1] = StringVar() var = self.variables[-1] def set_name(): if mode == "r": fn = tkFileDialog.askopenfilename(initialdir=".") else: fn = tkFileDialog.asksaveasfilename(initialdir=".") var.set(fn) label = Label(frame, text=name) label.grid(row=index, column=0, sticky="W", padx=10) field_button = Frame(frame) Grid.columnconfigure(field_button, 0, weight=1) field = Entry(field_button, textvariable=var) field.grid(row=0, column=0, sticky="WE") button = Button(field_button, text="...", command=set_name, width=1, padding=0) button.grid(row=0, column=1) field_button.grid(row=index, column=1, sticky="WE")
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 Halignment: def __init__(self): self.frame = Frame() self.frame.grid() def add(self, widget, i, j): self.widget = widget.widget self.widget.grid(row=i, column=j, sticky=W, pady=2)
class Halignment(): def __init__(self): self.frame = Frame() self.frame.grid() def add(self, widget, i, j): self.widget = widget.widget self.widget.grid(row=i, column=j, sticky=W, pady=2)
class Alignment: def __init__(self, frame): self.frame = Frame() self.frame.grid() def add(self, widget, i, j, span): self.widget = widget.widget self.widget.grid(row=i, column=j, columnspan=span, sticky=W, pady=2)
class Alignment(): def __init__(self, frame): self.frame = Frame() self.frame.grid() def add(self, widget, i, j, span): self.widget = widget.widget self.widget.grid(row=i, column=j, columnspan=span, sticky=W, pady=2)
class button: def __init__(self, frm, name): self.frame = Frame(frm.frame) self.frame.grid() self.widget = Button(frm.frame) self.widget.configure(text=name, fg="red") def bind(self, fn, *arc): self.widget.bind("<Button-1>", fn)
class button(): def __init__(self, frm, name): self.frame = Frame(frm.frame) self.frame.grid() self.widget = Button(frm.frame) self.widget.configure(text=name, fg="red") def bind(self, fn, *arc): self.widget.bind("<Button-1>", fn)
class Statictext: def __init__(self, frm): self.frame = Frame(frm.frame) self.frame.grid() self.lab = StringVar() self.widget = Label(frm.frame, textvariable=self.lab) def set_text(self, name): self.lab.set(name)
class ComboBox(): def __init__(self, frm, hello, arg): self.arg = arg self.frame = Frame(frm.frame) self.frame.grid() optionvalue = IntVar() optionvalue.set(hello) self.widget = OptionMenu(frm.frame, optionvalue, *self.arg) self.widget.state = []
class Statictext(): def __init__(self, frm): self.frame = Frame(frm.frame) self.frame.grid() self.lab = StringVar() self.widget = Label(frm.frame, textvariable=self.lab) def set_text(self, name): self.lab.set(name)
class ComboBox: def __init__(self, frm, hello, arg): self.arg = arg self.frame = Frame(frm.frame) self.frame.grid() optionvalue = IntVar() optionvalue.set(hello) self.widget = OptionMenu(frm.frame, optionvalue, *self.arg) self.widget.state = []
def initUI(self, parser) : # TODO required arguments # TODO repeated arguments (e.g. filenames) self.parent.title(self.progname) self.pack(fill=BOTH, expand=1) self.centerWindow() Grid.rowconfigure(self,1,weight=1) Grid.columnconfigure(self,0,weight=1) inputFrame = Frame(self) inputFrame.grid(row=0, column=0, sticky='WE') outputFrame = Frame(self) outputFrame.grid(row=1, column=0, sticky='WENS') self.outputText = ReadOnlyText(outputFrame) self.outputText.pack(fill=BOTH, expand=1) # Main controls frame mainFrame = Frame(inputFrame) mainFrame.pack(fill=BOTH, expand=1) # Auto-resize column Grid.columnconfigure(mainFrame,1,weight=1) # Ok button okButton = Button(inputFrame, text='Run', command=self.run, default='active') okButton.pack(side=RIGHT, padx=5, pady=5) # Cancel button cancelButton = Button(inputFrame, text='Exit', command=self.quit) cancelButton.pack(side=RIGHT) # Add controls to mainframe for all options for index, action in enumerate(parser._actions) : action_type = type(action).__name__ if action_type == '_HelpAction' : pass else : self.function.append(lambda v : [v]) self.variables.append(None) if action.choices : self._add_choice( mainFrame, index, action.dest, action.choices, action.default, action.option_strings[0] ) elif action_type == '_StoreTrueAction' : self._add_check( mainFrame, index, action.dest, False, action.option_strings[0] ) elif action_type == '_CountAction' : self._add_count( mainFrame, index, action.dest, 0, action.option_strings[0] ) elif action.type and action.type.__name__ == 'inputfile' : self._add_filename( mainFrame, index, action.dest, 'r', action.option_strings ) elif action.type and action.type.__name__ == 'outputfile' : self._add_filename( mainFrame, index, action.dest, 'w', action.option_strings ) else : self._add_field( mainFrame, index, action.dest )
class SpinCtrl: def __init__(self, frm, val, mini, maxi): self.frame = Frame(frm.frame) self.frame.grid() self.var = IntVar() self.var.set(5) self.widget = Spinbox(frm.frame, from_=mini, to=maxi) def get_value(self): print "spin= ", self.widget.get() return self.widget.get()
class ProgressBar: def __init__(self, frm, value, rang, wid, hite): self.frame = Frame(frm.frame) self.frame.grid() self.var = IntVar() self.var.set(value) self.widget = ttk.Progressbar(frm.frame, variable=self.var, orient=HORIZONTAL, length=wid, mode="determinate") self.widget.start() def stop(self): self.widget.stop()
class SpinCtrl(): def __init__(self, frm, val, mini, maxi): self.frame = Frame(frm.frame) self.frame.grid() self.var = IntVar() self.var.set(5) self.widget = Spinbox(frm.frame, from_=mini, to=maxi) def get_value(self): print 'spin= ', self.widget.get() return self.widget.get()
def _create_panel(self): panel = Frame(self, name='elastic') #panel.pack(side=TOP, fill=BOTH, expand=Y) panel.grid(row=0, column=0, sticky=NSEW) nb = Notebook(panel, name='notebook') nb.enable_traversal() #nb.pack(fill=BOTH, expand=Y, padx=2, pady=3) nb.grid(row=0, column=0, sticky=NSEW) self._create_setup_tab(nb) self._create_analyze_tab(nb)
class FileDialog(Frame): def __init__(self, parent, text): self.sukh = parent self.text = text self.frame = Frame(parent.frame) self.frame.grid() def get_value(self): ftypes = [(self.text, '*.jpg')] dlg = tkFileDialog.Open(filetypes=ftypes) fl = dlg.show() return fl
def initUI(self): self.parent.title('Prepare DWI') frm_output = Frame(self) frm_button = Frame(self) frm_list = VerticalScrolledFrame(self) self.frm_list_sub = frm_list.interior self.lst_dwi = self.List_DWI(self, self.frm_list_sub) i = 0 frm_output.grid(row=i, column=0, columnspan=6, sticky=EW) frm_output.grid_columnconfigure(1, weight=1) ii = 0; Label(frm_output, text='Subject').grid(row=ii, column=0) self.txt_subject = Entry(frm_output); self.txt_subject.grid(row=ii, column=1, sticky=EW) self.txt_subject.insert(0, self.subject_name) ii += 1; Label(frm_output, text='Output Directory').grid(row=ii, column=0) self.txt_output = Entry(frm_output); self.txt_output.grid(row=ii, column=1, sticky=EW) self.txt_output.insert(0, self.output_dir) btn_output = Button(frm_output, text='...', command=lambda:dirnameDialog_text(self.txt_output)); btn_output.grid(row=ii, column=2) ii += 1; Label(frm_output, text='Merged B0').grid(row=ii, column=0) self.txt_output_b0 = Entry(frm_output); self.txt_output_b0.grid(row=ii, column=1, sticky=EW) btn_output_b0 = Button(frm_output, text='Gen', command=lambda:self.lst_dwi.fn_b0(self.txt_output_b0)); btn_output_b0.grid(row=ii, column=2) ii += 1; Label(frm_output, text='Merged DWI').grid(row=ii, column=0) self.txt_output_dw = Entry(frm_output); self.txt_output_dw.grid(row=ii, column=1, sticky=EW) btn_output_dw = Button(frm_output, text='Gen', command=lambda:self.lst_dwi.fn_dw(self.txt_output_dw)); btn_output_dw.grid(row=ii, column=2) i += ii i += 1 frm_button.grid(row=i, column=0, columnspan=6, sticky=EW) ii = 0 btn_add = Button(frm_button, text='ADD Nifti1 file', command=self.add_dwi_list); btn_add.grid(row=ii, column=0) btn_run = Button(frm_button, text='Run', command=self.run); btn_run.grid(row=ii, column=1) i += ii i += 1 i_frm_list = i self.frm_list_sub.grid_columnconfigure(2, weight=1) frm_list.grid(row=i, column=0, columnspan=6, sticky=NSEW) self.grid_rowconfigure(i_frm_list, weight=1, minsize=20) #self.lst_dwi.add_one('test1') #self.lst_dwi.add_one('test2') self.grid_columnconfigure(0, weight=1) ni = i + 1 #for i in range(i_frm_list, ni): # self.grid_rowconfigure(i, weight=1, minsize=20) self.pack(fill=BOTH, expand=True)
class Slider: def __init__(self, frm, value, mini, maxi): self.frame = Frame(frm.frame) self.frame.grid() self.var = DoubleVar() self.var.set(value) self.widget = Scale( frm.frame, variable=self.var, from_=mini, to=maxi, length=200, sliderlength=8, orient=HORIZONTAL ) def get_value(self): return "Value = ", self.var.get()
class FileDialog(Frame): def __init__(self, parent, text): self.sukh = parent self.text = text self.frame = Frame(parent.frame) self.frame.grid() def get_value(self): ftypes = [(self.text, "*.jpg")] dlg = tkFileDialog.Open(filetypes=ftypes) fl = dlg.show() return fl
def create_frame(self, name, idx, frame_type=None, **kwargs): """Creates a gridded frame inside the window. ARGS: * name: name of the frame * idx: tuple containing the (r,c) designation of the frame within the grid. r=row. c=column.""" # create the frame frame = Frame(self.window) # add frame to list of frames self.frames[name] = frame # pre-fill the frame if frame_type is None: pass elif frame_type == 'plot': # determine initialization variables dim = kwargs.get('shape', None) ylim = kwargs.get('ylim', None) xlim = kwargs.get('xlim', None) xticks = kwargs.get('xticks', None) # generate the figure f = Figure(figsize=dim, dpi=113 ) a = f.add_subplot(111) # generate canvas canvas = FigureCanvasTkAgg(f, master=frame) # set axes ticks if ylim is not None: a.set_ylim(*ylim) if xlim is not None: a.set_xlim(*xlim) if xticks is not None: a.set_xticks(xticks) # Commit the canvas to the gui canvas.get_tk_widget().pack() # save canvas data for later access self.mpl_data[name] = {'axes':a, 'figure':f, 'canvas':canvas} self.frame_data['plot'] = {'mpl_canvas':canvas} # commit the frame to workspace frame.grid(row=idx[0], column=idx[1])
class ProgressBar(): def __init__(self, frm, value, rang, wid, hite): self.frame = Frame(frm.frame) self.frame.grid() self.var = IntVar() self.var.set(value) self.widget = ttk.Progressbar(frm.frame, variable=self.var, orient=HORIZONTAL, length=wid, mode='determinate') self.widget.start() def stop(self): self.widget.stop()
class SequencerFrame(Frame): def __init__(self, master, sequencer): Frame.__init__(self, master) self.sequencer = sequencer self.control_panel = MainControlFrame(self, sequencer) self.control_panel.grid(row=0, column=0, sticky='ns') self.instrument_panel = Frame(self) self.instrument_panel.grid(row=0, column=1) self.rythm_track_frames = [] for id, instrument in enumerate(sequencer.instruments): instrument_frame = get_instrument_frame(self.instrument_panel, instrument) instrument_frame.grid(row=id, column=0, sticky="NSEW") instrument_track_frame = Frame(self.instrument_panel) instrument_track_frame.grid(row=id, column=1, sticky="NSEW", padx=3, pady=3) tracks = [track for track in sequencer.tracks if track.instrument_id == id] for row, track in enumerate(tracks): rt_frame = RhythmTrackFrame(instrument_track_frame, track, sequencer) rt_frame.grid(row=row, column=0, sticky="EW") self.rythm_track_frames.append(rt_frame) self.events = [] sequencer.add_observer(self) self.running = True self.consume() def consume(self): if not self.running: return while len(self.events) > 0: time = self.events.pop().time for rt in self.rythm_track_frames: rt.set_time(time) self.after(UPDATE_INTERVAL,self.consume) def notify(self, event): self.events.append(event) def destroy(self): self.running = False return Frame.destroy(self)
class Slider(): def __init__(self, frm, value, mini, maxi): self.frame = Frame(frm.frame) self.frame.grid() self.var = DoubleVar() self.var.set(value) self.widget = Scale(frm.frame, variable=self.var, from_=mini, to=maxi, length=200, sliderlength=8, orient=HORIZONTAL) def get_value(self): return 'Value = ', self.var.get()
class SingleTextBox: def __init__(self, frm, visibilty): self.frame = Frame(frm.frame) self.frame.grid() self.v = StringVar() if visibilty == 1: self.widget = Entry(width=25, background="white", textvariable=self.v) if visibilty == 0: self.widget = Entry(width=25, background="white", show="*", textvariable=self.v) def set_text(self, text): self.v.set(text) def get_text(self): x = self.widget.get() return x
def __init__(self, master=None, title=None, message=None, data = []): self.master = master self.value = None self.data = data self.modalPane = Toplevel(self.master) self.modalPane.transient(self.master) self.modalPane.grab_set() self.modalPane.bind("<Return>", self._choose) self.modalPane.bind("<Escape>", self._cancel) self.modalPane.columnconfigure(0, pad = 5, weight = 1) self.modalPane.rowconfigure(0, pad = 5) self.modalPane.rowconfigure(1, pad = 5, weight = 1) self.modalPane.rowconfigure(2, pad = 5) if title: self.modalPane.title(title) if message: Label(self.modalPane, text=message).grid(row = 0, column = 0, padx = 10, sticky = W+E) listFrame = Frame(self.modalPane) listFrame.grid(row = 1, column = 0, sticky = W+E) scrollBar = Scrollbar(listFrame) scrollBar.pack(side=RIGHT, fill=Y) self.listBox = Listbox(listFrame, selectmode = SINGLE) self.listBox.pack(side = LEFT, fill = BOTH, expand = True) scrollBar.config(command = self.listBox.yview) self.listBox.config(yscrollcommand=scrollBar.set) for item in self.data: self.listBox.insert(END, item) buttonFrame = Frame(self.modalPane) buttonFrame.grid(row = 2, column = 0, sticky = W+E) chooseButton = Button(buttonFrame, text="Choose", command=self._choose) chooseButton.pack(padx=5, pady=5, side = LEFT) cancelButton = Button(buttonFrame, text="Cancel", command=self._cancel) cancelButton.pack(padx=5, pady=5, side=RIGHT)
class GeneralActionModulation(Frame): def __init__(self,parent): Frame.__init__(self,parent) self.parent = parent self.initUI() def initUI(self): self.frame = Frame(self.parent, relief=RAISED,borderwidth=1) self.frame_text = Frame(self.frame, relief=RAISED,borderwidth=1) self.frame_text.grid(row=0 , column=0) self.area = Text(self.frame_text) self.area.grid(row=0, column=0, columnspan=1, rowspan=1, padx=5) def getFrame(self): return self.frame def getText(self): return self.area.get('1.0', 'end')
class SingleTextBox(): def __init__(self, frm, visibilty): self.frame = Frame(frm.frame) self.frame.grid() self.v = StringVar() if visibilty == 1: self.widget = Entry(width=25, background='white', textvariable=self.v) if visibilty == 0: self.widget = Entry(width=25, background='white', show="*", textvariable=self.v) def set_text(self, text): self.v.set(text) def get_text(self): x = self.widget.get() return x
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)
class RadioButtonList(): #Widget class def __init__(self, frm, name, ch1, ch2, st, i): self.frame = Frame(frm.frame) self.frame.grid() self.ch1 = ch1 self.ch2 = ch2 self.i = i self.st = st v = IntVar() self.v = v self.shuu = name self.length = len(name) self.rb = {} r = 0 self.r = r for txt, val in name: self.rb[r] = Radiobutton(frm.frame, text=txt, padx=20, variable=v, value=val, command=self.onclick) self.rb[r].grid(row=i + r, column=0, sticky=W, pady=2) r = r + 1 self.r = r def onclick(self): if (self.ch1 == 1): if (self.v.get() == self.ch2): self.st.set_text('true') #v.add(self.st,self.i+self.r+1) else: self.st.set_text('false') #v.add(self.st,self.i+self.r+1) else: self.st.set_text('Your choice:' + self.shuu[self.v.get() - 1][0])
class NewActionModulation(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() def initUI(self): self.parent.title("Test") self.frameTab = Frame(self, relief=RAISED, borderwidth=1) self.frameTab.grid(row=3, column=0, columnspan=4) self.grid(row=0, column=0) self.frameTab.grid(row=0, column=0) self.note_book = Notebook(self.frameTab) self.specific_actions = ActionModulation.ActionModulation(self.note_book) self.note_book.add(self.specific_actions.getFrame(), text="specific actions") self.general_actions = GeneralActionModulation.GeneralActionModulation(self.note_book) self.note_book.add(self.general_actions.getFrame(), text="general actions") self.note_book.grid(row=0, column=0) self.frameButtons = Frame(self, relief=RAISED, borderwidth=1) self.frameButtons.grid(row=3, column=0, columnspan=4) self.buttonReset = Button(self.frameButtons, text="Reset") self.buttonReset.grid(row=0, column=0) self.buttonAbort = Button(self.frameButtons, text="Abort") self.buttonAbort.grid(row=0, column=1) self.buttonStop = Button(self.frameButtons, text="Stop") self.buttonStop.grid(row=0, column=2) self.buttonSendAction = Button(self.frameButtons, text="Send Action") self.buttonSendAction.grid(row=0, column=4) self.buttonSendEmotion = Button(self.frameButtons, text="Send Emotion") self.buttonSendEmotion.grid(row=0, column=5) def getCurrentTab(self): return self.note_book.index(self.note_book.select()) def getFirstTab(self): return self.specific_actions def getSecondTab(self): return self.general_actions def getButtonSendAction(self): return self.buttonSendAction def getButtonSendEmotion(self): return self.buttonSendEmotion def getButtonReset(self): return self.buttonReset def getButtonAbort(self): return self.buttonAbort def getButtonStop(self): return self.buttonStop
def create_ui(self, image_paths, supervoxel_id_path): """This function creates the UI elements.""" sub_frame = Frame(self) sub_frame.grid(column=1, row=0, columnspan=self.image_nb) # create a sub frame to select the image slices that are displayed slice_frame = Frame(sub_frame) slice_frame.grid(column=0, row=1, columnspan=self.image_nb) pic_frame = Frame(sub_frame) pic_frame.grid(column=0, row=0, columnspan=self.image_nb) self.configure_images(pic_frame, image_paths) self.add_slice_bar(slice_frame) self.set_optional_buttons(supervoxel_id_path)
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 JobParameters(Toplevel): def __init__(self, parent=None, **kwargs): Toplevel.__init__(self, parent) self.title('Job Parameters') self.parent = parent self.main_frame = Frame(self) self.input_directory_gui = DirectorySelector(self.main_frame, 'Input Directory:') self.output_directory_gui = DirectorySelector(self.main_frame, 'Output Directory:', get_default=lambda: self.input_directory_gui.get_directory() + '/output/') self.input_directory_gui.set_notify(self.notify) self.beginning_year = kwargs['beginning_year'] if 'beginning_year' in kwargs else 1950 self.ending_year = kwargs['ending_year'] if 'ending_year' in kwargs else 2100 self.beginning_year_selector = YearSelector(self.main_frame, text="Beginning Year:", min_value=self.beginning_year, max_value=self.ending_year) self.ending_year_selector = YearSelector(self.main_frame, text="Ending Year:", min_value=self.beginning_year, max_value=self.ending_year) self.one_decade_range_var = IntVar() self.one_decade_range = Checkbutton(self.main_frame, text='Calculate 10 Year Range', variable=self.one_decade_range_var, command=self.on_change) self.two_decade_range_var = IntVar() self.two_decade_range = Checkbutton(self.main_frame, text='Calculate 20 Year Range', variable=self.two_decade_range_var, command=self.on_change) self.custom_range_var = IntVar() self.custom_range = Checkbutton(self.main_frame, text='Calculate Custom Year Range', variable=self.custom_range_var, command=self.on_change) self.custom_range_val = StringVar() self.custom_range_input = Spinbox(self.main_frame, from_=30, to=100, textvariable=self.custom_range_val, command=self.on_change, width=5) # Initialize widget values self.beginning_year_selector.set_value(self.beginning_year) self.beginning_year_selector.set_args(check_other_func=self.ending_year_selector.get_less_than) self.ending_year_selector.set_value(self.ending_year) self.ending_year_selector.set_args(check_other_func=self.beginning_year_selector.get_greater_than) self.one_decade_range_var.set(1) self.two_decade_range_var.set(1) self.custom_range_var.set(0) self.custom_range_input.config(state=Tkinter.DISABLED) self.button_frame = Frame(self.main_frame) self.ok_button = Button(self.button_frame, text='OK', command=self.on_submit) self.cancel_button = Button(self.button_frame, text='Cancel', command=self.on_close) self.job_id = kwargs['job_id'] if 'job_id' in kwargs else None self.entry = kwargs['entry'] if 'entry' in kwargs else None self.grab_set() self.resizable(width=False, height=False) def notify(self): self.output_directory_gui.notify() self.lift() def set_grid(self): # Layout child widgets self.main_frame.grid() self.input_directory_gui.set_grid(row=0, padx=6) self.output_directory_gui.set_grid(row=1, padx=6) self.beginning_year_selector.set_grid(row=2, padx=6) self.ending_year_selector.set_grid(row=3, padx=6) self.one_decade_range.grid(row=4, column=1, sticky='w', padx=6) self.two_decade_range.grid(row=5, column=1, sticky='w', padx=6) self.custom_range.grid(row=6, column=1, sticky='w', padx=6) self.custom_range_input.grid(row=6, column=2, sticky='w', padx=6) self.button_frame.grid(row=7, columnspan=3, sticky='nsew') self.ok_button.pack(side=Tkinter.RIGHT) self.cancel_button.pack(side=Tkinter.RIGHT) #self.ok_button.grid(row=7, column=1, pady=2) #self.cancel_button.grid(row=7, column=2, pady=2) def on_change(self): is_custom_range_checked = self.custom_range_var.get() == 1 if is_custom_range_checked: self.custom_range_input.config(state=Tkinter.NORMAL) else: self.custom_range_input.config(state=Tkinter.DISABLED) def on_submit(self): if self.input_directory_gui.get_directory() == '' or self.output_directory_gui.get_directory() == '': self.on_close() return # The job parameters are extracted from the GUI here and passed to the processing thread to run the requisite job. job = dict() job['job_id'] = self.job_id job['delimiter'] = '.' job['individual_files'] = False job['input_directory'] = self.input_directory_gui.get_directory() job['output_directory'] = self.output_directory_gui.get_directory() job['start'] = self.beginning_year_selector.get_value() job['end'] = self.ending_year_selector.get_value() job['calculate_one_decade'] = self.one_decade_range_var.get() == 1 job['calculate_two_decade'] = self.two_decade_range_var.get() == 1 job['calculate_custom_range'] = self.custom_range_var.get() == 1 job['custom_range'] = int(self.custom_range_val.get()) job['log'] = True if self.entry != None: self.entry.add_job(job) self.on_close() def on_close(self): if self.parent != None: self.parent.focus_set() self.withdraw() self.destroy() def on_focus(self): self.focus_force()
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()
class TabSettings(Frame): def __init__(self, parent, txt=dict(), switcher=None): """Instanciating the output workbook.""" self.parent = parent Frame.__init__(self) # subframes self.FrOptProxy = Frame(self, name='settings_proxy') self.FrOptIsogeo = Frame(self, name='settings_isogeo') # options values self.opt_proxy = IntVar(self) # proxy option self.opt_isogeo = IntVar(self) # Isogeo option # Options form widgets caz_prox = Checkbutton(self, text=u'Proxy', variable=self.opt_proxy, command=lambda: switcher(self.opt_proxy, self.FrOptProxy)) caz_isogeo = Checkbutton(self, text=u'Isogeo', variable=self.opt_isogeo, command=lambda: switcher(self.opt_isogeo, self.FrOptIsogeo)) # positionning caz_prox.grid(row=0, column=0, sticky="NSWE", padx=2, pady=2) self.FrOptProxy.grid(row=0, column=1, columnspan=8, sticky="NSWE", padx=2, pady=2, rowspan=3) caz_isogeo.grid(row=3, column=0, sticky="NSWE", padx=2, pady=2) self.FrOptIsogeo.grid(row=3, column=1, columnspan=8, sticky="NSWE", padx=2, pady=2, rowspan=4) # ------------------------------------------------------------------------ # proxy specific variables self.opt_ntlm = IntVar(self.FrOptProxy, 0) # proxy NTLM protocol option self.prox_server = StringVar(self.FrOptProxy, 'proxy.server.com') self.prox_port = IntVar(self.FrOptProxy, 80) self.prox_user = StringVar(self.FrOptProxy, 'proxy_user') self.prox_pswd = StringVar(self.FrOptProxy, '****') # widgets self.prox_ent_H = Entry(self.FrOptProxy, textvariable=self.prox_server) self.prox_ent_P = Entry(self.FrOptProxy, textvariable=self.prox_port) self.prox_ent_M = Entry(self.FrOptProxy, textvariable=self.prox_pswd, show='*') self.prox_lb_H = Label(self.FrOptProxy, text=txt.get('gui_prox_server', "Host")) self.prox_lb_P = Label(self.FrOptProxy, text=txt.get('gui_port', "Port")) caz_ntlm = Checkbutton(self.FrOptProxy, text=u'NTLM', variable=self.opt_ntlm) self.prox_lb_M = Label(self.FrOptProxy, text=txt.get('gui_mdp', "Password")) # proxy widgets position self.prox_lb_H.grid(row=1, column=0, sticky="NSEW", padx=2, pady=2) self.prox_ent_H.grid(row=1, column=1, columnspan=2, sticky="NSEW", padx=2, pady=2) self.prox_lb_P.grid(row=1, column=2, sticky="NSEW", padx=2, pady=2) self.prox_ent_P.grid(row=1, column=3, columnspan=2, sticky="NSEW", padx=2, pady=2) caz_ntlm.grid(row=2, column=0, sticky="NSEW", padx=2, pady=2) self.prox_lb_M.grid(row=2, column=1, sticky="NSEW", padx=2, pady=2) self.prox_ent_M.grid(row=2, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2) # ------------------------------------------------------------------------ # Isogeo application variables self.isog_app_id = StringVar(self.FrOptIsogeo, 'application_id') self.isog_app_tk = StringVar(self.FrOptIsogeo, 'secret') # widgets isog_ent_id = Entry(self.FrOptIsogeo, textvariable=self.isog_app_id) isog_ent_tk = Entry(self.FrOptIsogeo, textvariable=self.isog_app_tk) isog_lb_id = Label(self.FrOptIsogeo, text="Application ID") isog_lb_tk = Label(self.FrOptIsogeo, text="Application secret") # Isogeo widgets position isog_lb_id.grid(row=1, column=1, sticky="NSEW", padx=2, pady=2) isog_ent_id.grid(row=1, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2) isog_lb_tk.grid(row=2, column=1, sticky="NSEW", padx=2, pady=2) isog_ent_tk.grid(row=2, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2)
def add_ui_components(self): # Creating the frames. self.sub_frame1 = Frame(self) self.sub_frame1.grid(column=0, row=0) sub_frame2 = Frame(self) sub_frame2.grid(column=0, row=1) sub_frame3 = Frame(self) sub_frame3.grid(column=0, row=2) sub_frame21 = Frame(sub_frame2) sub_frame21.grid(column=0, row=0) sub_frame22 = Frame(sub_frame2) sub_frame22.grid(padx=20, column=1, row=0) sub_frame221 = Frame(sub_frame22) sub_frame221.grid(row=1, column=0) # Creating the top-menu buttons. self.visualise_button = Button(self.sub_frame1, text="Visualise", command=self.start_visualisation) self.visualise_button.grid(row=0, column=1) self.help_button = Button(self.sub_frame1, text="Help", command=self.open_help) self.help_button.grid(row=0, column=2) # Creating the select modality path. self.modality_label = Label(sub_frame21, text="Path to patient folders", relief=FLAT) self.modality_label.grid(row=1, column=1) self.modality_path_entry = Entry(sub_frame21) self.modality_path_entry.grid(row=2, column=1) #self.modality_path_entry.set(self.patient_folder_path) self.modality_path_button = Button( sub_frame21, text="Choose", command=self.choose_directory_and_import) self.modality_path_button.grid(row=2, column=2) # Creating the patients listbox. self.label_patients = Label(sub_frame22, text="Patients") self.label_patients.grid(row=0, column=0) self.listbox_patients = Listbox(sub_frame221, selectmode='multiple', width=50, height=10) self.listbox_patients.pack(side=LEFT, fill=Y) #self.listbox_patients.grid(row=1, column=0) self.listbox_patients.bind("<Button-1>", self.listbox_changed) self.scrollbar = Scrollbar(sub_frame221) self.scrollbar.pack(side=RIGHT, fill=Y) # attach listbox to scrollbar self.listbox_patients.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.listbox_patients.yview) # Creating the status console. self.status_text = Text(sub_frame3, height=5) self.status_text.grid(column=0, row=0) self.status_text.tag_configure('title', justify='center', font="Arial 10 bold") self.status_text.tag_configure('entry', justify='left', font="Arial 9") self.status_text.insert(END, 'Status Console', 'title') self.status_text_entry_number = 1 self.status_text.configure(state='disabled')
class SelectPaths(MyFrame): def __init__(self, topframe=None): MyFrame.__init__(self, topframe=topframe) style = Style() style.theme_use('clam') self.patient_foler_path = "" self.patients = [] self.set_title('Brain segmentation GUI') self.add_ui_components() def add_ui_components(self): # Creating the frames. self.sub_frame1 = Frame(self) self.sub_frame1.grid(column=0, row=0) sub_frame2 = Frame(self) sub_frame2.grid(column=0, row=1) sub_frame3 = Frame(self) sub_frame3.grid(column=0, row=2) sub_frame21 = Frame(sub_frame2) sub_frame21.grid(column=0, row=0) sub_frame22 = Frame(sub_frame2) sub_frame22.grid(padx=20, column=1, row=0) sub_frame221 = Frame(sub_frame22) sub_frame221.grid(row=1, column=0) # Creating the top-menu buttons. self.visualise_button = Button(self.sub_frame1, text="Visualise", command=self.start_visualisation) self.visualise_button.grid(row=0, column=1) self.help_button = Button(self.sub_frame1, text="Help", command=self.open_help) self.help_button.grid(row=0, column=2) # Creating the select modality path. self.modality_label = Label(sub_frame21, text="Path to patient folders", relief=FLAT) self.modality_label.grid(row=1, column=1) self.modality_path_entry = Entry(sub_frame21) self.modality_path_entry.grid(row=2, column=1) #self.modality_path_entry.set(self.patient_folder_path) self.modality_path_button = Button( sub_frame21, text="Choose", command=self.choose_directory_and_import) self.modality_path_button.grid(row=2, column=2) # Creating the patients listbox. self.label_patients = Label(sub_frame22, text="Patients") self.label_patients.grid(row=0, column=0) self.listbox_patients = Listbox(sub_frame221, selectmode='multiple', width=50, height=10) self.listbox_patients.pack(side=LEFT, fill=Y) #self.listbox_patients.grid(row=1, column=0) self.listbox_patients.bind("<Button-1>", self.listbox_changed) self.scrollbar = Scrollbar(sub_frame221) self.scrollbar.pack(side=RIGHT, fill=Y) # attach listbox to scrollbar self.listbox_patients.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.listbox_patients.yview) # Creating the status console. self.status_text = Text(sub_frame3, height=5) self.status_text.grid(column=0, row=0) self.status_text.tag_configure('title', justify='center', font="Arial 10 bold") self.status_text.tag_configure('entry', justify='left', font="Arial 9") self.status_text.insert(END, 'Status Console', 'title') self.status_text_entry_number = 1 self.status_text.configure(state='disabled') # ***** EVENTS - START******************************** def start_visualisation(self): """ Launch visualisation module. Linked to self.visualise_button (Button). """ patient_path = os.path.join(self.patient_folder_path, 'processed_' + self.patients[0]) segmentation_path = os.path.join( patient_path, SEGM_PREFIX + '_' + self.patients[0] + '.nii.gz') supervoxel_path = os.path.join( patient_path, SUPERVOXEL_PREFIX + '_' + self.patients[0] + '.nii.gz') # check if the supervoxels and the segmentation exist if not os.path.exists(supervoxel_path): supervoxel_path = None if not os.path.exists(segmentation_path): segmentation_path = None mod_paths = [] for mod in MODALITY_PREFIXES: mod_paths.append(\ os.path.join(patient_path, mod+'_'+self.patients[0]+'.nii.gz')) vis = vv.VisualVolumes(image_paths=mod_paths, segm_path=segmentation_path, supervoxel_id_path=supervoxel_path, topframe=self.master) vis.tkraise() def listbox_changed(self, event): """ Add a patient upon selection in the listbox. Linked to self.listbox_patients (Listbox). """ indices = list(self.listbox_patients.curselection()) selected_idx = self.listbox_patients.nearest(event.y) if selected_idx == -1: return # remove or add a patient index if selected_idx not in indices: indices.append(selected_idx) else: indices.remove(selected_idx) # set self.patients based on the new patient indices and enable visualisation if only one is selected. self.patients = [] for idx in indices: self.patients.append(self.listbox_patients.get(idx).split(' ')[0]) if len(self.patients) == 1: self.visualise_button['state'] = 'enabled' else: self.visualise_button['state'] = 'disabled' def choose_directory_and_import(self): """ Allow the user to select an import path. Linked to self.modality_path_button (Button), and sets self.modality_path_entry (Entry). """ initialdir = DATA_PATH msg = 'Select directory containing patients' path = askdirectory(title=msg, initialdir=initialdir) # update the text box. self.modality_path_entry.delete(0, END) self.modality_path_entry.insert(0, str(path)) # Adding the modality paths after the folder is selected. self.patient_folder_path = self.modality_path_entry.get() if os.path.exists(self.patient_folder_path): patients_validation = os.listdir(self.patient_folder_path) # Checking if the patient has the right modalities and importing the patient. for i, patient in enumerate(patients_validation): # Checking if the patient was already processed. if patient.startswith('processed_') or os.path.exists( os.path.join(self.patient_folder_path, 'processed_' + patient)): print("The files of the patient " + patient + " are already copied") continue # If everything is fine, then it continues to makign folders and copying files # Copying the files into the new folder. valid = self._convert_and_copy_files(patient) if not valid: patients_validation[i] = None # We make a list of patients with only ids for the listbox. valid_patients = [p for p in patients_validation if p is not None] self.list_existing_patients(valid_patients) def _convert_and_copy_files(self, patient): """ Check if all valid files exist for this patient and return True if so. """ # Getting the list of modalities for every patient. patient_path = os.path.join(self.patient_folder_path, patient) modalities = os.listdir(patient_path) # Look for paths valid_paths = {} prefices = [SEGM_PREFIX, SUPERVOXEL_PREFIX] + MODALITY_PREFIXES for prefix in prefices: candidates = [modality \ for modality in modalities \ if modality.startswith(prefix+'.')] if len(candidates) != 1: err = '%s file not identified. Look for ambiguities in %s.' \ % (prefix, patient_path) print(err) return False modality = candidates[0] if not any([ modality.endswith(ext) for ext in ['.mha', '.nii', '.nii.gz'] ]): err = "Image format not recognized: %s. In %s" \ % (modality, patient_path) print(err) return False valid_paths[prefix] = modality # Creating a processed patient folder. os.mkdir(os.path.join(self.patient_folder_path, 'processed_' + patient)) for prefix, basename in valid_paths.iteritems(): shutil.copyfile( os.path.join(self.patient_folder_path, patient, basename), os.path.join(self.patient_folder_path, 'processed_' + patient, prefix + '_' + patient + '.nii.gz')) return True def open_help(self): self.help_window = help_window.HelpWindow() self.help_window.tkraise() # ***** EVENTS - END*************************** def list_existing_patients(self, patients=None): print("Importing existing patients") # We make a list of patients with only ids for the listbox. if patients is None: patients = os.listdir(self.patient_folder_path) self.patients = [] for patient in patients: if not patient.startswith('processed_'): self.patients.append(patient) self.patients.sort() self.populate_patient_listbox(self.patients) if self.listbox_patients.size() > 0: self.listbox_patients.selection_set(0) self.status_text.configure(state='normal') self.status_text.insert( END, '\n' + str(self.status_text_entry_number) + '- Patients are imported.', 'entry') self.status_text_entry_number += 1 self.status_text.insert( END, '\n' + str(self.status_text_entry_number) + '- Please select a patient to proceed', 'entry') self.status_text_entry_number += 1 self.status_text.configure(state='disabled') def populate_patient_listbox(self, patients): self.listbox_patients.delete(0, END) for patient in patients: patient_path = os.path.join(self.patient_folder_path, 'processed_' + patient) #check if a given patient has a label if os.path.exists( os.path.join( patient_path, 'corrected_' + SEGM_PREFIX + '_' + patient + '.nii.gz')): patient = patient + ' - segmentation corrected' self.listbox_patients.insert(END, patient)
class MultiTextBox(): def __init__(self, frm): self.frame = Frame(frm.frame) self.frame.grid() self.widget = Text(frm.frame, height=5, width=30, background='white')
def configure_images(self, pic_frame, image_paths): """Create widgets to place images, descriptions and slice scrollers.""" # create a sub frame to display the images self._imagelabel = [None for _ in range(self.image_nb)] self._image_view = [None for _ in range(self.image_nb)] _descrlabel = [None for _ in range(self.image_nb)] # descriptions of the images defaults to their path basenames descriptions = [os.path.basename(image_paths[i]) for i in range(self.image_nb)] self.histogram_sliders = [] for i in range(self.image_nb): _sub_pic_frame = Frame(pic_frame) _sub_pic_frame.grid(column=int(i%2), row=int(i/2), pady=5) # set Label for a description above the images _descrlabel[i] = Label(_sub_pic_frame, text=descriptions[i]) _descrlabel[i].grid(column=0, row=0) # set Label to depict the images self._imagelabel[i] = Label(_sub_pic_frame) self._imagelabel[i].grid(column=0, row=1) # set Scales for the intensity slides _sub_sub_frame = Frame(_sub_pic_frame) _sub_sub_frame.grid(column=0, row=2) min_val = np.min(self.images_original[i]) max_val = np.max(self.images_original[i]) intensity_scale1 = Scale(_sub_sub_frame, from_=min_val, to=max_val/2, orient=HORIZONTAL) intensity_scale1.set(min_val) intensity_scale1.grid(column=0, row=0, sticky=['e', 'w', 's']) intensity_scale2 = Scale(_sub_sub_frame, from_=max_val/2, to=max_val, orient=HORIZONTAL) intensity_scale2.set(max_val) intensity_scale2.grid(column=1, row=0, sticky=['e', 'w', 's']) self.histogram_sliders.append(intensity_scale1) self.histogram_sliders.append(intensity_scale2) intensity_scale1.bind("<B1-Motion>", self.change_intensity) intensity_scale2.bind("<B1-Motion>", self.change_intensity) # Attach commands to the image frames self._imagelabel[i].bind("<Button-1>", self.click_image) self._imagelabel[i].bind("<Button-3>", self.label_dropdown) self._imagelabel[i].bind("<Button 4>", self.slice_up) self._imagelabel[i].bind("<Button 5>", self.slice_down) self._imagelabel[i].bind("<B1-Motion>", self.motion_image) self._imagelabel[i].bind("<Double-Button-1>", self.select_connected)
class Reader(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() def initUI(self): self.parent.title("Graphs") self.style = Style() self.style.theme_use("clam") self.pack(fill=BOTH, expand=1) self.columnconfigure(1, weight=1) self.columnconfigure(3, weight=1) self.columnconfigure(6, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) menu = Menu(self.parent) self.parent.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_command(label="Load data",command = self.load_data) # lable to show current file and chanel self.file_lbl = Label(self, text="") self.file_lbl.grid(row = 0 , column = 3, pady=4, padx=5) # list box fro data files self.file_list = ScrolledList(self,lambda x: self.load_hunt_data(x)) self.file_list.grid(row=1, column=0, columnspan=3, rowspan=4, padx=5, sticky=E+W+S+N) # chanel graph viewer self.graph_viewer = TkinterGraph(self) self.graph_viewer.grid(row=1, column=3, columnspan=2, rowspan=4, padx=5, sticky=E+W+S+N) btn1 = Button(self, text="Left",command = lambda: self.plot_left()) btn1.grid(row=1, column=6) btn2 = Button(self, text="Right", command = lambda:self.plot_right()) btn2.grid(row=2, column=6, pady=4) # frames for the classifier for the two chanels self.frame_left = Frame(self, borderwidth=1) self.frame_right = Frame(self, borderwidth=1) self.frame_left.grid(row=5,column=3,columnspan=2, rowspan=1) btn4 = Button(self, text="SAVE", command = lambda:self.save_graph()) btn4.grid(row=5, column=6) # note manual addition of labels so that the lable will be to the right of tha radio button self.classify_left = StringVar() Label(self.frame_left,text="Left :").pack(side=LEFT) Label(self.frame_left,text="Type A").pack(side=LEFT) rb1 = Radiobutton(self.frame_left,variable=self.classify_left,value="TypeA") rb1.pack(side=LEFT) Label(self.frame_left,text="Type B").pack(side=LEFT) rb1 = Radiobutton(self.frame_left,variable=self.classify_left,value="TypeB") rb1.pack(side=LEFT) Label(self.frame_left,text="Type C").pack(side=LEFT) rb1 = Radiobutton(self.frame_left,variable=self.classify_left,value="TypeC") rb1.pack(side=LEFT) Label(self.frame_left,text="Type D").pack(side=LEFT) rb1 = Radiobutton(self.frame_left,variable=self.classify_left,value="TypeD") rb1.pack(side=LEFT) self.classify_right = StringVar() Label(self.frame_right,text="Right :").pack(side=LEFT) Label(self.frame_right,text="Type A").pack(side=LEFT) rb1 = Radiobutton(self.frame_right,variable=self.classify_right,value="TypeA") rb1.pack(side=LEFT) Label(self.frame_right,text="Type B").pack(side=LEFT) rb1 = Radiobutton(self.frame_right,variable=self.classify_right,value="TypeB") rb1.pack(side=LEFT) Label(self.frame_right,text="Type C").pack(side=LEFT) rb1 = Radiobutton(self.frame_right,variable=self.classify_right,value="TypeC") rb1.pack(side=LEFT) Label(self.frame_right,text="Type D").pack(side=LEFT) rb1 = Radiobutton(self.frame_right,variable=self.classify_right,value="TypeD") rb1.pack(side=LEFT) def load_data(self): # calls the file dialog box name = askopenfilename() (d_path,d_name)=split(name) # just want to extract the path of the file self.mypath = d_path # get 'filtered' files from that path files = self.get_files() # display in the list box self.file_list.load_data(files) def load_hunt_data(self,selection): (self.indx , self.filename) = selection d_file = join(self.mypath,self.filename) l_array=[] r_array=[] with open(d_file) as f: for line in f: data = line.split(',') if data[5]!='': r_array.append(data[5]) # RL_PVR l_array.append(data[6]) # LL_PVR self.rawy_l = numpy.array(l_array[1:]) # form 1 romove headder self.rawy_r = numpy.array(r_array[1:]) self.rawx = [i for i in range(len(self.rawy_l))] # reset the classification buttons self.classify_left.set("TypeA") self.classify_right.set("TypeA") self.plot_left() def plot_left(self): # choose th correct fram of radio buttons self.frame_right.grid_forget() self.frame_left.grid(row=5,column=3,columnspan=2, rowspan=1) # change display name self.file_lbl.configure(text=self.filename+" : Left") self.graph_viewer.change_data(self.rawx,self.rawy_l) def plot_right(self): self.frame_left.grid_forget() self.frame_right.grid(row=5,column=3,columnspan=2, rowspan=1) self.file_lbl.configure(text=self.filename+" : Right") self.graph_viewer.change_data(self.rawx,self.rawy_r) def save_graph(self): self.file_list.remove_item(self.indx) d_file = join(self.mypath,self.filename) # add a done prefix to the file name n_file = join(self.mypath,"done-"+self.filename) rename(d_file,n_file) # get the front of the filename fparts = self.filename.split('.') # save data wit the same name but with the chanel prefix and a dat postfix l_file = join(self.mypath,self.classify_left.get()+'-Left-'+fparts[0]+'.dat') # open file to write f = open(l_file, 'w') for v in self.rawy_l: f.write(v+'\n') f.close() r_file = join(self.mypath,self.classify_right.get()+'-Right-'+fparts[0]+'.dat') # open file to write f = open(r_file, 'w') for v in self.rawy_r: f.write(v+'\n') f.close() def get_files(self): files = [] for filename in listdir(self.mypath): # just get the files # note that it has to have the compleate path and name if isfile(join(self.mypath,filename)): # split the file name in to parts files.append(filename) #parts = filename.split('.') #print parts[-1] return files
def __init__(self, root): self.root = root ###CANVAS### im = PIL.Image.open('field.jpg') self.canvas = tk.Canvas(root, width=1300, height=846) self.canvas.grid(row=0, column=0) self.canvas.image = ImageTk.PhotoImage(im) self.canvas.create_image(635, 423, image=self.canvas.image) self.canvas.create_rectangle(0, 843, 200, 846, fill="blue") self.canvas.create_rectangle(0, 843, 3, 646, fill="red") self.canvas.create_text(200, 836, text="X", fill="blue") self.canvas.create_text(10, 646, text="Y", fill="red") ###FRAME### frame = Frame(self.root) frame.grid(row=0, column=1, sticky=W) ###ROBOT-COORDINATES###SMALL RobotCoordinates = Label(frame, text="SMALL ROBOT") RobotCoordinates.grid(row=1, column=1) Coordinates = Label(frame, text="Robot Coordinates: ") Coordinates.grid(row=6, column=1, sticky=W) curX = Label(frame, text="X =") curX.grid(row=7, column=1, sticky=E) curY = Label(frame, text="Y =") curY.grid(row=8, column=1, sticky=E) curA = Label(frame, text="A =") curA.grid(row=9, column=1, sticky=E) self.curXValue = Text(frame, height=1, width=5) self.curXValue.grid(row=7, column=2, sticky=W) self.curYValue = Text(frame, height=1, width=5) self.curYValue.grid(row=8, column=2, sticky=W) self.curAValue = Text(frame, height=1, width=5) self.curAValue.grid(row=9, column=2, sticky=W) ###LIDAR-COORDINATES### CoordinatesL = Label(frame, text="Lidar Coordinates: ") CoordinatesL.grid(row=10, column=1, sticky=W) curXL = Label(frame, text="X =") curXL.grid(row=11, column=1, sticky=E) curYL = Label(frame, text="Y =") curYL.grid(row=12, column=1, sticky=E) curAL = Label(frame, text="A =") curAL.grid(row=13, column=1, sticky=E) self.curXLValue = Text(frame, height=1, width=5) self.curXLValue.grid(row=11, column=2, sticky=W) self.curYLValue = Text(frame, height=1, width=5) self.curYLValue.grid(row=12, column=2, sticky=W) self.curALValue = Text(frame, height=1, width=5) self.curALValue.grid(row=13, column=2, sticky=W) ###COLLISION AVOIDANCE### coll = Label(frame, text="Collision:") coll.grid(row=14, column=1) self.collValue = Text(frame, height=1, width=3) self.collValue.grid(row=14, column=2, sticky=W) ###ADC### ADC = Label(frame, text="Client Small: ") ADC.grid(row=15, column=1) self.ADCValue = Text(frame, height=10, width=10) self.ADCValue.grid(row=16, column=1) ###BIG ROBOT######## ###BIG ROBOT### ###BIG ROBOT COORDINATES### RobotCoordinatesB = Label(frame, text="BIG ROBOT") RobotCoordinatesB.grid(row=1, column=3) CoordinatesB = Label(frame, text="Robot Coordinates: ") CoordinatesB.grid(row=6, column=3, sticky=W) curXB = Label(frame, text="X =") curXB.grid(row=7, column=3, sticky=E) curYB = Label(frame, text="Y =") curYB.grid(row=8, column=3, sticky=E) curAB = Label(frame, text="A =") curAB.grid(row=9, column=3, sticky=E) self.curXBValue = Text(frame, height=1, width=5) self.curXBValue.grid(row=7, column=4, sticky=W) self.curYBValue = Text(frame, height=1, width=5) self.curYBValue.grid(row=8, column=4, sticky=W) self.curABValue = Text(frame, height=1, width=5) self.curABValue.grid(row=9, column=4, sticky=W) ###BIG ROBOT LIDAR-COORDINATES### CoordinatesLB = Label(frame, text="Lidar Coordinates: ") CoordinatesLB.grid(row=10, column=3, sticky=W) curXLB = Label(frame, text="X =") curXLB.grid(row=11, column=3, sticky=E) curYLB = Label(frame, text="Y =") curYLB.grid(row=12, column=3, sticky=E) curALB = Label(frame, text="A =") curALB.grid(row=13, column=3, sticky=E) self.curXLBValue = Text(frame, height=1, width=5) self.curXLBValue.grid(row=11, column=4, sticky=W) self.curYLBValue = Text(frame, height=1, width=5) self.curYLBValue.grid(row=12, column=4, sticky=W) self.curALBValue = Text(frame, height=1, width=5) self.curALBValue.grid(row=13, column=4, sticky=W) ### BIG ROBOT COLLISION AVOIDANCE### collB = Label(frame, text="Collision:") collB.grid(row=14, column=3) self.collBValue = Text(frame, height=1, width=3) self.collBValue.grid(row=14, column=4, sticky=W) ###BIG ROBOT ADC### ADCB = Label(frame, text="Client Big: ") ADCB.grid(row=15, column=3) self.ADCBValue = Text(frame, height=10, width=10) self.ADCBValue.grid(row=16, column=3)
class TabSettings(Frame): def __init__(self, parent, txt=dict(), switcher=None): """Instanciating the output workbook.""" self.parent = parent Frame.__init__(self) # subframes self.FrOptProxy = Frame(self, name='settings_proxy') self.FrOptIsogeo = Frame(self, name='settings_isogeo') # options values self.opt_proxy = IntVar(self) # proxy option self.opt_isogeo = IntVar(self) # Isogeo option # Options form widgets caz_prox = Checkbutton( self, text=u'Proxy', variable=self.opt_proxy, command=lambda: switcher(self.opt_proxy, self.FrOptProxy)) caz_isogeo = Checkbutton( self, text=u'Isogeo', variable=self.opt_isogeo, command=lambda: switcher(self.opt_isogeo, self.FrOptIsogeo)) # positionning caz_prox.grid(row=0, column=0, sticky="NSWE", padx=2, pady=2) self.FrOptProxy.grid(row=0, column=1, columnspan=8, sticky="NSWE", padx=2, pady=2, rowspan=3) caz_isogeo.grid(row=3, column=0, sticky="NSWE", padx=2, pady=2) self.FrOptIsogeo.grid(row=3, column=1, columnspan=8, sticky="NSWE", padx=2, pady=2, rowspan=4) # ------------------------------------------------------------------------ # proxy specific variables self.opt_ntlm = IntVar(self.FrOptProxy, 0) # proxy NTLM protocol option self.prox_server = StringVar(self.FrOptProxy, 'proxy.server.com') self.prox_port = IntVar(self.FrOptProxy, 80) self.prox_user = StringVar(self.FrOptProxy, 'proxy_user') self.prox_pswd = StringVar(self.FrOptProxy, '****') # widgets self.prox_ent_H = Entry(self.FrOptProxy, textvariable=self.prox_server) self.prox_ent_P = Entry(self.FrOptProxy, textvariable=self.prox_port) self.prox_ent_M = Entry(self.FrOptProxy, textvariable=self.prox_pswd, show='*') self.prox_lb_H = Label(self.FrOptProxy, text=txt.get('gui_prox_server', "Host")) self.prox_lb_P = Label(self.FrOptProxy, text=txt.get('gui_port', "Port")) caz_ntlm = Checkbutton(self.FrOptProxy, text=u'NTLM', variable=self.opt_ntlm) self.prox_lb_M = Label(self.FrOptProxy, text=txt.get('gui_mdp', "Password")) # proxy widgets position self.prox_lb_H.grid(row=1, column=0, sticky="NSEW", padx=2, pady=2) self.prox_ent_H.grid(row=1, column=1, columnspan=2, sticky="NSEW", padx=2, pady=2) self.prox_lb_P.grid(row=1, column=2, sticky="NSEW", padx=2, pady=2) self.prox_ent_P.grid(row=1, column=3, columnspan=2, sticky="NSEW", padx=2, pady=2) caz_ntlm.grid(row=2, column=0, sticky="NSEW", padx=2, pady=2) self.prox_lb_M.grid(row=2, column=1, sticky="NSEW", padx=2, pady=2) self.prox_ent_M.grid(row=2, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2) # ------------------------------------------------------------------------ # Isogeo application variables self.isog_app_id = StringVar(self.FrOptIsogeo, 'application_id') self.isog_app_tk = StringVar(self.FrOptIsogeo, 'secret') # widgets isog_ent_id = Entry(self.FrOptIsogeo, textvariable=self.isog_app_id) isog_ent_tk = Entry(self.FrOptIsogeo, textvariable=self.isog_app_tk) isog_lb_id = Label(self.FrOptIsogeo, text="Application ID") isog_lb_tk = Label(self.FrOptIsogeo, text="Application secret") # Isogeo widgets position isog_lb_id.grid(row=1, column=1, sticky="NSEW", padx=2, pady=2) isog_ent_id.grid(row=1, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2) isog_lb_tk.grid(row=2, column=1, sticky="NSEW", padx=2, pady=2) isog_ent_tk.grid(row=2, column=2, columnspan=2, sticky="NSEW", padx=2, pady=2)
class CheckBox(): def __init__(self, frm, name): self.frame = Frame(frm.frame) self.frame.grid() self.widget = Checkbutton(frm.frame, text=name)
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 Window(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.initUI() self.UIwithGrid() def initUI(self): # creating gui self.frame1 = Frame(self) self.frame2 = Frame(self) self.frame3 = Frame(self) self.frame4 = Frame(self) self.frame5 = Frame(self) # created multiple frames self.label1 = Label(self.frame1, text="COURSE PROGRAM ESTIMATOR", font='Helvetica 25 bold', background="SpringGreen3", foreground="black") self.label2 = Label(self.frame1, text=" Training Data: ", font="Times 14") self.entry = Entry(self.frame1, width=65) self.entry.insert( 0, 'https://www.sehir.edu.tr/tr/duyurular/2017-2018-Akademik-Yili-Ders-Programi' ) self.color = Label( self.frame1, text=" ", background="red", ) self.button = Button(self.frame1, text="Fetch and Train", command=self.fetch) self.label3 = Label(self.frame2, text="Individual Courses:", font='Helvetica 10 bold') self.label4 = Label(self.frame3, text=" Top 3 Estimates:", font='Helvetica 10 bold') self.coursesListbox = Listbox(self.frame2, width=30) self.label5 = Label(self.frame4, text=" Accuracy Analysis \nBased on Programs: ", font='Helvetica 10 bold') self.programsListbox = Listbox(self.frame4, width=30) self.estimatesListbox = Text(self.frame5, width=30, height=10) self.scrollbar1 = Scrollbar(self.frame2, orient=VERTICAL) self.scrollbar2 = Scrollbar(self.frame4, orient=VERTICAL) self.scrollbar3 = Scrollbar(self.frame5, orient=VERTICAL) self.scrollbar1.config(command=self.coursesListbox.yview) self.scrollbar2.config(comman=self.programsListbox.yview) self.scrollbar3.config(command=self.estimatesListbox.yview) self.coursesListbox.config(yscrollcommand=self.scrollbar1.set) self.programsListbox.config(yscrollcommand=self.scrollbar2.set) self.estimatesListbox.config(yscrollcommand=self.scrollbar3.set) def UIwithGrid(self): self.frame1.grid(row=1, column=2, sticky=N + S + E + W) self.frame2.grid(row=2, column=1, columnspan=2, sticky=W) self.frame3.grid(row=2, column=2, sticky=N + E) self.frame4.grid(row=3, column=1, columnspan=2, sticky=W, pady=5) self.frame5.grid(row=3, column=2, columnspan=2, sticky=E, pady=5) self.label1.grid(row=1, column=2, sticky=E + W) self.label2.grid(row=2, column=1, columnspan=2, pady=25, sticky=W) self.entry.grid(row=2, column=2, columnspan=2, sticky=E) self.color.grid(row=3, column=2, columnspan=2) self.button.grid(row=3, column=2, sticky=E, padx=90) self.label3.grid(row=1, column=1) self.coursesListbox.grid(row=2, column=1) self.label4.pack(in_=self.frame3, side='left') self.label5.grid(row=1, column=1) self.programsListbox.grid(row=2, column=1) self.estimatesListbox.grid(row=2, column=3, sticky=E) self.scrollbar1.grid(row=2, column=1, sticky=N + S + E) self.scrollbar2.grid(row=2, column=1, sticky=N + E + S) self.scrollbar3.grid(row=2, column=2, columnspan=2, sticky=N + S + E) self.pack() def fetch(self): # fetching phase self.color.config(background='yellow') self.course_list = [] self.update() url = self.entry.get() self.dataobj = Data() # creating data obj self.dataobj.init_data(url) self.courses = self.dataobj.courselist.keys() # getting keys self.courses.sort() # sorting keys self.obj_list = [] for i in self.courses: self.obj_list.append(self.dataobj.courselist[i]) self.classifier_obj = docclass.naivebayes(docclass.getwords) for i in self.obj_list: # TRANING PHASE self.classifier_obj.train(i.split_name.lower(), i.first_code) r1 = re.compile("(.*?)\s*\(") for i in self.courses: # adding courses to listbox course_name = self.dataobj.courselist[i].name name = r1.match(course_name) if name != None: name1 = i + '' + '(' + name.group(1) + ')' else: name1 = i + ' ' + '(' + course_name + ')' self.coursesListbox.insert(END, name1) for z in self.courses: # adding course category to other listbox if self.dataobj.courselist[z].first_code not in self.course_list: self.course_list.append(self.dataobj.courselist[z].first_code) code = self.dataobj.courselist[z].first_code if code not in self.programsListbox.get(0, END): self.programsListbox.insert(END, code) self.color.config(background='green') self.update() self.coursesListbox.bind('<<ListboxSelect>>', self.estimate) self.programsListbox.bind('<<ListboxSelect>>', self.analyze) def estimate(self, event): # estimating phase try: for wid in self.frame3.winfo_children(): wid.destroy() self.label4 = Label(self.frame3, text=" Top 3 Estimates:", font='Helvetica 10 bold') self.label4.pack(in_=self.frame3) except: print 'ERROR !!!!' widget = event.widget selection = widget.curselection() picked = widget.get(selection[0]) x = picked.split('(') dict_ = {} for cat in self.course_list: # getting estimating scores dict_[cat] = self.classifier_obj.prob(x[1], cat) * 10 scores = dict_ sorted_scores = sorted(scores.items(), key=operator.itemgetter(1), reverse=True) # sorting dictionary top_3 = sorted_scores[0:3] # getting top 3 scores print top_3 dict_temp = {x[0].split(' ')[0]: top_3} m = 1 for key, value in dict_temp.items(): # adding items as labels for i in value: department, score = i if department != key: # checking if it is true estimation or not color = 'red' else: color = 'green' self.first_element = Label(self.frame3, text=department + ':' + str(score), font='Helvetica 15 bold', background=color, width=20) if m == 1: self.first_element.pack(in_=self.frame3) elif m == 2: self.first_element.pack(in_=self.frame3) elif m == 3: self.first_element.pack(in_=self.frame3) m = m + 1 def analyze(self, event): try: self.estimatesListbox.delete('1.0', END) except: print 'ERROR' widget = event.widget selection = widget.curselection() picked = widget.get(selection[0]) cat_ = picked course_names = {} for i in self.obj_list: # creating a dict. keys name of courses, values code of if i.first_code == cat_: # filtering print i.first_code, cat_ name = i.name.split('(')[0] course_names[name] = i.code else: continue info = {} for course in course_names.keys(): # finds best match for each course score_dict = {} for cat in self.course_list: score_dict[cat] = self.classifier_obj.prob(course, cat) sorted_scores = sorted(score_dict.items(), key=operator.itemgetter(1), reverse=True) info[course] = sorted_scores[0][0] all_info = { 'Total Number Of Courses: ': str(len(info)) } # creating initial analyzing data q = 0 for item in info.values(): # amount of accurate data if item != cat_: q = q + 1 all_info['Inaccurate Classification: '] = str(q) all_info['Accurately Classified: '] = len(info) - q all_info['Accuracy: '] = '%' + str( (float(all_info['Accurately Classified: ']) / float(len(info))) * 100) _ = all_info.keys() _.sort() for infos in _: self.estimatesListbox.insert(END, infos + str(all_info[infos]) + '\n ') for course_ in info: self.estimatesListbox.insert( END, '\t' + course_names[course_] + '-->' + info[course_] + '\n')
def __init__(self, root): self.root = root self.entry = tk.Entry(root) stvar = tk.StringVar() stvar.set("one") ###CANVAS### im = PIL.Image.open('field.jpg') canvas = tk.Canvas(root, width=1300, height=846) canvas.grid(row=0, column=0) """canvas.create_oval(10, 10, 80, 80, outline="gray", fill="gray", width=2) canvas.create_oval(110, 10, 210, 80, outline="gray", fill="gray", width=2) canvas.create_rectangle(230, 10, 290, 60, outline="gray", fill="gray", width=2) canvas.create_arc(30, 200, 90, 100, start=0, extent=210, outline="gray", fill="gray", width=2)""" canvas.image = ImageTk.PhotoImage(im) canvas.create_image(635, 423, image=canvas.image) canvas.create_rectangle(0, 843, 200, 846, fill="blue") canvas.create_rectangle(0, 843, 3, 646, fill="red") canvas.create_text(200, 836, text="X", fill="blue") canvas.create_text(10, 646, text="Y", fill="red") ###ROBOTS### """points = [150, 100, 300, 120, 240, 180] canvas.create_polygon(points, outline='gray', fill='gray', width=2)""" angle = 120 length = 10 alpha = angle * pi / 180 points_small = [100, 200, 220, 320] points_big = [200, 500, 300, 400] canvas.create_oval(points_small, outline="blue", fill="white", width=5) #small robot #canvas.create_line(points_small[1]-points_small[0],points_small[3]-points_small[2],(points_small[2]-points_small[0])+length*cos(alpha),(points_small[3]-points_small[1])+length*sin(alpha), fill="blue", width = 5) canvas.create_rectangle(points_big, outline="red", fill="white", width=5) #big robot #canvas.create_line(points_big[2]-points_big[0],points_big[3]-points_big[1],points_big[2]-points_big[0]+length*cos(alpha),points_big[3]-points_big[1]+length*sin(alpha), fill="red", width=5) ###FRAME### frame = Frame(self.root) frame.grid(row=0, column=1, sticky=W) ###STACK### Stack = Label(frame, text="Stack: ") Stack.grid(row=0, column=1, sticky=W) cntPoint = Label(frame, text="cntPoint = ") cntPoint.grid(row=1, column=1, columnspan=1, sticky=E) curPoint = Label(frame, text="curPoint = ") curPoint.grid(row=2, column=1, sticky=E) nextX = Label(frame, text="nextX =") nextX.grid(row=3, column=1, sticky=E) nextY = Label(frame, text="nextY = ") nextY.grid(row=4, column=1, sticky=E) nextA = Label(frame, text="nextA = ") nextA.grid(row=5, column=1, sticky=E) cntPointValue = Text(frame, height=1, width=5) cntPointValue.grid(row=1, column=2, sticky=W) curPointValue = Text(frame, height=1, width=5) curPointValue.grid(row=2, column=2, sticky=W) nextXValue = Text(frame, height=1, width=5) nextXValue.grid(row=3, column=2, sticky=W) nextYValue = Text(frame, height=1, width=5) nextYValue.grid(row=4, column=2, sticky=W) nextAValue = Text(frame, height=1, width=5) nextAValue.grid(row=5, column=2, sticky=W) ###ROBOT-COORDINATES### Coordinates = Label(frame, text="Robot Coordinates: ") Coordinates.grid(row=6, column=1, sticky=W) curX = Label(frame, text="X =") curX.grid(row=7, column=1, sticky=E) curY = Label(frame, text="Y =") curY.grid(row=8, column=1, sticky=E) curA = Label(frame, text="A =") curA.grid(row=9, column=1, sticky=E) curXValue = Text(frame, height=1, width=5) curXValue.grid(row=7, column=2, sticky=W) curYValue = Text(frame, height=1, width=5) curYValue.grid(row=8, column=2, sticky=W) curAValue = Text(frame, height=1, width=5) curAValue.grid(row=9, column=2, sticky=W) ###LIDAR-COORDINATES### CoordinatesL = Label(frame, text="Lidar Coordinates: ") CoordinatesL.grid(row=10, column=1, sticky=W) curXL = Label(frame, text="X =") curXL.grid(row=11, column=1, sticky=E) curYL = Label(frame, text="Y =") curYL.grid(row=12, column=1, sticky=E) curAL = Label(frame, text="A =") curAL.grid(row=13, column=1, sticky=E) curXLValue = Text(frame, height=1, width=5) curXLValue.grid(row=11, column=2, sticky=W) curYLValue = Text(frame, height=1, width=5) curYLValue.grid(row=12, column=2, sticky=W) curALValue = Text(frame, height=1, width=5) curALValue.grid(row=13, column=2, sticky=W) ###COLLISION AVOIDANCE### coll = Label(frame, text="Collision:") coll.grid(row=14, column=1) collValue = Text(frame, height=1, width=3) collValue.grid(row=14, column=2, sticky=W) ###ADC### ADC = Label(frame, text="ADC: ") ADC.grid(row=15, column=1) ADCValue = Text(frame, height=10, width=10) ADCValue.grid(row=16, column=1) ###INPUTS### INPUTS = Label(frame, text="INPUTS:") INPUTS.grid(row=17, column=1) INPUTSValue = Text(frame, height=10, width=10) INPUTSValue.grid(row=18, column=1) ###BUTTONS### startButton = Button(frame, text="START") startButton.grid(row=18, column=2, sticky=S, pady=30) #startButton.bind('<Button-1>', start_server()) stopButton = Button(frame, text="STOP") stopButton.grid(row=18, column=2, sticky=S)
def set_optional_buttons(self, supervoxel_id_path=None): """ Set bottoms to quit, change axis, show and hide segmentation, ... at the upper row of the main frame. """ _sub_frame1 = Frame(self) _sub_frame1.grid(column=0, row=0, padx=10, sticky=['n', 'e', 'w']) _sub_sub_frame1 = Frame(_sub_frame1) _sub_sub_frame1.grid(column=0, row=0, sticky=['e', 'w'], pady=10) ind = 0 self.button_axis = Button(_sub_sub_frame1, text="Change axis", command=self.change_axis) self.button_axis.grid(column=0, row=ind, pady=3) ind += 1 self.button_axis = Button(_sub_sub_frame1, text="Mirror Images", command=self.mirror_image) self.button_axis.grid(column=0, row=ind, pady=3) ind = 0 if self.segm is not None: _sub_sub_frame2 = Frame(_sub_frame1) _sub_sub_frame2.grid(column=0, row=1, sticky=['e', 'w'], pady=10) _sub_sub_frame3 = Frame(_sub_frame1) _sub_sub_frame3.grid(column=0, row=2, sticky=['e', 'w'], pady=10) self.button_supervoxels = Button(_sub_sub_frame2, text="Show/Hide supervoxels", command=self.change_supervoxels) self.button_supervoxels.grid(column=0, row=ind, sticky=['w', 'n', 'e']) if supervoxel_id_path is None: self.button_supervoxels['state'] = 'disabled' ind += 1 self.tumor_checkbox_label = Label(_sub_sub_frame2, text="Display tumor type: ", relief=FLAT) self.tumor_checkbox_label.grid(column=0, row=ind) ind += 1 self.tumor_cb = [] for i in range(len(labels)): tumor_button = IntVar() this_text = '%s (%s <%s>)' % (labels[i], label_colors_d[i], label_hot_keys[i+1]) button = Checkbutton(_sub_sub_frame2, text=this_text, variable=tumor_button, command=lambda arg0=i: self.change_segm(arg0)) button.grid(column=0, row=ind, sticky=['w', 'n', 'e']) self.tumor_cb.append(tumor_button) ind += 1 self.all_tumor_bc = IntVar() button = Checkbutton(_sub_sub_frame2, text="All tumors", variable=self.all_tumor_bc, command=lambda : self.change_segm(3)) button.grid(column=0, row=ind, sticky=['w', 'n', 'e']) ind += 1 self.no_tumor_bc = IntVar() button = Checkbutton(_sub_sub_frame2, text="No tumors", variable=self.no_tumor_bc, command=lambda : self.change_segm(4)) button.grid(column=0, row=ind, sticky=['w', 'n', 'e']) ind += 1 alpha_label = Label(_sub_sub_frame2, text="Opacity:") alpha_label.grid(column=0, row=ind) self.alpha_scale = Scale(_sub_sub_frame2, from_=0.0, to=1.0, command=self.set_alpha, orient=HORIZONTAL) ind += 1 self.alpha_scale.set(self.alpha) self.alpha_scale.grid(column=0, row=ind, columnspan=self.image_nb, sticky=['w', 'n', 'e']) ind = 0 self.button_save_segm = Button(_sub_sub_frame3, text="Save segmentation", command=self.save_segm) self.button_save_segm.grid(column=0, row=ind, sticky=['w', 'n', 'e']) ind += 1 self.button_open_segm = Button(_sub_sub_frame3, text="Open segmentation", command=self.open_segm) self.button_open_segm.grid(column=0, row=ind, sticky=['w', 'n', 'e'])
def __init__(self, root): self.root=root ###CANVAS### im = PIL.Image.open('field.jpg') self.canvas=tk.Canvas(root, width=1300, height=846) self.canvas.grid(row=0, column=0) self.canvas.image = ImageTk.PhotoImage(im) self.canvas.create_image(635,423,image = self.canvas.image) self.canvas.create_rectangle(0,843, 200, 846, fill="blue") self.canvas.create_rectangle(0,843, 3, 646, fill="red") self.canvas.create_text(200, 836, text="X", fill="blue") self.canvas.create_text(10, 646, text="Y", fill="red") ###FRAME### frame=Frame(self.root) frame.grid(row=0,column=1, sticky=W) ###ROBOT-COORDINATES###SMALL RobotCoordinates = Label(frame, text = "SMALL ROBOT") RobotCoordinates.grid(row = 1, column = 1) Coordinates = Label(frame, text="Robot Coordinates: ") Coordinates.grid(row = 6, column = 1, sticky=W) curX = Label(frame, text="X =") curX.grid(row=7, column=1, sticky=E) curY = Label(frame, text="Y =") curY.grid(row=8, column=1, sticky=E) curA = Label(frame, text="A =") curA.grid(row=9, column=1, sticky=E) self.curXValue = Text(frame, height=1, width=5) self.curXValue.grid(row=7, column=2, sticky=W) self.curYValue = Text(frame, height=1, width=5) self.curYValue.grid(row=8, column=2, sticky=W) self.curAValue = Text(frame, height=1, width=5) self.curAValue.grid(row=9, column=2, sticky=W) ###LIDAR-COORDINATES### CoordinatesL = Label(frame, text="Lidar Coordinates: ") CoordinatesL.grid(row = 10, column = 1, sticky=W) curXL = Label(frame, text="X =") curXL.grid(row=11, column=1, sticky=E) curYL = Label(frame, text="Y =") curYL.grid(row=12, column=1, sticky=E) curAL = Label(frame, text="A =") curAL.grid(row=13, column=1, sticky=E) self.curXLValue = Text(frame, height=1, width=5) self.curXLValue.grid(row=11, column=2, sticky=W) self.curYLValue = Text(frame, height=1, width=5) self.curYLValue.grid(row=12, column=2, sticky=W) self.curALValue = Text(frame, height=1, width=5) self.curALValue.grid(row=13, column=2, sticky=W) ###COLLISION AVOIDANCE### coll = Label(frame, text="Collision:") coll.grid(row = 14, column = 1) self.collValue = Text(frame, height=1, width=3) self.collValue.grid(row=14,column=2,sticky=W) ###ADC### ADC = Label(frame, text="Client Small: ") ADC.grid(row = 15, column = 1) self.ADCValue = Text(frame, height=10, width=10) self.ADCValue.grid(row=16, column=1) ###BIG ROBOT######## ###BIG ROBOT### ###BIG ROBOT COORDINATES### RobotCoordinatesB = Label(frame, text = "BIG ROBOT") RobotCoordinatesB.grid(row = 1, column = 3) CoordinatesB = Label(frame, text="Robot Coordinates: ") CoordinatesB.grid(row = 6, column = 3, sticky=W) curXB = Label(frame, text="X =") curXB.grid(row=7, column=3, sticky=E) curYB = Label(frame, text="Y =") curYB.grid(row=8, column=3, sticky=E) curAB = Label(frame, text="A =") curAB.grid(row=9, column=3, sticky=E) self.curXBValue = Text(frame, height=1, width=5) self.curXBValue.grid(row=7, column=4, sticky=W) self.curYBValue = Text(frame, height=1, width=5) self.curYBValue.grid(row=8, column=4, sticky=W) self.curABValue = Text(frame, height=1, width=5) self.curABValue.grid(row=9, column=4, sticky=W) ###BIG ROBOT LIDAR-COORDINATES### CoordinatesLB = Label(frame, text="Lidar Coordinates: ") CoordinatesLB.grid(row = 10, column = 3, sticky=W) curXLB = Label(frame, text="X =") curXLB.grid(row=11, column=3, sticky=E) curYLB = Label(frame, text="Y =") curYLB.grid(row=12, column=3, sticky=E) curALB = Label(frame, text="A =") curALB.grid(row=13, column=3, sticky=E) self.curXLBValue = Text(frame, height=1, width=5) self.curXLBValue.grid(row=11, column=4, sticky=W) self.curYLBValue = Text(frame, height=1, width=5) self.curYLBValue.grid(row=12, column=4, sticky=W) self.curALBValue = Text(frame, height=1, width=5) self.curALBValue.grid(row=13, column=4, sticky=W) ### BIG ROBOT COLLISION AVOIDANCE### collB = Label(frame, text="Collision:") collB.grid(row = 14, column = 3) self.collBValue = Text(frame, height=1, width=3) self.collBValue.grid(row=14,column=4,sticky=W) ###BIG ROBOT ADC### ADCB = Label(frame, text="Client Big: ") ADCB.grid(row = 15, column = 3) self.ADCBValue = Text(frame, height=10, width=10) self.ADCBValue.grid(row=16, column=3)
def __init__(self, root): self.root=root self.entry = tk.Entry(root) stvar=tk.StringVar() stvar.set("one") ###CANVAS### im = PIL.Image.open('field.jpg') canvas=tk.Canvas(root, width=1300, height=846) canvas.grid(row=0, column=0) """canvas.create_oval(10, 10, 80, 80, outline="gray", fill="gray", width=2) canvas.create_oval(110, 10, 210, 80, outline="gray", fill="gray", width=2) canvas.create_rectangle(230, 10, 290, 60, outline="gray", fill="gray", width=2) canvas.create_arc(30, 200, 90, 100, start=0, extent=210, outline="gray", fill="gray", width=2)""" canvas.image = ImageTk.PhotoImage(im) canvas.create_image(635,423,image = canvas.image) canvas.create_rectangle(0,843, 200, 846, fill="blue") canvas.create_rectangle(0,843, 3, 646, fill="red") canvas.create_text(200, 836, text="X", fill="blue") canvas.create_text(10, 646, text="Y", fill="red") ###ROBOTS### """points = [150, 100, 300, 120, 240, 180] canvas.create_polygon(points, outline='gray', fill='gray', width=2)""" angle = 120 length=10 alpha = angle*pi/180 points_small = [100, 200, 220, 320] points_big = [200,500, 300, 400] canvas.create_oval(points_small, outline="blue", fill="white", width=5)#small robot #canvas.create_line(points_small[1]-points_small[0],points_small[3]-points_small[2],(points_small[2]-points_small[0])+length*cos(alpha),(points_small[3]-points_small[1])+length*sin(alpha), fill="blue", width = 5) canvas.create_rectangle(points_big, outline="red", fill="white", width=5)#big robot #canvas.create_line(points_big[2]-points_big[0],points_big[3]-points_big[1],points_big[2]-points_big[0]+length*cos(alpha),points_big[3]-points_big[1]+length*sin(alpha), fill="red", width=5) ###FRAME### frame=Frame(self.root) frame.grid(row=0,column=1, sticky=W) ###STACK### Stack = Label(frame, text="Stack: ") Stack.grid(row = 0, column = 1, sticky=W) cntPoint = Label(frame, text="cntPoint = ") cntPoint.grid(row = 1, column = 1, columnspan=1, sticky=E) curPoint = Label(frame, text="curPoint = ") curPoint.grid(row=2, column=1, sticky=E) nextX = Label(frame, text="nextX =") nextX.grid(row=3, column=1, sticky=E) nextY = Label(frame, text="nextY = ") nextY.grid(row=4, column=1, sticky=E) nextA = Label(frame, text="nextA = ") nextA.grid(row=5, column=1, sticky=E) cntPointValue = Text(frame, height=1, width=5) cntPointValue.grid(row = 1, column = 2, sticky=W) curPointValue = Text(frame, height=1, width=5) curPointValue.grid(row = 2, column = 2, sticky=W) nextXValue = Text(frame, height=1, width=5) nextXValue.grid(row = 3, column = 2, sticky=W) nextYValue = Text(frame, height=1, width=5) nextYValue.grid(row = 4, column = 2, sticky=W) nextAValue = Text(frame, height=1, width=5) nextAValue.grid(row = 5, column = 2, sticky=W) ###ROBOT-COORDINATES### Coordinates = Label(frame, text="Robot Coordinates: ") Coordinates.grid(row = 6, column = 1, sticky=W) curX = Label(frame, text="X =") curX.grid(row=7, column=1, sticky=E) curY = Label(frame, text="Y =") curY.grid(row=8, column=1, sticky=E) curA = Label(frame, text="A =") curA.grid(row=9, column=1, sticky=E) curXValue = Text(frame, height=1, width=5) curXValue.grid(row=7, column=2, sticky=W) curYValue = Text(frame, height=1, width=5) curYValue.grid(row=8, column=2, sticky=W) curAValue = Text(frame, height=1, width=5) curAValue.grid(row=9, column=2, sticky=W) ###LIDAR-COORDINATES### CoordinatesL = Label(frame, text="Lidar Coordinates: ") CoordinatesL.grid(row = 10, column = 1, sticky=W) curXL = Label(frame, text="X =") curXL.grid(row=11, column=1, sticky=E) curYL = Label(frame, text="Y =") curYL.grid(row=12, column=1, sticky=E) curAL = Label(frame, text="A =") curAL.grid(row=13, column=1, sticky=E) curXLValue = Text(frame, height=1, width=5) curXLValue.grid(row=11, column=2, sticky=W) curYLValue = Text(frame, height=1, width=5) curYLValue.grid(row=12, column=2, sticky=W) curALValue = Text(frame, height=1, width=5) curALValue.grid(row=13, column=2, sticky=W) ###COLLISION AVOIDANCE### coll = Label(frame, text="Collision:") coll.grid(row = 14, column = 1) collValue = Text(frame, height=1, width=3) collValue.grid(row=14,column=2,sticky=W) ###ADC### ADC = Label(frame, text="ADC: ") ADC.grid(row = 15, column = 1) ADCValue = Text(frame, height=10, width=10) ADCValue.grid(row=16, column=1) ###INPUTS### INPUTS = Label(frame, text="INPUTS:") INPUTS.grid(row=17, column=1) INPUTSValue = Text(frame, height=10, width=10) INPUTSValue.grid(row=18, column=1) ###BUTTONS### startButton = Button(frame, text="START") startButton.grid(row=18, column=2, sticky=S, pady=30) #startButton.bind('<Button-1>', start_server()) stopButton = Button(frame, text="STOP") stopButton.grid(row=18, column=2, sticky=S)