def __init__(self, parent, controller, tabname, generic_methods=None): self.controller = controller tk.Frame.__init__(self,parent) self.tabClassName = tabname macrodata = self.controller.MacroDef.data.get(self.tabClassName,{}) self.tabname = macrodata.get("MTabName",self.tabClassName) self.title = macrodata.get("Title",self.tabClassName) self.startcmd_filename = "" self.grid_columnconfigure(0,weight=1) self.grid_rowconfigure(0,weight=1) self.frame=ttk.Frame(self,relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0,weight=1) self.frame.grid_rowconfigure(0,weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0,weight=1) self.scroll_main_frame.grid_rowconfigure(0,weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0,weight=1) self.main_frame.grid_rowconfigure(2,weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5,pady=(5,5)) #self.scroll_configframe = VerticalScrolledFrame(self.main_frame) #config_frame = self.controller.create_macroparam_frame(self.scroll_configframe.interior,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage") config_frame = self.controller.create_macroparam_frame(self.main_frame,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage",generic_methods=generic_methods) # --- Buttons self.button_frame = ttk.Frame(self.main_frame) self.button_frame2 = ttk.Frame(self.main_frame) button1_text = macrodata.get("Button_1",self.tabClassName) self.update_button1a = ttk.Button(self.button_frame, text=button1_text, command=self.save_config) self.update_button1a.pack(side="right", padx=10) self.update_button1b = ttk.Button(self.button_frame2, text=button1_text, command=self.save_config) self.update_button1b.pack(side="right", padx=10) button2_text = macrodata.get("Button_2",self.tabClassName) if button2_text != "": self.update_button2a = ttk.Button(self.button_frame, text=button2_text, command=self.button2_command) self.update_button2a.pack(side="right", padx=10) self.update_button2b = ttk.Button(self.button_frame2, text=button2_text, command=self.button2_command) self.update_button2b.pack(side="right", padx=10) #self.update_tree_button = ttk.Button(self.button_frame, text="Update Tree", command=self.update_tree) #self.update_tree_button.pack(side="left", padx=10) #self.tree_frame = ttk.Frame(self.main_frame) # --- placement # Tabframe self.frame.grid(row=0,column=0) self.scroll_main_frame.grid(row=0,column=0,sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0,column=0) # main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) self.button_frame.grid(row=1, column=0,pady=10, padx=10) config_frame.grid(row=2, column=0, pady=10, padx=10, sticky="nesw") #self.tree_frame.grid(row=3, column=0, pady=10, padx=10, sticky="nesw") self.button_frame2.grid(row=4, column=0,pady=10, padx=10) self.controller.update_variables_with_config_data(self.tabClassName) self.store_old_config()
def __init__(self, parent, controller): self.tabClassName = "DCCKeyboardPage" tk.Frame.__init__(self, parent) self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) #button1_text = macrodata.get("Button_1",self.tabClassName) #button2_text = macrodata.get("Button_2",self.tabClassName) self.fontlabel = self.controller.get_font("FontLabel") self.fontspinbox = self.controller.get_font("FontSpinbox") self.fonttext = self.controller.get_font("FontText") self.fontbutton = self.controller.get_font("FontLabel") self.fontentry = self.controller.get_font("FontEntry") self.fonttext = self.controller.get_font("FontText") self.fontscale = self.controller.get_font("FontScale") self.fonttitle = self.controller.get_font("FontTitle") self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=self.fonttitle) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") # create buttons base_address = int( self.controller.get_macroparam_val(self.tabClassName, "DCC BaseAddress")) row = 0 in_button_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=1) self.buttonlist = [] for j in range(0, 4): for i in range(0, 8): # create switch buttons address = j * 8 + i self.create_button(i, j * 2, address, 0, str(address + base_address), "red", in_button_frame) self.create_button(i, j * 2 + 1, address, 1, " ", "green", in_button_frame) # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) in_button_frame.grid(row=2, column=0, sticky="n", padx=4, pady=4)
class DCCKeyboardPage(tk.Frame): def __init__(self, parent, controller): self.tabClassName = "DCCKeyboardPage" tk.Frame.__init__(self, parent) self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) #button1_text = macrodata.get("Button_1",self.tabClassName) #button2_text = macrodata.get("Button_2",self.tabClassName) self.fontlabel = self.controller.get_font("FontLabel") self.fontspinbox = self.controller.get_font("FontSpinbox") self.fonttext = self.controller.get_font("FontText") self.fontbutton = self.controller.get_font("FontLabel") self.fontentry = self.controller.get_font("FontEntry") self.fonttext = self.controller.get_font("FontText") self.fontscale = self.controller.get_font("FontScale") self.fonttitle = self.controller.get_font("FontTitle") self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=self.fonttitle) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") # create buttons base_address = int( self.controller.get_macroparam_val(self.tabClassName, "DCC BaseAddress")) row = 0 in_button_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=1) self.buttonlist = [] for j in range(0, 4): for i in range(0, 8): # create switch buttons address = j * 8 + i self.create_button(i, j * 2, address, 0, str(address + base_address), "red", in_button_frame) self.create_button(i, j * 2 + 1, address, 1, " ", "green", in_button_frame) # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) in_button_frame.grid(row=2, column=0, sticky="n", padx=4, pady=4) # ---------------------------------------------------------------- # Standardprocedures for every tabpage # ---------------------------------------------------------------- def tabselected(self): #self.controller.currentTabClass = self.tabClassName logging.debug("Tabselected: %s", self.tabname) #self.controller.send_to_ARDUINO("#END") #time.sleep(ARDUINO_WAITTIME) pass def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) #self.controller.send_to_ARDUINO("#BEGIN") #time.sleep(ARDUINO_WAITTIME) pass def TabChanged(self, _event=None): logging.debug("Tabchanged: %s", self.tabname) pass def cancel(self, _event=None): pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): pass def MenuRedo(self, _event=None): pass def connect(self): pass def disconnect(self): pass # ---------------------------------------------------------------- # End of Standardprocedures for every tabpage # ---------------------------------------------------------------- def create_button(self, column, row, number, channel, text, color, in_button_frame): inbuttonlabel1 = tk.Label( in_button_frame, text=text, width=BUTTONLABELWIDTH, height=1, relief="raised", background=color, borderwidth=2, font=self.fontbutton ) #,command=lambda: self._button_cmd(button=number,channel=channel)) inbuttonlabel1.grid(row=row, column=column, sticky="n", padx=4, pady=4) inbuttonlabel1.button = number inbuttonlabel1.channel = channel inbuttonlabel1.bind("<Button-1>", self._buttonlabel_cmd) inbuttonlabel1.bind("<ButtonRelease-1>", lambda e: e.widget.configure(relief="raised")) #self.controller.ToolTip(inbuttonlabel1, text="Button {}".format(number)) self.buttonlist.append(inbuttonlabel1) def _buttonlabel_cmd(self, _event): """Respond to user click on a button item.""" label = _event.widget label.focus_set() label.configure(relief="sunken") self.update() address = self.controller.get_macroparam_val( self.tabClassName, "DCC BaseAddress") #self.input.get() address_int = address + label.button logging.debug("_button_cmd: %s - %s", address_int, label.channel) command = "@ {:03} {:02} 01".format(address_int, label.channel) self.send_command_to_ARDUINO(command) for button in self.buttonlist: if button.channel == 0: button.config(text=str(button.button + address)) def send_command_to_ARDUINO(self, command): self.controller.connect_if_not_connected() for c in command: self.controller.send_to_ARDUINO(c) #time.sleep(0.01) c = chr(10) self.controller.send_to_ARDUINO(c) def _button_cmd(self, button=0, channel=0): """Respond to user click on a Button""" address = self.controller.get_macroparam_val( self.tabClassName, "DCC BaseAddress") #self.input.get() address_int = address + button logging.debug("_button_cmd: %s - %s", address_int, channel) command = "@ {:03} {:02} 01".format(address_int, channel) self.send_command_to_ARDUINO(command)
class ConfigPagetemplate(tk.Frame): def __init__(self, parent, controller, tabname, generic_methods=None): self.controller = controller tk.Frame.__init__(self,parent) self.tabClassName = tabname macrodata = self.controller.MacroDef.data.get(self.tabClassName,{}) self.tabname = macrodata.get("MTabName",self.tabClassName) self.title = macrodata.get("Title",self.tabClassName) self.startcmd_filename = "" self.grid_columnconfigure(0,weight=1) self.grid_rowconfigure(0,weight=1) self.frame=ttk.Frame(self,relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0,weight=1) self.frame.grid_rowconfigure(0,weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0,weight=1) self.scroll_main_frame.grid_rowconfigure(0,weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0,weight=1) self.main_frame.grid_rowconfigure(2,weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5,pady=(5,5)) #self.scroll_configframe = VerticalScrolledFrame(self.main_frame) #config_frame = self.controller.create_macroparam_frame(self.scroll_configframe.interior,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage") config_frame = self.controller.create_macroparam_frame(self.main_frame,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage",generic_methods=generic_methods) # --- Buttons self.button_frame = ttk.Frame(self.main_frame) self.button_frame2 = ttk.Frame(self.main_frame) button1_text = macrodata.get("Button_1",self.tabClassName) self.update_button1a = ttk.Button(self.button_frame, text=button1_text, command=self.save_config) self.update_button1a.pack(side="right", padx=10) self.update_button1b = ttk.Button(self.button_frame2, text=button1_text, command=self.save_config) self.update_button1b.pack(side="right", padx=10) button2_text = macrodata.get("Button_2",self.tabClassName) if button2_text != "": self.update_button2a = ttk.Button(self.button_frame, text=button2_text, command=self.button2_command) self.update_button2a.pack(side="right", padx=10) self.update_button2b = ttk.Button(self.button_frame2, text=button2_text, command=self.button2_command) self.update_button2b.pack(side="right", padx=10) #self.update_tree_button = ttk.Button(self.button_frame, text="Update Tree", command=self.update_tree) #self.update_tree_button.pack(side="left", padx=10) #self.tree_frame = ttk.Frame(self.main_frame) # --- placement # Tabframe self.frame.grid(row=0,column=0) self.scroll_main_frame.grid(row=0,column=0,sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0,column=0) # main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) self.button_frame.grid(row=1, column=0,pady=10, padx=10) config_frame.grid(row=2, column=0, pady=10, padx=10, sticky="nesw") #self.tree_frame.grid(row=3, column=0, pady=10, padx=10, sticky="nesw") self.button_frame2.grid(row=4, column=0,pady=10, padx=10) self.controller.update_variables_with_config_data(self.tabClassName) self.store_old_config() #self.save_config() # ---------------------------------------------------------------- # Standardprocedures for every tabpage # ---------------------------------------------------------------- def tabselected(self): logging.debug("Tabselected: %s",self.tabname) self.controller.set_statusmessage("") self.store_old_config() def tabunselected(self): logging.debug("Tabunselected: %s",self.tabname) if self.check_if_config_data_changed(): logging.debug("Config_data changed - request save or cancel") answer = tk.messagebox.askyesnocancel ('Sie verlassen die Einstellungen','Die Einstellungen wurden verändert. Sollen die geänderten Einstellungen gesichert werden?',default='no') if answer == None: logging.debug("Config_data changed - answer: None") return # cancelation return to "ConfigurationOage" if answer: logging.debug("Config_data changed - answer: Yes") self.save_config() else: logging.debug("Config_data changed - answer: No") def cancel(self): self.save_config() def getConfigPageParams(self): pass def getConfigData(self, key,default=None): return self.controller.getConfigData(key,default=default) def readConfigData(self): self.controller.readConfigData() def setConfigData(self,key, value): self.controller.setConfigData(key, value) def setConfigDataDict(self,paramdict): self.controller.setConfigDataDict(paramdict) def get_macroparam_var_values(self,macro): return self.controller.get_macroparam_var_values(macro) def setParamData(self,key, value): self.controller.setParamData(key, value) def MenuUndo(self,_event=None): logging.debug("MenuUndo: %s",self.tabname) pass def MenuRedo(self,_event=None): logging.debug("MenuRedo: %s",self.tabname) pass # ---------------------------------------------------------------- # ConfigurationPage save_config # ---------------------------------------------------------------- def save_config(self): self.setConfigData("pos_x",self.winfo_x()) self.setConfigData("pos_y",self.winfo_y()) #try: #curItem = self.tree.focus() #curItem_value = self.tree.item(curItem) #except: #curItem_value = {} #selectedtrain=curItem_value.get("text","") param_values_dict = self.get_macroparam_var_values(self.tabClassName) self.setConfigDataDict(param_values_dict) self.store_old_config() self.controller.SaveConfigData() logging.debug("SaveConfig: %s - %s",self.tabname,repr(self.controller.ConfigData.data)) def button2_command(self): pass def store_old_config(self): self.old_param_values_dict = self.get_macroparam_var_values(self.tabClassName) def check_if_config_data_changed(self): param_values_dict = self.get_macroparam_var_values(self.tabClassName) if self.old_param_values_dict != param_values_dict: logging.debug("Config-Data changed") return True return False
class ARDUINOMonitorPage(tk.Frame): def __init__(self, parent, controller): self.tabClassName = "ARDUINOMonitorPage" tk.Frame.__init__(self, parent) self.controller = controller self.macrodata = self.controller.MacroDef.data.get( self.tabClassName, {}) self.tabname = self.macrodata.get("MTabName", self.tabClassName) self.title = self.macrodata.get("Title", self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) self.suppressLinesList = self.macrodata.get("suppressLinesList", []) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") text_frame = tk.Frame(self.main_frame, padx=10, pady=10) #self.text = tk.Text(frameLabel, wrap='word', bg=self.cget('bg'), height=25, width=70) # 04.12.19: Old: height=10, width=50 self.text = tk.Text(text_frame, wrap='word', bg=self.cget('bg'), height=25, width=100) # 04.12.19: Old: height=10, width=50 # add a vertical scroll bar to the text area scroll = tk.Scrollbar(text_frame) self.text.configure(yscrollcommand=scroll.set) scroll.config(command=self.text.yview) #pack everything self.text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) scroll.pack(side=tk.RIGHT, fill=tk.Y) # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # place frames in main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) text_frame.grid(row=3, column=0, padx=10, pady=(10, 4), sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(3, weight=1) # ---------------------------------------------------------------- # Standardprocedures for every tabpage # ---------------------------------------------------------------- def tabselected(self): #self.controller.currentTabClass = self.tabClassName logging.debug("Tabselected: %s", self.tabname) pass def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) pass def TabChanged(self, _event=None): logging.debug("Tabchanged: %s", self.tabname) pass def cancel(self, _event=None): pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): logging.debug("MenuUndo: %s", self.tabname) pass def MenuRedo(self, _event=None): logging.debug("ReUndo: %s", self.tabname) pass def connect(self): pass def disconnect(self): pass # ---------------------------------------------------------------- # End of Standardprocedures for every tabpage # ---------------------------------------------------------------- def block_line(self, string): for substring in self.suppressLinesList: if substring in string: return True return False def add_text_to_textwindow(self, text, highlight=""): date_time = datetime.now() d = date_time.strftime("%H:%M:%S") textlines = text.split("\n") textmessage = "" for textline in textlines: if textline != "": if not self.block_line(textline): logging.debug("%s: Textwindow: %s", self.tabname, textline) textmessage = d + " " + textline + "\n" self.text.insert("end", textmessage) self.text.yview("end") if highlight == "Error": self.text.tag_add("Text", "1.0", tk.END) self.text.tag_config("Text", background="red", foreground="white") elif highlight == "OK": self.text.tag_add("Text", "1.0", tk.END) self.text.tag_config("Text", background="green", foreground="white") else: self.text.tag_add("Text", "1.0", tk.END) self.text.tag_config("Text", background="white", foreground="black") def delete_text_from_textwindow(self): self.text.delete('1.0', tk.END)
def __init__(self, parent, controller): self.tabClassName = "ARDUINOMonitorPage" tk.Frame.__init__(self, parent) self.controller = controller self.macrodata = self.controller.MacroDef.data.get( self.tabClassName, {}) self.tabname = self.macrodata.get("MTabName", self.tabClassName) self.title = self.macrodata.get("Title", self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) self.suppressLinesList = self.macrodata.get("suppressLinesList", []) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") text_frame = tk.Frame(self.main_frame, padx=10, pady=10) #self.text = tk.Text(frameLabel, wrap='word', bg=self.cget('bg'), height=25, width=70) # 04.12.19: Old: height=10, width=50 self.text = tk.Text(text_frame, wrap='word', bg=self.cget('bg'), height=25, width=100) # 04.12.19: Old: height=10, width=50 # add a vertical scroll bar to the text area scroll = tk.Scrollbar(text_frame) self.text.configure(yscrollcommand=scroll.set) scroll.config(command=self.text.yview) #pack everything self.text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) scroll.pack(side=tk.RIGHT, fill=tk.Y) # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # place frames in main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) text_frame.grid(row=3, column=0, padx=10, pady=(10, 4), sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(3, weight=1)
class SerialMonitorPage(tk.Frame): def __init__(self, parent, controller): self.tabClassName = "SerialMonitorPage" tk.Frame.__init__(self, parent) self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) button1_text = macrodata.get("Button_1", self.tabClassName) button2_text = macrodata.get("Button_2", self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") button_frame = ttk.Frame(self.main_frame) self.send_button = ttk.Button(button_frame, text=button1_text, width=30, command=self.send) self.send_button.pack(side="left", padx=4, pady=(4, 1)) text_frame = tk.Frame(self.main_frame, padx=10, pady=10) self.text = tk.Text(text_frame, wrap='word', bg=self.cget('bg'), height=25, width=100) # 04.12.19: Old: height=10, width=50 scroll = tk.Scrollbar(text_frame) self.text.configure(yscrollcommand=scroll.set) scroll.config(command=self.text.yview) #pack everything self.text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) scroll.pack(side=tk.RIGHT, fill=tk.Y) # locate frames in main_frame # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) button_frame.grid(row=2, column=0, padx=10, pady=(10, 4)) text_frame.grid(row=3, column=0, padx=10, pady=(10, 4), sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(3, weight=1) self.queue = queue.Queue() self.monitor_serial = False self.Z21page = self.controller.tabdict.get("Z21MonitorPage", None) self.check_RMBUS = False if self.Z21page: self.RMBUS_request_timer_confvalue_str = self.controller.getConfigData( "RMbusTimer") if self.RMBUS_request_timer_confvalue_str == "": self.RMBUS_request_timer_confvalue = 0 else: self.RMBUS_request_timer_confvalue = int( self.RMBUS_request_timer_confvalue_str) self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue def tabselected(self): logging.debug("Tabselected: %s", self.tabname) logging.info(self.tabname) def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) def _update_value(self, paramkey): logging.info("SerialMonitorPage - update_value: %s", paramkey) message = self.controller.get_macroparam_val( self.tabClassName, "SerialMonitorInput") + "\r\n" #self.input.get() +"\r\n" self.controller.send_to_ARDUINO(message) def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): pass def MenuRedo(self, _event=None): pass def dummy(self, event): logging.info("dummy") def send(self, event=None): message = self.controller.get_macroparam_val( self.tabClassName, "SerialMonitorInput") + "\r\n" #self.input.get() +"\r\n" self.controller.send_to_ARDUINO(message) def process_serial(self): #print("process_serial: Start") textmessage = self.controller.checkconnection() if textmessage: self.text.insert("end", textmessage) self.text.yview("end") self.controller.set_ARDUINOmessage(textmessage) else: if self.controller.queue: while self.controller.queue.qsize(): #print("process_serial: While loop") try: readtext = self.controller.queue.get() date_time = datetime.now() d = date_time.strftime("%H:%M:%S") textmessage = d + " " + readtext if not textmessage.endswith("\n"): textmessage = textmessage + "\n" #write message into text window self.text.insert("end", textmessage) self.text.yview("end") if readtext.startswith("JSON:"): json_str = readtext[5:] if self.z21page: self.Z21page.notifyZ21_RMBUS_DATA(json_str) elif readtext.startswith("#?"): temp_list = readtext.split(",") self.controller.max_ledcnt_list = temp_list[1:] ledchannel_str = self.getConfigData("LEDchannel") if ledchannel_str != "": self.controller.LEDchannel = int( ledchannel_str) else: self.controller.LEDchannel = 0 if len(self.controller.max_ledcnt_list ) <= self.controller.LEDchannel: self.controller.LEDchannel = 0 self.controller.set_maxLEDcnt( int(self.controller.max_ledcnt_list[ self.controller.LEDchannel])) self.controller.LED_baseadress = 0 for i in range(0, self.controller.LEDchannel): self.controller.LED_baseadress += int( self.controller.max_ledcnt_list[i]) else: self.controller.set_ARDUINOmessage(textmessage) except IOError: pass if self.check_RMBUS: self.RMBUS_request_timer -= 1 if self.RMBUS_request_timer == 0: self.controller.send_to_ARDUINO("?*\r\n") self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue if self.monitor_serial: self.after(100, self.process_serial) def set_check_RMBUS(self, value=False): if self.RMBUS_request_timer_confvalue > 0: self.check_RMBUS = False #value else: self.check_RMBUS = False if self.check_RMBUS: self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue if value: self.controller.send_to_ARDUINO("?+\r\n") pass else: self.controller.send_to_ARDUINO("?-\r\n") pass def start_process_serial(self): global ThreadEvent ThreadEvent = threading.Event() ThreadEvent.set() time.sleep(2) ThreadEvent.clear() self.monitor_serial = True self.thread = SerialThread(self.controller.queue, self.controller.arduino) self.thread.start() self.process_serial() self.RMBUS_request_timer_confvalue_str = self.controller.getConfigData( "RMbusTimer") if self.RMBUS_request_timer_confvalue_str == "": self.RMBUS_request_timer_confvalue = 1 else: self.RMBUS_request_timer_confvalue = int( self.RMBUS_request_timer_confvalue_str) self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue def stop_process_serial(self): global ThreadEvent self.monitor_serial = False if ThreadEvent: ThreadEvent.set() #time.sleep(1) def cancel(self): self.stop_process_serial() def connect(self): self.start_process_serial() def disconnect(self): self.stop_process_serial()
def __init__(self, parent, controller): self.tabClassName = "SerialMonitorPage" tk.Frame.__init__(self, parent) self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) button1_text = macrodata.get("Button_1", self.tabClassName) button2_text = macrodata.get("Button_2", self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=1, style="CONFIGPage") button_frame = ttk.Frame(self.main_frame) self.send_button = ttk.Button(button_frame, text=button1_text, width=30, command=self.send) self.send_button.pack(side="left", padx=4, pady=(4, 1)) text_frame = tk.Frame(self.main_frame, padx=10, pady=10) self.text = tk.Text(text_frame, wrap='word', bg=self.cget('bg'), height=25, width=100) # 04.12.19: Old: height=10, width=50 scroll = tk.Scrollbar(text_frame) self.text.configure(yscrollcommand=scroll.set) scroll.config(command=self.text.yview) #pack everything self.text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) scroll.pack(side=tk.RIGHT, fill=tk.Y) # locate frames in main_frame # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, columnspan=2, pady=(4, 10), padx=10) config_frame.grid(row=1, columnspan=2, pady=(20, 30), padx=10) button_frame.grid(row=2, column=0, padx=10, pady=(10, 4)) text_frame.grid(row=3, column=0, padx=10, pady=(10, 4), sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(3, weight=1) self.queue = queue.Queue() self.monitor_serial = False self.Z21page = self.controller.tabdict.get("Z21MonitorPage", None) self.check_RMBUS = False if self.Z21page: self.RMBUS_request_timer_confvalue_str = self.controller.getConfigData( "RMbusTimer") if self.RMBUS_request_timer_confvalue_str == "": self.RMBUS_request_timer_confvalue = 0 else: self.RMBUS_request_timer_confvalue = int( self.RMBUS_request_timer_confvalue_str) self.RMBUS_request_timer = self.RMBUS_request_timer_confvalue
class ServoTestPage(tk.Frame): # ---------------------------------------------------------------- # ServoTestPage __init__ # ---------------------------------------------------------------- def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.tabClassName = "ServoTestPage" tk.Frame.__init__(self, parent) self.controller = controller self.fontlabel = self.controller.get_font("FontLabel") self.fontspinbox = self.controller.get_font("FontSpinbox") self.fonttext = self.controller.get_font("FontText") self.fontbutton = self.controller.get_font("FontLabel") self.fontentry = self.controller.get_font("FontEntry") self.fonttext = self.controller.get_font("FontText") self.fontscale = self.controller.get_font("FontScale") self.fonttitle = self.controller.get_font("FontTitle") macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) #button1_text = macrodata.get("Button_1",self.tabClassName) #button2_text = macrodata.get("Button_2",self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="flat", borderwidth=0) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="flat", borderwidth=0) label = ttk.Label(title_frame, text=self.title, font=self.fonttitle) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=4, startrow=1, style="CONFIGPage") self.on_lednum = 0 led = self.getConfigData("lastLed") serport = controller.arduino self.tab_frame = ttk.Frame(self.main_frame, borderwidth=0, relief="flat") #direct control frame for servos direct_control_frame = ttk.Frame(self.tab_frame, relief="flat", borderwidth=0) servo_direct_position_frame = ttk.Frame(direct_control_frame, relief="flat", borderwidth=0) servo_direct_position_frame.grid(row=0, column=0, padx=0, pady=0, sticky="") #dc_label1 = ttk.Label(servo_direct_position_frame, text='Servo Direct Control').grid(row=0, column=0, sticky='w', padx=4, pady=4) servo_direct_position_frame.columnconfigure(0, weight=1) self.buttonservostop = tk.Label(servo_direct_position_frame, text="Servo STOP", width=15, height=4, fg="black", relief="raised", font=self.fontbutton) self.controller.ToolTip(self.buttonservostop, text="Stop the Servo") self.buttonservostop.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event, code=0)) self.buttonservostop.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=0)) self.servo_pos_var = tk.DoubleVar() self.servo_pos_var.set(0) #self.servo_scale = ttk.Scale( servo_direct_position_frame, variable = self.servo_pos_var,command=self._update_servo_position,from_=0,to=220,orient=tk.HORIZONTAL,length=440) self.servo_scale = tk.Scale(servo_direct_position_frame, variable=self.servo_pos_var, command=self._update_servo_position, from_=Servo_Scale_Min, to=Servo_Scale_Max, orient=tk.HORIZONTAL, length=440, label="Servo position", tickinterval=20, font=self.fontscale) self.controller.ToolTip( self.servo_scale, text= "Position of Servo 10..220\nAnklicken zum Aktivieren der Tasten:\n[Right]/[Left]\n - single step\n[CTRL-Right]/[CTRL-Left]\n - long step\n[Pos1]/[Ende}\n - Anfang/Ende\n" + "\nKlicken auf dem Sliderfeld:\n<Linke Taste>\n - single step vorwärts/rückwärts\n<Rechte Taste>\n - spring zum angeklickten Wert\n<CTRL Linke Taste>\n - springe zum Anfang/Ende" ) self.servo_scale.focus_set() self.servo_scale.bind("<Button-1>", self.servo_scale_focus_set) # constants select_servo0 = 225 select_servo1 = 230 select_servo2 = 235 select_set_min_max_pos = 240 select_set_speed = 245 set_speed_by_button = 250 save_changes = 254 save_position = 205 back_to_normal = 0 lowPos = 1 high_pos = 220 servo_program_frame = ttk.Frame(self.tab_frame, relief="flat", borderwidth=0, width=500) #sp_label1 = ttk.Label(servo_program_frame, text='Servo Programmieren').grid(row=0, column=0, sticky='ew',padx=4, pady=4) # ------------- SERVO Pos s = ttk.Style() s.configure('my.TButton', font=self.fontbutton) servo_set_pos_speed_frame = ttk.Frame(servo_program_frame, relief="flat", borderwidth=0) ssp_label1 = ttk.Label( servo_set_pos_speed_frame, text='Programmierung von Min/Max Position und Geschwindigkeit', font=self.fontlabel) ssp_label1.grid(row=0, column=0, sticky='', padx=5, pady=5) self.button_cancel_mm_pos_speed = ttk.Button( servo_set_pos_speed_frame, text="Beende Programmierung ohne Speichern", command=self._cancel_set_min_max_pos, style='my.TButton') self.controller.ToolTip( self.button_cancel_mm_pos_speed, text="Beende die Programmierung ohne zu Speichern") #self.status = "Save Min Pos" self.status = "Start Min Pos" self.ssp_label2 = ttk.Label(servo_set_pos_speed_frame, text="", width=60, font=self.fontlabel) #self.button_start_save_mm_pos=ttk.Button(servo_set_pos_frame, text="Beende Min Pos programmieren",width=40, command=self._save_min_max_pos) self.button_start_save_mm_pos = ttk.Button( servo_set_pos_speed_frame, text="Starte Min-Max Pos/Speed programmieren", command=self._save_min_max_pos, style='my.TButton') self.controller.ToolTip( self.button_start_save_mm_pos, text= "Startet die Min/Max und Geschwindigkeitsprogrammierung und geht zum nächsten Schritt" ) self.button_start_save_mm_pos.grid(row=1, column=0, padx=5, pady=5, sticky='ew') self.ssp_label2.grid(row=2, column=0, sticky='ew', padx=5, pady=5) self.button_cancel_mm_pos_speed.grid(row=3, column=0, padx=5, pady=5, sticky='ew') self.servo_scale.grid(row=0, column=1, sticky="") self.buttonservostop.grid(row=0, column=0, sticky="", padx=20, pady=10) servo_set_pos_speed_frame.grid(row=1, column=0, pady=5, padx=5, sticky="") #servo_set_speed_frame.grid(row=3, column=1, pady=10, padx=10, sticky="e") # ------------------- buttons show_buttons = False if show_buttons: button_frame = ttk.Frame(self.tab_frame, relief="ridge", borderwidth=2, width=500) label1 = ttk.Label( button_frame, text='(Only for testing\nStep 1 - Select Servo').grid( row=1, column=0, sticky='e', padx=4, pady=4) button1 = ttk.Button( button_frame, text="T225 Sel Servo 1", width=20, command=lambda: self.servo_prog_button(code=225)) button1.grid(row=1, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button1, text="Taster1\n[CTRL-o]") button2 = ttk.Button( button_frame, text="T230 Sel Servo 2", width=20, command=lambda: self.servo_prog_button(code=230)) button2.grid(row=1, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button2, text="Taster2") button3 = ttk.Button( button_frame, text="T235 Sel Servo 3", width=20, command=lambda: self.servo_prog_button(code=235)) button3.grid(row=1, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button3, text="Taster1\n[CTRL-o]") label2 = ttk.Label(button_frame, text='Step 2 - Select Task').grid(row=2, column=0, sticky='e', padx=4, pady=4) button4 = ttk.Button( button_frame, text="T240 Set Min/Max", width=20, command=lambda: self.servo_prog_button(code=240)) button4.grid(row=2, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button4, text="Taster2") button5 = ttk.Button( button_frame, text="T245 Set Speed", width=20, command=lambda: self.servo_prog_button(code=245)) button5.grid(row=2, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button5, text="Taster1\n[CTRL-o]") button6 = ttk.Button( button_frame, text="T250 Start", width=20, command=lambda: self.servo_prog_button(code=250)) button6.grid(row=3, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button6, text="Taster2") label3 = ttk.Label(button_frame, text='Step 3 - Set Min').grid(row=4, column=0, sticky='e', padx=4, pady=4) label4 = ttk.Label(button_frame, text='Step 4 - Set Max').grid(row=5, column=0, sticky='e', padx=4, pady=4) button9 = ttk.Button( button_frame, text="T9 (205) Next step", width=20, command=lambda: self.servo_prog_button(code=205)) button9.grid(row=5, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button9, text="Taster2") label5 = ttk.Label(button_frame, text='Step 5 - use <<,<,>,>> to Set Max').grid( row=6, column=0, sticky='e', padx=4, pady=4) label6 = ttk.Label(button_frame, text='Step 6 - Store Max').grid(row=7, column=0, sticky='e', padx=4, pady=4) button9a = ttk.Button( button_frame, text="T205 Next step", width=20, command=lambda: self.servo_prog_button(code=205)) button9a.grid(row=7, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button9a, text="Taster2") label6 = ttk.Label(button_frame, text='Step 6 - save and end').grid(row=8, column=0, sticky='e', padx=4, pady=4) button10 = ttk.Button( button_frame, text="T254 Save", width=20, command=lambda: self.servo_prog_button(code=254)) button10.grid(row=8, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button10, text="Taster2") button11 = ttk.Button( button_frame, text="T0 Back to normal", width=20, command=lambda: self.servo_prog_button(code=0)) button11.grid(row=9, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button10, text="Taster2") button12 = ttk.Button( button_frame, text="T220 High Pos", width=20, command=lambda: self.servo_prog_button(code=220)) button12.grid(row=10, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button12, text="Taster2") button13 = ttk.Button( button_frame, text="T10 Low Pos", width=20, command=lambda: self.servo_prog_button(code=10)) button13.grid(row=10, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button13, text="Taster2") set_button_frame = ttk.Frame(servo_program_frame, relief="flat", borderwidth=0) button7 = tk.Label(set_button_frame, text="Dec <<", width=15, fg="black", relief="raised", font=self.fontbutton) button7.grid(row=4, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button7, text="T60 Dec <<") button7.bind("<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button7.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=60)) button7a = tk.Label(set_button_frame, text="Dec <", width=15, fg="black", relief="raised", font=self.fontbutton) button7a.grid(row=4, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button7a, text="T90 Dec <<") button7a.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button7a.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=90)) #button7b=ttk.Button(set_button_frame, text="Stop",width=15, command=lambda: self.servo_prog_button(code=100)) #button7b.grid(row=4, column=3, padx=10, pady=(10, 4), sticky='w') #self.controller.ToolTip(button7b, text="T100 Stop") button8 = tk.Label(set_button_frame, text="Inc >", width=15, fg="black", relief="raised", font=self.fontbutton) button8.grid(row=4, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button8, text="T110 Inc >") button8.bind("<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button8.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=110)) button8a = tk.Label(set_button_frame, text="Inc >>", width=15, fg="black", relief="raised", font=self.fontbutton) button8a.grid(row=4, column=4, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button8a, text="T140 Dec <<") button8a.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button8a.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=140)) # --- placement self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, pady=5, padx=5) config_frame.grid(row=1, column=0, pady=5, padx=5) self.tab_frame.grid(row=2, column=0, pady=0, padx=5) self.main_frame.columnconfigure(0, weight=1) # tab_frame direct_control_frame.grid(row=1, rowspan=1, column=0, pady=0, padx=5, sticky="") servo_program_frame.grid(row=2, column=0, pady=0, padx=5, sticky="ew") if show_buttons: button_frame.grid(row=3, column=0, pady=0, padx=5, sticky="ew") set_button_frame.grid(row=4, column=0, pady=0, padx=5, sticky="ew") self.tab_frame.grid_columnconfigure(0, weight=1) #self.tab_frame.grid_columnconfigure(1,weight=0) #self.tab_frame.grid_columnconfigure(2,weight=0) #self.tab_frame.grid_columnconfigure(3,weight=1) self.tab_frame.grid_rowconfigure(3, weight=1) # --- bindings #self.controller.bind("<Control-Right>",self.s_servo_address.invoke_buttonup) #self.controller.bind("<Control-Left>",self.s_servo_address.invoke_buttondown) #self.controller.bind("<Control-Up>",self.s_servo_channel.invoke_buttonup) #self.controller.bind("<Control-Down>",self.s_servo_channel.invoke_buttondown) self.controller.bind("<F1>", self.controller.call_helppage) self.controller.bind("<Alt-F4>", self.cancel) self.controller.bind("<Control-o>", self.led_off) def cancel(self, _event=None): try: pass except: pass #self.setConfigData("lastLed" , self.v_servo_address.get()) #self.setConfigData("lastservo_channel", self.v_servo_channel.get()) #self.setParamData("Lednum" , self.v_servo_address.get()) #self.setParamData("servo_channel" , self.v_servo_channel.get()) def tabselected(self): logging.debug("Tabselected: %s", self.tabname) #self.controller.currentTabClass = self.tabClassName #self.controller.send_to_ARDUINO("#BEGIN") #time.sleep(ARDUINO_WAITTIME) #self.controller.connect() self.controller.ARDUINO_begin_direct_mode() #self.controller.bind("<Control-Down>",self.s_servo_address.invoke_buttonup) #self.controller.bind("<Control-Up>",self.s_servo_address.invoke_buttondown) #self.controller.bind("<Control-Right>",self.s_servo_channel.invoke_buttonup) #self.controller.bind("<Control-Left>",self.s_servo_channel.invoke_buttondown) self.controller.bind("<F1>", self.controller.call_helppage) self.controller.bind("<Alt-F4>", self.cancel) def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) #self.controller.send_to_ARDUINO("#END") #time.sleep(ARDUINO_WAITTIME) self.controller.ARDUINO_end_direct_mode() pass logging.info(self.tabname) pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setParamData(self, key, value): self.controller.setParamData(key, value) def connect(self): pass def disconnect(self): pass @staticmethod def _select_all_spinbox(event): """Select all entry content.""" event.widget.selection('range', 0, 'end') return "break" @staticmethod def _select_all_entry(event): """Select all entry content.""" event.widget.selection_range(0, 'end') return "break" def _unfocus(self, event): """Unfocus palette items when click on bar or square.""" w = self.focus_get() if w != self and 'spinbox' not in str(w) and 'entry' not in str(w): self.focus_set() def servo_scale_focus_set(self, event=None): self.servo_scale.focus_set() def _update_servo_channel(self, servo_address, servo_channel, position): if servo_channel == 0: self._update_servos(servo_address, position, 0, 0) elif servo_channel == 1: self._update_servos(servo_address, 0, position, 0) else: self._update_servos(servo_address, 0, 0, position) def servo_pos_inc(self, event): #var = self.servo_pos_var.get() #self.servo_pos_var.set(var + 1) pass def servo_pos_dec(self, event): #var = self.servo_pos_var.get() #self.servo_pos_var.set(var - 1) pass def _update_servo_position(self, position): position_int = int(position) if position_int in range(1, Servo_Min): # Limit position_int = Servo_Min servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") self._update_servo_channel(servo_address, servo_channel, position_int) def _update_servo_speed(self, event=None): speed = self.v_speed_0.get() servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") self._update_servos(servo_address, speed, speed, speed) def _get_servo_channel_code(self, servo_channel): # select the right servo if servo_channel == 0: return 225 elif servo_channel == 1: return 230 else: return 235 def _cancel_set_min_max_pos(self, event=None): # select the right servo servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") #send code to ARDUINO self._update_servos(servo_address, 0, 0, 0) self.status = "Start Min Pos" self.ssp_label2.config(background="white", text="") self.button_start_save_mm_pos.config( text="Starte Min-Max Pos/Speed programmieren") def _save_min_max_pos(self, event=None): servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") servo_channel_code = self._get_servo_channel_code(servo_channel) if self.status == "Start Min Pos": #send code to ARDUINO self._update_servos(servo_address, servo_channel_code, 0, 0) # send "start pos setting" self._update_servos(servo_address, 240, 0, 0) # send "start min pos setting" self._update_servos(servo_address, 250, 0, 0) self.ssp_label2.config( background="#ffff05", text= "Bewege den Servo zur Min Position mit den <<,<,>,>> Tastern") self.button_start_save_mm_pos.config( text="Gehe zu Max Pos programmieren") self.status = "Save Min Pos" elif self.status == "Save Min Pos": self.status = "Save Max Pos" self.ssp_label2.config( text= "Bewege den Servo zur Max Position mit den <<,<,>,>> Tastern") #send "save"-code to ARDUINO self._update_servos(servo_address, 205, 0, 0) self.button_start_save_mm_pos.config( text="Beende Max Pos programmieren") elif self.status == "Save Max Pos": self.status = "Save Speed" self.ssp_label2.config( text= "Stelle die Geschwindigkeit mit mit den <<,<,>,>> Tastern ein") self.button_start_save_mm_pos.config( text="Beende Speed programmieren") #send PWMButton1-code to ARDUINO self._update_servos(servo_address, 205, 0, 0) #send speed-code to ARDUINO self._update_servos(servo_address, 245, 0, 0) # send "set speed" self._update_servos(servo_address, 250, 0, 0) else: self.status = "Start Min Pos" self.ssp_label2.config(background="white", text="") self.button_start_save_mm_pos.config( text="Starte Min-Max Pos/Speed programmieren") #send "end"-code to ARDUINO self._update_servos(servo_address, 254, 0, 0) #send "back to normal"-code to ARDUINO self._update_servos(servo_address, 0, 0, 0) def _save_min_max_pos2(self, event=None): servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") servo_channel_code = self._get_servo_channel_code(servo_channel) if self.status == "Save Min Pos": self.status = "Save Max Pos" self.ssp_label2.config( text= "Bewege den Servo zur Max Position mit den <<,<,>,>> Tastern") #send "save"-code to ARDUINO self._update_servos(servo_address, 205, 0, 0) self.button_start_save_mm_pos.config( text="Beende Max Pos programmieren") elif self.status == "Save Max Pos": self.status = "Save Speed" self.ssp_label2.config( text= "Stelle die Geschwindigkeit mit mit den <<,<,>,>> Tastern ein") self.button_start_save_mm_pos.config( text="Beende Speed programmieren") #send PWMButton1-code to ARDUINO self._update_servos(servo_address, 205, 0, 0) #send speed-code to ARDUINO self._update_servos(servo_address, 245, 0, 0) # send "set speed" self._update_servos(servo_address, 250, 0, 0) else: self.status = "Save Min Pos" self.ssp_label2.config(background="white", text="") self.button_start_save_mm_pos.config( text="Beende Min Pos programmieren") #send "end"-code to ARDUINO self._update_servos(servo_address, 254, 0, 0) #send "back to normal"-code to ARDUINO self._update_servos(servo_address, 0, 0, 0) def _update_set_servo_position(self, event=None): servo_position = self.servo_0.get() servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") def _update_servo_address(self, event=None): self.servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") self.servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") def led_off(self, _event=None): # switch off all LED self.ledhighlight = False if self.controller.mobaledlib_version == 1: message = "#L00 00 00 00 FF\n" else: message = "#L 00 00 00 00 7FFF\n" self.controller.send_to_ARDUINO(message) #self.controller.ledtable.clear() def servo_prog_button(self, event=None, code=0): # send code to Servo servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") self._update_servos(servo_address, code, 0, 0) def servo_prog_label_pressed(self, event=None, code=0): # send code to Servo event.widget.config(relief="sunken") servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") self._update_servos(servo_address, code, 0, 0) def servo_prog_label_released(self, event=None, code=100): # send code to Servo event.widget.config(relief="raised") servo_address = self.controller.get_macroparam_val( self.tabClassName, "ServoAddress") servo_channel = self.controller.get_macroparam_val( self.tabClassName, "ServoChannel") self._update_servos(servo_address, code, 0, 0) def _update_servos(self, lednum, servo_0, servo_1, servo_2): if self.controller.mobaledlib_version == 1: message = "#L" + '{:02x}'.format(lednum) + " " + '{:02x}'.format( servo_0) + " " + '{:02x}'.format( servo_1) + " " + '{:02x}'.format( servo_2) + " " + '{:02x}'.format(1) + "\n" else: message = "#L " + '{:02x}'.format(lednum) + " " + '{:02x}'.format( servo_0) + " " + '{:02x}'.format( servo_1) + " " + '{:02x}'.format( servo_2) + " " + '{:02x}'.format(1) + "\n" self.controller.send_to_ARDUINO(message) time.sleep(0.2)
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.tabClassName = "ServoTestPage" tk.Frame.__init__(self, parent) self.controller = controller self.fontlabel = self.controller.get_font("FontLabel") self.fontspinbox = self.controller.get_font("FontSpinbox") self.fonttext = self.controller.get_font("FontText") self.fontbutton = self.controller.get_font("FontLabel") self.fontentry = self.controller.get_font("FontEntry") self.fonttext = self.controller.get_font("FontText") self.fontscale = self.controller.get_font("FontScale") self.fonttitle = self.controller.get_font("FontTitle") macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) #button1_text = macrodata.get("Button_1",self.tabClassName) #button2_text = macrodata.get("Button_2",self.tabClassName) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="flat", borderwidth=0) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="flat", borderwidth=0) label = ttk.Label(title_frame, text=self.title, font=self.fonttitle) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=4, startrow=1, style="CONFIGPage") self.on_lednum = 0 led = self.getConfigData("lastLed") serport = controller.arduino self.tab_frame = ttk.Frame(self.main_frame, borderwidth=0, relief="flat") #direct control frame for servos direct_control_frame = ttk.Frame(self.tab_frame, relief="flat", borderwidth=0) servo_direct_position_frame = ttk.Frame(direct_control_frame, relief="flat", borderwidth=0) servo_direct_position_frame.grid(row=0, column=0, padx=0, pady=0, sticky="") #dc_label1 = ttk.Label(servo_direct_position_frame, text='Servo Direct Control').grid(row=0, column=0, sticky='w', padx=4, pady=4) servo_direct_position_frame.columnconfigure(0, weight=1) self.buttonservostop = tk.Label(servo_direct_position_frame, text="Servo STOP", width=15, height=4, fg="black", relief="raised", font=self.fontbutton) self.controller.ToolTip(self.buttonservostop, text="Stop the Servo") self.buttonservostop.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event, code=0)) self.buttonservostop.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=0)) self.servo_pos_var = tk.DoubleVar() self.servo_pos_var.set(0) #self.servo_scale = ttk.Scale( servo_direct_position_frame, variable = self.servo_pos_var,command=self._update_servo_position,from_=0,to=220,orient=tk.HORIZONTAL,length=440) self.servo_scale = tk.Scale(servo_direct_position_frame, variable=self.servo_pos_var, command=self._update_servo_position, from_=Servo_Scale_Min, to=Servo_Scale_Max, orient=tk.HORIZONTAL, length=440, label="Servo position", tickinterval=20, font=self.fontscale) self.controller.ToolTip( self.servo_scale, text= "Position of Servo 10..220\nAnklicken zum Aktivieren der Tasten:\n[Right]/[Left]\n - single step\n[CTRL-Right]/[CTRL-Left]\n - long step\n[Pos1]/[Ende}\n - Anfang/Ende\n" + "\nKlicken auf dem Sliderfeld:\n<Linke Taste>\n - single step vorwärts/rückwärts\n<Rechte Taste>\n - spring zum angeklickten Wert\n<CTRL Linke Taste>\n - springe zum Anfang/Ende" ) self.servo_scale.focus_set() self.servo_scale.bind("<Button-1>", self.servo_scale_focus_set) # constants select_servo0 = 225 select_servo1 = 230 select_servo2 = 235 select_set_min_max_pos = 240 select_set_speed = 245 set_speed_by_button = 250 save_changes = 254 save_position = 205 back_to_normal = 0 lowPos = 1 high_pos = 220 servo_program_frame = ttk.Frame(self.tab_frame, relief="flat", borderwidth=0, width=500) #sp_label1 = ttk.Label(servo_program_frame, text='Servo Programmieren').grid(row=0, column=0, sticky='ew',padx=4, pady=4) # ------------- SERVO Pos s = ttk.Style() s.configure('my.TButton', font=self.fontbutton) servo_set_pos_speed_frame = ttk.Frame(servo_program_frame, relief="flat", borderwidth=0) ssp_label1 = ttk.Label( servo_set_pos_speed_frame, text='Programmierung von Min/Max Position und Geschwindigkeit', font=self.fontlabel) ssp_label1.grid(row=0, column=0, sticky='', padx=5, pady=5) self.button_cancel_mm_pos_speed = ttk.Button( servo_set_pos_speed_frame, text="Beende Programmierung ohne Speichern", command=self._cancel_set_min_max_pos, style='my.TButton') self.controller.ToolTip( self.button_cancel_mm_pos_speed, text="Beende die Programmierung ohne zu Speichern") #self.status = "Save Min Pos" self.status = "Start Min Pos" self.ssp_label2 = ttk.Label(servo_set_pos_speed_frame, text="", width=60, font=self.fontlabel) #self.button_start_save_mm_pos=ttk.Button(servo_set_pos_frame, text="Beende Min Pos programmieren",width=40, command=self._save_min_max_pos) self.button_start_save_mm_pos = ttk.Button( servo_set_pos_speed_frame, text="Starte Min-Max Pos/Speed programmieren", command=self._save_min_max_pos, style='my.TButton') self.controller.ToolTip( self.button_start_save_mm_pos, text= "Startet die Min/Max und Geschwindigkeitsprogrammierung und geht zum nächsten Schritt" ) self.button_start_save_mm_pos.grid(row=1, column=0, padx=5, pady=5, sticky='ew') self.ssp_label2.grid(row=2, column=0, sticky='ew', padx=5, pady=5) self.button_cancel_mm_pos_speed.grid(row=3, column=0, padx=5, pady=5, sticky='ew') self.servo_scale.grid(row=0, column=1, sticky="") self.buttonservostop.grid(row=0, column=0, sticky="", padx=20, pady=10) servo_set_pos_speed_frame.grid(row=1, column=0, pady=5, padx=5, sticky="") #servo_set_speed_frame.grid(row=3, column=1, pady=10, padx=10, sticky="e") # ------------------- buttons show_buttons = False if show_buttons: button_frame = ttk.Frame(self.tab_frame, relief="ridge", borderwidth=2, width=500) label1 = ttk.Label( button_frame, text='(Only for testing\nStep 1 - Select Servo').grid( row=1, column=0, sticky='e', padx=4, pady=4) button1 = ttk.Button( button_frame, text="T225 Sel Servo 1", width=20, command=lambda: self.servo_prog_button(code=225)) button1.grid(row=1, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button1, text="Taster1\n[CTRL-o]") button2 = ttk.Button( button_frame, text="T230 Sel Servo 2", width=20, command=lambda: self.servo_prog_button(code=230)) button2.grid(row=1, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button2, text="Taster2") button3 = ttk.Button( button_frame, text="T235 Sel Servo 3", width=20, command=lambda: self.servo_prog_button(code=235)) button3.grid(row=1, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button3, text="Taster1\n[CTRL-o]") label2 = ttk.Label(button_frame, text='Step 2 - Select Task').grid(row=2, column=0, sticky='e', padx=4, pady=4) button4 = ttk.Button( button_frame, text="T240 Set Min/Max", width=20, command=lambda: self.servo_prog_button(code=240)) button4.grid(row=2, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button4, text="Taster2") button5 = ttk.Button( button_frame, text="T245 Set Speed", width=20, command=lambda: self.servo_prog_button(code=245)) button5.grid(row=2, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button5, text="Taster1\n[CTRL-o]") button6 = ttk.Button( button_frame, text="T250 Start", width=20, command=lambda: self.servo_prog_button(code=250)) button6.grid(row=3, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button6, text="Taster2") label3 = ttk.Label(button_frame, text='Step 3 - Set Min').grid(row=4, column=0, sticky='e', padx=4, pady=4) label4 = ttk.Label(button_frame, text='Step 4 - Set Max').grid(row=5, column=0, sticky='e', padx=4, pady=4) button9 = ttk.Button( button_frame, text="T9 (205) Next step", width=20, command=lambda: self.servo_prog_button(code=205)) button9.grid(row=5, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button9, text="Taster2") label5 = ttk.Label(button_frame, text='Step 5 - use <<,<,>,>> to Set Max').grid( row=6, column=0, sticky='e', padx=4, pady=4) label6 = ttk.Label(button_frame, text='Step 6 - Store Max').grid(row=7, column=0, sticky='e', padx=4, pady=4) button9a = ttk.Button( button_frame, text="T205 Next step", width=20, command=lambda: self.servo_prog_button(code=205)) button9a.grid(row=7, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button9a, text="Taster2") label6 = ttk.Label(button_frame, text='Step 6 - save and end').grid(row=8, column=0, sticky='e', padx=4, pady=4) button10 = ttk.Button( button_frame, text="T254 Save", width=20, command=lambda: self.servo_prog_button(code=254)) button10.grid(row=8, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button10, text="Taster2") button11 = ttk.Button( button_frame, text="T0 Back to normal", width=20, command=lambda: self.servo_prog_button(code=0)) button11.grid(row=9, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button10, text="Taster2") button12 = ttk.Button( button_frame, text="T220 High Pos", width=20, command=lambda: self.servo_prog_button(code=220)) button12.grid(row=10, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button12, text="Taster2") button13 = ttk.Button( button_frame, text="T10 Low Pos", width=20, command=lambda: self.servo_prog_button(code=10)) button13.grid(row=10, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button13, text="Taster2") set_button_frame = ttk.Frame(servo_program_frame, relief="flat", borderwidth=0) button7 = tk.Label(set_button_frame, text="Dec <<", width=15, fg="black", relief="raised", font=self.fontbutton) button7.grid(row=4, column=1, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button7, text="T60 Dec <<") button7.bind("<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button7.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=60)) button7a = tk.Label(set_button_frame, text="Dec <", width=15, fg="black", relief="raised", font=self.fontbutton) button7a.grid(row=4, column=2, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button7a, text="T90 Dec <<") button7a.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button7a.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=90)) #button7b=ttk.Button(set_button_frame, text="Stop",width=15, command=lambda: self.servo_prog_button(code=100)) #button7b.grid(row=4, column=3, padx=10, pady=(10, 4), sticky='w') #self.controller.ToolTip(button7b, text="T100 Stop") button8 = tk.Label(set_button_frame, text="Inc >", width=15, fg="black", relief="raised", font=self.fontbutton) button8.grid(row=4, column=3, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button8, text="T110 Inc >") button8.bind("<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button8.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=110)) button8a = tk.Label(set_button_frame, text="Inc >>", width=15, fg="black", relief="raised", font=self.fontbutton) button8a.grid(row=4, column=4, padx=10, pady=(10, 4), sticky='w') self.controller.ToolTip(button8a, text="T140 Dec <<") button8a.bind( "<ButtonRelease-1>", lambda event: self.servo_prog_label_released(event=event)) button8a.bind( "<Button-1>", lambda event: self.servo_prog_label_pressed(event=event, code=140)) # --- placement self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, pady=5, padx=5) config_frame.grid(row=1, column=0, pady=5, padx=5) self.tab_frame.grid(row=2, column=0, pady=0, padx=5) self.main_frame.columnconfigure(0, weight=1) # tab_frame direct_control_frame.grid(row=1, rowspan=1, column=0, pady=0, padx=5, sticky="") servo_program_frame.grid(row=2, column=0, pady=0, padx=5, sticky="ew") if show_buttons: button_frame.grid(row=3, column=0, pady=0, padx=5, sticky="ew") set_button_frame.grid(row=4, column=0, pady=0, padx=5, sticky="ew") self.tab_frame.grid_columnconfigure(0, weight=1) #self.tab_frame.grid_columnconfigure(1,weight=0) #self.tab_frame.grid_columnconfigure(2,weight=0) #self.tab_frame.grid_columnconfigure(3,weight=1) self.tab_frame.grid_rowconfigure(3, weight=1) # --- bindings #self.controller.bind("<Control-Right>",self.s_servo_address.invoke_buttonup) #self.controller.bind("<Control-Left>",self.s_servo_address.invoke_buttondown) #self.controller.bind("<Control-Up>",self.s_servo_channel.invoke_buttonup) #self.controller.bind("<Control-Down>",self.s_servo_channel.invoke_buttondown) self.controller.bind("<F1>", self.controller.call_helppage) self.controller.bind("<Alt-F4>", self.cancel) self.controller.bind("<Control-o>", self.led_off)
def __init__(self, parent, controller): self.tabClassName = "StartPage" logging.debug("Init Page %s ", self.tabClassName) self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) tk.Frame.__init__(self, parent) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=1) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) #config_frame = self.controller.create_macroparam_frame(self.main_frame,self.tabClassName, maxcolumns=4,startrow=1,style="CONFIGPage") text_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) #text = macrodata.get("Ausführliche Beschreibung","") photo_filename = macrodata.get("Photo", "") if photo_filename != "": try: logging.debug("Open Photo1 %s ", photo_filename) filedir = os.path.dirname(os.path.realpath(__file__)) self.photofilepath = os.path.join(filedir, photo_filename) text1 = tk.Text(text_frame, bg=self.cget('bg'), relief="flat", width=200) logging.debug("Open Photo2 %s ", self.photofilepath) self.photo = tk.PhotoImage(file=self.photofilepath) text1.insert(tk.END, '\n') text1.image_create(tk.END, image=self.photo) logging.debug("Open Photo %s ", self.photofilepath) except BaseException as e: logging.debug("Photo-Error", self.photofilepath, e) else: text1 = tk.Text(text_frame, bg=self.cget('bg'), relief="flat", width=200) content = macrodata.get("Content", {}) logging.debug("Open Content %s ", content) if content != {}: text_widget = tk.Text(text_frame, wrap=tk.WORD, bg=self.cget('bg'), relief="flat") text_scroll = tk.Scrollbar(text_frame, command=text_widget.yview) text_widget.configure(yscrollcommand=text_scroll.set) for titel, text in content.items(): text_widget.tag_configure('bold_italics', font=('Verdana', 10, 'bold', 'italic')) text_widget.tag_configure('big', font=('Verdana', 14, 'bold')) text_widget.tag_configure('normal', font=( 'Verdana', 10, )) text_widget.insert(tk.END, "\n" + titel + "\n", 'big') text_widget.insert(tk.END, text, 'normal') text_widget.config(state=tk.DISABLED) else: text_widget = tk.Text(text_frame, wrap=tk.WORD, bg=self.cget('bg'), relief="flat") text_scroll = tk.Scrollbar(text_frame, command=text_widget.yview) # --- placement # Tabframe => frame self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) # Frame placement => scroll_main_frame self.frame.grid(row=0, column=0, sticky="ns") self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) # scroll_main_frame => scroll_main_frame.interior => main_frame self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(1, weight=1) self.scroll_main_frame.interior.grid_rowconfigure(0, weight=1) self.scroll_main_frame.interior.grid_columnconfigure(0, weight=1) # main_frame => title_frame, config_frame, text_frame self.main_frame.grid(row=0, column=0, sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(1, weight=1) # place frames in main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) #config_frame.grid(row=1, column=0, pady=10, padx=10) text_frame.grid(row=2, column=0, padx=10, pady=0, sticky="nesw") text_frame.grid_columnconfigure(1, weight=1) text_frame.grid_rowconfigure(1, weight=1) # place widgets in text_frame => text1,text:widget, text_scroll #text1.pack(side=tk.LEFT,expand=0) #text_widget.pack(side=tk.LEFT,fill=tk.BOTH,padx=10,pady=(10,0)) #text_scroll.pack(side=tk.LEFT,fill=tk.Y) text1.grid(row=0, column=0, sticky="nesw") text_widget.grid(row=1, column=0, sticky=("nesw"), padx=10, pady=10) text_scroll.grid(row=1, column=1, sticky=("ns"))
def __init__(self, parent, controller): self.controller = controller self.arduino_portlist = {} tk.Frame.__init__(self, parent) self.tabClassName = "ConfigurationPage" macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) self.startcmd_filename = "" self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) #self.scroll_configframe = VerticalScrolledFrame(self.main_frame) #config_frame = self.controller.create_macroparam_frame(self.scroll_configframe.interior,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage") config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=10, style="CONFIGPage") # --- Buttons button_frame = ttk.Frame(self.main_frame) # button1_text = macrodata.get("Button_1", self.tabClassName) button2_text = macrodata.get("Button_2", self.tabClassName) button3_text = macrodata.get("Button_3", self.tabClassName) self.update_button = ttk.Button(button_frame, text=button1_text, command=self.save_config) self.update_button.pack(side="right", padx=10) # --- placement # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) button_frame.grid(row=1, column=0, pady=10, padx=10) config_frame.grid(row=2, column=0, pady=10, padx=10, sticky="nesw") macroparams = macrodata.get("Params", []) for paramkey in macroparams: paramconfig_dict = self.controller.MacroParamDef.data.get( paramkey, {}) param_type = paramconfig_dict.get("Type", "") if param_type == "Multipleparams": mparamlist = paramconfig_dict.get("MultipleParams", []) mp_repeat = paramconfig_dict.get("Repeat", "") if mp_repeat == "": for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val( self.tabClassName, mparamkey, value) else: # get the repeated multipleparams rep_mparamkey=macro.mparamkey.index (e.g. ConfigDataPage.Z21Data.0 for i in range(int(mp_repeat)): for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.controller.getConfigData_multiple( configdatakey, paramkey, i) mp_macro = self.tabClassName + "." + paramkey + "." + str( i) self.controller.set_macroparam_val( mp_macro, mparamkey, value) else: configdatakey = self.controller.getConfigDatakey(paramkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val(self.tabClassName, paramkey, value)
class ConfigurationPage(tk.Frame): def __init__(self, parent, controller): self.controller = controller self.arduino_portlist = {} tk.Frame.__init__(self, parent) self.tabClassName = "ConfigurationPage" macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) self.startcmd_filename = "" self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) #self.scroll_configframe = VerticalScrolledFrame(self.main_frame) #config_frame = self.controller.create_macroparam_frame(self.scroll_configframe.interior,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage") config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=10, style="CONFIGPage") # --- Buttons button_frame = ttk.Frame(self.main_frame) # button1_text = macrodata.get("Button_1", self.tabClassName) button2_text = macrodata.get("Button_2", self.tabClassName) button3_text = macrodata.get("Button_3", self.tabClassName) self.update_button = ttk.Button(button_frame, text=button1_text, command=self.save_config) self.update_button.pack(side="right", padx=10) # --- placement # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) button_frame.grid(row=1, column=0, pady=10, padx=10) config_frame.grid(row=2, column=0, pady=10, padx=10, sticky="nesw") macroparams = macrodata.get("Params", []) for paramkey in macroparams: paramconfig_dict = self.controller.MacroParamDef.data.get( paramkey, {}) param_type = paramconfig_dict.get("Type", "") if param_type == "Multipleparams": mparamlist = paramconfig_dict.get("MultipleParams", []) mp_repeat = paramconfig_dict.get("Repeat", "") if mp_repeat == "": for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val( self.tabClassName, mparamkey, value) else: # get the repeated multipleparams rep_mparamkey=macro.mparamkey.index (e.g. ConfigDataPage.Z21Data.0 for i in range(int(mp_repeat)): for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.controller.getConfigData_multiple( configdatakey, paramkey, i) mp_macro = self.tabClassName + "." + paramkey + "." + str( i) self.controller.set_macroparam_val( mp_macro, mparamkey, value) else: configdatakey = self.controller.getConfigDatakey(paramkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val(self.tabClassName, paramkey, value) # ---------------------------------------------------------------- # Standardprocedures for every tabpage # ---------------------------------------------------------------- def tabselected(self): #self.controller.currentTabClass = self.tabClassName #self.ledmaxcount.set(self.controller.get_maxLEDcnt()) logging.debug("Tabselected: %s", self.tabname) self.store_old_config() def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) if self.check_if_config_data_changed(): answer = tk.messagebox.askyesnocancel( 'Sie verlassen die Einstellungen', 'Die Einstellungen wurden verändert. Sollen die geänderten Einstellungen gesichert werden?', default='no') if answer == None: return # cancelation return to "ConfigurationOage" if answer: self.save_config() def cancel(self): self.save_config() def getConfigPageParams(self): pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setConfigDataDict(self, paramdict): self.controller.setConfigDataDict(paramdict) def get_macroparam_var_values(self, macro): return self.controller.get_macroparam_var_values(macro) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): logging.debug("MenuUndo: %s", self.tabname) pass def MenuRedo(self, _event=None): logging.debug("MenuRedo: %s", self.tabname) pass def connect(self): pass def disconnect(self): pass # ---------------------------------------------------------------- # ConfigurationPage save_config # ---------------------------------------------------------------- def save_config(self): self.setConfigData("pos_x", self.winfo_x()) self.setConfigData("pos_y", self.winfo_y()) param_values_dict = self.get_macroparam_var_values(self.tabClassName) # update maxLEDCnt maxLEDcnt = param_values_dict.get("maxLEDcount", "20") self.controller.set_maxLEDcnt(maxLEDcnt) self.setConfigDataDict(param_values_dict) self.store_old_config() self.controller.SaveConfigData() logging.debug("SaveConfig: %s - %s", self.tabname, repr(self.controller.ConfigData.data)) def store_old_config(self): self.old_param_values_dict = self.get_macroparam_var_values( self.tabClassName) def check_if_config_data_changed(self): param_values_dict = self.get_macroparam_var_values(self.tabClassName) if self.old_param_values_dict != param_values_dict: return True return False # ---------------------------------------------------------------- # ConfigurationPage _update_led_count # ---------------------------------------------------------------- def _update_led_count(self, event=None): if event is None or event.widget.old_value != event.widget.get(): maxledcount = self.s_ledmaxcount.get() def autocn(self, event=None): if self.s_autocnvar.get() == 1: self.setConfigData("autoconnect", True) else: self.setConfigData("autoconnect", False) def _update_cor_rgb(self, event=None): """Update display after a change in the RGB spinboxes.""" if event is None or event.widget.old_value != event.widget.get(): self.setConfigData("led_correction_r", self.cs_red.get()) self.setConfigData("led_correction_g", self.cs_green.get()) self.setConfigData("led_correction_b", self.cs_blue.get())
class StartPage(tk.Frame): def __init__(self, parent, controller): self.tabClassName = "StartPage" self.controller = controller macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) tk.Frame.__init__(self, parent) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=1) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=4, startrow=1, style="CONFIGPage") text_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) #text = macrodata.get("Ausführliche Beschreibung","") photo_filename = macrodata.get("Photo", "") if photo_filename != "": filedir = os.path.dirname(os.path.realpath(__file__)) self.photofilepath = os.path.join(filedir, photo_filename) text1 = tk.Text(text_frame, width=30, bg=self.cget('bg'), relief="flat") self.photo = tk.PhotoImage(file=self.photofilepath) text1.insert(tk.END, '\n') text1.image_create(tk.END, image=self.photo) content = macrodata.get("Content", {}) if content != {}: text_widget = tk.Text(text_frame, wrap=tk.WORD, bg=self.cget('bg'), relief="flat") text_scroll = tk.Scrollbar(text_frame, command=text_widget.yview) text_widget.configure(yscrollcommand=text_scroll.set) for titel, text in content.items(): text_widget.tag_configure('bold_italics', font=('Verdana', 10, 'bold', 'italic')) text_widget.tag_configure('big', font=('Verdana', 14, 'bold')) text_widget.tag_configure('normal', font=( 'Verdana', 10, )) text_widget.insert(tk.END, "\n" + titel + "\n", 'big') text_widget.insert(tk.END, text, 'normal') text_widget.config(state=tk.DISABLED) # --- placement # Tabframe => frame self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) # Frame placement => scroll_main_frame self.frame.grid(row=0, column=0, sticky="ns") self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) # scroll_main_frame => scroll_main_frame.interior => main_frame self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame.interior.grid_rowconfigure(0, weight=1) self.scroll_main_frame.interior.grid_columnconfigure(0, weight=1) # main_frame => title_frame, config_frame, text_frame self.main_frame.grid(row=0, column=0, sticky="nesw") self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) # place frames in main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) config_frame.grid(row=1, column=0, pady=10, padx=10) text_frame.grid(row=2, column=0, padx=10, pady=0, sticky="nesw") text_frame.grid_columnconfigure(1, weight=1) text_frame.grid_rowconfigure(0, weight=1) # place widgets in text_frame => text1,text:widget, text_scroll #text1.pack(side=tk.LEFT,expand=0) #text_widget.pack(side=tk.LEFT,fill=tk.BOTH,padx=10,pady=(10,0)) #text_scroll.pack(side=tk.LEFT,fill=tk.Y) text1.grid(row=0, column=0, sticky="ns") text_widget.grid(row=0, column=1, sticky=("nesw"), padx=10, pady=10) text_scroll.grid(row=0, column=2, sticky=("ns")) def cancel(self, _event=None): pass def tabselected(self): logging.debug("Tabselected: %s", self.tabname) #self.controller.currentTabClass = self.tabClassName logging.info(self.tabname) pass def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) pass def TabChanged(self, _event=None): pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): pass def MenuRedo(self, _event=None): pass def dummy(self, event): logging.info("dummy") def send_command_to_ARDUINO(self, command): pass def connect(self): pass def disconnect(self): pass
class ARDUINOConfigPage(tk.Frame): def __init__(self, parent, controller): self.controller = controller self.arduino_portlist = {} tk.Frame.__init__(self, parent) self.tabClassName = "ARDUINOConfigPage" macrodata = self.controller.MacroDef.data.get(self.tabClassName, {}) self.tabname = macrodata.get("MTabName", self.tabClassName) self.title = macrodata.get("Title", self.tabClassName) self.startcmd_filename = "" self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = ttk.Frame(self, relief="ridge", borderwidth=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1) self.scroll_main_frame = ScrolledFrame(self.frame) self.scroll_main_frame.grid_columnconfigure(0, weight=1) self.scroll_main_frame.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self.scroll_main_frame.interior, relief="ridge", borderwidth=2) self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(2, weight=1) title_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) label = ttk.Label(title_frame, text=self.title, font=LARGE_FONT) label.pack(padx=5, pady=(5, 5)) #self.scroll_configframe = VerticalScrolledFrame(self.main_frame) #config_frame = self.controller.create_macroparam_frame(self.scroll_configframe.interior,self.tabClassName, maxcolumns=1,startrow =10,style="CONFIGPage") config_frame = self.controller.create_macroparam_frame( self.main_frame, self.tabClassName, maxcolumns=1, startrow=10, style="CONFIGPage") # --- Buttons button_frame = ttk.Frame(self.main_frame) # button1_text = macrodata.get("Button_1", self.tabClassName) button2_text = macrodata.get("Button_2", self.tabClassName) button3_text = macrodata.get("Button_3", self.tabClassName) self.update_button = ttk.Button(button_frame, text=button1_text, command=self.save_config) self.update_button.pack(side="right", padx=10) # --- start cmd checkbox and file selection startcmd_frame = ttk.Frame(self.main_frame, relief="ridge", borderwidth=2) self.s_startcmdcbvar = tk.IntVar() self.s_startcmdcb = ttk.Checkbutton(startcmd_frame, text=button2_text, variable=self.s_startcmdcbvar, onvalue=1, offvalue=0, command=self.startcmd) self.s_startcmdcb.grid(sticky='w', padx=4, pady=4, row=0, column=0) self.s_startcmdcbvar.set(self.getConfigData("startcmdcb")) self.startcmd_filename = self.getConfigData("startcmd_filename") self.startcmd_button = ttk.Button(startcmd_frame, text=button3_text, width=30, command=self.askselectfile) self.startcmd_button.grid(row=0, column=1, padx=4, pady=4, sticky="w") self.startcmd_label = tk.Label(startcmd_frame, text=self.startcmd_filename, width=120, height=1, wraplength=700) self.startcmd_label.grid(row=1, column=0, columnspan=2, padx=4, pady=4, sticky="w") # --- placement # Tabframe self.frame.grid(row=0, column=0) self.scroll_main_frame.grid(row=0, column=0, sticky="nesw") # scroll_main_frame self.main_frame.grid(row=0, column=0) # main_frame title_frame.grid(row=0, column=0, pady=10, padx=10) button_frame.grid(row=1, column=0, pady=10, padx=10) config_frame.grid(row=2, column=0, pady=10, padx=10, sticky="nesw") startcmd_frame.grid(row=3, column=0, pady=10, padx=10, stick="ew") macroparams = macrodata.get("Params", []) for paramkey in macroparams: paramconfig_dict = self.controller.MacroParamDef.data.get( paramkey, {}) param_type = paramconfig_dict.get("Type", "") if param_type == "Multipleparams": mparamlist = paramconfig_dict.get("MultipleParams", []) mp_repeat = paramconfig_dict.get("Repeat", "") if mp_repeat == "": for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val( self.tabClassName, mparamkey, value) else: # get the repeated multipleparams rep_mparamkey=macro.mparamkey.index (e.g. ConfigDataPage.Z21Data.0 for i in range(int(mp_repeat)): for mparamkey in mparamlist: configdatakey = self.controller.getConfigDatakey( mparamkey) value = self.controller.getConfigData_multiple( configdatakey, paramkey, i) mp_macro = self.tabClassName + "." + paramkey + "." + str( i) self.controller.set_macroparam_val( mp_macro, mparamkey, value) else: configdatakey = self.controller.getConfigDatakey(paramkey) value = self.getConfigData(configdatakey) self.controller.set_macroparam_val(self.tabClassName, paramkey, value) # ---------------------------------------------------------------- # Standardprocedures for every tabpage # ---------------------------------------------------------------- def tabselected(self): #self.controller.currentTabClass = self.tabClassName #self.ledmaxcount.set(self.controller.get_maxLEDcnt()) logging.debug("Tabselected: %s", self.tabname) self.store_old_config() self.controller.disconnect() if self.arduino_portlist == {}: logging.debug("Create Portlist") self.comports = portlist.comports(include_links=False) self.old_ports = [] conarduino_str = "" for comport in self.comports: logging.debug("Portlist.ComPorts:" + comport[0] + " " + comport[1] + " " + comport[2]) if self.check_string( comport[1], ["ARDUINO", "CH340", "USB Serial Port", "ttyACM", "USB"]): portlist_data = self.arduino_portlist.get(comport[0], {}) if portlist_data == {}: self.arduino_portlist[comport[0]] = { "Description": comport[1], "Baudrate": "???", "DeviceSignature": "???", "Status": "unchecked" } else: portlist_data["Description"] = comport[1] portlist_data["Baudrate"] = "???" portlist_data["DeviceSignature"] = "???" portlist_data["Status"] = "unchecked" self.update_ARDUINO_data(update_comport=True) # bind update of Comport combobox to event combobox_var = self.controller.macroparams_var["ARDUINOConfigPage"][ "ARDUINO Port"] combobox_var.bind("<<ComboboxSelected>>", self.on_comport_value_changed) self.controller.set_macroparam_val(self.tabClassName, "ARDUINOMessage", "Erkennung der ARDUINOs ...", disable=True) logging.debug(repr(self.arduino_portlist)) self.monitor_arduino_ports = True self.after(200, self.on_update_ARDUINO_data) def tabunselected(self): logging.debug("Tabunselected: %s", self.tabname) self.monitor_arduino_ports = False self.blink_ARDUINO = "" if self.check_if_config_data_changed(): answer = tk.messagebox.askyesnocancel( 'Sie verlassen die ARDUINO Einstellungen', 'Die ARDUINO Einstellunegn wurden verändert. Sollen die geänderten ARDUINO Einstellungen gesichert werden?', default='no') if answer == None: return # cancelation return to "ConfigurationOage" if answer: self.save_config() def cancel(self): self.save_config() def getConfigPageParams(self): pass def getConfigData(self, key): return self.controller.getConfigData(key) def readConfigData(self): self.controller.readConfigData() def setConfigData(self, key, value): self.controller.setConfigData(key, value) def setConfigDataDict(self, paramdict): self.controller.setConfigDataDict(paramdict) def get_macroparam_var_values(self, macro): return self.controller.get_macroparam_var_values(macro) def setParamData(self, key, value): self.controller.setParamData(key, value) def MenuUndo(self, _event=None): logging.debug("MenuUndo: %s", self.tabname) pass def MenuRedo(self, _event=None): logging.debug("MenuRedo: %s", self.tabname) pass def connect(self): pass def disconnect(self): pass # ---------------------------------------------------------------- # ARDUINOConfigPage save_config # ---------------------------------------------------------------- DeviceSignature2Chip_dict = { b'\x1E\x90\x07': "ATtiny13", b'\x1E\x91\x0A': "ATtiny2313", b'\x1E\x92\x0A': "ATmega48P", b'\x1E\x93\x07': "ATmega8", b'\x1E\x94\x06': "ATmega168", b'\x1E\x95\x02': "ATmega32", b'\x1E\x95\x0F': "ATmega328P (Nano/Uno)", b'\x1E\x95\x14': "ATmega328-PU", b'\x1E\x96\x02': "ATmega64", b'\x1E\x96\x09': "ATmega644", b'\x1E\x97\x02': "ATmega128", b'\x1E\x97\x03': "ATmega1280", b'\x1E\x98\x01': "ATmega2560", "ESP32": "ESP32" } def on_comport_value_changed(self, event): combobox_var = event.widget port = combobox_var.get() logging.debug("Comport_value_changed %s", port) takeover = self.controller.get_macroparam_val("ARDUINOConfigPage", "ARDUINOTakeOver") if takeover: # set boardtype and baudrate portdata = self.arduino_portlist.get(port, {}) if portdata != {}: baudrate = portdata.get("Baudrate", "115200") if baudrate != 0: self.controller.set_macroparam_val("ARDUINOConfigPage", "ARDUINO Baudrate", baudrate) if baudrate == "115200": self.controller.set_macroparam_val( "ARDUINOConfigPage", "ARDUINO Type", 1) else: self.controller.set_macroparam_val( "ARDUINOConfigPage", "ARDUINO Type", 0) self.blink_ARDUINO = port self.after(200, self.on_blink_arduino_led) def on_blink_arduino_led(self): arduino_blick_cb = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINOBlink") if self.blink_ARDUINO != "" and arduino_blick_cb == 1: portdata = self.arduino_portlist.get(self.blink_ARDUINO, {}) if portdata != {}: baudrate = portdata.get("Baudrate", "0") if baudrate in ["115200", "57600"]: # check if device is an ARDUINO Baudrate = 50 Res, DeviceSignatur = self.Get_Arduino_Baudrate( self.blink_ARDUINO, Start_Baudrate=Baudrate, trials=1) self.after(2000, self.on_blink_arduino_led) def determine_new_and_removed_ports(self, updated_comports_list): removed_ports_list = [] new_ports_list = [] show_entry = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINOShowAll") # check for removed ports for port in self.old_ports: port_found = False for comport in updated_comports_list: if not show_entry: check_entry = self.check_string(comport[1], [ "ARDUINO", "CH340", "USB Serial Port", "ttyACM", "USB", "Silicon Labs CP210x" ]) if port == comport[0] and (show_entry or check_entry): port_found = True break if not port_found: removed_ports_list.append(port) # check for new ports for comport in updated_comports_list: port = comport[0] if not port in self.old_ports: if not show_entry: check_entry = self.check_string(comport[1], [ "ARDUINO", "CH340", "USB Serial Port", "ttyACM", "USB", "Silicon Labs CP210x" ]) if show_entry or check_entry: new_ports_list.append(port) self.arduino_portlist[port] = { "Description": comport[1], "Baudrate": "???", "DeviceSignature": "???", "Status": "unchecked" } if new_ports_list != []: logging.debug("determine_new_and_removed_ports %s", repr(new_ports_list)) if removed_ports_list != []: logging.debug("determine_new_and_removed_ports %s", repr(removed_ports_list)) return new_ports_list, removed_ports_list def update_ARDUINO_data(self, update_comport=False): conarduino_str = "" ARDUINO_port = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINO Port") new_ARDUINO_port = "NO DEVICE" port_found = False for port in sorted(self.arduino_portlist.keys()): port_data = self.arduino_portlist[port] conarduino_str += port + " " + port_data[ "Description"] + " Baudrate:" + port_data[ "Baudrate"] + " " + self.DeviceSignature2Chip_dict.get( port_data["DeviceSignature"], "unknown device") + "\n" if not port_data["Baudrate"] in ["???", "0"]: new_ARDUINO_port = port if port == ARDUINO_port: port_found = True if port_found: new_ARDUINO_port = ARDUINO_port self.controller.set_macroparam_val(self.tabClassName, "ARDUINOConnected", conarduino_str, disable=True) takeover = self.controller.get_macroparam_val("ARDUINOConfigPage", "ARDUINOTakeOver") if update_comport: comport_valuelist = sorted(self.arduino_portlist.keys()) comport_valuelist[:0] = ["NO DEVICE"] self.controller.update_combobox_valuelist("ARDUINOConfigPage", "ARDUINO Port", comport_valuelist, value=new_ARDUINO_port) if takeover and update_comport: #comport_valuelist = sorted(self.arduino_portlist.keys()) #comport_valuelist[:0] = ["NO DEVICE"] #self.controller.update_combobox_valuelist("ARDUINOConfigPage","ARDUINO Port",comport_valuelist,value=new_ARDUINO_port) paramconfig_dict = self.controller.MacroParamDef.data.get( "Z21Data", {}) mp_repeat = paramconfig_dict.get("Repeat", "") for i in range(int(mp_repeat)): self.controller.update_combobox_valuelist( "ConfigurationPage.Z21Data.{:1}".format(i), "ARDUINO Port", comport_valuelist, value="") portdata = self.arduino_portlist.get(new_ARDUINO_port, {}) if portdata != {}: baudrate = portdata.get("Baudrate", "115200") if baudrate != 0: self.controller.set_macroparam_val("ARDUINOConfigPage", "ARDUINO Baudrate", baudrate) if baudrate == "115200": self.controller.set_macroparam_val( "ARDUINOConfigPage", "ARDUINO Type", 1) else: self.controller.set_macroparam_val( "ARDUINOConfigPage", "ARDUINO Type", 0) if port_data["DeviceSignature"] == "ESP32": self.controller.set_macroparam_val("ARDUINOConfigPage", "ARDUINO Type", 2) def on_update_ARDUINO_data(self): if self.monitor_arduino_ports: temp_comports_list = portlist.comports(include_links=False) new_ports_list, removed_ports_list = self.determine_new_and_removed_ports( temp_comports_list) # delete ports not in ports_list anymore for port in removed_ports_list: logging.debug("Port %s delete from ARDUINO portlist", port) del self.arduino_portlist[port] self.old_ports.remove(port) for port in new_ports_list: logging.debug("Try to add Port %s to ARDUINO portlist", port) self.controller.set_macroparam_val(self.tabClassName, "ARDUINOMessage", "Teste Port: " + port + "...", disable=True) self.controller.update() portlist_data = self.arduino_portlist.get(port, {}) if not "Silicon Labs CP210x USB to UART Bridge" in portlist_data[ "Description"]: baudrate, DeviceSignature = self.Get_Arduino_Baudrate(port) else: baudrate = 115200 DeviceSignature = "ESP32" if portlist_data == {}: self.arduino_portlist[port] = { "Description": port, "Baudrate": str(baudrate), "DeviceSignature": DeviceSignature, "Status": "new" } else: portlist_data["Baudrate"] = str(baudrate) portlist_data["DeviceSignature"] = DeviceSignature portlist_data["Status"] = "new" self.old_ports.append(port) break if removed_ports_list != [] or new_ports_list != []: update_comport = len( new_ports_list) == 1 or removed_ports_list != [] self.update_ARDUINO_data(update_comport=update_comport) if new_ports_list != []: if self.monitor_arduino_ports: self.after(100, self.on_update_ARDUINO_data) self.controller.set_macroparam_val(self.tabClassName, "ARDUINOMessage", "ARDUINO Erkennung ... ", disable=True) else: if self.monitor_arduino_ports: self.after(1000, self.on_update_ARDUINO_data) self.controller.set_macroparam_val(self.tabClassName, "ARDUINOMessage", "ARDUINO Erkennung beendet", disable=True) def check_string(self, string, substring_list): for substring in substring_list: if substring.upper() in string.upper(): return True return False def Get_Arduino_Baudrate(self, ComPort, Start_Baudrate=1, trials=4): # Return >0: Baudrate 57600/115200 # 0: if no arduino is detected # -1: can't open com port => used by an other program ? # -2: can't create com port file # -3: can't reset arduino # DeviceSignature if Start_Baudrate == 1: Baudrate = 115200 elif Start_Baudrate == 2: Baudrate = 57600 else: Baudrate = Start_Baudrate #if not Baudrate in [115200,57600]: Baudrate = 115200 for i in range(trials): logging.debug("Trying COM %s with Baudrate %s", ComPort, Baudrate) Res, DeviceSignatur = self.detect_arduino(ComPort, Baudrate, No_of_trials=int(trials / 2)) if Res == 1: # Arduino detected logging.debug(" Serial Port : %s", ComPort) logging.debug(" Serial Baudrate : %s", Baudrate) logging.debug(" Device signature: %s", DeviceSignatur) if DeviceSignatur == b'\x1E\x95\x0F': logging.debug("ATMega328P") logging.debug( "Device: %s - %s", DeviceSignatur, self.DeviceSignature2Chip_dict.get(DeviceSignatur, "unknown device")) return Baudrate, DeviceSignatur elif Res == 0: logging.debug("%s:no ARDUINO detected, baudrate: %s", ComPort, Baudrate) pass elif Res == -1: DeviceSignatur = "can't open com port" logging.debug("%s:%s, baudrate: %s", ComPort, DeviceSignatur, Baudrate) return Res, DeviceSignatur elif Res == -2: DeviceSignatur = "can't create com port file" # should never happen logging.debug("%s:%s, baudrate: %s", ComPort, DeviceSignatur, Baudrate) return Res, DeviceSignatur elif Res == -3: DeviceSignatur = "can't reset ARDUINO" # should never happen logging.debug("%s:%s, baudrate: %s", ComPort, DeviceSignatur, Baudrate) return Res, DeviceSignatur else: logging.debug("%s:unkonw ERROR, baudrate: %s", ComPort, Baudrate) return Res, b"unknown ERROR " if Baudrate == 115200: Baudrate = 57600 else: Baudrate = 115200 #Check again with the other baudrate return 0, b'' def transact(self, bytemessage, nNumberOfBytesToRead=10): bytemessage += Sync_CRC_EOP # write message to serport nbytes_written = self.controller.arduino.write(bytemessage) if nbytes_written != len(bytemessage): logging.debug("ERROR write to ARDUINO") return b'' no_of_trials = 2 for i in range(no_of_trials): # read from serport nNumberOfBytesToRead read_data = self.controller.arduino.read(size=nNumberOfBytesToRead) logging.debug("transact: %s", read_data) if (read_data[:1] == Resp_STK_INSYNC and read_data[-1:] == Resp_STK_OK) or read_data[-1:] == Resp_STK_FAILED: # return response logging.debug("transact data_ok: %s", read_data) return read_data return b'' def getdeviceinformation(self): logging.debug("getdeviceinformation") DeviceSignatur = b'' HWVersion = b'' SWMajorVersion = b'' SWMinorVersion = b'' Data = self.transact(STK_READ_SIGN, 5) if len(Data) == 5: if Data[4].to_bytes(1, byteorder="little") == Resp_STK_OK: DeviceSignatur = Data[1:4] logging.debug("getdeviceinformation: %s", str(DeviceSignatur)) if DeviceSignatur == b'\x1E\x95\x0F': logging.info("ATMEGA328P") else: logging.info("Device Signatur: %s", str(DeviceSignatur)) return DeviceSignatur def detect_arduino(self, port, baudrate, No_of_trials=2): # protocol see application note 1AVR061 here http://ww1.microchip.com/downloads/en/Appnotes/doc2525.pdf # Result: 1: O.K # 0: Give up after n trials => if no arduino is detected # -1: can't open com port # -2: can't close and assign port # -3: can't reset arduino print("detect_arduino:", port) no_port = None try: # close the port if it is open and reopen it with DTR = False if self.controller.arduino and self.controller.arduino.is_open: self.controller.arduino.close() self.controller.arduino = serial.Serial( no_port, baudrate=baudrate, timeout=0.2, write_timeout=1, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) #logging.info("connected to: " + self.controller.arduino.port) except BaseException as e: logging.debug(e) logging.debug("detect_arduino: Error assigning port") return -2, None self.controller.arduino.port = port self.controller.arduino.dtr = False try: self.controller.arduino.open() except BaseException as e: logging.debug(e) logging.debug("detect_arduino: Error opening port") return -1, None try: self.controller.arduino.dtr = True time.sleep(0.250) self.controller.arduino.dtr = False except BaseException as e: logging.debug(e) logging.debug("Error, reset ARDUINO") return -3, None # now get in sync message = Cmnd_STK_GET_SYNC sucessful = False for i in range(No_of_trials): message = self.transact(Cmnd_STK_GET_SYNC, 2) if message == Resp_STK_INSYNC + Resp_STK_OK: devicesignatur = self.getdeviceinformation() self.controller.arduino.close() return 1, devicesignatur if not sucessful: logging.debug("Give up after %s trials", No_of_trials) return 0, None def save_config(self): self.setConfigData("pos_x", self.winfo_x()) self.setConfigData("pos_y", self.winfo_y()) self.setConfigData("startcmd_filename", self.startcmd_filename) param_values_dict = self.get_macroparam_var_values(self.tabClassName) self.setConfigDataDict(param_values_dict) self.store_old_config() self.controller.SaveConfigData() logging.debug("SaveConfig: %s - %s", self.tabname, repr(self.controller.ConfigData.data)) def store_old_config(self): self.old_startcmd_filename = self.startcmd_filename self.old_param_values_dict = self.get_macroparam_var_values( self.tabClassName) def check_if_config_data_changed(self): if self.old_startcmd_filename != self.startcmd_filename: return True param_values_dict = self.get_macroparam_var_values(self.tabClassName) if self.old_param_values_dict != param_values_dict: return True return False def autocn(self, event=None): if self.s_autocnvar.get() == 1: self.setConfigData("autoconnect", True) else: self.setConfigData("autoconnect", False) def startcmd(self, event=None): if self.s_startcmdcbvar.get() == 1: self.setConfigData("startcmdcb", True) else: self.setConfigData("startcmdcb", False) def askselectfile(self): self.startcmd_filename = tk.filedialog.askopenfilename() system_platform = platform.platform() macos = "macOS" in system_platform macos_fileending = "/Contents/MacOS/Arduino" if macos: logging.debug("This is a MAC") if not self.startcmd_filename.endswith(macos_fileending): self.startcmd_filename = self.startcmd_filename + "/Contents/MacOS/Arduino" self.startcmd_label.configure(text=self.startcmd_filename) def ButtonARDUINOTest(self): logging.debug("Function called: ButtonARDUINOConnect") ARDUINO_port = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINO Port") self.controller.connect(port=ARDUINO_port) def ButtonARDUINOInitLED(self): logging.debug("Function called: ButtonARDUINOInitLED") ARDUINO_port = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINO Port") answer = tk.messagebox.askyesnocancel( 'Initialisieren des LED ARDUINO ', 'Der LED ARDUINO wird jetzt mit dem MobaLedLib Programm beschrieben\nStellen Sie sicher, dass der LINKE ARDUINO mit dem Port ' + ARDUINO_port + " verbunden ist", default='no') if answer == None: return # no cancelation if answer: self.controller.showFramebyName("ARDUINOMonitorPage") self.update() effecttestpage_frame = self.controller.getFramebyName( "EffectTestPage") if effecttestpage_frame: effecttestpage_frame.upload_to_ARDUINO(init_arduino=True) def ButtonARDUINOInitDCC(self): logging.debug("Function called: ButtonARDUINOInitDCC") ARDUINO_port = self.controller.get_macroparam_val( "ARDUINOConfigPage", "ARDUINO Port") digital_system = self.controller.get_macroparam_val( "ARDUINOConfigPage", "MLL_DigitalSystem") if digital_System == "DCC": answer = tk.messagebox.askyesnocancel( 'Initialisieren des DCC ARDUINOs ', 'Der DCC ARDUINO wird jetzt mit dem DCC-Receiver Programm beschrieben\nStellen Sie sicher, dass der RECHTE ARDUINO mit dem Port ' + ARDUINO_port + " verbunden ist", default='no') if answer == None: return # no cancelation if answer: self.controller.showFramebyName("ARDUINOMonitorPage") self.update() effecttestpage_frame = self.controller.getFramebyName( "EffectTestPage") if effecttestpage_frame: effecttestpage_frame.upload_to_ARDUINO(init_arduino=True, arduino_type="DCC") elif digital_system == "Selectrix": answer = tk.messagebox.askyesnocancel( 'Initialisieren des Selectrix ARDUINOs ', 'Der Selectrix ARDUINO wird jetzt mit dem Selectrix-Receiver Programm beschrieben\nStellen Sie sicher, dass der RECHTE ARDUINO mit dem Port ' + ARDUINO_port + " verbunden ist", default='no') if answer == None: return # no cancelation if answer: self.controller.showFramebyName("ARDUINOMonitorPage") self.update() effecttestpage_frame = self.controller.getFramebyName( "EffectTestPage") if effecttestpage_frame: effecttestpage_frame.upload_to_ARDUINO( init_arduino=True, arduino_type="Selectrix") else: tk.messagebox.showerror( "Der zusätzliche ARDUINO wird nur für DCC/Selectrix Digital systeme benötigt. Bitte die Einstellungen überprüfen." )