forked from slyautomation/osrs_basic_botting_functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_generator.py
More file actions
139 lines (117 loc) · 4.17 KB
/
config_generator.py
File metadata and controls
139 lines (117 loc) · 4.17 KB
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
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('pybot-config.yaml')
if bool_config:
print('config already exists!')
with open("pybot-config.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
print("Read successful")
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']]]
else:
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']]
ensure_dir()
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('osrs_title_2.png')
image1 = Image.open(filename)
image1 = image1.convert('RGBA')
h = (400, 400)
image1.thumbnail(h, Image.NORMAL)
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:
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('switch-on.png')
image1 = image1.convert('RGBA')
h = (50, 50)
image1.thumbnail(h, Image.NORMAL)
on = ImageTk.PhotoImage(image1)
image2 = Image.open('switch-off.png')
image2 = image2.convert('RGBA')
h = (50, 50)
image2.thumbnail(h, Image.NORMAL)
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()
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
}
}
]
with open("pybot-config.yaml", 'w') as yamlfile:
data = yaml.dump(article_info, yamlfile)
print("Write successful")
print('config file generated!!!')
with open("pybot-config.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
print("Read successful")
print(data)
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()