From ee37a10a97e4c28650a678f761f427d79b115569 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 4 Apr 2025 22:21:15 +0200 Subject: [PATCH] Mejorado de las redimensiones de la ventana --- menu-ip-change.py | 192 +++++++++++++++++++++++++++------------------- 1 file changed, 112 insertions(+), 80 deletions(-) diff --git a/menu-ip-change.py b/menu-ip-change.py index 517ed7b..1151efb 100644 --- a/menu-ip-change.py +++ b/menu-ip-change.py @@ -245,6 +245,10 @@ class IPChangerApp: self.ip_setup_tab = ttk.Frame(self.notebook, padding="10") self.tools_tab = ttk.Frame(self.notebook, padding="10") + # Configure tab frames to expand + self.ip_setup_tab.columnconfigure(0, weight=1) + self.tools_tab.columnconfigure(0, weight=1) + # Add tabs to the notebook self.notebook.add(self.ip_setup_tab, text="IP Setup") self.notebook.add(self.tools_tab, text="Tools") @@ -286,7 +290,7 @@ class IPChangerApp: def create_ip_setup_tab(self): # Control frame for IP Setup tab self.control_frame = ttk.Frame(self.ip_setup_tab) - self.control_frame.grid(row=0, column=0, sticky="new") + self.control_frame.grid(row=0, column=0, sticky="nsew") self.control_frame.columnconfigure(0, weight=1) # Sección de interfaces @@ -294,6 +298,9 @@ class IPChangerApp: self.control_frame, text="Network Interfaces", padding="5" ) self.interfaces_frame.grid(row=0, column=0, sticky="ew", pady=(0, 10)) + self.interfaces_frame.columnconfigure( + 1, weight=1 + ) # Make combo box column expandable ttk.Label(self.interfaces_frame, text="Select Interface:").grid( row=0, column=0, sticky="w", padx=5 @@ -310,22 +317,23 @@ class IPChangerApp: self.control_frame, text="Current Configuration", padding="5" ) self.current_frame.grid(row=1, column=0, sticky="ew", pady=(0, 10)) + self.current_frame.columnconfigure(1, weight=1) # Make value column expandable self.current_ip_var = tk.StringVar() self.current_mask_var = tk.StringVar() self.current_gateway_var = tk.StringVar() self.dhcp_status_var = tk.StringVar() + # Current IP and copy button - aligned left ttk.Label(self.current_frame, text="Current IP:").grid( row=0, column=0, sticky="w", padx=5 ) - ttk.Label(self.current_frame, textvariable=self.current_ip_var).grid( - row=0, column=1, sticky="w" + ip_frame = ttk.Frame(self.current_frame) + ip_frame.grid(row=0, column=1, sticky="w") + ttk.Label(ip_frame, textvariable=self.current_ip_var).pack(side=tk.LEFT) + ttk.Button(ip_frame, text="Copy", width=5, command=self.copy_current_ip).pack( + side=tk.LEFT, padx=5 ) - # Add copy button for IP - ttk.Button( - self.current_frame, text="Copy", width=5, command=self.copy_current_ip - ).grid(row=0, column=2, padx=5) ttk.Label(self.current_frame, text="Subnet Mask:").grid( row=1, column=0, sticky="w", padx=5 @@ -334,16 +342,18 @@ class IPChangerApp: row=1, column=1, sticky="w" ) + # Gateway and copy button - aligned left ttk.Label(self.current_frame, text="Gateway:").grid( row=2, column=0, sticky="w", padx=5 ) - ttk.Label(self.current_frame, textvariable=self.current_gateway_var).grid( - row=2, column=1, sticky="w" + gateway_frame = ttk.Frame(self.current_frame) + gateway_frame.grid(row=2, column=1, sticky="w") + ttk.Label(gateway_frame, textvariable=self.current_gateway_var).pack( + side=tk.LEFT ) - # Add copy button for Gateway ttk.Button( - self.current_frame, text="Copy", width=5, command=self.copy_current_gateway - ).grid(row=2, column=2, padx=5) + gateway_frame, text="Copy", width=5, command=self.copy_current_gateway + ).pack(side=tk.LEFT, padx=5) ttk.Label(self.current_frame, text="DHCP Status:").grid( row=3, column=0, sticky="w", padx=5 @@ -357,45 +367,52 @@ class IPChangerApp: self.control_frame, text="IP Configuration", padding="5" ) self.ip_frame.grid(row=2, column=0, sticky="ew", pady=(0, 10)) + self.ip_frame.columnconfigure(1, weight=1) # Make IP entry column expandable + # IP Prefix row - all aligned left ttk.Label(self.ip_frame, text="IP Prefix (first 3 octets):").grid( row=0, column=0, sticky="w", padx=5 ) - self.ip_prefix = tk.StringVar(value=self.config.last_ip_prefix) - self.ip_entry = ttk.Entry(self.ip_frame, textvariable=self.ip_prefix, width=30) - self.ip_entry.grid(row=0, column=1, sticky="w", padx=5) + ip_prefix_frame = ttk.Frame(self.ip_frame) + ip_prefix_frame.grid(row=0, column=1, sticky="w", padx=5) - ttk.Label(self.ip_frame, text="Last Octet:").grid( - row=0, column=2, sticky="w", padx=5 + self.ip_prefix = tk.StringVar(value=self.config.last_ip_prefix) + self.ip_entry = ttk.Entry( + ip_prefix_frame, textvariable=self.ip_prefix, width=30 ) + self.ip_entry.pack(side=tk.LEFT) + + ttk.Label(ip_prefix_frame, text="Last Octet:").pack(side=tk.LEFT, padx=5) self.last_octet = tk.StringVar(value="249") self.last_octet_entry = ttk.Entry( - self.ip_frame, textvariable=self.last_octet, width=5 + ip_prefix_frame, textvariable=self.last_octet, width=5 ) - self.last_octet_entry.grid(row=0, column=3, sticky="w", padx=5) + self.last_octet_entry.pack(side=tk.LEFT) - # Add subnet mask configuration + # Subnet mask row - all aligned left ttk.Label(self.ip_frame, text="Subnet Mask:").grid( row=1, column=0, sticky="w", padx=5 ) + subnet_frame = ttk.Frame(self.ip_frame) + subnet_frame.grid(row=1, column=1, sticky="w", padx=5) + self.subnet_mask = tk.StringVar(value="255.255.255.0") self.subnet_entry = ttk.Entry( - self.ip_frame, textvariable=self.subnet_mask, width=15 + subnet_frame, textvariable=self.subnet_mask, width=15 ) - self.subnet_entry.grid(row=1, column=1, sticky="w", padx=5) + self.subnet_entry.pack(side=tk.LEFT) - ttk.Label(self.ip_frame, text="CIDR (/bits):").grid( - row=1, column=2, sticky="w", padx=5 - ) + ttk.Label(subnet_frame, text="CIDR (/bits):").pack(side=tk.LEFT, padx=5) self.cidr_bits = tk.StringVar(value="24") - self.cidr_entry = ttk.Entry(self.ip_frame, textvariable=self.cidr_bits, width=5) - self.cidr_entry.grid(row=1, column=3, sticky="w", padx=5) + self.cidr_entry = ttk.Entry(subnet_frame, textvariable=self.cidr_bits, width=5) + self.cidr_entry.pack(side=tk.LEFT) # Sección de historial self.history_frame = ttk.LabelFrame( self.control_frame, text="IP History", padding="5" ) self.history_frame.grid(row=3, column=0, sticky="ew", pady=(0, 10)) + self.history_frame.columnconfigure(1, weight=1) # Make combo column expandable ttk.Label(self.history_frame, text="Previous IPs:").grid( row=0, column=0, sticky="w", padx=5 @@ -414,6 +431,10 @@ class IPChangerApp: self.button_frame = ttk.Frame(self.control_frame) self.button_frame.grid(row=4, column=0, sticky="ew", pady=(0, 10)) + # Make the button frame distribute buttons evenly + for i in range(4): # For the 4 buttons + self.button_frame.columnconfigure(i, weight=1) + ttk.Button( self.button_frame, text="Set Static IP", command=self.set_static_ip ).grid(row=0, column=0, padx=5) @@ -432,14 +453,20 @@ class IPChangerApp: def create_tools_tab(self): # Control frame for Tools tab self.tools_control_frame = ttk.Frame(self.tools_tab) - self.tools_control_frame.grid(row=0, column=0, sticky="new") + self.tools_control_frame.grid(row=0, column=0, sticky="nsew") self.tools_control_frame.columnconfigure(0, weight=1) + self.tools_control_frame.rowconfigure( + 1, weight=1 + ) # Make the scan frame expandable # Network Tools section (moved from original layout) self.ping_frame = ttk.LabelFrame( self.tools_control_frame, text="Ping Tool", padding="5" ) self.ping_frame.grid(row=0, column=0, sticky="ew", pady=(0, 10)) + self.ping_frame.columnconfigure( + 1, weight=1 + ) # Make ping target field expandable ttk.Label(self.ping_frame, text="Target IP/Host:").grid( row=0, column=0, sticky="w", padx=5 @@ -465,71 +492,77 @@ class IPChangerApp: row=0, column=4, padx=5 ) - # Network Scan section + # Network Scan section - make it expand both horizontally and vertically self.scan_frame = ttk.LabelFrame( self.tools_control_frame, text="Network Scan", padding="5" ) - self.scan_frame.grid(row=1, column=0, sticky="ew", pady=(0, 10)) + self.scan_frame.grid(row=1, column=0, sticky="nsew", pady=(0, 10)) - # Start IP - ttk.Label(self.scan_frame, text="Start IP:").grid( - row=0, column=0, sticky="w", padx=5 - ) + # Configure column weights for scan frame to make it expandable + self.scan_frame.columnconfigure(0, weight=1) # Single column for frames + self.scan_frame.rowconfigure(4, weight=1) # Make results row expandable + + # Use frames to organize elements in a row and aligned left + # Start IP and End IP row + ip_range_frame = ttk.Frame(self.scan_frame) + ip_range_frame.grid(row=0, column=0, sticky="w", padx=5, pady=2) + + ttk.Label(ip_range_frame, text="Start IP:").pack(side=tk.LEFT, padx=(0, 5)) self.scan_start_ip = tk.StringVar() self.scan_start_entry = ttk.Entry( - self.scan_frame, textvariable=self.scan_start_ip, width=15 + ip_range_frame, textvariable=self.scan_start_ip, width=15 ) - self.scan_start_entry.grid(row=0, column=1, sticky="w", padx=5) + self.scan_start_entry.pack(side=tk.LEFT) - # End IP - ttk.Label(self.scan_frame, text="End IP:").grid( - row=0, column=2, sticky="w", padx=5 - ) + ttk.Label(ip_range_frame, text="End IP:").pack(side=tk.LEFT, padx=(10, 5)) self.scan_end_ip = tk.StringVar() self.scan_end_entry = ttk.Entry( - self.scan_frame, textvariable=self.scan_end_ip, width=15 + ip_range_frame, textvariable=self.scan_end_ip, width=15 ) - self.scan_end_entry.grid(row=0, column=3, sticky="w", padx=5) + self.scan_end_entry.pack(side=tk.LEFT) - # Add CIDR field in Network Scan - ttk.Label(self.scan_frame, text="CIDR (/bits):").grid( - row=0, column=4, sticky="w", padx=5 - ) + ttk.Label(ip_range_frame, text="CIDR (/bits):").pack(side=tk.LEFT, padx=(10, 5)) self.scan_cidr_bits = tk.StringVar(value="24") self.scan_cidr_entry = ttk.Entry( - self.scan_frame, textvariable=self.scan_cidr_bits, width=5 + ip_range_frame, textvariable=self.scan_cidr_bits, width=5 ) - self.scan_cidr_entry.grid(row=0, column=5, sticky="w", padx=5) + self.scan_cidr_entry.pack(side=tk.LEFT) # Add trace to update the scan range when CIDR changes self.scan_cidr_bits.trace("w", self.update_scan_range_from_cidr) - # Display number of nodes to scan - ttk.Label(self.scan_frame, text="Nodes to scan:").grid( - row=1, column=0, sticky="w", padx=5 - ) + # Nodes to scan and buttons row + controls_frame = ttk.Frame(self.scan_frame) + controls_frame.grid(row=1, column=0, sticky="ew", padx=5, pady=2) + controls_frame.columnconfigure( + 1, weight=1 + ) # Make space between nodes and buttons expandable + + nodes_frame = ttk.Frame(controls_frame) + nodes_frame.grid(row=0, column=0, sticky="w") + ttk.Label(nodes_frame, text="Nodes to scan:").pack(side=tk.LEFT, padx=(0, 5)) self.nodes_to_scan = tk.StringVar(value="0") nodes_display = ttk.Entry( - self.scan_frame, textvariable=self.nodes_to_scan, width=10, state="readonly" + nodes_frame, textvariable=self.nodes_to_scan, width=10, state="readonly" ) - nodes_display.grid(row=1, column=1, sticky="w", padx=5) + nodes_display.pack(side=tk.LEFT) - # Scan buttons - move to row 1, column 2-5 - self.scan_buttons_frame = ttk.Frame(self.scan_frame) - self.scan_buttons_frame.grid(row=1, column=2, columnspan=4, padx=5, sticky="e") + # Scan buttons - aligned right + self.scan_buttons_frame = ttk.Frame(controls_frame) + self.scan_buttons_frame.grid(row=0, column=1, sticky="e") ttk.Button( self.scan_buttons_frame, text="Start Scan", command=self.start_scan - ).grid(row=0, column=0, padx=5) + ).pack(side=tk.LEFT, padx=5) ttk.Button( self.scan_buttons_frame, text="Stop Scan", command=self.stop_scan - ).grid(row=0, column=1, padx=5) + ).pack(side=tk.LEFT, padx=5) ttk.Button( self.scan_buttons_frame, text="Get Host Info", command=self.gather_host_information, - ).grid(row=0, column=2, padx=5) + ).pack(side=tk.LEFT, padx=5) - # Scan progress - move to row 2 + # Scan progress - keep full width and make it expand horizontally self.scan_progress = ttk.Progressbar( self.scan_frame, orient="horizontal", @@ -537,24 +570,20 @@ class IPChangerApp: mode="determinate", variable=self.scan_progress_var, ) - self.scan_progress.grid( - row=2, column=0, columnspan=6, sticky="ew", padx=5, pady=5 - ) + self.scan_progress.grid(row=2, column=0, sticky="ew", padx=5, pady=5) - # Scan results - update row numbers + # Scan results - keep full width ttk.Label(self.scan_frame, text="Scan Results:").grid( row=3, column=0, sticky="w", padx=5 ) - # Frame for results list and scrollbar + # Frame for results list and scrollbar - make it fully expandable self.results_frame = ttk.Frame(self.scan_frame) - self.results_frame.grid( - row=4, column=0, columnspan=6, sticky="nsew", padx=5, pady=5 - ) + self.results_frame.grid(row=4, column=0, sticky="nsew", padx=5, pady=5) self.results_frame.columnconfigure(0, weight=1) self.results_frame.rowconfigure(0, weight=1) - # Replace Listbox with Treeview that has columns + # Replace Listbox with Treeview that has columns - make sure it expands self.scan_results_tree = ttk.Treeview( self.results_frame, columns=("ip", "hostname", "mac", "vendor"), # Add vendor column @@ -571,12 +600,19 @@ class IPChangerApp: ) # Add vendor heading # Set column widths - self.scan_results_tree.column("ip", width=120, anchor="w") - self.scan_results_tree.column("hostname", width=200, anchor="w") - self.scan_results_tree.column("mac", width=150, anchor="w") + total_width = 650 # Base total width for the columns self.scan_results_tree.column( - "vendor", width=180, anchor="w" - ) # Add vendor column width + "ip", width=int(total_width * 0.18), anchor="w", stretch=True + ) + self.scan_results_tree.column( + "hostname", width=int(total_width * 0.30), anchor="w", stretch=True + ) + self.scan_results_tree.column( + "mac", width=int(total_width * 0.22), anchor="w", stretch=True + ) + self.scan_results_tree.column( + "vendor", width=int(total_width * 0.30), anchor="w", stretch=True + ) # Add scrollbar self.scan_results_scrollbar = ttk.Scrollbar( @@ -584,14 +620,10 @@ class IPChangerApp: ) self.scan_results_tree.configure(yscrollcommand=self.scan_results_scrollbar.set) + # Make sure the treeview fills the available space self.scan_results_tree.grid(row=0, column=0, sticky="nsew") self.scan_results_scrollbar.grid(row=0, column=1, sticky="ns") - # Configure scan frame to expand - self.scan_frame.columnconfigure(1, weight=1) - self.scan_frame.columnconfigure(3, weight=1) - self.scan_frame.rowconfigure(3, weight=1) - def clear_log(self): self.log_text.delete("1.0", tk.END)