mirror of
https://github.com/maglore9900/max_headroom.git
synced 2025-06-04 10:30:24 +00:00
added a new timer with clippy
This commit is contained in:
parent
6098d4877d
commit
649d242f51
BIN
images/clippy.png
Normal file
BIN
images/clippy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -107,7 +107,7 @@ class Agent:
|
||||
return ""
|
||||
|
||||
@tool("set_timer")
|
||||
async def set_timer(self, time: str):
|
||||
async def set_timer(self, time: int):
|
||||
"""Sets a timer for the user
|
||||
Use this tool when the user says 'set timer' or similar words in their query.
|
||||
convert the user provided time to seconds
|
||||
@ -159,7 +159,7 @@ class Agent:
|
||||
command = (lambda x: x.get('time') or x.get('self'))(tool_action.tool_input)
|
||||
if not command:
|
||||
raise ValueError("No valid command found in tool_input")
|
||||
subprocess.run(["python", "modules/timer.py", str(command)], shell=True)
|
||||
subprocess.Popen(["python", "modules/timer_clippy.py", str(command)], shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
@ -295,6 +295,7 @@ class Agent:
|
||||
print(f"answer: {agent_out}")
|
||||
if "ToolAgentAction" not in str(agent_out):
|
||||
return agent_out
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
modules/clippy.png
Normal file
BIN
modules/clippy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 650 KiB |
BIN
modules/clippy2.png
Normal file
BIN
modules/clippy2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
106
modules/timer_clippy.py
Normal file
106
modules/timer_clippy.py
Normal file
@ -0,0 +1,106 @@
|
||||
import time
|
||||
import argparse
|
||||
import tkinter as tk
|
||||
from PIL import Image, ImageTk, ImageDraw, ImageFont
|
||||
|
||||
text_to_add = "I see you are just sitting there, would you like to get the F up?!"
|
||||
def wrap_text(text, font, max_width, draw):
|
||||
"""
|
||||
Wrap the text so that it fits within the given max_width.
|
||||
"""
|
||||
words = text.split(' ')
|
||||
lines = []
|
||||
current_line = []
|
||||
current_width = 0
|
||||
|
||||
for word in words:
|
||||
# Calculate the width of the word using textbbox
|
||||
word_width = draw.textbbox((0, 0), word + ' ', font=font)[2] - draw.textbbox((0, 0), word + ' ', font=font)[0]
|
||||
|
||||
if current_width + word_width <= max_width:
|
||||
current_line.append(word)
|
||||
current_width += word_width
|
||||
else:
|
||||
lines.append(' '.join(current_line))
|
||||
current_line = [word]
|
||||
current_width = word_width
|
||||
lines.append(' '.join(current_line)) # Add the last line
|
||||
|
||||
return '\n'.join(lines)
|
||||
|
||||
def start_timer(seconds):
|
||||
seconds = int(seconds)
|
||||
print(f"Timer started for {seconds} seconds...")
|
||||
time.sleep(seconds)
|
||||
|
||||
# Create the root window and remove the title bar
|
||||
root = tk.Tk()
|
||||
root.overrideredirect(1) # Remove title bar
|
||||
root.attributes("-topmost", True) # Keep window on top of others
|
||||
|
||||
# Get the screen width and height
|
||||
screen_width = root.winfo_screenwidth()
|
||||
screen_height = root.winfo_screenheight()
|
||||
|
||||
# Load the image
|
||||
image = Image.open("images/clippy.png") # Replace with your image path
|
||||
|
||||
# Initialize ImageDraw to modify the image
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
# Load a font. You can use default fonts or specify your own .ttf file.
|
||||
try:
|
||||
font = ImageFont.truetype("tahoma.ttf", 24) # You can replace this with any font available on your system
|
||||
except IOError:
|
||||
font = ImageFont.load_default() # Fallback to default if font not found
|
||||
|
||||
# Get the width and height of the image
|
||||
img_width, img_height = image.size
|
||||
|
||||
# Set a maximum text width to allow word wrapping
|
||||
max_text_width = img_width - 40 # Padding of 20px on each side
|
||||
|
||||
# Wrap the text to fit within the max_text_width
|
||||
wrapped_text = wrap_text(text_to_add, font, max_text_width, draw)
|
||||
|
||||
# Add padding for the text position
|
||||
text_x = 20 # Left alignment padding
|
||||
text_y = img_height // 2 - 130 # Higher position for the text
|
||||
|
||||
# Add wrapped text to the image (left-aligned)
|
||||
draw.text((text_x, text_y), wrapped_text, font=font, fill="black", align="left")
|
||||
|
||||
# Convert the image to a format Tkinter can display
|
||||
photo = ImageTk.PhotoImage(image)
|
||||
|
||||
# Display image with text
|
||||
label_image = tk.Label(root, image=photo)
|
||||
label_image.pack()
|
||||
|
||||
# Add a wider close button ("X")
|
||||
close_button = tk.Button(root, text=" X ", command=root.destroy, bg="red", fg="white", bd=0) # Extra spaces for width
|
||||
close_button.place(relx=1.0, rely=0.0, anchor="ne")
|
||||
|
||||
# Define padding for bottom-right position (e.g., 20px padding)
|
||||
padding_x = 20
|
||||
padding_y = 70
|
||||
|
||||
# Calculate position to place window in the bottom-right of the screen with padding
|
||||
window_x = screen_width - img_width - padding_x
|
||||
window_y = screen_height - img_height - padding_y
|
||||
|
||||
# Position the window at the bottom-right corner with padding
|
||||
root.geometry(f"{img_width}x{img_height}+{window_x}+{window_y}")
|
||||
|
||||
# Auto-close the window after 5 seconds if not closed manually
|
||||
root.after(5000, root.destroy)
|
||||
|
||||
# Run the main loop to display the window and handle events
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Simple Timer Script")
|
||||
parser.add_argument("seconds", type=int, help="Number of seconds to set the timer for")
|
||||
args = parser.parse_args()
|
||||
|
||||
start_timer(args.seconds)
|
4168
tmp/app_index.json
4168
tmp/app_index.json
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user