-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathconfig_generator.py
169 lines (146 loc) · 5.68 KB
/
config_generator.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
import yaml
def resourcePath(relativePath):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
basePath = sys._MEIPASS
except Exception:
basePath = os.path.abspath(".")
return os.path.join(basePath, relativePath)
import os
def ensure_dir():
directory = os.path.dirname('config')
print(directory)
if not os.path.exists('config'):
os.makedirs('config')
bool_config = os.path.isfile(resourcePath('pybot-config.yaml'))
if not bool_config:
f = open(resourcePath("pybot-config.yaml"), "w")
config_list = [['client title','OpenOSRS'], ['pc_profile','C:\\Users\\i7 8700'],
['file_path_to_client', '\\.openosrs\\'], ['tesseract_path','C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'],
['enable_on_start', True]]
article_info= [{
'Config': {
'client_title': config_list[0][1],
'pc_profile': config_list[1][1],
'file_path_to_client': config_list[2][1],
'tesseract_path': config_list[3][1],
'enable_on_start': config_list[4][1]
}
}]
data = yaml.dump(article_info, f)
f.close()
bool_config = os.path.isfile(resourcePath('pybot-config.yaml'))
if bool_config:
print('config already exists!')
with open(resourcePath("pybot-config.yaml"), "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
print("Read successful")
yamlfile.close()
print(data)
config_list = [['client title', data[0]['Config']['client_title']], ['pc_profile', data[0]['Config']['pc_profile']],
['file_path_to_client', data[0]['Config']['file_path_to_client']],
['tesseract_path', data[0]['Config']['tesseract_path']],
['enable_on_start', data[0]['Config']['enable_on_start']]
]
ensure_dir()
if data[0]['Config']['enable_on_start'] == True:
import tkinter
from tkinter import *
from PIL import Image, ImageTk
test = []
root = Tk()
root.title('Sly OSRS PyBot_Config')
root.geometry('715x465')
root.configure(background='#40362C')
Font_tuple = ('Unispace', 15)
Font_tuple_entry = ('Unispace', 10)
filename = resourcePath('images/osrs_title_2.png')
image1 = Image.open(filename)
image1 = image1.convert('RGBA')
h = (400, 400)
image1.thumbnail(h)
test1 = ImageTk.PhotoImage(image1)
label1 = tkinter.Label(image=test1, background='#40362C', anchor=CENTER, justify=CENTER)
label1.image = test1
label1.grid(column=0, columnspan=2)
x = 1
while x < len(config_list) + 1:
lbl = Label(root, text=(config_list[(x - 1)][0]), background='#40362C', fg='yellow', padx=20)
lbl.configure(font=Font_tuple)
lbl.grid(column=0, row=x)
x += 1
x = 1
while x < len(config_list) + 1:
print(config_list[(x - 1)][0])
if config_list[(x - 1)][0] != 'enable_on_start':
txt = Entry(root,width=50, background='#40362C', fg='yellow')
txt.insert(-1, (config_list[(x - 1)][1]) )
txt.configure(font=Font_tuple_entry)
test.append(txt)
txt.grid(column=1, row=x)
x += 1
is_on = True
# Define Our Images
image1 = Image.open(resourcePath('images/switch-on.png'))
image1 = image1.convert('RGBA')
h = (50, 50)
image1.thumbnail(h)
on = ImageTk.PhotoImage(image1)
image2 = Image.open(resourcePath('images/switch-off.png'))
image2 = image2.convert('RGBA')
h = (50, 50)
image2.thumbnail(h)
off = ImageTk.PhotoImage(image2)
def toggle():
global is_on
if is_on:
toggle_btn.config(image=off)
is_on = False
else:
toggle_btn.config(image=on)
is_on = True
#lbl = Label(root, text=('Tesseract'), background='#40362C', fg='yellow', padx=20)
#lbl.configure(font=Font_tuple)
#lbl.grid(column=0, row=len(config_list) + 1)
toggle_btn = Button(image=on, width=50, background='#40362C', activebackground='#40362C', bd=0, relief=None, fg='yellow', command=toggle)
toggle_btn.grid(column=0, row=5, columnspan=2, pady=2)
def clicked():
c_title = test[0].get()
if is_on:
t_enable = True
else:
t_enable = False
p_profile = test[1].get()
f_path = test[2].get()
t_path = test[3].get()
article_info = [
{
'Config': {
'client_title': c_title,
'pc_profile': p_profile,
'file_path_to_client': f_path,
'tesseract_path': t_path,
'enable_on_start': t_enable
}
}
]
with open("pybot-config.yaml", 'w') as yamlfile:
data = yaml.dump(article_info, yamlfile)
print("Write successful")
yamlfile.close()
print('config file generated!!!')
with open("pybot-config.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
print("Read successful")
yamlfile.close()
print(data)
root.quit()
root.destroy()
btn = Button(root, text='Generate Config File', fg='yellow',
command=clicked,
background='#40362C',
pady=0)
btn.grid(column=0, row=6, columnspan=2, pady=2)
btn.configure(font=Font_tuple)
root.mainloop()