forked from nachifur/MulimgViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
executable file
·62 lines (49 loc) · 1.33 KB
/
utils.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
import sys
from pathlib import Path
import numpy as np
import copy
import wx
class MyTestEvent(wx.PyCommandEvent):
def __init__(self, evtType, id=0):
wx.PyCommandEvent.__init__(self, evtType, id)
self.eventArgs = ""
def GetEventArgs(self):
return self.eventArgs
def SetEventArgs(self, args):
self.eventArgs = args
def get_resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return str(Path(sys._MEIPASS)/relative_path)
return str(Path(relative_path).absolute())
def solve_factor(num):
# solve factors for a number
list_factor = []
i = 1
if num > 2:
while i <= num:
i += 1
if num % i == 0:
list_factor.append(i)
else:
pass
else:
pass
list_factor = list(set(list_factor))
list_factor = np.sort(list_factor)
return list_factor
def change_order(list_):
if isinstance(list_[1], list):
temp = copy.deepcopy(list_[0])
else:
temp = list_[0]
list_[0] = list_[1]
list_[1] = temp
return list_
def rgb2hex(rgbcolor):
# https://blog.csdn.net/Forter_J/article/details/89145794
rgb = rgbcolor.split(',')
strs = '#'
for i in rgb:
num = int(i)
strs += str(hex(num))[-2:].replace('x', '0').upper()
return strs