-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutil.py
70 lines (60 loc) · 2.64 KB
/
util.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
import os, requests, json, shutil, string, webbrowser
from tkinter import messagebox
import torch
language_map = {
"Korean": "ko",
"Japanese": "ja",
"Simplified Chinese": "ch_sim",
"Traditional Chinese": "ch_tra",
"English": "en",
"Russian": "ru",
"Spanish": "es",
"Italian": "it"
}
def checkUpdate(tag):
try:
r = requests.get("https://api.github.com/repos/Aeonss/BubbleBlaster/releases/latest")
latest_tag = json.loads(r.content).get("tag_name")
if latest_tag > tag:
res = messagebox.askquestion(title="BubbleBlaster", message=f"A new update has been released for BubbleBlaster (v{latest_tag})! Do you want to download it?")
if res == 'yes':
webbrowser.open(f"https://github.com/Aeonss/BubbleBlaster/releases/tag/{latest_tag}/")
except:
print("Error getting latest update")
def setLog(self):
if not torch.cuda.is_available():
self.configure(text="Cuda is HIGHLY recommended. Click to download here.")
self.configure(state="disabled")
self.bind("<Button-1>", lambda e:webbrowser.open("https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html"))
# Checks if two rectangles are intersecting using Separating Axis Theorem
# (top right(x,y)), bottom left(x,y))
def intersect(top_right1, bottom_left1, top_right2, bottom_left2):
return not (top_right1[0] < bottom_left2[0] or bottom_left1[0] > top_right2[0] or top_right1[1] < bottom_left2[1] or bottom_left1[1] > top_right2[1])
# Exports raw text in the image into a text file
def exportRaw(image, raw_list, rects):
path = os.path.dirname(image)
raw_string = ""
for index, obj in enumerate(raw_list):
if index > 0:
if intersect(rects[index][0], rects[index][1], rects[index-1][0], rects[index-1][1]):
raw_string += obj
else:
raw_string += "\n" + obj
else:
raw_string += obj
with open(os.path.join(path, os.path.splitext(os.path.basename(image))[0] + "_raw.txt"), 'w', encoding='UTF-8') as fp:
fp.write(raw_string)
return raw_string
def sanitize_image_name(image, index):
if not image.isascii():
name = ''.join(c for c in image if c in string.printable)
basename, ext = os.path.splitext(os.path.basename(name))
# Handle the case where there is no extension
if not ext:
ext = ''
else:
basename = os.path.splitext(basename)[0]
new_name = os.path.join(os.path.dirname(image), f"{basename}{index}{ext}")
shutil.copy(image, new_name)
return new_name
return image