-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
executable file
·131 lines (118 loc) · 4.43 KB
/
gui.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""
App GUI module
"""
import threading
import time
import tkinter as tk
import utils
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.status = True
self.xposition = None
self.yposition = None
self.master.resizable(False, False)
self.master.attributes("-topmost", True)
self.master.wm_withdraw()
self.master.overrideredirect(True)
self.master.bind("<Motion>", lambda *ignore: self.set_status(True))
self.master.bind("<Leave>", lambda *ignore: self.set_status(False))
self.create_buttons()
self.start_thread()
self.pack()
def set_status(self, status: bool):
self.status = status
def hide(self):
self.master.wm_withdraw()
self.xposition = None
self.yposition = None
self.status = True
def start_thread(self):
def to_check():
while True:
# to hide the app
status = self.status
if status is False:
time.sleep(1)
if status == self.status:
self.hide()
if self.xposition and self.yposition:
cursor_position = utils.get_mouse_cursor_position()
xdifference = abs(cursor_position.x - self.xposition)
ydifference = abs(cursor_position.y - self.yposition)
if xdifference > 300 or ydifference > 250:
self.hide()
# detect change of selected text
if utils.detect_selected_text_changed():
cursor_position = utils.get_mouse_cursor_position()
app_wsize = utils.Size(250, 35)
x, y = utils.get_cursor_position_to_set(app_wsize, cursor_position)
self.master.geometry(f"+{x}+{y}")
self.xposition = x
self.yposition = y
self.master.wm_deiconify()
thread = threading.Thread(target=to_check, daemon=True)
thread.start()
def create_buttons(self):
common_options = dict(
borderwidth=0,
anchor="w",
background="#4f6481",
activebackground="#153158",
foreground="white",
activeforeground="white"
)
self.title_button = tk.Button(
self,
text="AbC",
command=lambda: utils.concatenate_functions_calls(utils.title_converter(), utils.call_to_paste(), self.hide()),
**common_options
)
self.after_period_capitalize_button = tk.Button(
self,
text="Ab.C",
command=lambda: utils.concatenate_functions_calls(utils.capitalize_after_one_periodconverter(), utils.call_to_paste(),
self.hide()),
**common_options
)
self.uppercase_button = tk.Button(
self,
text="A",
command=lambda: utils.concatenate_functions_calls(utils.upper_converter(), utils.call_to_paste(), self.hide()),
**common_options
)
self.lowercase_button = tk.Button(
self,
text="a",
command=lambda: utils.concatenate_functions_calls(utils.lower_converter(), utils.call_to_paste(), self.hide()),
**common_options
)
self.capitalize_button = tk.Button(
self,
text="Ab",
command=lambda: utils.concatenate_functions_calls(utils.capitalizer_converter(), utils.call_to_paste(), self.hide()),
**common_options
)
self.close_button = tk.Button(
self,
text="X",
command=self.master.destroy,
borderwidth=0,
anchor="w",
foreground="white",
activebackground="#fd5454",
background="#fd5454",
activeforeground="white"
)
self.close_button.pack(side="right")
self.after_period_capitalize_button.pack(side="right")
self.title_button.pack(side="right")
self.capitalize_button.pack(side="right")
self.lowercase_button.pack(side="right")
self.uppercase_button.pack(side="right")
if __name__ == "__main__":
root = tk.Tk()
app = Application(master=root)
app.mainloop()