def create_other_buttons(self): '''Return (frame, others) for testing. Others is a list of value, label pairs. A gridded frame from make_frame is filled with radio buttons. ''' frame = self.make_frame("Direction")[0] var = self.engine.backvar others = [(1, 'Up'), (0, 'Down')] for val, label in others: btn = Radiobutton(frame, anchor="w", variable=var, value=val, text=label) btn.pack(side="left", fill="both") if var.get() == val: btn.select() return frame, others
def __init__(self, parent): Frame.__init__(self, parent) self.observers = [] self.CLASS_NAME = ['Class {0}'.format(i+1) for i in range(MAX_NUMBER_OF_CLASSES)] self.selected_class = IntVar() self.class_buttons = {} for i in range(MAX_NUMBER_OF_CLASSES): class_button = Radiobutton( self, text = self.CLASS_NAME[i], fg = CLASS_COLOR[i], state = 'disabled', variable = self.selected_class, value = i, command = self._on_sample_class_selection) class_button.pack(anchor = 'w', padx=5) self.class_buttons[i] = class_button self.label = Label(self) self.label.pack() self.class_number = DEFAULT_NUMBER_OF_CLASS self.samples = [[]] * MAX_NUMBER_OF_CLASSES self.samples_coordinates = [[]] * MAX_NUMBER_OF_CLASSES self.select_default_class()
def __init__(self, parent): Frame.__init__(self, parent) self.observers = [] self.CLASS_NAME = [ 'Class {0}'.format(i + 1) for i in range(MAX_NUMBER_OF_CLASSES) ] self.selected_class = IntVar() self.class_buttons = {} for i in range(MAX_NUMBER_OF_CLASSES): class_button = Radiobutton(self, text=self.CLASS_NAME[i], fg=CLASS_COLOR[i], state='disabled', variable=self.selected_class, value=i, command=self._on_sample_class_selection) class_button.pack(anchor='w', padx=5) self.class_buttons[i] = class_button self.label = Label(self) self.label.pack() self.class_number = DEFAULT_NUMBER_OF_CLASS self.samples = [[]] * MAX_NUMBER_OF_CLASSES self.samples_coordinates = [[]] * MAX_NUMBER_OF_CLASSES self.select_default_class()
def build_devices_arch(self): #8bits name_checked = self.main.configIDE.config("Board", "board_8", "Pinguino 2550") arch_8 = filter(lambda board:board.arch==8, self.main.pinguinoAPI._boards_) arch_8.sort() frame_left = Frame(self.frame_8b) frame_left.pack(expand=True, fill=BOTH, side=LEFT) frame_right = Frame(self.frame_8b) frame_right.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left #left for board in arch_8: if arch_8.index(board) == (len(arch_8) / 2) + 1: parent = frame_right #rigth radio = Radiobutton(parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev8_var, command=lambda :self.set_board_name(board.name, "8")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_8) #self.board_config.gridLayout_device_8.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "8")) #32bits name_checked = self.main.configIDE.config("Board", "board_32", "PIC32 Pinguino OTG") arch_32 = filter(lambda board:board.arch==32, self.main.pinguinoAPI._boards_) arch_32.sort() frame_left0 = Frame(self.frame_32b) frame_left0.pack(expand=True, fill=BOTH, side=LEFT) frame_right0 = Frame(self.frame_32b) frame_right0.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left0 #left for board in arch_32: if arch_32.index(board) == (len(arch_32) / 2) + 1: parent = frame_right0 #rigth radio = Radiobutton(parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev32_var, command=lambda :self.set_board_name(board.name, "32")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_32) #self.board_config.gridLayout_device_32.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select()
class PageTab(Frame): """ a 'page tab' like framed button """ def __init__(self, parent): Frame.__init__(self, parent, borderwidth=2, relief=MYRIDGE) self.button = Radiobutton(self, padx=5, pady=5, takefocus=0, indicatoron=FALSE, highlightthickness=0, borderwidth=0, selectcolor=self.cget('bg')) self.button.pack()
def create_other_buttons(self): f = self.make_frame("Direction") btn = Radiobutton(f, variable=self.engine.backvar, value=1, text="Up") btn.pack(side="left") if self.engine.isback(): btn.invoke() btn = Radiobutton(f, variable=self.engine.backvar, value=0, text="Down") btn.pack(side="left") if not self.engine.isback(): btn.invoke()
def radio_part(self, _s_row_, _text_, _desc_=[''], _vals_=[]): _f_labels = format_dec([_s_row_, _text_])#, _pack_=False) radio_var = IntVar() for d in range( len( _desc_)): label_rb = Radiobutton(_s_row_, width=0, text= _desc_[d] ,variable = radio_var , value= len( _desc_)-1-d ,command = self.solvastuff , anchor='w' ) label_rb.pack(side='left', padx=6) self.objt_c.append( radio_var)
def start_video(self, root): def snd1(): os.system( "/Users/priscilla/Documents/Thesis/BCI_Experimentation_System/sample1.mp4" ) var = IntVar() rb1 = Radiobutton(root, text="Play Video", variable=var, value=1, command=snd1) rb1.pack() self.Fcanvas.pack() root.mainloop()
def __init__(self, wname='guippy', master=None): Tkinter.Frame.__init__(self, master) self.master.title(wname) self.radio_value = IntVar() self.radio_values = { 'test1': 0, 'test2': 1, 'test3': 2, } self.check_values = { 'test1': BooleanVar(), 'test2': BooleanVar(), 'test3': BooleanVar(), } self.option_value = StringVar() self.entry_value = StringVar() self.result_value = StringVar() self.radio_entry = StringVar() self.check_entry = StringVar() # widgets kwds = {'padx': 3, 'pady': 3, 'side': Tkinter.LEFT} ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='w') Button(ff, text='apply ', command=self.apply).pack(**kwds) Button(ff, text='reapply').pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='w') for key, val in sorted(self.radio_values.items()): _r = Radiobutton(ff, text=key, variable=self.radio_value, value=val) _r.pack(**kwds) Entry(ff, textvariable=self.radio_entry).pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='c') for key, val in sorted(self.check_values.items()): _w = Checkbutton(ff, text=key, variable=val) _w.pack(**kwds) Entry(ff, textvariable=self.check_entry).pack(**kwds)
def create_other_buttons(self): "Fill frame with buttons tied to other options." f = self.make_frame("Direction") btn = Radiobutton(f, anchor="w", variable=self.engine.backvar, value=1, text="Up") btn.pack(side="left", fill="both") if self.engine.isback(): btn.select() btn = Radiobutton(f, anchor="w", variable=self.engine.backvar, value=0, text="Down") btn.pack(side="left", fill="both") if not self.engine.isback(): btn.select()
def __init__(self, parent): top = self.top = Toplevel(parent) Label(top, text="Pick your color").pack() self.v = 0 rb1 = Radiobutton(top, text="Yellow", value=YELLOW, command=self.sari) rb1.pack() rb1.select() rb2 = Radiobutton(top, text="Green", value=GREEN, command=self.yesil) rb2.pack() rb2.deselect() b = Button(top, text="OK", command=self.ok) b.pack(pady=5)
def add_screen( self, fr, title ): b = Radiobutton( self.rb_fr, text=title, indicatoron=0, \ variable=self.choice, value=self.count, \ command=lambda: self.display( fr ), padx=10, pady=5 ) b.pack( fill=BOTH, side=self.side ) # ensures the first frame will be # the first selected/enabled if not self.active_fr: fr.pack( fill=BOTH, expand=1 ) self.active_fr = fr self.count += 1 # returns a reference to the newly created # radiobutton (allowing its configuration/destruction) return b
def __init__(self, wname='guippy', master=None): Tkinter.Frame.__init__(self, master) self.master.title(wname) self.radio_value = IntVar() self.radio_values = {'test1': 0, 'test2': 1, 'test3': 2, } self.check_values = {'test1': BooleanVar(), 'test2': BooleanVar(), 'test3': BooleanVar(), } self.option_value = StringVar() self.entry_value = StringVar() self.result_value = StringVar() self.radio_entry = StringVar() self.check_entry = StringVar() # widgets kwds = {'padx':3, 'pady': 3, 'side': Tkinter.LEFT} ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='w') Button(ff, text='apply ', command=self.apply).pack(**kwds) Button(ff, text='reapply').pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='w') for key, val in sorted(self.radio_values.items()): _r = Radiobutton(ff, text=key, variable=self.radio_value, value=val) _r.pack(**kwds) Entry(ff, textvariable=self.radio_entry).pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor='c') for key, val in sorted(self.check_values.items()): _w = Checkbutton(ff, text=key, variable=val) _w.pack(**kwds) Entry(ff, textvariable=self.check_entry).pack(**kwds)
def __init__(self, master): root_frame = Frame(master) root_frame.pack() menubar = Menu(master) menufile = Menu(menubar, tearoff=0) menufile.add_command(label="Open") menufile.add_command(label="Save") menubar.add_cascade(label="File", menu=menufile) master.config(menu=menubar) right_frame = Frame(root_frame, bg="white") right_frame.pack(side=RIGHT) self.button = Button(right_frame, text="quit", fg="red", command=root_frame.quit) self.button.pack(side=TOP) MODES = [("3D", "rectangle"), ("2D", "line")] self.mode = StringVar() self.mode.set("line") for text, mode in MODES: b = Radiobutton(right_frame, text=text, variable=self.mode, value=mode) b.pack(anchor=W) self.camera_canvas = Canvas(right_frame, bg="red") self.camera_canvas.bind("<ButtonPress-1>", self.pressed) self.camera_canvas.bind("<B1-Motion>", self.moved) self.camera_canvas.bind("<ButtonRelease-1>", self.released) self.camera_canvas.pack(side=BOTTOM) self.plot_canvas = Canvas(root_frame, width=100, bg="blue") self.plot_canvas.pack(side=LEFT) self.tomogram_canvas = Canvas(root_frame, bg="black") self.tomogram_canvas.pack(side=LEFT)
def __init__(self,master): root_frame = Frame(master) root_frame.pack() menubar = Menu(master) menufile = Menu(menubar,tearoff=0) menufile.add_command(label="Open") menufile.add_command(label="Save") menubar.add_cascade(label="File",menu=menufile) master.config(menu=menubar) right_frame = Frame(root_frame,bg="white") right_frame.pack(side=RIGHT) self.button = Button(right_frame, text="quit", fg="red", command=root_frame.quit) self.button.pack(side=TOP) MODES = [("3D","rectangle"),("2D","line")] self.mode = StringVar() self.mode.set("line") for text,mode in MODES: b = Radiobutton(right_frame,text=text, variable=self.mode,value=mode) b.pack(anchor=W) self.camera_canvas = Canvas(right_frame,bg="red") self.camera_canvas.bind("<ButtonPress-1>", self.pressed) self.camera_canvas.bind("<B1-Motion>", self.moved) self.camera_canvas.bind("<ButtonRelease-1>", self.released) self.camera_canvas.pack(side=BOTTOM) self.plot_canvas = Canvas(root_frame,width=100,bg="blue") self.plot_canvas.pack(side=LEFT) self.tomogram_canvas = Canvas(root_frame,bg="black") self.tomogram_canvas.pack(side=LEFT)
def __init__(self, wname="guippy", master=None): Tkinter.Frame.__init__(self, master) self.master.title(wname) self.radio_value = IntVar() self.radio_values = {"test1": 0, "test2": 1, "test3": 2} self.check_values = {"test1": BooleanVar(), "test2": BooleanVar(), "test3": BooleanVar()} self.option_value = StringVar() self.entry_value = StringVar() self.result_value = StringVar() self.radio_entry = StringVar() self.check_entry = StringVar() # widgets kwds = {"padx": 3, "pady": 3, "side": Tkinter.LEFT} ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor="w") Button(ff, text="apply ", command=self.apply).pack(**kwds) Button(ff, text="reapply").pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor="w") for key, val in sorted(self.radio_values.items()): _r = Radiobutton(ff, text=key, variable=self.radio_value, value=val) _r.pack(**kwds) Entry(ff, textvariable=self.radio_entry).pack(**kwds) ff = Frame(self) ff.pack(side=Tkinter.TOP, anchor="c") for key, val in sorted(self.check_values.items()): _w = Checkbutton(ff, text=key, variable=val) _w.pack(**kwds) Entry(ff, textvariable=self.check_entry).pack(**kwds)
class MyFirstGUI: def __init__(self, master): self.master = master master.title("listening window") self.label = Label(master, text="This is our first GUI!") self.label.pack() self.label.place(x=100, y=30) self.label_2 = Label(master, text="Enter the name if you see fit: ") self.label_2.pack() self.label_2.place(x=100, y=5) self.message = StringVar() self.entry = Entry(textvariable=self.message) self.entry.place(x=320, y=15, anchor="c") self.label_word = Label(master, text="Vocalize: a") self.label_word.pack() self.label_word.place(x=120, y=60) self.var = IntVar() self.var.set(0) self.checkRU = Radiobutton(master, value=0, variable=self.var, text="Russian") self.checkRU.pack() self.checkRU.place(x=310, y=30) self.checkEn = Radiobutton(master, value=1, variable=self.var, text="English") self.checkEn.pack() self.checkEn.place(x=310, y=60) self.start_button = Button(master, text="Start recording", width=11, command=self.greet) self.start_button.pack() self.start_button.place(x=210, y=30) self.close_button = Button(master, text="Close", width=11, command=master.quit) self.close_button.pack() self.close_button.place(x=210, y=60) self.alphabet_english = [x for x in 'abcdefghijklmnopqrstuvwxyz'] self.alphabet_russian = [x for x in unicode('абвгдежзийклмнопрстуфхцчшщыэюя', "utf-8")] self.x = voice_recording self.close_button = Button(master, text="Redirect", width=11, command=self.redirect) self.close_button.pack() self.close_button.place(x=210, y=90) def greet(self): if self.var.get() == 0: str_alphabet = "абвгдежзийклмнопрстуфхцчшщыэюя" else: str_alphabet = "abcdefghijklmnopqrstuvwxyz" if (self.var.get() == 1) and (not self.alphabet_english): print("List is empty") self.alphabet_english = [x for x in str_alphabet] elif (self.var.get() == 0) and (not self.alphabet_russian): self.alphabet_russian = [x for x in unicode(str_alphabet, "utf-8")] if self.var.get() == 0: number = self.alphabet_russian.pop(0) else: number = self.alphabet_english.pop(0) print (number) name = "default" if self.message.get(): name = self.message.get() self.x.my_record(name + "_" + number + ".wav") if self.alphabet_english and self.var.get() == 1: self.label_word['text'] = "Vocalize: " + self.alphabet_english[0] elif self.alphabet_english and self.var.get() == 0: self.label_word['text'] = "Vocalize: " + self.alphabet_russian[0] else: self.label_word['text'] = 'Vocalize: a' subprocess.call("python voice_acting.py combined.wav", shell=True) def redirect(self): subprocess.call("python read_GUI.py " + self.message.get())
Label(form, text="Radiobuttons:").grid(row=4, column=0, sticky=E, pady=(8, 0)) column = Frame(form) column.grid(row=5, column=1, sticky=E + W) # All radiobuttons require a variable variable = StringVar() radiobutton0 = Radiobutton(column, variable=variable, value="value0", text="Selection 0") radiobutton0.fieldname = "radiobutton" radiobutton0.pack(side=LEFT) radiobutton1 = Radiobutton(column, variable=variable, value="value1", text="Selection 1") radiobutton0.fieldname = "radiobutton" radiobutton1.pack(side=LEFT) Label(form, text="Text area:").grid(row=6, column=0, sticky=E, pady=(8, 0)) text = Text(form, height=5) text.fieldname = "text" text.grid(row=7, column=1, sticky=E + W) Label(form, text="Listbox:").grid(row=8, column=0, sticky=E, pady=(8, 0))
def start(): #CREATE THE WINDOW global prefstr window = Tkinter.Tk() screen_width = window.winfo_screenwidth() # width of the screen screen_height = window.winfo_screenheight() # height of the screen window.title("EvE Route Optimizer") window.geometry('%dx%d+%d+%d' % (680, 640, (screen_width / 2) - 340, (screen_height / 2) - 320)) window.configure(background='gray') result = ScrolledText.ScrolledText(window, width=60, height=20) result.configure(font=("Arial Bold", 12), fg="white") result.configure(background='black') start_field = Entry(window, width=37, font=("Arial Bold", 12)) end_field = Entry(window, width=37, font=("Arial Bold", 12)) fixed_end_field = Entry(window, width=37, font=("Arial Bold", 12)) iteration_field = Entry(window, width=6, font=("Arial Bold", 12)) start_field.insert(0, "Origin") end_field.insert(0, "Destination") fixed_end_field.insert(0, "Fixed End Point") iteration_field.insert(0, "Cycles") result.pack() start_field.pack() end_field.pack() fixed_end_field.pack() iteration_field.pack() fixed_end_field.configure(state=DISABLED) try: version_url = "https://sites.google.com/site/ustleveonline/route_optimizer_version" version_response = urllib.urlopen(version_url).read() local_version_file = open("route_optimizer_version", "r") local_version = local_version_file.read() if str(local_version) != str(version_response): result.insert( INSERT, "\nAn update for EvE Route Optimizer is available.\n") result.see("end") webbrowser.open( "https://sites.google.com/site/ustleveonline/route-optimizer", new=1, autoraise=True) else: result.insert(INSERT, "\nEvE Route Optimizer is up to date.\n") result.see("end") except: result.insert(INSERT, "\n" + "ERROR: Please check your internet connection!") result.see("end") #ADD A WAYPOINT def add_waypoint(Event=None): global o_system global d_system global waypoint_adding_done waypoint_adding_done = False o_system = start_field.get() d_system = end_field.get() if (o_system != "" and d_system != "" and o_system != "Origin" and d_system != "Destination"): try: number_of_routes = len(routes) start_field.delete(0, 'end') end_field.delete(0, 'end') start_field.insert(0, d_system) create_route(False) if len(routes) > number_of_routes: result.insert( INSERT, "\n" + "Added Route: " + o_system + " to " + d_system) result.see("end") else: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") waypoint_adding_done = True except: result.insert(INSERT, "\n" + "ERROR: Invalid!") result.see("end") #CREATE ROUTE USING GIVEN WAYPOINTS def create_route(optimizing): global routes global waypoints global o_system global d_system global prefstr #GET ORIGIN ID try: o_base = "https://esi.evetech.net/latest/search/?categories=solar_system&search=" o_end = "&strict=true" o_url = o_base + o_system + o_end o_response = urllib.urlopen(o_url).read() o_split_response = o_response.split(":") o_id_section = o_split_response[1] o_id_leftbracket = o_id_section.replace('[', '') o_id_rightbracket = o_id_leftbracket.replace(']', '') o_id_final = o_id_rightbracket.replace('}', '') except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET DESTINATION ID try: d_base = "https://esi.evetech.net/latest/search/?categories=solar_system&search=" d_end = "&strict=true" d_url = d_base + d_system + d_end d_response = urllib.urlopen(d_url).read() d_split_response = d_response.split(":") d_id_section = d_split_response[1] d_id_leftbracket = d_id_section.replace('[', '') d_id_rightbracket = d_id_leftbracket.replace(']', '') d_id_final = d_id_rightbracket.replace('}', '') except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET ROUTE try: r_base = "https://esi.evetech.net/latest/route/" r_end = "/?datasource=tranquility&flag=" r_type = prefstr r_slash = "/" r_url = r_base + o_id_final + r_slash + d_id_final + r_end + r_type except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #IF THIS ROUTE IS PART OF THE ORIGINAL REQUEST, ADD IT TO THE LIST try: if optimizing == False: r_response = urllib.urlopen(r_url).read() routes.append(r_response) waypoints.append(o_system) else: r_response = urllib.urlopen(r_url).read() return r_response except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #OPTIMIZE THE ROUTE def optimize(): global o_system global d_system global routes global waypoints global optimized_routes global previous_routes global tested_routes global total_routes global final_routes global origins global destinations global initialized global cycles global final_best_route global fixed_endpoint_name result.insert(INSERT, "\n") last_destination = "" last_route = [None] * 10000 best_route = [None] * 10000 sys1 = "" sys2 = "" waypoints.append(d_system) #GET AND DISPLAY THE TOTAL ROUTE DISTANCE IN NUMBER OF JUMPS total_distance = 0 for route in routes: split_route = route.split(",") total_distance += len(split_route) result.insert(INSERT, "\n" + "Number of jumps: " + str(total_distance)) result.see("end") if fixed_endpoint == False: #GET ID FOR THE ORIGIN split_for_origin = routes[0].split(",") first_origin = split_for_origin[0].split("[")[1] #GET ID FOR THE LAST STOP final_route = routes[len(routes) - 1] split_final_route = final_route.split(",") last_stop = split_final_route[len(split_final_route) - 1].split("]")[0] try: #CONVERT ID TO NAME FOR ORIGIN first_begin_url = "https://esi.evetech.net/latest/universe/systems/" first_end_url = "/?datasource=tranquility&language=en-us" first_final_url = first_begin_url + first_origin + first_end_url first_response = urllib.urlopen(first_final_url).read() first_final_origin = first_response.split(":")[2].split( ",")[0].replace('"', "") d_system = first_final_origin #CONVERT ID TO NAME FOR DESTINATION endpoint_begin_url = "https://esi.evetech.net/latest/universe/systems/" endpoint_end_url = "/?datasource=tranquility&language=en-us" endpoint_final_url = endpoint_begin_url + last_stop + endpoint_end_url endpoint_response = urllib.urlopen(endpoint_final_url).read() endpoint_final_response = endpoint_response.split( ":")[2].split(",")[0].replace('"', "") o_system = endpoint_final_response except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET AND DISPLAY THE TOTAL ROUTE DISTANCE INCLUDING RETURN TO ORIGIN return_route = create_route(True) return_distance = len(return_route.split(",")) result.insert( INSERT, "\n" + "Including return to origin: " + str(total_distance + return_distance) + "\n") result.see("end") else: #SET DESTINATION TO THE FIXED ENDPOINT if fixed_endpoint_name != "" and fixed_endpoint_name != "Fixed End Point": try: d_system = fixed_endpoint_name except: result.insert(INSERT, "\n" + "ERROR: Invalid Fixed End Point!") result.see("end") #GET THE ID FOR THE LAST STOP final_route = routes[len(final_routes) - 1] split_final_route = final_route.split(",") last_stop = split_final_route[len(split_final_route) - 1].split("]")[0] try: #CONVERT ID TO NAME FOR DESTINATION endpoint_begin_url = "https://esi.evetech.net/latest/universe/systems/" endpoint_end_url = "/?datasource=tranquility&language=en-us" endpoint_final_url = endpoint_begin_url + last_stop + endpoint_end_url endpoint_response = urllib.urlopen(endpoint_final_url).read() endpoint_final_response = endpoint_response.split( ":")[2].split(",")[0].replace('"', "") o_system = endpoint_final_response except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET AND DISPLAY THE TOTAL TRIP DISTANCE INCLUDING RETURN TO ORIGIN return_route = create_route(True) return_distance = len(return_route.split(",")) result.insert( INSERT, "\n" + "Including fixed end point: " + str(total_distance + return_distance) + "\n") result.see("end") try: cycles = int(iteration_field.get()) except: cycles = 1 count = 0 while count < cycles: count += 1 result.insert(INSERT, "\nCycle " + str(count) + ":\n") result.see("end") for route in routes: try: #CONVERT ID TO NAME FOR ORIGIN split_route = route.split(",") origin = split_route[0].split("[")[1] begin_url = "https://esi.evetech.net/latest/universe/systems/" end_url = "/?datasource=tranquility&language=en-us" final_url = begin_url + origin + end_url response = urllib.urlopen(final_url).read() final_origin = response.split(":")[2].split( ",")[0].replace('"', "") o_system = final_origin except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #ADD THE ORIGIN AS A DESTINATION SO IT'S NOT INCLUDED IN POTENTIAL ROUTES if initialized == False: destinations.append(o_system) initialized = True last_destination = o_system #WHEN THE ROUTE IS CHANGED, THE PREVIOUS WAYPOINT MUST BE UPDATED elif o_system != last_destination: o_system = last_destination #RESET THE BOOLEAN VALUES FOR ROUTE UPDATES optimized = False passed = False result.insert( INSERT, "\n" + "Finding the shortest route from " + o_system + " to another waypoint.\n") result.see("end") for waypoint in waypoints: if o_system != waypoint and passed == False: #PREVENT ROUTING TO THE CURRENT SYSTEM d_system = waypoint potential_route = create_route( True ) #CREATE A ROUTE TO GET THE LENGTH IN NUMBER OF JUMPS split_pot = potential_route.split(",") #FIND THE SHORTEST ROUTE FROM THE CURRENT LOCATION TO ANOTHER LOCATION IN THE LIST if optimized == True: split_best = best_route.split(",") if d_system not in destinations and o_system not in origins and len( best_route ) != 10000 and potential_route not in tested_routes: result.insert( INSERT, "\nChecking route " + str(o_system) + " to " + str(d_system) + ": " + str(len(split_pot)) + " jumps. Best found: " + str(len(split_best)) + " jumps.") result.see("end") if len(split_pot) < len( split_best ) and d_system not in destinations and o_system not in origins: best_route = potential_route sys1 = o_system sys2 = d_system elif len(split_pot) == len( split_best ) and d_system not in destinations and o_system not in origins: passed = True optimized = False else: if len(split_pot) < len( last_route ) and d_system not in destinations and o_system not in origins: if d_system not in destinations and o_system not in origins and len( best_route ) != 10000 and potential_route not in tested_routes: result.insert( INSERT, "\nChecking route " + str(o_system) + " to " + str(d_system) + ": " + str(len(split_pot)) + " jumps. Best found: " + str(len(last_route)) + " jumps.") result.see("end") best_route = potential_route sys1 = o_system sys2 = d_system optimized = True elif len(split_pot) == len( last_route ) and d_system not in destinations and o_system not in origins: passed = True optimized = False else: last_route = split_pot #OPTIMAL ROUTE WAS FOUND if optimized == True: result.insert( INSERT, "\n\n" + "Optimized route: " + sys1 + " to " + sys2 + "\n") result.see("end") optimized_routes.append(best_route) origins.append(sys1) destinations.append(sys2) last_destination = sys2 #OPTIMAL ROUTE WAS NOT FOUND, SO THE NEXT WAYPOINT IN THE LIST IS USED elif optimized == False: finished = False for waypoint in waypoints: if finished == False: if o_system != waypoint and waypoint not in destinations: #GET THE FIRST UNUSED WAYPOINT d_system = waypoint potential_route = create_route(True) if potential_route not in tested_routes: #THIS ROUTE HAS NOT YET BEEN EXAMINED tested_routes.append(potential_route) optimized_routes.append(potential_route) result.insert( INSERT, "\n\n" + "No exceptional route found. Creating route: " + o_system + " to " + d_system + "\n") result.see("end") origins.append(o_system) destinations.append(d_system) last_destination = d_system finished = True if finished == False: #ALL POSSIBLE ROUTES HAVE BEEN EXAMINED FOR THIS WAYPOINT SO THE SHORTEST ONE IS SELECTED previous_best_route = [None] * 10000 best_tested_route = [] for route in tested_routes: split_route = str(route).split(",") origin = split_route[0].split("[")[1] try: o_begin_url = "https://esi.evetech.net/latest/universe/systems/" o_end_url = "/?datasource=tranquility&language=en-us" o_final_url = o_begin_url + origin + o_end_url o_response = urllib.urlopen(o_final_url).read() o_final_response = o_response.split( ":")[2].split(",")[0].replace('"', "") except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!" ) result.see("end") if o_final_response == o_system: if len(previous_best_route) != 10000: result.insert( INSERT, "\n" + "Comparing potential routes for this waypoint: " + str(len(split_route)) + " jumps VS " + str(len(previous_best_route)) + " jumps.") result.see("end") s_destination = split_route[len(split_route) - 1].split("]")[0] try: s_d_begin_url = "https://esi.evetech.net/latest/universe/systems/" s_d_end_url = "/?datasource=tranquility&language=en-us" s_d_final_url = s_d_begin_url + s_destination + s_d_end_url s_d_response = urllib.urlopen( s_d_final_url).read() s_d_final_response = s_d_response.split( ":")[2].split(",")[0].replace('"', "") except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!" ) result.see("end") if s_d_final_response not in destinations and len( split_route) < len( previous_best_route): best_tested_route = route previous_best_route = split_route split_best_route = str(best_tested_route).split(",") origin = split_best_route[0].split("[")[1] destination = split_best_route[len(split_best_route) - 1].split("]")[0] try: o_begin_url = "https://esi.evetech.net/latest/universe/systems/" o_end_url = "/?datasource=tranquility&language=en-us" o_final_url = o_begin_url + origin + o_end_url o_response = urllib.urlopen(o_final_url).read() t_o_final_response = o_response.split( ":")[2].split(",")[0].replace('"', "") d_begin_url = "https://esi.evetech.net/latest/universe/systems/" d_end_url = "/?datasource=tranquility&language=en-us" d_final_url = d_begin_url + destination + d_end_url d_response = urllib.urlopen(d_final_url).read() t_d_final_response = d_response.split( ":")[2].split(",")[0].replace('"', "") except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!" ) result.see("end") optimized_routes.append(best_tested_route) result.insert( INSERT, "\n\n" + "All possible routes considered. Using route: " + t_o_final_response + " to " + t_d_final_response + "\n") result.see("end") origins.append(t_o_final_response) destinations.append(t_d_final_response) last_destination = t_d_final_response finished = True total_routes.append(optimized_routes) previous_routes = optimized_routes optimized_routes = [] origins = [] destinations = [] optimized = False initialized = False #SELECT THE BEST ROUTE FROM ALL CYCLES previous_best_distance = 10000 for route in total_routes: total_route_distance = 0 for r in route: s_r = r.split(",") total_route_distance += len(s_r) if previous_best_distance != 10000: result.insert( INSERT, "\n" + "Comparing optimized routes: " + str(total_route_distance) + " jumps VS " + str(previous_best_distance) + " jumps.") result.see("end") if total_route_distance < previous_best_distance: final_best_route = route previous_best_distance = total_route_distance #DISPLAY THE OPTIMIZED ROUTE previous_destination = "" for route in final_best_route: split_route = str(route).split(",") origin = split_route[0].split("[")[1] destination = split_route[len(split_route) - 1].split("]")[0] #CONVERT THE ID TO NAME FOR EACH ROUTE try: o_begin_url = "https://esi.evetech.net/latest/universe/systems/" o_end_url = "/?datasource=tranquility&language=en-us" o_final_url = o_begin_url + origin + o_end_url o_response = urllib.urlopen(o_final_url).read() o_final_response = o_response.split(":")[2].split( ",")[0].replace('"', "") d_begin_url = "https://esi.evetech.net/latest/universe/systems/" d_end_url = "/?datasource=tranquility&language=en-us" d_final_url = d_begin_url + destination + d_end_url d_response = urllib.urlopen(d_final_url).read() d_final_response = d_response.split(":")[2].split( ",")[0].replace('"', "") #SET THE CURRENT SYSTEM TO INITIALIZE ITERATION if previous_destination == "": previous_destination = o_final_response result.insert(INSERT, "\n\n" + "New Route:" + "\n") result.see("end") #SET THE CURRENT SYSTEM TO THE PREVIOUS DESTINATION if o_final_response == previous_destination: final_routes.append(route) previous_destination = d_final_response result.insert( INSERT, "\n" + o_final_response + " to " + d_final_response) result.see("end") else: #THIS IS FOR DEBUGGING AND SHOULD NEVER HAPPEN result.insert( INSERT, "\n" + "ERROR: Out of order! " + o_final_response + ":" + d_final_response) result.see("end") except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET AND DISPLAY THE TOTAL TRIP DISTANCE IN NUMBER OF JUMPS total_distance = 0 for route in final_routes: split_route = route.split(",") total_distance += len(split_route) result.insert(INSERT, "\n\n" + "Number of jumps: " + str(total_distance)) result.see("end") if fixed_endpoint == False: #GET THE ID FOR THE ORIGIN split_for_origin = final_routes[0].split(",") first_origin = split_for_origin[0].split("[")[1] #GET THE ID FOR THE LAST STOP final_route = final_routes[len(final_routes) - 1] split_final_route = final_route.split(",") last_stop = split_final_route[len(split_final_route) - 1].split("]")[0] try: #CONVERT ID TO NAME FOR ORIGIN first_begin_url = "https://esi.evetech.net/latest/universe/systems/" first_end_url = "/?datasource=tranquility&language=en-us" first_final_url = first_begin_url + first_origin + first_end_url first_response = urllib.urlopen(first_final_url).read() first_final_origin = first_response.split(":")[2].split( ",")[0].replace('"', "") d_system = first_final_origin #CONVERT ID TO NAME FOR DESTINATION endpoint_begin_url = "https://esi.evetech.net/latest/universe/systems/" endpoint_end_url = "/?datasource=tranquility&language=en-us" endpoint_final_url = endpoint_begin_url + last_stop + endpoint_end_url endpoint_response = urllib.urlopen(endpoint_final_url).read() endpoint_final_response = endpoint_response.split( ":")[2].split(",")[0].replace('"', "") o_system = endpoint_final_response except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET AND DISPLAY THE TOTAL TRIP DISTANCE INCLUDING RETURN TO ORIGIN return_route = create_route(True) return_distance = len(return_route.split(",")) result.insert( INSERT, "\n" + "Including return to origin: " + str(total_distance + return_distance) + "\n") result.see("end") else: #SET DESTINATION TO THE FIXED ENDPOINT d_system = fixed_endpoint_name #GET THE ID FOR THE LAST STOP final_route = final_routes[len(final_routes) - 1] split_final_route = final_route.split(",") last_stop = split_final_route[len(split_final_route) - 1].split("]")[0] try: #CONVERT ID TO NAME FOR DESTINATION endpoint_begin_url = "https://esi.evetech.net/latest/universe/systems/" endpoint_end_url = "/?datasource=tranquility&language=en-us" endpoint_final_url = endpoint_begin_url + last_stop + endpoint_end_url endpoint_response = urllib.urlopen(endpoint_final_url).read() endpoint_final_response = endpoint_response.split( ":")[2].split(",")[0].replace('"', "") o_system = endpoint_final_response except: result.insert( INSERT, "\n" + "ERROR: Unable to get data from esi.evetech.net!") result.see("end") #GET AND DISPLAY THE TOTAL TRIP DISTANCE INCLUDING RETURN TO ORIGIN return_route = create_route(True) return_distance = len(return_route.split(",")) result.insert( INSERT, "\n" + "Including fixed end point: " + str(total_distance + return_distance) + "\n") result.see("end") #RESET VARIABLES SO ANOTHER SET OF WAYPOINTS CAN BE ENTERED previous_routes = [] total_routes = [] tested_routes = [] final_best_route = [] routes = [] optimized_routes = [] final_routes = [] waypoints = [] o_system = "" d_system = "" origins = [] destinations = [] initialized = False start_field.delete(0, 'end') end_field.delete(0, 'end') start_field.insert(0, "Origin") end_field.insert(0, "Destination") result.insert(INSERT, "\n") result.see("end") #START THE OPTIMIZATION THREAD def begin_optimization(): global waypoint_adding_done if waypoint_adding_done == True: optimization_thread = threading.Thread(target=optimize) optimization_thread.start() #CHANGE THE ROUTE PREFERENCE def change_preference(): global prefstr if preference.get() == 1: prefstr = "shortest" if preference.get() == 2: prefstr = "secure" if preference.get() == 3: prefstr = "insecure" #CHANGE THE FIXED ENDPOINT def set_fixed_endpoint(): global fixed_endpoint_name global fixed_endpoint if fixed.get() == 1: fixed_endpoint = True fixed_end_field.configure(state=NORMAL) else: fixed_endpoint = False fixed_end_field.configure(state=DISABLED) #FINALIZE FIXED ENDPOINT def lock_fixed_endpoint(Event=None): global fixed_endpoint_name fixed_endpoint_name = fixed_end_field.get() fixed_end_field.configure(state=DISABLED) #SETUP BUTTONS fixed = IntVar() fixed_end_button = Checkbutton(window, text="Fixed End-Point", variable=fixed, command=set_fixed_endpoint, onvalue=1, offvalue=0, bg="gray", font=("Arial Bold", 12)) fixed_end_button.pack() preference = IntVar() R1 = Radiobutton(window, text="Shortest", variable=preference, value=1, command=change_preference, bg="gray", font=("Arial Bold", 12)) R1.pack() R2 = Radiobutton(window, text="Secure", variable=preference, value=2, command=change_preference, bg="gray", font=("Arial Bold", 12)) R2.pack() R3 = Radiobutton(window, text="Insecure", variable=preference, value=3, command=change_preference, bg="gray", font=("Arial Bold", 12)) R3.pack() button = Button(window, text="Optimize", font=("Arial Bold", 12), bg="gray", fg="blue", command=begin_optimization) button.pack() end_field.bind( "<Return>", add_waypoint ) #ALLOWS THE RETURN KEY TO ADD A WAYPOINT INSTEAD OF CLICKING THE BUTTON fixed_end_field.bind("<Return>", lock_fixed_endpoint) window.mainloop()
checkbutton1.fieldname = "checkbutton1" checkbutton1.pack(side=LEFT) checkbutton2 = Checkbutton(column, text="Option 2") checkbutton2.fieldname = "checkbutton2" checkbutton2.pack(side=LEFT) Label(form, text="Radiobuttons:").grid(row=4,column=0, sticky=E, pady=(8,0)) column = Frame(form) column.grid(row=5,column=1, sticky =E+W) # All radiobuttons require a variable variable = StringVar() radiobutton0 = Radiobutton(column, variable = variable, value="value0", text="Selection 0") radiobutton0.fieldname = "radiobutton" radiobutton0.pack(side=LEFT) radiobutton1 = Radiobutton(column, variable = variable, value="value1", text="Selection 1") radiobutton0.fieldname = "radiobutton" radiobutton1.pack(side=LEFT) Label(form, text="Text area:").grid(row=6,column=0, sticky=E, pady=(8,0)) text = Text(form, height=5) text.fieldname = "text" text.grid(row=7,column=1, sticky =E+W) Label(form, text="Listbox:").grid(row=8,column=0, sticky=E, pady=(8,0)) listbox = Listbox(form) listbox.fieldname = "listbox"
class TabButton(Frame): """A simple tab-like widget.""" bw = 2 # borderwidth def __init__(self, name, select_command, tab_row, tab_set): """Constructor arguments: name -- The tab's name, which will appear in its button. select_command -- The command to be called upon selection of the tab. It is called with the tab's name as an argument. """ Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED) self.name = name self.select_command = select_command self.tab_set = tab_set self.is_last_in_row = False self.button = Radiobutton( self, text=name, command=self._select_event, padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE, highlightthickness=0, selectcolor='', borderwidth=0) self.button.pack(side=LEFT, fill=X, expand=True) self._init_masks() self.set_normal() def _select_event(self, *args): """Event handler for tab selection. With TabbedPageSet, this calls TabbedPageSet.change_page, so that selecting a tab changes the page. Note that this does -not- call set_selected -- it will be called by TabSet.set_selected_tab, which should be called when whatever the tabs are related to changes. """ self.select_command(self.name) return def set_selected(self): """Assume selected look""" self._place_masks(selected=True) def set_normal(self): """Assume normal look""" self._place_masks(selected=False) def _init_masks(self): page_set = self.tab_set.page_set background = page_set.pages_frame.cget('background') # mask replaces the middle of the border with the background color self.mask = Frame(page_set, borderwidth=0, relief=FLAT, background=background) # mskl replaces the bottom-left corner of the border with a normal # left border self.mskl = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskl.ml = Frame(self.mskl, borderwidth=self.bw, relief=RAISED) self.mskl.ml.place(x=0, y=-self.bw, width=2*self.bw, height=self.bw*4) # mskr replaces the bottom-right corner of the border with a normal # right border self.mskr = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskr.mr = Frame(self.mskr, borderwidth=self.bw, relief=RAISED) def _place_masks(self, selected=False): height = self.bw if selected: height += self.bw self.mask.place(in_=self, relx=0.0, x=0, rely=1.0, y=0, relwidth=1.0, width=0, relheight=0.0, height=height) self.mskl.place(in_=self, relx=0.0, x=-self.bw, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) page_set = self.tab_set.page_set if selected and ((not self.is_last_in_row) or (self.winfo_rootx() + self.winfo_width() < page_set.winfo_rootx() + page_set.winfo_width()) ): # for a selected tab, if its rightmost edge isn't on the # rightmost edge of the page set, the right mask should be one # borderwidth shorter (vertically) height -= self.bw self.mskr.place(in_=self, relx=1.0, x=0, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) self.mskr.mr.place(x=-self.bw, y=-self.bw, width=2*self.bw, height=height + self.bw*2) # finally, lower the tab set so that all of the frames we just # placed hide it self.tab_set.lower()
def initUI(self): """ Initializes the user interface Setting up the entry widgets for: - Experiment_ID - Participant Name - Session Day - Pupil Size - Practice - Stereo """ # Set the title self.parent.title(EXP_NAME) # Create the label for Experiment_ID and set location label_id = Label(text='Participant ID:') label_id.place(x=20, y=20) # Check the DATA_DIR directory for previous participants # and choose the next Experiment_ID in line self.folders = listdir(DATA_DIR) # Initiate Tkinter's StringVar self.value_id = StringVar() # Set the default value self.value_id.set('001') # Going in reverse order of the participants' directories in # DATA_DIR, find the last participant's Experiment_ID and opt # for the next one in line for folder in reversed(self.folders): try: # Check if the value of the first 3 digits of the # directory name is greater than the default value if int(folder[:3]) >= int(self.value_id.get()): # Get the next Experiment_ID in integer form and # convert to string format num = str(int(folder[:3]) + 1) # Actions to perform in case scenarios for each # of the possibilites of num_length num_length = { 3: num, 2: '0%s' % num, 1: '00%s' % num } # Set the value accordingly to the StringVar, # replacing the default self.value_id.set(num_length[len(num)]) # In case there are other folders in DATA_DIR, for which # the first 3 characters are not digits, we must cater # for when an exception is thrown up except ValueError: pass # Create the entry widget for Experiment_ID with the preset # value and state disabled self.input_id = Entry(self.parent, width=5, state=DISABLED, textvariable=self.value_id) self.input_id.place(x=150, y=20) # Create the label for Participant Name and set location label_name = Label(text='Participant Name:') label_name.place(x=20, y=50) # Initiate Tkinter's StringVar self.value_name = StringVar() # Set the default value self.value_name.set('') # Create the entry for Participant Name and set location self.input_name = Entry(self.parent, width=35, textvariable=self.value_name) self.input_name.place(x=150, y=50) self.input_name.focus() # Create the label for Session Day and set location label_day = Label(text='Session Day:') label_day.place(x=20, y=80) # Create value holder for Session Day as IntVar and set default # value to 1 self.value_day = IntVar() self.value_day.set(1) # Create the radiobuttons as required for day in range(1, TOTAL_SESSIONS + 1): input_day = Radiobutton(self.parent, text=str(day), variable=self.value_day, value=day) # Anchor them to the West (W) input_day.pack(anchor=W) # Choose location for the radiobuttons input_day.place(x=150, y=(50 + (day * 25))) # Create the label for Pupil Size and set location label_pupilsize = Label(text='Pupil Size:') label_pupilsize.place(x=20, y=140) self.value_pupilsize = StringVar() self.value_pupilsize.set('') # Create the MaxLengthEntry for Pupil Size and set location # The maximum length is set to 3 characters and a float must be # provided self.input_pupilsize = MaxLengthEntry(self.parent, width=5, maxlength=3, required_type=float) self.input_pupilsize.config(textvariable=self.value_pupilsize) self.input_pupilsize.place(x=150, y=140) # Create value folder for Practice as IntVar self.value_practice = IntVar() # Create the checkbutton for Practice and set location input_practice = Checkbutton(self.parent, text='Practice', variable=self.value_practice, onvalue=1, offvalue=0) input_practice.place(x=150, y=170) # Create value holder for Stereo as IntVar self.value_stereo = IntVar() # Create the checkbutton for Stereo and set location input_stereo = Checkbutton(self.parent, text='Stereo', variable=self.value_stereo, onvalue=1, offvalue=0) input_stereo.place(x=150, y=200) # Create the label for Previous Subjects and set location label_previous = Label(text='Previous Subjects:') label_previous.place(x=20, y=250) # Create the Listboc containing all the previous participants self.input_previous = Listbox(self.parent, width=35, height=10) for identifier in self.folders: self.input_previous.insert(END, identifier) self.input_previous.place(x=150, y=250) self.input_previous.bind('<<ListboxSelect>>', self.__select_previous) # Create the submit button, give command upon pressing and set # location submit = Button(text='Submit', width=47, command=self.gather_input) submit.pack(padx=8, pady=8) submit.place(x=20, y=425)
def _init_components(self): # group type selection (alternating, classical, sporadic, exceptional) group_type_frame = LabelFrame(self, text="Group type", padx=10, pady=5) group_type_frame.pack(expand=True, fill='x') # group type radio buttons (Alternating, Classical etc.) self._group_type = StringVar() self._type_radio_buttons = dict() for group_type in ("Alternating", "Classical", "Exceptional", "Sporadic"): radiobutton = Radiobutton(group_type_frame, variable=self._group_type, value=group_type, text=group_type) radiobutton.pack(anchor='nw') self._type_radio_buttons[group_type] = radiobutton # set group type selection handler self._group_type.trace("w", lambda n, i, m: self._group_type_selection()) # spacer Frame(self, height=10).pack() # parameters for each group (degree for alternating, field and dimension for classical etc.) # notice that we do not pack LabelFrame contents. We do that in _group_type_selection method instead. group_params_frame = LabelFrame(self, text="Parameters", padx=10, pady=5) group_params_frame.pack(expand=True, fill='x') # alternating self._alt_params = Frame(group_params_frame) self._alt_params.columnconfigure(1, weight=1) Label(self._alt_params, text="Degree").grid(sticky='w') self._alt_degree = NumberBox(self._alt_params, constraints=Constraints(min=5)) self._alt_degree.grid(row=0, column=1, sticky='we') # classical self._clas_params = Frame(group_params_frame) self._clas_params.columnconfigure(1, weight=1) Label(self._clas_params, text="Type").grid(row=0, sticky='w') self._clas_type = OptionList(self._clas_params, values=ClassicalGroup.types()) self._clas_type.variable.trace("w", lambda n, i, m: self._classical_group_type_selection()) self._clas_type.grid(row=0, column=1, sticky='we') Label(self._clas_params, text="Dimension").grid(row=1, sticky='w') self._clas_dim = NumberBox(self._clas_params) self._clas_dim.grid(row=1, column=1, sticky='we') Label(self._clas_params, text="Field order").grid(row=2, sticky='w') self._clas_field = NumberBox(self._clas_params, constraints=Constraints(primality=numeric.PRIME_POWER)) self._clas_field.grid(row=2, column=1, sticky='we') self._classical_group_type_selection() # exceptional self._ex_params = Frame(group_params_frame) self._ex_params.columnconfigure(1, weight=1) Label(self._ex_params, text="Type").grid(row=0, sticky='w') self._ex_type = OptionList(self._ex_params, values=ExceptionalGroup.types()) self._ex_type.setvar(value=ExceptionalGroup.types()[0]) self._ex_type.grid(row=0, column=1, sticky='we') Label(self._ex_params, text="Field order").grid(row=1, sticky='w') self._ex_field = NumberBox(self._ex_params, constraints=Constraints(primality=numeric.PRIME_POWER)) self._ex_field.grid(row=1, column=1, sticky='we') # sporadic self._spor_params = Frame(group_params_frame) self._spor_params.columnconfigure(1, weight=1) Label(self._spor_params, text="Group").grid(row=0, sticky='w') self._sporadic_group = OptionList(self._spor_params, values=SporadicGroup.all_groups()) self._sporadic_group.grid(row=0, column=1, sticky='we')
def create(self, S={}): root = self.root # #BackgroundFile = Image(file='/home/dmitrey/tmp_i/Backgd01.jpg') # bgfile = '/home/dmitrey/tmp_i/Backgd01.gif' # #bgfile = '/home/dmitrey/IP.png' # BackgroundFile = PhotoImage(file=bgfile) # #RootFrame.create_image(0, 0, image=BackgroundFile) RootFrame = Canvas(root)#, image=BackgroundFile) # RootFrame.create_image(0, 0, image=BackgroundFile) # RootFrame.image = BackgroundFile RootFrame.pack() self.NameEntriesList, self.LB_EntriesList, self.UB_EntriesList, self.TolEntriesList, self.ValueEntriesList = [], [], [], [], [] self.calculated_points = S.get('calculated_points', []) # Title #root.wm_title(' FuncDesigner ' + fdversion + ' Manager') C = Canvas(root) """ Buttons """ Frame(RootFrame).pack(ipady=4) #Label(root, text=' FuncDesigner ' + fdversion + ' ').pack() # Upper Frame UpperFrame = Frame(RootFrame) ProjectNameFrame = Frame(UpperFrame)#, relief = 'ridge', bd=2) Label(ProjectNameFrame, text = 'Project name:').pack(side = 'left') ProjectNameEntry = Entry(ProjectNameFrame) ProjectNameEntry.pack(side = 'left') self.ProjectNameEntry = ProjectNameEntry ProjectNameFrame.pack(side = 'left') GoalSelectFrame = Frame(UpperFrame, relief = 'ridge', bd=2) GoalSelectText = StringVar(value = 'Goal:') Label(GoalSelectFrame, textvariable = GoalSelectText).pack(side = 'left') goal = StringVar() r1 = Radiobutton(GoalSelectFrame, text = 'Minimum', value = 'min', variable=goal) r1.pack(side = 'left') r2 = Radiobutton(GoalSelectFrame, text = 'Maximum', value = 'max', variable=goal) r2.pack(side = 'left') goal.set('min') GoalSelectFrame.pack(side = 'left', padx = 10) self.goal = goal ObjectiveToleranceFrame = Frame(UpperFrame, relief = 'ridge', bd=2) ObjectiveToleranceFrame.pack(side='left') Label(ObjectiveToleranceFrame, text='Objective function tolerance:').pack(side = 'left') ObjTolEntry = Entry(ObjectiveToleranceFrame) ObjTolEntry.pack(side='left') self.ObjTolEntry = ObjTolEntry UpperFrame.pack(side = 'top', expand=True, fill = 'x') # Variables Frame varsRoot = Frame(RootFrame) # Lower frame LowerFrame = Frame(varsRoot) LowerFrame.pack(side = 'bottom', expand=True, fill = 'x') from webbrowser import open_new_tab About = Button(LowerFrame, text = 'About', command = lambda: open_new_tab('http://openopt.org/MultiFactorAnalysis')) About.pack(side='left') SaveButton = Button(LowerFrame, text = 'Save', command = self.save) SaveButton.pack(side='left', padx = 15) SaveAsButton = Button(LowerFrame, text = 'Save As ...', command = self.save) SaveAsButton.pack(side='left') Write_xls_Button = Button(LowerFrame, text = 'Write xls report', command = self.write_xls_report) Write_xls_Button.pack(side='left', padx = 15) # PlotButton = Button(LowerFrame, text = 'Plot', command = lambda: Plot(C, self.prob)) # PlotButton.pack(side='left') ExperimentNumber = IntVar() ExperimentNumber.set(1) self.ExperimentNumber = ExperimentNumber ObjVal = StringVar() ObjEntry = Entry(LowerFrame, textvariable = ObjVal) self.ObjEntry = ObjEntry NN = StringVar(LowerFrame) NN_Label = Label(LowerFrame, textvariable = NN) names, lbs, ubs, tols, currValues = \ Frame(varsRoot), Frame(varsRoot), Frame(varsRoot), Frame(varsRoot), Frame(varsRoot) Label(names, text=' Variable Name ').pack(side = 'top') Label(lbs, text=' Lower Bound ').pack(side = 'top') Label(ubs, text=' Upper Bound ').pack(side = 'top') Label(tols, text=' Tolerance ').pack(side = 'top') ValsColumnName = StringVar() ValsColumnName.set(' Initial Point ') Label(currValues, textvariable=ValsColumnName).pack(side = 'top') self.ValsColumnName = ValsColumnName # Commands Frame CommandsRoot = Frame(RootFrame) CommandsRoot.pack(side = 'right', expand = False, fill='y') AddVar = Button(CommandsRoot, text = 'Add Variable', command = \ lambda: self.addVar(names, lbs, ubs, tols, currValues)) AddVar.pack(side = 'top', fill='x') Next = Button(CommandsRoot, text = 'Next', command = lambda: ExperimentNumber.set(ExperimentNumber.get()+1)) #Next.pack(side='bottom', fill='x') names.pack(side = 'left', ipady=5) lbs.pack(side = 'left', ipady=5) ubs.pack(side = 'left', ipady=5) tols.pack(side = 'left', ipady=5) currValues.pack(side = 'left', ipady=5) #currValues.pack_forget() varsRoot.pack() Start = Button(CommandsRoot, text = 'Start', \ command = lambda: (Start.destroy(), \ Next.pack(side='bottom', fill='x'), #C.pack(side = 'bottom', expand=True, fill='both'), r1.config(state=DISABLED), r2.config(state=DISABLED), ObjTolEntry.config(state=DISABLED), ObjEntry.pack(side='right', ipady=4), NN_Label.pack(side='right'), \ self.startOptimization(root, varsRoot, AddVar, currValues, ValsColumnName, ObjEntry, ExperimentNumber, Next, NN, goal.get(), float(ObjTolEntry.get()), C))) Start.pack(side = 'bottom', fill='x') self.Start = Start if len(S) != 0: for i in range(len(S['names'])): tmp = S['values'][i] if self.x0 is None else self.x0.split(' ')[i] self.addVar(names, lbs, ubs, tols, currValues, S['names'][i], S['lbs'][i], S['ubs'][i], S['tols'][i], tmp) else: self.addVar(names, lbs, ubs, tols, currValues)
def initUI(self): """ Initializes the user interface Setting up the entry widgets for: - Experiment_ID - Participant Name - Session Day - Pupil Size - Practice - Stereo """ # Set the title self.parent.title(EXP_NAME) # Create the label for Experiment_ID and set location label_id = Label(text='Participant ID:') label_id.place(x=20, y=20) # Check the DATA_DIR directory for previous participants # and choose the next Experiment_ID in line self.folders = listdir(DATA_DIR) # Initiate Tkinter's StringVar self.value_id = StringVar() # Set the default value self.value_id.set('001') # Going in reverse order of the participants' directories in # DATA_DIR, find the last participant's Experiment_ID and opt # for the next one in line for folder in reversed(self.folders): try: # Check if the value of the first 3 digits of the # directory name is greater than the default value if int(folder[:3]) >= int(self.value_id.get()): # Get the next Experiment_ID in integer form and # convert to string format num = str(int(folder[:3]) + 1) # Actions to perform in case scenarios for each # of the possibilites of num_length num_length = {3: num, 2: '0%s' % num, 1: '00%s' % num} # Set the value accordingly to the StringVar, # replacing the default self.value_id.set(num_length[len(num)]) # In case there are other folders in DATA_DIR, for which # the first 3 characters are not digits, we must cater # for when an exception is thrown up except ValueError: pass # Create the entry widget for Experiment_ID with the preset # value and state disabled self.input_id = Entry(self.parent, width=5, state=DISABLED, textvariable=self.value_id) self.input_id.place(x=150, y=20) # Create the label for Participant Name and set location label_name = Label(text='Participant Name:') label_name.place(x=20, y=50) # Initiate Tkinter's StringVar self.value_name = StringVar() # Set the default value self.value_name.set('') # Create the entry for Participant Name and set location self.input_name = Entry(self.parent, width=35, textvariable=self.value_name) self.input_name.place(x=150, y=50) self.input_name.focus() # Create the label for Session Day and set location label_day = Label(text='Session Day:') label_day.place(x=20, y=80) # Create value holder for Session Day as IntVar and set default # value to 1 self.value_day = IntVar() self.value_day.set(1) # Create the radiobuttons as required for day in range(1, TOTAL_SESSIONS + 1): input_day = Radiobutton(self.parent, text=str(day), variable=self.value_day, value=day) # Anchor them to the West (W) input_day.pack(anchor=W) # Choose location for the radiobuttons input_day.place(x=150, y=(50 + (day * 25))) # Create the label for Pupil Size and set location label_pupilsize = Label(text='Pupil Size:') label_pupilsize.place(x=20, y=140) self.value_pupilsize = StringVar() self.value_pupilsize.set('') # Create the MaxLengthEntry for Pupil Size and set location # The maximum length is set to 3 characters and a float must be # provided self.input_pupilsize = MaxLengthEntry(self.parent, width=5, maxlength=3, required_type=float) self.input_pupilsize.config(textvariable=self.value_pupilsize) self.input_pupilsize.place(x=150, y=140) # Create value folder for Practice as IntVar self.value_practice = IntVar() # Create the checkbutton for Practice and set location input_practice = Checkbutton(self.parent, text='Practice', variable=self.value_practice, onvalue=1, offvalue=0) input_practice.place(x=150, y=170) # Create value holder for Stereo as IntVar self.value_stereo = IntVar() # Create the checkbutton for Stereo and set location input_stereo = Checkbutton(self.parent, text='Stereo', variable=self.value_stereo, onvalue=1, offvalue=0) input_stereo.place(x=150, y=200) # Create the label for Previous Subjects and set location label_previous = Label(text='Previous Subjects:') label_previous.place(x=20, y=250) # Create the Listboc containing all the previous participants self.input_previous = Listbox(self.parent, width=35, height=10) for identifier in self.folders: self.input_previous.insert(END, identifier) self.input_previous.place(x=150, y=250) self.input_previous.bind('<<ListboxSelect>>', self.__select_previous) # Create the submit button, give command upon pressing and set # location submit = Button(text='Submit', width=47, command=self.gather_input) submit.pack(padx=8, pady=8) submit.place(x=20, y=425)
def create(self, S={}): root = self.root # #BackgroundFile = Image(file='/home/dmitrey/tmp_i/Backgd01.jpg') # bgfile = '/home/dmitrey/tmp_i/Backgd01.gif' # #bgfile = '/home/dmitrey/IP.png' # BackgroundFile = PhotoImage(file=bgfile) # #RootFrame.create_image(0, 0, image=BackgroundFile) RootFrame = Canvas(root) #, image=BackgroundFile) # RootFrame.create_image(0, 0, image=BackgroundFile) # RootFrame.image = BackgroundFile RootFrame.pack() self.NameEntriesList, self.LB_EntriesList, self.UB_EntriesList, self.TolEntriesList, self.ValueEntriesList = [], [], [], [], [] self.calculated_points = S.get('calculated_points', []) # Title #root.wm_title(' FuncDesigner ' + fdversion + ' Manager') C = Canvas(root) """ Buttons """ Frame(RootFrame).pack(ipady=4) #Label(root, text=' FuncDesigner ' + fdversion + ' ').pack() # Upper Frame UpperFrame = Frame(RootFrame) ProjectNameFrame = Frame(UpperFrame) #, relief = 'ridge', bd=2) Label(ProjectNameFrame, text='Project name:').pack(side='left') ProjectNameEntry = Entry(ProjectNameFrame) ProjectNameEntry.pack(side='left') self.ProjectNameEntry = ProjectNameEntry ProjectNameFrame.pack(side='left') GoalSelectFrame = Frame(UpperFrame, relief='ridge', bd=2) GoalSelectText = StringVar(value='Goal:') Label(GoalSelectFrame, textvariable=GoalSelectText).pack(side='left') goal = StringVar() r1 = Radiobutton(GoalSelectFrame, text='Minimum', value='min', variable=goal) r1.pack(side='left') r2 = Radiobutton(GoalSelectFrame, text='Maximum', value='max', variable=goal) r2.pack(side='left') goal.set('min') GoalSelectFrame.pack(side='left', padx=10) self.goal = goal ObjectiveToleranceFrame = Frame(UpperFrame, relief='ridge', bd=2) ObjectiveToleranceFrame.pack(side='left') Label(ObjectiveToleranceFrame, text='Objective function tolerance:').pack(side='left') ObjTolEntry = Entry(ObjectiveToleranceFrame) ObjTolEntry.pack(side='left') self.ObjTolEntry = ObjTolEntry UpperFrame.pack(side='top', expand=True, fill='x') # Variables Frame varsRoot = Frame(RootFrame) # Lower frame LowerFrame = Frame(varsRoot) LowerFrame.pack(side='bottom', expand=True, fill='x') from webbrowser import open_new_tab About = Button(LowerFrame, text='About', command=lambda: open_new_tab( 'http://openopt.org/MultiFactorAnalysis')) About.pack(side='left') SaveButton = Button(LowerFrame, text='Save', command=self.save) SaveButton.pack(side='left', padx=15) SaveAsButton = Button(LowerFrame, text='Save As ...', command=self.save) SaveAsButton.pack(side='left') Write_xls_Button = Button(LowerFrame, text='Write xls report', command=self.write_xls_report) Write_xls_Button.pack(side='left', padx=15) # PlotButton = Button(LowerFrame, text = 'Plot', command = lambda: Plot(C, self.prob)) # PlotButton.pack(side='left') ExperimentNumber = IntVar() ExperimentNumber.set(1) self.ExperimentNumber = ExperimentNumber ObjVal = StringVar() ObjEntry = Entry(LowerFrame, textvariable=ObjVal) self.ObjEntry = ObjEntry NN = StringVar(LowerFrame) NN_Label = Label(LowerFrame, textvariable=NN) names, lbs, ubs, tols, currValues = \ Frame(varsRoot), Frame(varsRoot), Frame(varsRoot), Frame(varsRoot), Frame(varsRoot) Label(names, text=' Variable Name ').pack(side='top') Label(lbs, text=' Lower Bound ').pack(side='top') Label(ubs, text=' Upper Bound ').pack(side='top') Label(tols, text=' Tolerance ').pack(side='top') ValsColumnName = StringVar() ValsColumnName.set(' Initial Point ') Label(currValues, textvariable=ValsColumnName).pack(side='top') self.ValsColumnName = ValsColumnName # Commands Frame CommandsRoot = Frame(RootFrame) CommandsRoot.pack(side='right', expand=False, fill='y') AddVar = Button(CommandsRoot, text = 'Add Variable', command = \ lambda: self.addVar(names, lbs, ubs, tols, currValues)) AddVar.pack(side='top', fill='x') Next = Button( CommandsRoot, text='Next', command=lambda: ExperimentNumber.set(ExperimentNumber.get() + 1)) #Next.pack(side='bottom', fill='x') names.pack(side='left', ipady=5) lbs.pack(side='left', ipady=5) ubs.pack(side='left', ipady=5) tols.pack(side='left', ipady=5) currValues.pack(side='left', ipady=5) #currValues.pack_forget() varsRoot.pack() Start = Button(CommandsRoot, text = 'Start', \ command = lambda: (Start.destroy(), \ Next.pack(side='bottom', fill='x'), #C.pack(side = 'bottom', expand=True, fill='both'), r1.config(state=DISABLED), r2.config(state=DISABLED), ObjTolEntry.config(state=DISABLED), ObjEntry.pack(side='right', ipady=4), NN_Label.pack(side='right'), \ self.startOptimization(root, varsRoot, AddVar, currValues, ValsColumnName, ObjEntry, ExperimentNumber, Next, NN, goal.get(), float(ObjTolEntry.get()), C))) Start.pack(side='bottom', fill='x') self.Start = Start if len(S) != 0: for i in range(len(S['names'])): tmp = S['values'][i] if self.x0 is None else self.x0.split( ' ')[i] self.addVar(names, lbs, ubs, tols, currValues, S['names'][i], S['lbs'][i], S['ubs'][i], S['tols'][i], tmp) else: self.addVar(names, lbs, ubs, tols, currValues)
class Controller(Observer): def __init__(self,parent,view,lissajou,subjectSig,subjects): self.cursorFrame = Frame(parent) self.selectionFrame = Frame(self.cursorFrame) self.view = view self.lissajou = lissajou self.subjects = subjects self.subjectSig=subjectSig self.amp=IntVar() self.scale_amp=Scale(self.cursorFrame,variable=self.amp, label="Amplitude", orient="horizontal",length=250,from_=0,to=10, sliderlength=50,tickinterval=1,showvalue=0, command=self.update) self.freq=IntVar() self.scale_freq=Scale(self.cursorFrame,variable=self.freq, label="Frequence", orient="horizontal",length=250,from_=0,to=10, sliderlength=50,tickinterval=0,showvalue=0, command=self.update) self.offset=DoubleVar() self.scale_offset=Scale(self.cursorFrame,variable=self.offset, label="Offset", orient="horizontal",length=250,from_=-10.0,to=10.0, sliderlength=50,tickinterval=5,showvalue=0, command=self.update) self.phase=IntVar() self.scale_phase=Scale(self.cursorFrame,variable=self.phase, label="Phase", orient="horizontal",length=250,from_=-90,to=90, sliderlength=10,tickinterval=45,showvalue=0, command=self.update) self.voltVar = DoubleVar() self.voltVar.set(1) self.button1 = Radiobutton(self.selectionFrame, text="1V", variable=self.voltVar, value=1.0*5.0,command =lambda:self.update(None)) self.button1.select() self.button2 = Radiobutton(self.selectionFrame, text="2V", variable=self.voltVar, value=2.0*5.0, command =lambda:self.update(None)) self.button5 = Radiobutton(self.selectionFrame, text="5V", variable=self.voltVar, value=5.0*5.0, command =lambda:self.update(None)) self.isOffsetVar= IntVar() self.isOffset = Checkbutton(self.selectionFrame,text = "Offset",variable = self.isOffsetVar, command =lambda:self.update(None)) def update(self,event): self.update_amplitude(event) self.update_offset(event) self.update_frequency(event) self.update_phase(event) self.view.update() if self.lissajou!=None: self.lissajou.update() def update_amplitude(self,event): print("update_amplitude(self,event)",self.amp.get()) self.subjectSig.set_magnitude(self.amp.get()/self.voltVar.get()) self.subjects.generate_XYCurve() def update_frequency(self,event): print("update_frequency(self,event)",self.freq.get()) self.subjectSig.set_frequency(self.freq.get()) self.subjects.generate_XYCurve() def update_phase(self,event): print("update_phase(self,event)",self.phase.get()) self.subjectSig.set_phase(self.phase.get()) self.subjects.generate_XYCurve() def update_offset(self,event): if self.isOffsetVar.get(): print("update_offset(self,event)",self.isOffsetVar.get()) self.subjectSig.set_offset(self.offset.get()/self.voltVar.get()) self.subjects.generate_XYCurve() else: self.subjectSig.set_offset(0.0) self.subjects.generate_XYCurve() def setLissajou(self,lissajou): self.lissajou = lissajou def packing(self) : self.selectionFrame.pack(side='top') self.button1.pack(side='left') self.button2.pack(side='left') self.button5.pack(side='left') self.isOffset.pack(side='left') self.cursorFrame.pack(side='left',expand=1, fill='both') self.scale_amp.pack() self.scale_freq.pack() self.scale_offset.pack() self.scale_phase.pack()
class TabButton(Frame): """A simple tab-like widget.""" bw = 2 # borderwidth def __init__(self, name, select_command, tab_row, tab_set): """Constructor arguments: name -- The tab's name, which will appear in its button. select_command -- The command to be called upon selection of the tab. It is called with the tab's name as an argument. """ Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED) self.name = name self.select_command = select_command self.tab_set = tab_set self.is_last_in_row = False self.button = Radiobutton( self, text=name, command=self._select_event, padx=5, pady=1, takefocus=False, indicatoron=False, highlightthickness=0, selectcolor='', borderwidth=0) self.button.pack(side=LEFT, fill=X, expand=True) self._init_masks() self.set_normal() def _select_event(self, *args): """Event handler for tab selection. With TabbedPageSet, this calls TabbedPageSet.change_page, so that selecting a tab changes the page. Note that this does -not- call set_selected -- it will be called by TabSet.set_selected_tab, which should be called when whatever the tabs are related to changes. """ self.select_command(self.name) return def set_selected(self): """Assume selected look""" self._place_masks(selected=True) def set_normal(self): """Assume normal look""" self._place_masks(selected=False) def _init_masks(self): page_set = self.tab_set.page_set background = page_set.pages_frame.cget('background') # mask replaces the middle of the border with the background color self.mask = Frame(page_set, borderwidth=0, relief=FLAT, background=background) # mskl replaces the bottom-left corner of the border with a normal # left border self.mskl = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskl.ml = Frame(self.mskl, borderwidth=self.bw, relief=RAISED) self.mskl.ml.place(x=0, y=-self.bw, width=2*self.bw, height=self.bw*4) # mskr replaces the bottom-right corner of the border with a normal # right border self.mskr = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskr.mr = Frame(self.mskr, borderwidth=self.bw, relief=RAISED) def _place_masks(self, selected=False): height = self.bw if selected: height += self.bw self.mask.place(in_=self, relx=0.0, x=0, rely=1.0, y=0, relwidth=1.0, width=0, relheight=0.0, height=height) self.mskl.place(in_=self, relx=0.0, x=-self.bw, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) page_set = self.tab_set.page_set if selected and ((not self.is_last_in_row) or (self.winfo_rootx() + self.winfo_width() < page_set.winfo_rootx() + page_set.winfo_width()) ): # for a selected tab, if its rightmost edge isn't on the # rightmost edge of the page set, the right mask should be one # borderwidth shorter (vertically) height -= self.bw self.mskr.place(in_=self, relx=1.0, x=0, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) self.mskr.mr.place(x=-self.bw, y=-self.bw, width=2*self.bw, height=height + self.bw*2) # finally, lower the tab set so that all of the frames we just # placed hide it self.tab_set.lower()
class BoardConfig(Frame): def __init__(self, master=None, main=None): Frame.__init__(self, master) self.parent = master self.main = main self.parent.geometry("336x424") self.parent.title(os.getenv("NAME") + " - Board Config") self.master.configure(padx=10, pady=10) self.intvar = IntVar() #Arch self.arch_var = IntVar() lf_arch = LabelFrame(self.parent, text="Architecture") lf_arch.pack(fill=X, expand=True, side=TOP) frame_arch = Frame(lf_arch) frame_arch.pack(fill=X, expand=True, side=TOP) frame_left1 = Frame(frame_arch) frame_left1.pack(expand=True, fill=BOTH, side=LEFT) frame_right1 = Frame(frame_arch) frame_right1.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_arch_8 = Radiobutton(frame_left1, text="8-bit ", anchor="w", width=10, value=8, variable=self.arch_var, command=self.update_mode) self.radioButton_arch_8.pack(fill=X, side=TOP) self.radioButton_arch_32 = Radiobutton(frame_right1, text="32-bit", anchor="w", width=10, value=32, variable=self.arch_var, command=self.update_mode) self.radioButton_arch_32.pack(fill=X, side=TOP) #Mode self.mode_var = StringVar() lf_mode = LabelFrame(self.parent, text="Programming mode") lf_mode.pack(fill=X, expand=True, side=TOP) frame_mode = Frame(lf_mode) frame_mode.pack(fill=X, expand=True, side=TOP) frame_left2 = Frame(frame_mode) frame_left2.pack(expand=True, fill=BOTH, side=LEFT) frame_right2 = Frame(frame_mode) frame_right2.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_mode_icsp = Radiobutton(frame_left2, text="ICSP", anchor="w", width=10, value="icsp", variable=self.mode_var, command=self.update_mode) self.radioButton_mode_icsp.pack(side=TOP, fill=X) self.radioButton_mode_bootloader = Radiobutton(frame_right2, text="Bootloader", anchor="w", width=10, value="bootloader", variable=self.mode_var, command=self.update_mode) self.radioButton_mode_bootloader.pack(side=TOP, fill=X) #Bootloader self.boot_var = StringVar() self.lf_boot = LabelFrame(self.parent, text="Bootloader") self.lf_boot.pack(fill=X, expand=True, side=TOP) frame_boot = Frame(self.lf_boot) frame_boot.pack(fill=X, expand=True, side=TOP) frame_left3 = Frame(frame_boot) frame_left3.pack(expand=True, fill=BOTH, side=LEFT) frame_right3 = Frame(frame_boot) frame_right3.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_bootloader_v1_v2 = Radiobutton(frame_left3, text="v1.x or v2.x", anchor="w", width=10, value="v1_v2", variable=self.boot_var) self.radioButton_bootloader_v1_v2.pack(fill=X, side=TOP, expand=True) self.radioButton_bootloader_v4 = Radiobutton(frame_right3, text="v4.x", anchor="w", width=10, value="v4", variable=self.boot_var) self.radioButton_bootloader_v4.pack(fill=X, side=TOP, expand=True) #Devices 8bit self.dev8_var = StringVar() self.lf_dev8 = LabelFrame(self.parent, text="Devices") self.lf_dev8.pack(fill=X, expand=True, side=TOP) self.frame_8b = Frame(self.lf_dev8) self.frame_8b.pack(fill=X, expand=True, side=TOP) #Devices 32bit self.dev32_var = StringVar() self.lf_dev32 = LabelFrame(self.parent, text="Devices") self.lf_dev32.pack(fill=X, expand=True, side=TOP) self.frame_32b = Frame(self.lf_dev32) self.frame_32b.pack(fill=X, expand=True, side=TOP) frame_buttons = Frame(self.parent) Button(frame_buttons, text="Accept", command=self.accept_config).pack(fill=X, expand=True, side=RIGHT) Button(frame_buttons, text="Cancel", command=self.quit).pack(fill=X, expand=True, side=LEFT) frame_buttons.pack(fill=X, expand=True, side=BOTTOM) frame_advance = Frame(self.parent) self.advanceoptions = Button(frame_advance, text="Advance options", command=self.advance) self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) frame_advance.pack(fill=X, expand=True, side=BOTTOM) frame_warning = Frame(self.parent) self.label_warning = Label(frame_warning, fg="red", text="warning!", anchor="w") self.label_warning.pack(fill=X, expand=True, side=BOTTOM) frame_warning.pack(fill=X, expand=True, side=BOTTOM) self.build_devices_arch() self.load_config() self.init_groups() #---------------------------------------------------------------------- def quit(self): self.master.destroy() #---------------------------------------------------------------------- def build_devices_arch(self): #8bits name_checked = self.main.configIDE.config("Board", "board_8", "Pinguino 2550") arch_8 = filter(lambda board:board.arch==8, self.main.pinguinoAPI._boards_) arch_8.sort() frame_left = Frame(self.frame_8b) frame_left.pack(expand=True, fill=BOTH, side=LEFT) frame_right = Frame(self.frame_8b) frame_right.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left #left for board in arch_8: if arch_8.index(board) == (len(arch_8) / 2) + 1: parent = frame_right #rigth radio = Radiobutton(parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev8_var, command=lambda :self.set_board_name(board.name, "8")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_8) #self.board_config.gridLayout_device_8.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "8")) #32bits name_checked = self.main.configIDE.config("Board", "board_32", "PIC32 Pinguino OTG") arch_32 = filter(lambda board:board.arch==32, self.main.pinguinoAPI._boards_) arch_32.sort() frame_left0 = Frame(self.frame_32b) frame_left0.pack(expand=True, fill=BOTH, side=LEFT) frame_right0 = Frame(self.frame_32b) frame_right0.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left0 #left for board in arch_32: if arch_32.index(board) == (len(arch_32) / 2) + 1: parent = frame_right0 #rigth radio = Radiobutton(parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev32_var, command=lambda :self.set_board_name(board.name, "32")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_32) #self.board_config.gridLayout_device_32.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "32")) #---------------------------------------------------------------------- def load_config(self): self.main.configIDE.load_config() arch = self.main.configIDE.config("Board", "arch", 8) getattr(self.radioButton_arch_8, "select" if (arch == 8) else "deselect")() getattr(self.radioButton_arch_32, "select" if (arch == 32) else "deselect")() if arch == 32: self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) else: self.advanceoptions.forget() mode = self.main.configIDE.config("Board", "mode", "bootloader") getattr(self.radioButton_mode_bootloader, "select" if (mode == "bootloader") else "deselect")() getattr(self.radioButton_mode_icsp, "select" if (mode == "icsp") else "deselect")() bootloader = self.main.configIDE.config("Board", "bootloader", "v1_v2") getattr(self.radioButton_bootloader_v1_v2, "select" if (bootloader == "v1_v2") else "deselect")() getattr(self.radioButton_bootloader_v4, "select" if (bootloader == "v4") else "deselect")() self.update_mode() #---------------------------------------------------------------------- def update_mode(self): mode_boot = self.mode_var.get() == "bootloader" arch_8 = self.arch_var.get() == 8 if mode_boot and arch_8: self.lf_boot.pack(fill=X, expand=True, side=TOP) else: self.lf_boot.forget() self.init_groups() if not mode_boot: self.label_warning.configure(text="WARNING!! this mode can overwite the bootloader code.") else: self.label_warning.configure(text="") #---------------------------------------------------------------------- def set_board_name(self, name, arch): def dummy(): self.main.configIDE.set("Board", "board_"+arch, name) return dummy #---------------------------------------------------------------------- def init_groups(self): self.lf_dev32.forget() self.lf_dev8.forget() if self.arch_var.get() == 8: self.lf_dev8.pack(fill=X, expand=True, side=TOP) self.advanceoptions.forget() else: self.lf_dev32.pack(fill=X, expand=True, side=TOP) self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) #---------------------------------------------------------------------- def save_config(self): #if self.board_config.radioButton_arch_8.isChecked(): arch = 8 #else: arch = 32 self.main.configIDE.set("Board", "arch", self.arch_var.get()) #if self.board_config.radioButton_mode_bootloader.isChecked(): mode = "bootloader" #else: mode = "icsp" self.main.configIDE.set("Board", "mode", self.mode_var.get()) #if self.board_config.radioButton_bootloader_v1_v2.isChecked(): bootloader = "v1_v2" #else: bootloader = "v4" self.main.configIDE.set("Board", "bootloader", self.boot_var.get()) name = self.main.configIDE.config("Board", "board_"+str(self.arch_var.get()), None) self.main.configIDE.set("Board", "board", name) #---------------------------------------------------------------------- def accept_config(self): self.save_config() self.main.configIDE.save_config() self.main.statusbar_ide(self.main.get_status_board()) self.close_advance() self.quit() #---------------------------------------------------------------------- def advance(self): root = Toplevel() self.frame_advance = BoardConfigAdvance(master=root, main=self.main) self.frame_advance.mainloop() #---------------------------------------------------------------------- def close_advance(self): try: assert self.frame_advance except: return self.frame_advance.quit()
def __init__(self, app, printer, settings, logger, *arg): self.app = app self.printer = printer self.settings = settings self.logger = logger self.afterID = None self.selection = None if not self.app.printing: self.logger.logMsg("Report only available while printing") return Toplevel.__init__(self, app, *arg) self.title("Layer by Layer Timing") self.protocol("WM_DELETE_WINDOW", self.doCancel) fUL = Frame(self) fUL.grid(row=1, column=1, rowspan=2, padx=10) l = Label(fUL, text="Choose layer:") l.pack() lbf = Frame(fUL) lbf.pack() self.lbLayers = Listbox(lbf) self.lbLayers.bind("<ButtonRelease-1>", self.clickLayers) self.sb = Scrollbar(lbf, orient=VERTICAL) self.sb.config(command=self.lbLayers.yview) self.lbLayers.config(yscrollcommand=self.sb.set) self.sb.pack(side=RIGHT, fill=Y) self.lbLayers.pack(side=LEFT, fill=BOTH, expand=1) rbf = LabelFrame(fUL, text="Time Format") rbf.pack() self.rbvTimeFmt = StringVar() self.rbvTimeFmt.set(TIME_WALL) rb = Radiobutton(rbf, text="Wall time", variable=self.rbvTimeFmt, value=TIME_WALL, command=self.doTimeFormat) rb.pack(anchor=W) rb = Radiobutton(rbf, text="From start", variable=self.rbvTimeFmt, value=TIME_START, command=self.doTimeFormat) rb.pack(anchor=W) rb = Radiobutton(rbf, text="From now", variable=self.rbvTimeFmt, value=TIME_NOW, command=self.doTimeFormat) rb.pack(anchor=W) fUR = Frame(self) fUR.grid(row=1, column=2, rowspan=2, padx=10) row = 1 lf = LabelFrame(fUR, text="Print Times: ") lf.grid(row=row, column=1) l = Label(lf, text="Start: ", width=12, justify=RIGHT) l.grid(row=1, column=1, padx=10, sticky=E) self.timePStart = Label(lf, text="", anchor=W, justify=LEFT) self.timePStart.grid(row=1, column=3, padx=10) l = Label(lf, text="Elapsed: ", width=12, justify=RIGHT) l.grid(row=2, column=1, padx=10, sticky=E) self.timeElapsed = Label(lf, text="", anchor=W, justify=LEFT) self.timeElapsed.grid(row=2, column=3, padx=10) l = Label(lf, text="Current: ", width=12, justify=RIGHT) l.grid(row=3, column=1, padx=10, sticky=E) self.timeNow = Label(lf, text="", anchor=W, justify=LEFT) self.timeNow.grid(row=3, column=3, padx=10) row += 1 lf = LabelFrame(fUR, text="Layer Start Time: ") lf.grid(row=row, column=1) l = Label(lf, text="original: ", width=12, justify=RIGHT) l.grid(row=1, column=1, padx=10, sticky=E) self.timeOStart = Label(lf, text="", anchor=W, justify=LEFT) self.timeOStart.grid(row=1, column=2, padx=10) l = Label(lf, text="revised: ", width=12, justify=RIGHT) l.grid(row=2, column=1, padx=10, sticky=E) self.timeRStart = Label(lf, text="", anchor=W, justify=LEFT) self.timeRStart.grid(row=2, column=2, padx=10) row += 1 lf = LabelFrame(fUR, text="Time in Layer: ") lf.grid(row=row, column=1) l = Label(lf, text="original: ", width=12, justify=RIGHT) l.grid(row=1, column=2, padx=10, sticky=E) self.timeOLayer = Label(lf, text="", anchor=W, justify=LEFT) self.timeOLayer.grid(row=1, column=3, padx=10) l = Label(lf, text="revised: ", width=12, justify=RIGHT) l.grid(row=2, column=2, padx=10, sticky=E) self.timeRLayer = Label(lf, text="", anchor=W, justify=LEFT) self.timeRLayer.grid(row=2, column=3, padx=10) row += 1 lf = LabelFrame(fUR, text="Layer Finish Time: ") lf.grid(row=row, column=1) l = Label(lf, text="original: ", width=12, justify=RIGHT) l.grid(row=1, column=2, padx=10, sticky=E) self.timeOFinish = Label(lf, text="", anchor=W, justify=LEFT) self.timeOFinish.grid(row=1, column=3, padx=10) l = Label(lf, text="revised: ", width=12, justify=RIGHT) l.grid(row=2, column=2, padx=10, sticky=E) self.timeRFinish = Label(lf, text="", anchor=W, justify=LEFT) self.timeRFinish.grid(row=2, column=3, padx=10) self.ticker()
def build_devices_arch(self): #8bits name_checked = self.main.configIDE.config("Board", "board_8", "Pinguino 2550") arch_8 = filter(lambda board: board.arch == 8, self.main.pinguinoAPI._boards_) arch_8.sort() frame_left = Frame(self.frame_8b) frame_left.pack(expand=True, fill=BOTH, side=LEFT) frame_right = Frame(self.frame_8b) frame_right.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left #left for board in arch_8: if arch_8.index(board) == (len(arch_8) / 2) + 1: parent = frame_right #rigth radio = Radiobutton( parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev8_var, command=lambda: self.set_board_name(board.name, "8")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_8) #self.board_config.gridLayout_device_8.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "8")) #32bits name_checked = self.main.configIDE.config("Board", "board_32", "PIC32 Pinguino OTG") arch_32 = filter(lambda board: board.arch == 32, self.main.pinguinoAPI._boards_) arch_32.sort() frame_left0 = Frame(self.frame_32b) frame_left0.pack(expand=True, fill=BOTH, side=LEFT) frame_right0 = Frame(self.frame_32b) frame_right0.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left0 #left for board in arch_32: if arch_32.index(board) == (len(arch_32) / 2) + 1: parent = frame_right0 #rigth radio = Radiobutton( parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev32_var, command=lambda: self.set_board_name(board.name, "32")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_32) #self.board_config.gridLayout_device_32.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select()
class MainWindow: def __init__(self): self.root = Tk() self.input_type = Tkinter.IntVar() self.input_type.set(1) self.normalize_data = Tkinter.IntVar() self.normalize_data.set(1) self.root.title("Code energy calculator") self.left_frame = LabelFrame(self.root, text="Input and output") self.left_frame.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=True, padx=(10, 5), pady=10) self.right_frame = LabelFrame(self.root, text="Code") self.right_frame.pack(side=Tkinter.RIGHT, fill=Tkinter.BOTH, expand=True, padx=(5, 10), pady=10) code_hscroll = Scrollbar(self.right_frame, orient=Tkinter.HORIZONTAL) code_hscroll.pack(side=Tkinter.BOTTOM, fill=Tkinter.X) code_vscroll = Scrollbar(self.right_frame) code_vscroll.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) self.code_text = Text(self.right_frame, wrap=Tkinter.NONE, xscrollcommand=code_hscroll.set, yscrollcommand=code_vscroll.set) self.code_text.pack() self.code_text.insert(Tkinter.INSERT, DEFAULT_CODE) code_hscroll.config(command=self.code_text.xview) code_vscroll.config(command=self.code_text.yview) self.input_file_entry =\ self.create_and_add_file_field(self.left_frame, "Input file", 5, False) self.spherical_coord_option =\ Radiobutton(self.left_frame, text="Spherical coordinates", variable=self.input_type, value=1) self.spherical_coord_option.pack(anchor=Tkinter.W) self.cartesian_coord_option =\ Radiobutton(self.left_frame, text="Cartesian coordinates", variable=self.input_type, value=2) self.cartesian_coord_option.pack(anchor=Tkinter.W) self.spherical_coord_option.select() self.output_file_entry =\ self.create_and_add_file_field(self.left_frame, "Output file", 5, True) self.normalize_check = Checkbutton(self.left_frame, text="Normalize data", variable=self.normalize_data, offvalue=0, onvalue=1) self.normalize_check.pack() self.normalize_check.deselect() self.do_button = Button(self.left_frame, text="Run", command=self.run) self.do_button.pack(side=Tkinter.BOTTOM, pady=(0, 10)) def create_and_add_file_field(self, parent, title, pad, is_save): title_label = Label(parent, text=title) title_label.pack(side=Tkinter.TOP, padx=pad) container_frame = Frame(parent) container_frame.pack(side=Tkinter.TOP, padx=pad, pady=(0, pad)) filename_entry = Entry(container_frame) filename_entry.pack(side=Tkinter.LEFT) browse_button = \ Button(container_frame, text="Browse...", command=lambda: self.select_file(filename_entry, is_save)) browse_button.pack(side=Tkinter.RIGHT) return filename_entry @staticmethod def select_file(text_field, is_save): text_field.delete(0, Tkinter.END) if is_save: filename = asksaveasfilename() else: filename = askopenfilename() text_field.insert(0, filename) def run(self): input_fname = self.input_file_entry.get() output_fname = self.output_file_entry.get() code = self.code_text.get(1.0, Tkinter.END) do_work(input_fname, output_fname, code, self.input_type.get(), self.normalize_data.get()) def show(self): self.root.mainloop()
class BoardConfig(Frame): def __init__(self, master=None, main=None): Frame.__init__(self, master) self.parent = master self.main = main self.parent.geometry("336x424") self.parent.title(os.getenv("NAME") + " - Board Config") self.master.configure(padx=10, pady=10) self.intvar = IntVar() #Arch self.arch_var = IntVar() lf_arch = LabelFrame(self.parent, text="Architecture") lf_arch.pack(fill=X, expand=True, side=TOP) frame_arch = Frame(lf_arch) frame_arch.pack(fill=X, expand=True, side=TOP) frame_left1 = Frame(frame_arch) frame_left1.pack(expand=True, fill=BOTH, side=LEFT) frame_right1 = Frame(frame_arch) frame_right1.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_arch_8 = Radiobutton(frame_left1, text="8-bit ", anchor="w", width=10, value=8, variable=self.arch_var, command=self.update_mode) self.radioButton_arch_8.pack(fill=X, side=TOP) self.radioButton_arch_32 = Radiobutton(frame_right1, text="32-bit", anchor="w", width=10, value=32, variable=self.arch_var, command=self.update_mode) self.radioButton_arch_32.pack(fill=X, side=TOP) #Mode self.mode_var = StringVar() lf_mode = LabelFrame(self.parent, text="Programming mode") lf_mode.pack(fill=X, expand=True, side=TOP) frame_mode = Frame(lf_mode) frame_mode.pack(fill=X, expand=True, side=TOP) frame_left2 = Frame(frame_mode) frame_left2.pack(expand=True, fill=BOTH, side=LEFT) frame_right2 = Frame(frame_mode) frame_right2.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_mode_icsp = Radiobutton(frame_left2, text="ICSP", anchor="w", width=10, value="icsp", variable=self.mode_var, command=self.update_mode) self.radioButton_mode_icsp.pack(side=TOP, fill=X) self.radioButton_mode_bootloader = Radiobutton( frame_right2, text="Bootloader", anchor="w", width=10, value="bootloader", variable=self.mode_var, command=self.update_mode) self.radioButton_mode_bootloader.pack(side=TOP, fill=X) #Bootloader self.boot_var = StringVar() self.lf_boot = LabelFrame(self.parent, text="Bootloader") self.lf_boot.pack(fill=X, expand=True, side=TOP) frame_boot = Frame(self.lf_boot) frame_boot.pack(fill=X, expand=True, side=TOP) frame_left3 = Frame(frame_boot) frame_left3.pack(expand=True, fill=BOTH, side=LEFT) frame_right3 = Frame(frame_boot) frame_right3.pack(expand=True, fill=BOTH, side=RIGHT) self.radioButton_bootloader_v1_v2 = Radiobutton(frame_left3, text="v1.x or v2.x", anchor="w", width=10, value="v1_v2", variable=self.boot_var) self.radioButton_bootloader_v1_v2.pack(fill=X, side=TOP, expand=True) self.radioButton_bootloader_v4 = Radiobutton(frame_right3, text="v4.x", anchor="w", width=10, value="v4", variable=self.boot_var) self.radioButton_bootloader_v4.pack(fill=X, side=TOP, expand=True) #Devices 8bit self.dev8_var = StringVar() self.lf_dev8 = LabelFrame(self.parent, text="Devices") self.lf_dev8.pack(fill=X, expand=True, side=TOP) self.frame_8b = Frame(self.lf_dev8) self.frame_8b.pack(fill=X, expand=True, side=TOP) #Devices 32bit self.dev32_var = StringVar() self.lf_dev32 = LabelFrame(self.parent, text="Devices") self.lf_dev32.pack(fill=X, expand=True, side=TOP) self.frame_32b = Frame(self.lf_dev32) self.frame_32b.pack(fill=X, expand=True, side=TOP) frame_buttons = Frame(self.parent) Button(frame_buttons, text="Accept", command=self.accept_config).pack(fill=X, expand=True, side=RIGHT) Button(frame_buttons, text="Cancel", command=self.quit).pack(fill=X, expand=True, side=LEFT) frame_buttons.pack(fill=X, expand=True, side=BOTTOM) frame_advance = Frame(self.parent) self.advanceoptions = Button(frame_advance, text="Advance options", command=self.advance) self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) frame_advance.pack(fill=X, expand=True, side=BOTTOM) frame_warning = Frame(self.parent) self.label_warning = Label(frame_warning, fg="red", text="warning!", anchor="w") self.label_warning.pack(fill=X, expand=True, side=BOTTOM) frame_warning.pack(fill=X, expand=True, side=BOTTOM) self.build_devices_arch() self.load_config() self.init_groups() #---------------------------------------------------------------------- def quit(self): self.master.destroy() #---------------------------------------------------------------------- def build_devices_arch(self): #8bits name_checked = self.main.configIDE.config("Board", "board_8", "Pinguino 2550") arch_8 = filter(lambda board: board.arch == 8, self.main.pinguinoAPI._boards_) arch_8.sort() frame_left = Frame(self.frame_8b) frame_left.pack(expand=True, fill=BOTH, side=LEFT) frame_right = Frame(self.frame_8b) frame_right.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left #left for board in arch_8: if arch_8.index(board) == (len(arch_8) / 2) + 1: parent = frame_right #rigth radio = Radiobutton( parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev8_var, command=lambda: self.set_board_name(board.name, "8")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_8) #self.board_config.gridLayout_device_8.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "8")) #32bits name_checked = self.main.configIDE.config("Board", "board_32", "PIC32 Pinguino OTG") arch_32 = filter(lambda board: board.arch == 32, self.main.pinguinoAPI._boards_) arch_32.sort() frame_left0 = Frame(self.frame_32b) frame_left0.pack(expand=True, fill=BOTH, side=LEFT) frame_right0 = Frame(self.frame_32b) frame_right0.pack(expand=True, fill=BOTH, side=RIGHT) parent = frame_left0 #left for board in arch_32: if arch_32.index(board) == (len(arch_32) / 2) + 1: parent = frame_right0 #rigth radio = Radiobutton( parent, text=board.name, anchor="w", width=10, value=board.name, variable=self.dev32_var, command=lambda: self.set_board_name(board.name, "32")) radio.pack(expand=True, fill=X, side=TOP) #radio = QtGui.QRadioButton(self.board_config.groupBox_devices_32) #self.board_config.gridLayout_device_32.addWidget(radio, count, side, 1, 1) #radio.setText(board.name) #radio.setToolTip(board.proc) if name_checked == board.name: radio.select() #self.connect(radio, QtCore.SIGNAL("clicked()"), self.set_board_name(board.name, "32")) #---------------------------------------------------------------------- def load_config(self): self.main.configIDE.load_config() arch = self.main.configIDE.config("Board", "arch", 8) getattr(self.radioButton_arch_8, "select" if (arch == 8) else "deselect")() getattr(self.radioButton_arch_32, "select" if (arch == 32) else "deselect")() if arch == 32: self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) else: self.advanceoptions.forget() mode = self.main.configIDE.config("Board", "mode", "bootloader") getattr(self.radioButton_mode_bootloader, "select" if (mode == "bootloader") else "deselect")() getattr(self.radioButton_mode_icsp, "select" if (mode == "icsp") else "deselect")() bootloader = self.main.configIDE.config("Board", "bootloader", "v1_v2") getattr(self.radioButton_bootloader_v1_v2, "select" if (bootloader == "v1_v2") else "deselect")() getattr(self.radioButton_bootloader_v4, "select" if (bootloader == "v4") else "deselect")() self.update_mode() #---------------------------------------------------------------------- def update_mode(self): mode_boot = self.mode_var.get() == "bootloader" arch_8 = self.arch_var.get() == 8 if mode_boot and arch_8: self.lf_boot.pack(fill=X, expand=True, side=TOP) else: self.lf_boot.forget() self.init_groups() if not mode_boot: self.label_warning.configure( text="WARNING!! this mode can overwite the bootloader code.") else: self.label_warning.configure(text="") #---------------------------------------------------------------------- def set_board_name(self, name, arch): def dummy(): self.main.configIDE.set("Board", "board_" + arch, name) return dummy #---------------------------------------------------------------------- def init_groups(self): self.lf_dev32.forget() self.lf_dev8.forget() if self.arch_var.get() == 8: self.lf_dev8.pack(fill=X, expand=True, side=TOP) self.advanceoptions.forget() else: self.lf_dev32.pack(fill=X, expand=True, side=TOP) self.advanceoptions.pack(fill=X, expand=True, side=BOTTOM) #---------------------------------------------------------------------- def save_config(self): #if self.board_config.radioButton_arch_8.isChecked(): arch = 8 #else: arch = 32 self.main.configIDE.set("Board", "arch", self.arch_var.get()) #if self.board_config.radioButton_mode_bootloader.isChecked(): mode = "bootloader" #else: mode = "icsp" self.main.configIDE.set("Board", "mode", self.mode_var.get()) #if self.board_config.radioButton_bootloader_v1_v2.isChecked(): bootloader = "v1_v2" #else: bootloader = "v4" self.main.configIDE.set("Board", "bootloader", self.boot_var.get()) name = self.main.configIDE.config("Board", "board_" + str(self.arch_var.get()), None) self.main.configIDE.set("Board", "board", name) #---------------------------------------------------------------------- def accept_config(self): self.save_config() self.main.configIDE.save_config() self.main.statusbar_ide(self.main.get_status_board()) self.close_advance() self.quit() #---------------------------------------------------------------------- def advance(self): root = Toplevel() self.frame_advance = BoardConfigAdvance(master=root, main=self.main) self.frame_advance.mainloop() #---------------------------------------------------------------------- def close_advance(self): try: assert self.frame_advance except: return self.frame_advance.quit()
def __init__(self, parent): top = self.top = Toplevel(parent) Label(top, text="Pick your color").pack() self.v = 0; rb1 = Radiobutton(top, text="Yellow",value=YELLOW,command=self.sari) rb1.pack() rb1.select() rb2 = Radiobutton(top, text="Green",value=GREEN,command=self.yesil) rb2.pack() rb2.deselect() b = Button(top, text="OK", command=self.ok) b.pack(pady=5)