-
Notifications
You must be signed in to change notification settings - Fork 0
/
FN33and.py
1692 lines (1648 loc) · 69.4 KB
/
FN33and.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#5b\b3b5c3e922dd
#b'blob 62200\x00
#!/usr/bin/env python3
"""
ph3fn="pyhook-1.6.1-cp35-cp35m-win32.whl"
ph3downdir="\\\\$ph3fn"
ph3downlink="https://files.pythonhosted.org/packages/00/36/c08af743a671d94da7fe10ac2d078624f3efc09273ffae7b18601a8414fe/PyHook3-1.6.1-cp35-win32.whl"
curl -o "$ph3fn" "$ph3downlink"
"""
import os, signal, sys, threading
import _thread
from FN33andlib import *
from functools import partial
#https://stackoverflow.com/questions/4789837/how-to-terminate-a-python-subprocess-launched-with-shell-true
# The os.setsid() is passed in the argument preexec_fn so
# it's run after the fork() and before exec() to run the shell.
#pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,
# shell=True, preexec_fn=os.setsid)
dir0 = os.path.dirname(os.path.realpath(__file__))
textclick=0
pause=0
is_recording=0
linuxpc=1
def Default():
textclick=0
pause=0
is_recording=0
Default()
def checkdep():
deplist=["pyautogui pyuserinput"]
deplist.split()
if sys.platform in ['linux', 'linux2']:
callpip="pip3"
if sys.platform in ['Windows', 'win32', 'cygwin']:
callpip="pip"
for f in deplist:
subprocess.call(callpip+" install "+str(f),shell=True)
#checkdep()
def MouseGetPos():
if sys.platform in ['linux', 'linux2']:
screenroot=display.Display().screen().root
pointer = screenroot.query_pointer()
data = pointer._data
x=data["root_x"]
y=data["root_y"]
return x, y
if sys.platform in ['Windows', 'win32', 'cygwin']:
pass
import win32api, win32con
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
"""
wsh.AppActivate("Notepad") # select another application
wsh.AppActivate("%USERPROFILE%\\Documents\\Docs\\Automate\\FiiNoteWINE\\FiiNote.exe")
focusprog("FiiNote")
"""
def mouseclick(x,y):
time.sleep(0.1)
x=int(x)
y=int(y)
if sys.platform in ['linux', 'linux2']:
subprocess.call("xdotool mousemove "+str(x)+" "+str(y)+" click 1", shell=True)
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
pass
def dragfromto(startx,starty,stopx,stopy):
startx=int(startx)
starty=int(starty)
stopx=int(stopx)
stopy=int(stopy)
if sys.platform in ['linux', 'linux2']:
#subprocess.call("xdotool mousemove "+str(x)+" "+str(y)+" click 1", shell=True)
subprocess.call("xdotool mousemove "+startx+" "+starty+" mousedown 1", shell=True)
subprocess.call("xdotool mousemove "+stopx+" "+stopy+" mouseup 1", shell=True)
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
win32api.SetCursorPos((startx,starty))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,startx,starty,0,0)
#time.sleep(0.9)
win32api.SetCursorPos((stopx,stopy))
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,stopx,stopy,0,0)
pass
def sendthiskey(thekey):
global wsh
time.sleep(0.1)
if sys.platform in ['linux', 'linux2']:
subprocess.call("xdotool "+thekey, shell=True)
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
wsh.SendKeys(str(thekey))
pass
def FindColor():
import pyscreenshot as ImageGrab
from PIL import Image
if sys.platform in ['linux', 'linux2'] :
screenw = Home.winfo_screenwidth()
screenh = Home.winfo_screenheight()
if sys.platform in ['Windows', 'win32', 'cygwin']:
from win32api import GetSystemMetrics
screenw=GetSystemMetrics(0)
screenh=GetSystemMetrics(1)
im=pyscreenshot.grab(bbox=(0,0,screenw,screenh),childprocess=False)
for x in range(1,int(screenw)):
for y in range(1,int(screenh)):
px = im.getpixel((x, y))
if px[0]>230 and px[0]<250 and px[1]>140 and px[2]>140 and px[1]<208 and px[2]<208 and px[1] == px[2]:
pos=x,y
#px = im.getpixel((x, y))
print("Red="+str(pos))
#sys.exit()
return pos
roottrans=""
def spawntrans():
global roottrans
#roottrans = tk.Tk()
roottrans=tk.Toplevel()
if sys.platform in ['linux', 'linux2'] :
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
if sys.platform in ['Windows', 'win32', 'cygwin']:
w=GetSystemMetrics(0)
h=GetSystemMetrics(1)
h=95/100*h
starth=1.8/100*h
#roottrans.attributes('-alpha', 0.3)
roottrans.wm_attributes('-alpha',0.1,'-topmost',1)
roottrans.geometry('%dx%d+%d+%d' % (w, h, 0,starth))
roottrans.resizable(False, False)
roottrans.update_idletasks()
roottrans.overrideredirect(True)
def closetrans():
global roottrans
if roottrans:
roottrans.destroy()
roottrans=""
im=None
screengrab=True
sgrabauto=False
fnmove=False
detectred=False
rectcoordlist=[]
picdirlist=[]
if sys.platform in ['linux', 'linux2'] or sys.platform in ['Windows', 'win32', 'cygwin']:
def mouselu(event):
global textclick, clickStartX, clickStartY, clickStopX, clickStopY, objno2, Home,im
global picdirlist
rectcoordlist=[]
if pause==0 and not Home:
if sys.platform in ['linux', 'linux2']:
clickX, clickY=MouseGetPos()
if sys.platform in ['Windows', 'win32', 'cygwin']:
clickX, clickY=event.Position
#lastapp=active_window_process_name()
#if "FiiNote.exe" in lastapp:
# wsh.SendKeys("^s")
if (textclick==0):
clickStartX, clickStartY=clickX, clickY
print(clickStartX, clickStartY)
TT.config(text="C")
if screengrab or sgrabauto:
TT.config(text="C1")
#spawntrans()
if (linuxpc==0) and os.path.exists("/run/user/1000/gvfs/*/Internal"):
subprocess.call("adb shell \"su -c 'input keyevent KEYCODE_ESCAPE && sleep 0.1 && killall com.fiistudio.fiinote'\"", shell=True)
clickStartX, clickStartY=clickX, clickY
grabscreen()
#_thread.start_new_thread(grabscreen,())
textclick=1
if fnmove:
textclick=5
if detectred:
#sendthiskey("alt+3")
#sendthiskey("alt+s")
#mouseclick(clickStartX,clickStartY)
if sys.platform in ['linux', 'linux2'] :
sendthiskey("ctrl+x")
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
sendthiskey("^x")
pass
textclick=5
elif (textclick==1):
clickStopX, clickStopY=clickX, clickY
print(clickStopX, clickStopY)
clickStartX=int(clickStartX)
clickStartY=int(clickStartY)
clickStopX=int(clickStopX)
clickStopY=int(clickStopY)
TT.config(text="P")
if screengrab or sgrabauto:
if clickStartX<clickStopX and clickStartY<clickStopY:
global curattachdirpc
TT.config(text="P2")
#SS=SS1(clickStartX,clickStartY,clickStopX,clickStopY,curattachdirpc)
SS=SS2(clickStartX,clickStartY,clickStopX,clickStopY,curattachdirpc)
print(SS)
newdir1=getnewdirlatest()
if objno2<=2:
if screengrab:
columntype="nearlatest;;firstcolumn;;firstline"
if sgrabauto:
columntype="slide1"
rectcoordlist=everyletter(curattachdirpc,SS[2],"contouredc"+SS[2],1000,"",withcolour=True,testing=False,wledposdir="",rectcoordlist=rectcoordlist)
objno2=convertjpg2note(curattachdirpc,0,newdir1,objno2,"",rectcoordlist,"")
if objno2>2:
if screengrab:
columntype="nearlatest;;firstcolumn;;nextline"
if sgrabauto:
with open(curnotefpc, 'rb') as f:
content = f.read()
cihx=str(binascii.hexlify(content).decode('utf-8'))
regexc1=re.compile(patternpic)
print("findpatternpic1")
if regexc1.search(cihx):
print("findpatternpic2")
mox= re.search(patternpicx,cihx)
prevxcoordinate=mox.group(5)
prevycoordinate=mox.group(7)
prevdefyscale=mox.group(11)
prevendyscale=mox.group(13)
column="exactcopyrest;;"+prevycoordinate
print(str(column))
lastline=""
columntype="slidenextline"
rectcoordlist=everyletter(curattachdirpc,SS[2],"contouredc"+SS[2],1000,"",withcolour=True,testing=False,wledposdir="",rectcoordlist=rectcoordlist)
objno2=convertjpg2note(curattachdirpc,column,newdir1,objno2,"",rectcoordlist,"")
TT.config(text="DoneP")
#objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],newdir1,SS[4],columntype,rectcoordlist,"")
lastapp=active_window_process_name()
#if "FiiNote.exe" in lastapp and screengrab:
if "FiiNote.exe" in lastappglobal and screengrab:
print(lastappglobal)
pass
else:
objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],newdir1,SS[4],columntype,rectcoordlist,"")
imgdir=curattachdirpc+os.path.sep+SS[2]
picdirlist.append(imgdir)
if (linuxpc==0) and os.path.exists("/run/user/1000/gvfs/*/Internal"):
subprocess.call("adb push -p "+imgdir+" "+fnnotesanddirint+newdir1+".notz/attach",shell=True)
TT2.config(text=str(objno2))
##subprocess.call("adb shell su -c 'monkey -p com.fiistudio.fiinote -c android.intent.category.LAUNCHER 1'", shell=True)
## \\"su -c 'killall com.fiistudio.fiinote'\\"
#except :
##TT.config(text="try")
##monkey -p com.fiistudio.fiinote.editor.Fiinote -c android.intent.category.LAUNCHER 1
textclick=0
#closetrans()
else:
TT.config(text="Rep")
if fnmove:
textclick=6
TT.config(text="pasting")
if detectred:
if sys.platform in ['linux', 'linux2'] :
#sendthiskey("alt+3 alt+s")
#sendthiskey("ctrl+v")
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
#sendthiskey("!3")
#sendthiskey("!s")
#sendthiskey("^v")
pass
time.sleep(0.5)
TT.config(text="lookred")
Redpos=FindColor()
if "None" in str(Redpos):
TT.config(text="noRed")
else:
RedX, RedY=Redpos
clickStartX,clickStartY=str(RedX+20),RedY
TT.config(text="gotRed")
#if sys.platform in ['linux', 'linux2'] :
# sendthiskey("alt+3 alt+s")
#if sys.platform in ['Windows', 'win32', 'cygwin']:
# sendthiskey("!3")
# sendthiskey("!s")
#time.sleep(0.3)
mouseclick(clickStartX,clickStartY)
time.sleep(0.1)
dragfromto(clickStartX,clickStartY,clickStopX,clickStopY)
textclick=0
if fnmove:
if textclick==5:
textclick=1
def task2():
global root,TT,TT2
#global fnnotesdirpc
root=tk.Tk()
#root=tk.Toplevel()
m = Button(root, text="Pause R", command=Suspend1,height=3,width=3)
m.pack()
newf = Button(root, text="New F", command=newnotz1,height=3,width=3)
newf.pack()
clickmodebutton = Button(root, text="clickmode", command=changeclickmode,height=3,width=3)
clickmodebutton.pack()
selallk = Button(root, text="selallcp", command=selallkey,height=3,width=3)
selallk.pack()
copyk = Button(root, text="copy", command=copykey,height=3,width=3)
copyk.pack()
pastek = Button(root, text="paste", command=pastekey,height=3,width=3)
pastek.pack()
delk = Button(root, text="delete", command=delkey,height=3,width=3)
delk.pack()
restartgui=Button(root, text="restart", command=restartguifn,height=3,width=3)
restartgui.pack()
choosepdf=Button(root, text="choosepdf", command=choosepdfguiinit,height=3,width=3)
choosepdf.pack()
exitall=Button(root, text="exitsc", command=quitthis,height=1,width=3)
exitall.pack()
rnotz=Button(root, text="rbnotz", command=rebuildnotzguiinit,height=1,width=3)
rnotz.pack()
rindex=Button(root, text="rbindex", command=partial(rebuildindex,fnnotesdirpc),height=1,width=3)
rindex.pack()
#scmtext="cto=Normal"
#scmtext="cto=Auto"
#scmodeb=Button(root, text=str(scmtext), command=scmodechange,height=1,width=3)
#scmodeb.pack()
TT=Label(root, relief='raised')
TT.pack()
TT2=Label(root)
TT2.pack()
#root.withdraw()
if sys.platform in ['linux', 'linux2'] :
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
if sys.platform in ['Windows', 'win32', 'cygwin']:
w=GetSystemMetrics(0)
h=GetSystemMetrics(1)
x = w-70
y = h-(h*1300/1440)
wn=50
#hn=800
hn=int(0.7*h)
root.wm_attributes('-alpha',0.50,'-topmost',1)
root.geometry('%dx%d+%d+%d' % (wn, hn, x,y))
root.resizable(False, False)
root.update_idletasks()
root.overrideredirect(True)
Suspend1()
#MainApplication(rootimgv).pack(side="top", fill="both", expand=True)
root.mainloop()
def pastethistoapp():
return True
def pastethistobend():
return True
def quitthis():
global root,hm, pro
hm.UnhookMouse()
hm.UnhookKeyboard()
if root:
root.destroy()
#os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
sys.exit()
exit()
quit()
os.exit(0)
def restartguifn():
global root
root.destroy()
root=""
time.sleep(0.5)
#if sys.platform in ['linux', 'linux2'] :
if sys.platform in ['Windows', 'win32', 'cygwin']:
#subprocess.call("%USERPROFILE%\\Documents\\GitHub\\FN35OCVbside\\fn33andguistart.bat",shell=True)
username=subprocess.getoutput("echo %USERNAME%")
if username=="SP3":
pythondir=userhomedir+"\\Documents\\Docs\\Automate\\3WinPython-32bit-3.5.3.1Qt5\\python-3.5.3\\python.exe"
subprocess.call(pythondir+" %USERPROFILE%\\Documents\\GitHub\\FN35OCVbside\\FN33and.py",shell=True)
time.sleep(2)
quitthis()
return True
def choosepdfguiinit():
_thread.start_new_thread(choosepdfgui,())
#choosepdfgui()
return True
def ClearTT():
TT.config(text="")
return True
def delkey():
if sys.platform in ['linux', 'linux2'] :
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
#wsh.AppActivate("Notepad") # select another application
#wsh.AppActivate("%USERPROFILE%\\Documents\\Docs\\Automate\\FiiNoteWINE\\FiiNote.exe")
focusprog("FiiNote")
wsh.SendKeys("%{TAB}")
time.sleep(0.3)
wsh.SendKeys("{DELETE}")
def selallkey():
if sys.platform in ['linux', 'linux2'] :
pass
if sys.platform in ['Windows', 'win32', 'cygwin']:
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
#wsh.AppActivate("Notepad") # select another application
#wsh.AppActivate("%USERPROFILE%\\Documents\\Docs\\Automate\\FiiNoteWINE\\FiiNote.exe")
focusprog("FiiNote")
wsh.SendKeys("%{TAB}")
time.sleep(0.3)
wsh.SendKeys("%s")
time.sleep(0.3)
wsh.SendKeys("^a") # send the keys you want
time.sleep(0.3)
wsh.SendKeys("^c")
def copykey():
#if sys.platform in ['linux', 'linux2'] :
if sys.platform in ['Windows', 'win32', 'cygwin']:
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
#wsh.AppActivate("Notepad") # select another application
#wsh.AppActivate("%USERPROFILE%\\Documents\\Docs\\Automate\\FiiNoteWINE\\FiiNote.exe")
focusprog("FiiNote")
wsh.SendKeys("%{TAB}")
time.sleep(0.3)
wsh.SendKeys("^c") # send the keys you want
def pastekey():
#if sys.platform in ['linux', 'linux2'] :
if sys.platform in ['Windows', 'win32', 'cygwin']:
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
#wsh.AppActivate("%USERPROFILE%\\Documents\\Docs\\Automate\\FiiNoteWINE\\FiiNote.exe")
#focusprog("Atom")
focusprog("FiiNote")
wsh.SendKeys("%{TAB}")
time.sleep(0.3)
wsh.SendKeys("^v") # send the keys you want
clickmode=0
def changeclickmode():
global screengrab, sgrabauto, fnmove,TT,textclick,clickmode
clickmode+=1
if clickmode==1:
screengrab=False
sgrabauto=True
fnmove=False
TT.config(text="sgrabauto")
elif clickmode==2:
screengrab=False
sgrabauto=False
fnmove=True
TT.config(text="fnmove")
elif clickmode>2 or clickmode==0:
clickmode=0
screengrab=True
sgrabauto=False
fnmove=False
TT.config(text="scrngrab")
"""
if screengrab and not fnmove:
screengrab=False
fnmove=True
TT.config(text="fnmove")
elif fnmove and not screengrab:
screengrab=True
fnmove=False
TT.config(text="scrngrab")
"""
textclick=0
import win32api
from win32con import *
import win32com.client as comclt
wsh=comclt.Dispatch("WScript.Shell")
nircmddir="%USERPROFILE%\\Documents\\GitHub\\FN35OCVbside\\others\\nircmd-x64\\nircmdc.exe"
from pynput.mouse import Button, Controller
mouse = Controller()
lastappglobal=""
def Suspend1():
global pause, textclick, screengrab
global picdirlist
global lastappglobal
fnpicmode=False
countscroll=0
if pause==0:
pause=1
TT.config(text="Suspended")
fiinotew10pcdir=userhomedir+"\\\\Documents\\\\Docs\\\\Automate\\\\FiiNoteWINE\\\\FiiNote.exe"
closetrans()
if sys.platform in ['Windows', 'win32', 'cygwin'] and screengrab:
#restartfn()
if picdirlist:
print("Copying picdirlist...")
for picdir in picdirlist:
#https://superuser.com/questions/372602/how-to-copy-picture-from-a-file-to-clipboard
print(nircmddir+" clipboard copyimage "+picdir)
subprocess.call(nircmddir+" clipboard copyimage "+picdir, shell=True)
lastapp=active_window_process_name()
if "FiiNote.exe" in lastapp:
#scrolldown
if not fnpicmode:
focusprog("FiiNote")
#sendthiskey("%{TAB}")
sendthiskey("%3")
sendthiskey("%s")
if len(picdirlist)>2:
#sendthiskey("^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
sendthiskey("^{=}")
fnpicmode=True
#win32api.mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -15, 0)
#mouse.scroll(0, 20)
sendthiskey("{DOWN}")
sendthiskey("^v")
time.sleep(0.1)
countscroll+=1
for f in range(countscroll):
#win32api.mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 15, 0)
sendthiskey("{UP}")
#mouse.scroll(0, -20)
pass
if len(picdirlist)>2:
sendthiskey("^{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
sendthiskey("^{-}")
picdirlist=[]
pass
elif pause==1:
pause=0
TT.config(text="Resume")
if sys.platform in ['Windows', 'win32', 'cygwin'] and screengrab:
picdirlist=[]
lastapp=active_window_process_name()
lastappglobal=lastapp
if "FiiNote.exe" in lastapp:
wsh.SendKeys("^s")
#subprocess.call("taskkill /F /IM FiiNote.exe /T",shell=True)
pass
spawntrans()
textclick=0
def wlstatus():
global wlareastatus
if wlareastatus==True:
wlareastatus=False
TT.config(text="wl=off")
elif wlareastatus==False:
wlareastatus=True
TT.config(text="wl=on")
def newnotz1():
global newdir1,objno2
#newnotz0()
#print(curnotzpc,curnotefpc,curattachdirpc,curnotzand,curattachdirand)
newdir1,objno2=newnotz(fnnotesdirpc,fnnotesdirpc)
TT2.config(text="NEW")
def term(scriptn):
if sys.platform in ['linux', 'linux2'] :
python_path=""
subprocess.call("python3 "+str(dir0)+"/"+str(scriptn)+".py", shell=True)
print(python_path+"sudo python3 "+str(dir0)+"/"+scriptn)
if sys.platform in ['Windows', 'win32', 'cygwin']:
python_path=dir0+os.path.sep+"WinPython-32bit-3.5.3.1Qt5"+os.path.sep+"scripts"+os.path.sep
subprocess.call(python_path+"python "+str(dir0)+"\\"+str(scriptn)+".py", shell=True)
return True
def choosepdfgui0():
global rootimgv,Top,Mid,mfwidth,mfheight
if sys.platform in ['Windows', 'win32', 'cygwin']:
userhomedir=subprocess.getoutput("echo %USERPROFILE%")
#rootimgv = tk.Tk()
rootimgv=tk.Toplevel()
width = 600
height = 300
screen_width = rootimgv.winfo_screenwidth()
screen_height = rootimgv.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (height/2)
rootimgv.geometry("%dx%d+%d+%d" % (width, height, x, y))
rootimgv.resizable(0, 0)
#================================FRAMES=========================================
mfwidth=500
mfheight=200
Top = Frame(rootimgv, width=mfwidth, bd=1, relief=SOLID)
Top.pack(side=TOP)
Mid = Frame(rootimgv, width=mfwidth, height=mfheight, bd=1, relief=SOLID)
Mid.pack_propagate(0)
Mid.pack(pady=20)
lbl_title = Label(Top, text="Python: Simple Image Viewer", width=mfwidth, font=("arial", 20))
lbl_title.pack(fill=X)
allfilesdir,allfilesname,allfilesfulldir=listfilesext(dir0,".pdf")
placebutton(allfilesdir,allfilesname,allfilesfulldir)
#rootimgv.mainloop()
def choosepdfgui():
global Top,Mid,mfwidth,mfheight,Home1
if sys.platform in ['Windows', 'win32', 'cygwin']:
userhomedir=subprocess.getoutput("echo %USERPROFILE%")
Home1=Toplevel()
width = 600
height = 800
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (height/2)
Home1.geometry("%dx%d+%d+%d" % (width, height, x, y))
Home1.resizable(0, 0)
#================================FRAMES=========================================
mfwidth=600
mfheight=800
Top = Frame(Home1, width=mfwidth, bd=1, relief=SOLID)
Top.pack(side=TOP)
Mid = Frame(Home1, width=mfwidth, height=mfheight, bd=1, relief=SOLID)
Mid.pack_propagate(0)
Mid.pack(pady=20)
lbl_title = Label(Top, text="Python: Simple Image Viewer", width=mfwidth, font=("arial", 20))
lbl_title.pack(fill=X)
allfilesdir,allfilesname,allfilesfulldir=listfilesext(dir0,".pdf")
placebutton(allfilesdir,allfilesname,allfilesfulldir,Top,Mid)
#https://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application
#https://www.sourcecodester.com/tutorials/python/12128/python-simple-image-viewer.html
#================================METHODS========================================
def changepage(pdfdir,pdfname,lastpage,ptype):
global Home1,Home,panel,panel1
if panel1:
panel1.destroy()
if panel:
panel.destroy()
if ptype=="prev":
choosepage=int(lastpage)-1
elif ptype=="next":
choosepage=int(lastpage)+1
print("lpcp="+str(choosepage))
DisplayImage(pdfdir,pdfname,choosepage,[])
return True
def choosepageguiinit(pdfdir,pdfname):
_thread.start_new_thread(partial(choosepagegui,pdfdir,pdfname),())
def choosepagegui(pdfdir,pdfname):
def show_entry_fields():
print("First Name: %s" % (e1.get()))
choosepage=int(e1.get())
DisplayImage(pdfdir,pdfname,choosepage,[])
print(pdfdir+" "+pdfname)
Home2=Toplevel()
Label(Home2, text="Page").grid(row=0)
e1 = Entry(Home2)
e1.grid(row=0, column=1)
Button(Home2, text='Show', command=show_entry_fields).grid(row=3, column=0, sticky=W, pady=4)
def rebuildnotzguiinit():
_thread.start_new_thread(rebuildnotzgui,())
def rebuildnotzgui():
global curattachdirpc
def show_entry_fields():
global curattachdirpc,objno2
print("Attachdir: %s" % (e1.get()))
attachdir=str(e1.get())
if sys.platform in ['Windows', 'win32', 'cygwin']:
#attachdirfix=re.sub(r"\\\\","\\\\",attachdir)
attachdirfix=attachdir
else:
attachdirfix=attachdir
print(attachdirfix)
newnotz1()
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(attachdirfix) if isfile(join(attachdirfix, f))]
for files in onlyfiles:
picname=files
oldimgdir=attachdirfix+os.path.sep+files
newimgdir=curattachdirpc+os.path.sep+files
print("capc="+curattachdirpc,"obj2="+str(objno2),oldimgdir,newimgdir)
shutil.copy(oldimgdir,newimgdir)
w, h=imgsize(newimgdir)
objno2,curattachdirpc=appendnewpic(w,h,picname,newdir1,objno2,"nearlatest")
Home2=Toplevel()
Label(Home2, text="AttachDir").grid(row=0)
e1 = Entry(Home2)
e1.grid(row=0, column=1)
Button(Home2, text='Rebuild', command=show_entry_fields).grid(row=3, column=0, sticky=W, pady=4)
def whitelistpagearea(page,x,y):
import cv2
return True
def progresspage(page):
return True
def progresspagewhitelist():
return True
def perccolor(imgdir):
#https://stackoverflow.com/questions/43167867/color-percentage-in-image-python-opencv-using-histogram
import numpy as np
import cv2
img = cv2.imread(imgdir)
brown = [145, 80, 40] # RGB
diff = 20
boundaries = [([brown[2]-diff, brown[1]-diff, brown[0]-diff],
[brown[2]+diff, brown[1]+diff, brown[0]+diff])]
# in order BGR as opencv represents images as numpy arrays in reverse order
for (lower, upper) in boundaries:
lower = np.array(lower, dtype=np.uint8)
upper = np.array(upper, dtype=np.uint8)
mask = cv2.inRange(img, lower, upper)
output = cv2.bitwise_and(img, img, mask=mask)
ratio_brown = cv2.countNonZero(mask)/(img.size/3)
#print('brown pixel percentage:', np.round(ratio_brown*100, 2))
cv2.imshow("images", np.hstack([img, output]))
cv2.waitKey(0)
###bindkeyboardandmouse
###http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
##Example:http://www.java2s.com/Code/Python/Event/MouseeventsonaframeMouseclickedposition.htm
##https://www.daniweb.com/programming/software-development/threads/364829/mouse-position-tkinter
##class:https://stackoverflow.com/questions/3288047/how-do-i-get-mouse-position-relative-to-the-parent-widget-in-tkinter
#https://www.reddit.com/r/learnpython/comments/gwrig/questions_about_getting_mouse_coordinates_in/
#https://bytes.com/topic/python/answers/888796-how-get-x-coordinate-image
#https://stackoverflow.com/questions/38428593/getting-the-absolute-position-of-cursor-in-tkinter
#https://www.quora.com/In-Python-using-Tkinter-how-can-I-get-the-mouse-position-on-the-screen
#print root.winfo_pointerxy()
xpos1=""
ypos1=""
xpos2=""
ypos2=""
prevx1=""
prevx2=""
prevy1=""
prevy2=""
def gettkinterxypos(eventorigin,convimgdir,wledimgdir,pdfdir,pdfname,lastpage,anglecorrection,imgw,imgh,showimgw,showimgh):
global pause,textclick,wlareastatus
print(str(pause)+" "+str(textclick))
def callback():
global root
global textclick,pause,xpos1,ypos1,xpos2,ypos2
global prevx1,prevx2,prevy1,prevy2
global newdir1,objno2,curattachdirpc
global Home
global xcorrection,ycorrection
xcorrection=0
ycorrection=0
xandy=False
if pause==0 and textclick==0:
xpos1=eventorigin.x
ypos1=eventorigin.y
print(str(xpos1)+" "+str(ypos1))
textclick=1
elif pause==0 and textclick==1:
xpos2=eventorigin.x
ypos2=eventorigin.y
print(str(xpos2)+" "+str(ypos2))
if os.path.exists(wledimgdir):
global screenw,screenh
if screenw==1920 and screenh==1080:
ycorrection=10
else:
#ycorrection=20
ycorrection=0
if anglecorrection==270:
if ypos1>ypos2 and xpos2>xpos1:
xpos1ac=imgw-ypos1
xpos2ac=imgw-ypos2
ypos1ac=xpos1
ypos2ac=xpos2
xcorrection=60
ycorrection=0
xandy=True
elif ypos2>ypos1 and xpos2>xpos1:
xpos1ac=imgw-ypos2
xpos2ac=imgw-ypos1
ypos1ac=xpos1
ypos2ac=xpos2
xcorrection=60
ycorrection=0
else:
print("trya")
return True
actxp1=int(imgw/showimgw*xpos1ac)+xcorrection
actyp1=int(imgh/showimgh*ypos1ac)+ycorrection
actxp2=int(imgw/showimgw*xpos2ac)+xcorrection
actyp2=int(imgh/showimgh*ypos2ac)+ycorrection
else:
if screenh>screenw:
ycorrection=0
print(ycorrection)
xpos1ac=xpos1
xpos2ac=xpos2
ypos1ac=ypos1
ypos2ac=ypos2
actxp1=int(imgw/showimgw*xpos1ac)+xcorrection
actyp1=int(imgh/showimgh*ypos1ac)+ycorrection
actxp2=int(imgw/showimgw*xpos2ac)+xcorrection
actyp2=int(imgh/showimgh*ypos2ac)+ycorrection
print(actxp1,actxp2,actyp1,actyp2)
if (actxp2>actxp1 and actyp2>actyp1) or xandy:
SS=cutarea(pdfdir,pdfname,lastpage,actxp1,actyp1,actxp2,actyp2,convimgdir,anglecorrection)
print(SS)
if objno2<=2:
objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],SS[3],SS[4],"nearlatest;;firstcolumn;;firstline")
if objno2>2:
if prevx1 and actxp1>prevx1 and (actyp1 in range(prevy1-50,prevy1+50)):
objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],SS[3],SS[4],"nearlatest;;nextcolumn;;sameline")
elif prevx1 and actyp1>prevy1:
objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],SS[3],SS[4],"nearlatest;;firstcolumn;;nextline")
else:
objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],SS[3],SS[4],"nearlatest;;firstcolumn;;sameline")
#objno2,curattachdirpc=appendnewpic(SS[0],SS[1],SS[2],SS[3],SS[4],"nearlatest")
imgdir=curattachdirpc+os.path.sep+SS[2]
if (linuxpc==0) and os.path.exists("/run/user/1000/gvfs/*/Internal"):
subprocess.call("adb push -p "+imgdir+" "+fnnotesanddirint+newdir1+".notz/attach",shell=True)
##subprocess.call("adb shell su -c 'monkey -p com.fiistudio.fiinote -c android.intent.category.LAUNCHER 1'", shell=True)
## \"su -c 'killall com.fiistudio.fiinote'\"w
#except :
##TT.config(text="try")
##monkey -p com.fiistudio.fiinote.editor.Fiinote -c android.intent.category.LAUNCHER 1
TT.config(text="P")
TT2.config(text=str(objno2))
if wlareastatus:
loadimg=whitelistarea(pdfdir,pdfname,lastpage,actxp1,actyp1,actxp2,actyp2,wledimgdir)
DisplayImage(pdfdir,pdfname,lastpage,loadimg)
prevx1,prevx2,prevy1,prevy2=actxp1,actxp2,actyp1,actyp2
else:
TT.config(text="Rep")
textclick=0
pass
textclick=0
else:
textclick=0
pass
print("objno2="+str(objno2))
callback()
return True
def cutarea(pdfdir,pdfname,lastpage,actxp1,actyp1,actxp2,actyp2,convimgdir,anglecorrection):
global curattachdirpc,newdir1,objno2
picname=strftime("%Y%m%d%H%M%S")+'abcdefghijklmno.jpg'
imgdir=curattachdirpc+os.path.sep+picname
print(convimgdir)
print(imgdir)
print(str(actyp1)+" "+str(actyp2)+","+str(actxp1)+":"+str(actxp2))
temp=cv2.imread(convimgdir)
img=temp[actyp1:actyp2,actxp1:actxp2]
cv2.imwrite(imgdir,img)
w,h=imgsize(imgdir)
print(str(w)+" "+str(h))
print(newdir1+" "+str(objno2))
return w,h,picname,newdir1,objno2
def whitelistarea(pdfdir,pdfname,lastpage,actxp1,actyp1,actxp2,actyp2,wledimgdir):
convimgdir=re.sub(r"wled","conv",wledimgdir)
image=cv2.imread(wledimgdir)
#imgh,imgw,channels=image.shape
#load2=np.zeros((imgh,imgw,4))
cv2.rectangle(image, (actxp1, actyp1), (actxp2, actyp2), white_color, -1)
#cv2.imwrite(wledimgdir, image)
#src=cv2.imread(wledimgdir)
src=image
tmp = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
_,alpha = cv2.threshold(tmp,0,255,cv2.THRESH_BINARY)
b, g, r = cv2.split(src)
rgba = [b,g,r, alpha]
dst = cv2.merge(rgba,4)
cv2.imwrite(wledimgdir, dst)
print("donewlarea="+wledimgdir)
wledposfile=re.sub(r"wled","wledpos",wledimgdir)
wledposfile=re.sub(r"(.jpg|.png)","",wledposfile)
appendpos=str(actxp1)+","+str(actyp1)+","+str(actxp2)+","+str(actyp2)
print(appendpos)
appendtext(wledposfile,appendpos,"a")
return dst
def removelastlinefromfile(thefile):
#sys.argv[1]
file = open(thefile, "r+", encoding = "utf-8")
#Move the pointer (similar to a cursor in a text editor) to the end of the file.
file.seek(0, os.SEEK_END)
#This code means the following code skips the very last character in the file -
#i.e. in the case the last line is null we delete the last line
#and the penultimate one
pos = file.tell() - 1
#Read each character in the file one at a time from the penultimate
#character going backwards, searching for a newline character
#If we find a new line, exit the search
while pos > 0 and file.read(1) != "\n":
pos -= 1
file.seek(pos, os.SEEK_SET)
#So long as we're not at the start of the file, delete all the characters ahead of this position
if pos > 0:
file.seek(pos, os.SEEK_SET)
file.truncate()
file.close()
#https://mail.python.org/pipermail/python-list/2005-January/315395.html
def awk_it(instring,index,delimiter):
try:
return [instring,instring.split(delimiter)[index-1]][max(0,min(1,index))]
except:
return ""
#https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html
#https://stackoverflow.com/questions/14063070/overlay-a-smaller-image-on-a-larger-image-python-opencv
def undolatestwl(pdfdir,pdfname,convimgdir,wledimgdir,lastpage):
global Home
#imgtype="png"
#Home.destroy()
#wledimgdir=re.sub(r"conv","wled",convimgdir)
wledposfile=re.sub(r"conv","wledpos",convimgdir)
wledposfile=re.sub(r"(.jpg|.png)","",wledposfile)
with open(wledposfile, 'r') as f:
try:
lines = f.read().splitlines()
last_line = lines[-1]
print("lastline="+last_line)
except:
last_line=""
if last_line!="" :
temp = cv2.imread(convimgdir)
ypos1=int(awk_it(last_line,2,","))
ypos2=int(awk_it(last_line,4,","))
xpos1=int(awk_it(last_line,1,","))
xpos2=int(awk_it(last_line,3,","))
img=temp[ypos1:ypos2+3,xpos1:xpos2+3]
target=cv2.imread(wledimgdir)
if ".png" in wledimgdir:
print("png",str(xpos1),str(xpos2),str(ypos1),str(ypos2))
src=target
cv2.rectangle(src, (xpos1, ypos1), (xpos2+3, ypos2+3), black_color, -1)
tmp = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
_,alpha = cv2.threshold(tmp,0,255,cv2.THRESH_BINARY)
b, g, r = cv2.split(src)
rgba = [b,g,r, alpha]
dst = cv2.merge(rgba,4)
cv2.imwrite(wledimgdir, dst)
if ".jpg" in wledimgdir:
target[ypos1:ypos2+3,xpos1:xpos2+3]=img
#imgwled=re.sub("wled","img",wledimgdir)
#newwled=re.sub("wled","newwled",wledimgdir)
#cv2.imwrite(imgwled,img)
#cv2.imwrite(newwled, target)
cv2.imwrite(wledimgdir, target)
file = open(wledposfile)
filetext=file.read()
newwledpos=re.sub("\n"+last_line,"",str(filetext))
print("readf="+str(filetext),"nwwpos="+newwledpos)
appendtext(wledposfile,newwledpos,"w+")
#removelastlinefromfile(wledposfile)
DisplayImage(pdfdir,pdfname,lastpage,[])
return True
Home=""
choosepdfpagenext=""
choosepdfpageprev=""
undowlarea=""
cpageg=""
wlbutton=""
rootimgv=""
pdfdir=""
pdfname=""
pdfdir0=""
pdfname0=""
lastpage=""
load=None
imgh=None
imgw=None
panel=None
panel1=None
touchpanel=None
screenw=None
screenh=None
loadimg=None
prevlastpage=None
wlareastatus=True
black_color= (0, 0, 0, 255)
white_color= (255, 255, 255, 255)