t5 commited on
Commit
ea6f606
·
1 Parent(s): dbc588b
Files changed (1) hide show
  1. altEdit.py +339 -0
altEdit.py ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ ##import sys;sys.path.append("N:\\afilen\\program\\python\\Mjmoji");from wr import *
3
+ ##import altEdit;altEdit.scroll()
4
+ import sys
5
+ import time
6
+ from ctypes import *
7
+ import subprocess as p
8
+ from wr import tfolder
9
+ args=sys.argv
10
+ ##PyScripter=r"C:\Program Files\PyScripter\PyScripter.exe"
11
+ PyScripter=r"C:\alte\PyScripter\PyScripter.exe"
12
+ ##PyScripter=r"E:\Python34\Scripts\spyder.bat"
13
+ VK_SHIFT = 0x10
14
+ VK_CONTROL = 0x11
15
+ VK_MENU = 0x12
16
+ VK_CAPITAL = 0x14
17
+ VK_NUMLOCK = 0x90
18
+ VK_SCROLL = 0x91
19
+ VK_LWIN = 0x5B
20
+ VK_RWIN = 0x5C
21
+ dlivk=(0x10,0x11,0x12,0x14,0x90,0x91)
22
+
23
+ KEYEVENTF_EXTENDEDKEY= 0x0001
24
+ KEYEVENTF_KEYUP= 0x0002
25
+
26
+ def acs():#alt ctrl shift
27
+ time.sleep(0.6)
28
+ r = windll.user32.GetKeyState(16)#shift
29
+ if 0xff==(r>>8):#ff00|ff01
30
+ p.Popen([PyScripter] + [args[0]],shell=False);
31
+ sys.exit(0)
32
+ def isshift():
33
+ return windll.user32.GetKeyState(16)&256
34
+ def isscroll():
35
+ return windll.user32.GetKeyState(VK_SCROLL)
36
+ def winmod():
37
+ press,impc=GetKeyboardState()
38
+ tea=""
39
+ ## print(f"{impc[0x10]:b},{impc[0x10]>>6:b}")
40
+ if impc[0x11]>>6: tea+="c"
41
+ if impc[0x10]>>6: tea+="s"
42
+ if impc[0x12]>>6: tea+="a"
43
+ if impc[VK_NUMLOCK]==1: tea+="n"
44
+ if impc[VK_SCROLL]==1: tea+="l"
45
+ return tea
46
+ def scroll0():
47
+ pc=c_char_p(b"hal")
48
+ impc=c_byte(2)
49
+ ## pc=pointer(impc)
50
+ r = windll.user32.GetKeyboardState(pc)
51
+ print(r,pc,pc.value)#,["%x"%b for b in pc.value])
52
+ print(r,impc,impc.value,pc)#,["%x"%b for b in impc.value])
53
+ #set([(n) for n,o in enumerate(impc) if o]).intersection({VK_SCROLL,VK_NUMLOCK})
54
+ def GetKeyboardState():
55
+ impc=(c_byte*256)()
56
+ pc=pointer(impc)
57
+ r = windll.user32.GetKeyboardState(pc)
58
+ press=set([(n) for n,o in enumerate(impc) if o])
59
+ return r!=0 and press, impc
60
+ def scrollFull(app=PyScripter, ars=[args[0]], sh=False):
61
+ press,impc=GetKeyboardState()
62
+ ## print(impc[:]);
63
+ if press and press.intersection({VK_SCROLL,VK_NUMLOCK}):
64
+ if impc[VK_SCROLL]==1:
65
+ p.Popen([app] + ars,shell=sh);
66
+ elif impc[VK_NUMLOCK]==1:
67
+ windll.user32.keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0)#press
68
+ windll.user32.keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0)#release
69
+ p.Popen(["start","cmd.exe","/k"]+sys.argv,shell=True);
70
+ print("altEdit")
71
+ sys.exit()
72
+ def Wrap1(ars=[args[0]]):
73
+ scrollFull(app=PyScripter, ars=ars, sh=False)
74
+ scroll=Wrap1
75
+ #
76
+ #
77
+
78
+
79
+ def ctockai( text ):
80
+ import os
81
+ logfile=[fr"{tfolder}/1.txt",fr"{tfolder}/2er.txt"]
82
+ ## for f in logfile: os.path.exists(f) and os.remove(f)
83
+ ip = p.Popen( ['cmd'], stdin=p.PIPE, shell=True )
84
+ #text="%s > %s 2>&1 \n"%(text,erfile)#write
85
+ text="{} 1> {} 2> {} \n".format(text,*logfile)#write
86
+ ## orror(text);
87
+ ip.stdin.write( text.encode("cp932"))
88
+ ip.stdin.close()
89
+ retcode = ip.wait()
90
+ #
91
+ lir=list(open(f,"rb").read() for f in logfile)
92
+ ## lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("mbcs") for te in lir]
93
+ lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("utf8") for te in lir]
94
+ return (retcode,lir[0],lir[1])
95
+ def ctod( text ,sh=True,cp="cp932",si=None):
96
+ ip = p.Popen( ['cmd']if(sh)else text, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=sh )
97
+ if 0:#no
98
+ ip.stdin.write("echo 1\n".encode())
99
+ for x in iter(ip.stdout.readline, b''):x
100
+ if 0:#no
101
+ ip.stdin.write("chcp 65001\n".encode("cp932"))
102
+ ip.stdin.flush()
103
+ ip.stdout.flush()
104
+ print(ip.stdout.read());
105
+ if(sh):
106
+ text+="\n";
107
+ ip.stdin.write( text.encode("cp932"))
108
+ ip.stdin.close()
109
+ elif(si):
110
+ ip.stdin.write(si)
111
+ ip.stdin.close()
112
+
113
+ retcode=None
114
+ try:
115
+ ## retcode = ip.wait(timeout=0)
116
+ retcode = ip.wait()
117
+ res=(ip.stdout.read()[96:],
118
+ ip.stderr.read())
119
+ ## for f in range(212): er=ip.stdout.read(2)
120
+ except p.TimeoutExpired as e:
121
+ ## return ip.stdout.readline(21)
122
+ res=(ip.stdout.read()[96:],
123
+ ip.stderr.read())
124
+ fds
125
+ ## cp="utf8"
126
+ ## try:
127
+ ## return retcode,r.decode(cp),er.decode(cp),ip
128
+ ## except:
129
+ ## cp="cp932"
130
+ ## return retcode,r.decode(cp),er.decode(cp),ip
131
+ res=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n") for te in res]
132
+ from wr import vcs
133
+ res=[vcs(te) for te in res]
134
+ return retcode,*res,ip
135
+ def Runw(li): ctod(li,sh=False)
136
+ ##(ctockai(jw(" ",["node",r"C:\v\P\electron\electron-quick-start\or1.js"])))
137
+ ##print(ctockai("dir ."))
138
+ ##print(ctod(jw(" ",["node",r"C:\v\P\electron\electron-quick-start\or1.js"])))
139
+ import os
140
+ import th
141
+ class cltof():
142
+ def __init__(zl):
143
+ #zl.mutex=fwe
144
+ zl.ev=th.Event()
145
+ zl.lock=th.Lock()
146
+ os.environ['PYTHONIOENCODING'] = 'utf-8'
147
+ def ctof(zl,cb,to, text ):
148
+ from wr import vcs, tp, wfd
149
+ zl.ev.clear()
150
+ if 0==to:to=3600*12
151
+ time0=time.perf_counter()
152
+ def fppc():
153
+ return time.perf_counter()-time0
154
+ def fpin(cb,text):
155
+ date=tp()
156
+ if isinstance(text,(list,tuple)): c=os.path.basename((text[0]))
157
+ elif isinstance(text,(str)): c= "C"
158
+ logfile=zl.logfile=[fr"{tfolder}/ctof_{c}_{x}_{date}.txt" for x in ("1","2")]
159
+ ## print(text,cb)
160
+ for f in logfile: os.path.exists(f) and os.remove(f)
161
+ ## ip = p.Popen( [("echo ff"),"1>",logfile[0],"2>",logfile[1]], shell=True )
162
+ if isinstance(text,(list,tuple)): te= [*text,"1>",logfile[0],"2>",logfile[1]]
163
+ elif isinstance(text,(str)):te= text+" 1> {} 2> {}".format(*logfile)
164
+ ## zl.ip=ip=p.Popen(te,shell=True)
165
+ zl.ip=ip=p.Popen(text,shell=True, stdout=open(logfile[0],"w"), stderr=open(logfile[1],"w"))
166
+ ## zl.ip=ip = p.Popen( ['cmd /c {} 1> {} 2> {} '.format(text,*logfile) ])
167
+ ## ip = p.Popen( ['cmd /c {} 1> {} 2> {} '.format(*text,*logfile) ], stdin=p.PIPE, shell=True )
168
+ ## orror(text);
169
+ ## ip.stdin.write( text.encode("cp932"))
170
+ ## ip.stdin.close()
171
+ ## if 1:
172
+ ## while ip.poll() is None:
173
+ ## time.sleep(0.2)
174
+
175
+ while any([False==os.path.exists(f) for f in logfile]):
176
+ print("not ready;",[os.path.exists(f) for f in logfile],te)
177
+ time.sleep(0.1)
178
+ while 1:
179
+ ## try:
180
+ #with open(logfile[0],"rb") as fo:
181
+ lifo=[open(f,"rb") for f in logfile]
182
+ while 1:
183
+ poll=zl.poll=ip.poll()
184
+ for x,fo in enumerate(lifo):
185
+ bit=fo.read()
186
+ ## print("p;",poll,bit)#lwt
187
+ if bit and cb: cb(x+1, vcs(bit))
188
+ if poll!=None: break
189
+ time.sleep(0.2)
190
+ if poll!=None: break
191
+ if to<(d:=fppc()):return
192
+ ## print(d)
193
+ #retcode = ip.wait()
194
+ ## except 2: f
195
+ if ip.poll()!=None:break
196
+ if to<(d:=fppc()):break
197
+ def fpin1(*w):
198
+ cb,*_=w
199
+ try:
200
+ res=fpin(*w)
201
+ ## except Exception as e:
202
+ ## wfd("r:\\logEdit.txt").t(str(e))
203
+ finally:
204
+ zl.ev.set()
205
+ return res
206
+ t=th.run(fpin1,(cb,text))
207
+ ## jw(t,)
208
+ ## time.sleep(1)
209
+ return t
210
+ @property
211
+ def te(zl):
212
+ from wr import vcs
213
+ if 1:
214
+ logfile=zl.logfile
215
+ lir=list(open(f,"rb").read() for f in logfile)
216
+ ## lir=[te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n").decode("mbcs") for te in lir]
217
+ ## print(lir[0].decode("cp932"),poll)
218
+ lir=[vcs(te.replace(b"\r\r\n",b"\n").replace(b"\r\n",b"\n"))for te in lir]
219
+ return (zl.poll,lir[0],lir[1])
220
+ @property
221
+ def wa(zl):
222
+ try:zl.ev.wait()
223
+ except KeyboardInterrupt as e:e
224
+ return zl
225
+ @staticmethod
226
+ def cbpr(std,b): print(f"{std} cblen({len(b)}) {b}")
227
+ def ctof(*w):
228
+ p=cltof()
229
+ p.ctof(*w)
230
+ return p
231
+ ##def watofin(*w):
232
+ ## p=ctof(*w).wa
233
+ ## return p
234
+ ##def returnwat():
235
+ def watof(*w):
236
+ p=ctof(*w)
237
+ te=p.wa.te
238
+ return te[1]+"\n"+te[2]
239
+ def tofu(*w):
240
+ return ctof(*w).wa.te
241
+ import subprocess, shlex
242
+ from threading import Timer
243
+
244
+ def run(cmd, timeout_sec):
245
+ proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
246
+ stderr=subprocess.PIPE)
247
+ kill_proc = lambda p: p.kill()
248
+ timer = Timer(timeout_sec, kill_proc, [proc])
249
+ try:
250
+ timer.start()
251
+ stdout,stderr = proc.communicate()
252
+ finally:
253
+ timer.cancel()
254
+ #
255
+ import time
256
+ import signal,os
257
+ def reloadFull(timeout=2.2, me=[sys.argv[0],"-r"]):
258
+ ip=p.Popen(me,shell=True)
259
+ try:
260
+ ri=ip.wait(timeout=timeout)#idea
261
+ print("eof. continue")
262
+ except subprocess.TimeoutExpired as e:
263
+ print("reload",e)
264
+ sys.exit(0)
265
+ def r1reloadFull(dure,me):
266
+ def handler(signum, frame):
267
+ print("reload,handler",signum)
268
+ def handlerth(signum, frame):
269
+ print("reload",signum)
270
+ ## sys.exit(0)#no
271
+ os.kill(os.getpid(),signal.SIGINT)
272
+ ## os.kill(os.getpid(),signal.SIGTERM)#ideaLk
273
+ signal.signal(signal.SIGTERM, handler)
274
+ signal.signal(signal.SIGINT, handler)
275
+ timer=Timer(dure-0.2,handlerth,args=[1,2])
276
+ #
277
+ try:
278
+ timer.start()
279
+ ip=p.Popen( me,bufsize=2, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=True )
280
+ while ip.poll() is None:
281
+ time.sleep(0.2)
282
+ print("while_poll",ip.poll())
283
+ pass
284
+ ## print(ip.stdout.read())
285
+ print("poll2",ip.poll())
286
+ try:
287
+ ## ri=ip.wait(timeout=dure)#idea
288
+ ri=ip.wait()
289
+ except subprocess.TimeoutExpired as e:
290
+ print(e)
291
+ ## sys.exit(0)
292
+ ## ri
293
+ finally:
294
+ timer.cancel()
295
+
296
+ if __name__ == '__main__':
297
+ scroll()
298
+ acs()
299
+ ars=sys.argv
300
+ c1=ars[1]if(len(ars)>=2)else None
301
+ def reheasal():
302
+ import multiprocessing as mlti
303
+ sys.stdin.conn
304
+
305
+ if(c1=="-out"):
306
+ for j in ars[2]:
307
+ time.sleep(0.3)
308
+ sys.stdout.write(j)
309
+ if(c1=="-c"):
310
+ for f in ":苍天\n:":
311
+ print(f)
312
+ ## sys.stdout.write(f)
313
+ if(c1=="-e"): fwf
314
+ if(c1=="-lf"):
315
+ for f in "123\n234":
316
+ print(f)
317
+ print(" start ",end="")
318
+ ## input("pw")
319
+ sys.stdout.flush()
320
+ print("", flush=True)#,file=stdout
321
+ time.sleep(1)
322
+ if not c1:
323
+ print("c1;")
324
+ ## reloadFull([r"dir"])
325
+ ## reloadFull(2,[r"N:\afilen\program\python\work\ClipArg.py"] + args)
326
+ ## r1reloadFull(5,[r"N:\afilen\program\python\qt\ClipProcess2.pyw"] + args)
327
+ ## r1reloadFull(5,[ars[0],"-out", jw(".",[str(j)for j in list(range(2))])] )
328
+ ## ctof(__file__,"-out","21212")
329
+ ## print(";;",ctof(f'{__file__} -out 21\n\n\n'))
330
+ #? print(";;",ctof(f'{__file__}',"-out", '"21\n21"'))
331
+ ## print(";;",ctof(f'{__file__}',"-out", "21"))
332
+ #lwt
333
+ def cb(std,b): print(f"{std} cblen({len(b)}) {b}")
334
+ ## print(";",ctof(cb,'ffmpeg',"-y","-i",r"r:\\p9.mkv","r:\\fw.mp4"))
335
+ ## print(";;",ctof(f'{__file__}',"-c",''))
336
+ ## print(";;",ctof(f'{__file__}',"-e"))
337
+ ## print(";;",watof(cb,10,(f'{__file__}',"-lf")))
338
+ print(";;",watof(cb,10,(f'{__file__}'+" -lf")))
339
+ ## print(";;",watof(f'{__file__}',"-out",'21212苍天\nf'))#?