Skip to content

Commit 48ef9a5

Browse files
committed
support PySide2
1 parent e397db8 commit 48ef9a5

File tree

220 files changed

+2460
-2545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+2460
-2545
lines changed

Demo/AutoRestart.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
Created on 2017年3月31日
6-
@author: Irony."[讽刺]
7-
@site: https://pyqt5.com , https://github.com/892768447
6+
@author: Irony
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: AutoRestart
1010
@description:
11-
'''
11+
"""
1212

13-
from optparse import OptionParser
1413
import os
1514
import sys
15+
from optparse import OptionParser
1616

17-
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout
18-
17+
try:
18+
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout
19+
except ImportError:
20+
from PySide2.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout
1921

2022
canRestart = True
2123

Demo/BubbleTips.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
Created on 2018年1月27日
6-
@author: Irony."[讽刺]
7-
@site: https://pyqt5.com , https://github.com/892768447
6+
@author: Irony
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: BubbleTips
1010
@description:
11-
'''
11+
"""
1212
import sys
1313

14-
from PyQt5.QtCore import QRectF, Qt, QPropertyAnimation, pyqtProperty, \
15-
QPoint, QParallelAnimationGroup, QEasingCurve
16-
from PyQt5.QtGui import QPainter, QPainterPath, QColor, QPen
17-
from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication,\
18-
QLineEdit, QPushButton
19-
20-
21-
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
22-
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
23-
__Version__ = "Version 1.0"
14+
try:
15+
from PyQt5.QtCore import QRectF, Qt, QPropertyAnimation, pyqtProperty, \
16+
QPoint, QParallelAnimationGroup, QEasingCurve
17+
from PyQt5.QtGui import QPainter, QPainterPath, QColor, QPen
18+
from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication, \
19+
QLineEdit, QPushButton
20+
except ImportError:
21+
from PySide2.QtCore import QRectF, Qt, QPropertyAnimation, Property as pyqtProperty, \
22+
QPoint, QParallelAnimationGroup, QEasingCurve
23+
from PySide2.QtGui import QPainter, QPainterPath, QColor, QPen
24+
from PySide2.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication, \
25+
QLineEdit, QPushButton
2426

2527

2628
class BubbleLabel(QWidget):
27-
2829
BackgroundColor = QColor(195, 195, 195)
2930
BorderColor = QColor(150, 150, 150)
3031

@@ -133,10 +134,10 @@ def setWindowOpacity(self, opacity):
133134
opacity = pyqtProperty(float, windowOpacity, setWindowOpacity)
134135

135136

136-
class TestWidget(QWidget):
137+
class Window(QWidget):
137138

138139
def __init__(self, *args, **kwargs):
139-
super(TestWidget, self).__init__(*args, **kwargs)
140+
super(Window, self).__init__(*args, **kwargs)
140141
layout = QVBoxLayout(self)
141142
self.msgEdit = QLineEdit(self, returnPressed=self.onMsgShow)
142143
self.msgButton = QPushButton("显示内容", self, clicked=self.onMsgShow)
@@ -158,6 +159,6 @@ def onMsgShow(self):
158159

159160
if __name__ == "__main__":
160161
app = QApplication(sys.argv)
161-
w = TestWidget()
162+
w = Window()
162163
w.show()
163164
sys.exit(app.exec_())

Demo/CallVirtualKeyboard.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
"""
55
Created on 2019年5月22日
66
@author: Irony
7-
@site: https://pyqt5.com https://github.com/892768447
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: Demo.CallVirtualKeyboard
1010
@description: 调用系统虚拟键盘
1111
"""
1212
import glob
1313

14-
from PyQt5.QtCore import QProcess, QSysInfo
15-
from PyQt5.QtWidgets import QWidget, QTextEdit, QVBoxLayout, QPushButton
16-
17-
18-
__Author__ = 'Irony'
19-
__Copyright__ = 'Copyright (c) 2019 Irony'
20-
__Version__ = 1.0
14+
try:
15+
from PyQt5.QtCore import QProcess, QSysInfo
16+
from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton
17+
except ImportError:
18+
from PySide2.QtCore import QProcess, QSysInfo
19+
from PySide2.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton
2120

2221

2322
class Window(QWidget):
@@ -50,7 +49,7 @@ def _onOpenKeyboard(self):
5049
self.resultEdit.append('start osk error: %s' % e)
5150
elif kernelType == 'darwin':
5251
pass
53-
# elif kernelType=='linux':
52+
# elif kernelType=='linux':
5453
else:
5554
ret = QProcess.startDetached('florence')
5655
self.resultEdit.append('start florence: %s' % ret)
@@ -62,7 +61,7 @@ def _onOpenKeyboard(self):
6261

6362
if __name__ == '__main__':
6463
import sys
65-
from PyQt5.QtWidgets import QApplication
64+
6665
app = QApplication(sys.argv)
6766
w = Window()
6867
w.show()

Demo/CircleLine.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
Created on 2019年3月19日
66
@author: Irony
7-
@site: https://pyqt5.com https://github.com/892768447
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: CircleLine
1010
@description:
@@ -14,13 +14,14 @@
1414
from random import random, randint
1515
from time import time
1616

17-
from PyQt5.QtCore import QTimer, Qt
18-
from PyQt5.QtGui import QColor, QPainter, QPainterPath, QPen
19-
from PyQt5.QtWidgets import QWidget
20-
21-
22-
__Author__ = 'Irony'
23-
__Copyright__ = 'Copyright (c) 2019'
17+
try:
18+
from PyQt5.QtCore import QTimer, Qt
19+
from PyQt5.QtGui import QColor, QPainter, QPainterPath, QPen
20+
from PyQt5.QtWidgets import QWidget, QApplication
21+
except ImportError:
22+
from PySide2.QtCore import QTimer, Qt
23+
from PySide2.QtGui import QColor, QPainter, QPainterPath, QPen
24+
from PySide2.QtWidgets import QWidget, QApplication
2425

2526
# 最小和最大半径、半径阈值和填充圆的百分比
2627
radMin = 10
@@ -60,18 +61,21 @@
6061
circleExpSp = 0.00004
6162
circlePulse = False
6263

64+
6365
# 生成随机整数 a<=x<=b
6466

6567

6668
def randint(a, b):
6769
return floor(random() * (b - a + 1) + a)
6870

71+
6972
# 生成随机小数
7073

7174

7275
def randRange(a, b):
7376
return random() * (b - a) + a
7477

78+
7579
# 生成接近a的随机小数
7680

7781

@@ -88,7 +92,7 @@ def __init__(self, background, width, height):
8892
self.radius = hyperRange(radMin, radMax)
8993
self.filled = (False if randint(
9094
0, 100) > concentricCircle else 'full') if self.radius < radThreshold else (
91-
False if randint(0, 100) > concentricCircle else 'concentric')
95+
False if randint(0, 100) > concentricCircle else 'concentric')
9296
self.color = colors[randint(0, len(colors) - 1)]
9397
self.borderColor = colors[randint(0, len(colors) - 1)]
9498
self.opacity = 0.05
@@ -233,29 +237,29 @@ def renderPoints(self, painter, circles):
233237
# otherwise we connect them only if the dist is < linkDist
234238
if dist < self.linkDist:
235239
xi = (1 if circles[i].x < circles[j].x else -
236-
1) * abs(circles[i].radius * deltax / dist)
240+
1) * abs(circles[i].radius * deltax / dist)
237241
yi = (1 if circles[i].y < circles[j].y else -
238-
1) * abs(circles[i].radius * deltay / dist)
242+
1) * abs(circles[i].radius * deltay / dist)
239243
xj = (-1 if circles[i].x < circles[j].x else 1) * \
240-
abs(circles[j].radius * deltax / dist)
244+
abs(circles[j].radius * deltax / dist)
241245
yj = (-1 if circles[i].y < circles[j].y else 1) * \
242-
abs(circles[j].radius * deltay / dist)
246+
abs(circles[j].radius * deltay / dist)
243247
path = QPainterPath()
244248
path.moveTo(circles[i].x + xi, circles[i].y + yi)
245249
path.lineTo(circles[j].x + xj, circles[j].y + yj)
246-
# samecolor = circles[i].color == circles[j].color
250+
# samecolor = circles[i].color == circles[j].color
247251
c = QColor(circles[i].borderColor)
248252
c.setAlphaF(min(circles[i].opacity, circles[j].opacity)
249253
* ((self.linkDist - dist) / self.linkDist))
250254
painter.setPen(QPen(c, (
251255
lineBorder * backgroundMlt if circles[i].background else lineBorder) * (
252-
(self.linkDist - dist) / self.linkDist)))
256+
(self.linkDist - dist) / self.linkDist)))
253257
painter.drawPath(path)
254258

255259

256260
if __name__ == '__main__':
257261
import sys
258-
from PyQt5.QtWidgets import QApplication
262+
259263
app = QApplication(sys.argv)
260264
w = CircleLineWindow()
261265
w.resize(800, 600)

Demo/CustomProperties.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
Created on 2017年4月12日
6-
@author: Irony."[讽刺]
7-
@site: https://pyqt5.com , https://github.com/892768447
6+
@author: Irony
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: 自定义属性测试
1010
@description:
11-
'''
11+
"""
1212
from random import randint
1313

14-
from PyQt5.QtCore import pyqtProperty, pyqtSignal
15-
from PyQt5.QtWidgets import QPushButton
16-
17-
18-
__version__ = "0.0.1"
14+
try:
15+
from PyQt5.QtCore import pyqtProperty, pyqtSignal
16+
from PyQt5.QtWidgets import QPushButton, QApplication
17+
except ImportError:
18+
from PySide2.QtCore import Property as pyqtProperty, Signal as pyqtSignal
19+
from PySide2.QtWidgets import QPushButton, QApplication
1920

2021

2122
class Window(QPushButton):
22-
2323
bgChanged = pyqtSignal(str, str)
2424

2525
def __init__(self):
@@ -56,7 +56,7 @@ def setTextColor(self, c):
5656

5757
if __name__ == "__main__":
5858
import sys
59-
from PyQt5.QtWidgets import QApplication
59+
6060
app = QApplication(sys.argv)
6161
w = Window()
6262
w.setStyleSheet(

Demo/EmbedWindow.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
"""
55
Created on 2018年3月1日
66
@author: Irony
7-
@site: https://pyqt5.com , https://github.com/892768447
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: EmbedWindow
1010
@description: 嵌入外部窗口
1111
"""
1212

13-
__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com'
14-
__Copyright__ = 'Copyright (c) 2018 Irony'
15-
__Version__ = 1.0
16-
1713
import win32con
1814
import win32gui
19-
from PyQt5.QtCore import Qt
20-
from PyQt5.QtGui import QWindow
21-
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \
22-
QLabel
15+
16+
try:
17+
from PyQt5.QtCore import Qt
18+
from PyQt5.QtGui import QWindow
19+
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \
20+
QLabel, QApplication
21+
except ImportError:
22+
from PySide2.QtCore import Qt
23+
from PySide2.QtGui import QWindow
24+
from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \
25+
QLabel, QApplication
2326

2427

2528
class Window(QWidget):
@@ -113,8 +116,7 @@ def _enumWindows(self, hwnd, _):
113116
import sys
114117
import cgitb
115118

116-
cgitb.enable(format='txt')
117-
from PyQt5.QtWidgets import QApplication
119+
cgitb.enable(format='text')
118120

119121
app = QApplication(sys.argv)
120122
w = Window()

Demo/FacePoints.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
Created on 2018年1月29日
6-
@author: Irony."[讽刺]
7-
@site: https://pyqt5.com , https://github.com/892768447
6+
@author: Irony
7+
@site: https://pyqt.site , https://github.com/PyQt5
88
@email: 892768447@qq.com
99
@file: FacePoints
1010
@description: 人脸特征点
11-
'''
12-
from bz2 import BZ2Decompressor
11+
"""
1312
import cgitb
1413
import os
1514
import sys
15+
from bz2 import BZ2Decompressor
1616

17-
from PyQt5.QtCore import QTimer, QUrl, QFile, QIODevice
18-
from PyQt5.QtGui import QImage, QPixmap
19-
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
20-
from PyQt5.QtWidgets import QLabel, QMessageBox, QApplication
2117
import cv2 # @UnresolvedImport
2218
import dlib
2319
import numpy
2420

25-
26-
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
27-
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
28-
__Version__ = "Version 1.0"
21+
try:
22+
from PyQt5.QtCore import QTimer, QUrl, QFile, QIODevice
23+
from PyQt5.QtGui import QImage, QPixmap
24+
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
25+
from PyQt5.QtWidgets import QLabel, QMessageBox, QApplication
26+
except ImportError:
27+
from PySide2.QtCore import QTimer, QUrl, QFile, QIODevice
28+
from PySide2.QtGui import QImage, QPixmap
29+
from PySide2.QtNetwork import QNetworkAccessManager, QNetworkRequest
30+
from PySide2.QtWidgets import QLabel, QMessageBox, QApplication
2931

3032
DOWNSCALE = 4
3133
URL = 'http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2'
@@ -163,7 +165,7 @@ def onCapture(self):
163165

164166

165167
if __name__ == "__main__":
166-
cgitb.enable(1, None, 5, '')
168+
cgitb.enable(format='text')
167169
app = QApplication(sys.argv)
168170
w = OpencvWidget()
169171
w.show()

0 commit comments

Comments
 (0)