-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
104 lines (80 loc) · 3.08 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import logging
import queue
import importlib
import pkgutil
import tkinter as tk
from PIL import Image
from imageloader import ImageLoader
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.floater = FloatingWindow(self)
self.withdraw()
class FloatingWindow(tk.Toplevel):
def __init__(self, *args, **kwargs):
tk.Toplevel.__init__(self, *args, **kwargs)
self.app = args[0]
self.overrideredirect(True)
self.geometry("+450+450")
self.wm_attributes("-topmost", True)
self.wm_attributes("-transparentcolor", "brown")
self.image = ImageLoader('ghost.yaml')
self.grip = tk.Canvas(self, width=450+450, height=1000, background="brown", bd=0, highlightthickness=0, relief='ridge')
self.config = dict(
exit_initiated=False,
voice_enabled=tk.BooleanVar()
)
self.config['voice_enabled'].set(True)
self.dialogue_queue = queue.Queue()
self.voice_queue = queue.Queue()
self._plugins_modules = {
name: importlib.import_module('.' + name, package='plugins')
for finder, name, ispkg
in pkgutil.iter_modules(path=['plugins'])
}
self.plugins = {
name: plugin.Plugin(self, 'ghost.yaml') for name, plugin in self._plugins_modules.items()
}
self.menu = tk.Menu(self, tearoff=0)
self.menu.add_command(label="Next expression", command=self.plugins['expression_plugin'].random_tick)
self.menu.add_command(label="Show dialogue", command=self.plugins['random_dialogue_plugin']._say)
config_menu = tk.Menu(self.menu)
config_menu.add_checkbutton(label="Voice Enabled", onvalue=1, offvalue=0, variable=self.config['voice_enabled'])
self.menu.add_cascade(label='Configuration', menu=config_menu)
self.menu.add_separator()
self.menu.add_command(label="Exit", command=lambda: self.menu_callback("exit"))
self.grip.bind("<ButtonPress-1>", self.left_press)
self.grip.bind("<ButtonPress-3>", self.right_press)
self.grip.bind("<ButtonRelease-1>", self.left_release)
self.grip.bind("<B1-Motion>", self.do_move)
@staticmethod
def RBGAImage(path):
return Image.open(path).convert("RGBA")
def left_press(self, event):
self.x = event.x
self.y = event.y
def right_press(self, event):
try:
self.menu.tk_popup(event.x_root, event.y_root)
finally:
self.menu.grab_release()
def menu_callback(self, element):
if element == "exit":
self.do_exit()
else:
raise
def left_release(self, event):
self.x = None
self.y = None
def do_move(self, event):
deltax = event.x - self.x
deltay = event.y - self.y
x = self.winfo_x() + deltax
y = self.winfo_y() + deltay
self.geometry(f"+{x}+{y}")
def do_exit(self):
self.config['exit_initiated'] = True
self.app.destroy()
logging.basicConfig(level=logging.DEBUG)
app=App()
app.mainloop()