This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from Shirros/desktop-pet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (45 loc) · 1.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tkinter as tk
import json
from pet import Pet, PetState
from os.path import join
import sys
if len(sys.argv) >= 2:
CONFIG_PATH = sys.argv[1]
else:
CONFIG_PATH = "assets\\cave_chaos\\"
def create_event_func(event, pet):
if event["type"] == "state_change":
return lambda e: pet.set_state(event["new_state"])
elif event["type"] == "ollama":
return lambda e: pet.start_chat(event["system_message"], event["listen_state"], event["response_state"],
event["end_state"])
def update():
frame = pet.next_frame()
label.configure(image=frame)
window.geometry(
f'{pet.current_state.w}x{pet.current_state.h}+{pet.x + pet.current_state.ox}+{pet.y + pet.current_state.oy}')
window.after(100, update)
if __name__ == "__main__":
window = tk.Tk()
with open(join(CONFIG_PATH, "config.json")) as config:
config_obj = json.load(config)
states = {state['state_name']: PetState(state, CONFIG_PATH) for state in config_obj["states"]}
# Validate
for state in states.values():
for state in state.next_states.names:
assert state in states
pet = Pet(states, window)
for event in config_obj["events"]:
event_func = create_event_func(event, pet)
if event["trigger"] == "right-click":
window.bind("<Button-3>", event_func)
elif event["trigger"] == "left-click":
window.bind("<Button-1>", event_func)
# window configuration
window.config(highlightbackground='black')
label = tk.Label(window, bd=0, bg='black')
window.overrideredirect(True)
window.wm_attributes('-transparentcolor', 'black')
label.pack()
window.after(1, update)
window.mainloop()