import tkinter as tk from tkinter import ttk class ScadaFrame(ttk.Frame): """Frame for configuring SCADA project settings.""" def __init__(self, parent, **kwargs): super().__init__(parent, padding="10", **kwargs) self.columnconfigure(1, weight=1) self.columnconfigure(3, weight=1) self.settings = {} # Define settings fields and their labels/types # (Label, key, row, column, columnspan, type ['entry', 'spinbox']) self.field_definitions = [ ("Project Title:", 'project_title', 0, 0, 1, 'entry'), # ("Parent Project:", 'parent_project', 0, 2, 1, 'entry'), # Removed parent project field ("Ignition Base Dir:", 'ignition_base_dir', 0, 2, 1, 'entry'), # Added ("View Name:", 'view_name', 1, 0, 1, 'entry'), ("View Path (Optional):", 'view_path', 1, 2, 1, 'entry'), ("Background SVG URL (Optional):", 'svg_url', 2, 0, 3, 'entry'), ("Image Width:", 'image_width', 3, 0, 1, 'spinbox'), ("Image Height:", 'image_height', 3, 2, 1, 'spinbox'), ("Default View Width:", 'default_width', 4, 0, 1, 'spinbox'), ("Default View Height:", 'default_height', 4, 2, 1, 'spinbox'), ] # Create label and entry/spinbox widgets for each setting self.settings_vars = {} for label_text, key, r, c, span, field_type in self.field_definitions: label = ttk.Label(self, text=label_text) label.grid(row=r, column=c, padx=5, pady=5, sticky="w") var = tk.StringVar() self.settings_vars[key] = var if field_type == 'spinbox': widget = ttk.Spinbox(self, from_=0, to=10000, textvariable=var, width=10) else: # Default to entry widget = ttk.Entry(self, textvariable=var) widget.grid(row=r, column=c + 1, columnspan=span, padx=5, pady=5, sticky="ew") def get_settings(self): """Get the current settings from the input fields.""" settings = {key: var.get() for key, var in self.settings_vars.items()} # Add back parent_project as empty string for potential compatibility, or handle upstream? # For direct creation, it's not used by ScadaViewCreator, so omitting it is cleaner. # settings['parent_project'] = '' # No longer needed return settings def set_settings(self, settings_dict): """Set the input fields based on a dictionary.""" for key, var in self.settings_vars.items(): var.set(settings_dict.get(key, '')) # Handle parent_project if it exists in the dict (e.g., from old config) # No need to set parent_project_var as the field is removed # Example usage (for testing) if __name__ == '__main__': root = tk.Tk() root.title("SCADA Frame Test") root.geometry("600x400") # Style for testing style = ttk.Style() style.theme_use('clam') style.configure('TFrame', background='#f0f0f0') style.configure('TLabel', background='#f0f0f0') # Create and pack the SCADA frame scada_frame = ScadaFrame(root) scada_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10) # Test buttons def get_settings(): settings = scada_frame.get_settings() print("Current settings:", settings) def set_settings(): test_settings = { 'project_title': 'Test Project', 'parent_project': 'com.inductiveautomation.perspective', 'view_name': 'TestView', 'view_path': '', 'svg_url': 'http://example.com/test.svg', 'image_width': '800', 'image_height': '600', 'default_width': '14', 'default_height': '14' } scada_frame.set_settings(test_settings) ttk.Button(root, text="Get Settings", command=get_settings).pack(pady=5) ttk.Button(root, text="Set Settings", command=set_settings).pack(pady=5) root.mainloop()