-
Notifications
You must be signed in to change notification settings - Fork 98
/
jamscreenshot.py
2376 lines (2158 loc) · 118 KB
/
jamscreenshot.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
import gc
import math
import os
import re
import sys
import time
import cv2
from numpy import array, zeros, uint8, float32,array
from PyQt5.QtCore import QPoint, QRectF, QMimeData
from PyQt5.QtCore import QRect, Qt, pyqtSignal, QStandardPaths, QTimer, QSettings, QUrl
from PyQt5.QtGui import QCursor, QBrush, QScreen,QWindow
from PyQt5.QtGui import QPixmap, QPainter, QPen, QIcon, QFont, QImage, QColor
from PyQt5.QtWidgets import QApplication, QLabel, QPushButton, QTextEdit, QFileDialog, QMenu, QGroupBox, QSpinBox, \
QWidget
from PyQt5.QtWidgets import QSlider, QColorDialog
from jamWidgets import FramelessEnterSendQTextEdit,Freezer
from jampublic import OcrimgThread, Commen_Thread, TipsShower, PLATFORM_SYS,CONFIG_DICT
from jamroll_screenshot import Splicing_shots
import jamresourse
from pynput.mouse import Controller
def cut_polypng(img, pointlist): # 多边形裁剪
xlist = [i[0] for i in pointlist]
ylist = [i[1] for i in pointlist]
w = max(xlist) - min(xlist)
h = max(ylist) - min(ylist)
x0, y0 = min(xlist), min(ylist)
for i, lis in enumerate(pointlist):
pointlist[i] = [lis[0] - x0, lis[1] - y0]
img = img[y0:y0 + h, x0:x0 + w]
pts = array(pointlist)
pts = array([pts])
# 和原始图像一样大小的0矩阵,作为mask
mask = zeros(img.shape[:2], uint8)
# 在mask上将多边形区域填充为白色
cv2.polylines(mask, pts, 1, 255) # 描绘边缘
cv2.fillPoly(mask, pts, 255) # 填充
# 逐位与,得到裁剪后图像,此时是黑色背景
dstimg = cv2.bitwise_and(img, img, mask=mask)
return dstimg
def cut_mutipic(img, pointlist): # 透视裁剪
xlist = [i[0] for i in pointlist]
ylist = [i[1] for i in pointlist]
w = max(xlist) - min(xlist)
h = max(ylist) - min(ylist)
bl = w / abs(pointlist[0][0] - pointlist[1][0])
x0, y0 = min(xlist), min(ylist)
for i, lis in enumerate(pointlist):
pointlist[i] = [lis[0] - x0, lis[1] - y0]
img = img[y0:y0 + h, x0:x0 + w]
pts = array(pointlist)
pts = array([pts])
# 和原始图像一样大小的0矩阵,作为mask
mask = zeros(img.shape[:2], uint8)
# 在mask上将多边形区域填充为白色
cv2.polylines(mask, pts, 1, 255) # 描绘边缘
cv2.fillPoly(mask, pts, 255) # 填充
# 逐位与,得到裁剪后图像,此时是黑色背景
dstimg = cv2.bitwise_and(img, img, mask=mask)
# cv2.imshow("dst", dst)
tw = max(math.sqrt((pointlist[0][1] - pointlist[3][1]) ** 2 + (pointlist[0][0] - pointlist[3][0]) ** 2),
math.sqrt((pointlist[1][1] - pointlist[2][1]) ** 2 + (pointlist[1][0] - pointlist[2][0]) ** 2))
th = max(math.sqrt((pointlist[0][1] - pointlist[3][1]) ** 2 + (pointlist[0][0] - pointlist[3][0]) ** 2),
math.sqrt((pointlist[2][1] - pointlist[1][1]) ** 2 + (pointlist[2][0] - pointlist[1][0]) ** 2),
h)
# if bl>1:
# th=th*bl
tw, th = int(tw), int(th)
org = array(pointlist, float32)
dst = array([[0, 0],
[tw, 0],
[tw, th],
[0, th]], float32)
warpR = cv2.getPerspectiveTransform(org, dst)
result = cv2.warpPerspective(dstimg, warpR, (tw, th), borderMode=cv2.BORDER_TRANSPARENT)
# cv2.namedWindow("result",0)
# cv2.imshow("result", result)
# cv2.waitKey(0)
return result
def get_opposite_color(color: QColor):
return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue())
def image_fill(image, x, y, color: tuple = (0, 0, 255), d=0): # 泛洪填充
src = image.copy() # 先创建一个副本
cv2.floodFill(src, None, (x, y), color, (d, d, d), (d, d, d), cv2.FLOODFILL_FIXED_RANGE)
# cv2.circle(src, (x, y), 2, color=(0, 255, 0), thickness=4)
# cv2.imshow('flood_fill', src)
return src
def get_line_interpolation(p1, p2): # 线性插值
res = []
dy = p1[1] - p2[1]
dx = p1[0] - p2[0]
n = max(abs(dy), abs(dx))
nx = dx / n
ny = dy / n
for i in range(n):
res.append([p2[0] + i * nx, p2[1] + i * ny])
return res
class ColorButton(QPushButton):
select_color_signal = pyqtSignal(str)
def __init__(self, color, parent):
super(ColorButton, self).__init__("", parent)
self.color = QColor(color).name()
self.setStyleSheet("background-color:{}".format(self.color))
self.clicked.connect(self.sendcolor)
def sendcolor(self):
self.select_color_signal.emit(self.color)
class HoverButton(QPushButton):
hoversignal = pyqtSignal(int)
def enterEvent(self, e) -> None:
super(HoverButton, self).enterEvent(e)
self.hoversignal.emit(1)
print("enter")
def leaveEvent(self, e):
super(HoverButton, self).leaveEvent(e)
# time.sleep(2)
self.hoversignal.emit(0)
print("leave")
class HoverGroupbox(QGroupBox):
hoversignal = pyqtSignal(int)
def enterEvent(self, e) -> None:
super(HoverGroupbox, self).enterEvent(e)
self.hoversignal.emit(1)
print("enter")
def leaveEvent(self, e):
super(HoverGroupbox, self).leaveEvent(e)
# time.sleep(2)
self.hoversignal.emit(0)
print("leave")
class CanMoveGroupbox(QGroupBox): # 移动groupbox
def __init__(self, parent):
super(CanMoveGroupbox, self).__init__(parent)
self.drag = False
self.p_x, self.p_y = 0, 0
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton and event.x() < 100:
self.setCursor(Qt.SizeAllCursor)
self.drag = True
self.p_x, self.p_y = event.x(), event.y()
# super(CanMoveGroupbox, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.setCursor(Qt.ArrowCursor)
self.drag = False
# super(CanMoveGroupbox, self).mouseReleaseEvent(event)
def mouseMoveEvent(self, event):
if self.isVisible():
if self.drag:
self.move(event.x() + self.x() - self.p_x, event.y() + self.y() - self.p_y)
# super(CanMoveGroupbox, self).mouseMoveEvent(event)
class Finder(): # 选择智能选区
def __init__(self, parent):
self.h = self.w = 0
self.rect_list = self.contours = []
self.area_threshold = 200
self.parent = parent
self.img = None
def find_contours_setup(self):
try:
self.area_threshold = self.parent.parent.ss_areathreshold.value()
except:
self.area_threshold = 200
# t1 = time.process_time()
# self.img = cv2.imread('j_temp/get.png')
# t2 = time.process_time()
self.h, self.w, _ = self.img.shape
gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY) # 灰度化
# t3 = time.process_time()
# ret, th = cv2.threshold(gray, 50, 255, cv2.THRESH_BINARY)
th = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 2) # 自动阈值
# th = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_TRUNC, 11, 2) # 自动阈值
# t4 = time.process_time()
self.contours = cv2.findContours(th, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]
self.find_contours()
# print('setuptime', t2 - t1, t3 - t2, t4 - t3)
def find_contours(self):
draw_img = cv2.drawContours(self.img.copy(), self.contours, -1, (0, 255, 0), 1)
# cv2.imshow("tt", draw_img)
# cv2.imwrite("test.png", self.img.copy())
# cv2.waitKey(0)
# newcontours = []
self.rect_list = [[0, 0, self.w, self.h]]
for i in self.contours:
x, y, w, h = cv2.boundingRect(i)
area = cv2.contourArea(i)
if area > self.area_threshold and w > 10 and h > 10:
# cv2.rectangle(self.img, (x, y), (x + w, y + h), (0, 0, 255), 1)
# newcontours.append(i)
self.rect_list.append([x, y, x + w, y + h])
print('contours:', len(self.contours), 'left', len(self.rect_list))
def find_targetrect(self, point):
# print(len(self.rect_list))
# point = (1000, 600)
target_rect = [0, 0, self.w, self.h]
target_area = 1920 * 1080
for rect in self.rect_list:
if point[0] in range(rect[0], rect[2]):
# print('xin',rect)
if point[1] in range(rect[1], rect[3]):
# print('yin', rect)
area = (rect[3] - rect[1]) * (rect[2] - rect[0])
# print(area,target_area)
if area < target_area:
target_rect = rect
target_area = area
# print('target', target_area, target_rect)
# x,y,w,h=target_rect[0],target_rect[1],target_rect[2]-target_rect[0],target_rect[3]-target_rect[1]
# cv2.rectangle(self.img, (x, y), (x + w, y + h), (0, 0, 255), 1)
# cv2.imwrite("img.png", self.img)
return target_rect
def clear_setup(self):
self.h = self.w = 0
self.rect_list = self.contours = []
self.img = None
class MaskLayer(QLabel):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.setMouseTracking(True)
def paintEvent(self, e):
super().paintEvent(e)
if self.parent.on_init:
print('oninit return')
return
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
if self.parent.painter_tools["perspective_cut_on"]: # 透视裁剪工具
# painter.setPen(QPen(self.parent.pencolor, 3, Qt.SolidLine))
color = get_opposite_color(self.parent.pencolor)
for i in range(len(self.parent.perspective_cut_pointlist)):
painter.setPen(QPen(color, 10, Qt.SolidLine))
painter.drawPoint(
QPoint(self.parent.perspective_cut_pointlist[i][0], self.parent.perspective_cut_pointlist[i][1]))
painter.setPen(QPen(color, 3, Qt.SolidLine))
if i < len(self.parent.perspective_cut_pointlist) - 1:
painter.drawLine(self.parent.perspective_cut_pointlist[i][0],
self.parent.perspective_cut_pointlist[i][1],
self.parent.perspective_cut_pointlist[i + 1][0],
self.parent.perspective_cut_pointlist[i + 1][1])
else:
painter.drawLine(self.parent.perspective_cut_pointlist[i][0],
self.parent.perspective_cut_pointlist[i][1],
self.parent.mouse_posx, self.parent.mouse_posy)
painter.drawLine(self.parent.perspective_cut_pointlist[0][0],
self.parent.perspective_cut_pointlist[0][1],
self.parent.mouse_posx, self.parent.mouse_posy)
# 画网格
painter.setPen(QPen(QColor(120, 180, 120, 180), 1, Qt.SolidLine))
if len(self.parent.perspective_cut_pointlist) >= 2:
p0 = self.parent.perspective_cut_pointlist[0]
p1 = self.parent.perspective_cut_pointlist[1]
pp1 = pp0 = (self.parent.mouse_posx, self.parent.mouse_posy)
if len(self.parent.perspective_cut_pointlist) > 2:
pp1 = self.parent.perspective_cut_pointlist[2]
dx1 = pp1[0] - p1[0]
dy1 = pp1[1] - p1[1]
dx0 = pp0[0] - p0[0]
dy0 = pp0[1] - p0[1]
maxs = max(math.sqrt(dy0 ** 2 + dx0 ** 2), math.sqrt(dy1 ** 2 + dx1 ** 2))
if maxs > 25:
n = maxs // 25
ddx0 = dx0 / (n + 1)
ddy0 = dy0 / (n + 1)
ddx1 = dx1 / (n + 1)
ddy1 = dy1 / (n + 1)
for i in range(int(n) + 1):
painter.drawLine(pp0[0] - i * ddx0, pp0[1] - i * ddy0, pp1[0] - i * ddx1, pp1[1] - i * ddy1)
if len(self.parent.perspective_cut_pointlist) >= 3:
p0 = self.parent.perspective_cut_pointlist[1]
p1 = self.parent.perspective_cut_pointlist[2]
pp1 = (self.parent.mouse_posx, self.parent.mouse_posy)
pp0 = self.parent.perspective_cut_pointlist[0]
dx1 = pp1[0] - p1[0]
dy1 = pp1[1] - p1[1]
dx0 = pp0[0] - p0[0]
dy0 = pp0[1] - p0[1]
maxs = max(math.sqrt(dy0 ** 2 + dx0 ** 2), math.sqrt(dy1 ** 2 + dx1 ** 2))
if maxs > 25:
n = maxs // 25
ddx0 = dx0 / (n + 1)
ddy0 = dy0 / (n + 1)
ddx1 = dx1 / (n + 1)
ddy1 = dy1 / (n + 1)
for i in range(int(n) + 1):
painter.drawLine(pp0[0] - i * ddx0, pp0[1] - i * ddy0, pp1[0] - i * ddx1, pp1[1] - i * ddy1)
elif self.parent.painter_tools["polygon_ss_on"]: # 多边形截图
color = get_opposite_color(self.parent.pencolor)
for i in range(len(self.parent.polygon_ss_pointlist)):
painter.setPen(QPen(color, 3, Qt.SolidLine))
if i < len(self.parent.polygon_ss_pointlist) - 1:
painter.drawLine(self.parent.polygon_ss_pointlist[i][0],
self.parent.polygon_ss_pointlist[i][1],
self.parent.polygon_ss_pointlist[i + 1][0],
self.parent.polygon_ss_pointlist[i + 1][1])
else:
painter.drawLine(self.parent.polygon_ss_pointlist[i][0],
self.parent.polygon_ss_pointlist[i][1],
self.parent.mouse_posx, self.parent.mouse_posy)
painter.setPen(QPen(QColor(200, 200, 200, 222), 2, Qt.DashDotLine))
painter.drawLine(self.parent.polygon_ss_pointlist[0][0],
self.parent.polygon_ss_pointlist[0][1],
self.parent.mouse_posx, self.parent.mouse_posy)
elif not (self.parent.painter_tools['selectcolor_on'] or self.parent.painter_tools['bucketpainter_on']):
# 正常显示选区
rect = QRect(min(self.parent.x0, self.parent.x1), min(self.parent.y0, self.parent.y1),
abs(self.parent.x1 - self.parent.x0), abs(self.parent.y1 - self.parent.y0))
painter.setPen(QPen(Qt.green, 2, Qt.SolidLine))
painter.drawRect(rect)
painter.drawRect(0, 0, self.width(), self.height())
painter.setPen(QPen(QColor(0, 150, 0), 8, Qt.SolidLine))
painter.drawPoint(
QPoint(self.parent.x0, min(self.parent.y1, self.parent.y0) + abs(self.parent.y1 - self.parent.y0) // 2))
painter.drawPoint(
QPoint(min(self.parent.x1, self.parent.x0) + abs(self.parent.x1 - self.parent.x0) // 2, self.parent.y0))
painter.drawPoint(
QPoint(self.parent.x1, min(self.parent.y1, self.parent.y0) + abs(self.parent.y1 - self.parent.y0) // 2))
painter.drawPoint(
QPoint(min(self.parent.x1, self.parent.x0) + abs(self.parent.x1 - self.parent.x0) // 2, self.parent.y1))
painter.drawPoint(QPoint(self.parent.x0, self.parent.y0))
painter.drawPoint(QPoint(self.parent.x0, self.parent.y1))
painter.drawPoint(QPoint(self.parent.x1, self.parent.y0))
painter.drawPoint(QPoint(self.parent.x1, self.parent.y1))
x = y = 100
if self.parent.x1 > self.parent.x0:
x = self.parent.x0 + 5
else:
x = self.parent.x0 - 72
if self.parent.y1 > self.parent.y0:
y = self.parent.y0 + 15
else:
y = self.parent.y0 - 5
painter.setPen(QPen(Qt.darkGreen, 2, Qt.SolidLine))
painter.drawText(x, y,
'{}x{}'.format(abs(self.parent.x1 - self.parent.x0), abs(self.parent.y1 - self.parent.y0)))
painter.setPen(Qt.NoPen)
painter.setBrush(QColor(0, 0, 0, 120))
painter.drawRect(0, 0, self.width(), min(self.parent.y1, self.parent.y0))
painter.drawRect(0, min(self.parent.y1, self.parent.y0), min(self.parent.x1, self.parent.x0),
self.height() - min(self.parent.y1, self.parent.y0))
painter.drawRect(max(self.parent.x1, self.parent.x0), min(self.parent.y1, self.parent.y0),
self.width() - max(self.parent.x1, self.parent.x0),
self.height() - min(self.parent.y1, self.parent.y0))
painter.drawRect(min(self.parent.x1, self.parent.x0), max(self.parent.y1, self.parent.y0),
max(self.parent.x1, self.parent.x0) - min(self.parent.x1, self.parent.x0),
self.height() - max(self.parent.y1, self.parent.y0))
# 以下为鼠标放大镜
if not (self.parent.painter_tools['drawcircle_on'] or self.parent.painter_tools['drawrect_bs_on'] or
self.parent.painter_tools['pen_on'] or self.parent.painter_tools['eraser_on'] or
self.parent.painter_tools['drawtext_on'] or self.parent.painter_tools['backgrounderaser_on']
or self.parent.painter_tools['drawpix_bs_on'] or self.parent.move_rect):
select_color_mode = True if self.parent.painter_tools['selectcolor_on'] or self.parent.painter_tools['bucketpainter_on'] else False # 取色器或油漆桶
if self.parent.mouse_posx > self.width() - 140:
enlarge_box_x = self.parent.mouse_posx - 140
else:
enlarge_box_x = self.parent.mouse_posx + 20
if self.parent.mouse_posy > self.height() - 140:
enlarge_box_y = self.parent.mouse_posy - 120
else:
enlarge_box_y = self.parent.mouse_posy + 20
enlarge_rect = QRect(enlarge_box_x, enlarge_box_y, 120, 120)
painter.setPen(QPen(QColor(Qt.green), 1, Qt.SolidLine))
painter.drawRect(enlarge_rect)
painter.setBrush(QBrush(QColor(80, 80, 80, 180)))
painter.drawRect(QRect(enlarge_box_x, enlarge_box_y-43, enlarge_rect.width(), 43))
painter.setBrush(Qt.NoBrush)
# painter.drawRect(QRect(enlarge_box_x, enlarge_box_y-42, enlarge_rect.width(), 42))
color = QColor(self.parent.qimg.pixelColor(self.parent.mouse_posx, self.parent.mouse_posy))
RGB_color = [color.red(), color.green(), color.blue()]
HSV_color = cv2.cvtColor(array([[RGB_color]], dtype=uint8),cv2.COLOR_RGB2HSV).tolist()[0][0]
painter.drawText(enlarge_box_x, enlarge_box_y - 6,
' POS:({},{}) {}'.format(self.parent.mouse_posx, self.parent.mouse_posy,color.name().upper()if select_color_mode else ""))
painter.drawText(enlarge_box_x, enlarge_box_y - 18,
" HSV:({},{},{})".format(HSV_color[0], HSV_color[1], HSV_color[2]))
painter.drawText(enlarge_box_x, enlarge_box_y - 30,
" RGB:({},{},{})".format(RGB_color[0],RGB_color[1],RGB_color[2]))
if select_color_mode:
painter.setBrush(QBrush(color))
painter.drawRect(QRect(enlarge_box_x - 20, enlarge_box_y, 20, 20))
painter.setBrush(Qt.NoBrush)
try: # 鼠标放大镜
painter.setCompositionMode(QPainter.CompositionMode_Source)
rpix = QPixmap(self.width() + 120, self.height() + 120)
rpix.fill(QColor(0, 0, 0))
rpixpainter = QPainter(rpix)
rpixpainter.drawPixmap(60, 60, self.parent.pixmap())
rpixpainter.end()
larger_pix = rpix.copy(self.parent.mouse_posx, self.parent.mouse_posy, 120, 120).scaled(
120 + self.parent.tool_width * 10, 120 + self.parent.tool_width * 10)
pix = larger_pix.copy(larger_pix.width() // 2 - 60, larger_pix.height() // 2 - 60, 120, 120)
painter.drawPixmap(enlarge_box_x, enlarge_box_y, pix)
painter.setPen(QPen(Qt.green, 1, Qt.SolidLine))
painter.drawLine(enlarge_box_x, enlarge_box_y + 60, enlarge_box_x + 120, enlarge_box_y + 60)
painter.drawLine(enlarge_box_x + 60, enlarge_box_y, enlarge_box_x + 60, enlarge_box_y + 120)
except:
print('draw_enlarge_box fail')
painter.end()
class PaintLayer(QLabel):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
self.setAttribute(Qt.WA_TranslucentBackground, True)
# self.setAutoFillBackground(False)
# self.setPixmap(QPixmap())
self.setMouseTracking(True)
self.px = self.py = -50
self.pixpng = QPixmap(":/msk.jpg")
def paintEvent(self, e):
super().paintEvent(e)
if self.parent.on_init:
print('oninit return')
return
if 1 in self.parent.painter_tools.values(): # 如果有画笔工具打开
painter = QPainter(self)
color = QColor(self.parent.pencolor)
color.setAlpha(255)
width = self.parent.tool_width
if self.parent.painter_tools['selectcolor_on'] or self.parent.painter_tools['bucketpainter_on']:
width = 5
color = QColor(Qt.white)
painter.setPen(QPen(color, 1, Qt.SolidLine))
rect = QRectF(self.px - width // 2, self.py - width // 2,
width, width)
painter.drawEllipse(rect) # 画鼠标圆
painter.end()
# self.pixPainter.begin()
try:
self.pixPainter = QPainter(self.pixmap())
self.pixPainter.setRenderHint(QPainter.Antialiasing)
except:
print('pixpainter fail!')
while len(self.parent.eraser_pointlist): # 橡皮擦工具
# self.pixPainter.setRenderHint(QPainter.Antialiasing)
self.pixPainter.setBrush(QColor(0, 0, 0, 0))
self.pixPainter.setPen(Qt.NoPen)
self.pixPainter.setCompositionMode(QPainter.CompositionMode_Clear)
new_pen_point = self.parent.eraser_pointlist.pop(0)
if self.parent.old_pen is None:
self.parent.old_pen = new_pen_point
continue
if self.parent.old_pen[0] != -2 and new_pen_point[0] != -2:
self.pixPainter.drawEllipse(new_pen_point[0] - self.parent.tool_width / 2,
new_pen_point[1] - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
if abs(new_pen_point[0] - self.parent.old_pen[0]) > 1 or abs(
new_pen_point[1] - self.parent.old_pen[1]) > 1:
interpolateposs = get_line_interpolation(new_pen_point[:], self.parent.old_pen[:])
if interpolateposs is not None:
for pos in interpolateposs:
x, y = pos
self.pixPainter.drawEllipse(x - self.parent.tool_width / 2,
y - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
self.parent.old_pen = new_pen_point
def get_ture_pen_alpha_color():
color = QColor(self.parent.pencolor)
if color.alpha() != 255:
al = self.parent.pencolor.alpha() / (self.parent.tool_width / 2)
if al > 1:
color.setAlpha(al)
else:
color.setAlpha(1)
return color
while len(self.parent.pen_pointlist): # 画笔工具
color = get_ture_pen_alpha_color()
self.pixPainter.setBrush(color)
self.pixPainter.setPen(Qt.NoPen)
# self.pixPainter.setPen(QPen(self.parent.pencolor, self.parent.tool_width, Qt.SolidLine))
self.pixPainter.setRenderHint(QPainter.Antialiasing)
new_pen_point = self.parent.pen_pointlist.pop(0)
if self.parent.old_pen is None:
self.parent.old_pen = new_pen_point
continue
if self.parent.old_pen[0] != -2 and new_pen_point[0] != -2:
self.pixPainter.drawEllipse(new_pen_point[0] - self.parent.tool_width / 2,
new_pen_point[1] - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
if abs(new_pen_point[0] - self.parent.old_pen[0]) > 1 or abs(
new_pen_point[1] - self.parent.old_pen[1]) > 1:
interpolateposs = get_line_interpolation(new_pen_point[:], self.parent.old_pen[:])
if interpolateposs is not None:
for pos in interpolateposs:
x, y = pos
self.pixPainter.drawEllipse(x - self.parent.tool_width / 2,
y - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
self.parent.old_pen = new_pen_point
while len(self.parent.drawpix_pointlist): # 贴图工具
brush = QBrush(self.parent.pencolor)
tpix = QPixmap(self.parent.tool_width, self.parent.tool_width)
tpix.fill(Qt.transparent)
tpixpainter = QPainter(tpix)
tpixpainter.setCompositionMode(QPainter.CompositionMode_Source)
tpixpainter.drawPixmap(0, 0, self.pixpng.scaled(self.parent.tool_width, self.parent.tool_width))
tpixpainter.setCompositionMode(QPainter.CompositionMode_DestinationIn)
if self.parent.pencolor.alpha() != 255:
al = self.parent.pencolor.alpha() / (self.parent.tool_width / 2)
else:
al = 255
tpixpainter.fillRect(tpix.rect(), QColor(0, 0, 0, al))
tpixpainter.end()
brush.setTexture(tpix)
self.pixPainter.setBrush(brush)
self.pixPainter.setPen(Qt.NoPen)
new_pen_point = self.parent.drawpix_pointlist.pop(0)
if self.parent.old_pen is None:
self.parent.old_pen = new_pen_point
continue
if self.parent.old_pen[0] != -2 and new_pen_point[0] != -2:
self.pixPainter.drawEllipse(new_pen_point[0] - self.parent.tool_width / 2,
new_pen_point[1] - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
if abs(new_pen_point[0] - self.parent.old_pen[0]) > 1 or abs(
new_pen_point[1] - self.parent.old_pen[1]) > 1:
interpolateposs = get_line_interpolation(new_pen_point[:], self.parent.old_pen[:])
if interpolateposs is not None:
for pos in interpolateposs:
x, y = pos
self.pixPainter.drawEllipse(x - self.parent.tool_width / 2,
y - self.parent.tool_width / 2,
self.parent.tool_width, self.parent.tool_width)
self.parent.old_pen = new_pen_point
if self.parent.drawrect_pointlist[0][0] != -2 and self.parent.drawrect_pointlist[1][0] != -2: # 画矩形工具
# print(self.parent.drawrect_pointlist)
temppainter = QPainter(self)
temppainter.setPen(QPen(self.parent.pencolor, self.parent.tool_width, Qt.SolidLine))
poitlist = self.parent.drawrect_pointlist
temppainter.drawRect(min(poitlist[0][0], poitlist[1][0]), min(poitlist[0][1], poitlist[1][1]),
abs(poitlist[0][0] - poitlist[1][0]), abs(poitlist[0][1] - poitlist[1][1]))
temppainter.end()
if self.parent.drawrect_pointlist[2] == 1:
self.pixPainter.setPen(QPen(self.parent.pencolor, self.parent.tool_width, Qt.SolidLine))
self.pixPainter.drawRect(min(poitlist[0][0], poitlist[1][0]), min(poitlist[0][1], poitlist[1][1]),
abs(poitlist[0][0] - poitlist[1][0]), abs(poitlist[0][1] - poitlist[1][1]))
self.parent.drawrect_pointlist = [[-2, -2], [-2, -2], 0]
# print("panit",self.parent.drawrect_pointlist)
# self.parent.drawrect_pointlist[0] = [-2, -2]
if self.parent.drawcircle_pointlist[0][0] != -2 and self.parent.drawcircle_pointlist[1][0] != -2: # 画圆工具
temppainter = QPainter(self)
temppainter.setPen(QPen(self.parent.pencolor, self.parent.tool_width, Qt.SolidLine))
poitlist = self.parent.drawcircle_pointlist
temppainter.drawEllipse(min(poitlist[0][0], poitlist[1][0]), min(poitlist[0][1], poitlist[1][1]),
abs(poitlist[0][0] - poitlist[1][0]), abs(poitlist[0][1] - poitlist[1][1]))
temppainter.end()
if self.parent.drawcircle_pointlist[2] == 1:
self.pixPainter.setPen(QPen(self.parent.pencolor, self.parent.tool_width, Qt.SolidLine))
self.pixPainter.drawEllipse(min(poitlist[0][0], poitlist[1][0]), min(poitlist[0][1], poitlist[1][1]),
abs(poitlist[0][0] - poitlist[1][0]), abs(poitlist[0][1] - poitlist[1][1]))
self.parent.drawcircle_pointlist = [[-2, -2], [-2, -2], 0]
# self.parent.drawcircle_pointlist[0] = [-2, -2]
if self.parent.drawarrow_pointlist[0][0] != -2 and self.parent.drawarrow_pointlist[1][0] != -2: # 画箭头
# print(self.parent.drawarrow_pointlist)
# self.pixPainter = QPainter(self.pixmap())
temppainter = QPainter(self)
# temppainter.setPen(QPen(self.parent.pencolor, 3, Qt.SolidLine))
# brush = QBrush(self.parent.pencolor)
# brush.setTexture(QPixmap(":/msk.jpg").scaled(225, 225))
# temppainter.setBrush(brush)
poitlist = self.parent.drawarrow_pointlist
temppainter.translate(poitlist[0][0], poitlist[0][1])
degree = math.degrees(math.atan2(poitlist[1][1] - poitlist[0][1], poitlist[1][0] - poitlist[0][0]))
temppainter.rotate(degree)
dx = math.sqrt((poitlist[1][1] - poitlist[0][1]) ** 2 + (poitlist[1][0] - poitlist[0][0]) ** 2)
dy = 30
temppainter.drawPixmap(0, -dy / 2, QPixmap(':/arrow.png').scaled(dx, dy))
temppainter.end()
if self.parent.drawarrow_pointlist[2] == 1:
self.pixPainter.translate(poitlist[0][0], poitlist[0][1])
degree = math.degrees(math.atan2(poitlist[1][1] - poitlist[0][1], poitlist[1][0] - poitlist[0][0]))
self.pixPainter.rotate(degree)
dx = math.sqrt((poitlist[1][1] - poitlist[0][1]) ** 2 + (poitlist[1][0] - poitlist[0][0]) ** 2)
dy = 30
self.pixPainter.drawPixmap(0, -dy / 2, QPixmap(':/arrow.png').scaled(dx, dy))
self.parent.drawarrow_pointlist = [[-2, -2], [-2, -2], 0]
# self.parent.drawarrow_pointlist[0] = [-2, -2]
if len(self.parent.drawtext_pointlist) > 1 or self.parent.text_box.paint: # 绘制文字
self.parent.text_box.paint = False
# print(self.parent.drawtext_pointlist)
text = self.parent.text_box.toPlainText()
self.parent.text_box.clear()
pos = self.parent.drawtext_pointlist.pop(0)
if text:
self.pixPainter.setFont(QFont('黑体', self.parent.tool_width))
self.pixPainter.setPen(QPen(self.parent.pencolor, 3, Qt.SolidLine))
self.pixPainter.drawText(pos[0] + self.parent.text_box.document.size().height() / 8,
pos[1] + self.parent.text_box.document.size().height() * 32 / 41, text)
self.parent.backup_shortshot()
self.parent.setFocus()
self.update()
# self.repaint()
try:
self.pixPainter.end()
except:
print("pixpainter end fail!")
class AutotextEdit(QTextEdit):
def __init__(self, parent=None):
super().__init__(parent)
self.document = self.document()
self.document.contentsChanged.connect(self.textAreaChanged)
self.setLineWrapMode(QTextEdit.NoWrap)
self.paint = False
self.parent = parent
def textAreaChanged(self, minsize=0):
self.document.adjustSize()
newWidth = self.document.size().width() + 25
newHeight = self.document.size().height() + 15
if newWidth != self.width():
if newWidth < minsize:
self.setFixedWidth(minsize)
else:
self.setFixedWidth(newWidth)
if newHeight != self.height():
if newHeight < minsize:
self.setFixedHeight(minsize)
else:
self.setFixedHeight(newHeight)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Return:
self.paint = True
self.hide()
super().keyPressEvent(e)
def keyReleaseEvent(self, e):
if e.key() == Qt.Key_Return:
self.parent.update()
super().keyReleaseEvent(e)
class Slabel(QLabel): # 区域截图功能
showm_signal = pyqtSignal(str)
recorder_recordchange_signal = pyqtSignal()
close_signal = pyqtSignal()
ocr_image_signal = pyqtSignal(str)
screen_shot_result_signal = pyqtSignal(str)
screen_shot_end_show_sinal = pyqtSignal(QPixmap)
set_area_result_signal = pyqtSignal(list)
getpix_result_signal = pyqtSignal(tuple,QPixmap)
def __init__(self, parent=None):
super().__init__()
# self.ready_flag = False
self.parent = parent
if not os.path.exists("j_temp"):
os.mkdir("j_temp")
# self.pixmap()=QPixmap()
def setup(self,mode = "screenshot"): # 初始化界面
self.on_init = True
self.mode = mode
self.paintlayer = PaintLayer(self) # 绘图层
self.mask = MaskLayer(self) # 遮罩层
self.text_box = AutotextEdit(self) # 文字工具类
self.ocr_freezer = None
self.shower = FramelessEnterSendQTextEdit(self, enter_tra=True) # 截屏时文字识别的小窗口
self.settings = QSettings('Fandes', 'jamtools')
self.setMouseTracking(True)
if PLATFORM_SYS == "darwin":
self.setWindowFlags(Qt.FramelessWindowHint)
else:
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint) # Sheet
# self.setAttribute(Qt.WA_TransparentForMouseEvents, True)
self.botton_box = QGroupBox(self) # botton_box是截屏选框旁边那个按钮堆的box
self.save_botton = QPushButton(QIcon(":/saveicon.png"), '', self.botton_box)
self.save_botton.clicked.connect(lambda: self.cutpic(1))
self.ssrec_botton = QPushButton(QIcon(":/ssrecord.png"), '', self.botton_box)
self.ocr_botton = QPushButton(self.botton_box)
self.roll_ss_btn = QPushButton(self.botton_box)
self.sure_btn = QPushButton("确定", self.botton_box)
self.freeze_img_botton = QPushButton(self.botton_box)
self.pencolor = QColor(Qt.red)
self.painter_box = CanMoveGroupbox(self) # painter_box是绘图工具堆里的那个box,可移动
self.choice_clor_btn = HoverButton('', self.painter_box)
self.selectcolor_btn = QPushButton("", self.painter_box)
self.original_btn = QPushButton("", self.painter_box)
self.size_slider = QSlider(Qt.Vertical, self.painter_box)
self.alpha_slider = QSlider(Qt.Vertical, self.painter_box)
self.sizetextlabel = QLabel(self.painter_box)
self.alphatextlabel = QLabel(self.painter_box)
self.size_slider_label = QLabel(self.painter_box)
self.alpha_slider_label = QLabel(self.painter_box)
self.drawarrow = QPushButton('', self.painter_box)
self.msk = QPushButton('', self.painter_box)
self.choise_pix = QPushButton('', self.painter_box)
self.drawcircle = QPushButton('', self.painter_box)
self.bs = QPushButton('', self.painter_box)
self.drawtext = QPushButton('', self.painter_box)
self.pen = QPushButton('', self.painter_box)
self.eraser = QPushButton('', self.painter_box)
self.backgrounderaser = QPushButton('', self.painter_box)
self.smartcursor_btn = QPushButton('', self.painter_box)
self.bucketpainter_btn = QPushButton("", self.painter_box)
self.bucketpainter_tolerance = QSpinBox(self.painter_box)
self.backgroundrepair_btn = QPushButton("", self.painter_box)
self.perspective_cut_btn = QPushButton("", self.painter_box)
self.polygon_ss_btn = QPushButton("", self.painter_box)
self.lastbtn = QPushButton("", self.painter_box)
self.nextbtn = QPushButton("", self.painter_box)
self.finder = Finder(self) # 智能选区的寻找器
self.Tipsshower = TipsShower(" ", targetarea=(100, 70, 0, 0), parent=self) # 左上角的大字提示
self.Tipsshower.hide()
self.shower.showm_signal.connect(self.Tipsshower.setText)
if PLATFORM_SYS == "darwin":
self.init_slabel_ui()
print("init slabel ui")
else:
self.init_slabel_ui()
print("init slabel ui")
# self.init_slabel_thread = Commen_Thread(self.init_slabel_ui)
# self.init_slabel_thread.start()
if mode != "screenshot":#非截屏模式(jamtools中也会调用截屏工具进行选取录屏或者文字识别)
self.painter_box.hide()
self.save_botton.hide()
self.freeze_img_botton.hide()
self.roll_ss_btn.hide()
self.ocr_botton.hide()
elif mode != "set_area":
self.ssrec_botton.hide()
# self.setVisible(False)
# self.setWindowOpacity(0)
# self.showFullScreen()
# self.hide()
# self.setWindowOpacity(1)
self.init_parameters()
self.backup_ssid = 0 # 当前备份数组的id,用于确定回退了几步
self.backup_pic_list = [] # 备份页面的数组,用于前进/后退
self.on_init = False
def init_parameters(self): # 初始化参数
self.NpainterNmoveFlag = self.choicing = self.move_rect = self.move_y0 = self.move_x0 = self.move_x1 \
= self.change_alpha = self.move_y1 = False
self.x0 = self.y0 = self.rx0 = self.ry0 = self.x1 = self.y1 = self.mouse_posx = self.mouse_posy = -50
self.screen_init_xy = [0, 0]
self.bx = self.by = 0
self.alpha = 255 # 透明度值
self.smartcursor_on = self.settings.value("screenshot/smartcursor", True, type=bool)
self.finding_rect = True # 正在自动寻找选取的控制变量,就进入截屏之后会根据鼠标移动到的位置自动选取,
self.tool_width = 5
self.roller_area = (0, 0, 1, 1)
self.backgrounderaser_pointlist = [] # 下面xxpointlist都是储存绘图数据的列表
self.eraser_pointlist = []
self.pen_pointlist = []
self.drawpix_pointlist = []
self.repairbackground_pointlist = []
self.drawtext_pointlist = []
self.perspective_cut_pointlist = []
self.polygon_ss_pointlist = []
self.drawrect_pointlist = [[-2, -2], [-2, -2], 0]
self.drawarrow_pointlist = [[-2, -2], [-2, -2], 0]
self.drawcircle_pointlist = [[-2, -2], [-2, -2], 0]
self.painter_tools = {'drawpix_bs_on': 0, 'drawarrow_on': 0, 'drawcircle_on': 0, 'drawrect_bs_on': 0,
'pen_on': 0, 'eraser_on': 0, 'drawtext_on': 0,
'backgrounderaser_on': 0, 'selectcolor_on': 0, "bucketpainter_on": 0,
"repairbackground_on": 0, "perspective_cut_on": 0, "polygon_ss_on": 0}
self.old_pen = self.old_eraser = self.old_brush = self.old_backgrounderaser = [-2, -2]
self.left_button_push = False
def init_slabel_ui(self): # 初始化界面的参数
self.shower.hide()
# self.shower.setWindowOpacity(0.8)
# if PLATFORM_SYS == "darwin":
# self.move(-QApplication.desktop().width(), -QApplication.desktop().height())
self.setToolTip("左键框选,右键返回")
self.ssrec_botton.setGeometry(0, 0, 40, 35)
self.ssrec_botton.clicked.connect(self.ssrec)
self.ssrec_botton.setToolTip('开始录屏')
self.save_botton.setGeometry(self.ssrec_botton.x() + self.ssrec_botton.width(), 0, 40, 35)
self.save_botton.setToolTip('另存为文件')
self.freeze_img_botton.setGeometry(self.save_botton.x() + self.save_botton.width(), 0, 40, 35)
self.freeze_img_botton.setIcon(QIcon(":/freeze.png"))
self.freeze_img_botton.setToolTip('固定图片于屏幕上')
self.freeze_img_botton.clicked.connect(self.freeze_img)
self.ocr_botton.setGeometry(self.freeze_img_botton.x() + self.freeze_img_botton.width(), 0, 40, 35)
self.ocr_botton.setIcon(QIcon(":/OCR.png"))
self.ocr_botton.setToolTip('文字识别')
self.ocr_botton.clicked.connect(self.ocr)
if PLATFORM_SYS == "darwin": # 不支持macos滚动截屏
self.roll_ss_btn.hide()
self.sure_btn.setGeometry(self.ocr_botton.x() + self.ocr_botton.width(), 0, 60, 35)
else:
self.roll_ss_btn.setGeometry(self.ocr_botton.x() + self.ocr_botton.width(), 0, 40, 35)
self.roll_ss_btn.clicked.connect(self.roll_shot)
self.roll_ss_btn.setToolTip('滚动截屏功能')
self.roll_ss_btn.setIcon(QIcon(":/scroll_icon.png"))
self.sure_btn.setGeometry(self.roll_ss_btn.x() + self.roll_ss_btn.width(), 0, 60, 35)
self.sure_btn.clicked.connect(self.cutpic)
a = self.roll_ss_btn.width() if PLATFORM_SYS != "darwin" else 0
if self.mode == "screenshot":
self.botton_box.resize(
self.sure_btn.width() + self.ocr_botton.width() + self.ssrec_botton.width()
+ a + self.save_botton.width() + self.freeze_img_botton.width(),
self.sure_btn.height())
elif self.mode == "set_area":
self.Tipsshower.setText("设置录屏区域...")
self.sure_btn.setGeometry(self.ssrec_botton.x() + self.ssrec_botton.width(), 0, 60, 35)
self.botton_box.resize(
self.sure_btn.width()+self.ssrec_botton.width(),
self.sure_btn.height())
else:
self.sure_btn.setGeometry(0, 0, 60, 35)
self.botton_box.resize(
self.sure_btn.width(),
self.sure_btn.height())
self.botton_box.hide()
self.painter_box.setGeometry(0, QApplication.desktop().height() // 2 - 200, 100, 400)
self.size_slider_label.setStyleSheet('background-color:rgba(0,0,0,0);color: rgb(255,255,255);')
self.size_slider_label.resize(20, 20)
self.size_slider.setGeometry(10, 20, 25, 60)
self.size_slider.setToolTip('设置画笔大小,也可用鼠标滚轮调节')
self.size_slider.valueChanged.connect(self.change_size_fun)
self.sizetextlabel.setText("size")
self.sizetextlabel.setGeometry(self.size_slider.x() - 2, self.size_slider.y() + self.size_slider.height() - 2,
35, 20)
self.sizetextlabel.setStyleSheet('background-color:rgba(0,0,0,0);color: rgb(255,255,255);')
self.size_slider.setMaximum(99)
self.size_slider.setValue(5)
self.size_slider.setMinimum(1)
self.size_slider_label.move(self.size_slider.x() + 5, 0)
self.size_slider.show()
self.alpha_slider_label.setStyleSheet('background-color:rgba(0,0,0,0);color: rgb(255,255,255);')
self.alpha_slider_label.resize(25, 20)
self.alpha_slider.setGeometry(55, 20, 25, 60)
self.alpha_slider.setToolTip('设置画笔透明度,按住Ctrl+滚轮也可以调节透明度')
self.alpha_slider.valueChanged.connect(self.change_alpha_fun)
self.alphatextlabel.setText("alpha")
self.alphatextlabel.setGeometry(self.alpha_slider.x() - 4,
self.alpha_slider.y() + self.alpha_slider.height() - 2,
40, 20)
self.alphatextlabel.setStyleSheet('background-color:rgba(0,0,0,0);color: rgb(255,255,255);')
self.alpha_slider.setMaximum(255)
self.alpha_slider.setValue(255)
self.alpha_slider.setMinimum(1)
self.alpha_slider_label.move(self.alpha_slider.x() + 2, 0)
self.alpha_slider.show()
# print(pic)
self.choice_clor_btn.setToolTip('选择画笔颜色,点击可选择更多')
self.choice_clor_btn.setIcon(QIcon(":/yst.png"))
self.choice_clor_btn.setGeometry(4, 100, 41, 28)
self.choice_clor_btn.clicked.connect(self.get_color)
self.choice_clor_btn.hoversignal.connect(self.Color_hoveraction)
self.selectcolor_btn.setIcon(QIcon(":/colorsampler.png"))
self.selectcolor_btn.setGeometry(50, self.choice_clor_btn.y(), self.choice_clor_btn.width(),
self.choice_clor_btn.height())
self.selectcolor_btn.setToolTip("取色器")
self.selectcolor_btn.clicked.connect(self.selectcolor)
self.msk.setToolTip('材质贴图工具,可以充当马赛克')
self.msk.setIcon(QIcon(":/mskicon.png"))
self.msk.setGeometry(self.choice_clor_btn.x(), self.choice_clor_btn.y() + self.choice_clor_btn.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.msk.clicked.connect(self.change_msk_fun)
self.choise_pix.setToolTip('选择笔刷材质贴图')
self.choise_pix.setIcon(QIcon(":/msk.jpg"))
self.choise_pix.setGeometry(35, self.msk.y(), self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.choise_pix.clicked.connect(self.choise_drawpix_fun)
self.choise_pix.setStyleSheet("background-color:rgb(255,255,255);border: 3px solid #ffffff;")
self.choise_pix.hide()
self.drawarrow.setToolTip('绘制箭头')
self.drawarrow.setIcon(QIcon(":/arrowicon.png"))
self.drawarrow.setGeometry(self.selectcolor_btn.x(), self.selectcolor_btn.y() + self.selectcolor_btn.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.drawarrow.clicked.connect(self.draw_arrow_fun)
self.drawcircle.setToolTip('绘制圆')
self.drawcircle.setIcon(QIcon(":/circle.png"))
self.drawcircle.setGeometry(self.choice_clor_btn.x(), self.msk.y() + self.msk.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.drawcircle.clicked.connect(self.drawcircle_fun)
self.bs.setToolTip('绘制矩形')
self.bs.setIcon(QIcon(":/rect.png"))
self.bs.setGeometry(self.drawarrow.x(), self.drawarrow.y() + self.drawarrow.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.bs.clicked.connect(self.change_bs_fun)
self.drawtext.setToolTip('绘制文字')
self.drawtext.setIcon(QIcon(":/texticon.png"))
self.drawtext.setGeometry(self.choice_clor_btn.x(), self.drawcircle.y() + self.drawcircle.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.drawtext.clicked.connect(self.drawtext_fun)
self.pen.setToolTip('画笔工具')
self.pen.setIcon(QIcon(":/pen.png"))
self.pen.setGeometry(self.bs.x(), self.bs.y() + self.bs.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.pen.clicked.connect(self.change_pen_fun)
self.eraser.setToolTip('橡皮擦')
self.eraser.setIcon(QIcon(":/eraser.png"))
self.eraser.setGeometry(self.choice_clor_btn.x(), self.drawtext.y() + self.drawtext.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.eraser.clicked.connect(self.clear_paint_fun)
self.backgrounderaser.setIcon(QIcon(":/backgrounderaser.png"))
self.backgrounderaser.setToolTip('背景橡皮擦,图片包含透明通道,擦除部分图片将变透明,\n但由于win的剪切板不支持透明通道,只有另存时透明通道才有作用!')
self.backgrounderaser.setGeometry(self.pen.x(), self.pen.y() + self.pen.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.backgrounderaser.clicked.connect(self.clear_background_fun)
self.backgroundrepair_btn.setIcon(QIcon(":/backgroundrepair.png"))
self.backgroundrepair_btn.setToolTip('背景修复画笔,用于将背景图片层复原')
self.backgroundrepair_btn.setGeometry(self.backgrounderaser.x(),
self.backgrounderaser.y() + self.backgrounderaser.height(),
self.choice_clor_btn.width(), self.choice_clor_btn.height())
self.backgroundrepair_btn.clicked.connect(self.repair_background_fun)
self.bucketpainter_btn.setToolTip("油漆桶工具")
self.bucketpainter_btn.setIcon(QIcon(":/yqt.png"))
self.bucketpainter_btn.setGeometry(self.choice_clor_btn.x(),
self.backgrounderaser.y() + self.backgrounderaser.height(),