Skip to content

Commit

Permalink
Update calculator.py
Browse files Browse the repository at this point in the history
Add function to export to clip board
  • Loading branch information
MootSeeker committed Sep 10, 2024
1 parent 9cccb26 commit 595e260
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def treeview_sort_column(tv, col, reverse):

tv.heading(col, command=lambda: treeview_sort_column(tv, col, not reverse))

## @brief Function to copy the results to the clipboard.
def copy_to_clipboard():
"""Copies the Treeview results to the clipboard."""
clipboard_content = ""
# Get all rows in the Treeview
for row in tree.get_children():
values = tree.item(row)["values"]
row_text = "\t".join([str(value) for value in values]) + "\n"
clipboard_content += row_text

# Copy to clipboard
root.clipboard_clear()
root.clipboard_append(clipboard_content)
root.update() # now it stays on the clipboard after the window is closed

## @brief Function to perform battery lifetime calculations and display results in the Treeview.
def calculate_battery_life():
"""Calculates battery life for various modes and displays the filtered results."""
Expand Down Expand Up @@ -383,6 +398,9 @@ def exit_app():
exit_button = tk.Button(frame_buttons, text="Exit", command=exit_app)
exit_button.grid(row=0, column=1, padx=5)

# Copy to Clipboard button
copy_button = tk.Button(frame_buttons, text="Export to Clipboard", command=copy_to_clipboard)
copy_button.grid(row=0, column=2, padx=5)

# Frame to contain the Treeview and Scrollbars
frame_tree = tk.Frame(root)
Expand Down

0 comments on commit 595e260

Please sign in to comment.