-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility63rabbits.py
71 lines (56 loc) · 1.9 KB
/
utility63rabbits.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
import os
import sys
import re
# for Platform
class PLTFORM:
@staticmethod
def is_windows():
if os.name == 'nt': return True
return False
@staticmethod
def is_linux():
if os.name == 'posix': return True
return False
@staticmethod
def is_mac():
return PLTFORM.is_linux()
# for Resource Control
class RSC:
@staticmethod
def get_resource_path(filename):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, filename)
# return os.path.join(filename)
return filename
# for Window
class WIN:
@staticmethod
def get_pos_string_on_screen(self, width, height, position='C', x_offset=0, y_offset=0):
sw = self.winfo_screenwidth()
sh = self.winfo_screenheight()
xy = ((sw - width) // 2, (sh - height) // 2)
p = position.upper()
if p == 'NW': xy = (0, 0)
elif p == 'N': xy = ((sw - width)//2, 0)
elif p == 'NE': xy = (sw - width, 0)
elif p == 'W': xy = (0, (sh - height)//2)
elif p == 'C': pass
elif p == 'E': xy = (sw - width, (sh - height)//2)
elif p == 'SW': xy = (0, sh - height)
elif p == 'S': xy = ((sw - width)//2, sh - height)
elif p == 'SE': xy = (sw - width, sh - height)
xy = (xy[0]+x_offset, xy[1]+y_offset)
r = (f'{width}x{height}+{xy[0]}+{xy[1]}', width, height, xy[0], xy[1])
return r
# for Drag and Drop with tkinterdnd2
class DND:
@staticmethod
def make_file_list(dnd_files_string):
rawfs = dnd_files_string
bfs = re.findall('{.+?}', rawfs)
fs = []
for f in bfs:
rawfs = rawfs.replace(f, '')
fs.append(f.replace('{', '').replace('}', ''))
fs = sorted(fs + rawfs.split())
return fs