Change the border color of the window to green: def showstats(self): """Display stats…
- User
Change the border color of the window to green: def show_stats(self): """Display stats about the boolean columns in a menu-like popup with a table.""" table_name = self.app.current_table_name if not table_name: messagebox.showwarning("No Table Selected", "Please select a table to view stats.") return
if not self.app.current_sheet: messagebox.showwarning("No Data", "No data available to show stats.") return data = self.app.current_sheet.get_sheet_data() current_headers = self.app.current_sheet.headers() data_types = self.app.data_manager.tables_data[table_name].get("data_types", []) while len(data_types) < len(current_headers): data_types.append('string') total_rows = len(data) boolean_columns = [] for col_idx, dtype in enumerate(data_types): if dtype == 'boolean': header = current_headers[col_idx] column_data = [bool(row[col_idx]) if row[col_idx] is not None else False for row in data] true_count = sum(1 for val in column_data if val is True) false_count = sum(1 for val in column_data if val is False) boolean_columns.append((header, true_count, false_count)) if hasattr(self, 'stats_popup') and self.stats_popup.winfo_exists(): self.stats_popup.destroy() self.stats_popup = tk.Toplevel(self.root) self.stats_popup.overrideredirect(True) self.stats_popup.config(bg=self.colors["background"]) border_width = 1 border_color = self.colors.get("menu_border", "black") self.stats_popup.config(highlightthickness=border_width, highlightbackground=border_color) content_frame = tk.Frame(self.stats_popup, bg=self.colors["background"]) content_frame.pack(padx=5, pady=5) total_label = tk.Label( content_frame, text=f"Total: {total_rows}", bg=self.colors["background"], fg=self.colors["text"], font=self.fonts["text"] ) total_label.pack(pady=(0, 5), anchor='center') separator = tk.Frame(content_frame, bg=self.colors["header_info"], height=1) separator.pack(fill=tk.X, pady=(0, 5)) if boolean_columns: table_frame = tk.Frame(content_frame, bg=self.colors["background"]) table_frame.pack() headers = ["Column", "True", "False"] for col_num, header_text in enumerate(headers): header_label = tk.Label( table_frame, text=header_text, bg=self.colors["background"], fg=self.colors["text"], font=self.fonts["text"] ) header_label.grid(row=0, column=col_num, padx=10, pady=2, sticky='w') for row_num, (header, true_count, false_count) in enumerate(boolean_columns, start=1): header_label = tk.Label( table_frame, text=header, bg=self.colors["background"], fg=self.colors["header_info"], font=self.fonts["text"] ) header_label.grid(row=row_num, column=0, padx=10, pady=2, sticky='w') true_label = tk.Label( table_frame, text=str(true_count), bg=self.colors["background"], fg=self.colors["header_info"], font=self.fonts["text"] ) true_label.grid(row=row_num, column=1, padx=10, pady=2, sticky='w') false_label = tk.Label( table_frame, text=str(false_count), bg=self.colors["background"], fg=self.colors["header_info"], font=self.fonts["text"] ) false_label.grid(row=row_num, column=2, padx=10, pady=2, sticky='w') for col_num in range(3): table_frame.grid_columnconfigure(col_num, weight=1) else: no_data_label = tk.Label( content_frame, text="No boolean columns to display.", bg=self.colors["background"], fg=self.colors["text"], font=self.fonts["text"] ) no_data_label.pack(pady=10) self.stats_popup.update_idletasks() popup_width = self.stats_popup.winfo_width() popup_height = self.stats_popup.winfo_height() screen_width = self.root.winfo_screenwidth() screen_height = self.root.winfo_screenheight() menu_x = self.root.winfo_pointerx() menu_y = self.root.winfo_pointery() padding = 10 if menu_x + popup_width > screen_width - padding: menu_x = screen_width - popup_width - padding if menu_y + popup_height > screen_height - padding: menu_y = screen_height - popup_height - padding menu_x = max(padding, menu_x) menu_y = max(padding, menu_y) self.stats_popup.geometry(f"+{menu_x}+{menu_y}") def close_popup(event=None): if self.stats_popup.winfo_exists(): self.stats_popup.destroy() self.root.unbind("<Button-1>", self.click_outside_popup) self.root.unbind("<Configure>", self.window_resized) def click_outside_popup(event): if not str(event.widget).startswith(str(self.stats_popup)): close_popup() self.click_outside_popup = self.root.bind("<Button-1>", click_outside_popup) self.window_resized = self.root.bind("<Configure>", lambda e: close_popup()) self.stats_popup.bind("<FocusOut>", close_popup) self.stats_popup.bind("<Escape>", close_popup) self.stats_popup.focus_force() - Assistant