-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotkey_text_changer.py
executable file
·96 lines (78 loc) · 2.55 KB
/
hotkey_text_changer.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from Tkinter import *
import function_loader
import sys
from changers import *
class MainWindow:
def __init__(self, modules_path):
self.root = Tk()
self.root.geometry("130x500+900+200")
self.count = 0
self.modules_path = modules_path
self.func_loader = function_loader.FunctionStorage()
# Add listbox for user. TODO: set size of listbox to fill full window
self.listbox = Listbox(self.root, width=900, height=900)
self.listbox.pack()
[self.listbox.insert(END, data_string)
for data_string in self.func_loader.get_commands_visable_data()]
# init hotkeys
[self.root.bind_all("<" + key + ">", self.hotkey_reaction)
for key in self.func_loader.get_all_hotkeys()]
self.root.mainloop()
def hotkey_reaction(self, event):
result_str = ''
try:
geted_str = self.root.clipboard_get()
function = self.func_loader.find_command_by_key(event.char)
result_str = function(geted_str)
self.root.clipboard_clear()
self.root.clipboard_append(result_str)
except:
result_str = 'Nothing to show!'
self.create_hint(result_str)
# We want to quit programm when work is done. Don't really shure thats
# leave it here or not. Problem is - after end of work clipboard make clear
# and we can't use changed string.
#self.root.after(6000, self.root.destroy)
def create_hint(self, out_str):
hint_to_show = Hint(self.root)
hint_to_show.set_out_string(out_str)
hint_to_show.hint_lifecycle()
class Hint(Toplevel):
'''A toplevel widget with the ability to fade in'''
def __init__(self, *args, **kwargs):
Toplevel.__init__(self, *args, **kwargs)
# need to choose place depending on monitor sizes
self.geometry("500x50+780+30")
self.attributes("-alpha", 0.0)
self.overrideredirect(1)
self.hint_textbox = Text(self)
self.hint_textbox.pack()
def set_out_string(self, out_string):
self.hint_textbox.insert(INSERT, out_string)
def hint_lifecycle(self):
self.fade_in()
self.after(3000, self.fade_out)
def fade_in(self):
alpha = self.attributes("-alpha")
if alpha == 1:
alpha = 0
alpha = min(alpha + .01, 1.0)
self.attributes("-alpha", alpha)
if alpha < 1.0:
self.after(10, self.fade_in)
def fade_out(self):
alpha = self.attributes("-alpha")
alpha = max(alpha - .01, 0)
self.attributes("-alpha", alpha)
if alpha > 0:
self.after(10, self.fade_out)
if alpha == 0:
self.destroy()
if __name__ == "__main__":
if 1 == len(sys.argv):
main = MainWindow("")
else:
# we get path of json and modules as arguments, so use it
main = MainWindow(sys.argv[1])