Skip to content

Commit 506c6ba

Browse files
Add tooltips
1 parent b502d06 commit 506c6ba

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

gui.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
1616
"""
1717

18-
# TODO: Add tooltips
19-
2018
import tkinter as tk
2119
from tkinter import ttk
2220
from tkinter import messagebox as mbox
@@ -134,6 +132,16 @@ def show_traceback(self) -> bool:
134132
except AttributeError:
135133
return False
136134

135+
def add_tooltip(self, widget: tk.Widget, text: str) -> None:
136+
"""
137+
Add a tooltip to a widget.
138+
139+
:param widget: The widget to add to.
140+
:param text: The text in the tooltip.
141+
:return: None.
142+
"""
143+
tooltip.Hovertip(anchor_widget=widget, text=text)
144+
137145
def create_config(self) -> None:
138146
"""
139147
Re-create the config keys if they do not exist.
@@ -283,9 +291,11 @@ def create_new_project_location(self) -> None:
283291
textvariable=self.project_location_var, width=51)
284292
self.project_location_entry.initiate_right_click_menu()
285293
self.project_location_entry.grid(row=0, column=1, padx=1, pady=1, sticky=tk.NW)
294+
self.add_tooltip(self.project_location_entry, "Where to put the new project.")
286295
self.project_location_button = ttk.Button(master=self.project_location_frame, text="Browse...",
287296
command=self.open_new_project_directory)
288297
self.project_location_button.grid(row=0, column=2, padx=1, pady=0, sticky=tk.NW)
298+
self.add_tooltip(self.project_location_button, "Launch the directory selector.")
289299

290300
def create_new_project_details(self) -> None:
291301
"""
@@ -301,10 +311,12 @@ def create_new_project_details(self) -> None:
301311
self.project_title_entry = EntryWithRightClick(master=self.project_details_frame, width=40, textvariable=self.project_title_var)
302312
self.project_title_entry.initiate_right_click_menu()
303313
self.project_title_entry.grid(row=0, column=1, padx=1, pady=1, sticky=tk.NW)
314+
self.add_tooltip(self.project_title_entry, "The title of the project.")
304315
self.project_autogen_var = tk.BooleanVar(value=True)
305316
self.project_autogen_checkbox = ttk.Checkbutton(master=self.project_details_frame, text="Auto-generate a .gitignore",
306317
variable=self.project_autogen_var)
307318
self.project_autogen_checkbox.grid(row=0, column=2, padx=1, pady=1, sticky=tk.NW)
319+
self.add_tooltip(self.project_autogen_checkbox, "Whether to auto-generate a .gitignore file for the Git VCS.")
308320
self.project_description_label = ttk.Label(master=self.project_details_frame, text="Project description: ")
309321
self.project_description_label.grid(row=1, column=0, columnspan=3, padx=1, pady=1, sticky=tk.NW)
310322
self.project_description_text = TextWithRightClick(master=self.project_details_frame, width=60, height=10)
@@ -352,9 +364,11 @@ def create_new_project_buttons(self) -> None:
352364
self.make_new_project_button = ttk.Button(master=self.project_buttons_frame, text="Make new project",
353365
command=self.start_create_new_project_thread)
354366
self.make_new_project_button.grid(row=0, column=0, padx=1, pady=1, sticky=tk.N)
367+
self.add_tooltip(self.make_new_project_button, "Make a new project.")
355368
self.cancel_new_project_button = ttk.Button(master=self.project_buttons_frame, text="Cancel",
356369
command=lambda: self.dismiss_dialog(self.new_project_window))
357370
self.cancel_new_project_button.grid(row=0, column=1, padx=1, pady=1, sticky=tk.N)
371+
self.add_tooltip(self.cancel_new_project_button, "Close this dialog without creating a new project.")
358372
self.update_new_project_buttons()
359373

360374
def set_childrens_state(self, frame, enabled: bool = True) -> None:
@@ -661,6 +675,7 @@ def make_title(self, title: str) -> None:
661675
self.title_entry = EntryWithRightClick(master=self.title_frame, width=29, textvariable=self.title_var)
662676
self.title_entry.initiate_right_click_menu()
663677
self.title_entry.grid(row=0, column=1, padx=1, pady=1, sticky=tk.NW)
678+
self.add_tooltip(self.title_entry, "The title of the opened project.")
664679

665680
def make_description(self, description: str) -> None:
666681
"""
@@ -677,6 +692,8 @@ def make_description(self, description: str) -> None:
677692
self.description_text.initiate_right_click_menu()
678693
self.description_text.grid(row=1, column=0, padx=1, pady=1, sticky=tk.NW)
679694
self.description_text.insert("1.0", description)
695+
# TODO: Tooltips for text doesn't work
696+
self.add_tooltip(self.description_text, "The description of the opened project.")
680697

681698
def update_drives(self) -> None:
682699
"""
@@ -713,12 +730,15 @@ def make_drive_selector(self, drive: Path) -> None:
713730
self.drive_selector_combobox = ComboboxWithRightClick(master=self.drive_selector_frame, width=48, textvariable=self.drive_selector_var)
714731
self.drive_selector_combobox.initiate_right_click_menu()
715732
self.drive_selector_combobox.grid(row=0, column=1, padx=1, pady=1, sticky=tk.NW)
733+
self.add_tooltip(self.drive_selector_combobox, "The CircuitPython device to sync to.")
716734
self.drive_selector_refresh_btn = ttk.Button(master=self.drive_selector_frame, text="↻", width=2, command=self.update_drives)
717735
self.drive_selector_refresh_btn.grid(row=0, column=2, padx=1, pady=0, sticky=tk.NW)
736+
self.add_tooltip(self.drive_selector_refresh_btn, "Refresh the list of connected drives.")
718737
self.drive_selector_show_all_var = tk.BooleanVar(value=False)
719738
self.drive_selector_show_all_checkbtn = ttk.Checkbutton(master=self.drive_selector_frame, text="Show all drives?",
720739
variable=self.drive_selector_show_all_var, command=self.update_drives)
721740
self.drive_selector_show_all_checkbtn.grid(row=0, column=3, padx=1, pady=1, sticky=tk.NW)
741+
self.add_tooltip(self.drive_selector_show_all_checkbtn, "Whether to show all drives in the list of connected drives instead of just CircuitPython drives.")
722742
self.update_drives()
723743

724744
def update_listbox_context(self):
@@ -752,6 +772,7 @@ def make_file_sync_listbox(self, to_sync: list[str], project_root: Path) -> None
752772
self.to_sync_listbox.right_click_menu.add_command(label="Add file", command=self.add_file_to_sync)
753773
self.to_sync_listbox.right_click_menu.add_command(label="Add directory", command=self.add_directory_to_sync)
754774
self.to_sync_listbox.grid(row=1, column=0, padx=1, pady=1, sticky=tk.NW)
775+
self.add_tooltip(self.to_sync_listbox, "The files and directories to sync to the CircuitPython device.")
755776
self.to_sync_scrollbar = ttk.Scrollbar(master=self.to_sync_frame, command=self.to_sync_listbox.yview)
756777
self.to_sync_scrollbar.grid(row=1, column=1, padx=0, pady=1, sticky=tk.NSEW)
757778
self.to_sync_listbox.config(yscrollcommand=self.to_sync_scrollbar.set)
@@ -862,12 +883,15 @@ def make_file_sync_buttons(self) -> None:
862883
self.to_sync_add_file_btn = ttk.Button(master=self.right_frame, text="Add file", width=12,
863884
command=self.add_file_to_sync)
864885
self.to_sync_add_file_btn.grid(row=0, column=0, padx=1, pady=1, sticky=tk.NW)
886+
self.add_tooltip(self.to_sync_add_file_btn, "Add a new file via the file selector.")
865887
self.to_sync_add_directory_btn = ttk.Button(master=self.right_frame, text="Add directory",
866888
command=self.add_directory_to_sync)
867889
self.to_sync_add_directory_btn.grid(row=1, column=0, padx=1, pady=1, sticky=tk.NW)
890+
self.add_tooltip(self.to_sync_add_directory_btn, "Add a new directory via the directory selector.")
868891
self.to_sync_remove_btn = ttk.Button(master=self.right_frame, text="Remove", width=12,
869892
command=self.remove_thing_to_sync)
870893
self.to_sync_remove_btn.grid(row=2, column=0, padx=1, pady=1, sticky=tk.NW)
894+
self.add_tooltip(self.to_sync_remove_btn, "Remove a file/directory from being synced.")
871895
self.update_file_sync_buttons()
872896

873897
def save_modified(self) -> None:
@@ -975,10 +999,13 @@ def make_save_and_sync_buttons(self) -> None:
975999
"""
9761000
self.save_config_btn = ttk.Button(master=self.right_frame, text="Save", width=12, command=self.save_modified)
9771001
self.save_config_btn.grid(row=4, column=0, padx=1, pady=1, sticky=tk.NW)
1002+
self.add_tooltip(self.save_config_btn, "Save the .cpypmconfig file to disk.")
9781003
self.discard_config_btn = ttk.Button(master=self.right_frame, text="Discard", width=12, command=self.discard_modified)
9791004
self.discard_config_btn.grid(row=5, column=0, padx=1, pady=1, sticky=tk.NW)
1005+
self.add_tooltip(self.discard_config_btn, "Discard changes and reload the .cpypmconfig file from disk")
9801006
self.sync_files_btn = ttk.Button(master=self.right_frame, text="Sync", width=12, command=self.start_sync_thread)
9811007
self.sync_files_btn.grid(row=6, column=0, padx=1, pady=1, sticky=tk.NW)
1008+
self.add_tooltip(self.sync_files_btn, "Sync the files to the CircuitPython drive.")
9821009
self.check_sync_buttons()
9831010

9841011
def update_main_gui(self) -> None:

0 commit comments

Comments
 (0)