def makeView(self, master): frame = mtk.Frame(master, **self.configArgs) bg = frame.cget('bg') bg = convertToColorCode(master, bg) l = mtk.Label(frame, text=self.label, width=self.labelWidth, anchor="w", bg=bg) self.variable = mtk.StringVar(frame) self.variable.set(self.defaultEntry) self.optionMenu = mtk.OptionMenu(frame, self.variable, command=self.valueChanged, *self.options) self.optionMenu.config( bg=bg, highlightthickness=0, activebackground=colorscale( bg, 0.95)) #, activeforeground=colorscale(bg,1.5) ) if (self.boxWidth): self.optionMenu.config(width=self.boxWidth) if (self.direction == "vertical"): l.pack(side=mtk.TOP, fill=mtk.X) self.optionMenu.pack(side=mtk.BOTTOM, fill=mtk.X, expand=True) else: l.pack(side=mtk.LEFT, fill=mtk.X) self.optionMenu.pack(side=mtk.RIGHT, fill=mtk.X, expand=True) frame.pack(fill=mtk.X, expand=True) return frame
def app(): # initialise a window. root = tk.Tk() root.config(background='white') root.geometry("1000x700") lab = tk.Label(root, text="Osciloscopio Digital", bg='white').pack() fig = Figure() ax = fig.add_subplot(111) ax.set_xlabel("X axis") ax.set_ylabel("Y axis") # fig = plt.figure(1) # plt.ion() graph = FigureCanvasTkAgg(fig, master=root) graph.get_tk_widget().pack(side="top", fill='both', expand=True) variable = tk.StringVar(root) variable.set("3 V ") #defaultvalue w = tk.OptionMenu(root, variable, "3 V ", "1 V ", "0.3 V ") w.place(x=300, y=672) var = tk.StringVar(root) var.set("1ms") option = tk.OptionMenu(root, var, "0.1ms", "1ms", "10ms") option.place(x=600, y=672) def osciloscopio(): valch1_lower = np.array([], np.dtype(int)) valch1_upper = np.array([], np.dtype(int)) valch2_lower = np.array([], np.dtype(int)) valch2_upper = np.array([], np.dtype(int)) vald1 = np.array([], np.dtype(int)) vald2 = np.array([], np.dtype(int)) data_count = 0 cnt = 0 point_count = 0 #create the serial port object port = serial.Serial('/dev/ttyUSB0', 115200, timeout=0.5) while continuePlotting: #port.write(b's') #handshake with Arduino if (port.inWaiting()): # if the arduino replies value = np.array(map(ord, port.read(8000))) # read the reply if cnt == 0: cnt = cnt + 1 continue data = '' first_mask = value[:len(value)] < 128 valch1_upper = value[np.array(np.flatnonzero(first_mask))] & 63 index1 = np.flatnonzero(first_mask) + 1 valch1_lower = value[index1[:-1]] & 63 index2 = np.array(np.flatnonzero(first_mask)) + 2 valch2_upper = value[index2[:-2]] & 63 vald1 = value[index2[:-2]] >> 6 vald1 = vald1 - 2 index3 = np.array(np.flatnonzero(first_mask)) + 3 valch2_lower = value[index3[:-3]] & 63 vald2 = value[index3[:-3]] >> 6 vald2 = vald2 - 2 end_array = SampleOptions[var.get()] valch1_lower = valch1_lower[:end_array] #print('lower') #print(map(bin,valch1_lower[:10])) valch1_upper = valch1_upper[:end_array] #print(map(bin,valch1_upper[:10])) valch2_lower = valch2_lower[:end_array] valch2_upper = valch2_upper[:end_array] makeFig(valch1_lower, valch1_upper, valch2_lower, valch2_upper, vald1, vald2, ax, graph, variable, var) valch1_lower = np.array([], np.dtype(int)) valch1_upper = np.array([], np.dtype(int)) valch2_lower = np.array([], np.dtype(int)) valch2_upper = np.array([], np.dtype(int)) vald1 = np.array([], np.dtype(int)) vald2 = np.array([], np.dtype(int)) def gui_handler(): change_state() threading.Thread(target=osciloscopio).start() b = tk.Button(root, text="Start/Stop", command=gui_handler, bg="red", fg="white") b.place(x=450, y=20) b1 = tk.Button(root, text="Channel1", command=change_channel1state, bg="blue", fg="white") b1.pack(side="left") b2 = tk.Button(root, text="Channel2", command=change_channel2state, bg="blue", fg="white") b2.pack(side="left") b3 = tk.Button(root, text="ChannelD1", command=change_channelD1state, bg="blue", fg="white") b3.pack(side="right") b4 = tk.Button(root, text="ChannelD2", command=change_channelD2state, bg="blue", fg="white") b4.pack(side="right") root.mainloop()
def __init__(self, inputDict=None, debug=False): self.inputDict = inputDict self.debug = debug self.rxd = [] self.txd = [] self.window = tk.Tk() self.window.title(window_title) self.window.geometry(window_size) self.right_frame = tk.Frame(self.window, width=450, height=100) self.left_frame = tk.Frame(self.window, width=250, height=100) self.corner_frame = tk.Frame(self.window, width=100, height=20) self.extra_frame = tk.Frame(self.window, width=30, height=100) self.window.grid_columnconfigure(1, weight=1) self.right_frame.grid(row=0, column=1) self.left_frame.grid(row=0, column=0, sticky="nsew") self.corner_frame.grid(row=1, column=0, sticky="sw") self.extra_frame.grid(row=0, column=2) # textbot for rx self.rx_box_scrollbar = tk.Scrollbar(self.left_frame) self.rx_box_text = tk.Text(self.left_frame, height=rx_textbox_height, width=rx_textbox_width) self.rx_box_scrollbar.grid(column=1, row=0, sticky=tk.N + tk.S + tk.W) self.rx_box_text.grid(column=0, row=0) self.rx_box_scrollbar.config(command=self.rx_box_text.yview) self.rx_box_text.config(yscrollcommand=self.rx_box_scrollbar.set) # rx button self.receive_start_button = tk.Button(self.right_frame, text="Start RX", command=self.receive) self.receive_start_button.grid(column=0, row=0, pady=5) # clear rx box windows button self.clear_button = tk.Button(self.right_frame, text="Clear", command=self.clear) self.clear_button.grid(column=0, row=1, pady=5) # tx button self.transmit_start_button = tk.Button(self.corner_frame, text="Start TX", command=self.transmit) self.transmit_start_button.grid(column=2, row=0) # tx message self.tx_msg = tk.Entry(self.corner_frame, width=tx_msg_width) self.tx_msg.grid(column=1, row=0) # tx label self.txlbl = tk.Label(self.corner_frame, text="TX Message:") self.txlbl.grid(column=0, row=0) # rx channel button self.rx_channel_button = tk.Button(self.right_frame, text="Set RX channel", command=self.setRXchannel) self.rx_channel_button.grid(column=1, row=3, pady=5) # rx channel self.rx_channel = tk.Entry(self.right_frame, width=10) self.rx_channel.grid(column=1, row=4, pady=5) # tx channel button self.tx_channel_button = tk.Button(self.right_frame, text="Set TX channel", command=self.setTXchannel) self.tx_channel_button.grid(column=0, row=3, pady=5) # tx channel self.tx_channel = tk.Entry(self.right_frame, width=10) self.tx_channel.grid(column=0, row=4, pady=5) # reset button self.reset_button = tk.Button(self.right_frame, text="Reset Device", command=self.reset) self.reset_button.grid(column=0, row=2, pady=5) # opMode droplist and button OPTIONS = [ "NORMAL_MODE", "SLEEP_MODE", "INTERNAL_LOOPBACK_MODE", "LISTEN_ONLY_MODE", "CONFIGURATION_MODE", "EXTERNAL_LOOPBACK_MODE", "CLASSIC_MODE", "RESTRICTED_MODE", "INVALID_MODE" ] self.droplist = tk.StringVar(self.left_frame) self.droplist.set(OPTIONS[0]) # default value w = tk.OptionMenu(self.right_frame, self.droplist, *OPTIONS) w.grid(column=1, row=1, padx=5) self.opmode_button = tk.Button(self.right_frame, text="Set config mode", command=self.changemode) self.opmode_button.grid(column=1, row=2, pady=5) # stop button self.stop_button = tk.Button(self.right_frame, text="STOP", command=self.stop) self.stop_button.grid(column=1, row=0, pady=5) # connect button self.connect_button = tk.Button(self.extra_frame, text="CONNECT", command=self.connect) self.connect_button.grid(column=0, row=2, pady=5) # enlarge self.connect_button.config(height=3, width=15) # bit time button self.bittime = tk.Button(self.extra_frame, text="BIT TIME", command=self.bittime) self.bittime.grid(column=0, row=3, pady=5) # bit time droplist OPTIONS_bit = ["500k_2M", "500k_4M"] self.droplist_bit = tk.StringVar(self.extra_frame) self.droplist_bit.set(OPTIONS_bit[0]) # default value w = tk.OptionMenu(self.extra_frame, self.droplist_bit, *OPTIONS_bit) w.grid(column=0, row=4, padx=5) #self.droplist_bit.grid(column=0, row=4, pady=5) # dlc droplist and button OPTIONS_dlc = [ "CAN_DLC_0", "CAN_DLC_1", "CAN_DLC_2", "CAN_DLC_3", "CAN_DLC_4", "CAN_DLC_5", "CAN_DLC_6", "CAN_DLC_7", "CAN_DLC_8", "CAN_DLC_12", "CAN_DLC_16", "CAN_DLC_20", "CAN_DLC_24", "CAN_DLC_32", "CAN_DLC_48", "CAN_DLC_64" ] self.droplist_dlc = tk.StringVar(self.extra_frame) self.droplist_dlc.set(OPTIONS_dlc[-1]) # default value w_dlc = tk.OptionMenu(self.extra_frame, self.droplist_dlc, *OPTIONS_dlc) w_dlc.grid(column=0, row=0, padx=5) self.dlc_button = tk.Button(self.extra_frame, text="Set DLC", command=self.changedlc) self.dlc_button.grid(column=0, row=1, pady=5) self.canfd = None if self.debug: # self.window.after(1000, self.dummy_main) pass else: try: self.connect() except RuntimeError: self.rx_box_text.insert( tk.END, "Device not ready. Connect manually." + '\n') finally: #self.window.after(10, self.main) self.main() self.window.mainloop()