-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclnch_misc.py
186 lines (136 loc) · 5.05 KB
/
clnch_misc.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import sys
import os
import shutil
import datetime
import ctypes
import pyauto
import ckit
import clnch_resource
from ckit.ckit_const import *
## @addtogroup misc その他雑多な機能
## @{
#--------------------------------------------------------------------
ignore_1second = True
#--------------------------------------------------------------------
def getFileSizeString(size):
if size < 1000:
return "%dB" % ( size, )
if size < 1000*1024:
s = "%.1fK" % ( size / float(1024), )
if len(s)<=6 : return s
if size < 1000*1024*1024:
s = "%.1fM" % ( size / float(1024*1024), )
if len(s)<=6 : return s
if size < 1000*1024*1024*1024:
s = "%.1fG" % ( size / float(1024*1024*1024), )
if len(s)<=6 : return s
return "%.1fT" % ( size / float(1024*1024*1024*1024), )
#--------------------------------------------------------------------
_net_connection_handler = None
def registerNetConnectionHandler(handler):
global _net_connection_handler
_net_connection_handler = handler
def checkNetConnection(path):
drive, tail = os.path.splitdrive(path)
unc = ( drive.startswith("\\\\") or drive.startswith("//") )
if unc:
remote_resource_name = drive.replace('/','\\').rstrip('\\')
try:
_net_connection_handler(remote_resource_name)
except Exception as e:
print( e )
#--------------------------------------------------------------------
def compareTime( t1, t2 ):
if ignore_1second:
delta = abs( datetime.datetime(*t1) - datetime.datetime(*t2) )
if delta.days==0 and delta.seconds<=1 : return 0
return cmp(t1,t2)
#--------------------------------------------------------------------
def findExistingClnchWindow():
found = [None]
def callback( wnd, arg ):
if wnd.getClassName()=="ClnchWindowClass" and wnd.getText()==clnch_resource.clnch_appname + " MainWindow":
found[0] = wnd
return False
return True
pyauto.Window.enum( callback, None )
return found[0]
#--------------------------------------------------------------------
def replaceMacro( s, map = { "%%" : "%" }, environ=True ):
search_pos = 0
while 1:
var_start = s.find('%',search_pos)
if var_start < 0 : break;
var_end = s.find('%',var_start+1)
if var_end < 0 : break;
try:
after = map[ s[ var_start : var_end+1 ] ]
s = s[:var_start] + after + s[var_end+1:]
search_pos += len(after)
continue
except KeyError:
pass
if environ:
try:
after = os.environ[ s[ var_start + 1 : var_end ] ]
s = s[:var_start] + after + s[var_end+1:]
search_pos += len(after)
continue
except KeyError:
pass
search_pos += 1
return s
def joinArgs( args ):
result = ''
for arg in args:
if arg.find(' ') >= 0 :
result += ' '+ '"' + arg + '"'
else:
result += ' '+ arg
return result.strip()
#--------------------------------------------------------------------
_commandline_normalize_table = str.maketrans(
"\t\r\n",
" "
)
def normalizeCommandLineText(s):
s = s.translate(_commandline_normalize_table)
while s.find(" ")>=0:
s = s.replace( " ", " " )
return s
#--------------------------------------------------------------------
def adjustWindowPosition( base_window, new_window, default_up, monitor_adjust_vertical=True, monitor_adjust_horizontal=True ):
base_window_rect = base_window.getWindowRect()
x1 = base_window_rect[0]
x2 = base_window_rect[2]
y1 = base_window_rect[1]
y2 = base_window_rect[3]
if default_up:
y = y1
origin_y = ORIGIN_Y_BOTTOM
else:
y = y2
origin_y = ORIGIN_Y_TOP
x = x1
origin_x = ORIGIN_X_LEFT
monitor_info_list = pyauto.Window.getMonitorInfo()
for monitor_info in monitor_info_list:
if monitor_info[0][0] <= x1 < monitor_info[0][2] and monitor_info[0][1] <= y1 < monitor_info[0][3]:
new_window_rect = new_window.getWindowRect()
char_w, char_h = new_window.getCharSize()
if monitor_adjust_vertical:
if default_up:
if y1 - (new_window_rect[3]-new_window_rect[1]) < monitor_info[1][1]:
y = y2
origin_y = ORIGIN_Y_TOP
else:
if y2 + (new_window_rect[3]-new_window_rect[1]) >= monitor_info[1][3]:
y = y1
origin_y = ORIGIN_Y_BOTTOM
if monitor_adjust_horizontal:
if x1 + (new_window_rect[2]-new_window_rect[0]) >= monitor_info[1][2]:
x = x2
origin_x = ORIGIN_X_RIGHT
break
new_window.setPosSize( x, y, new_window.width(), new_window.height(), origin_x | origin_y )
## @} misc