2020-05-05 12:55:06 +00:00
|
|
|
import webbrowser
|
|
|
|
from tkinter import *
|
|
|
|
from tkinter.ttk import *
|
2020-12-07 15:40:05 +00:00
|
|
|
import re
|
2020-05-05 12:55:06 +00:00
|
|
|
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
from fishy import helper, web
|
2020-10-17 19:06:07 +00:00
|
|
|
from fishy.helper.config import config
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
hyperlinkPattern = re.compile(r'\[(?P<title>.*?)\]\((?P<address>.*?)\)')
|
2020-05-05 12:55:06 +00:00
|
|
|
|
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
def check_eula():
|
2020-05-05 12:55:06 +00:00
|
|
|
if not config.get("eula", False):
|
2020-10-17 19:06:07 +00:00
|
|
|
_run_terms_window()
|
2020-05-05 12:55:06 +00:00
|
|
|
return config.get("eula", False)
|
|
|
|
|
|
|
|
return config.get("eula", False)
|
|
|
|
|
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
def _run_terms_window():
|
2020-05-05 12:55:06 +00:00
|
|
|
def accept():
|
|
|
|
config.set("eula", True)
|
|
|
|
root.destroy()
|
|
|
|
|
|
|
|
def disable_enable_button():
|
2020-05-14 02:03:13 +00:00
|
|
|
accept_button.config(state=NORMAL if check_value.get() else DISABLED)
|
2020-05-05 12:55:06 +00:00
|
|
|
|
|
|
|
root = Tk()
|
|
|
|
message = f'I agree to the [Terms of Service and Privacy Policy]({web.get_terms_page()})'
|
|
|
|
root.title("EULA")
|
|
|
|
root.resizable(False, False)
|
2020-05-12 06:13:42 +00:00
|
|
|
root.iconbitmap(helper.manifest_file('icon.ico'))
|
2020-05-05 12:55:06 +00:00
|
|
|
|
|
|
|
f = Frame(root)
|
|
|
|
canvas = Canvas(f, width=300, height=200)
|
|
|
|
canvas.pack()
|
2020-05-12 06:13:42 +00:00
|
|
|
root.image = Image.open(helper.manifest_file('fishybot_logo.png')).resize((300, 200))
|
2020-05-05 12:55:06 +00:00
|
|
|
root.image = ImageTk.PhotoImage(root.image)
|
|
|
|
canvas.create_image(0, 0, anchor=NW, image=root.image)
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
check_value = IntVar(0)
|
2020-05-05 12:55:06 +00:00
|
|
|
|
|
|
|
g1 = Frame(f)
|
2020-05-14 02:03:13 +00:00
|
|
|
Checkbutton(g1, command=disable_enable_button, variable=check_value).pack(side=LEFT)
|
2020-10-14 02:29:06 +00:00
|
|
|
text = Text(g1, width=len(hyperlinkPattern.sub(r'\g<title>', message)),
|
2020-05-05 12:55:06 +00:00
|
|
|
height=1, borderwidth=0, highlightthickness=0)
|
|
|
|
text["background"] = root["background"]
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
_format_hyper_link(text, message)
|
2020-05-05 12:55:06 +00:00
|
|
|
text.config(state=DISABLED)
|
|
|
|
text.pack(side=LEFT)
|
|
|
|
g1.pack()
|
|
|
|
|
|
|
|
f.pack(padx=(10, 10), pady=(20, 20))
|
|
|
|
|
|
|
|
g2 = Frame(f)
|
|
|
|
accept_button = Button(g2, text="Accept",
|
|
|
|
command=accept)
|
|
|
|
accept_button.grid(row=0, column=0)
|
|
|
|
Button(g2, text="Deny",
|
|
|
|
command=lambda: root.destroy()).grid(row=0, column=1)
|
|
|
|
g2.pack(pady=(5, 0))
|
|
|
|
disable_enable_button()
|
|
|
|
|
|
|
|
root.mainloop()
|
|
|
|
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def _format_hyper_link(text, message):
|
2020-05-05 12:55:06 +00:00
|
|
|
start = 0
|
|
|
|
for index, match in enumerate(hyperlinkPattern.finditer(message)):
|
|
|
|
groups = match.groupdict()
|
|
|
|
text.insert("end", message[start: match.start()])
|
|
|
|
# insert hyperlink tag here
|
|
|
|
text.insert("end", groups['title'])
|
|
|
|
text.tag_add(str(index),
|
|
|
|
"end-%dc" % (len(groups['title']) + 1),
|
|
|
|
"end", )
|
|
|
|
text.tag_config(str(index),
|
|
|
|
foreground="blue",
|
|
|
|
underline=1)
|
|
|
|
text.tag_bind(str(index),
|
|
|
|
"<Enter>",
|
|
|
|
lambda *a, **k: text.config(cursor="hand2"))
|
|
|
|
text.tag_bind(str(index),
|
|
|
|
"<Leave>",
|
|
|
|
lambda *a, **k: text.config(cursor="arrow"))
|
|
|
|
text.tag_bind(str(index),
|
|
|
|
"<Button-1>",
|
2020-05-07 06:03:30 +00:00
|
|
|
lambda x: webbrowser.open(groups['address']))
|
2020-05-05 12:55:06 +00:00
|
|
|
start = match.end()
|
|
|
|
else:
|
|
|
|
text.insert("end", message[start:])
|