Skip to content

Commit 7956acc

Browse files
committed
reordering stuff in a table
1 parent 79ec7dc commit 7956acc

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

menus.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def select_microcontroller(self, microcontroller_name):
154154
messagebox.showinfo("Microcontroller Selected", f"{microcontroller_name} has been selected.")
155155

156156
def show_correspondence_table(self):
157-
"""Displays the correspondence table between pin_io objects and microcontroller pins."""
157+
"""Displays the correspondence table between pin_io objects and microcontroller pins in a table format."""
158158
if self.selected_microcontroller is None:
159159
messagebox.showwarning("No Microcontroller Selected", "Please select a microcontroller first.")
160160
return
@@ -188,21 +188,41 @@ def show_correspondence_table(self):
188188
)
189189
return
190190

191-
# Generate the correspondence table
192-
correspondence = []
191+
# Create a new window for the correspondence table
192+
table_window = tk.Toplevel(self.parent)
193+
table_window.title("Correspondence Table")
194+
table_window.geometry("400x300")
195+
196+
# Create a Treeview widget for the table
197+
tree = ttk.Treeview(table_window, columns=("ID", "Type", "MCU Pin"), show="headings", height=10)
198+
tree.pack(expand=True, fill="both", padx=10, pady=10)
199+
200+
# Define columns and headings
201+
tree.column("ID", anchor="center", width=120)
202+
tree.column("Type", anchor="center", width=80)
203+
tree.column("MCU Pin", anchor="center", width=120)
204+
tree.heading("ID", text="Pin IO ID")
205+
tree.heading("Type", text="Type")
206+
tree.heading("MCU Pin", text="MCU Pin")
207+
208+
# Populate the table with input and output pin mappings
193209
for idx, pin_io in enumerate(input_pin_ios):
194210
mcu_pin = input_pins[idx]
195-
correspondence.append(f"{pin_io['id']} (Input) --> MCU Pin {mcu_pin}")
211+
tree.insert("", "end", values=(pin_io["id"], "Input", mcu_pin))
196212

197213
for idx, pin_io in enumerate(output_pin_ios):
198214
mcu_pin = output_pins[idx]
199-
correspondence.append(f"{pin_io['id']} (Output) --> MCU Pin {mcu_pin}")
215+
tree.insert("", "end", values=(pin_io["id"], "Output", mcu_pin))
216+
217+
# Add a scrollbar if the list gets too long
218+
scrollbar = ttk.Scrollbar(table_window, orient="vertical", command=tree.yview)
219+
tree.configure(yscroll=scrollbar.set)
220+
scrollbar.pack(side="right", fill="y")
200221

201-
# Display the correspondence table
202-
table_text = "\n".join(correspondence)
203-
print("Correspondence Table:\n", table_text)
204-
# Show in a message box or create a new window
205-
messagebox.showinfo("Correspondence Table", table_text)
222+
# Show the table in the new window
223+
table_window.transient(self.parent) # Set to be on top of the parent window
224+
table_window.grab_set() # Prevent interaction with the main window until closed
225+
table_window.mainloop()
206226

207227
def create_menu(self, menu_name, options, menu_commands):
208228
"""

0 commit comments

Comments
 (0)