def __init__(self, port=None, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0, writeTimeout=None, dsrdtr=None): self.upref = UserPrefs() sleeptime = float(self.upref.getvalue('sleeptime')) Thread.__init__(self) self.dl_started = Event() self.dl_finished = Event() serial.Serial.__init__(self, port=port, baudrate=baudrate, bytesize=bytesize, parity=parity, stopbits=stopbits, timeout=timeout, xonxoff=xonxoff, rtscts=rtscts, writeTimeout=writeTimeout, dsrdtr=dsrdtr)
def __init__(self, parent): #init user's preferences config file object self.upref = UserPrefs() buttons_width = 8 imb_buttonx = "2m" imb_buttony = "1m" imb_buttons_framex = "3m" imb_buttons_framey = "2m" imb_int_buttons_framex = "3m" imb_int_buttons_framey = "1m" self.myParent = parent self.main_frame = Frame(parent) ### self.main_frame.pack(expand=YES, fill=BOTH) #MENU self.menubar = Menu(self.myParent) self.myParent.config(menu=self.menubar) topsmenu = Menu(self.menubar, tearoff=0) topsmenu.add_command(label=_("Connect"), command=self.connect) topsmenu.add_command(label=_("Process data"), command=self.process) topsmenu.add_separator() topsmenu.add_command(label=_("Quit"), command=self.on_app_close) filemenu = Menu(self.menubar, tearoff=0) filemenu.add_command(label=_("Open file"), command=self.open_a_file) filemenu.add_command(label=_("Save raw data"), command=self.save_a_file) helpmenu = Menu(self.menubar, tearoff=0) helpmenu.add_command(label=_("About TOPS"), command=self.about) languagemenu = Menu(self.menubar, tearoff=0) language = StringVar() languagemenu.add_radiobutton(label="English",variable=language,value="en") languagemenu.add_radiobutton(label="Italiano",variable=language,value="it") self.menubar.add_cascade(label="Total Station", menu=topsmenu) self.menubar.add_cascade(label="File", menu=filemenu) #self.menubar.add_cascade(label="Language", menu=languagemenu) self.menubar.add_cascade(label="Help", menu=helpmenu) self.upper_frame = Frame(self.main_frame) ### self.upper_frame.pack(side=TOP, expand=NO, padx=10, pady=5, ipadx=5, ipady=5) self.logo_frame = Frame(self.upper_frame) self.logo_frame.pack(side=LEFT, expand=NO) self.logo_data = logo_data self.logo = PhotoImage(data=self.logo_data) self.logo_canvas = Label(self.logo_frame, image=self.logo) self.logo_canvas.pack(side=LEFT, expand=NO, padx=5, pady=5) self.header_frame = Frame(self.upper_frame) self.header_frame.pack(side=LEFT, expand=NO, pady=5) self.buttons_frame = Frame(self.header_frame) self.buttons_frame.pack( side=TOP, expand=NO, fill=Y, ipadx=5, ipady=5) # default control panel self.control_panel0 = Frame(self.header_frame) self.control_panel0.pack( side=TOP, expand=YES, fill=Y, padx=5, pady=5) # control panel for custom serial connection self.control_panel = Frame(self.header_frame) # option 1 : serial port self.option1_frame = Frame(self.control_panel0, relief=RIDGE, bd=1) self.option1_frame.pack(side=TOP) self.option1_label = Label(self.option1_frame, text=_("Port"), width=30) self.option1_label.pack(side=LEFT) self.option1_value = StringVar() self.option1_value.set(self.upref.getvalue('port')) # Leave this Entry uncommented to enter port as a string, or ... # self.option1_entry = Entry(self.option1_frame, textvariable=self.option1_value, width=20) # ... comment out this Menubutton if you want to use the scan() output # # self.option1_entry = Menubutton(self.option1_frame, # text="choose a value", # textvariable=self.option1_value, # relief=RAISED, # width=24) # self.option1_entry.menu = Menu( self.option1_entry, tearoff=0 ) # self.option1_entry["menu"] = self.option1_entry.menu # for n,s in scan(): # self.option1_entry.menu.add_radiobutton ( label=s, # variable=self.option1_value, # value = s) self.option1_entry.pack(side=LEFT, anchor=W) # option MODEL substitutes all connection parameters for better # user experience self.optionMODEL_frame = Frame( self.control_panel0, relief=RIDGE, bd=1) self.optionMODEL_frame.pack(side=TOP) self.optionMODEL_label = Label(self.optionMODEL_frame, text=_("Total Station"), justify=LEFT, width=30) self.optionMODEL_label.pack(side=LEFT, anchor=E) self.optionMODEL_value = StringVar() self.optionMODEL_value.set(self.upref.getvalue('model')) self.optionMODEL_entry = Menubutton(self.optionMODEL_frame, text="choose a model", textvariable=self.optionMODEL_value, relief=RAISED, width=20) self.optionMODEL_entry.menu = Menu(self.optionMODEL_entry, tearoff=0) self.optionMODEL_entry["menu"] = self.optionMODEL_entry.menu for k, (l, m, n) in list(BUILTIN_MODELS.items()): self.optionMODEL_entry.menu.add_radiobutton( label=n, variable=self.optionMODEL_value, value=k, command=self.print_model) self.optionMODEL_entry.pack(side=LEFT, anchor=W) # option 2 : baudrate self.option2_frame = Frame(self.control_panel, relief=RIDGE, bd=1) self.option2_frame.pack(side=TOP) self.option2_label = Label(self.option2_frame, text="Baudrate", width=30) self.option2_label.pack(side=LEFT) self.option2_value = IntVar() try: assert serial.baudrate_constants assert serial.baudrate_constants is not {} except (AttributeError, AssertionError): self.option2_entry = Entry(self.option2_frame, textvariable=self.option2_value, width=20) else: self.option2_entry = Menubutton(self.option2_frame, text=_("choose a value"), textvariable=self.option2_value, relief=RAISED, width=20) self.option2_entry.menu = Menu(self.option2_entry, tearoff=0) self.option2_entry["menu"] = self.option2_entry.menu for key in sorted(serial.baudrate_constants.keys()): # dynamic list self.option2_entry.menu.add_radiobutton( label="%s" % key, variable=self.option2_value, value=key, ) self.option2_entry.pack(side=LEFT, anchor=W) # option 3 : bytesize self.option3_frame = Frame(self.control_panel, relief=RIDGE, bd=1) self.option3_frame.pack(side=TOP) self.option3_label = Label(self.option3_frame, text=_("Bytesize"), justify=LEFT, width=30) self.option3_label.pack(side=LEFT, anchor=E) self.option3_value = IntVar() self.option3_entry = Menubutton(self.option3_frame, text=_("choose a value"), textvariable=self.option3_value, relief=RAISED, width=20) self.option3_entry.menu = Menu(self.option3_entry, tearoff=0) self.option3_entry["menu"] = self.option3_entry.menu for v in [8,7,6,5]: self.option3_entry.menu.add_radiobutton(label=str(v), variable=self.option3_value, value=v) self.option3_entry.pack(side=LEFT, anchor=W) # option 4 : parity self.option4_frame = Frame(self.control_panel, relief=RIDGE, bd=1) self.option4_frame.pack(side=TOP) self.option4_label = Label(self.option4_frame, text=_("Parity setting"), justify=LEFT, width=30) self.option4_label.pack(side=LEFT, anchor=E) self.option4_value = StringVar() self.option4_entry = Menubutton(self.option4_frame, text=_("choose a value"), textvariable=self.option4_value, relief=RAISED, width=20) self.option4_entry.menu = Menu(self.option4_entry, tearoff=0) self.option4_entry["menu"] = self.option4_entry.menu for v in ['Even', 'None', 'Odd']: self.option4_entry.menu.add_radiobutton(label=_(v), variable=self.option4_value, value=v[0]) self.option4_entry.pack(side=LEFT, anchor=W) # option 5 : stop bit self.option5_frame = Frame(self.control_panel, relief=RIDGE, bd=1) self.option5_frame.pack(side=TOP) self.option5_label = Label(self.option5_frame, text=_("Stop bit"), justify=LEFT, width=30) self.option5_label.pack(side=LEFT, anchor=E) self.option5_value = IntVar() self.option5_entry = Menubutton(self.option5_frame, text=_("choose a value"), textvariable=self.option5_value, relief=RAISED, width=20) self.option5_entry.menu = Menu(self.option5_entry, tearoff=0) self.option5_entry["menu"] = self.option5_entry.menu for v in [1, 2]: self.option5_entry.menu.add_radiobutton(label=str(v), variable=self.option5_value, value=v) self.option5_entry.pack(side=LEFT, anchor=W) # option 6 : time lapse between data packets self.option6_frame = Frame(self.control_panel, relief=RIDGE, bd=1) self.option6_frame.pack(side=TOP) self.option6_label = Label(self.option6_frame, text=_("Time lapse between data packets"), justify=LEFT, width=30) self.option6_label.pack(side=LEFT, anchor=E) self.option6_value = DoubleVar() self.option6_value.set(self.upref.getvalue('sleeptime')) self.option6_entry = Entry(self.option6_frame, textvariable=self.option6_value, relief=RAISED, justify=RIGHT, width=20) self.option6_entry.pack(side=LEFT, anchor=W) # control buttons self.connect_button = Button(self.buttons_frame, text=_("Connect"), padx=imb_buttonx, pady=imb_buttony) self.connect_button.pack(side=LEFT, anchor=S) self.connect_button.bind("<Button-1>", self.connect_action) self.connect_button.bind("<Return>", self.connect_action) self.save_button = Button(self.buttons_frame, text=_("Save raw data"), padx=imb_buttonx, pady=imb_buttony) self.save_button.pack(side=LEFT, anchor=S) self.save_button.bind("<Button-1>", self.save_action) self.save_button.bind("<Return>", self.save_action) self.process_button = Button(self.buttons_frame, text=_("Process data"), padx=imb_buttonx, pady=imb_buttony) self.process_button.pack(side=LEFT, anchor=S) self.process_button.bind("<Button-1>", self.process_action) self.process_button.bind("<Return>", self.process_action) self.status = StatusBar(self.main_frame) self.status.set('Welcome to Total Open Station') self.status.pack(side=BOTTOM, fill=X) # text frame self.text_frame = Frame(self.main_frame) self.text_frame.pack(side=BOTTOM, expand=YES, fill=BOTH) self.text_area = Text(self.text_frame, width=80) self.text_area.insert(END, _("Welcome.\nTurn your device on.")) self.text_area.pack(side=LEFT, expand=YES, fill=Y) self.scrollY = Scrollbar(self.text_frame, orient=VERTICAL, command=self.text_area.yview) self.text_area['yscrollcommand'] = self.scrollY.set self.scrollY.pack(side=RIGHT, expand=YES, fill=Y, anchor=W) # init stuff self.myParent.title("Total Open Station") self.myParent.protocol("WM_DELETE_WINDOW", self.on_app_close) self.print_model() self.myParent.mainloop()