-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspellbook.py
171 lines (128 loc) · 4.56 KB
/
spellbook.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import runpy
from pynput import keyboard
import sqlite3
from tkinter import *
from tkinter import ttk
from time import sleep
import os
import sv_ttk
# Learn about dev chrome control, more general creation of folders and applying scripts in files with routing logic or manual folder creation with auto script finding
# Outside scripts return 0, configures scripts to run, have the window work and scripts run when not withdrawn
########## Tkinter Initialization Start ##########
#Create root
root = Tk()
root.title("Spellbook")
root.attributes("-topmost", 1)
root.geometry('600x150+700-49')
#Mainframe settings
mainframe = ttk.Frame(root, padding="12 12 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
mainframe.place(relx=0.5, rely=0.5, anchor=CENTER)
#Initialize
defaultKeys = 'asdfjkl;qweruiopzxcvm,./ghtybn'
rootDirectory = './spells (scripts)'
currentDirectory = './spells (scripts)'
directories = os.listdir(currentDirectory)
dirLength = len(directories)
menu = ''
for i in range(dirLength):
menu += defaultKeys[i] + '. ' + directories[i] + '\n'
# title = ttk.Label(mainframe, text='Spellbook')
# title.grid(column=1, row=1, sticky=(W, E))
menuLabel = ttk.Label(mainframe, text=menu)
menuLabel.grid(column=1, row=2, sticky=(W, E))
########## Tkinter Initialization End ##########
########## Hotkey Listener Start ##########
withDrawn = False
def toggle_menu():
# print('<ctrl>+<shift> pressed')
global withDrawn
if(withDrawn):
root.deiconify()
withDrawn = False
else:
root.withdraw()
withDrawn = True
def close_menu():
global hotkeyListener
# print('<shift>+<esc> pressed')
hotkeyListener.stop()
sleep(0.1)
root.destroy()
hotkeyListener = keyboard.GlobalHotKeys({
'<ctrl>+<shift>': toggle_menu,
'<shift>+<esc>': close_menu})
hotkeyListener.start()
########## Hotkey Listener End ##########
########## Keypress Listener Start ##########
keypressListener = keyboard.Listener()
def on_press(key):
#No actions when withdrawn
global withDrawn
# print(withDrawn)
if(withDrawn):
return
global currentDirectory
global defaultKeys
global menuLabel
global rootDirectory
#Entering scopes
try:
defaultKeyIndex = defaultKeys.find('{0}'.format(key.char))
currentDirectory += '/' + os.listdir(currentDirectory)[defaultKeyIndex]
if('.py' in currentDirectory):
runpy.run_path(currentDirectory)
currentDirectories = os.listdir(currentDirectory)
dirLength = len(currentDirectories)
newMenu = ''
for i in range(dirLength):
newMenu += defaultKeys[i] + '. ' + currentDirectories[i] + '\n'
menuLabel.configure(text = newMenu)
#Exiting scopes
except AttributeError:
if(key == keyboard.Key.tab):
currentDirectory = currentDirectory[0:currentDirectory.rfind('/')]
if(currentDirectory == '.'):
currentDirectory = rootDirectory
return
currentDirectories = os.listdir(currentDirectory)
dirLength = len(currentDirectories)
newMenu = ''
for i in range(dirLength):
newMenu += defaultKeys[i] + '. ' + currentDirectories[i] + '\n'
menuLabel.configure(text = newMenu)
if(key == keyboard.Key.esc):
currentDirectory = rootDirectory
currentDirectories = os.listdir(currentDirectory)
dirLength = len(currentDirectories)
newMenu = ''
for i in range(dirLength):
newMenu += defaultKeys[i] + '. ' + currentDirectories[i] + '\n'
menuLabel.configure(text = newMenu)
except NotADirectoryError:
currentDirectory = rootDirectory
currentDirectories = os.listdir(currentDirectory)
dirLength = len(currentDirectories)
newMenu = ''
for i in range(dirLength):
newMenu += defaultKeys[i] + '. ' + currentDirectories[i] + '\n'
menuLabel.configure(text = newMenu)
toggle_menu()
except IndexError:
return
listener = keyboard.Listener(
on_press=on_press)
listener.start()
########## Keypress Listener End ##########
sv_ttk.set_theme("dark")
root.mainloop()
"""
wizardDatabaseConnection = sqlite3.connect('wizard.db')
cursor = wizardDatabaseConnection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS spells (hotkey text, script text)')
cursor.execute('')
"""