diff --git a/Demo/AutoRestart.py b/Demo/AutoRestart.py index 7037595..024d61b 100644 --- a/Demo/AutoRestart.py +++ b/Demo/AutoRestart.py @@ -1,21 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月31日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AutoRestart @description: -''' +""" -from optparse import OptionParser import os import sys +from optparse import OptionParser -from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout - +try: + from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout +except ImportError: + from PySide2.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout canRestart = True diff --git a/Demo/BubbleTips.py b/Demo/BubbleTips.py index 8af85c7..6f842a3 100644 --- a/Demo/BubbleTips.py +++ b/Demo/BubbleTips.py @@ -1,30 +1,31 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月27日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: BubbleTips @description: -''' +""" import sys -from PyQt5.QtCore import QRectF, Qt, QPropertyAnimation, pyqtProperty, \ - QPoint, QParallelAnimationGroup, QEasingCurve -from PyQt5.QtGui import QPainter, QPainterPath, QColor, QPen -from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication,\ - QLineEdit, QPushButton - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QRectF, Qt, QPropertyAnimation, pyqtProperty, \ + QPoint, QParallelAnimationGroup, QEasingCurve + from PyQt5.QtGui import QPainter, QPainterPath, QColor, QPen + from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication, \ + QLineEdit, QPushButton +except ImportError: + from PySide2.QtCore import QRectF, Qt, QPropertyAnimation, Property as pyqtProperty, \ + QPoint, QParallelAnimationGroup, QEasingCurve + from PySide2.QtGui import QPainter, QPainterPath, QColor, QPen + from PySide2.QtWidgets import QLabel, QWidget, QVBoxLayout, QApplication, \ + QLineEdit, QPushButton class BubbleLabel(QWidget): - BackgroundColor = QColor(195, 195, 195) BorderColor = QColor(150, 150, 150) @@ -133,10 +134,10 @@ class BubbleLabel(QWidget): opacity = pyqtProperty(float, windowOpacity, setWindowOpacity) -class TestWidget(QWidget): +class Window(QWidget): def __init__(self, *args, **kwargs): - super(TestWidget, self).__init__(*args, **kwargs) + super(Window, self).__init__(*args, **kwargs) layout = QVBoxLayout(self) self.msgEdit = QLineEdit(self, returnPressed=self.onMsgShow) self.msgButton = QPushButton("显示内容", self, clicked=self.onMsgShow) @@ -158,6 +159,6 @@ class TestWidget(QWidget): if __name__ == "__main__": app = QApplication(sys.argv) - w = TestWidget() + w = Window() w.show() sys.exit(app.exec_()) diff --git a/Demo/CallVirtualKeyboard.py b/Demo/CallVirtualKeyboard.py index b44af51..4afe18b 100644 --- a/Demo/CallVirtualKeyboard.py +++ b/Demo/CallVirtualKeyboard.py @@ -4,20 +4,19 @@ """ Created on 2019年5月22日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Demo.CallVirtualKeyboard @description: 调用系统虚拟键盘 """ import glob -from PyQt5.QtCore import QProcess, QSysInfo -from PyQt5.QtWidgets import QWidget, QTextEdit, QVBoxLayout, QPushButton - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QProcess, QSysInfo + from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton +except ImportError: + from PySide2.QtCore import QProcess, QSysInfo + from PySide2.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton class Window(QWidget): @@ -50,7 +49,7 @@ class Window(QWidget): self.resultEdit.append('start osk error: %s' % e) elif kernelType == 'darwin': pass -# elif kernelType=='linux': + # elif kernelType=='linux': else: ret = QProcess.startDetached('florence') self.resultEdit.append('start florence: %s' % ret) @@ -62,7 +61,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/Demo/CircleLine.py b/Demo/CircleLine.py index 11a92dc..83102c7 100644 --- a/Demo/CircleLine.py +++ b/Demo/CircleLine.py @@ -4,7 +4,7 @@ """ Created on 2019年3月19日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CircleLine @description: @@ -14,13 +14,14 @@ from math import floor, pi, cos, sin from random import random, randint from time import time -from PyQt5.QtCore import QTimer, Qt -from PyQt5.QtGui import QColor, QPainter, QPainterPath, QPen -from PyQt5.QtWidgets import QWidget - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' +try: + from PyQt5.QtCore import QTimer, Qt + from PyQt5.QtGui import QColor, QPainter, QPainterPath, QPen + from PyQt5.QtWidgets import QWidget, QApplication +except ImportError: + from PySide2.QtCore import QTimer, Qt + from PySide2.QtGui import QColor, QPainter, QPainterPath, QPen + from PySide2.QtWidgets import QWidget, QApplication # 最小和最大半径、半径阈值和填充圆的百分比 radMin = 10 @@ -60,18 +61,21 @@ circleExpMin = 0.997 circleExpSp = 0.00004 circlePulse = False + # 生成随机整数 a<=x<=b def randint(a, b): return floor(random() * (b - a + 1) + a) + # 生成随机小数 def randRange(a, b): return random() * (b - a) + a + # 生成接近a的随机小数 @@ -88,7 +92,7 @@ class Circle: self.radius = hyperRange(radMin, radMax) self.filled = (False if randint( 0, 100) > concentricCircle else 'full') if self.radius < radThreshold else ( - False if randint(0, 100) > concentricCircle else 'concentric') + False if randint(0, 100) > concentricCircle else 'concentric') self.color = colors[randint(0, len(colors) - 1)] self.borderColor = colors[randint(0, len(colors) - 1)] self.opacity = 0.05 @@ -233,29 +237,29 @@ class CircleLineWindow(QWidget): # otherwise we connect them only if the dist is < linkDist if dist < self.linkDist: xi = (1 if circles[i].x < circles[j].x else - - 1) * abs(circles[i].radius * deltax / dist) + 1) * abs(circles[i].radius * deltax / dist) yi = (1 if circles[i].y < circles[j].y else - - 1) * abs(circles[i].radius * deltay / dist) + 1) * abs(circles[i].radius * deltay / dist) xj = (-1 if circles[i].x < circles[j].x else 1) * \ - abs(circles[j].radius * deltax / dist) + abs(circles[j].radius * deltax / dist) yj = (-1 if circles[i].y < circles[j].y else 1) * \ - abs(circles[j].radius * deltay / dist) + abs(circles[j].radius * deltay / dist) path = QPainterPath() path.moveTo(circles[i].x + xi, circles[i].y + yi) path.lineTo(circles[j].x + xj, circles[j].y + yj) -# samecolor = circles[i].color == circles[j].color + # samecolor = circles[i].color == circles[j].color c = QColor(circles[i].borderColor) c.setAlphaF(min(circles[i].opacity, circles[j].opacity) * ((self.linkDist - dist) / self.linkDist)) painter.setPen(QPen(c, ( lineBorder * backgroundMlt if circles[i].background else lineBorder) * ( - (self.linkDist - dist) / self.linkDist))) + (self.linkDist - dist) / self.linkDist))) painter.drawPath(path) if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = CircleLineWindow() w.resize(800, 600) diff --git a/Demo/CustomProperties.py b/Demo/CustomProperties.py index 8a053a2..43eab24 100644 --- a/Demo/CustomProperties.py +++ b/Demo/CustomProperties.py @@ -1,25 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年4月12日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 自定义属性测试 @description: -''' +""" from random import randint -from PyQt5.QtCore import pyqtProperty, pyqtSignal -from PyQt5.QtWidgets import QPushButton - - -__version__ = "0.0.1" +try: + from PyQt5.QtCore import pyqtProperty, pyqtSignal + from PyQt5.QtWidgets import QPushButton, QApplication +except ImportError: + from PySide2.QtCore import Property as pyqtProperty, Signal as pyqtSignal + from PySide2.QtWidgets import QPushButton, QApplication class Window(QPushButton): - bgChanged = pyqtSignal(str, str) def __init__(self): @@ -56,7 +56,7 @@ class Window(QPushButton): if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.setStyleSheet( diff --git a/Demo/EmbedWindow.py b/Demo/EmbedWindow.py index 2238238..b6ffe04 100644 --- a/Demo/EmbedWindow.py +++ b/Demo/EmbedWindow.py @@ -4,22 +4,25 @@ """ Created on 2018年3月1日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: EmbedWindow @description: 嵌入外部窗口 """ -__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com' -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - import win32con import win32gui -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QWindow -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \ - QLabel + +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QWindow + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \ + QLabel, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QWindow + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget, \ + QLabel, QApplication class Window(QWidget): @@ -113,8 +116,7 @@ if __name__ == '__main__': import sys import cgitb - cgitb.enable(format='txt') - from PyQt5.QtWidgets import QApplication + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() diff --git a/Demo/FacePoints.py b/Demo/FacePoints.py index 9df0060..98b6165 100644 --- a/Demo/FacePoints.py +++ b/Demo/FacePoints.py @@ -1,31 +1,33 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月29日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FacePoints @description: 人脸特征点 -''' -from bz2 import BZ2Decompressor +""" import cgitb import os import sys +from bz2 import BZ2Decompressor -from PyQt5.QtCore import QTimer, QUrl, QFile, QIODevice -from PyQt5.QtGui import QImage, QPixmap -from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest -from PyQt5.QtWidgets import QLabel, QMessageBox, QApplication import cv2 # @UnresolvedImport import dlib import numpy - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QTimer, QUrl, QFile, QIODevice + from PyQt5.QtGui import QImage, QPixmap + from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest + from PyQt5.QtWidgets import QLabel, QMessageBox, QApplication +except ImportError: + from PySide2.QtCore import QTimer, QUrl, QFile, QIODevice + from PySide2.QtGui import QImage, QPixmap + from PySide2.QtNetwork import QNetworkAccessManager, QNetworkRequest + from PySide2.QtWidgets import QLabel, QMessageBox, QApplication DOWNSCALE = 4 URL = 'http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2' @@ -163,7 +165,7 @@ class OpencvWidget(QLabel): if __name__ == "__main__": - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = OpencvWidget() w.show() diff --git a/Demo/FollowWindow.py b/Demo/FollowWindow.py index 5e54287..41ad74c 100644 --- a/Demo/FollowWindow.py +++ b/Demo/FollowWindow.py @@ -4,23 +4,21 @@ """ Created on 2018年10月22日 @author: Irony -@site: https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FollowWindow @description: 跟随外部窗口 """ import os -from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton import win32gui - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication class Window(QWidget): @@ -53,7 +51,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + # 先检测是否已有记事本打开 hwnd = win32gui.FindWindow('Notepad', None) print('hwnd', hwnd) diff --git a/Demo/FramelessDialog.py b/Demo/FramelessDialog.py index 4f3d551..b55bef3 100644 --- a/Demo/FramelessDialog.py +++ b/Demo/FramelessDialog.py @@ -4,20 +4,22 @@ """ Created on 2019年4月19日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FramelessDialog @description: 无边框圆角对话框 """ -from PyQt5.QtCore import Qt, QSize, QTimer -from PyQt5.QtWidgets import QDialog, QVBoxLayout, QWidget,\ - QGraphicsDropShadowEffect, QPushButton, QGridLayout, QSpacerItem,\ - QSizePolicy - -__Author__ = "Irony" -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt, QSize, QTimer + from PyQt5.QtWidgets import QDialog, QVBoxLayout, QWidget, \ + QGraphicsDropShadowEffect, QPushButton, QGridLayout, QSpacerItem, \ + QSizePolicy, QApplication +except ImportError: + from PySide2.QtCore import Qt, QSize, QTimer + from PySide2.QtWidgets import QDialog, QVBoxLayout, QWidget, \ + QGraphicsDropShadowEffect, QPushButton, QGridLayout, QSpacerItem, \ + QSizePolicy, QApplication Stylesheet = """ #Custom_Widget { @@ -77,7 +79,7 @@ class Dialog(QDialog): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Dialog() w.exec_() diff --git a/Demo/FramelessWindow.py b/Demo/FramelessWindow.py index aef6c26..7e1608e 100644 --- a/Demo/FramelessWindow.py +++ b/Demo/FramelessWindow.py @@ -1,24 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit + + +""" +Created on 2018年4月30日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: Test +@description: +""" + +try: + from PyQt5.QtGui import QIcon + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit, QApplication +except ImportError: + from PySide2.QtGui import QIcon + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit, QApplication from Lib.FramelessWindow import FramelessWindow # @UnresolvedImport -# Created on 2018年4月30日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: Test -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class MainWindow(QWidget): def __init__(self, *args, **kwargs): @@ -63,7 +65,7 @@ TitleBar { if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet(StyleSheet) w = FramelessWindow() diff --git a/Demo/GifCursor.py b/Demo/GifCursor.py index 61be6f5..0b1ea8f 100644 --- a/Demo/GifCursor.py +++ b/Demo/GifCursor.py @@ -4,21 +4,20 @@ """ Created on 2020年3月13日 @author: Irony -@site: https://pyqt.site https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Demo.GifCursor @description: """ -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton + +try: + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication +except ImportError: + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication from Lib.QCursorGif import QCursorGif -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 1.0 - - class Window(QWidget, QCursorGif): def __init__(self, *args, **kwargs): @@ -38,8 +37,9 @@ class Window(QWidget, QCursorGif): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/Demo/IsSignalConnected.py b/Demo/IsSignalConnected.py index c651e61..7d534f3 100644 --- a/Demo/IsSignalConnected.py +++ b/Demo/IsSignalConnected.py @@ -4,7 +4,7 @@ """ Created on 2019年2月24日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: IsSignalConnected @description: 判断信号是否连接 @@ -13,13 +13,6 @@ Created on 2019年2月24日 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextBrowser -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - - class Window(QWidget): def __init__(self, *args, **kwargs): @@ -37,8 +30,10 @@ class Window(QWidget): # button1 clicked 是否连接: %s, %s # button2 clicked 是否连接: %s, %s """ % ( - self.isSignalConnected(self.button1, 'clicked()'), self.button1.receivers(self.button1.clicked) > 0, - self.isSignalConnected(self.button2, 'clicked()'), self.button2.receivers(self.button2.clicked) > 0, + self.isSignalConnected(self.button1, 'clicked()'), + self.button1.receivers(self.button1.clicked) > 0, + self.isSignalConnected(self.button2, 'clicked()'), + self.button2.receivers(self.button2.clicked) > 0, )) def isSignalConnected(self, obj, name): @@ -57,6 +52,7 @@ class Window(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/Demo/Lib/Application.py b/Demo/Lib/Application.py index c121600..eed9376 100644 --- a/Demo/Lib/Application.py +++ b/Demo/Lib/Application.py @@ -1,35 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 单实例应用.Application @description: -''' +""" + from PyQt5.QtCore import QSharedMemory, pyqtSignal, Qt from PyQt5.QtNetwork import QLocalSocket, QLocalServer from PyQt5.QtWidgets import QApplication -__version__ = "0.0.1" - class SharedApplication(QApplication): - + def __init__(self, *args, **kwargs): super(SharedApplication, self).__init__(*args, **kwargs) self._running = False - key = "SharedApplication" + __version__ + key = "SharedApplication" self._memory = QSharedMemory(key, self) - + isAttached = self._memory.isAttached() print("isAttached", isAttached) if isAttached: # 如果进程附加在共享内存上 detach = self._memory.detach() # 取消进程附加在共享内存上 print("detach", detach) - + if self._memory.create(1) and self._memory.error() != QSharedMemory.AlreadyExists: # 创建共享内存,如果创建失败,则说明已经创建,否则未创建 print("create ok") @@ -37,14 +36,14 @@ class SharedApplication(QApplication): print("create failed") self._running = True del self._memory - + def isRunning(self): return self._running + class QSingleApplication(QApplication): - messageReceived = pyqtSignal(str) - + def __init__(self, *args, **kwargs): super(QSingleApplication, self).__init__(*args, **kwargs) appid = QApplication.applicationFilePath().lower().split("/")[-1] @@ -56,13 +55,13 @@ class QSingleApplication(QApplication): self._socketIn = None self._socketOut = None self._running = False - + # 先尝试连接 self._socketOut = QLocalSocket(self) self._socketOut.connectToServer(self._socketName) self._socketOut.error.connect(self.handleError) self._running = self._socketOut.waitForConnected() - + if not self._running: # 程序未运行 self._socketOut.close() del self._socketOut @@ -70,20 +69,20 @@ class QSingleApplication(QApplication): self._socketServer.listen(self._socketName) self._socketServer.newConnection.connect(self._onNewConnection) self.aboutToQuit.connect(self.removeServer) - + def handleError(self, message): print("handleError message: ", message) - + def isRunning(self): return self._running - + def activationWindow(self): return self._activationWindow - + def setActivationWindow(self, activationWindow, activateOnMessage=True): self._activationWindow = activationWindow self._activateOnMessage = activateOnMessage - + def activateWindow(self): if not self._activationWindow: return @@ -91,7 +90,7 @@ class QSingleApplication(QApplication): self._activationWindow.windowState() & ~Qt.WindowMinimized) self._activationWindow.raise_() self._activationWindow.activateWindow() - + def sendMessage(self, message, msecs=5000): if not self._socketOut: return False @@ -99,10 +98,10 @@ class QSingleApplication(QApplication): message = str(message).encode() self._socketOut.write(message) if not self._socketOut.waitForBytesWritten(msecs): - raise RuntimeError("Bytes not written within %ss" % + raise RuntimeError("Bytes not written within %ss" % (msecs / 1000.)) return True - + def _onNewConnection(self): if self._socketIn: self._socketIn.readyRead.disconnect(self._onReadyRead) @@ -112,7 +111,7 @@ class QSingleApplication(QApplication): self._socketIn.readyRead.connect(self._onReadyRead) if self._activateOnMessage: self.activateWindow() - + def _onReadyRead(self): while 1: message = self._socketIn.readLine() @@ -123,4 +122,4 @@ class QSingleApplication(QApplication): def removeServer(self): self._socketServer.close() - self._socketServer.removeServer(self._socketName) \ No newline at end of file + self._socketServer.removeServer(self._socketName) diff --git a/Demo/Lib/FramelessWindow.py b/Demo/Lib/FramelessWindow.py index 04afccb..b4fa3e0 100644 --- a/Demo/Lib/FramelessWindow.py +++ b/Demo/Lib/FramelessWindow.py @@ -1,26 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from PyQt5.QtCore import Qt, pyqtSignal, QPoint -from PyQt5.QtGui import QFont, QEnterEvent, QPainter, QColor, QPen -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel,\ - QSpacerItem, QSizePolicy, QPushButton -# Created on 2018年4月30日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: FramelessWindow -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +""" +Created on 2018年4月30日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: FramelessWindow +@description: +""" + +try: + from PyQt5.QtCore import Qt, pyqtSignal, QPoint + from PyQt5.QtGui import QFont, QEnterEvent, QPainter, QColor, QPen + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ + QSpacerItem, QSizePolicy, QPushButton +except ImportError: + from PySide2.QtCore import Qt, Signal as pyqtSignal, QPoint + from PySide2.QtGui import QFont, QEnterEvent, QPainter, QColor, QPen + from PySide2.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ + QSpacerItem, QSizePolicy, QPushButton class TitleBar(QWidget): - # 窗口最小化信号 windowMinimumed = pyqtSignal() # 窗口最大化信号 @@ -48,7 +51,7 @@ class TitleBar(QWidget): layout.setContentsMargins(0, 0, 0, 0) # 窗口图标 self.iconLabel = QLabel(self) -# self.iconLabel.setScaledContents(True) + # self.iconLabel.setScaledContents(True) layout.addWidget(self.iconLabel) # 窗口标题 self.titleLabel = QLabel(self) @@ -138,7 +141,6 @@ Left, Top, Right, Bottom, LeftTop, RightTop, LeftBottom, RightBottom = range(8) class FramelessWindow(QWidget): - # 四周边距 Margins = 5 diff --git a/Demo/Lib/QCursorGif.py b/Demo/Lib/QCursorGif.py index 0ff9959..707e747 100644 --- a/Demo/Lib/QCursorGif.py +++ b/Demo/Lib/QCursorGif.py @@ -4,19 +4,20 @@ """ Created on 2020年3月13日 @author: Irony -@site: https://pyqt.site https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Demo.Lib.QCursorGif @description: """ -from PyQt5.QtCore import QTimer, Qt -from PyQt5.QtGui import QCursor, QPixmap -from PyQt5.QtWidgets import QApplication - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QTimer, Qt + from PyQt5.QtGui import QCursor, QPixmap + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QTimer, Qt + from PySide2.QtGui import QCursor, QPixmap + from PySide2.QtWidgets import QApplication class QCursorGif: @@ -55,4 +56,4 @@ class QCursorGif: def setOldCursor(self, parent=None): self._oldCursor = (parent.cursor() or Qt.ArrowCursor) if parent else ( - QApplication.instance().overrideCursor() or Qt.ArrowCursor) + QApplication.instance().overrideCursor() or Qt.ArrowCursor) diff --git a/Demo/Lib/UiNotify.py b/Demo/Lib/UiNotify.py index 20d26aa..38f1ad9 100644 --- a/Demo/Lib/UiNotify.py +++ b/Demo/Lib/UiNotify.py @@ -6,46 +6,50 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +try: + from PyQt5 import QtCore, QtGui, QtWidgets +except ImportError: + from PySide2 import QtCore, QtGui, QtWidgets + class Ui_NotifyForm(object): def setupUi(self, NotifyForm): NotifyForm.setObjectName("NotifyForm") NotifyForm.resize(300, 200) NotifyForm.setStyleSheet("QWidget#widgetTitle {\n" -" background-color: rgb(76, 169, 106);\n" -"}\n" -"QWidget#widgetBottom {\n" -" border-top-style: solid;\n" -" border-top-width: 2px;\n" -" border-top-color: rgb(185, 218, 201);\n" -"}\n" -"QLabel#labelTitle {\n" -" color: rgb(255, 255, 255);\n" -"}\n" -"QLabel#labelContent {\n" -" padding: 5px;\n" -"}\n" -"QPushButton {\n" -" border: none;\n" -" background: transparent;\n" -"}\n" -"QPushButton#buttonClose {\n" -" font-family: \"webdings\";\n" -" color: rgb(255, 255, 255);\n" -"}\n" -"QPushButton#buttonClose:hover {\n" -" background-color: rgb(212, 64, 39);\n" -"}\n" -"QPushButton#buttonView {\n" -" color: rgb(255, 255, 255);\n" -" border-radius: 5px;\n" -" border: solid 1px rgb(76, 169, 106);\n" -" background-color: rgb(76, 169, 106);\n" -"}\n" -"QPushButton#buttonView:hover {\n" -" color: rgb(0, 0, 0);\n" -"}") + " background-color: rgb(76, 169, 106);\n" + "}\n" + "QWidget#widgetBottom {\n" + " border-top-style: solid;\n" + " border-top-width: 2px;\n" + " border-top-color: rgb(185, 218, 201);\n" + "}\n" + "QLabel#labelTitle {\n" + " color: rgb(255, 255, 255);\n" + "}\n" + "QLabel#labelContent {\n" + " padding: 5px;\n" + "}\n" + "QPushButton {\n" + " border: none;\n" + " background: transparent;\n" + "}\n" + "QPushButton#buttonClose {\n" + " font-family: \"webdings\";\n" + " color: rgb(255, 255, 255);\n" + "}\n" + "QPushButton#buttonClose:hover {\n" + " background-color: rgb(212, 64, 39);\n" + "}\n" + "QPushButton#buttonView {\n" + " color: rgb(255, 255, 255);\n" + " border-radius: 5px;\n" + " border: solid 1px rgb(76, 169, 106);\n" + " background-color: rgb(76, 169, 106);\n" + "}\n" + "QPushButton#buttonView:hover {\n" + " color: rgb(0, 0, 0);\n" + "}") self.verticalLayout = QtWidgets.QVBoxLayout(NotifyForm) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setSpacing(6) @@ -61,7 +65,8 @@ class Ui_NotifyForm(object): self.labelTitle.setText("") self.labelTitle.setObjectName("labelTitle") self.horizontalLayout_3.addWidget(self.labelTitle) - spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem) self.buttonClose = QtWidgets.QPushButton(self.widgetTitle) self.buttonClose.setMinimumSize(QtCore.QSize(26, 26)) @@ -80,7 +85,8 @@ class Ui_NotifyForm(object): self.horizontalLayout.setContentsMargins(0, 5, 5, 5) self.horizontalLayout.setSpacing(0) self.horizontalLayout.setObjectName("horizontalLayout") - spacerItem1 = QtWidgets.QSpacerItem(170, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + spacerItem1 = QtWidgets.QSpacerItem(170, 20, QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem1) self.buttonView = QtWidgets.QPushButton(self.widgetBottom) self.buttonView.setMinimumSize(QtCore.QSize(75, 25)) @@ -102,10 +108,10 @@ class Ui_NotifyForm(object): if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) NotifyForm = QtWidgets.QWidget() ui = Ui_NotifyForm() ui.setupUi(NotifyForm) NotifyForm.show() sys.exit(app.exec_()) - diff --git a/Demo/Lib/ui_frameless.py b/Demo/Lib/ui_frameless.py index 31d0e9f..94bc7b7 100644 --- a/Demo/Lib/ui_frameless.py +++ b/Demo/Lib/ui_frameless.py @@ -8,7 +8,10 @@ # run again. Do not edit this file unless you know what you are doing. -from PyQt5 import QtCore, QtGui, QtWidgets +try: + from PyQt5 import QtCore, QtGui, QtWidgets +except ImportError: + from PySide2 import QtCore, QtGui, QtWidgets class Ui_FormFrameless(object): @@ -28,7 +31,8 @@ class Ui_FormFrameless(object): self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setSpacing(0) self.horizontalLayout.setObjectName("horizontalLayout") - spacerItem = QtWidgets.QSpacerItem(253, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + spacerItem = QtWidgets.QSpacerItem(253, 20, QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.buttonMinimum = QtWidgets.QPushButton(self.widgetTitleBar) self.buttonMinimum.setMinimumSize(QtCore.QSize(36, 36)) @@ -83,15 +87,17 @@ class Ui_FormFrameless(object): self.buttonNormal.setText(_translate("FormFrameless", "2")) self.buttonClose.setToolTip(_translate("FormFrameless", "Close")) self.buttonClose.setText(_translate("FormFrameless", "r")) - self.textEdit.setHtml(_translate("FormFrameless", "\n" -"\n" -"

frameless window with move and resize

")) + self.textEdit.setHtml(_translate("FormFrameless", + "\n" + "\n" + "

frameless window with move and resize

")) if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) FormFrameless = QtWidgets.QWidget() ui = Ui_FormFrameless() diff --git a/Demo/NativeEvent.py b/Demo/NativeEvent.py index 2ccf169..00833ff 100644 --- a/Demo/NativeEvent.py +++ b/Demo/NativeEvent.py @@ -2,42 +2,40 @@ # -*- coding: utf-8 -*- """Created on 2018年8月2日 author: Irony -site: https://pyqt5.com , https://github.com/892768447 +site: https://pyqt.site , https://github.com/PyQt5 email: 892768447@qq.com file: win无边框调整大小 description: """ -from ctypes.wintypes import POINT import ctypes.wintypes +from ctypes.wintypes import POINT -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QPushButton -from PyQt5.QtWinExtras import QtWin import win32api import win32con import win32gui - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QWidget, QPushButton, QApplication + from PyQt5.QtWinExtras import QtWin +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QWidget, QPushButton, QApplication + from PySide2.QtWinExtras import QtWin class MINMAXINFO(ctypes.Structure): _fields_ = [ - ("ptReserved", POINT), - ("ptMaxSize", POINT), - ("ptMaxPosition", POINT), - ("ptMinTrackSize", POINT), - ("ptMaxTrackSize", POINT), + ("ptReserved", POINT), + ("ptMaxSize", POINT), + ("ptMaxPosition", POINT), + ("ptMinTrackSize", POINT), + ("ptMaxTrackSize", POINT), ] class Window(QWidget): - BorderWidth = 5 def __init__(self, *args, **kwargs): @@ -121,7 +119,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() btn = QPushButton('exit', w, clicked=app.quit) diff --git a/Demo/NewFramelessWindow.py b/Demo/NewFramelessWindow.py index 1b077fe..788a140 100644 --- a/Demo/NewFramelessWindow.py +++ b/Demo/NewFramelessWindow.py @@ -10,10 +10,16 @@ Created on 2018年4月30日 @description: """ +try: + from PyQt5.QtCore import QTimer, Qt, QEvent, QObject + from PyQt5.QtGui import QWindow, QPainter, QColor, QMouseEvent + from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox +except ImportError: + from PySide2.QtCore import QTimer, Qt, QEvent, QObject + from PySide2.QtGui import QWindow, QPainter, QColor, QMouseEvent + from PySide2.QtWidgets import QApplication, QWidget, QMessageBox + from Lib.ui_frameless import Ui_FormFrameless -from PyQt5.QtCore import QTimer, Qt, QEvent, QObject -from PyQt5.QtGui import QWindow, QPainter, QColor, QMouseEvent -from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox class FramelessObject(QObject): diff --git a/Demo/Notification.py b/Demo/Notification.py index f7a0ab1..889c103 100644 --- a/Demo/Notification.py +++ b/Demo/Notification.py @@ -4,30 +4,30 @@ """ Created on 2018年9月9日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Notification @description: """ import base64 -from PyQt5.QtCore import Qt, QRectF, QSize, pyqtSignal, QTimer -from PyQt5.QtGui import QPixmap, QImage, QPainter, QPainterPath,\ - QColor -from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout,\ - QGridLayout, QSpacerItem, QSizePolicy, QGraphicsDropShadowEffect,\ - QListWidget, QListWidgetItem - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt, QRectF, QSize, pyqtSignal, QTimer + from PyQt5.QtGui import QPixmap, QImage, QPainter, QPainterPath, \ + QColor + from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, \ + QGridLayout, QSpacerItem, QSizePolicy, QGraphicsDropShadowEffect, \ + QListWidget, QListWidgetItem, QApplication, QPushButton +except ImportError: + from PySide2.QtCore import Qt, QRectF, QSize, Signal as pyqtSignal, QTimer + from PySide2.QtGui import QPixmap, QImage, QPainter, QPainterPath, \ + QColor + from PySide2.QtWidgets import QWidget, QLabel, QHBoxLayout, \ + QGridLayout, QSpacerItem, QSizePolicy, QGraphicsDropShadowEffect, \ + QListWidget, QListWidgetItem, QApplication, QPushButton class NotificationIcon: - Info, Success, Warning, Error, Close = range(5) Types = { Info: None, @@ -39,10 +39,14 @@ class NotificationIcon: @classmethod def init(cls): - cls.Types[cls.Info] = QPixmap(QImage.fromData(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAC5ElEQVRYR8VX0VHbQBB9e/bkN3QQU0FMBSEVYFcQ8xPBJLJ1FWAqOMcaxogfTAWQCiAVRKkgTgfmM4zRZu6QhGzL0p0nDPr17e7bt7tv14RX/uiV48MJgAon+8TiAMRtMFogaqUJxADPwRRzg67kl8+xbWJWANR40iPQSSFgtX/mGQkaDr56V3VAKgGos4s2JXwJoF3naMPvMS+SrpTHs032GwGkdF+DsFMVnJm/oyGGeHico0EjIjpYes+YMyVd6R/flfkpBWCCQ9zaZM2LZDfLMGXsZ5kdI/lYBmINgHHyyLd1mWdBbAFAM/GY7K2WYx1AeB4T6L1N9umbGxZ0qktATaEAdCps48D39oq/LwEw3U5CN92LfczJoewfT7MAywDCaEbAuxeLrh0zz4L+0e4aAJfGy+sP3IMxlH1vpMJoSMCJDXgWtJeJVc6ACs9HBBrYODCJAFdYvAmkPJxnNqMwYht7Bn+T/lGg3z4DGEd3RPhQ54DBvwAOVkeqagRXfTLjh+x7+8sALOtfHLuiYzWOAiLoKbD58mnIGbCmLxUepS6NQmYlUGE0JeCTTXT9JvA9E9sZgO5iIpoyc6/YzcqSwQzgGgBXB7oXpH9klpRSkxY1xW/b7Iu2zk34PILPnazCqEPAtTWA8iZ0HsOu9L0bw4DzCJeNocMGNDpQ3IKO+6NUiJ4ysZNiBv5I3zPnmJmG5oM+wbS+9+qkvGi7NAXGmeUy0ioofa+XA0jH0UaMKpdRWs/adcwMqfV/tenqpqHY/Znt+j2gJi00RUzA201dXaxh9iZdZloJS+9H1otrkbRrD5InFqpPskxEshJQ468CkSmJC+i1HigaaxCAuCljgoDhwPdOjf7rFVxxuJrMkXScjtKc1rOLNpJk6nii5XmYzbngzlZn+RIb40kPJPTBYXUt6VEDJ8Pi6bWpNFb/jFYY6YGpDeKdjBmTKdMcxDGEmP73v2a2Gr/NOycGtglQZ/MPzEqCMLGckJEAAAAASUVORK5CYII='))) - cls.Types[cls.Success] = QPixmap(QImage.fromData(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACZUlEQVRYR8VXS3LTQBDtVsDbcAPMCbB3limkcAKSG4QFdnaYE2BOQLKzxSLJCeAGSUQheSnfwLmB2VJhXmpExpFHI2sk2RWv5FJPv9evP9NieuIfPzE+VSJw8qt3IMDvmahDoDYxt2UAACXMWIIowR5ffn8TJbaBWRE4CXvHAH9RgKXOgQUI48CfXZbZbiTw8Xe/w3d0zkydMkem91IZpyWOJu5sUXS+kEAqt3B+MNOLOuDqDEBLxxFHk7eza5MfIwEJDjhXTYD1s8zinYlEjsCD7FdNI9cJpEq0RFdPR47AMOzLCn69zegz6UgCP+pmfa8RSKudnPNdgCufTOLDxJtdPP7PoA1Cd8HEL5sSUCCD0B0x8bc1f8Bi6sevcgS2VXh6hMOwDz0gsUddNaxWKRjeuKfE/KlJ9Dq4UYH/o/Ns6scj+bgiMAjdayb26xLQwTfVEwg3gRcf6ARq578KuLo7VDc8psCQqwfjr4EfjYvkrAquFJ56UYpdSkAZSmNd1rrg0leOQFELgvA58OJTxVyRaAJORPOpF6UXnFUR5sDiXjs7UqsOMGMRlrWhTkJXpFL3mNrQZhA1lH3F0TiI5FurUQyMpn58VjhkSqQA4Tbw4nSVW6sBU5VXktXSeONlJH3s8jrOVr9RgVSFuNcWfzlh5n3LoKzMAPxxWuiULiQpiR2sZNnCyzIuWUr5Z1Ml0sgdHFZaShVDuR86/0huL3VXtDk/F4e11vKsTHLSCeKx7bYkW80hjLOrV1GhWH0ZrSlyh2MwdZhYfi8oZeYgLBmUiGd8sfVPM6syr2lUSYGaGBuP3QN6rVUwYV/egwAAAABJRU5ErkJggg=='))) - cls.Types[cls.Warning] = QPixmap(QImage.fromData(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACmElEQVRYR8VXTW7TUBD+xjYSXZFukOIsSE9AskNJJMoJmq4r7OYEwAkabhBOkB/Emt4gVIojdpgbpIumEitX6gKB7UHPkauXxLHfc4F6Z3l+vvnmm/fGhAd+6IHzQwvA9cfOITMfAdQAcx1EdVEAM/tEFADsWyaPn57MfdXClABcT1qnzHSWJiwMzrwgoF91vXGRbS6AH59ajd8hDYmoURQo67tgxoij42rv62KX/04Agu44xmciVMokT32YERgGjquvZ1+y4mQCWPUa0/sk3vQlwqssEFsAVrQbU4XKL/ai2+5PPK6waQ4AOsoDnDARh83NdmwBuJq0fQI9L6p+L7rd3+/5gbAToMPI+FbkIzRRc72mbLcGIFE7jGFRIPHddmZrvstJh1X8CHGv6sxHqe1GkPYCoGcqgcoCAPPCdr2DLQC6wqMoPEj7qdqCNKllxs30sLpjYDluDUDGG5XqhY2sal3w4PiD7c7fJnHShMtJR8zpy/8CALiwndnhBgD1/t+XAXkaZAaUVHwnHulg0W6BNEWlAQD8zna8gQB0Ne70iXCm2j55jCUAei1gxvuaO+uXAcDg7zXHSy640iKUAehOEDJFqDmGQkiPLO5Fv+KADXOqvCuIsrPGsIyQdHou22YeRMJgOdHTQTkAfGk7XrLKrWlAvOhcRgBfWiZ3RQti0zxXuUFXCXMuo0TRitfxugjbIxC5RYzI6s9kIGFh+KLOpiW22id5AUuI8IaisFG4kCQg/sFKJgtPLix3KWXGeRETRbQDuCFCV2spTYMm+2FEI1WBbYIRPTeiqFtqLZeDraaD+qrbkpgQAvfl1WsXU0p/RjIjYYhTkNFgcCVlRlRKoAAc+5aF0V//NVPoc2kTLQZKZ8lx/AMXBmMwuXUwOAAAAABJRU5ErkJggg=='))) - cls.Types[cls.Error] = QPixmap(QImage.fromData(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACrklEQVRYR82XW27aQBSG/4PtiNhIpStouoImKwjZAV1B07coWCpZQcgK6kh2lLeSFZSsIOwgdAdkBaUSEBQDpxpjU9vM+EJR03nDzJz/mzm3GcIrD3plfZQCeD47O1ho2jERNRmoE9AQG2BgBGBAwIiZe5Zh3JPjiG+5oxCAEF5q2iWITnMtRhOYu5XF4mr/9naYtSYXYGLbHQCXhYVTEwlom657rVqvBOB2uz71/a+ldq1SYe6ahnEhc4sSYGzbfQKOt915eh0D/ZrrnqS/SwEmrVYXRJ92Jb4OC+C65rrtuN0NgIltNwF837V4zN5Hy3V70e9NgFZrCKJ3CQDmJ9MwDsW36XzeB/AhA/CHqeuN2WxWX2paX2JraHneeynA+Pz8lCqVbxLjV5brimxAEJxqiEA8CjZVBvFy+bl2c9MV9hInoAw85qFpGEeRYQVEQjzMokcQHWxsiPne8jzh6j8AodGfyqNlHpiGcaKAkIk/gChwm2yYuv5W2FqfwLNtN5bAQ2bwySB83zENo50A8/1McaFRAU72XVek+mpk+D/JlIKI/xkee654uCbIhjVAqZIrgSgpLhiCwN4OAEj4vEB2yDybBCjsAol4ZD0nRdMQSRcUCsKUeNSw4o2mKMRGEOamoVx8FXDZKVosDYNMUHXAsBRnppo8RQcbpTgIGEkhykpFjnWxzGhPQYxt2yHgS/oIlKVYTJxImpG482nz+VG1Wh1N84pMCCGa0ULXHwmoJwCYnyzPW5fn/68dh7EgPbrMMl3gz7gro+n/7EoWD7w4a96l1NnJ1Yz5Lt6wCgFEk0r1CIkbiPnC9DxH5aHcd4FYGD5MOqVOg/muslh0/vphkm63k5eXZvA0I6qD+ZCI3jDzLxANiHn1NNvb6+30aVYgwLeeUsgFW1svsPA3Ncq4MHzVeO8AAAAASUVORK5CYII='))) + cls.Types[cls.Info] = QPixmap(QImage.fromData(base64.b64decode( + 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAC5ElEQVRYR8VX0VHbQBB9e/bkN3QQU0FMBSEVYFcQ8xPBJLJ1FWAqOMcaxogfTAWQCiAVRKkgTgfmM4zRZu6QhGzL0p0nDPr17e7bt7tv14RX/uiV48MJgAon+8TiAMRtMFogaqUJxADPwRRzg67kl8+xbWJWANR40iPQSSFgtX/mGQkaDr56V3VAKgGos4s2JXwJoF3naMPvMS+SrpTHs032GwGkdF+DsFMVnJm/oyGGeHico0EjIjpYes+YMyVd6R/flfkpBWCCQ9zaZM2LZDfLMGXsZ5kdI/lYBmINgHHyyLd1mWdBbAFAM/GY7K2WYx1AeB4T6L1N9umbGxZ0qktATaEAdCps48D39oq/LwEw3U5CN92LfczJoewfT7MAywDCaEbAuxeLrh0zz4L+0e4aAJfGy+sP3IMxlH1vpMJoSMCJDXgWtJeJVc6ACs9HBBrYODCJAFdYvAmkPJxnNqMwYht7Bn+T/lGg3z4DGEd3RPhQ54DBvwAOVkeqagRXfTLjh+x7+8sALOtfHLuiYzWOAiLoKbD58mnIGbCmLxUepS6NQmYlUGE0JeCTTXT9JvA9E9sZgO5iIpoyc6/YzcqSwQzgGgBXB7oXpH9klpRSkxY1xW/b7Iu2zk34PILPnazCqEPAtTWA8iZ0HsOu9L0bw4DzCJeNocMGNDpQ3IKO+6NUiJ4ysZNiBv5I3zPnmJmG5oM+wbS+9+qkvGi7NAXGmeUy0ioofa+XA0jH0UaMKpdRWs/adcwMqfV/tenqpqHY/Znt+j2gJi00RUzA201dXaxh9iZdZloJS+9H1otrkbRrD5InFqpPskxEshJQ468CkSmJC+i1HigaaxCAuCljgoDhwPdOjf7rFVxxuJrMkXScjtKc1rOLNpJk6nii5XmYzbngzlZn+RIb40kPJPTBYXUt6VEDJ8Pi6bWpNFb/jFYY6YGpDeKdjBmTKdMcxDGEmP73v2a2Gr/NOycGtglQZ/MPzEqCMLGckJEAAAAASUVORK5CYII='))) + cls.Types[cls.Success] = QPixmap(QImage.fromData(base64.b64decode( + 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACZUlEQVRYR8VXS3LTQBDtVsDbcAPMCbB3limkcAKSG4QFdnaYE2BOQLKzxSLJCeAGSUQheSnfwLmB2VJhXmpExpFHI2sk2RWv5FJPv9evP9NieuIfPzE+VSJw8qt3IMDvmahDoDYxt2UAACXMWIIowR5ffn8TJbaBWRE4CXvHAH9RgKXOgQUI48CfXZbZbiTw8Xe/w3d0zkydMkem91IZpyWOJu5sUXS+kEAqt3B+MNOLOuDqDEBLxxFHk7eza5MfIwEJDjhXTYD1s8zinYlEjsCD7FdNI9cJpEq0RFdPR47AMOzLCn69zegz6UgCP+pmfa8RSKudnPNdgCufTOLDxJtdPP7PoA1Cd8HEL5sSUCCD0B0x8bc1f8Bi6sevcgS2VXh6hMOwDz0gsUddNaxWKRjeuKfE/KlJ9Dq4UYH/o/Ns6scj+bgiMAjdayb26xLQwTfVEwg3gRcf6ARq578KuLo7VDc8psCQqwfjr4EfjYvkrAquFJ56UYpdSkAZSmNd1rrg0leOQFELgvA58OJTxVyRaAJORPOpF6UXnFUR5sDiXjs7UqsOMGMRlrWhTkJXpFL3mNrQZhA1lH3F0TiI5FurUQyMpn58VjhkSqQA4Tbw4nSVW6sBU5VXktXSeONlJH3s8jrOVr9RgVSFuNcWfzlh5n3LoKzMAPxxWuiULiQpiR2sZNnCyzIuWUr5Z1Ml0sgdHFZaShVDuR86/0huL3VXtDk/F4e11vKsTHLSCeKx7bYkW80hjLOrV1GhWH0ZrSlyh2MwdZhYfi8oZeYgLBmUiGd8sfVPM6syr2lUSYGaGBuP3QN6rVUwYV/egwAAAABJRU5ErkJggg=='))) + cls.Types[cls.Warning] = QPixmap(QImage.fromData(base64.b64decode( + 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACmElEQVRYR8VXTW7TUBD+xjYSXZFukOIsSE9AskNJJMoJmq4r7OYEwAkabhBOkB/Emt4gVIojdpgbpIumEitX6gKB7UHPkauXxLHfc4F6Z3l+vvnmm/fGhAd+6IHzQwvA9cfOITMfAdQAcx1EdVEAM/tEFADsWyaPn57MfdXClABcT1qnzHSWJiwMzrwgoF91vXGRbS6AH59ajd8hDYmoURQo67tgxoij42rv62KX/04Agu44xmciVMokT32YERgGjquvZ1+y4mQCWPUa0/sk3vQlwqssEFsAVrQbU4XKL/ai2+5PPK6waQ4AOsoDnDARh83NdmwBuJq0fQI9L6p+L7rd3+/5gbAToMPI+FbkIzRRc72mbLcGIFE7jGFRIPHddmZrvstJh1X8CHGv6sxHqe1GkPYCoGcqgcoCAPPCdr2DLQC6wqMoPEj7qdqCNKllxs30sLpjYDluDUDGG5XqhY2sal3w4PiD7c7fJnHShMtJR8zpy/8CALiwndnhBgD1/t+XAXkaZAaUVHwnHulg0W6BNEWlAQD8zna8gQB0Ne70iXCm2j55jCUAei1gxvuaO+uXAcDg7zXHSy640iKUAehOEDJFqDmGQkiPLO5Fv+KADXOqvCuIsrPGsIyQdHou22YeRMJgOdHTQTkAfGk7XrLKrWlAvOhcRgBfWiZ3RQti0zxXuUFXCXMuo0TRitfxugjbIxC5RYzI6s9kIGFh+KLOpiW22id5AUuI8IaisFG4kCQg/sFKJgtPLix3KWXGeRETRbQDuCFCV2spTYMm+2FEI1WBbYIRPTeiqFtqLZeDraaD+qrbkpgQAvfl1WsXU0p/RjIjYYhTkNFgcCVlRlRKoAAc+5aF0V//NVPoc2kTLQZKZ8lx/AMXBmMwuXUwOAAAAABJRU5ErkJggg=='))) + cls.Types[cls.Error] = QPixmap(QImage.fromData(base64.b64decode( + 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACrklEQVRYR82XW27aQBSG/4PtiNhIpStouoImKwjZAV1B07coWCpZQcgK6kh2lLeSFZSsIOwgdAdkBaUSEBQDpxpjU9vM+EJR03nDzJz/mzm3GcIrD3plfZQCeD47O1ho2jERNRmoE9AQG2BgBGBAwIiZe5Zh3JPjiG+5oxCAEF5q2iWITnMtRhOYu5XF4mr/9naYtSYXYGLbHQCXhYVTEwlom657rVqvBOB2uz71/a+ldq1SYe6ahnEhc4sSYGzbfQKOt915eh0D/ZrrnqS/SwEmrVYXRJ92Jb4OC+C65rrtuN0NgIltNwF837V4zN5Hy3V70e9NgFZrCKJ3CQDmJ9MwDsW36XzeB/AhA/CHqeuN2WxWX2paX2JraHneeynA+Pz8lCqVbxLjV5brimxAEJxqiEA8CjZVBvFy+bl2c9MV9hInoAw85qFpGEeRYQVEQjzMokcQHWxsiPne8jzh6j8AodGfyqNlHpiGcaKAkIk/gChwm2yYuv5W2FqfwLNtN5bAQ2bwySB83zENo50A8/1McaFRAU72XVek+mpk+D/JlIKI/xkee654uCbIhjVAqZIrgSgpLhiCwN4OAEj4vEB2yDybBCjsAol4ZD0nRdMQSRcUCsKUeNSw4o2mKMRGEOamoVx8FXDZKVosDYNMUHXAsBRnppo8RQcbpTgIGEkhykpFjnWxzGhPQYxt2yHgS/oIlKVYTJxImpG482nz+VG1Wh1N84pMCCGa0ULXHwmoJwCYnyzPW5fn/68dh7EgPbrMMl3gz7gro+n/7EoWD7w4a96l1NnJ1Yz5Lt6wCgFEk0r1CIkbiPnC9DxH5aHcd4FYGD5MOqVOg/muslh0/vphkm63k5eXZvA0I6qD+ZCI3jDzLxANiHn1NNvb6+30aVYgwLeeUsgFW1svsPA3Ncq4MHzVeO8AAAAASUVORK5CYII='))) cls.Types[cls.Close] = QPixmap(QImage.fromData(base64.b64decode( 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeElEQVQ4T2NkoBAwUqifgboGzJy76AIjE3NCWmL0BWwumzV/qcH/f38XpCfHGcDkUVwAUsDw9+8GBmbmAHRDcMlheAGbQnwGYw0DZA1gp+JwFUgKZyDCDQGpwuIlrGGAHHAUGUCRFygKRIqjkeKERE6+oG5eIMcFAOqSchGwiKKAAAAAAElFTkSuQmCC'))) @@ -52,7 +56,6 @@ class NotificationIcon: class NotificationItem(QWidget): - closed = pyqtSignal(QListWidgetItem) def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs): @@ -152,7 +155,6 @@ class NotificationItem(QWidget): class NotificationWindow(QListWidget): - _instance = None def __init__(self, *args, **kwargs): @@ -243,15 +245,18 @@ class NotificationWindow(QListWidget): if __name__ == '__main__': import sys import cgitb - sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text') - from PyQt5.QtWidgets import QApplication, QPushButton + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = QWidget() layout = QHBoxLayout(w) + def callback(): print('回调点击') + layout.addWidget(QPushButton( 'Info', w, clicked=lambda: NotificationWindow.info('提示', '这是一条会自动关闭的消息', callback=callback))) layout.addWidget(QPushButton( @@ -268,9 +273,9 @@ if __name__ == '__main__': callback=callback))) w.show() -# NotificationIcon.init() -# ww = NotificationItem('提示', '

这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案

', None, -# ntype=NotificationIcon.Error) -# ww.bgWidget.setVisible(True) -# ww.show() + # NotificationIcon.init() + # ww = NotificationItem('提示', '

这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案

', None, + # ntype=NotificationIcon.Error) + # ww.bgWidget.setVisible(True) + # ww.show() sys.exit(app.exec_()) diff --git a/Demo/ProbeWindow.py b/Demo/ProbeWindow.py index 7bc4b0b..e023359 100644 --- a/Demo/ProbeWindow.py +++ b/Demo/ProbeWindow.py @@ -3,23 +3,22 @@ """ Created on 2018年6月8日 author: Irony -site: https://pyqt5.com , https://github.com/892768447 +site: https://pyqt.site , https://github.com/PyQt5 email: 892768447@qq.com file: ProbeWindow description: 简单探测窗口和放大截图 """ -from PyQt5.QtCore import Qt, QRect -from PyQt5.QtGui import QPainter, QPen, QCursor, QColor -from PyQt5.QtWidgets import QLabel, QWidget, QApplication import win32gui - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt, QRect + from PyQt5.QtGui import QPainter, QPen, QCursor, QColor + from PyQt5.QtWidgets import QLabel, QWidget, QApplication +except ImportError: + from PySide2.QtCore import Qt, QRect + from PySide2.QtGui import QPainter, QPen, QCursor, QColor + from PySide2.QtWidgets import QLabel, QWidget, QApplication class FrameWidget(QWidget): @@ -111,11 +110,12 @@ class Label(QLabel): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignLeft | Qt.AlignBottom, '({}, {})\nRGB: ({}, {}, {})\n{}'.format( - pos.x(), pos.y(), r, g, b, QColor(r, g, b).name())) + pos.x(), pos.y(), r, g, b, QColor(r, g, b).name())) if __name__ == '__main__': import sys + app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(True) w = Label() diff --git a/Demo/QtThreading.py b/Demo/QtThreading.py index 63f3697..d053385 100644 --- a/Demo/QtThreading.py +++ b/Demo/QtThreading.py @@ -4,7 +4,7 @@ """ Created on 2019年3月8日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Threading.QtThreading @description: @@ -12,19 +12,15 @@ Created on 2019年3月8日 from threading import Thread from time import sleep -from PyQt5.QtCore import QObject, pyqtSignal, QTimer, Qt -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QObject, pyqtSignal, QTimer, Qt + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QApplication +except ImportError: + from PySide2.QtCore import QObject, Signal as pyqtSignal, QTimer, Qt + from PySide2.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QApplication class _Signals(QObject): - updateProgress = pyqtSignal(int) @@ -63,7 +59,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/Demo/RestartWindow.py b/Demo/RestartWindow.py index 9eec224..bd9709b 100644 --- a/Demo/RestartWindow.py +++ b/Demo/RestartWindow.py @@ -1,26 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月17日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: RestartWindow @description: 窗口重启 -''' -from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QLineEdit,\ - QMessageBox +""" - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import pyqtSignal + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QLineEdit, \ + QMessageBox, QApplication +except ImportError: + from PySide2.QtCore import Signal as pyqtSignal + from PySide2.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QLineEdit, \ + QMessageBox, QApplication class RestartWindow(QWidget): - restarted = pyqtSignal(QWidget, str) _Self = None # 很重要,保留窗口引用 @@ -55,7 +55,7 @@ class RestartWindow(QWidget): if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = RestartWindow("test") w.show() diff --git a/Demo/ScreenNotify.py b/Demo/ScreenNotify.py index 33c29cb..f2c9f9c 100644 --- a/Demo/ScreenNotify.py +++ b/Demo/ScreenNotify.py @@ -4,15 +4,19 @@ """ Created on 2021/4/13 @author: Irony -@site: https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScreenNotify @description: 屏幕、分辨率、DPI变化通知 """ import sys -from PyQt5.QtCore import QTimer, QRect -from PyQt5.QtWidgets import QApplication, QPlainTextEdit, qApp +try: + from PyQt5.QtCore import QTimer, QRect + from PyQt5.QtWidgets import QApplication, QPlainTextEdit +except ImportError: + from PySide2.QtCore import QTimer, QRect + from PySide2.QtWidgets import QApplication, QPlainTextEdit class Window(QPlainTextEdit): @@ -27,22 +31,24 @@ class Window(QPlainTextEdit): self.m_timer.setSingleShot(True) # **重要** 保证多次信号尽量少的调用函数 # 主要是多屏幕->无屏幕->有屏幕 - qApp.primaryScreenChanged.connect(lambda _: self.m_timer.start(1000)) + QApplication.instance().primaryScreenChanged.connect(lambda _: self.m_timer.start(1000)) # 其它信号最终基本上都会调用该信号 - qApp.primaryScreen().virtualGeometryChanged.connect(lambda _: self.m_timer.start(1000)) + QApplication.instance().primaryScreen().virtualGeometryChanged.connect( + lambda _: self.m_timer.start(1000)) # DPI变化 - qApp.primaryScreen().logicalDotsPerInchChanged.connect(lambda _: self.m_timer.start(1000)) + QApplication.instance().primaryScreen().logicalDotsPerInchChanged.connect( + lambda _: self.m_timer.start(1000)) def onSolutionChanged(self): # 获取主屏幕 - screen = qApp.primaryScreen() + screen = QApplication.instance().primaryScreen() if self.m_rect == screen.availableVirtualGeometry(): return self.m_rect = screen.availableVirtualGeometry() # 所有屏幕可用大小 self.appendPlainText('\navailableVirtualGeometry: {0}'.format(str(screen.availableVirtualGeometry()))) # 获取所有屏幕 - screens = qApp.screens() + screens = QApplication.instance().screens() for screen in screens: self.appendPlainText( 'screen: {0}, geometry({1}), availableGeometry({2}), logicalDotsPerInch({3}), ' diff --git a/Demo/ScreenShotDll.py b/Demo/ScreenShotDll.py index 964df60..0def9e7 100644 --- a/Demo/ScreenShotDll.py +++ b/Demo/ScreenShotDll.py @@ -1,3 +1,4 @@ from ctypes import CDLL + dll = CDLL('Data/ScreenShot.dll') dll.PrScrn() diff --git a/Demo/SharedMemory.py b/Demo/SharedMemory.py index 0ec5919..f654ad1 100644 --- a/Demo/SharedMemory.py +++ b/Demo/SharedMemory.py @@ -1,28 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TestQSharedMemory @description: -''' -from PyQt5.QtWidgets import QWidget +""" +from PyQt5.QtWidgets import QWidget from Lib.Application import SharedApplication # @UnresolvedImport -__version__ = "0.0.1" class Widget(QWidget): - - def __init__(self,*args,**kwargs): - super(Widget, self).__init__(*args,**kwargs) + + def __init__(self, *args, **kwargs): + super(Widget, self).__init__(*args, **kwargs) + if __name__ == "__main__": - import sys,os + import sys, os + print(os.getpid()) app = SharedApplication(sys.argv) if app.isRunning(): @@ -30,4 +31,4 @@ if __name__ == "__main__": sys.exit(0) w = Widget() w.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/Demo/ShowFrameWhenDrag.py b/Demo/ShowFrameWhenDrag.py index a7c986e..5f0993f 100644 --- a/Demo/ShowFrameWhenDrag.py +++ b/Demo/ShowFrameWhenDrag.py @@ -4,20 +4,18 @@ """ Created on 2019年4月23日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ShowFrameWhenDrag @description: 调整窗口显示边框 """ -from ctypes import sizeof, windll, c_int, byref, c_long, c_void_p, c_ulong, c_longlong,\ +from ctypes import sizeof, windll, c_int, byref, c_long, c_void_p, c_ulong, c_longlong, \ c_ulonglong, WINFUNCTYPE, c_uint -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QApplication +except ImportError: + from PySide2.QtWidgets import QWidget, QVBoxLayout, QLabel, QApplication if sizeof(c_long) == sizeof(c_void_p): WPARAM = c_ulong @@ -82,7 +80,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/Demo/SingleApplication.py b/Demo/SingleApplication.py index d452e16..1f5f74e 100644 --- a/Demo/SingleApplication.py +++ b/Demo/SingleApplication.py @@ -1,28 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TestQSingleApplication @description: -''' +""" + from PyQt5.QtWidgets import QTextEdit from Lib.Application import QSingleApplication # @UnresolvedImport -__version__ = "0.0.1" - class Widget(QTextEdit): - + def __init__(self, *args, **kwargs): super(Widget, self).__init__(*args, **kwargs) + if __name__ == "__main__": import sys + app = QSingleApplication(sys.argv) if app.isRunning(): app.sendMessage("app is running") diff --git a/Demo/VerificationCode.py b/Demo/VerificationCode.py index df25ba7..9490d8e 100644 --- a/Demo/VerificationCode.py +++ b/Demo/VerificationCode.py @@ -1,23 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年4月5日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: widgets.WidgetCode @description: -''' -from random import sample +""" import string +from random import sample -from PyQt5.QtCore import Qt, qrand, QPointF, QPoint, QBasicTimer -from PyQt5.QtGui import QPainter, QBrush, QPen, QPalette, QFontMetrics -from PyQt5.QtWidgets import QLabel - - -__version__ = "0.0.1" +try: + from PyQt5.QtCore import Qt, qrand, QPointF, QPoint, QBasicTimer + from PyQt5.QtGui import QPainter, QBrush, QPen, QPalette, QFontMetrics, QFontDatabase + from PyQt5.QtWidgets import QLabel, QApplication, QWidget, QHBoxLayout, QLineEdit +except ImportError: + from PySide2.QtCore import Qt, qrand, QPointF, QPoint, QBasicTimer + from PySide2.QtGui import QPainter, QBrush, QPen, QPalette, QFontMetrics, QFontDatabase + from PySide2.QtWidgets import QLabel, QApplication, QWidget, QHBoxLayout, QLineEdit DEF_NOISYPOINTCOUNT = 60 # 噪点数量 COLORLIST = ("black", "gray", "red", "green", "blue", "magenta") @@ -28,8 +30,9 @@ FONT = "{word}" WORDS = list(string.ascii_letters + string.digits) SINETABLE = (0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38) + class WidgetCode(QLabel): - + def __init__(self, *args, **kwargs): super(WidgetCode, self).__init__(*args, **kwargs) self._sensitive = False # 是否大小写敏感 @@ -47,33 +50,33 @@ class WidgetCode(QLabel): self.step = 0 self.timer = QBasicTimer() self.timer.start(60, self) - + def reset(self): self._code = "".join(sample(WORDS, 4)) # 随机4个字符 self.setText(self._code) - + def check(self, code): return self._code == str(code) if self._sensitive else self._code.lower() == str(code).lower() - + def setSensitive(self, sensitive): self._sensitive = sensitive - -# def setText(self, text): -# text = text if (text and len(text) == 4) else "".join(sample(WORDS, 4)) # 随机4个字符 -# self._code = str(text) -# html = "".join([FONT.format(color=COLORLIST[qrand() % 6], word=t) for t in text]) -# super(WidgetCode, self).setText(HTML.format(html=html)) - + + # def setText(self, text): + # text = text if (text and len(text) == 4) else "".join(sample(WORDS, 4)) # 随机4个字符 + # self._code = str(text) + # html = "".join([FONT.format(color=COLORLIST[qrand() % 6], word=t) for t in text]) + # super(WidgetCode, self).setText(HTML.format(html=html)) + def mouseReleaseEvent(self, event): super(WidgetCode, self).mouseReleaseEvent(event) self.reset() - + def timerEvent(self, event): if event.timerId() == self.timer.timerId(): self.step += 1 return self.update() return super(WidgetCode, self).timerEvent(event) - + def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) @@ -107,21 +110,20 @@ class WidgetCode(QLabel): painter.drawText(x, y - ((SINETABLE[index] * metrics.height()) / 400), ch) x += metrics.width(ch) + if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout - from PyQt5.QtGui import QFontDatabase - from PyQt5.QtWidgets import QLineEdit + app = QApplication(sys.argv) app.setApplicationName("Validate Code") QFontDatabase.addApplicationFont("Data/itckrist.ttf") w = QWidget() layout = QHBoxLayout(w) - + cwidget = WidgetCode(w, minimumHeight=35, minimumWidth=80) layout.addWidget(cwidget) lineEdit = QLineEdit(w, maxLength=4, placeholderText="请输入验证码并按回车验证", - returnPressed=lambda:print(cwidget.check(lineEdit.text()))) + returnPressed=lambda: print(cwidget.check(lineEdit.text()))) layout.addWidget(lineEdit) w.show() sys.exit(app.exec_()) diff --git a/Demo/WeltHideWindow.py b/Demo/WeltHideWindow.py index 73ba7b0..5faa20b 100644 --- a/Demo/WeltHideWindow.py +++ b/Demo/WeltHideWindow.py @@ -4,18 +4,18 @@ """ Created on 2018年3月1日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: WeltHideWindow @description: 简单的窗口贴边隐藏 """ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton - -__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com' -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication class WeltHideWindow(QWidget): @@ -88,7 +88,7 @@ class WeltHideWindow(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = WeltHideWindow() w.show() diff --git a/Demo/WindowNotify.py b/Demo/WindowNotify.py index 408ff5e..490dbd4 100644 --- a/Demo/WindowNotify.py +++ b/Demo/WindowNotify.py @@ -1,27 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: WindowNotify @description: 右下角弹窗 -''' +""" import webbrowser -from PyQt5.QtCore import Qt, QPropertyAnimation, QPoint, QTimer, pyqtSignal -from PyQt5.QtWidgets import QWidget, QPushButton +try: + from PyQt5.QtCore import Qt, QPropertyAnimation, QPoint, QTimer, pyqtSignal + from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QHBoxLayout +except ImportError: + from PySide2.QtCore import Qt, QPropertyAnimation, QPoint, QTimer, Signal as pyqtSignal + from PySide2.QtWidgets import QWidget, QPushButton, QApplication, QHBoxLayout from Lib.UiNotify import Ui_NotifyForm # @UnresolvedImport -__version__ = "0.0.1" - - class WindowNotify(QWidget, Ui_NotifyForm): - SignalClosed = pyqtSignal() # 弹窗关闭信号 def __init__(self, title="", content="", timeout=5000, *args, **kwargs): @@ -60,10 +60,10 @@ class WindowNotify(QWidget, Ui_NotifyForm): webbrowser.open_new_tab("http://alyl.vip") def onClose(self): - #点击关闭按钮时 + # 点击关闭按钮时 print("onClose") self.isShow = False - QTimer.singleShot(100, self.closeAnimation)#启动弹回动画 + QTimer.singleShot(100, self.closeAnimation) # 启动弹回动画 def _init(self): # 隐藏任务栏|去掉边框|顶层显示 @@ -112,13 +112,14 @@ class WindowNotify(QWidget, Ui_NotifyForm): print("showAnimation isShow = True") # 显示动画 self.isShow = True - self.animation.stop()#先停止之前的动画,重新开始 + self.animation.stop() # 先停止之前的动画,重新开始 self.animation.setStartValue(self.pos()) self.animation.setEndValue(self._endPos) self.animation.start() # 弹出5秒后,如果没有焦点则弹回去 self._timer.start(self._timeout) -# QTimer.singleShot(self._timeout, self.closeAnimation) + + # QTimer.singleShot(self._timeout, self.closeAnimation) def closeAnimation(self): print("closeAnimation hasFocus", self.hasFocus()) @@ -158,9 +159,10 @@ class WindowNotify(QWidget, Ui_NotifyForm): if self._timeouted: QTimer.singleShot(1000, self.closeAnimation) + if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication, QHBoxLayout + app = QApplication(sys.argv) window = QWidget() diff --git a/PyQtGraph/Data/__init__.py b/PyQtGraph/Data/__init__.py index c5a3c6f..ce54303 100644 --- a/PyQtGraph/Data/__init__.py +++ b/PyQtGraph/Data/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" @author: wxj @license: (C) Hefei tongzhi electromechanical control technology co.LTD @contact: @@ -8,4 +8,4 @@ @file: __init__.py.py @time: 2019/5/21 18:07 @desc: -''' +""" diff --git a/PyQtGraph/Data/graphAnalysis.py b/PyQtGraph/Data/graphAnalysis.py index 6743853..0f30b3a 100644 --- a/PyQtGraph/Data/graphAnalysis.py +++ b/PyQtGraph/Data/graphAnalysis.py @@ -8,6 +8,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets + class graph_Form(object): def setupUi(self, Form): Form.setObjectName("Form") @@ -50,4 +51,3 @@ class graph_Form(object): self.label.setText(_translate("Form", "图形分析")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Form", "折线图")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Tab 2")) - diff --git a/PyQtGraph/Data/graphTest.py b/PyQtGraph/Data/graphTest.py index 22cf8f7..06ffde6 100644 --- a/PyQtGraph/Data/graphTest.py +++ b/PyQtGraph/Data/graphTest.py @@ -8,6 +8,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets + class graph_Form(object): def setupUi(self, Form): Form.setObjectName("Form") @@ -51,4 +52,3 @@ class graph_Form(object): self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Form", "折线图")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Tab 2")) self.pushButton_7.setText(_translate("Form", "分析")) - diff --git a/PyQtGraph/graph1.py b/PyQtGraph/graph1.py index 521ec41..b37b8ad 100644 --- a/PyQtGraph/graph1.py +++ b/PyQtGraph/graph1.py @@ -1,19 +1,22 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2019年5月21日 @author: weike32 -@site: https://pyqt5.com ,https://github.com/weike32 +@site: https://pyqt.site ,https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: 禁止右键,添加滑动窗口,点击按钮生成图片,自定义Y轴坐标,背景颜色调整 -''' +""" import sys -from PyQt5.QtWidgets import QDialog, QApplication, QWidget -from qtpy import QtWidgets + import pyqtgraph as pg +from PyQt5.QtGui import QSpacerItem, QSizePolicy +from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QScrollArea, QVBoxLayout + from PyQtGraph.Data.graphTest import graph_Form + class CustomViewBox(pg.ViewBox): def __init__(self, *args, **kwds): pg.ViewBox.__init__(self, *args, **kwds) @@ -27,11 +30,12 @@ class CustomViewBox(pg.ViewBox): def mouseDragEvent(self, ev): pg.ViewBox.mouseDragEvent(self, ev) - def wheelEvent(self,ev, axis=None): + def wheelEvent(self, ev, axis=None): # pg.ViewBox.wheelEvent(self, ev, axis) ev.ignore() -class graphAnalysis(QDialog,graph_Form): + +class graphAnalysis(QDialog, graph_Form): def __init__(self): super(graphAnalysis, self).__init__() self.setupUi(self) @@ -39,35 +43,37 @@ class graphAnalysis(QDialog,graph_Form): self.tabWidget.clear() def test(self): - tab1 = QtWidgets.QWidget() - scrollArea = QtWidgets.QScrollArea(tab1) - scrollArea.setMinimumSize(984,550) + tab1 = QWidget() + scrollArea = QScrollArea(tab1) + scrollArea.setMinimumSize(984, 550) scrollArea.setWidgetResizable(True) labelsContainer = QWidget() - labelsContainer.setMinimumSize(0,1500) + labelsContainer.setMinimumSize(0, 1500) scrollArea.setWidget(labelsContainer) - layout = QtWidgets.QVBoxLayout(labelsContainer) + layout = QVBoxLayout(labelsContainer) time = ['2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00'] value = [1.2, 2, 1, 4] xdict = dict(enumerate(time)) ticks = [list(zip(range(4), tuple(time)))] vb = CustomViewBox() - plt = pg.PlotWidget(title="标题这里填写",viewBox=vb) + plt = pg.PlotWidget(title="标题这里填写", viewBox=vb) plt.setBackground(background=None) plt.plot(list(xdict.keys()), value) plt.getPlotItem().getAxis("bottom").setTicks(ticks) - temp = QtWidgets.QWidget() - temp.setMinimumSize(900,300) - temp.setMaximumSize(900,300) - layout1 = QtWidgets.QVBoxLayout(temp) + temp = QWidget() + temp.setMinimumSize(900, 300) + temp.setMaximumSize(900, 300) + layout1 = QVBoxLayout(temp) layout1.addWidget(plt) layout.addWidget(temp) - spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, + QSizePolicy.Expanding) layout.addItem(spacerItem) self.tabWidget.addTab(tab1, '这里tabWidget修改标签') -if __name__ =="__main__": + +if __name__ == "__main__": app = QApplication(sys.argv) w = graphAnalysis() w.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/PyQtGraph/mouseFlow.py b/PyQtGraph/mouseFlow.py index 9d9f9fb..1d3503b 100644 --- a/PyQtGraph/mouseFlow.py +++ b/PyQtGraph/mouseFlow.py @@ -1,18 +1,20 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2019年5月2日 @author: weike32 -@site: https://pyqt5.com ,https://github.com/weike32 +@site: https://pyqt.site ,https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: 查阅了很多博客,如果有异,可以联系作者邮箱。本Demo仅作学习参考用,保有后续相关权益。 -''' +""" import sys -from PyQt5.QtWidgets import QApplication, QMainWindow -from PyQt5 import QtCore + import numpy as np import pyqtgraph as pg +from PyQt5 import QtCore +from PyQt5.QtWidgets import QApplication, QMainWindow + class Ui_Form(object): def setupUi(self, Form): @@ -22,6 +24,7 @@ class Ui_Form(object): self.graphicsView.setGeometry(QtCore.QRect(75, 131, 621, 441)) self.graphicsView.setObjectName("graphicsView") + class MyWindow(QMainWindow, Ui_Form): def __init__(self, parent=None): super(MyWindow, self).__init__(parent) @@ -33,12 +36,15 @@ class MyWindow(QMainWindow, Ui_Form): self.graphicsView.addItem(self.label) self.setMouseTracking(True) self.graphicsView.scene().sigMouseMoved.connect(self.onMouseMoved) + def onMouseMoved(self, evt): if self.graphicsView.plotItem.vb.mapSceneToView(evt): - point =self.graphicsView.plotItem.vb.mapSceneToView(evt) + point = self.graphicsView.plotItem.vb.mapSceneToView(evt) self.label.setHtml("

横坐标:{0}

".format(point.x())) + + if __name__ == '__main__': app = QApplication(sys.argv) myWin = MyWindow() myWin.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/PyQtGraph/testGraphAnalysis.py b/PyQtGraph/testGraphAnalysis.py index 7cdbb0b..23f23a4 100644 --- a/PyQtGraph/testGraphAnalysis.py +++ b/PyQtGraph/testGraphAnalysis.py @@ -1,18 +1,19 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2019年8月17日 @author: weike32 -@site: https://pyqt5.com ,https://github.com/weike32 +@site: https://pyqt.site ,https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: -''' +""" import sys -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QDialog, QApplication, QWidget -from qtpy import QtWidgets + import pyqtgraph as pg +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QSpacerItem, QSizePolicy +from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QScrollArea, QVBoxLayout from PyQtGraph.Data.graphAnalysis import graph_Form @@ -26,38 +27,41 @@ class CustomViewBox(pg.ViewBox): def mouseClickEvent(self, ev): if ev.button() == pg.QtCore.Qt.RightButton: self.autoRange() + def mouseDragEvent(self, ev): pg.ViewBox.mouseDragEvent(self, ev) - def wheelEvent(self,ev,axis=None): + + def wheelEvent(self, ev, axis=None): ev.ignore() -class graphAnalysis(QDialog,graph_Form): + +class graphAnalysis(QDialog, graph_Form): def __init__(self): super(graphAnalysis, self).__init__() self.setupUi(self) self.pushButton_7.clicked.connect(self.test) self.tabWidget.clear() - def handleChanged(self,item,column): + def handleChanged(self, item, column): count = item.childCount() if item.checkState(column) == Qt.Checked: for index in range(count): - item.child(index).setCheckState(0,Qt.Checked) + item.child(index).setCheckState(0, Qt.Checked) if item.checkState(column) == Qt.Unchecked: for index in range(count): - item.child(index).setCheckState(0,Qt.Unchecked) + item.child(index).setCheckState(0, Qt.Unchecked) def test(self): - tab1 = QtWidgets.QWidget() - scrollArea = QtWidgets.QScrollArea(tab1) - scrollArea.setMinimumSize(650,550) + tab1 = QWidget() + scrollArea = QScrollArea(tab1) + scrollArea.setMinimumSize(650, 550) scrollArea.setWidgetResizable(True) labelsContainer = QWidget() - labelsContainer.setMinimumSize(0,3000+200) + labelsContainer.setMinimumSize(0, 3000 + 200) scrollArea.setWidget(labelsContainer) - layout = QtWidgets.QVBoxLayout(labelsContainer) + layout = QVBoxLayout(labelsContainer) time = ['2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00'] value = [1.2, 2, 1, 4] @@ -65,26 +69,28 @@ class graphAnalysis(QDialog,graph_Form): ticks = [list(zip(range(4), tuple(time)))] for i in range(11): vb1 = CustomViewBox() - plt1 = pg.PlotWidget(title="Basic array plotting%s"%i, viewBox=vb1) + plt1 = pg.PlotWidget(title="Basic array plotting%s" % i, viewBox=vb1) plt1.resize(500, 500) plt1.setBackground(background=None) plt1.plot(list(xdict.keys()), value) plt1.getPlotItem().getAxis("bottom").setTicks(ticks) - temp1 = QtWidgets.QWidget() + temp1 = QWidget() temp1.setMinimumSize(600, 300) temp1.setMaximumSize(600, 300) - layout2 = QtWidgets.QVBoxLayout(temp1) + layout2 = QVBoxLayout(temp1) layout2.addWidget(plt1) layout.addWidget(temp1) - spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, + QSizePolicy.Expanding) layout.addItem(spacerItem) # print(layout.count()) self.tabWidget.addTab(tab1, '12') for i in range(self.tabWidget.count()): self.tabWidget.widget(i) -if __name__ =="__main__": + +if __name__ == "__main__": app = QApplication(sys.argv) w = graphAnalysis() w.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/PyQtGraph/tools.py b/PyQtGraph/tools.py index edfb931..5a867de 100644 --- a/PyQtGraph/tools.py +++ b/PyQtGraph/tools.py @@ -1,27 +1,31 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2019年5月21日 @author: weike32 -@site: https://pyqt5.com ,https://github.com/weike32 +@site: https://pyqt.site ,https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: 工具类 -''' +""" +import pyqtgraph as pg from pyqtgraph.exporters.ImageExporter import ImageExporter, Exporter from pyqtgraph.parametertree import Parameter -import pyqtgraph as pg -#不用修改源码,重加载,解决右键保存图片异常 + + +# 不用修改源码,重加载,解决右键保存图片异常 def widthChanged(self): sr = self.getSourceRect() ar = float(sr.height()) / sr.width() self.params.param('height').setValue(int(self.params['width'] * ar), blockSignal=self.heightChanged) + def heightChanged(self): sr = self.getSourceRect() ar = float(sr.width()) / sr.height() self.params.param('width').setValue(int(self.params['height'] * ar), blockSignal=self.widthChanged) + def New__init__(self, item): Exporter.__init__(self, item) tr = self.getTargetRect() @@ -42,11 +46,14 @@ def New__init__(self, item): ]) self.params.param('width').sigValueChanged.connect(self.widthChanged) self.params.param('height').sigValueChanged.connect(self.heightChanged) + + ImageExporter.heightChanged = heightChanged ImageExporter.widthChanged = widthChanged ImageExporter.__init__ = New__init__ -#解决自定义坐标轴密集显示 + +# 解决自定义坐标轴密集显示 class MyStringAxis(pg.AxisItem): def __init__(self, xdict, *args, **kwargs): pg.AxisItem.__init__(self, *args, **kwargs) @@ -62,6 +69,8 @@ class MyStringAxis(pg.AxisItem): vstr = "" strings.append(vstr) return strings + + # 禁止鼠标事件 class CustomViewBox(pg.ViewBox): def __init__(self, *args, **kwds): @@ -76,5 +85,5 @@ class CustomViewBox(pg.ViewBox): def mouseDragEvent(self, ev): pg.ViewBox.mouseDragEvent(self, ev) - def wheelEvent(self,ev, axis=None): - pg.ViewBox.wheelEvent(self, ev, axis) \ No newline at end of file + def wheelEvent(self, ev, axis=None): + pg.ViewBox.wheelEvent(self, ev, axis) diff --git a/QAxWidget/ViewOffice.py b/QAxWidget/ViewOffice.py index f30d753..3c33180 100644 --- a/QAxWidget/ViewOffice.py +++ b/QAxWidget/ViewOffice.py @@ -1,24 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年4月6日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ViewOffice @description: -''' +""" + from PyQt5.QAxContainer import QAxWidget -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QFileDialog,\ +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QFileDialog, \ QMessageBox -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - - class AxWidget(QWidget): def __init__(self, *args, **kwargs): @@ -68,6 +64,7 @@ class AxWidget(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = AxWidget() w.show() diff --git a/QCalendarWidget/CalendarQssStyle.py b/QCalendarWidget/CalendarQssStyle.py index b385325..9d2e092 100644 --- a/QCalendarWidget/CalendarQssStyle.py +++ b/QCalendarWidget/CalendarQssStyle.py @@ -1,19 +1,23 @@ """ Created on 2018年1月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CalendarQssStyle @description: 日历美化样式 """ import sys -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QTextCharFormat, QBrush, QColor -from PyQt5.QtWidgets import QApplication, QCalendarWidget +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QTextCharFormat, QBrush, QColor + from PyQt5.QtWidgets import QApplication, QCalendarWidget +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QTextCharFormat, QBrush, QColor + from PySide2.QtWidgets import QApplication, QCalendarWidget - -StyleSheet = ''' +StyleSheet = """ /*顶部导航区域*/ #qt_calendar_navigationbar { background-color: rgb(0, 188, 212); @@ -101,7 +105,7 @@ CalendarWidget QToolButton::menu-indicator { outline: 0px;/*去掉选中后的虚线框*/ selection-background-color: rgb(0, 188, 212); /*选中背景颜色*/ } -''' +""" class CalendarWidget(QCalendarWidget): diff --git a/QComboBox/CityLinkage.py b/QComboBox/CityLinkage.py index 603f342..203888f 100644 --- a/QComboBox/CityLinkage.py +++ b/QComboBox/CityLinkage.py @@ -3,8 +3,8 @@ """ Created on 2018年1月27日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CityLinkage @description: 下拉联动 @@ -12,16 +12,18 @@ Created on 2018年1月27日 import json import sys -from PyQt5.QtCore import Qt, QSortFilterProxyModel, QRegExp -from PyQt5.QtGui import QStandardItemModel, QStandardItem -from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout, QComboBox,\ - QLabel, QSpacerItem, QSizePolicy import chardet - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt, QSortFilterProxyModel, QRegExp + from PyQt5.QtGui import QStandardItemModel, QStandardItem + from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout, QComboBox, \ + QLabel, QSpacerItem, QSizePolicy +except ImportError: + from PySide2.QtCore import Qt, QSortFilterProxyModel, QRegExp + from PySide2.QtGui import QStandardItemModel, QStandardItem + from PySide2.QtWidgets import QWidget, QApplication, QHBoxLayout, QComboBox, \ + QLabel, QSpacerItem, QSizePolicy class SortFilterProxyModel(QSortFilterProxyModel): diff --git a/QFileSystemModel/CustomIcon.py b/QFileSystemModel/CustomIcon.py index 9eb15b8..9b32228 100644 --- a/QFileSystemModel/CustomIcon.py +++ b/QFileSystemModel/CustomIcon.py @@ -3,28 +3,29 @@ """ Created on 2018年1月26日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com -@file: FileSystemModel +@file: CustomIcon @description: """ + import sys -from PyQt5.QtCore import QFileInfo -from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QFileSystemModel, QFileIconProvider, QApplication,\ - QTreeView - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - -# 图标提供类 +try: + from PyQt5.QtCore import QFileInfo + from PyQt5.QtGui import QIcon + from PyQt5.QtWidgets import QFileSystemModel, QFileIconProvider, QApplication, \ + QTreeView +except ImportError: + from PySide2.QtCore import QFileInfo + from PySide2.QtGui import QIcon + from PySide2.QtWidgets import QFileSystemModel, QFileIconProvider, QApplication, \ + QTreeView class FileIconProvider(QFileIconProvider): + """图标提供类""" def __init__(self, *args, **kwargs): super(FileIconProvider, self).__init__(*args, **kwargs) diff --git a/QFlowLayout/HotPlaylist.py b/QFlowLayout/HotPlaylist.py index 2fef167..f50627d 100644 --- a/QFlowLayout/HotPlaylist.py +++ b/QFlowLayout/HotPlaylist.py @@ -1,33 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年2月4日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TencentMovieHotPlay_Flow @description: -''' +""" import os import sys import webbrowser from PyQt5.QtCore import QSize, Qt, QUrl, QTimer, pyqtSignal -from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor,\ +from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor, \ QBrush, QPaintEvent, QPixmap from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest from PyQt5.QtSvg import QSvgWidget -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel,\ +from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel, \ QHBoxLayout, QSpacerItem, QSizePolicy, QScrollArea, QAbstractSlider - -from Lib.flowlayout import FlowLayout # @UnresolvedImport from lxml.etree import HTML # @UnresolvedImport - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +from Lib.flowlayout import FlowLayout # @UnresolvedImport # offset=0,30,60,90 Url = "http://v.qq.com/x/list/movie?pay=-1&offset={0}" @@ -78,8 +73,8 @@ class CoverLabel(QLabel): def __init__(self, cover_path, cover_title, video_url, *args, **kwargs): super(CoverLabel, self).__init__(*args, **kwargs) -# super(CoverLabel, self).__init__( -# ''.format(os.path.abspath(cover_path)), *args, **kwargs) + # super(CoverLabel, self).__init__( + # ''.format(os.path.abspath(cover_path)), *args, **kwargs) self.setCursor(Qt.PointingHandCursor) self.setScaledContents(True) self.setMinimumSize(220, 308) @@ -168,7 +163,8 @@ class ItemWidget(QWidget): def setCover(self, path): self.clabel.setCoverPath(path) self.clabel.setPixmap(QPixmap(path)) -# self.clabel.setText(''.format(os.path.abspath(path))) + + # self.clabel.setText(''.format(os.path.abspath(path))) def sizeHint(self): # 每个item控件的大小 @@ -188,7 +184,6 @@ class ItemWidget(QWidget): class GridWidget(QWidget): - Page = 0 loadStarted = pyqtSignal(bool) @@ -252,11 +247,11 @@ class GridWidget(QWidget): figure_score = "".join(li.xpath(".//em/text()")) # 评分 # 主演 figure_desc = "主演:" + \ - "".join([Actor.format(**dict(fd.items())) - for fd in li.xpath(".//div[@class='figure_desc']/a")]) + "".join([Actor.format(**dict(fd.items())) + for fd in li.xpath(".//div[@class='figure_desc']/a")]) # 播放数 figure_count = ( - li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] + li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] path = "cache/{0}.jpg".format( os.path.splitext(os.path.basename(video_url))[0]) cover_path = "Data/pic_v.png" diff --git a/QFlowLayout/Lib/flowlayout.py b/QFlowLayout/Lib/flowlayout.py index ef1d54e..58315d1 100644 --- a/QFlowLayout/Lib/flowlayout.py +++ b/QFlowLayout/Lib/flowlayout.py @@ -152,7 +152,6 @@ class FlowLayout(QLayout): if __name__ == '__main__': - import sys app = QApplication(sys.argv) diff --git a/QFont/AwesomeFont.py b/QFont/AwesomeFont.py index 7d8098d..58b1baf 100644 --- a/QFont/AwesomeFont.py +++ b/QFont/AwesomeFont.py @@ -1,24 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AwesomeFont @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" import sys -from PyQt5.QtGui import QFontDatabase, QFont -from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout,\ - QScrollArea, QPushButton +try: + from PyQt5.QtGui import QFontDatabase, QFont + from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, \ + QScrollArea, QPushButton +except ImportError: + from PySide2.QtGui import QFontDatabase, QFont + from PySide2.QtWidgets import QApplication, QWidget, QGridLayout, \ + QScrollArea, QPushButton from Lib.FontAwesome import FontAwesomes # @UnresolvedImport @@ -44,7 +45,7 @@ class ScrollArea(QScrollArea): minimumHeight=33, font=QFont("FontAwesome", 14)), row, col, 1, 1) - + self.showMaximized() def resizeEvent(self, event): diff --git a/QFont/Data/提取字符/get.py b/QFont/Data/提取字符/get.py index 624999c..216d2e3 100644 --- a/QFont/Data/提取字符/get.py +++ b/QFont/Data/提取字符/get.py @@ -1,5 +1,6 @@ # from bs4 import BeautifulSoup import re + cheatsheet = open("cheatsheet.txt", "rb").read().decode() re_fa = re.compile(" fa(.*)") diff --git a/QFont/Lib/FontAwesome.py b/QFont/Lib/FontAwesome.py index 60ca9ca..3527c2e 100644 --- a/QFont/Lib/FontAwesome.py +++ b/QFont/Lib/FontAwesome.py @@ -1,21 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年3月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FontAwesome @description: -''' +""" + + # FontAwesome 版本: 4.7.0 # 字体图标地址: http://fontawesome.io/icons/ # 字体字符地址: http://fontawesome.io/cheatsheet/ class FontAwesomes: - FA = None @classmethod diff --git a/QGraphicsDropShadowEffect/Lib/AnimationShadowEffect.py b/QGraphicsDropShadowEffect/Lib/AnimationShadowEffect.py index 9cbbd75..4551bd4 100644 --- a/QGraphicsDropShadowEffect/Lib/AnimationShadowEffect.py +++ b/QGraphicsDropShadowEffect/Lib/AnimationShadowEffect.py @@ -4,20 +4,18 @@ """ Created on 2018年9月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AnimationShadowEffect @description: 边框动画阴影动画 """ -from PyQt5.QtCore import QPropertyAnimation, pyqtProperty -from PyQt5.QtWidgets import QGraphicsDropShadowEffect - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QPropertyAnimation, pyqtProperty + from PyQt5.QtWidgets import QGraphicsDropShadowEffect +except ImportError: + from PySide2.QtCore import QPropertyAnimation, Property as pyqtProperty + from PySide2.QtWidgets import QGraphicsDropShadowEffect class AnimationShadowEffect(QGraphicsDropShadowEffect): diff --git a/QGraphicsDropShadowEffect/ShadowEffect.py b/QGraphicsDropShadowEffect/ShadowEffect.py index 9c03cc6..b121e85 100644 --- a/QGraphicsDropShadowEffect/ShadowEffect.py +++ b/QGraphicsDropShadowEffect/ShadowEffect.py @@ -4,25 +4,24 @@ """ Created on 2018年9月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ShadowEffect @description: """ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit + +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPixmap + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPixmap + from PySide2.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit, QApplication from Lib.AnimationShadowEffect import AnimationShadowEffect # @UnresolvedImport -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class Window(QWidget): def __init__(self, *args, **kwargs): @@ -64,7 +63,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QGraphicsView/AddQWidget.py b/QGraphicsView/AddQWidget.py index 1689972..ff8026c 100644 --- a/QGraphicsView/AddQWidget.py +++ b/QGraphicsView/AddQWidget.py @@ -3,22 +3,22 @@ """ Created on 2017年12月23日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AddQWidget @description: """ import sys -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout,\ - QApplication, QGraphicsView, QGraphicsScene - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout, \ + QApplication, QGraphicsView, QGraphicsScene +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout, \ + QApplication, QGraphicsView, QGraphicsScene class ToolTipItem(QWidget): diff --git a/QGraphicsView/ImageView.py b/QGraphicsView/ImageView.py index 5058e59..f6789c5 100644 --- a/QGraphicsView/ImageView.py +++ b/QGraphicsView/ImageView.py @@ -4,21 +4,22 @@ """ Created on 2020/11/12 @author: Irony -@site: https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ImageView @description: 图片查看控件,支持移动、放大、缩小 """ -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020 Irony' -__Version__ = 1.0 - import os -from PyQt5.QtCore import QPointF, Qt, QRectF, QSizeF -from PyQt5.QtGui import QPainter, QColor, QImage, QPixmap -from PyQt5.QtWidgets import QGraphicsView, QGraphicsPixmapItem, QGraphicsScene +try: + from PyQt5.QtCore import QPointF, Qt, QRectF, QSizeF + from PyQt5.QtGui import QPainter, QColor, QImage, QPixmap + from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsPixmapItem, QGraphicsScene +except ImportError: + from PySide2.QtCore import QPointF, Qt, QRectF, QSizeF + from PySide2.QtGui import QPainter, QColor, QImage, QPixmap + from PySide2.QtWidgets import QApplication, QGraphicsView, QGraphicsPixmapItem, QGraphicsScene class ImageView(QGraphicsView): @@ -141,7 +142,6 @@ if __name__ == '__main__': import cgitb cgitb.enable(format='text') - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = ImageView(image='Data/bg.jpg', background=Qt.black) diff --git a/QGraphicsView/WorldMap.py b/QGraphicsView/WorldMap.py index 3efc7b1..32428df 100644 --- a/QGraphicsView/WorldMap.py +++ b/QGraphicsView/WorldMap.py @@ -3,8 +3,8 @@ """ Created on 2017年12月17日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: WorldMap @description: @@ -12,19 +12,19 @@ Created on 2017年12月17日 import json import math -from PyQt5.QtCore import Qt, QPointF, QRectF -from PyQt5.QtGui import QColor, QPainter, QPolygonF, QPen, QBrush -from PyQt5.QtOpenGL import QGLFormat -from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsPolygonItem - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt, QPointF, QRectF + from PyQt5.QtGui import QColor, QPainter, QPolygonF, QPen, QBrush + from PyQt5.QtOpenGL import QGLFormat + from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsPolygonItem +except ImportError: + from PySide2.QtCore import Qt, QPointF, QRectF + from PySide2.QtGui import QColor, QPainter, QPolygonF, QPen, QBrush + from PySide2.QtOpenGL import QGLFormat + from PySide2.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsPolygonItem class GraphicsView(QGraphicsView): - # 背景区域颜色 backgroundColor = QColor(31, 31, 47) # 边框颜色 @@ -94,8 +94,8 @@ class GraphicsView(QGraphicsView): AnchorUnderMouse 鼠标当前位置被用作锚点 ''' self.setTransformationAnchor(self.AnchorUnderMouse) -# if QGLFormat.hasOpenGL(): # 如果开启了OpenGL则使用OpenGL Widget -# self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers))) + # if QGLFormat.hasOpenGL(): # 如果开启了OpenGL则使用OpenGL Widget + # self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers))) ''' #参考 http://doc.qt.io/qt-5/qgraphicsview.html#ViewportUpdateMode-enum FullViewportUpdate 当场景的任何可见部分改变或重新显示时,QGraphicsView将更新整个视口。 当QGraphicsView花费更多的时间来计算绘制的内容(比如重复更新很多小项目)时,这种方法是最快的。 这是不支持部分更新(如QGLWidget)的视口以及需要禁用滚动优化的视口的首选更新模式。 @@ -157,7 +157,7 @@ class GraphicsView(QGraphicsView): if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) print("OpenGL Status:", QGLFormat.hasOpenGL()) view = GraphicsView() diff --git a/QGridLayout/HotPlaylist.py b/QGridLayout/HotPlaylist.py index a2022c2..43bce4e 100644 --- a/QGridLayout/HotPlaylist.py +++ b/QGridLayout/HotPlaylist.py @@ -1,34 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年2月4日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TencentMovieHotPlay @description: -''' +""" import os import sys import webbrowser from PyQt5.QtCore import QSize, Qt, QUrl, QTimer, pyqtSignal -from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor,\ +from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor, \ QBrush, QPaintEvent, QPixmap from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest from PyQt5.QtSvg import QSvgWidget -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel,\ - QHBoxLayout, QSpacerItem, QSizePolicy, QScrollArea, QGridLayout,\ +from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel, \ + QHBoxLayout, QSpacerItem, QSizePolicy, QScrollArea, QGridLayout, \ QAbstractSlider - from lxml.etree import HTML # @UnresolvedImport - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - # offset=0,30,60,90 Url = "http://v.qq.com/x/list/movie?pay=-1&offset={0}" @@ -166,7 +160,8 @@ class ItemWidget(QWidget): def setCover(self, path): self.clabel.setCoverPath(path) self.clabel.setPixmap(QPixmap(path)) -# self.clabel.setText(''.format(os.path.abspath(path))) + + # self.clabel.setText(''.format(os.path.abspath(path))) def sizeHint(self): # 每个item控件的大小 @@ -186,7 +181,6 @@ class ItemWidget(QWidget): class GridWidget(QWidget): - Page = 0 loadStarted = pyqtSignal(bool) @@ -268,18 +262,19 @@ class GridWidget(QWidget): figure_score = "".join(li.xpath(".//em/text()")) # 评分 # 主演 figure_desc = "主演:" + \ - "".join([Actor.format(**dict(fd.items())) - for fd in li.xpath(".//div[@class='figure_desc']/a")]) + "".join([Actor.format(**dict(fd.items())) + for fd in li.xpath(".//div[@class='figure_desc']/a")]) # 播放数 figure_count = ( - li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] + li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] path = "cache/{0}.jpg".format( os.path.splitext(os.path.basename(video_url))[0]) cover_path = "Data/pic_v.png" if os.path.isfile(path): cover_path = path iwidget = ItemWidget(cover_path, figure_info, figure_title, - figure_score, figure_desc, figure_count, video_url, cover_url, path, self) + figure_score, figure_desc, figure_count, video_url, cover_url, path, + self) self._layout.addWidget(iwidget, row_count + row, col) diff --git a/QLabel/CircleImage.py b/QLabel/CircleImage.py index 0c805cb..7b59420 100644 --- a/QLabel/CircleImage.py +++ b/QLabel/CircleImage.py @@ -3,19 +3,21 @@ """ Created on 2018年1月20日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CircleImage @description: 圆形图片 """ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap, QPainter, QPainterPath -from PyQt5.QtWidgets import QLabel, QWidget, QHBoxLayout -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPixmap, QPainter, QPainterPath + from PyQt5.QtWidgets import QLabel, QWidget, QHBoxLayout, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPixmap, QPainter, QPainterPath + from PySide2.QtWidgets import QLabel, QWidget, QHBoxLayout, QApplication class Label(QLabel): @@ -67,7 +69,6 @@ class Window(QWidget): if __name__ == "__main__": import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QLabel/ImageRotate.py b/QLabel/ImageRotate.py index f0dd48d..142299b 100644 --- a/QLabel/ImageRotate.py +++ b/QLabel/ImageRotate.py @@ -4,22 +4,22 @@ """ Created on 2018年11月19日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: @description: """ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap, QPainter, QImage -from PyQt5.QtWidgets import QWidget, QLabel, QPushButton,\ - QVBoxLayout, QHBoxLayout, QSpacerItem, QSizePolicy - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPixmap, QPainter, QImage + from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, \ + QVBoxLayout, QHBoxLayout, QSpacerItem, QSizePolicy, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPixmap, QPainter, QImage + from PySide2.QtWidgets import QWidget, QLabel, QPushButton, \ + QVBoxLayout, QHBoxLayout, QSpacerItem, QSizePolicy, QApplication class Window(QWidget): @@ -73,12 +73,12 @@ class Window(QWidget): self.srcImage = image # 替换 self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) -# # 下面这个旋转方法针对90度的倍数,否则图片会变大 -# trans = QTransform() -# trans.rotate(90) -# self.srcImage = self.srcImage.transformed( -# trans, Qt.SmoothTransformation) -# self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) + # # 下面这个旋转方法针对90度的倍数,否则图片会变大 + # trans = QTransform() + # trans.rotate(90) + # self.srcImage = self.srcImage.transformed( + # trans, Qt.SmoothTransformation) + # self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) def doAnticlockwise(self): # 逆时针45度 @@ -96,6 +96,7 @@ class Window(QWidget): self.srcImage = image # 替换 self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) + # # 下面这个旋转方法针对90度的倍数,否则图片会变大 # trans = QTransform() # trans.rotate(90) @@ -106,7 +107,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QLabel/ImageSlipped.py b/QLabel/ImageSlipped.py index dfcac07..1ea7818 100644 --- a/QLabel/ImageSlipped.py +++ b/QLabel/ImageSlipped.py @@ -4,20 +4,18 @@ """ Created on 2018年10月18日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ImageSlipped @description: """ -from PyQt5.QtGui import QPixmap, QPainter -from PyQt5.QtWidgets import QWidget - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtGui import QPixmap, QPainter + from PyQt5.QtWidgets import QWidget, QApplication +except ImportError: + from PySide2.QtGui import QPixmap, QPainter + from PySide2.QtWidgets import QWidget, QApplication class SlippedImgWidget(QWidget): @@ -73,7 +71,7 @@ class SlippedImgWidget(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = SlippedImgWidget('Data/bg1.jpg', 'Data/fg1.png') w.show() diff --git a/QLabel/Lib/NinePatch.py b/QLabel/Lib/NinePatch.py index 966903a..e157f1b 100644 --- a/QLabel/Lib/NinePatch.py +++ b/QLabel/Lib/NinePatch.py @@ -4,22 +4,19 @@ """ Created on 2018年10月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: NinePatch @description: """ from math import fabs -from PyQt5.QtCore import QRect -from PyQt5.QtGui import QImage, QColor, QPainter, qRed, qGreen, qBlue, qAlpha - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QRect + from PyQt5.QtGui import QImage, QColor, QPainter, qRed, qGreen, qBlue, qAlpha +except ImportError: + from PySide2.QtCore import QRect + from PySide2.QtGui import QImage, QColor, QPainter, qRed, qGreen, qBlue, qAlpha class _Exception(Exception): @@ -44,7 +41,8 @@ class ExceptionIncorrectWidth(_Exception): class ExceptionIncorrectWidthAndHeight(_Exception): def __str__(self): - return "Input incorrect width width and height. Minimum width = :{imgW} . Minimum height = :{imgH}".format(imgW=self.imgW, imgH=self.imgH) + return "Input incorrect width width and height. Minimum width = :{imgW} . Minimum height = :{imgH}".format( + imgW=self.imgW, imgH=self.imgH) class ExceptionIncorrectHeight(_Exception): @@ -62,11 +60,11 @@ class ExceptionNot9Patch(Exception): class NinePatch: def __init__(self, fileName): - self.CachedImage = None # 缓存图片 + self.CachedImage = None # 缓存图片 self.OldWidth = -1 self.OldHeight = -1 self.ResizeDistancesX = [] - self.ResizeDistancesY = [] # [(int,int)]数组 + self.ResizeDistancesY = [] # [(int,int)]数组 self.setImage(fileName) def width(self): @@ -103,7 +101,8 @@ class NinePatch: for i in range(len(self.ResizeDistancesY)): resizeHeight += self.ResizeDistancesY[i][1] - if (width < (self.Image.width() - 2 - resizeWidth) and height < (self.Image.height() - 2 - resizeHeight)): + if (width < (self.Image.width() - 2 - resizeWidth) and height < ( + self.Image.height() - 2 - resizeHeight)): raise ExceptionIncorrectWidthAndHeight( self.Image.width() - 2, self.Image.height() - 2) @@ -123,7 +122,8 @@ class NinePatch: @classmethod def GetContentAreaRect(self, width, height): # print("GetContentAreaRect : width:%d height:%d" % (width, height)) - return (QRect(self.ContentArea.x(), self.ContentArea.y(), (width - (self.Image.width() - 2 - self.ContentArea.width())), + return (QRect(self.ContentArea.x(), self.ContentArea.y(), + (width - (self.Image.width() - 2 - self.ContentArea.width())), (height - (self.Image.height() - 2 - self.ContentArea.height())))) def DrawScaledPart(self, oldRect, newRect, painter): @@ -189,7 +189,8 @@ class NinePatch: for i in range(self.Image.width()): if (self.IsColorBlack(self.Image.pixel(i, j)) and left == 0): left = i - if (left and self.IsColorBlack(self.Image.pixel(i, j)) and not self.IsColorBlack(self.Image.pixel(i + 1, j))): + if (left and self.IsColorBlack(self.Image.pixel(i, j)) and not self.IsColorBlack( + self.Image.pixel(i + 1, j))): right = i left -= 1 # print("ResizeDistancesX.append ", left, " ", right - left) @@ -204,7 +205,8 @@ class NinePatch: if (self.IsColorBlack(self.Image.pixel(i, j)) and top == 0): top = j - if (top and self.IsColorBlack(self.Image.pixel(i, j)) and not self.IsColorBlack(self.Image.pixel(i, j + 1))): + if (top and self.IsColorBlack(self.Image.pixel(i, j)) and not self.IsColorBlack( + self.Image.pixel(i, j + 1))): bot = j top -= 1 # print("ResizeDistancesY.append ", top, " ", bot - top) @@ -241,10 +243,10 @@ class NinePatch: # print("after GetFactor: ", width, height, factorX, factorY) lostX = 0.0 lostY = 0.0 - x1 = 0 # for image parts X - y1 = 0 # for image parts Y -# widthResize # width for image parts -# heightResize # height for image parts + x1 = 0 # for image parts X + y1 = 0 # for image parts Y + # widthResize # width for image parts + # heightResize # height for image parts resizeX = 0 resizeY = 0 offsetX = 0 @@ -310,7 +312,8 @@ class NinePatch: offsetY = 0 for i in range(len(self.ResizeDistancesY)): self.DrawConstPart(QRect(x1 + 1, y1 + 1, widthResize, self.ResizeDistancesY[i][0] - y1), - QRect(x1 + offsetX, y1 + offsetY, widthResize, self.ResizeDistancesY[i][0] - y1), painter) + QRect(x1 + offsetX, y1 + offsetY, widthResize, + self.ResizeDistancesY[i][0] - y1), painter) y1 = self.ResizeDistancesY[i][0] resizeY = round(float(self.ResizeDistancesY[i][1]) * factorY) lostY += resizeY - (float(self.ResizeDistancesY[i][1]) * factorY) @@ -334,7 +337,8 @@ class NinePatch: offsetX = 0 for i in range(len(self.ResizeDistancesX)): self.DrawConstPart(QRect(x1 + 1, y1 + 1, self.ResizeDistancesX[i][0] - x1, heightResize), - QRect(x1 + offsetX, y1 + offsetY, self.ResizeDistancesX[i][0] - x1, heightResize), painter) + QRect(x1 + offsetX, y1 + offsetY, self.ResizeDistancesX[i][0] - x1, + heightResize), painter) x1 = self.ResizeDistancesX[i][0] resizeX = round(float(self.ResizeDistancesX[i][1]) * factorX) lostX += resizeX - (float(self.ResizeDistancesX[i][1]) * factorX) diff --git a/QLabel/Lib/QtNinePatch/sip/configure.py b/QLabel/Lib/QtNinePatch/sip/configure.py index eae22a5..a3cc255 100644 --- a/QLabel/Lib/QtNinePatch/sip/configure.py +++ b/QLabel/Lib/QtNinePatch/sip/configure.py @@ -5,9 +5,8 @@ import os import shutil import PyQt5 -from PyQt5.QtCore import PYQT_CONFIGURATION import sipconfig - +from PyQt5.QtCore import PYQT_CONFIGURATION # 模块名 moduleName = 'QtNinePatch' @@ -35,14 +34,13 @@ sip_cmd = ' '.join([ '-b', "build/" + build_file, '-I', config.default_sip_dir + '/PyQt5', PYQT_CONFIGURATION.get('sip_flags', ''), - '%s.sip' % moduleName, + '%s.sip' % moduleName, ]) os.makedirs('build', exist_ok=True) print(sip_cmd) os.system(sip_cmd) - # Create the Makefile. makefile = sipconfig.SIPModuleMakefile( config, build_file, dir='build' diff --git a/QLabel/Lib/QtNinePatch2.py b/QLabel/Lib/QtNinePatch2.py index b0a8435..7697cc6 100644 --- a/QLabel/Lib/QtNinePatch2.py +++ b/QLabel/Lib/QtNinePatch2.py @@ -4,22 +4,19 @@ """ Created on 2018年10月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtNinePatch @description: """ from math import floor -from PyQt5.QtCore import Qt, QRect -from PyQt5.QtGui import qAlpha, QPixmap, QPainter - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt, QRect + from PyQt5.QtGui import qAlpha, QPixmap, QPainter +except ImportError: + from PySide2.QtCore import Qt, QRect + from PySide2.QtGui import qAlpha, QPixmap, QPainter class Part: diff --git a/QLabel/Lib/res_rc.py b/QLabel/Lib/res_rc.py index baab0b9..0bebdc4 100644 --- a/QLabel/Lib/res_rc.py +++ b/QLabel/Lib/res_rc.py @@ -6,7 +6,10 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore +try: + from PyQt5 import QtCore +except ImportError: + from PySide2 import QtCore qt_resource_data = b"\ \x00\x00\x19\xf0\ @@ -462,10 +465,13 @@ else: rcc_version = 2 qt_resource_struct = qt_resource_struct_v2 + def qInitResources(): QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) + def qCleanupResources(): QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) + qInitResources() diff --git a/QLabel/Lib/xpmres.py b/QLabel/Lib/xpmres.py index fea8f79..b589c8d 100644 --- a/QLabel/Lib/xpmres.py +++ b/QLabel/Lib/xpmres.py @@ -1,18 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月23日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: xpmres @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" # 这里把转换的xpm数组直接放到py文件中当做一个变量 diff --git a/QLabel/NinePatch.py b/QLabel/NinePatch.py index 936faf7..f072dc1 100644 --- a/QLabel/NinePatch.py +++ b/QLabel/NinePatch.py @@ -4,23 +4,20 @@ """ Created on 2018年10月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: NinePatch @description: """ - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - import sys -from PyQt5.QtGui import QImage, QPainter -from PyQt5.QtWidgets import QApplication, QLabel, QWidget +try: + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication, QWidget +except ImportError: + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication, QWidget from Lib.NinePatch import NinePatch @@ -29,7 +26,7 @@ class Label(QWidget): def __init__(self, *args, **kwargs): super(Label, self).__init__(*args, **kwargs) - #.9 格式的图片 + # .9 格式的图片 self.image = NinePatch('Data/skin_aio_friend_bubble_pressed.9.png') def paintEvent(self, event): diff --git a/QLabel/QtNinePatch.py b/QLabel/QtNinePatch.py index 8fbdbc9..497b7bf 100644 --- a/QLabel/QtNinePatch.py +++ b/QLabel/QtNinePatch.py @@ -4,22 +4,15 @@ """ Created on 2018年10月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: testQtNinePatch @description: """ - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - import sys - from ctypes import CDLL + from PyQt5.QtGui import QImage from PyQt5.QtWidgets import QApplication, QLabel @@ -32,7 +25,7 @@ class Label(QLabel): def __init__(self, *args, **kwargs): super(Label, self).__init__(*args, **kwargs) - #.9 格式的图片 + # .9 格式的图片 self.image = QImage('Data/skin_aio_friend_bubble_pressed.9.png') def showEvent(self, event): diff --git a/QLabel/QtNinePatch2.py b/QLabel/QtNinePatch2.py index 187b15c..f861461 100644 --- a/QLabel/QtNinePatch2.py +++ b/QLabel/QtNinePatch2.py @@ -4,23 +4,20 @@ """ Created on 2018年10月25日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtNinePatch2 @description: """ - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - import sys -from PyQt5.QtGui import QImage -from PyQt5.QtWidgets import QApplication, QLabel +try: + from PyQt5.QtGui import QImage + from PyQt5.QtWidgets import QApplication, QLabel +except ImportError: + from PySide2.QtGui import QImage + from PySide2.QtWidgets import QApplication, QLabel from Lib import QtNinePatch2 @@ -29,7 +26,7 @@ class Label(QLabel): def __init__(self, *args, **kwargs): super(Label, self).__init__(*args, **kwargs) - #.9 格式的图片 + # .9 格式的图片 self.image = QImage('Data/skin_aio_friend_bubble_pressed.9.png') def showEvent(self, event): diff --git a/QLabel/ShowImage.py b/QLabel/ShowImage.py index ac3fb9f..41ca08e 100644 --- a/QLabel/ShowImage.py +++ b/QLabel/ShowImage.py @@ -1,29 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月23日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ShowImage @description: -''' +""" import sys -from PyQt5.QtCore import QResource -from PyQt5.QtGui import QPixmap, QMovie -from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout, QLabel +try: + from PyQt5.QtCore import QResource + from PyQt5.QtGui import QPixmap, QMovie + from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout, QLabel +except ImportError: + from PySide2.QtCore import QResource + from PySide2.QtGui import QPixmap, QMovie + from PySide2.QtWidgets import QWidget, QApplication, QHBoxLayout, QLabel -from Lib import res_rc # @UnresolvedImport @UnusedImport from Lib.xpmres import image_head # @UnresolvedImport -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - - class ImageView(QWidget): def __init__(self, *args, **kwargs): diff --git a/QListView/CustomWidgetItem.py b/QListView/CustomWidgetItem.py index 6a8a1be..3bffcac 100644 --- a/QListView/CustomWidgetItem.py +++ b/QListView/CustomWidgetItem.py @@ -1,22 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from PyQt5.QtCore import QSize -from PyQt5.QtGui import QStandardItemModel, QStandardItem -from PyQt5.QtWidgets import QListView, QWidget, QHBoxLayout, QLineEdit,\ - QPushButton -# Created on 2018年8月4日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: QListView.显示自定义Widget -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +""" +Created on 2018年8月4日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: QListView.显示自定义Widget +@description: +""" + +try: + from PyQt5.QtCore import QSize + from PyQt5.QtGui import QStandardItemModel, QStandardItem + from PyQt5.QtWidgets import QListView, QWidget, QHBoxLayout, QLineEdit, \ + QPushButton, QApplication +except ImportError: + from PySide2.QtCore import QSize + from PySide2.QtGui import QStandardItemModel, QStandardItem + from PySide2.QtWidgets import QListView, QWidget, QHBoxLayout, QLineEdit, \ + QPushButton, QApplication class CustomWidget(QWidget): @@ -56,7 +60,7 @@ class ListView(QListView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = ListView() w.show() diff --git a/QListView/CustomWidgetSortItem.py b/QListView/CustomWidgetSortItem.py index 09fe903..3a68ef2 100644 --- a/QListView/CustomWidgetSortItem.py +++ b/QListView/CustomWidgetSortItem.py @@ -1,26 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from random import choice, randint + + +""" +Created on 2018年8月4日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: QListView.显示自定义Widget并排序 +@description: +""" import string +from random import choice, randint from time import time -from PyQt5.QtCore import QSortFilterProxyModel, Qt, QSize -from PyQt5.QtGui import QStandardItem, QStandardItemModel -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListView,\ - QHBoxLayout, QLineEdit - - -# Created on 2018年8月4日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: QListView.显示自定义Widget并排序 -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QSortFilterProxyModel, Qt, QSize + from PyQt5.QtGui import QStandardItem, QStandardItemModel + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListView, \ + QHBoxLayout, QLineEdit, QApplication +except ImportError: + from PySide2.QtCore import QSortFilterProxyModel, Qt, QSize + from PySide2.QtGui import QStandardItem, QStandardItemModel + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListView, \ + QHBoxLayout, QLineEdit, QApplication def randomChar(y): @@ -55,11 +58,11 @@ class SortFilterProxyModel(QSortFilterProxyModel): leftData = leftData.split('-')[-1] rightData = rightData.split('-')[-1] return leftData < rightData -# elif self.sortOrder() == Qt.AscendingOrder: -# #按照名字升序排序 -# leftData = leftData.split('-')[0] -# rightData = rightData.split('-')[0] -# return leftData < rightData + # elif self.sortOrder() == Qt.AscendingOrder: + # #按照名字升序排序 + # leftData = leftData.split('-')[0] + # rightData = rightData.split('-')[0] + # return leftData < rightData return super(SortFilterProxyModel, self).lessThan(source_left, source_right) @@ -89,7 +92,7 @@ class Window(QWidget): times = time() + randint(0, 30) # 当前时间随机+ value = '{}-{}'.format(name, times) # 内容用-分开 item = QStandardItem(value) -# item.setData(value, Qt.UserRole + 2) + # item.setData(value, Qt.UserRole + 2) self.dmodel.appendRow(item) # 索引 index = self.fmodel.mapFromSource(item.index()) @@ -109,7 +112,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QListView/ImageView.py b/QListView/ImageView.py index 2f3aa01..b030806 100644 --- a/QListView/ImageView.py +++ b/QListView/ImageView.py @@ -4,16 +4,21 @@ """ Created on 2021/4/15 @author: Irony -@site: https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ImageView @description: """ import os -from PyQt5.QtCore import QPointF, Qt, QRectF, QSizeF -from PyQt5.QtGui import QStandardItem, QStandardItemModel, QPainter, QColor, QImage, QPixmap -from PyQt5.QtWidgets import QListView, QGraphicsView, QGraphicsPixmapItem, QGraphicsScene +try: + from PyQt5.QtCore import QPointF, Qt, QRectF, QSizeF + from PyQt5.QtGui import QStandardItem, QStandardItemModel, QPainter, QColor, QImage, QPixmap + from PyQt5.QtWidgets import QApplication, QListView, QGraphicsView, QGraphicsPixmapItem, QGraphicsScene +except ImportError: + from PySide2.QtCore import QPointF, Qt, QRectF, QSizeF + from PySide2.QtGui import QStandardItem, QStandardItemModel, QPainter, QColor, QImage, QPixmap + from PySide2.QtWidgets import QApplication, QListView, QGraphicsView, QGraphicsPixmapItem, QGraphicsScene ScrollPixel = 40 @@ -223,7 +228,6 @@ if __name__ == '__main__': import cgitb cgitb.enable(format='text') - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = ImageView() diff --git a/QListView/SortItemByRole.py b/QListView/SortItemByRole.py index b0a963e..d4ccd87 100644 --- a/QListView/SortItemByRole.py +++ b/QListView/SortItemByRole.py @@ -4,23 +4,21 @@ """ Created on 2018年12月27日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QListView.SortItemByRole @description: """ from random import choice -from PyQt5.QtCore import QSortFilterProxyModel, Qt -from PyQt5.QtGui import QStandardItem, QStandardItemModel -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QListView, QPushButton - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QSortFilterProxyModel, Qt + from PyQt5.QtGui import QStandardItem, QStandardItemModel + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QListView, QPushButton +except ImportError: + from PySide2.QtCore import QSortFilterProxyModel, Qt + from PySide2.QtGui import QStandardItem, QStandardItemModel + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QListView, QPushButton class SortFilterProxyModel(QSortFilterProxyModel): @@ -72,8 +70,8 @@ IndexDict = { 4: '清', } -IdRole = Qt.UserRole + 1 # 用于恢复排序 -ClassifyRole = Qt.UserRole + 2 # 用于按照分类序号排序 +IdRole = Qt.UserRole + 1 # 用于恢复排序 +ClassifyRole = Qt.UserRole + 2 # 用于按照分类序号排序 class Window(QWidget): @@ -96,8 +94,8 @@ class Window(QWidget): def restoreSort(self): # 恢复默认排序 - self.fmodel.setSortRole(IdRole) # 必须设置排序角色为ID - self.fmodel.sort(0) # 排序第一列按照ID升序 + self.fmodel.setSortRole(IdRole) # 必须设置排序角色为ID + self.fmodel.sort(0) # 排序第一列按照ID升序 def sortByClassify(self): self.fmodel.setSortIndex(NameDict.get( @@ -141,8 +139,9 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QListWidget/DeleteCustomItem.py b/QListWidget/DeleteCustomItem.py index 73c972e..ab8516e 100644 --- a/QListWidget/DeleteCustomItem.py +++ b/QListWidget/DeleteCustomItem.py @@ -4,25 +4,23 @@ """ Created on 2018年11月4日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 删除Item @description: """ -from PyQt5.QtCore import QSize, pyqtSignal -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLineEdit, QPushButton,\ - QListWidgetItem, QVBoxLayout, QListWidget - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QSize, pyqtSignal + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLineEdit, QPushButton, \ + QListWidgetItem, QVBoxLayout, QListWidget, QApplication +except ImportError: + from PySide2.QtCore import QSize, Signal as pyqtSignal + from PySide2.QtWidgets import QWidget, QHBoxLayout, QLineEdit, QPushButton, \ + QListWidgetItem, QVBoxLayout, QListWidget, QApplication class ItemWidget(QWidget): - itemDeleted = pyqtSignal(QListWidgetItem) def __init__(self, text, item, *args, **kwargs): @@ -91,8 +89,9 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QListWidget/DragDrop.py b/QListWidget/DragDrop.py index dcc8818..0df4479 100644 --- a/QListWidget/DragDrop.py +++ b/QListWidget/DragDrop.py @@ -4,21 +4,20 @@ """ Created on 2018年9月14日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: DragListWidget @description: """ -from PyQt5.QtCore import Qt, QSize, QRect, QPoint -from PyQt5.QtGui import QColor, QPixmap, QDrag, QPainter, QCursor -from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QLabel, QRubberBand - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt, QSize, QRect, QPoint + from PyQt5.QtGui import QColor, QPixmap, QDrag, QPainter, QCursor + from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QLabel, QRubberBand, QApplication +except ImportError: + from PySide2.QtCore import Qt, QSize, QRect, QPoint + from PySide2.QtGui import QColor, QPixmap, QDrag, QPainter, QCursor + from PySide2.QtWidgets import QListWidget, QListWidgetItem, QLabel, QRubberBand, QApplication class DropListWidget(QListWidget): @@ -162,7 +161,7 @@ class DragListWidget(QListWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet("""QListWidget { outline: 0px; diff --git a/QListWidget/FoldWidget.py b/QListWidget/FoldWidget.py index ac383b4..7f75a8d 100644 --- a/QListWidget/FoldWidget.py +++ b/QListWidget/FoldWidget.py @@ -4,22 +4,17 @@ """ Created on 2019年5月27日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FoldWidget @description: 自定义item折叠控件仿QTreeWidget """ from PyQt5.QtCore import QSize -from PyQt5.QtWidgets import QWidget, QPushButton, QFormLayout,\ +from PyQt5.QtWidgets import QWidget, QPushButton, QFormLayout, \ QLineEdit, QListWidget, QListWidgetItem, QCheckBox -__Author__ = "Irony" -__Copyright__ = "Copyright (c) 2019" -__Version__ = "Version 1.0" - - class CustomWidget(QWidget): def __init__(self, item, *args, **kwargs): @@ -79,8 +74,10 @@ class Window(QListWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + + cgitb.enable(format='text') from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) # 通过qss改变按钮的高度 app.setStyleSheet('#testBtn{min-height:40px;}') diff --git a/QListWidget/HotPlaylist.py b/QListWidget/HotPlaylist.py index bcba0d6..4738794 100644 --- a/QListWidget/HotPlaylist.py +++ b/QListWidget/HotPlaylist.py @@ -1,34 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年2月4日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TencentMovieHotPlay_ListWidget @description: -''' +""" import os import sys import webbrowser from PyQt5.QtCore import QSize, Qt, QUrl, QTimer -from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor,\ +from PyQt5.QtGui import QPainter, QFont, QLinearGradient, QGradient, QColor, \ QBrush, QPaintEvent, QPixmap from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest from PyQt5.QtSvg import QSvgWidget -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel,\ - QHBoxLayout, QSpacerItem, QSizePolicy, QAbstractSlider,\ +from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QLabel, \ + QHBoxLayout, QSpacerItem, QSizePolicy, QAbstractSlider, \ QListWidget, QListWidgetItem - from lxml.etree import HTML # @UnresolvedImport - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - # offset=0,30,60,90 Url = "http://v.qq.com/x/list/movie?pay=-1&offset={0}" @@ -78,8 +72,8 @@ class CoverLabel(QLabel): def __init__(self, cover_path, cover_title, video_url, *args, **kwargs): super(CoverLabel, self).__init__(*args, **kwargs) -# super(CoverLabel, self).__init__( -# ''.format(os.path.abspath(cover_path)), *args, **kwargs) + # super(CoverLabel, self).__init__( + # ''.format(os.path.abspath(cover_path)), *args, **kwargs) self.setCursor(Qt.PointingHandCursor) self.setScaledContents(True) self.setMinimumSize(220, 308) @@ -131,7 +125,8 @@ class CoverLabel(QLabel): class ItemWidget(QWidget): def __init__(self, cover_path, figure_info, figure_title, - figure_score, figure_desc, figure_count, video_url, cover_url, img_path, manager, *args, **kwargs): + figure_score, figure_desc, figure_count, video_url, cover_url, img_path, manager, *args, + **kwargs): super(ItemWidget, self).__init__(*args, **kwargs) self.setMaximumSize(220, 420) self.setMaximumSize(220, 420) @@ -169,7 +164,8 @@ class ItemWidget(QWidget): def setCover(self, path): self.clabel.setCoverPath(path) self.clabel.setPixmap(QPixmap(path)) -# self.clabel.setText(''.format(os.path.abspath(path))) + + # self.clabel.setText(''.format(os.path.abspath(path))) def sizeHint(self): # 每个item控件的大小 @@ -189,7 +185,6 @@ class ItemWidget(QWidget): class Window(QListWidget): - Page = 0 def __init__(self, *args, **kwargs): @@ -267,18 +262,19 @@ class Window(QListWidget): figure_score = "".join(li.xpath(".//em/text()")) # 评分 # 主演 figure_desc = "主演:" + \ - "".join([Actor.format(**dict(fd.items())) - for fd in li.xpath(".//div[@class='figure_desc']/a")]) + "".join([Actor.format(**dict(fd.items())) + for fd in li.xpath(".//div[@class='figure_desc']/a")]) # 播放数 figure_count = ( - li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] + li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0] path = "cache/{0}.jpg".format( os.path.splitext(os.path.basename(video_url))[0]) cover_path = "Data/pic_v.png" if os.path.isfile(path): cover_path = path iwidget = ItemWidget(cover_path, figure_info, figure_title, - figure_score, figure_desc, figure_count, video_url, cover_url, path, self._manager, self) + figure_score, figure_desc, figure_count, video_url, cover_url, path, + self._manager, self) item = QListWidgetItem(self) item.setSizeHint(iwidget.sizeHint()) self.setItemWidget(item, iwidget) diff --git a/QListWidget/SignalsExample.py b/QListWidget/SignalsExample.py index bb17e42..38f20c2 100644 --- a/QListWidget/SignalsExample.py +++ b/QListWidget/SignalsExample.py @@ -4,20 +4,22 @@ """ Created on 2019年7月3日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QListWidget.SignalsExample @description: """ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QColor -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QListWidget, QPlainTextEdit,\ - QListWidgetItem, QAbstractItemView, QListView - -__Author__ = "Irony" -__Copyright__ = "Copyright (c) 2019" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QColor + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QListWidget, QPlainTextEdit, \ + QListWidgetItem, QAbstractItemView, QListView, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QColor + from PySide2.QtWidgets import QWidget, QHBoxLayout, QListWidget, QPlainTextEdit, \ + QListWidgetItem, QAbstractItemView, QListView, QApplication def formatColor(text, color): @@ -118,7 +120,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QMenu/MultiSelect.py b/QMenu/MultiSelect.py index 1708d22..31a78c8 100644 --- a/QMenu/MultiSelect.py +++ b/QMenu/MultiSelect.py @@ -4,20 +4,16 @@ """ Created on 2018年10月24日 @author: Irony -@site: https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: MultiSelect @description: """ -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QMenu,\ - QAction - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QMenu, QAction +except ImportError: + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QMenu, QAction class Window(QWidget): @@ -70,8 +66,9 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.resize(400, 400) diff --git a/QMenu/QQMenu.py b/QMenu/QQMenu.py index 5a144bb..a561eb4 100644 --- a/QMenu/QQMenu.py +++ b/QMenu/QQMenu.py @@ -4,7 +4,7 @@ """ Created on 2021/4/7 @author: Irony -@site: https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QQMenu @description: @@ -12,9 +12,14 @@ Created on 2021/4/7 import string from random import choice, randint -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap, QPainter, QFont, QIcon -from PyQt5.QtWidgets import QLabel, QMenu, QApplication +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPixmap, QPainter, QFont, QIcon + from PyQt5.QtWidgets import QLabel, QMenu, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPixmap, QPainter, QFont, QIcon + from PySide2.QtWidgets import QLabel, QMenu, QApplication Style = """ QMenu { @@ -121,7 +126,7 @@ if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) app.setStyleSheet(Style) w = Window() diff --git a/QMessageBox/ChineseText.py b/QMessageBox/ChineseText.py index e1e766d..8ba7277 100644 --- a/QMessageBox/ChineseText.py +++ b/QMessageBox/ChineseText.py @@ -4,19 +4,17 @@ """ Created on 2019年7月10日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ChineseText @description: 修改消息对话框文字汉化 """ import sys -from PyQt5.QtWidgets import QApplication, QMessageBox - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtWidgets import QApplication, QMessageBox +except ImportError: + from PySide2.QtWidgets import QApplication, QMessageBox TextStyle = """ QMessageBox QPushButton[text="OK"] { diff --git a/QMessageBox/CountDownClose.py b/QMessageBox/CountDownClose.py index 2252ce0..e582bb5 100644 --- a/QMessageBox/CountDownClose.py +++ b/QMessageBox/CountDownClose.py @@ -4,22 +4,19 @@ """ Created on 2018年6月22日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: MessageBox @description: """ from random import randrange -from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QMessageBox - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtWidgets import QApplication, QMessageBox, QPushButton +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtWidgets import QApplication, QMessageBox, QPushButton class MessageBox(QMessageBox): @@ -53,7 +50,7 @@ class MessageBox(QMessageBox): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication, QPushButton + app = QApplication(sys.argv) w = QPushButton('点击弹出对话框') w.resize(200, 200) diff --git a/QMessageBox/CustomColorIcon.py b/QMessageBox/CustomColorIcon.py index 53d95c1..e41748c 100644 --- a/QMessageBox/CustomColorIcon.py +++ b/QMessageBox/CustomColorIcon.py @@ -1,23 +1,21 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月17日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CustomBtnIcon @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" import sys -from PyQt5.QtWidgets import QApplication, QMessageBox - +try: + from PyQt5.QtWidgets import QApplication, QMessageBox +except ImportError: + from PySide2.QtWidgets import QApplication, QMessageBox app = QApplication(sys.argv) app.setStyleSheet('''QDialogButtonBox { @@ -62,15 +60,15 @@ QMessageBox QPushButton[text="Apply"] { } ''') QMessageBox.information(None, "information", "消息", - QMessageBox.Apply | - QMessageBox.Cancel | - QMessageBox.Close | - QMessageBox.Discard | - QMessageBox.Help | - QMessageBox.No | - QMessageBox.Ok | - QMessageBox.Open | - QMessageBox.Reset | - QMessageBox.Save | - QMessageBox.Yes) + QMessageBox.Apply | + QMessageBox.Cancel | + QMessageBox.Close | + QMessageBox.Discard | + QMessageBox.Help | + QMessageBox.No | + QMessageBox.Ok | + QMessageBox.Open | + QMessageBox.Reset | + QMessageBox.Save | + QMessageBox.Yes) sys.exit() diff --git a/QProgressBar/Lib/DWaterProgress.py b/QProgressBar/Lib/DWaterProgress.py index 0b6e69f..9242ada 100644 --- a/QProgressBar/Lib/DWaterProgress.py +++ b/QProgressBar/Lib/DWaterProgress.py @@ -4,7 +4,7 @@ """ Created on 2021/1/1 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: DWaterProgress @see https://github.com/linuxdeepin/dtkwidget/blob/master/src/widgets/dwaterprogress.cpp @@ -12,10 +12,18 @@ Created on 2021/1/1 """ import math -from PyQt5.QtCore import pyqtSlot, QTimer, QSizeF, Qt, QRectF, QPointF, QRect, QPoint, QSize -from PyQt5.QtGui import QImage, QColor, QPainter, QLinearGradient, QGradient, QPainterPath, QPixmap, QBrush, QPen -from PyQt5.QtSvg import QSvgRenderer -from PyQt5.QtWidgets import QProgressBar, QGraphicsDropShadowEffect +try: + from PyQt5.QtCore import pyqtSlot, QTimer, QSizeF, Qt, QRectF, QPointF, QRect, QPoint, QSize + from PyQt5.QtGui import QImage, QColor, QPainter, QLinearGradient, QGradient, QPainterPath, QPixmap, \ + QBrush, QPen + from PyQt5.QtSvg import QSvgRenderer + from PyQt5.QtWidgets import QProgressBar, QGraphicsDropShadowEffect +except ImportError: + from PySide2.QtCore import Slot as pyqtSlot, QTimer, QSizeF, Qt, QRectF, QPointF, QRect, QPoint, QSize + from PySide2.QtGui import QImage, QColor, QPainter, QLinearGradient, QGradient, QPainterPath, QPixmap, \ + QBrush, QPen + from PySide2.QtSvg import QSvgRenderer + from PySide2.QtWidgets import QProgressBar, QGraphicsDropShadowEffect WATER_FRONT = """ @@ -162,9 +170,11 @@ class DWaterProgress(QProgressBar): waterPainter.setCompositionMode(QPainter.CompositionMode_SourceOver) waterPainter.drawImage(int(self.backXOffset), yOffset, self.waterBackImage) - waterPainter.drawImage(int(self.backXOffset) - self.waterBackImage.width(), yOffset, self.waterBackImage) + waterPainter.drawImage(int(self.backXOffset) - self.waterBackImage.width(), yOffset, + self.waterBackImage) waterPainter.drawImage(int(self.frontXOffset), yOffset, self.waterFrontImage) - waterPainter.drawImage(int(self.frontXOffset) - self.waterFrontImage.width(), yOffset, self.waterFrontImage) + waterPainter.drawImage(int(self.frontXOffset) - self.waterFrontImage.width(), yOffset, + self.waterFrontImage) # draw pop if self.value() > 30: diff --git a/QProgressBar/Lib/WaterRippleProgressBar.py b/QProgressBar/Lib/WaterRippleProgressBar.py index 3673a71..605e56d 100644 --- a/QProgressBar/Lib/WaterRippleProgressBar.py +++ b/QProgressBar/Lib/WaterRippleProgressBar.py @@ -1,28 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Created on 2018年4月1日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: WaterRippleProgressBar -# description: - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +""" +Created on 2018年4月1日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: WaterRippleProgressBar +@description: +""" import math -from PyQt5.QtCore import QTimer, Qt, QRectF, QSize -from PyQt5.QtGui import QPainter, QPainterPath, QColor, QFont -from PyQt5.QtWidgets import QProgressBar +try: + from PyQt5.QtCore import QTimer, Qt, QRectF, QSize + from PyQt5.QtGui import QPainter, QPainterPath, QColor, QFont + from PyQt5.QtWidgets import QProgressBar +except ImportError: + from PySide2.QtCore import QTimer, Qt, QRectF, QSize + from PySide2.QtGui import QPainter, QPainterPath, QColor, QFont + from PySide2.QtWidgets import QProgressBar class WaterRippleProgressBar(QProgressBar): - # 浪高百分比 waterHeight = 1 # 密度 @@ -84,7 +84,7 @@ class WaterRippleProgressBar(QProgressBar): # 正弦曲线公式 y = A * sin(ωx + φ) + k # 当前值所占百分比 percent = 1 - (self.value() - self.minimum()) / \ - (self.maximum() - self.minimum()) + (self.maximum() - self.minimum()) # w表示周期,6为人为定义 w = 6 * self.waterDensity * math.pi / self.width() # A振幅 高度百分比,1/26为人为定义 diff --git a/QProgressBar/MetroCircleProgress.py b/QProgressBar/MetroCircleProgress.py index 3b1fe1f..58f4f46 100644 --- a/QProgressBar/MetroCircleProgress.py +++ b/QProgressBar/MetroCircleProgress.py @@ -4,27 +4,25 @@ """ Created on 2018年9月日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: MetroCircleProgress @description: """ -from PyQt5.QtCore import QSequentialAnimationGroup, pyqtProperty,\ - QPauseAnimation, QPropertyAnimation, QParallelAnimationGroup,\ - QObject, QSize, Qt, pyqtSignal, QRectF -from PyQt5.QtGui import QPainter, QColor -from PyQt5.QtWidgets import QWidget, QVBoxLayout - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QSequentialAnimationGroup, QPauseAnimation, QPropertyAnimation, \ + QParallelAnimationGroup, QObject, QSize, Qt, QRectF, pyqtSignal, pyqtProperty + from PyQt5.QtGui import QPainter, QColor + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout +except ImportError: + from PySide2.QtCore import QSequentialAnimationGroup, QPauseAnimation, QPropertyAnimation, \ + QParallelAnimationGroup, QObject, QSize, Qt, QRectF, Signal as pyqtSignal, Property as pyqtProperty + from PySide2.QtGui import QPainter, QColor + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout class CircleItem(QObject): - X = 0 # x坐标 Opacity = 1 # 透明度0~1 valueChanged = pyqtSignal() @@ -52,7 +50,6 @@ def qBound(miv, cv, mxv): class MetroCircleProgress(QWidget): - Radius = 5 # 半径 Color = QColor(24, 189, 155) # 圆圈颜色 BackgroundColor = QColor(Qt.transparent) # 背景颜色 @@ -189,7 +186,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QProgressBar/PercentProgressBar.py b/QProgressBar/PercentProgressBar.py index 80f5d6c..8e46910 100644 --- a/QProgressBar/PercentProgressBar.py +++ b/QProgressBar/PercentProgressBar.py @@ -4,25 +4,23 @@ """ Created on 2018年9月4日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PercentProgressBar @description: """ -from PyQt5.QtCore import pyqtProperty, QSize, Qt, QRectF, QTimer -from PyQt5.QtGui import QColor, QPainter, QFont -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QSlider - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import pyqtProperty, QSize, Qt, QRectF, QTimer + from PyQt5.QtGui import QColor, QPainter, QFont + from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QSlider +except ImportError: + from PySide2.QtCore import Property as pyqtProperty, QSize, Qt, QRectF, QTimer + from PySide2.QtGui import QColor, QPainter, QFont + from PySide2.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QSlider class PercentProgressBar(QWidget): - MinValue = 0 MaxValue = 100 Value = 0 @@ -300,8 +298,10 @@ class Window(QWidget): self.staticPercentProgressBar.showFreeArea = True self.staticPercentProgressBar.ShowSmallCircle = True vlayout.addWidget(self.staticPercentProgressBar) - vlayout.addWidget(QSlider(self, minimum=0, maximum=100, orientation=Qt.Horizontal, - valueChanged=self.staticPercentProgressBar.setValue)) + + self.slider = QSlider(self, minimum=0, maximum=100, orientation=Qt.Horizontal) + self.slider.valueChanged.connect(self.staticPercentProgressBar.setValue) + vlayout.addWidget(self.slider) self._timer.start(100) @@ -316,8 +316,9 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QProgressBar/RoundProgressBar.py b/QProgressBar/RoundProgressBar.py index d406a66..a52cef1 100644 --- a/QProgressBar/RoundProgressBar.py +++ b/QProgressBar/RoundProgressBar.py @@ -4,25 +4,23 @@ """ Created on 2018年9月4日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 界面美化.圆形进度条.CircleProgressBar @description: """ -from PyQt5.QtCore import QSize, pyqtProperty, QTimer, Qt -from PyQt5.QtGui import QColor, QPainter -from PyQt5.QtWidgets import QWidget, QHBoxLayout - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QSize, pyqtProperty, QTimer, Qt + from PyQt5.QtGui import QColor, QPainter + from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout +except ImportError: + from PySide2.QtCore import QSize, Property as pyqtProperty, QTimer, Qt + from PySide2.QtGui import QColor, QPainter + from PySide2.QtWidgets import QApplication, QWidget, QHBoxLayout class CircleProgressBar(QWidget): - Color = QColor(24, 189, 155) # 圆圈颜色 Clockwise = True # 顺时针还是逆时针 Delta = 36 @@ -105,7 +103,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QProgressBar/SimpleStyle.py b/QProgressBar/SimpleStyle.py index 2ad17c8..b8aa5b7 100644 --- a/QProgressBar/SimpleStyle.py +++ b/QProgressBar/SimpleStyle.py @@ -1,26 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月30日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: SimpleStyle @description: -''' -from random import randint +""" + import sys +from random import randint -from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QProgressBar +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QProgressBar +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtWidgets import QWidget, QApplication, QVBoxLayout, QProgressBar - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - -StyleSheet = ''' +StyleSheet = """ /*设置红色进度条*/ #RedProgressBar { text-align: center; /*进度值居中*/ @@ -50,7 +50,7 @@ StyleSheet = ''' width: 10px; /*区块宽度*/ margin: 0.5px; } -''' +""" class ProgressBar(QProgressBar): diff --git a/QProgressBar/WaterProgress.py b/QProgressBar/WaterProgress.py index 1188db6..97bbc20 100644 --- a/QProgressBar/WaterProgress.py +++ b/QProgressBar/WaterProgress.py @@ -4,16 +4,21 @@ """ Created on 2021/1/1 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: WaterProgress @description: """ import sys +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout + from Lib.DWaterProgress import DWaterProgress -from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout class WaterProgressWindow(QWidget): diff --git a/QProgressBar/WaterProgressBar.py b/QProgressBar/WaterProgressBar.py index 5704fe0..30aa6d4 100644 --- a/QProgressBar/WaterProgressBar.py +++ b/QProgressBar/WaterProgressBar.py @@ -1,27 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Created on 2018年4月1日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: WaterProgressBar -# description: - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - +""" +Created on 2018年4月1日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: WaterProgressBar +@description: +""" from random import randint -from PyQt5.Qt import QSpinBox -from PyQt5.QtCore import QTimer -from PyQt5.QtGui import QPixmap, QIcon -from PyQt5.QtWidgets import QWidget, QFormLayout, QRadioButton, QPushButton,\ - QColorDialog +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtGui import QPixmap, QIcon + from PyQt5.QtWidgets import QApplication, QWidget, QFormLayout, QRadioButton, QPushButton, QColorDialog, \ + QSpinBox +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtGui import QPixmap, QIcon + from PySide2.QtWidgets import QApplication, QWidget, QFormLayout, QRadioButton, QPushButton, QColorDialog, \ + QSpinBox from Lib.WaterRippleProgressBar import WaterRippleProgressBar # @UnresolvedImport @@ -53,11 +53,13 @@ class Window(QWidget): layout.addWidget( QPushButton('设置随机0-100固定值', self, clicked=self.setRandomValue)) - layout.addRow('振幅(浪高)', - QSpinBox(self, value=1, valueChanged=self.bar.setWaterHeight)) + spb1 = QSpinBox(self, value=1) + spb1.valueChanged.connect(self.bar.setWaterHeight) + layout.addRow('振幅(浪高)', spb1) - layout.addRow('周期(密度)', - QSpinBox(self, value=1, valueChanged=self.bar.setWaterDensity)) + spb2 = QSpinBox(self, value=1) + spb2.valueChanged.connect(self.bar.setWaterDensity) + layout.addRow('周期(密度)', spb2) layout.addWidget(self.bar) @@ -116,9 +118,10 @@ class Window(QWidget): value = 0 self.bar.setValue(value) + if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QPropertyAnimation/Data/pointtool.pyx b/QPropertyAnimation/Data/pointtool.pyx index bd47b66..3300cc6 100644 --- a/QPropertyAnimation/Data/pointtool.pyx +++ b/QPropertyAnimation/Data/pointtool.pyx @@ -1,10 +1,8 @@ from libc.math cimport pow - def getDistance(p1, p2): return pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) - def findClose(points): cdef int plen = len(points) cdef int i = 0 diff --git a/QPropertyAnimation/Data/setup.py b/QPropertyAnimation/Data/setup.py index 09839f6..3112b44 100644 --- a/QPropertyAnimation/Data/setup.py +++ b/QPropertyAnimation/Data/setup.py @@ -10,8 +10,9 @@ # ) from distutils.core import setup + from Cython.Build import cythonize setup( ext_modules=cythonize("pointtool.pyx"), -) \ No newline at end of file +) diff --git a/QPropertyAnimation/FadeInOut.py b/QPropertyAnimation/FadeInOut.py index edf30ea..024c65c 100644 --- a/QPropertyAnimation/FadeInOut.py +++ b/QPropertyAnimation/FadeInOut.py @@ -1,20 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from PyQt5.QtCore import QPropertyAnimation -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton -# Created on 2018年6月14日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: FadeInOut -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +""" +Created on 2018年6月14日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: FadeInOut +@description: +""" + +try: + from PyQt5.QtCore import QPropertyAnimation + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton +except ImportError: + from PySide2.QtCore import QPropertyAnimation + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class Window(QWidget): @@ -55,7 +57,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QPropertyAnimation/FlipWidgetAnimation.py b/QPropertyAnimation/FlipWidgetAnimation.py index c41947b..1adc264 100644 --- a/QPropertyAnimation/FlipWidgetAnimation.py +++ b/QPropertyAnimation/FlipWidgetAnimation.py @@ -4,23 +4,24 @@ """ Created on 2019年5月15日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 翻转动画 @description: """ -from PyQt5.QtCore import Qt, pyqtSignal, QTimer -from PyQt5.QtGui import QPixmap -from PyQt5.QtWidgets import QStackedWidget, QLabel + +try: + from PyQt5.QtCore import Qt, pyqtSignal, QTimer + from PyQt5.QtGui import QPixmap + from PyQt5.QtWidgets import QApplication, QStackedWidget, QLabel +except ImportError: + from PySide2.QtCore import Qt, Signal as pyqtSignal, QTimer + from PySide2.QtGui import QPixmap + from PySide2.QtWidgets import QApplication, QStackedWidget, QLabel from Lib.FlipWidget import FlipWidget -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - - class LoginWidget(QLabel): # 只是显示登录界面截图 @@ -97,22 +98,22 @@ class Window(QStackedWidget): def jumpLoginWidget(self): # 翻转到登录界面 - self.setWindowOpacity(0) # 类似隐藏,但是保留了任务栏 + self.setWindowOpacity(0) # 类似隐藏,但是保留了任务栏 self.setCurrentWidget(self.loginWidget) # 很重要,一定要先切换过去,不然会导致第一次截图有误 - image1 = self.loginWidget.grab() # 截图1 - image2 = self.settingWidget.grab() # 截图2 - padding = 100 # 扩大边距 @UnusedVariable + image1 = self.loginWidget.grab() # 截图1 + image2 = self.settingWidget.grab() # 截图2 + padding = 100 # 扩大边距 @UnusedVariable self.flipWidget.setGeometry(self.geometry()) # .adjusted(-padding, -padding, padding, padding)) self.flipWidget.updateImages(FlipWidget.Right, image2, image1) def jumpSettingWidget(self): # 翻转到设置界面 - self.setWindowOpacity(0) # 类似隐藏,但是保留了任务栏 + self.setWindowOpacity(0) # 类似隐藏,但是保留了任务栏 self.setCurrentWidget(self.settingWidget) # 很重要,一定要先切换过去,不然会导致第一次截图有误 - image1 = self.loginWidget.grab() # 截图1 - image2 = self.settingWidget.grab() # 截图2 - padding = 100 # 扩大边距 @UnusedVariable + image1 = self.loginWidget.grab() # 截图1 + image2 = self.settingWidget.grab() # 截图2 + padding = 100 # 扩大边距 @UnusedVariable self.flipWidget.setGeometry(self.geometry()) # .adjusted(-padding, -padding, padding, padding)) self.flipWidget.updateImages(FlipWidget.Left, image1, image2) @@ -120,7 +121,7 @@ class Window(QStackedWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QPropertyAnimation/Lib/FlipWidget.py b/QPropertyAnimation/Lib/FlipWidget.py index 25ed75c..6878e63 100644 --- a/QPropertyAnimation/Lib/FlipWidget.py +++ b/QPropertyAnimation/Lib/FlipWidget.py @@ -4,26 +4,27 @@ """ Created on 2019年5月15日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: FlipWidget @description: 动画翻转窗口 """ -from PyQt5.QtCore import pyqtSignal, Qt, QPropertyAnimation, QEasingCurve,\ - pyqtProperty, QPointF -from PyQt5.QtGui import QPainter, QTransform -from PyQt5.QtWidgets import QWidget - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' +try: + from PyQt5.QtCore import pyqtSignal, pyqtProperty, Qt, QPropertyAnimation, QEasingCurve, QPointF + from PyQt5.QtGui import QPainter, QTransform + from PyQt5.QtWidgets import QWidget +except ImportError: + from PySide2.QtCore import Signal as pyqtSignal, Property as pyqtProperty, Qt, QPropertyAnimation, \ + QEasingCurve, QPointF + from PySide2.QtGui import QPainter, QTransform + from PySide2.QtWidgets import QWidget class FlipWidget(QWidget): - - Left = 0 # 从右往左 - Right = 1 # 从左往右 - Scale = 3 # 图片缩放比例 + Left = 0 # 从右往左 + Right = 1 # 从左往右 + Scale = 3 # 图片缩放比例 finished = pyqtSignal() def __init__(self, *args, **kwargs): diff --git a/QPropertyAnimation/Lib/SlidingStackedWidget.py b/QPropertyAnimation/Lib/SlidingStackedWidget.py index 0d35b79..b10bb34 100644 --- a/QPropertyAnimation/Lib/SlidingStackedWidget.py +++ b/QPropertyAnimation/Lib/SlidingStackedWidget.py @@ -4,25 +4,23 @@ """ Created on 2018年11月24日 author: Irony -site: https://pyqt5.com , https://github.com/892768447 +site: https://pyqt.site , https://github.com/PyQt5 email: 892768447@qq.com file: description: 参考 http://qt.shoutwiki.com/wiki/Extending_QStackedWidget_for_sliding_page_animations_in_Qt """ -from PyQt5.QtCore import Qt, pyqtProperty, QEasingCurve, QPoint, \ - QPropertyAnimation, QParallelAnimationGroup, QTimer -from PyQt5.QtWidgets import QStackedWidget - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt, pyqtProperty, QEasingCurve, QPoint, QPropertyAnimation, \ + QParallelAnimationGroup, QTimer + from PyQt5.QtWidgets import QStackedWidget +except ImportError: + from PySide2.QtCore import Qt, Property as pyqtProperty, QEasingCurve, QPoint, QPropertyAnimation, \ + QParallelAnimationGroup, QTimer + from PySide2.QtWidgets import QStackedWidget class SlidingStackedWidget(QStackedWidget): - LEFT2RIGHT, RIGHT2LEFT, TOP2BOTTOM, BOTTOM2TOP, AUTOMATIC = range(5) def __init__(self, *args, **kwargs): @@ -210,7 +208,7 @@ class SlidingStackedWidget(QStackedWidget): def animationDoneSlot(self): """动画结束处理函数""" # 由于重写了setCurrentIndex方法所以这里要用父类本身的方法 -# self.setCurrentIndex(self._next) + # self.setCurrentIndex(self._next) QStackedWidget.setCurrentIndex(self, self._next) w = self.widget(self._now) w.hide() diff --git a/QPropertyAnimation/Lib/UiImageSlider.py b/QPropertyAnimation/Lib/UiImageSlider.py index a47fb81..78be130 100644 --- a/QPropertyAnimation/Lib/UiImageSlider.py +++ b/QPropertyAnimation/Lib/UiImageSlider.py @@ -6,7 +6,11 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +try: + from PyQt5 import QtCore, QtWidgets +except ImportError: + from PySide2 import QtCore, QtWidgets + class Ui_Form(object): def setupUi(self, Form): @@ -89,14 +93,15 @@ class Ui_Form(object): self.pushButtonStart.setText(_translate("Form", "轮播开始")) self.pushButtonStop.setText(_translate("Form", "轮播停止")) + from Lib.SlidingStackedWidget import SlidingStackedWidget if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_()) - diff --git a/QPropertyAnimation/MenuAnimation.py b/QPropertyAnimation/MenuAnimation.py index e8a84c5..4e8c7cd 100644 --- a/QPropertyAnimation/MenuAnimation.py +++ b/QPropertyAnimation/MenuAnimation.py @@ -4,20 +4,18 @@ """ Created on 2018年8月22日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: MenuAnimation @description: """ -from PyQt5.QtCore import QPropertyAnimation, QEasingCurve, QRect -from PyQt5.QtWidgets import QWidget, QMenu, QApplication - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QPropertyAnimation, QEasingCurve, QRect + from PyQt5.QtWidgets import QWidget, QMenu, QApplication +except ImportError: + from PySide2.QtCore import QPropertyAnimation, QEasingCurve, QRect + from PySide2.QtWidgets import QWidget, QMenu, QApplication class Window(QWidget): @@ -61,7 +59,8 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text') + + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/QPropertyAnimation/PageSwitching.py b/QPropertyAnimation/PageSwitching.py index 739f404..9477eb4 100644 --- a/QPropertyAnimation/PageSwitching.py +++ b/QPropertyAnimation/PageSwitching.py @@ -4,27 +4,25 @@ """ Created on 2018年11月24日 author: Irony -site: https://pyqt5.com , https://github.com/892768447 +site: https://pyqt.site , https://github.com/PyQt5 email: 892768447@qq.com file: PageSwitching description: """ import os -from PyQt5.QtCore import QEasingCurve, Qt -from PyQt5.QtGui import QPixmap -from PyQt5.QtWidgets import QWidget, QLabel +try: + from PyQt5.QtCore import QEasingCurve, Qt + from PyQt5.QtGui import QPixmap + from PyQt5.QtWidgets import QWidget, QLabel, QApplication +except ImportError: + from PySide2.QtCore import QEasingCurve, Qt + from PySide2.QtGui import QPixmap + from PySide2.QtWidgets import QWidget, QLabel, QApplication from Lib.UiImageSlider import Ui_Form # @UnresolvedImport -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class ImageSliderWidget(QWidget, Ui_Form): def __init__(self, *args, **kwargs): @@ -76,7 +74,7 @@ class ImageSliderWidget(QWidget, Ui_Form): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = ImageSliderWidget() w.show() diff --git a/QPropertyAnimation/RlatticeEffect.py b/QPropertyAnimation/RlatticeEffect.py index e91e215..a57c37b 100644 --- a/QPropertyAnimation/RlatticeEffect.py +++ b/QPropertyAnimation/RlatticeEffect.py @@ -4,7 +4,7 @@ """ Created on 2018年11月22日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: RlatticeEffect @description: @@ -12,29 +12,29 @@ Created on 2018年11月22日 from random import random from time import time -from PyQt5.QtCore import QPropertyAnimation, QObject, pyqtProperty, QEasingCurve,\ - Qt, QRectF, pyqtSignal -from PyQt5.QtGui import QColor, QPainterPath, QPainter -from PyQt5.QtWidgets import QWidget - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - +try: + from PyQt5.QtCore import QPropertyAnimation, QObject, QEasingCurve, Qt, QRectF, pyqtSignal, pyqtProperty + from PyQt5.QtGui import QColor, QPainterPath, QPainter + from PyQt5.QtWidgets import QApplication, QWidget +except ImportError: + from PySide2.QtCore import QPropertyAnimation, QObject, QEasingCurve, Qt, QRectF, Signal as pyqtSignal, \ + Property as pyqtProperty + from PySide2.QtGui import QColor, QPainterPath, QPainter + from PySide2.QtWidgets import QApplication, QWidget try: from Lib import pointtool # @UnusedImport @UnresolvedImport + getDistance = pointtool.getDistance findClose = pointtool.findClose except: import math + def getDistance(p1, p2): return math.pow(p1.x - p2.x, 2) + math.pow(p1.y - p2.y, 2) + def findClose(points): plen = len(points) for i in range(plen): @@ -66,8 +66,7 @@ class Target: class Point(QObject): - - valueChanged = pyqtSignal() + valueChanged = pyqtSignal(int) def __init__(self, x, ox, y, oy, *args, **kwargs): super(Point, self).__init__(*args, **kwargs) @@ -90,12 +89,12 @@ class Point(QObject): # 属性动画 if not hasattr(self, 'xanimation'): self.xanimation = QPropertyAnimation( - self, b'x', self, valueChanged=self.valueChanged.emit, - easingCurve=QEasingCurve.InOutSine) + self, b'x', self, easingCurve=QEasingCurve.InOutSine) + self.xanimation.valueChanged.connect(self.valueChanged.emit) self.yanimation = QPropertyAnimation( - self, b'y', self, valueChanged=self.valueChanged.emit, - easingCurve=QEasingCurve.InOutSine, - finished=self.updateAnimation) + self, b'y', self, easingCurve=QEasingCurve.InOutSine) + self.yanimation.valueChanged.connect(self.valueChanged.emit) + self.yanimation.finished.connect(self.updateAnimation) self.updateAnimation() def updateAnimation(self): @@ -138,6 +137,9 @@ class Window(QWidget): self.target = Target(self.width() / 2, self.height() / 2) self.initPoints() + def update(self, *args): + super(Window, self).update() + def paintEvent(self, event): super(Window, self).paintEvent(event) painter = QPainter() @@ -220,8 +222,9 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QPropertyAnimation/ShakeWindow.py b/QPropertyAnimation/ShakeWindow.py index b161ce3..6c7d9c9 100644 --- a/QPropertyAnimation/ShakeWindow.py +++ b/QPropertyAnimation/ShakeWindow.py @@ -4,18 +4,18 @@ """ Created on 2019年5月8日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ShakeWindow @description: 抖动动画 """ -from PyQt5.QtCore import QPropertyAnimation, QPoint -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QPropertyAnimation, QPoint + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton +except ImportError: + from PySide2.QtCore import QPropertyAnimation, QPoint + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class Window(QWidget): @@ -66,7 +66,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QProxyStyle/Lib/TabBarStyle.py b/QProxyStyle/Lib/TabBarStyle.py index 12d7c8a..59406cc 100644 --- a/QProxyStyle/Lib/TabBarStyle.py +++ b/QProxyStyle/Lib/TabBarStyle.py @@ -4,7 +4,7 @@ """ Created on 2018年12月27日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TabBarStyle @description: @@ -13,13 +13,6 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QProxyStyle -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - - class TabBarStyle(QProxyStyle): def sizeFromContents(self, types, option, size, widget): diff --git a/QProxyStyle/Lib/TabCornerStyle.py b/QProxyStyle/Lib/TabCornerStyle.py index f6df52b..fe79354 100644 --- a/QProxyStyle/Lib/TabCornerStyle.py +++ b/QProxyStyle/Lib/TabCornerStyle.py @@ -9,8 +9,13 @@ Created on 2021年06月23日 @file: TabCornerStyle @description: """ -from PyQt5.QtCore import QRect -from PyQt5.QtWidgets import QProxyStyle, QStyle + +try: + from PyQt5.QtCore import QRect + from PyQt5.QtWidgets import QProxyStyle, QStyle +except ImportError: + from PySide2.QtCore import QRect + from PySide2.QtWidgets import QProxyStyle, QStyle class TabCornerStyle(QProxyStyle): diff --git a/QProxyStyle/TabCornerWidget.py b/QProxyStyle/TabCornerWidget.py index d130788..39d7146 100644 --- a/QProxyStyle/TabCornerWidget.py +++ b/QProxyStyle/TabCornerWidget.py @@ -9,9 +9,15 @@ Created on 2021年06月23日 @file: TabCornerWidget @description: """ -from PyQt5.QtCore import pyqtSignal, Qt -from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QSpacerItem, QSizePolicy, \ - QTabWidget + +try: + from PyQt5.QtCore import pyqtSignal, Qt + from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QSpacerItem, QSizePolicy, \ + QTabWidget +except ImportError: + from PySide2.QtCore import Signal as pyqtSignal, Qt + from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QSpacerItem, QSizePolicy, \ + QTabWidget from QProxyStyle.Lib.TabCornerStyle import TabCornerStyle diff --git a/QProxyStyle/TabTextDirection.py b/QProxyStyle/TabTextDirection.py index 22dc4d8..52ba568 100644 --- a/QProxyStyle/TabTextDirection.py +++ b/QProxyStyle/TabTextDirection.py @@ -4,7 +4,7 @@ """ Created on 2018年12月27日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TestTabWidget @description: @@ -14,13 +14,6 @@ from PyQt5.QtWidgets import QTabWidget, QLabel, QWidget, QGridLayout from Lib.TabBarStyle import TabBarStyle -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - - class TabWidget(QTabWidget): def __init__(self, *args, **kwargs): @@ -44,6 +37,7 @@ class Window(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyle(TabBarStyle()) w = Window() diff --git a/QPushButton/BottomLineProgress.py b/QPushButton/BottomLineProgress.py index 7a19e59..00352f5 100644 --- a/QPushButton/BottomLineProgress.py +++ b/QPushButton/BottomLineProgress.py @@ -1,25 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年2月1日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PushButtonLine @description: -''' -from random import randint +""" + import sys +from random import randint -from PyQt5.QtCore import QTimer, QThread, pyqtSignal -from PyQt5.QtGui import QPainter, QColor, QPen -from PyQt5.QtWidgets import QPushButton, QApplication, QWidget, QVBoxLayout - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QTimer, QThread, pyqtSignal + from PyQt5.QtGui import QPainter, QColor, QPen + from PyQt5.QtWidgets import QPushButton, QApplication, QWidget, QVBoxLayout +except ImportError: + from PySide2.QtCore import QTimer, QThread, Signal as pyqtSignal + from PySide2.QtGui import QPainter, QColor, QPen + from PySide2.QtWidgets import QPushButton, QApplication, QWidget, QVBoxLayout StyleSheet = ''' PushButtonLine { @@ -32,7 +33,6 @@ PushButtonLine { class LoadingThread(QThread): - valueChanged = pyqtSignal(float) # 当前值/最大值 def __init__(self, *args, **kwargs): @@ -41,12 +41,13 @@ class LoadingThread(QThread): def run(self): for i in range(self.totalValue + 1): + if self.isInterruptionRequested(): + break self.valueChanged.emit(i / self.totalValue) QThread.msleep(randint(50, 100)) class PushButtonLine(QPushButton): - lineColor = QColor(0, 150, 136) def __init__(self, *args, **kwargs): @@ -57,6 +58,9 @@ class PushButtonLine(QPushButton): self._timer = QTimer(self, timeout=self.update) self.clicked.connect(self.start) + def __del__(self): + self.stop() + def paintEvent(self, event): super(PushButtonLine, self).paintEvent(event) if not self._timer.isActive(): @@ -79,14 +83,21 @@ class PushButtonLine(QPushButton): self.setText(self._waitText) def stop(self): - self.loadingThread.valueChanged.disconnect(self.setPercent) - self.loadingThread.terminate() - self.loadingThread.deleteLater() - QThread.msleep(100) # 延迟等待deleteLater执行完毕 - del self.loadingThread - self._percent = 0 - self._timer.stop() - self.setText(self._text) + try: + if hasattr(self, "loadingThread"): + if self.loadingThread.isRunning(): + self.loadingThread.requestInterruption() + self.loadingThread.quit() + self.loadingThread.wait(2000) + del self.loadingThread + except RuntimeError: + pass + try: + self._percent = 0 + self._timer.stop() + self.setText(self._text) + except RuntimeError: + pass def setPercent(self, v): self._percent = v diff --git a/QPushButton/FontRotate.py b/QPushButton/FontRotate.py index c9cae27..e8a728a 100644 --- a/QPushButton/FontRotate.py +++ b/QPushButton/FontRotate.py @@ -1,31 +1,30 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年2月1日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PushButtonFont @description: -''' - +""" import sys -from PyQt5.QtCore import QPropertyAnimation, Qt, QRectF -from PyQt5.QtGui import QFontDatabase -from PyQt5.QtWidgets import QPushButton, QApplication, QStyleOptionButton,\ - QStylePainter, QStyle - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QPropertyAnimation, Qt, QRectF + from PyQt5.QtGui import QFontDatabase + from PyQt5.QtWidgets import QPushButton, QApplication, QStyleOptionButton, \ + QStylePainter, QStyle +except ImportError: + from PySide2.QtCore import QPropertyAnimation, Qt, QRectF + from PySide2.QtGui import QFontDatabase + from PySide2.QtWidgets import QPushButton, QApplication, QStyleOptionButton, \ + QStylePainter, QStyle class PushButtonFont(QPushButton): - LoadingText = "\uf110" def __init__(self, *args, **kwargs): diff --git a/QPushButton/NormalStyle.py b/QPushButton/NormalStyle.py index 831064b..ec36a89 100644 --- a/QPushButton/NormalStyle.py +++ b/QPushButton/NormalStyle.py @@ -1,23 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月29日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: NormalStyle @description: -''' +""" + import sys -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QPushButton, QApplication +try: + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QPushButton, QApplication +except ImportError: + from PySide2.QtWidgets import QWidget, QHBoxLayout, QPushButton, QApplication -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - -StyleSheet = ''' +StyleSheet = """ /*这里是通用设置,所有按钮都有效,不过后面的可以覆盖这个*/ QPushButton { border: none; /*去掉边框*/ @@ -85,7 +85,7 @@ QPushButton[text="purple button"] { color: white; /*文字颜色*/ background-color: #9c27b0; } -''' +""" class Window(QWidget): diff --git a/QPushButton/SignalsExample.py b/QPushButton/SignalsExample.py index 0b3cf66..35163e8 100644 --- a/QPushButton/SignalsExample.py +++ b/QPushButton/SignalsExample.py @@ -4,17 +4,16 @@ """ Created on 2019年7月2日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QPushButton.SignalsExample @description: 按钮信号例子 """ -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QPlainTextEdit - -__Author__ = "Irony" -__Copyright__ = "Copyright (c) 2019" -__Version__ = "Version 1.0" +try: + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QPlainTextEdit +except ImportError: + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QPlainTextEdit class Window(QWidget): @@ -26,14 +25,23 @@ class Window(QWidget): btn1 = QPushButton('按钮点击信号', self) btn1.setObjectName('ClickBtn') btn1.clicked.connect(self.onClicked) - layout.addWidget(btn1) - layout.addWidget(QPushButton( - '按钮按下信号', self, objectName='PressBtn', pressed=self.onPressed)) - layout.addWidget(QPushButton( - '按钮释放信号', self, objectName='ReleaseBtn', released=self.onReleased)) - layout.addWidget(QPushButton( - '按钮选中信号', self, checkable=True, objectName='ToggleBtn', toggled=self.onToggled)) + + btn2 = QPushButton('按钮按下信号', self) + btn2.setObjectName('PressBtn') + btn2.pressed.connect(self.onPressed) + layout.addWidget(btn2) + + btn3 = QPushButton('按钮释放信号', self) + btn3.setObjectName('ReleaseBtn') + btn3.released.connect(self.onReleased) + layout.addWidget(btn3) + + btn4 = QPushButton('按钮释放信号', self) + btn4.setObjectName('ToggleBtn') + btn4.setCheckable(True) + btn4.toggled.connect(self.onToggled) + layout.addWidget(btn4) self.resultView = QPlainTextEdit(self) self.resultView.setReadOnly(True) @@ -58,7 +66,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QScrollArea/Lib/SettingUi.py b/QScrollArea/Lib/SettingUi.py index a9bfdff..d25f3ef 100644 --- a/QScrollArea/Lib/SettingUi.py +++ b/QScrollArea/Lib/SettingUi.py @@ -6,7 +6,11 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +try: + from PyQt5 import QtCore, QtWidgets +except ImportError: + from PySide2 import QtCore, QtWidgets + class Ui_Setting(object): def setupUi(self, Setting): @@ -151,7 +155,8 @@ class Ui_Setting(object): self.comboBox.addItem("") self.comboBox.addItem("") self.horizontalLayout_2.addWidget(self.comboBox) - spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_2.addItem(spacerItem) self.formLayout_9.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_2) self.checkBox_30 = QtWidgets.QCheckBox(self.widget_2) @@ -171,7 +176,8 @@ class Ui_Setting(object): self.pushButton_4 = QtWidgets.QPushButton(self.widget_2) self.pushButton_4.setObjectName("pushButton_4") self.horizontalLayout_3.addWidget(self.pushButton_4) - spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem1) self.formLayout_9.setLayout(4, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_3) self.verticalLayout.addWidget(self.widget_2) @@ -469,7 +475,8 @@ class Ui_Setting(object): self.checkBox_23.setText(_translate("Setting", "启用一声问候消息")) self.checkBox_24.setText(_translate("Setting", "启用设备连接提醒")) self.right5.setText(_translate("Setting", "当插入安卓设备时,提示安装或者更新QQ手机版")) - self.label_3.setText(_translate("Setting", "

您可以设置是否在屏幕右下角收到来自QQ空间的通知,进入设置

")) + self.label_3.setText(_translate("Setting", + "

您可以设置是否在屏幕右下角收到来自QQ空间的通知,进入设置

")) self.label_4.setText(_translate("Setting", "好友上线提醒")) self.radioButton.setText(_translate("Setting", "关闭好友上线提醒")) self.radioButton_2.setText(_translate("Setting", "全部好友上线提醒")) @@ -485,10 +492,10 @@ class Ui_Setting(object): if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) Setting = QtWidgets.QWidget() ui = Ui_Setting() ui.setupUi(Setting) Setting.show() sys.exit(app.exec_()) - diff --git a/QScrollArea/QQSettingPanel.py b/QScrollArea/QQSettingPanel.py index 6dccd7c..2a5236a 100644 --- a/QScrollArea/QQSettingPanel.py +++ b/QScrollArea/QQSettingPanel.py @@ -1,24 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from PyQt5.QtWidgets import QWidget + +""" +Created on 2018年3月28日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: QQSettingPanel +@description: +""" + +try: + from PyQt5.QtWidgets import QApplication, QWidget +except ImportError: + from PySide2.QtWidgets import QApplication, QWidget from Lib.SettingUi import Ui_Setting # @UnresolvedImport -# Created on 2018年3月28日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: QQSettingPanel -# description: - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class Window(QWidget, Ui_Setting): def __init__(self, *args, **kwargs): @@ -59,9 +58,9 @@ class Window(QWidget, Ui_Setting): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) - app.setStyleSheet(open("Data/style.qss", "rb").read().decode("utf-8")) + app.setStyleSheet(open('Data/style.qss', 'rb').read().decode('utf-8')) w = Window() w.show() sys.exit(app.exec_()) diff --git a/QScrollBar/StyleScrollBar.py b/QScrollBar/StyleScrollBar.py index 96c591d..f5d4d34 100644 --- a/QScrollBar/StyleScrollBar.py +++ b/QScrollBar/StyleScrollBar.py @@ -1,22 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月20日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScrollBar @description: -''' -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QTextEdit, QApplication +""" import chardet - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QTextEdit, QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QTextEdit, QApplication class Window(QTextEdit): @@ -38,6 +38,7 @@ class Window(QTextEdit): if __name__ == "__main__": import sys + app = QApplication(sys.argv) app.setApplicationName("滚动条样式") app.setApplicationDisplayName("滚动条样式") diff --git a/QSerialPort/Lib/UiSerialPort.py b/QSerialPort/Lib/UiSerialPort.py index 0da8c35..934e215 100644 --- a/QSerialPort/Lib/UiSerialPort.py +++ b/QSerialPort/Lib/UiSerialPort.py @@ -6,19 +6,20 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtWidgets + class Ui_FormSerialPort(object): def setupUi(self, FormSerialPort): FormSerialPort.setObjectName("FormSerialPort") FormSerialPort.resize(721, 597) FormSerialPort.setStyleSheet("#labelStatus {\n" -" border-radius: 13px;\n" -" background-color: gray;\n" -"}\n" -"#labelStatus[isOn=\"true\"] {\n" -" background-color: green;\n" -"}") + " border-radius: 13px;\n" + " background-color: gray;\n" + "}\n" + "#labelStatus[isOn=\"true\"] {\n" + " background-color: green;\n" + "}") self.gridLayout = QtWidgets.QGridLayout(FormSerialPort) self.gridLayout.setObjectName("gridLayout") self.groupBox = QtWidgets.QGroupBox(FormSerialPort) @@ -86,7 +87,8 @@ class Ui_FormSerialPort(object): self.labelStatus.setProperty("isOn", False) self.labelStatus.setObjectName("labelStatus") self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.labelStatus) - spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, + QtWidgets.QSizePolicy.Expanding) self.formLayout.setItem(6, QtWidgets.QFormLayout.FieldRole, spacerItem) self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1) self.textBrowser = QtWidgets.QTextBrowser(FormSerialPort) @@ -166,10 +168,10 @@ class Ui_FormSerialPort(object): if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) FormSerialPort = QtWidgets.QWidget() ui = Ui_FormSerialPort() ui.setupUi(FormSerialPort) FormSerialPort.show() sys.exit(app.exec_()) - diff --git a/QSerialPort/SerialDebugAssistant.py b/QSerialPort/SerialDebugAssistant.py index a3869a2..5f5c8e4 100644 --- a/QSerialPort/SerialDebugAssistant.py +++ b/QSerialPort/SerialDebugAssistant.py @@ -4,7 +4,7 @@ """ Created on 2018年11月6日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: SerialDebugAssistant @description: 串口调试小助手 @@ -16,13 +16,6 @@ from PyQt5.QtWidgets import QWidget, QMessageBox from Lib.UiSerialPort import Ui_FormSerialPort # @UnresolvedImport -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class Window(QWidget, Ui_FormSerialPort): def __init__(self, *args, **kwargs): @@ -51,7 +44,7 @@ class Window(QWidget, Ui_FormSerialPort): QMessageBox.critical(self, '错误', '没有选择串口') return port = self._ports[name] -# self._serial.setPort(port) + # self._serial.setPort(port) # 根据名字设置串口(也可以用上面的函数) self._serial.setPortName(port.systemLocation()) # 设置波特率 @@ -139,8 +132,10 @@ class Window(QWidget, Ui_FormSerialPort): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + + cgitb.enable(format='text') from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QSlider/ClickJumpSlider.py b/QSlider/ClickJumpSlider.py index ecab9ef..d12f97a 100644 --- a/QSlider/ClickJumpSlider.py +++ b/QSlider/ClickJumpSlider.py @@ -4,21 +4,20 @@ """ Created on 2018年11月5日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ClickJumpSlider @description: """ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QSlider, QStyleOptionSlider, QStyle, QWidget,\ - QFormLayout, QLabel - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QApplication, QSlider, QStyleOptionSlider, QStyle, QWidget, QFormLayout, \ + QLabel +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QApplication, QSlider, QStyleOptionSlider, QStyle, QWidget, QFormLayout, \ + QLabel class ClickJumpSlider(QSlider): @@ -55,31 +54,34 @@ class DemoWindow(QWidget): layout = QFormLayout(self) self.label1 = QLabel('0', self) - layout.addRow(self.label1, ClickJumpSlider( - Qt.Horizontal, valueChanged=lambda v: self.label1.setText(str(v)))) + self.slider1 = ClickJumpSlider(Qt.Horizontal) + self.slider1.valueChanged.connect(lambda v: self.label1.setText(str(v))) + layout.addRow(self.label1, self.slider1) # 横向-反向显示 self.label2 = QLabel('0', self) - layout.addRow(self.label2, ClickJumpSlider( - Qt.Horizontal, invertedAppearance=True, - valueChanged=lambda v: self.label2.setText(str(v)))) + self.slider2 = ClickJumpSlider(Qt.Horizontal, invertedAppearance=True) + self.slider2.valueChanged.connect(lambda v: self.label2.setText(str(v))) + layout.addRow(self.label2, self.slider2) self.label3 = QLabel('0', self) - layout.addRow(self.label3, ClickJumpSlider( - Qt.Vertical, minimumHeight=200, valueChanged=lambda v: self.label3.setText(str(v)))) + self.slider3 = ClickJumpSlider(Qt.Vertical, minimumHeight=200) + self.slider3.valueChanged.connect(lambda v: self.label3.setText(str(v))) + layout.addRow(self.label3, self.slider3) # 纵向反向显示 self.label4 = QLabel('0', self) - layout.addRow(self.label4, ClickJumpSlider( - Qt.Vertical, invertedAppearance=True, - minimumHeight=200, valueChanged=lambda v: self.label4.setText(str(v)))) + self.slider4 = ClickJumpSlider(Qt.Vertical, invertedAppearance=True, minimumHeight=200) + self.slider4.valueChanged.connect(lambda v: self.label4.setText(str(v))) + layout.addRow(self.label4, self.slider4) if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = DemoWindow() w.show() diff --git a/QSlider/LfSlider.py b/QSlider/LfSlider.py index 5a6116a..2c900cf 100644 --- a/QSlider/LfSlider.py +++ b/QSlider/LfSlider.py @@ -4,15 +4,21 @@ """ Created on 2021/4/9 @author: Irony -@site: https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: LfSlider @description: 降低值变化频率 """ from datetime import datetime -from PyQt5.QtCore import pyqtSignal, QTimer, Qt -from PyQt5.QtWidgets import QSlider, QWidget, QVBoxLayout, QPlainTextEdit, QHBoxLayout, QGroupBox +try: + from PyQt5.QtCore import pyqtSignal, QTimer, Qt + from PyQt5.QtWidgets import QApplication, QSlider, QWidget, QVBoxLayout, QPlainTextEdit, QHBoxLayout, \ + QGroupBox +except ImportError: + from PySide2.QtCore import Signal as pyqtSignal, QTimer, Qt + from PySide2.QtWidgets import QApplication, QSlider, QWidget, QVBoxLayout, QPlainTextEdit, QHBoxLayout, \ + QGroupBox class LfSlider(QSlider): @@ -32,10 +38,10 @@ class LfSlider(QSlider): self.valueChanged.emit(self.lastValue) -class TestWindow(QWidget): +class Window(QWidget): def __init__(self, *args, **kwargs): - super(TestWindow, self).__init__(*args, **kwargs) + super(Window, self).__init__(*args, **kwargs) layout = QHBoxLayout(self) # 左侧原始 @@ -74,9 +80,8 @@ if __name__ == '__main__': import cgitb cgitb.enable(format='text') - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) - w = TestWindow() + w = Window() w.show() sys.exit(app.exec_()) diff --git a/QSlider/PaintQSlider.py b/QSlider/PaintQSlider.py index 0d154e8..d72a757 100644 --- a/QSlider/PaintQSlider.py +++ b/QSlider/PaintQSlider.py @@ -4,24 +4,18 @@ """ Created on 2018年5月15日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PaintQSlider @description: """ + from PyQt5.QtCore import Qt, QRect, QPointF from PyQt5.QtGui import QPainter, QColor -from PyQt5.QtWidgets import QSlider, QWidget, QVBoxLayout, QProxyStyle, QStyle,\ +from PyQt5.QtWidgets import QSlider, QWidget, QVBoxLayout, QProxyStyle, QStyle, \ QStyleOptionSlider -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - - class SliderStyle(QProxyStyle): def subControlRect(self, control, option, subControl, widget=None): @@ -124,6 +118,7 @@ class Window(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.setStyleSheet('QWidget {background: gray;}') diff --git a/QSlider/QssQSlider.py b/QSlider/QssQSlider.py index af65e49..7b3a0f3 100644 --- a/QSlider/QssQSlider.py +++ b/QSlider/QssQSlider.py @@ -4,20 +4,18 @@ """ Created on 2018年5月15日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QssQSlider @description: 通过QSS美化QSlider """ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSlider - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSlider +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QSlider StyleSheet = """ QWidget { @@ -76,7 +74,7 @@ class Window(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet(StyleSheet) w = Window() diff --git a/QSplashScreen/GifSplashScreen.py b/QSplashScreen/GifSplashScreen.py index bf16d7b..d409dd0 100644 --- a/QSplashScreen/GifSplashScreen.py +++ b/QSplashScreen/GifSplashScreen.py @@ -4,21 +4,22 @@ """ Created on 2020/6/11 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: @description: """ -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' - from time import sleep -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QMovie -from PyQt5.QtWidgets import QApplication, QSplashScreen, QWidget +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QMovie + from PyQt5.QtWidgets import QApplication, QSplashScreen, QWidget +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QMovie + from PySide2.QtWidgets import QApplication, QSplashScreen, QWidget class GifSplashScreen(QSplashScreen): @@ -55,7 +56,7 @@ if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) diff --git a/QSplitter/RewriteHandle.py b/QSplitter/RewriteHandle.py index 241f6c2..d69ab63 100644 --- a/QSplitter/RewriteHandle.py +++ b/QSplitter/RewriteHandle.py @@ -4,25 +4,23 @@ """ Created on 2018年3月21日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: Splitter @description: """ import sys -from PyQt5.QtCore import Qt, QPointF, pyqtSignal -from PyQt5.QtGui import QPainter, QPolygonF -from PyQt5.QtWidgets import QTextEdit, QListWidget,\ - QTreeWidget, QSplitter, QApplication, QMainWindow, QSplitterHandle - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0"\ - +try: + from PyQt5.QtCore import Qt, QPointF, pyqtSignal + from PyQt5.QtGui import QPainter, QPolygonF + from PyQt5.QtWidgets import QTextEdit, QListWidget, \ + QTreeWidget, QSplitter, QApplication, QMainWindow, QSplitterHandle +except ImportError: + from PySide2.QtCore import Qt, QPointF, Signal as pyqtSignal + from PySide2.QtGui import QPainter, QPolygonF + from PySide2.QtWidgets import QTextEdit, QListWidget, \ + QTreeWidget, QSplitter, QApplication, QMainWindow, QSplitterHandle class SplitterHandle(QSplitterHandle): @@ -49,7 +47,7 @@ class SplitterHandle(QSplitterHandle): else: # 设置默认的鼠标样式并可以移动 self.setCursor(Qt.SplitHCursor if self.orientation() - == Qt.Horizontal else Qt.SplitVCursor) + == Qt.Horizontal else Qt.SplitVCursor) super(SplitterHandle, self).mouseMoveEvent(event) def paintEvent(self, event): diff --git a/QStackedWidget/LeftTabStacked.py b/QStackedWidget/LeftTabStacked.py index cc5d761..6c8257d 100644 --- a/QStackedWidget/LeftTabStacked.py +++ b/QStackedWidget/LeftTabStacked.py @@ -1,24 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + +""" +Created on 2018年5月29日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: LeftTabWidget +@description: +""" + from random import randint -from PyQt5.QtCore import Qt, QSize -from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QWidget, QListWidget, QStackedWidget, QHBoxLayout,\ - QListWidgetItem, QLabel - - -# Created on 2018年5月29日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: LeftTabWidget -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt, QSize + from PyQt5.QtGui import QIcon + from PyQt5.QtWidgets import QApplication, QWidget, QListWidget, QStackedWidget, QHBoxLayout, \ + QListWidgetItem, QLabel +except ImportError: + from PySide2.QtCore import Qt, QSize + from PySide2.QtGui import QIcon + from PySide2.QtWidgets import QApplication, QWidget, QListWidget, QStackedWidget, QHBoxLayout, \ + QListWidgetItem, QLabel class LeftTabWidget(QWidget): @@ -26,7 +29,7 @@ class LeftTabWidget(QWidget): def __init__(self, *args, **kwargs): super(LeftTabWidget, self).__init__(*args, **kwargs) self.resize(800, 600) - #左右布局(左边一个QListWidget + 右边QStackedWidget) + # 左右布局(左边一个QListWidget + 右边QStackedWidget) layout = QHBoxLayout(self, spacing=0) layout.setContentsMargins(0, 0, 0, 0) # 左侧列表 @@ -102,7 +105,7 @@ QLabel { if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet(Stylesheet) w = LeftTabWidget() diff --git a/QSystemTrayIcon/MinimizeToTray.py b/QSystemTrayIcon/MinimizeToTray.py index 2438215..f432583 100755 --- a/QSystemTrayIcon/MinimizeToTray.py +++ b/QSystemTrayIcon/MinimizeToTray.py @@ -1,11 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import sys -from PyQt5.QtWidgets import ( - QApplication, QMainWindow, - QLabel, QGridLayout, QWidget, - QCheckBox, QSystemTrayIcon, - QSpacerItem, QSizePolicy, QMenu, QAction, QStyle, qApp) -from PyQt5.QtCore import QSize +try: + from PyQt5.QtCore import QSize + from PyQt5.QtWidgets import ( + QApplication, QMainWindow, + QLabel, QGridLayout, QWidget, + QCheckBox, QSystemTrayIcon, + QSpacerItem, QSizePolicy, QMenu, QAction, QStyle) +except ImportError: + from PySide2.QtCore import QSize + from PySide2.QtWidgets import ( + QApplication, QMainWindow, + QLabel, QGridLayout, QWidget, + QCheckBox, QSystemTrayIcon, + QSpacerItem, QSizePolicy, QMenu, QAction, QStyle) class MainWindow(QMainWindow): @@ -21,14 +32,14 @@ class MainWindow(QMainWindow): # Be sure to call the super class method QMainWindow.__init__(self) - self.setMinimumSize(QSize(480, 80)) # Set sizes + self.setMinimumSize(QSize(480, 80)) # Set sizes self.setWindowTitle("System Tray Application") # Set a title # Create a central widget central_widget = QWidget(self) # Set the central widget self.setCentralWidget(central_widget) - grid_layout = QGridLayout(self) # Create a QGridLayout + grid_layout = QGridLayout(self) # Create a QGridLayout # Set the layout into the central widget central_widget.setLayout(grid_layout) grid_layout.addWidget( @@ -56,7 +67,7 @@ class MainWindow(QMainWindow): hide_action = QAction("Hide", self) show_action.triggered.connect(self.show) hide_action.triggered.connect(self.hide) - quit_action.triggered.connect(qApp.quit) + quit_action.triggered.connect(QApplication.instance().quit) tray_menu = QMenu() tray_menu.addAction(show_action) tray_menu.addAction(hide_action) @@ -82,4 +93,4 @@ if __name__ == "__main__": app = QApplication(sys.argv) mw = MainWindow() mw.show() - sys.exit(app.exec()) + sys.exit(app.exec_()) diff --git a/QTableView/CopyContent.py b/QTableView/CopyContent.py index b5c8294..abeabe4 100644 --- a/QTableView/CopyContent.py +++ b/QTableView/CopyContent.py @@ -1,22 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年4月6日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CopyContent @description: -''' -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QStandardItemModel, QStandardItem -from PyQt5.QtWidgets import QTableView, QApplication, QAction, QMessageBox +""" - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QStandardItemModel, QStandardItem + from PyQt5.QtWidgets import QTableView, QApplication, QAction, QMessageBox +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QStandardItemModel, QStandardItem + from PySide2.QtWidgets import QTableView, QApplication, QAction, QMessageBox class TableView(QTableView): @@ -98,8 +99,10 @@ class TableView(QTableView): self.myModel.setItem( row, col, QStandardItem("row: {row},col: {col}".format(row=row + 1, col=col + 1))) + if __name__ == "__main__": import sys + app = QApplication(sys.argv) app.setApplicationName("TableView") w = TableView() diff --git a/QTableWidget/Lib/TableWidget.py b/QTableWidget/Lib/TableWidget.py deleted file mode 100644 index 75e61f4..0000000 --- a/QTableWidget/Lib/TableWidget.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 -''' -@author: wxj -@license: (C) Hefei tongzhi electromechanical control technology co.LTD -@contact: -@software: garner -@file: table.py -@time: 2019/4/11 21:26 -@desc: -''' -from PyQt5 import QtWidgets -from PyQt5.QtWidgets import * -from PyQt5.QtGui import * -from PyQt5.QtCore import * -import sys - -class MyTable(QTableWidget): - def __init__(self,parent=None): - super(MyTable, self).__init__(parent) - self.setWindowTitle("我是一个表格") - self.setWindowIcon(QIcon("male.png")) - self.resize(920, 240) - self.setColumnCount(6) - self.setRowCount(2) - #设置表格有两行五列。 - self.setColumnWidth(0, 200) - self.setColumnWidth(4, 200) - self.setRowHeight(0, 100) - #设置第一行高度为100px,第一列宽度为200px。 - - self.table() - - def table(self): - self.setItem(0,0,QTableWidgetItem(" 你的名字")) - self.setItem(0,1,QTableWidgetItem("性别")) - self.setItem(0,2,QTableWidgetItem("出生日期")) - self.setItem(0,3, QTableWidgetItem("职业")) - self.setItem(0,4, QTableWidgetItem("收入")) - self.setItem(0, 5, QTableWidgetItem("进度条")) - #添加表格的文字内容. - self.setHorizontalHeaderLabels(["第一行", "第二行", "第三行", "第四行", "第五行","第六行"]) - self.setVerticalHeaderLabels(["第一列", "第二列"]) - #设置表头 - lbp = QLabel() - lbp.setPixmap(QPixmap("Male.png")) - self.setCellWidget(1,1,lbp) - #在表中添加一张图片 - twi = QTableWidgetItem(" 新海诚") - twi.setFont(QFont("Times", 10, )) - self.setItem(1,0,twi) - - #添加一个自己设置了大小和类型的文字。 - dte = QDateTimeEdit() - dte.setDateTime(QDateTime.currentDateTime()) - dte.setDisplayFormat("yyyy/MM/dd") - dte.setCalendarPopup(True) - self.setCellWidget(1,2,dte) - #添加一个弹出的日期选择,设置默认值为当前日期,显示格式为年月日。 - cbw = QComboBox() - cbw.addItem("医生") - cbw.addItem("老师") - cbw.addItem("律师") - self.setCellWidget(1,3,cbw) - #添加了一个下拉选择框 - sb = QSpinBox() - sb.setRange(1000,10000) - sb.setValue(5000)#设置最开始显示的数字 - sb.setDisplayIntegerBase(10)#这个是显示数字的进制,默认是十进制。 - sb.setSuffix("元")#设置后辍 - sb.setPrefix("RMB: ")#设置前辍 - sb.setSingleStep(100) - self.setCellWidget(1,4,sb) - # 添加一个进度条 - - self.progressBar = QtWidgets.QProgressBar(self) - self.progressBar.setProperty("value", 0) - self.progressBar.setObjectName("progressBar") - self.setCellWidget(1, 5, self.progressBar) - self.step = 0 - self.timer = QTimer() - self.timer.setInterval(1000) - self.timer.start() - # 信号连接到槽 - self.timer.timeout.connect(self.onTimerOut) - self.count=0 - def onTimerOut(self): # 重写timerEvent - self.count +=1 - if self.count >= 100: # value >= 100时,停止计时器 - self.timer.stop() - print("结束") - # self.progressBar.setValue(self.step) - else: - print(self.count) - self.progressBar.setValue(self.count) - # return - # self.step += 1 - - - -if __name__ == '__main__': - app = QApplication(sys.argv) - myTable = MyTable() - myTable.show() - app.exit(app.exec_()) diff --git a/QTableWidget/Lib/mainui.py b/QTableWidget/Lib/mainui.py index d5f7041..c8f4665 100644 --- a/QTableWidget/Lib/mainui.py +++ b/QTableWidget/Lib/mainui.py @@ -6,7 +6,11 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +try: + from PyQt5 import QtCore, QtWidgets +except ImportError: + from PySide2 import QtCore, QtWidgets + class Ui_Form(object): def setupUi(self, Form): @@ -102,10 +106,10 @@ class Ui_Form(object): if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_()) - diff --git a/QTableWidget/SqlQuery.py b/QTableWidget/SqlQuery.py index 0e417f7..c40581e 100644 --- a/QTableWidget/SqlQuery.py +++ b/QTableWidget/SqlQuery.py @@ -4,26 +4,27 @@ """ Created on 2018年5月15日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: SqlQuery @description: """ -from PyQt5.QtCore import pyqtSlot -from PyQt5.QtWidgets import QWidget, QMessageBox, QTableWidgetItem + +try: + from PyQt5.QtCore import pyqtSlot + from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox, QTableWidgetItem +except ImportError: + from PySide2.QtCore import Slot as pyqtSlot + from PySide2.QtWidgets import QApplication, QWidget, QMessageBox, QTableWidgetItem + from sqlalchemy.engine import create_engine from sqlalchemy.ext.declarative.api import declarative_base from sqlalchemy.orm.session import sessionmaker from sqlalchemy.sql.expression import and_ from sqlalchemy.sql.schema import Column from sqlalchemy.sql.sqltypes import Integer, Text -from Lib.mainui import Ui_Form -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +from Lib.mainui import Ui_Form # engine = create_engine('mysql+mysqldb://root@localhost:3306/tourist?charset=utf8') engine = create_engine('sqlite:///Data/data.sqlite3', echo=True) # echo 表示开启命令显示 @@ -31,7 +32,6 @@ Base = declarative_base() class Tourist(Base): - __tablename__ = 'tourist' id = Column(Integer, primary_key=True) @@ -141,8 +141,9 @@ class Window(QWidget, Ui_Form): if __name__ == '__main__': import sys import cgitb - sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QTableWidget/TableWidget.py b/QTableWidget/TableWidget.py index bae38af..a052566 100644 --- a/QTableWidget/TableWidget.py +++ b/QTableWidget/TableWidget.py @@ -1,75 +1,83 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2017年4月21日 @author: weike32 -@site: https://pyqt5.com ,https://github.com/weike32 +@site: https://pyqt.site ,https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: 查阅了很多博客,如果有异,可以联系作者邮箱。本Demo仅作学习参考用,保有后续相关权益。 -''' -from PyQt5 import QtWidgets -from PyQt5.QtWidgets import * -from PyQt5.QtGui import * -from PyQt5.QtCore import * +""" import sys +try: + from PyQt5 import QtWidgets + from PyQt5.QtCore import * + from PyQt5.QtGui import * + from PyQt5.QtWidgets import * +except ImportError: + from PySide2 import QtWidgets + from PySide2.QtCore import * + from PySide2.QtGui import * + from PySide2.QtWidgets import * + + class MyTable(QTableWidget): - def __init__(self,parent=None): + def __init__(self, parent=None): super(MyTable, self).__init__(parent) self.setWindowTitle("我是一个表格") self.setWindowIcon(QIcon("male.png")) self.resize(920, 240) self.setColumnCount(6) self.setRowCount(2) - #设置表格有两行五列。 + # 设置表格有两行五列。 self.setColumnWidth(0, 200) self.setColumnWidth(4, 200) self.setRowHeight(0, 100) - #设置第一行高度为100px,第一列宽度为200px。 + # 设置第一行高度为100px,第一列宽度为200px。 self.table() def table(self): - self.setItem(0,0,QTableWidgetItem("你的名字")) - self.setItem(0,1,QTableWidgetItem("性别")) - self.setItem(0,2,QTableWidgetItem("出生日期")) - self.setItem(0,3, QTableWidgetItem("职业")) - self.setItem(0,4, QTableWidgetItem("收入")) + self.setItem(0, 0, QTableWidgetItem("你的名字")) + self.setItem(0, 1, QTableWidgetItem("性别")) + self.setItem(0, 2, QTableWidgetItem("出生日期")) + self.setItem(0, 3, QTableWidgetItem("职业")) + self.setItem(0, 4, QTableWidgetItem("收入")) self.setItem(0, 5, QTableWidgetItem("进度条")) - #添加表格的文字内容. - self.setHorizontalHeaderLabels(["第一行", "第二行", "第三行", "第四行", "第五行","第六行"]) + # 添加表格的文字内容. + self.setHorizontalHeaderLabels(["第一行", "第二行", "第三行", "第四行", "第五行", "第六行"]) self.setVerticalHeaderLabels(["第一列", "第二列"]) - #设置表头 + # 设置表头 lbp = QLabel() lbp.setPixmap(QPixmap("youPicture.png")) - self.setCellWidget(1,1,lbp) - #在表中添加一张图片 + self.setCellWidget(1, 1, lbp) + # 在表中添加一张图片 twi = QTableWidgetItem("Graph") twi.setFont(QFont("Times", 10, )) - self.setItem(1,0,twi) + self.setItem(1, 0, twi) - #添加一个自己设置了大小和类型的文字。 + # 添加一个自己设置了大小和类型的文字。 dte = QDateTimeEdit() dte.setDateTime(QDateTime.currentDateTime()) dte.setDisplayFormat("yyyy/MM/dd") dte.setCalendarPopup(True) - self.setCellWidget(1,2,dte) - #添加一个弹出的日期选择,设置默认值为当前日期,显示格式为年月日。 + self.setCellWidget(1, 2, dte) + # 添加一个弹出的日期选择,设置默认值为当前日期,显示格式为年月日。 cbw = QComboBox() cbw.addItem("医生") cbw.addItem("老师") cbw.addItem("律师") - self.setCellWidget(1,3,cbw) - #添加了一个下拉选择框 + self.setCellWidget(1, 3, cbw) + # 添加了一个下拉选择框 sb = QSpinBox() - sb.setRange(1000,10000) - sb.setValue(5000)#设置最开始显示的数字 - sb.setDisplayIntegerBase(10)#这个是显示数字的进制,默认是十进制。 - sb.setSuffix("元")#设置后辍 - sb.setPrefix("RMB: ")#设置前辍 + sb.setRange(1000, 10000) + sb.setValue(5000) # 设置最开始显示的数字 + sb.setDisplayIntegerBase(10) # 这个是显示数字的进制,默认是十进制。 + sb.setSuffix("元") # 设置后辍 + sb.setPrefix("RMB: ") # 设置前辍 sb.setSingleStep(100) - self.setCellWidget(1,4,sb) + self.setCellWidget(1, 4, sb) # 添加一个进度条 self.progressBar = QtWidgets.QProgressBar(self) @@ -82,9 +90,10 @@ class MyTable(QTableWidget): self.timer.start() # 信号连接到槽 self.timer.timeout.connect(self.onTimerOut) - self.count=0 + self.count = 0 + def onTimerOut(self): # 重写timerEvent - self.count +=1 + self.count += 1 if self.count >= 100: # value >= 100时,停止计时器 self.timer.stop() print("结束") @@ -96,7 +105,6 @@ class MyTable(QTableWidget): # self.step += 1 - if __name__ == '__main__': app = QApplication(sys.argv) myTable = MyTable() diff --git a/QTextBrowser/DynamicRes.py b/QTextBrowser/DynamicRes.py index 634a57b..2c229fe 100644 --- a/QTextBrowser/DynamicRes.py +++ b/QTextBrowser/DynamicRes.py @@ -4,7 +4,7 @@ """ Created on 2020/6/3 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: DynamicRes @description: @@ -12,13 +12,15 @@ Created on 2020/6/3 from threading import Thread import requests -from PyQt5.QtCore import QUrl, QByteArray -from PyQt5.QtGui import QImage, QTextDocument -from PyQt5.QtWidgets import QTextBrowser, QWidget, QVBoxLayout, QPushButton -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtCore import QUrl, QByteArray + from PyQt5.QtGui import QImage, QTextDocument + from PyQt5.QtWidgets import QApplication, QTextBrowser, QWidget, QVBoxLayout, QPushButton +except ImportError: + from PySide2.QtCore import QUrl, QByteArray + from PySide2.QtGui import QImage, QTextDocument + from PySide2.QtWidgets import QApplication, QTextBrowser, QWidget, QVBoxLayout, QPushButton class TextBrowser(QTextBrowser): @@ -44,7 +46,8 @@ class TextBrowser(QTextBrowser): return ret if url.toString().startswith('irony'): # 自定义的协议头 print('加载本地', '../Donate/zhifubao.png', url) - return QImage('../Donate/zhifubao.png') # 或者 QByteArray(open('../Donate/zhifubao.png', 'rb').read()) + return QImage( + '../Donate/zhifubao.png') # 或者 QByteArray(open('../Donate/zhifubao.png', 'rb').read()) elif url.toString().startswith('http'): # 加载网络图片 img, status = self.NetImages.get(url, [None, None]) if url not in self.NetImages or status is None: @@ -79,7 +82,8 @@ class Window(QWidget): # 加载本地图片 img = QImage('../Donate/weixin.png') # 第二个参数为任意唯一的url类似于qrc方式 - self.textBrowser.document().addResource(QTextDocument.ImageResource, QUrl('dynamic:/images/weixin.png'), img) + self.textBrowser.document().addResource(QTextDocument.ImageResource, + QUrl('dynamic:/images/weixin.png'), img) # 设置html # 需要注意里面的图片地址 @@ -87,16 +91,15 @@ class Window(QWidget): '

' # 方式一直接加载本地图片 '

' # 方式二通过addResource添加资源 '

' # 方式三定义自定义的协议头通过loadResource动态加载 - '

') + '

') if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() diff --git a/QTextEdit/HighlightText.py b/QTextEdit/HighlightText.py index 092554a..ca7398f 100644 --- a/QTextEdit/HighlightText.py +++ b/QTextEdit/HighlightText.py @@ -1,8 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2019年5月22日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: +@description: +""" + import sys -from PyQt5.QtCore import QRegExp -from PyQt5.QtGui import QTextCharFormat, QTextDocument, QTextCursor -from PyQt5.QtWidgets import (QApplication, QMainWindow, QTextEdit, - QToolBar, QLineEdit, QPushButton, QColorDialog, QHBoxLayout, QWidget) + +try: + from PyQt5.QtCore import QRegExp + from PyQt5.QtGui import QTextCharFormat, QTextCursor + from PyQt5.QtWidgets import (QApplication, QMainWindow, QTextEdit, + QToolBar, QLineEdit, QPushButton, QColorDialog, QHBoxLayout, QWidget) +except ImportError: + from PySide2.QtCore import QRegExp + from PySide2.QtGui import QTextCharFormat, QTextCursor + from PySide2.QtWidgets import (QApplication, QMainWindow, QTextEdit, + QToolBar, QLineEdit, QPushButton, QColorDialog, QHBoxLayout, QWidget) class TextEdit(QMainWindow): diff --git a/QThread/InheritQThread.py b/QThread/InheritQThread.py index ea10801..051f5f6 100644 --- a/QThread/InheritQThread.py +++ b/QThread/InheritQThread.py @@ -4,27 +4,28 @@ """ Created on 2018年3月9日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: InheritQThread @description: 继承QThread """ -from PyQt5.QtCore import QThread, pyqtSignal -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QPushButton - -__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com' -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QThread, pyqtSignal + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QPushButton +except ImportError: + from PySide2.QtCore import QThread, Signal as pyqtSignal + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QPushButton class Worker(QThread): - valueChanged = pyqtSignal(int) # 值变化信号 def run(self): - print('thread id', int(QThread.currentThreadId())) + print('thread id', QThread.currentThread()) for i in range(1, 101): + if self.isInterruptionRequested(): + break print('value', i) self.valueChanged.emit(i) QThread.sleep(1) @@ -41,7 +42,7 @@ class Window(QWidget): layout.addWidget(QPushButton('开启线程', self, clicked=self.onStart)) # 当前线程id - print('main id', int(QThread.currentThreadId())) + print('main id', QThread.currentThread()) # 子线程 self._thread = Worker(self) @@ -49,21 +50,26 @@ class Window(QWidget): self._thread.valueChanged.connect(self.progressBar.setValue) def onStart(self): - print('main id', int(QThread.currentThreadId())) - self._thread.start() # 启动线程 + if not self._thread.isRunning(): + print('main id', QThread.currentThread()) + self._thread.start() # 启动线程 def closeEvent(self, event): if self._thread.isRunning(): + self._thread.requestInterruption() self._thread.quit() + self._thread.wait() # 强制 # self._thread.terminate() - del self._thread + self._thread.deleteLater() super(Window, self).closeEvent(event) if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + import cgitb + + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/QThread/QuitThread.py b/QThread/QuitThread.py index 5b71a72..35b7a8e 100644 --- a/QThread/QuitThread.py +++ b/QThread/QuitThread.py @@ -4,26 +4,25 @@ """ Created on 2020/11/27 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QuitThread @description: """ -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' - import sys from time import time -from PyQt5.QtCore import QThread, QCoreApplication, QTimer +try: + from PyQt5.QtCore import QThread, QCoreApplication, QTimer +except ImportError: + from PySide2.QtCore import QThread, QCoreApplication, QTimer class Thread(QThread): def run(self): - print('thread id', int(QThread.currentThreadId())) + print('thread id', QThread.currentThread()) i = 0 while i < 101 and not self.isInterruptionRequested(): print('value', i, time()) diff --git a/QThread/SuspendThread.py b/QThread/SuspendThread.py index 707324e..32c3601 100644 --- a/QThread/SuspendThread.py +++ b/QThread/SuspendThread.py @@ -1,26 +1,24 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + +""" +Created on 2018年3月13日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: +@description: +""" + import ctypes +import win32con from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QPushButton -import win32con from win32process import SuspendThread, ResumeThread -# Created on 2018年3月13日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: 多线程使用.a -# description: -__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com' -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class Worker(QThread): - valueChanged = pyqtSignal(int) # 值变化信号 handle = -1 @@ -109,8 +107,10 @@ class Window(QWidget): if __name__ == '__main__': import sys import os + print('pid', os.getpid()) from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QThread/WakeupThread.py b/QThread/WakeupThread.py index 66c299f..e935037 100644 --- a/QThread/WakeupThread.py +++ b/QThread/WakeupThread.py @@ -4,7 +4,7 @@ """ Created on 2018年11月11日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: @description: @@ -13,15 +13,7 @@ from PyQt5.QtCore import QThread, QWaitCondition, QMutex, pyqtSignal from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QProgressBar -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class Thread(QThread): - valueChange = pyqtSignal(int) def __init__(self, *args, **kwargs): @@ -75,8 +67,10 @@ class Window(QWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + + cgitb.enable(format='text') from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QThread/moveToThread.py b/QThread/moveToThread.py index ea1602d..77214df 100644 --- a/QThread/moveToThread.py +++ b/QThread/moveToThread.py @@ -4,27 +4,28 @@ """ Created on 2018年3月9日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: moveToThread @description: moveToThread """ -from PyQt5.QtCore import QObject, pyqtSignal, QThread -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QPushButton - -__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com' -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +try: + from PyQt5.QtCore import QObject, pyqtSignal, QThread + from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QPushButton +except ImportError: + from PySide2.QtCore import QObject, Signal as pyqtSignal, QThread + from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QPushButton class Worker(QObject): - valueChanged = pyqtSignal(int) # 值变化信号 def run(self): - print('thread id', int(QThread.currentThreadId())) + print('thread id', ) for i in range(1, 101): + if QThread.currentThread().isInterruptionRequested(): + break print('value', i) self.valueChanged.emit(i) QThread.sleep(1) @@ -41,33 +42,38 @@ class Window(QWidget): layout.addWidget(QPushButton('开启线程', self, clicked=self.onStart)) # 当前线程id - print('main id', int(QThread.currentThreadId())) + print('main id', QThread.currentThread()) # 启动线程更新进度条值 self._thread = QThread(self) self._worker = Worker() self._worker.moveToThread(self._thread) # 移动到线程中执行 self._thread.finished.connect(self._worker.deleteLater) + self._thread.started.connect(self._worker.run) self._worker.valueChanged.connect(self.progressBar.setValue) def onStart(self): - print('main id', int(QThread.currentThreadId())) - self._thread.started.connect(self._worker.run) - self._thread.start() # 启动线程 + if not self._thread.isRunning(): + print('main id', QThread.currentThread()) + self._thread.start() # 启动线程 def closeEvent(self, event): if self._thread.isRunning(): + self._thread.requestInterruption() self._thread.quit() + self._thread.wait() # 强制 # self._thread.terminate() - del self._thread - del self._worker + self._thread.deleteLater() super(Window, self).closeEvent(event) if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + import cgitb + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QTreeWidget/Lib/testTree.py b/QTreeWidget/Lib/testTree.py index 647f005..2745b72 100644 --- a/QTreeWidget/Lib/testTree.py +++ b/QTreeWidget/Lib/testTree.py @@ -6,7 +6,8 @@ # # WARNING! All changes made in this file will be lost! -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtWidgets + class Ui_Form(object): def setupUi(self, Form): @@ -48,10 +49,10 @@ class Ui_Form(object): if __name__ == "__main__": import sys + app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_()) - diff --git a/QTreeWidget/ParentNodeForbid.py b/QTreeWidget/ParentNodeForbid.py index 18759dd..1a139e7 100644 --- a/QTreeWidget/ParentNodeForbid.py +++ b/QTreeWidget/ParentNodeForbid.py @@ -4,19 +4,20 @@ """ Created on 2019年11月8日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QTreeWidget.ParentNodeForbid @description: 父节点不可选中 """ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QStyledItemDelegate,\ - QStyle - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 1.0 +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QStyledItemDelegate, \ + QStyle +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QStyledItemDelegate, \ + QStyle class NoColorItemDelegate(QStyledItemDelegate): @@ -84,8 +85,9 @@ class Window(QTreeWidget): if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') - from PyQt5.QtWidgets import QApplication + + cgitb.enable(format='text') + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QTreeWidget/ParsingJson.py b/QTreeWidget/ParsingJson.py index dbbc088..c32480c 100644 --- a/QTreeWidget/ParsingJson.py +++ b/QTreeWidget/ParsingJson.py @@ -4,7 +4,7 @@ """ Created on 2018年4月8日 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ParsingJson @description: @@ -12,18 +12,18 @@ Created on 2018年4月8日 import json import webbrowser -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QWidget,\ - QLabel, QSpacerItem, QSizePolicy, QHBoxLayout import chardet - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QIcon + from PyQt5.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QWidget, \ + QLabel, QSpacerItem, QSizePolicy, QHBoxLayout +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QIcon + from PySide2.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QWidget, \ + PySide2, QSpacerItem, QSizePolicy, QHBoxLayout class ItemWidget(QWidget): @@ -94,7 +94,7 @@ class JsonTreeWidget(QTreeWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet("""QTreeView { outline: 0px; diff --git a/QTreeWidget/testTreeWidget.py b/QTreeWidget/testTreeWidget.py index 39aecad..3bdb956 100644 --- a/QTreeWidget/testTreeWidget.py +++ b/QTreeWidget/testTreeWidget.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # encoding: utf-8 -''' +""" Created on 2017年4月20日 @author: weike32 -@site: https://pyqt5.com , https://github.com/weike32 +@site: https://pyqt.site , https://github.com/weike32 @email: 394967319@qq.com @file: CopyContent @description: -''' +""" import sys from PyQt5.QtCore import Qt diff --git a/QWebEngineView/BlockRequest.py b/QWebEngineView/BlockRequest.py index e46744e..27b86d7 100644 --- a/QWebEngineView/BlockRequest.py +++ b/QWebEngineView/BlockRequest.py @@ -4,19 +4,22 @@ """ Created on 2019年9月24日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com -@file: QWebEngineView.BlockAds +@file: BlockRequest @description: 拦截请求 """ -from PyQt5.QtCore import QUrl -from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtCore import QUrl + from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QUrl + from PySide2.QtWebEngineCore import QWebEngineUrlRequestInterceptor + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile + from PySide2.QtWidgets import QApplication class RequestInterceptor(QWebEngineUrlRequestInterceptor): @@ -39,7 +42,7 @@ class Window(QWebEngineView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebEngineView/BlockRequestData.py b/QWebEngineView/BlockRequestData.py index 00da4fb..eea7a02 100644 --- a/QWebEngineView/BlockRequestData.py +++ b/QWebEngineView/BlockRequestData.py @@ -4,20 +4,24 @@ """ Created on 2020年2月18日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com -@file: QWebEngineView.BlockRequestData +@file: BlockRequestData @description: 拦截请求内容 """ -from PyQt5.QtCore import QUrl, QFile, QIODevice -from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler,\ - QWebEngineUrlRequestInterceptor, QWebEngineUrlScheme # @UnresolvedImport -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtCore import QUrl, QFile, QIODevice, QByteArray + from PyQt5.QtWidgets import QApplication + from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler, \ + QWebEngineUrlRequestInterceptor, QWebEngineUrlScheme # @UnresolvedImport + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile +except ImportError: + from PySide2.QtCore import QUrl, QFile, QIODevice, QByteArray + from PySide2.QtWidgets import QApplication + from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler, \ + QWebEngineUrlRequestInterceptor, QWebEngineUrlScheme # @UnresolvedImport + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile # 自定义url协议头 @@ -30,6 +34,7 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler): file.open(QIODevice.ReadOnly) job.reply(b'image/png', file) + # 请求拦截器 @@ -50,8 +55,8 @@ class Window(QWebEngineView): self.resize(800, 600) # 首先获取默认的url协议 - h1 = QWebEngineUrlScheme.schemeByName(b'http') - h2 = QWebEngineUrlScheme.schemeByName(b'https') + h1 = QWebEngineUrlScheme.schemeByName(QByteArray(b'http')) + h2 = QWebEngineUrlScheme.schemeByName(QByteArray(b'https')) # 这里需要修改增加本地文件和跨域支持 CorsEnabled = 0x80 # 5.14才增加 @@ -69,12 +74,12 @@ class Window(QWebEngineView): # 安装url拦截器和自定义url协议处理 de = QWebEngineProfile.defaultProfile() # @UndefinedVariable de.setRequestInterceptor(RequestInterceptor(self)) - de.installUrlSchemeHandler(b'myurl', UrlSchemeHandler(self)) + de.installUrlSchemeHandler(QByteArray(b'myurl'), UrlSchemeHandler(self)) if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebEngineView/GetCookie.py b/QWebEngineView/GetCookie.py index 81aa259..f74eae8 100644 --- a/QWebEngineView/GetCookie.py +++ b/QWebEngineView/GetCookie.py @@ -1,28 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月10日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: GetCookie @description: -''' +""" + import sys -from PyQt5.QtCore import QUrl, QByteArray -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile -from PyQt5.QtWidgets import QApplication, QTextEdit - - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QUrl, QByteArray + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile + from PyQt5.QtWidgets import QApplication, QTextEdit +except ImportError: + from PySide2.QtCore import QUrl, QByteArray + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile + from PySide2.QtWidgets import QApplication, QTextEdit class WebEngineView(QWebEngineView): - DomainCookies = {} # 存放domain的key-value PathCookies = {} # 存放domain+path的key-value @@ -63,9 +63,9 @@ class WebEngineView(QWebEngineView): "AllPathCookies: " + self.bytestostr(self.getAllPathCookies())) self.cookieView.append('') - print("*****pyqt5.com cookie:", self.getDomainCookies(".pyqt5.com")) - print("*****pyqt5.com / path cookie:", - self.getPathCookies(".pyqt5.com/")) + print("*****pyqt.site cookie:", self.getDomainCookies(".pyqt.site")) + print("*****pyqt.site / path cookie:", + self.getPathCookies(".pyqt.site/")) def getAllDomainCookies(self): return self.DomainCookies @@ -80,9 +80,9 @@ class WebEngineView(QWebEngineView): return self.PathCookies.get(dpath, {}) def onCookieAdd(self, cookie): - ''' + """ :param cookie: QNetworkCookie - ''' + """ domain = cookie.domain() path = cookie.path() name = cookie.name().data() @@ -98,6 +98,8 @@ class WebEngineView(QWebEngineView): _cookie[name] = value else: self.PathCookies[domain_path] = {name: value} + + # print("add cookie:", cookie.domain(), # cookie.path(), cookie.name(), cookie.value()) @@ -106,5 +108,5 @@ if __name__ == "__main__": app = QApplication(sys.argv) w = WebEngineView() w.show() - w.load(QUrl("https://pyqt5.com")) + w.load(QUrl("https://pyqt.site")) sys.exit(app.exec_()) diff --git a/QWebEngineView/GetRequestInfo.py b/QWebEngineView/GetRequestInfo.py index 91b5105..a86d810 100644 --- a/QWebEngineView/GetRequestInfo.py +++ b/QWebEngineView/GetRequestInfo.py @@ -4,20 +4,26 @@ """ Created on 2019年9月24日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebEngineView.BlockAds @description: 拦截请求 """ -from PyQt5.QtCore import QUrl -from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest -from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler, QWebEngineUrlScheme, \ - QWebEngineUrlRequestInterceptor -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtCore import QUrl, QByteArray + from PyQt5.QtWidgets import QApplication + from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest + from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler, QWebEngineUrlScheme, \ + QWebEngineUrlRequestInterceptor + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile +except ImportError: + from PySide2.QtCore import QUrl, QByteArray + from PySide2.QtWidgets import QApplication + from PySide2.QtNetwork import QNetworkAccessManager, QNetworkRequest + from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler, QWebEngineUrlScheme, \ + QWebEngineUrlRequestInterceptor + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile class UrlSchemeHandler(QWebEngineUrlSchemeHandler): @@ -86,23 +92,29 @@ class Window(QWebEngineView): profile = QWebEngineProfile.defaultProfile() # 首先获取默认的url协议 - o_http = QWebEngineUrlScheme.schemeByName(b'http') - o_https = QWebEngineUrlScheme.schemeByName(b'https') + o_http = QWebEngineUrlScheme.schemeByName(QByteArray(b'http')) + o_https = QWebEngineUrlScheme.schemeByName(QByteArray(b'https')) print('scheme:', o_http, o_https) # 这里需要修改增加本地文件和跨域支持 CorsEnabled = 0x80 # 5.14才增加 - o_http.setFlags( - o_http.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) - o_https.setFlags( - o_https.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) + o_http.setFlags(o_http.flags() | + QWebEngineUrlScheme.SecureScheme | + QWebEngineUrlScheme.LocalScheme | + QWebEngineUrlScheme.LocalAccessAllowed | + CorsEnabled) + o_https.setFlags(o_https.flags() | + QWebEngineUrlScheme.SecureScheme | + QWebEngineUrlScheme.LocalScheme | + QWebEngineUrlScheme.LocalAccessAllowed | + CorsEnabled) # 安装url拦截器和自定义url协议处理 de = QWebEngineProfile.defaultProfile() # @UndefinedVariable de.setRequestInterceptor(RequestInterceptor(self)) self.urlSchemeHandler = UrlSchemeHandler(self) - de.installUrlSchemeHandler(b'myurl', self.urlSchemeHandler) # for http - de.installUrlSchemeHandler(b'myurls', self.urlSchemeHandler) # for https + de.installUrlSchemeHandler(QByteArray(b'myurl'), self.urlSchemeHandler) # for http + de.installUrlSchemeHandler(QByteArray(b'myurls'), self.urlSchemeHandler) # for https if __name__ == '__main__': @@ -112,7 +124,6 @@ if __name__ == '__main__': import cgitb cgitb.enable(format='text') - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) # 开启F12 控制台功能,需要单独通过浏览器打开这个页面 diff --git a/QWebEngineView/JsSignals.py b/QWebEngineView/JsSignals.py index 725ea90..aac9401 100644 --- a/QWebEngineView/JsSignals.py +++ b/QWebEngineView/JsSignals.py @@ -4,7 +4,7 @@ """ Created on 2019年4月27日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebEngineView.JsSignals @description: @@ -12,18 +12,19 @@ Created on 2019年4月27日 import os from time import time -from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal -from PyQt5.QtWebChannel import QWebChannel -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings -from PyQt5.QtWidgets import QMessageBox, QWidget, QVBoxLayout, QPushButton - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' +try: + from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal + from PyQt5.QtWebChannel import QWebChannel + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings + from PyQt5.QtWidgets import QMessageBox, QWidget, QVBoxLayout, QPushButton +except ImportError: + from PySide2.QtCore import QUrl, Slot as pyqtSlot, Signal as pyqtSignal + from PySide2.QtWebChannel import QWebChannel + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings + from PySide2.QtWidgets import QMessageBox, QWidget, QVBoxLayout, QPushButton class WebEngineView(QWebEngineView): - customSignal = pyqtSignal(str) def __init__(self, *args, **kwargs): @@ -38,13 +39,13 @@ class WebEngineView(QWebEngineView): # START #####以下代码可能是在5.6 QWebEngineView刚出来时的bug,必须在每次加载页面的时候手动注入 #### 也有可能是跳转页面后就失效了,需要手动注入,有没有修复具体未测试 -# self.page().loadStarted.connect(self.onLoadStart) -# self._script = open('Data/qwebchannel.js', 'rb').read().decode() + # self.page().loadStarted.connect(self.onLoadStart) + # self._script = open('Data/qwebchannel.js', 'rb').read().decode() -# def onLoadStart(self): -# self.page().runJavaScript(self._script) + # def onLoadStart(self): + # self.page().runJavaScript(self._script) - # END ########################### + # END ########################### # 注意pyqtSlot用于把该函数暴露给js可以调用 @pyqtSlot(str) @@ -58,16 +59,16 @@ class WebEngineView(QWebEngineView): @pyqtSlot(str) @pyqtSlot(QUrl) def load(self, url): - ''' - eg: load("https://pyqt5.com") + """ + eg: load("https://pyqt.site") :param url: 网址 - ''' + """ return super(WebEngineView, self).load(QUrl(url)) def initSettings(self): - ''' + """ eg: 初始化设置 - ''' + """ # 获取浏览器默认设置 settings = QWebEngineSettings.globalSettings() # 设置默认编码utf8 @@ -133,9 +134,10 @@ class Window(QWidget): os.path.abspath('Data/JsSignals.html'))) -if __name__ == "__main__": +if __name__ == '__main__': from PyQt5.QtWidgets import QApplication import sys + # 开启F12 控制台功能,需要单独通过浏览器打开这个页面 # 这里可以做个保护, 发布软件,启动时把这个环境变量删掉。防止他人通过环境变量开启 os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '9966' diff --git a/QWebEngineView/ScreenShotPage.py b/QWebEngineView/ScreenShotPage.py index cf117b2..bef6438 100644 --- a/QWebEngineView/ScreenShotPage.py +++ b/QWebEngineView/ScreenShotPage.py @@ -4,7 +4,7 @@ """ Created on 2019年7月8日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScreenShotPage @description: 网页整体截图 @@ -14,18 +14,22 @@ import cgitb import os import sys -from PyQt5.QtCore import QUrl, Qt, pyqtSlot, QSize, QTimer -from PyQt5.QtGui import QImage, QPainter, QIcon, QPixmap -from PyQt5.QtWebChannel import QWebChannel -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton,\ - QGroupBox, QLineEdit, QHBoxLayout, QListWidget, QListWidgetItem,\ - QProgressDialog - - -__Author__ = "Irony" -__Copyright__ = "Copyright (c) 2019" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QUrl, Qt, pyqtSlot, QSize, QTimer, QPoint + from PyQt5.QtGui import QImage, QPainter, QIcon, QPixmap + from PyQt5.QtWebChannel import QWebChannel + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings + from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, \ + QGroupBox, QLineEdit, QHBoxLayout, QListWidget, QListWidgetItem, \ + QProgressDialog +except ImportError: + from PySide2.QtCore import QUrl, Qt, Slot as pyqtSlot, QSize, QTimer, QPoint + from PySide2.QtGui import QImage, QPainter, QIcon, QPixmap + from PySide2.QtWebChannel import QWebChannel + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings + from PySide2.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, \ + QGroupBox, QLineEdit, QHBoxLayout, QListWidget, QListWidgetItem, \ + QProgressDialog # 对部分内容进行截图 CODE = """ @@ -116,8 +120,8 @@ class Window(QWidget): open('Data/qwebchannel.js', 'rb').read().decode()) page.runJavaScript( open('Data/jquery.js', 'rb').read().decode()) -# page.runJavaScript( -# open('Data/promise-7.0.4.min.js', 'rb').read().decode()) + # page.runJavaScript( + # open('Data/promise-7.0.4.min.js', 'rb').read().decode()) page.runJavaScript( open('Data/html2canvas.min.js', 'rb').read().decode()) page.runJavaScript(CreateBridge) @@ -143,7 +147,7 @@ class Window(QWidget): painter.setRenderHint(QPainter.TextAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) - self.webView.render(painter) + self.webView.render(painter, QPoint()) painter.end() self.webView.resize(oldSize) @@ -181,11 +185,11 @@ class Window(QWidget): item.setData(Qt.UserRole + 1, image) -if __name__ == "__main__": +if __name__ == '__main__': # 开启F12 控制台功能,需要单独通过浏览器打开这个页面 # 这里可以做个保护, 发布软件,启动时把这个环境变量删掉。防止他人通过环境变量开启 os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '9966' - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebEngineView/SiteDiffUser.py b/QWebEngineView/SiteDiffUser.py index 89d096a..d4e18aa 100644 --- a/QWebEngineView/SiteDiffUser.py +++ b/QWebEngineView/SiteDiffUser.py @@ -4,20 +4,22 @@ """ Created on 2019年8月23日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebEngineView.SiteDiffUser @description: 同个网站不同用户 """ -from PyQt5.QtCore import QUrl -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage,\ - QWebEngineProfile -from PyQt5.QtWidgets import QTabWidget - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtCore import QUrl + from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ + QWebEngineProfile + from PyQt5.QtWidgets import QApplication, QTabWidget +except ImportError: + from PySide2.QtCore import QUrl + from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ + QWebEngineProfile + from PySide2.QtWidgets import QApplication, QTabWidget class Window(QTabWidget): @@ -53,7 +55,7 @@ class Window(QTabWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebView/BlockRequest.py b/QWebView/BlockRequest.py index 3db7d0d..dd50c6e 100644 --- a/QWebView/BlockRequest.py +++ b/QWebView/BlockRequest.py @@ -4,21 +4,16 @@ """ Created on 2019年9月24日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebView.BlockAds @description: 拦截请求 """ -from PyQt5.QtCore import QUrl, QBuffer, QByteArray +from PyQt5.QtCore import QUrl, QBuffer from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtWebKitWidgets import QWebView -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' -__Version__ = 'Version 1.0' - - class RequestInterceptor(QNetworkAccessManager): def createRequest(self, op, originalReq, outgoingData): @@ -55,6 +50,7 @@ class Window(QWebView): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebView/DreamTree.py b/QWebView/DreamTree.py index 8263b01..071e2f1 100644 --- a/QWebView/DreamTree.py +++ b/QWebView/DreamTree.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年4月6日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: DreamTree @description: -''' +""" import sys @@ -17,12 +17,8 @@ from PyQt5.QtGui import QPalette from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout -from Lib import data_rc # @UnusedImport @UnresolvedImport # from PyQt5.QtWebKit import QWebSettings -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" # 要实现透明的webview,需要先用一个QWidget作为父控件 diff --git a/QWebView/GetCookie.py b/QWebView/GetCookie.py index 5514103..1420837 100644 --- a/QWebView/GetCookie.py +++ b/QWebView/GetCookie.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月10日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: GetCookie @description: -''' +""" import cgitb import sys @@ -17,11 +17,6 @@ from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWidgets import QApplication, QTextEdit -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - - class WebView(QWebView): def __init__(self, *args, **kwargs): @@ -52,7 +47,7 @@ class WebView(QWebView): allCookies = self.page().networkAccessManager().cookieJar().allCookies() print("allCookies:", allCookies) for cookie in allCookies: - # if cookie.domain() == ".pyqt5.com": + # if cookie.domain() == ".pyqt.site": self.cookieView.append( "domain: " + self.bytestostr(cookie.domain())) self.cookieView.append("path: " + self.bytestostr(cookie.path())) @@ -68,9 +63,9 @@ class WebView(QWebView): if __name__ == "__main__": - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = WebView() w.show() - w.load(QUrl("https://pyqt5.com")) + w.load(QUrl("https://pyqt.site")) sys.exit(app.exec_()) diff --git a/QWebView/JsSignals.py b/QWebView/JsSignals.py index 878e61b..6a3d7a5 100644 --- a/QWebView/JsSignals.py +++ b/QWebView/JsSignals.py @@ -4,7 +4,7 @@ """ Created on 2019年4月27日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebEngineView.JsSignals @description: @@ -18,12 +18,7 @@ from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWidgets import QMessageBox, QWidget, QVBoxLayout, QPushButton -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' - - class WebView(QWebView): - customSignal = pyqtSignal(str) def __init__(self, *args, **kwargs): @@ -50,7 +45,7 @@ class WebView(QWebView): @pyqtSlot(QUrl) def load(self, url): ''' - eg: load("https://pyqt5.com") + eg: load("https://pyqt.site") :param url: 网址 ''' return super(WebView, self).load(QUrl(url)) @@ -85,6 +80,7 @@ class Window(QWidget): if __name__ == "__main__": from PyQt5.QtWidgets import QApplication import sys + app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWebView/Lib/data_rc.py b/QWebView/Lib/data_rc.py index 59b9117..17c0cc2 100644 --- a/QWebView/Lib/data_rc.py +++ b/QWebView/Lib/data_rc.py @@ -6216,10 +6216,13 @@ qt_resource_struct = b"\ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ " + def qInitResources(): QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) + def qCleanupResources(): QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) + qInitResources() diff --git a/QWebView/PlayFlash.py b/QWebView/PlayFlash.py index dc992f5..15da61d 100644 --- a/QWebView/PlayFlash.py +++ b/QWebView/PlayFlash.py @@ -4,7 +4,7 @@ """ Created on 2019年9月18日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QWebView.PlayFlash @description: 播放Flash @@ -19,11 +19,6 @@ from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWidgets import QApplication -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - - class Window(QWebView): def __init__(self, *args, **kwargs): @@ -53,5 +48,6 @@ if __name__ == '__main__': app = QApplication(sys.argv) w = Window() w.show() - w.load(QUrl('https://www.17sucai.com/preview/8825/2013-07-07/%E4%B8%80%E6%AC%BE%E4%BA%BA%E5%BD%A2%E5%8A%A8%E4%BD%9C%E6%98%BE%E7%A4%BA%E7%9A%84flash%E6%97%B6%E9%97%B4/index.html')) + w.load(QUrl( + 'https://www.17sucai.com/preview/8825/2013-07-07/%E4%B8%80%E6%AC%BE%E4%BA%BA%E5%BD%A2%E5%8A%A8%E4%BD%9C%E6%98%BE%E7%A4%BA%E7%9A%84flash%E6%97%B6%E9%97%B4/index.html')) sys.exit(app.exec_()) diff --git a/QWebView/ScreenShotPage.py b/QWebView/ScreenShotPage.py index aeec283..6a00fc9 100644 --- a/QWebView/ScreenShotPage.py +++ b/QWebView/ScreenShotPage.py @@ -4,7 +4,7 @@ """ Created on 2019年7月8日 @author: Irony -@site: https://pyqt5.com https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScreenShotPage @description: 网页整体截图 @@ -17,15 +17,10 @@ from PyQt5.QtCore import QUrl, Qt, pyqtSlot, QSize from PyQt5.QtGui import QImage, QPainter, QIcon, QPixmap from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKitWidgets import QWebView -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton,\ - QGroupBox, QLineEdit, QHBoxLayout, QListWidget, QListWidgetItem,\ +from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, \ + QGroupBox, QLineEdit, QHBoxLayout, QListWidget, QListWidgetItem, \ QProgressDialog - -__Author__ = "Irony" -__Copyright__ = "Copyright (c) 2019" -__Version__ = "Version 1.0" - # 对部分内容进行截图 CODE = """ var el = $("%s"); @@ -80,7 +75,7 @@ class Window(QWidget): QWebSettings.DeveloperExtrasEnabled, True) self.webView.loadStarted.connect(self.onLoadStarted) self.webView.loadFinished.connect(self.onLoadFinished) - self.webView.load(QUrl("https://pyqt5.com")) + self.webView.load(QUrl("https://pyqt.site")) # 暴露接口和加载完成后执行jquery等一些库文件 self.webView.page().mainFrame().javaScriptWindowObjectCleared.connect( @@ -165,7 +160,7 @@ class Window(QWidget): if __name__ == "__main__": - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/QWidget/Lib/CustomPaintWidget.py b/QWidget/Lib/CustomPaintWidget.py index 4d5d4ed..f006d0a 100644 --- a/QWidget/Lib/CustomPaintWidget.py +++ b/QWidget/Lib/CustomPaintWidget.py @@ -1,21 +1,21 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月10日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CustomPaintWidget @description: -''' -from PyQt5.QtGui import QPainter -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QStyleOption, QStyle +""" - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QStyleOption, QStyle +except ImportError: + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QWidget, QVBoxLayout, QLabel, QStyleOption, QStyle class CustomPaintWidget(QWidget): diff --git a/QWidget/Lib/CustomWidget.py b/QWidget/Lib/CustomWidget.py index 11edcfb..0231fc9 100644 --- a/QWidget/Lib/CustomWidget.py +++ b/QWidget/Lib/CustomWidget.py @@ -1,20 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月10日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CustomWidget @description: -''' -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel +""" - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel +except ImportError: + from PySide2.QtWidgets import QWidget, QVBoxLayout, QLabel class CustomWidget(QWidget): @@ -22,4 +21,4 @@ class CustomWidget(QWidget): def __init__(self, *args, **kwargs): super(CustomWidget, self).__init__(*args, **kwargs) layout = QVBoxLayout(self) - layout.addWidget(QLabel("我是自定义CustomWidget", self)) \ No newline at end of file + layout.addWidget(QLabel("我是自定义CustomWidget", self)) diff --git a/QWidget/WidgetStyle.py b/QWidget/WidgetStyle.py index 945407c..842a29a 100644 --- a/QWidget/WidgetStyle.py +++ b/QWidget/WidgetStyle.py @@ -1,28 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月10日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: test @description: -''' +""" + import sys -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout +try: + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QWidget, QApplication, QHBoxLayout from Lib.CustomPaintWidget import CustomPaintWidget # @UnresolvedImport from Lib.CustomWidget import CustomWidget # @UnresolvedImport -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - - class Window(QWidget): def __init__(self, *args, **kwargs): @@ -31,9 +31,9 @@ class Window(QWidget): layout.addWidget(CustomPaintWidget(self)) layout.addWidget(CustomWidget(self)) # 注意 - w = CustomWidget(self) - w.setAttribute(Qt.WA_StyledBackground) # 很重要 - layout.addWidget(w) + wc = CustomWidget(self) + wc.setAttribute(Qt.WA_StyledBackground) # 很重要 + layout.addWidget(wc) if __name__ == "__main__": diff --git a/QtChart/AreaChart.py b/QtChart/AreaChart.py index 9e2d022..80b8868 100644 --- a/QtChart/AreaChart.py +++ b/QtChart/AreaChart.py @@ -4,14 +4,27 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AreaChart @description: 区域图表 """ -from PyQt5.QtChart import QChartView, QChart, QLineSeries, QAreaSeries -from PyQt5.QtCore import QPointF -from PyQt5.QtGui import QColor, QGradient, QLinearGradient, QPainter, QPen + +try: + from PyQt5.QtChart import QChartView, QChart, QLineSeries, QAreaSeries + from PyQt5.QtCore import QPointF + from PyQt5.QtGui import QColor, QGradient, QLinearGradient, QPainter, QPen + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QPointF + from PySide2.QtGui import QColor, QGradient, QLinearGradient, QPainter, QPen + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries + QAreaSeries = QtCharts.QAreaSeries class Window(QChartView): @@ -42,9 +55,9 @@ class Window(QChartView): # 添加数据 series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) \ - << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5) + << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5) series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) \ - << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3) + << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3) # 创建区域图 series = QAreaSeries(series0, series1) @@ -67,7 +80,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/BarChart.py b/QtChart/BarChart.py index 73bd762..fadcbdb 100644 --- a/QtChart/BarChart.py +++ b/QtChart/BarChart.py @@ -4,14 +4,28 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: BarChart @description: 柱状图表 """ -from PyQt5.QtChart import QChartView, QChart, QBarSet, QBarSeries, QBarCategoryAxis -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPainter + +try: + from PyQt5.QtChart import QChartView, QChart, QBarSet, QBarSeries, QBarCategoryAxis + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QBarSet = QtCharts.QBarSet + QBarSeries = QtCharts.QBarSeries + QBarCategoryAxis = QtCharts.QBarCategoryAxis class Window(QChartView): @@ -72,7 +86,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/BarStack.py b/QtChart/BarStack.py index 6267f42..f0ea25c 100644 --- a/QtChart/BarStack.py +++ b/QtChart/BarStack.py @@ -1,27 +1,36 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: charts.bar.BarStack @description: like http://echarts.baidu.com/demo.html#bar-stack -''' +""" import sys from random import randint -from PyQt5.QtChart import QChartView, QChart, QBarSeries, QBarSet, QBarCategoryAxis -from PyQt5.QtCore import Qt, QPointF, QRectF, QPoint -from PyQt5.QtGui import QPainter, QPen -from PyQt5.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ - QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget +try: + from PyQt5.QtChart import QChartView, QChart, QBarSeries, QBarSet, QBarCategoryAxis + from PyQt5.QtCore import Qt, QPointF, QRectF, QPoint + from PyQt5.QtGui import QPainter, QPen + from PyQt5.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ + QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget +except ImportError: + from PySide2.QtCore import Qt, QPointF, QRectF, QPoint + from PySide2.QtGui import QPainter, QPen + from PySide2.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ + QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget + from PySide2.QtCharts import QtCharts -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QBarSeries = QtCharts.QBarSeries + QBarSet = QtCharts.QBarSet + QBarCategoryAxis = QtCharts.QBarCategoryAxis class ToolTipItem(QWidget): @@ -44,7 +53,6 @@ class ToolTipItem(QWidget): class ToolTipWidget(QWidget): - Cache = {} def __init__(self, *args, **kwargs): @@ -134,7 +142,7 @@ class ChartView(QChartView): serie = self._chart.series()[0] bars = [(bar, bar.at(index)) for bar in serie.barSets() if self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y] -# print(bars) + # print(bars) if bars: right_top = self._chart.mapToPosition( QPointF(self.max_x, self.max_y)) @@ -153,10 +161,10 @@ class ChartView(QChartView): t_height = self.toolTipWidget.height() # 如果鼠标位置离右侧的距离小于tip宽度 x = pos.x() - t_width if self.width() - \ - pos.x() - 20 < t_width else pos.x() + pos.x() - 20 < t_width else pos.x() # 如果鼠标位置离底部的高度小于tip高度 y = pos.y() - t_height if self.height() - \ - pos.y() - 20 < t_height else pos.y() + pos.y() - 20 < t_height else pos.y() self.toolTipWidget.show( title, bars, QPoint(x, y)) else: diff --git a/QtChart/ChartThemes.py b/QtChart/ChartThemes.py index 3870401..059e7f1 100644 --- a/QtChart/ChartThemes.py +++ b/QtChart/ChartThemes.py @@ -4,7 +4,7 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ChartThemes @description: 图表主题动画等 @@ -29,13 +29,30 @@ Created on 2019/10/2 import random -from PyQt5.QtChart import (QAreaSeries, QBarSet, QChart, QChartView, - QLineSeries, QPieSeries, QScatterSeries, QSplineSeries, - QStackedBarSeries) -from PyQt5.QtCore import pyqtSlot, QPointF, Qt -from PyQt5.QtGui import QColor, QPainter, QPalette -from PyQt5.QtWidgets import (QCheckBox, QComboBox, QGridLayout, QHBoxLayout, - QLabel, QSizePolicy, QWidget) +try: + from PyQt5.QtChart import (QAreaSeries, QBarSet, QChart, QChartView, + QLineSeries, QPieSeries, QScatterSeries, QSplineSeries, + QStackedBarSeries) + from PyQt5.QtCore import pyqtSlot, QPointF, Qt + from PyQt5.QtGui import QColor, QPainter, QPalette + from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox, QComboBox, QGridLayout, QHBoxLayout, \ + QLabel, QSizePolicy, QWidget +except ImportError: + from PySide2.QtCore import Slot as pyqtSlot, QPointF, Qt + from PySide2.QtGui import QColor, QPainter, QPalette + from PySide2.QtWidgets import QApplication, QMainWindow, QCheckBox, QComboBox, QGridLayout, QHBoxLayout, \ + QLabel, QSizePolicy, QWidget + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QAreaSeries = QtCharts.QAreaSeries + QBarSet = QtCharts.QBarSet + QLineSeries = QtCharts.QLineSeries + QPieSeries = QtCharts.QPieSeries + QScatterSeries = QtCharts.QScatterSeries + QSplineSeries = QtCharts.QSplineSeries + QStackedBarSeries = QtCharts.QStackedBarSeries class ThemeWidget(QWidget): @@ -238,7 +255,7 @@ class ThemeWidget(QWidget): series = QPieSeries(chart) for value, label in data_list: slice = series.append(label, value.y()) - if len(series) == 1: + if series.count() == 1: slice.setLabelVisible() slice.setExploded() @@ -290,7 +307,7 @@ class ThemeWidget(QWidget): if self.m_charts[0].chart().theme() != theme: for chartView in self.m_charts: - chartView.chart().setTheme(theme) + chartView.chart().setTheme(QChart.ChartTheme(theme)) pal = self.window().palette() @@ -349,8 +366,6 @@ class ThemeWidget(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication, QMainWindow - app = QApplication(sys.argv) window = QMainWindow() diff --git a/QtChart/CpuLineChart.py b/QtChart/CpuLineChart.py index 731b805..17b521e 100644 --- a/QtChart/CpuLineChart.py +++ b/QtChart/CpuLineChart.py @@ -4,7 +4,7 @@ """ Created on 2021/5/13 @author: Irony -@site: https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CpuLineChart @description: diff --git a/QtChart/CustomXYaxis.py b/QtChart/CustomXYaxis.py index 9ab84fb..014ab6b 100644 --- a/QtChart/CustomXYaxis.py +++ b/QtChart/CustomXYaxis.py @@ -1,22 +1,30 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月19日 -@author: Irony."[讽刺] -@site: http://alyl.vip, http://orzorz.vip, http://coding.net/u/892768447, http://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: CustomXYaxis @description: -''' +""" import random import sys -from PyQt5.QtChart import QChartView, QLineSeries, QChart, QCategoryAxis -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout +try: + from PyQt5.QtChart import QChartView, QLineSeries, QChart, QCategoryAxis + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtWidgets import QApplication, QWidget, QHBoxLayout + from PySide2.QtCharts import QtCharts -__version__ = "0.0.1" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries + QCategoryAxis = QtCharts.QCategoryAxis m_listCount = 3 m_valueMax = 10 diff --git a/QtChart/DynamicSpline.py b/QtChart/DynamicSpline.py index 3ed3b85..b6bed0e 100644 --- a/QtChart/DynamicSpline.py +++ b/QtChart/DynamicSpline.py @@ -10,12 +10,21 @@ Created on 2019年5月5日 """ import sys -from PyQt5.QtChart import QChartView, QChart, QSplineSeries, QValueAxis -from PyQt5.QtCore import Qt, QTimer, QRandomGenerator -from PyQt5.QtGui import QPainter, QPen -from PyQt5.QtWidgets import QApplication +try: + from PyQt5.QtChart import QChartView, QChart, QSplineSeries, QValueAxis + from PyQt5.QtCore import Qt, QTimer, QRandomGenerator + from PyQt5.QtGui import QPainter, QPen + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import Qt, QTimer, QRandomGenerator + from PySide2.QtGui import QPainter, QPen + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts -__version__ = "0.0.1" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QSplineSeries = QtCharts.QSplineSeries + QValueAxis = QtCharts.QValueAxis class DynamicSpline(QChart): diff --git a/QtChart/HorizontalBarChart.py b/QtChart/HorizontalBarChart.py index 1f4000d..6018cef 100644 --- a/QtChart/HorizontalBarChart.py +++ b/QtChart/HorizontalBarChart.py @@ -4,14 +4,28 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: HorizontalBarChart @description: 横向柱状图表 """ -from PyQt5.QtChart import QChartView, QChart, QBarSet, QHorizontalBarSeries, QBarCategoryAxis -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPainter + +try: + from PyQt5.QtChart import QChartView, QChart, QBarSet, QHorizontalBarSeries, QBarCategoryAxis + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QBarSet = QtCharts.QBarSet + QHorizontalBarSeries = QtCharts.QHorizontalBarSeries + QBarCategoryAxis = QtCharts.QBarCategoryAxis class Window(QChartView): @@ -72,7 +86,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/HorizontalPercentBarChart.py b/QtChart/HorizontalPercentBarChart.py index 6f807e2..785efc9 100644 --- a/QtChart/HorizontalPercentBarChart.py +++ b/QtChart/HorizontalPercentBarChart.py @@ -4,14 +4,26 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: HorizontalPercentBarChart @description: 横向百分比柱状图表 """ -from PyQt5.QtChart import QChartView, QChart, QBarSet, QHorizontalPercentBarSeries, QBarCategoryAxis -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPainter + +try: + from PyQt5.QtChart import QChartView, QChart, QBarSet, QHorizontalPercentBarSeries, QBarCategoryAxis + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPainter +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPainter + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QBarSet = QtCharts.QBarSet + QHorizontalPercentBarSeries = QtCharts.QHorizontalPercentBarSeries + QBarCategoryAxis = QtCharts.QBarCategoryAxis class Window(QChartView): diff --git a/QtChart/LineChart.py b/QtChart/LineChart.py index aa2709c..9386a99 100644 --- a/QtChart/LineChart.py +++ b/QtChart/LineChart.py @@ -1,27 +1,33 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月19日 -@author: Irony."[讽刺] -@site: http://alyl.vip, http://orzorz.vip, http://coding.net/u/892768447, http://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: LineChart @description: -''' +""" import sys -from PyQt5.QtChart import QChartView, QLineSeries, QChart -from PyQt5.QtGui import QPainter -from PyQt5.QtWidgets import QApplication +try: + from PyQt5.QtChart import QChartView, QLineSeries, QChart + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts -__version__ = "0.0.1" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries - -if __name__ == "__main__": +if __name__ == '__main__': app = QApplication(sys.argv) chart = QChart() - chart.setTitle("Line Chart 1") + chart.setTitle('Line Chart 1') series = QLineSeries(chart) series.append(0, 6) series.append(2, 4) diff --git a/QtChart/LineStack.py b/QtChart/LineStack.py index 7a06c81..fb03eaf 100644 --- a/QtChart/LineStack.py +++ b/QtChart/LineStack.py @@ -1,27 +1,36 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: charts.line.LineStack @description: like http://echarts.baidu.com/demo.html#line-stack -''' +""" import sys -from PyQt5.QtChart import QChartView, QChart, QLineSeries, QLegend, \ - QCategoryAxis -from PyQt5.QtCore import Qt, QPointF, QRectF, QPoint -from PyQt5.QtGui import QPainter, QPen -from PyQt5.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ - QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget +try: + from PyQt5.QtChart import QChartView, QChart, QLineSeries, QLegend, \ + QCategoryAxis + from PyQt5.QtCore import Qt, QPointF, QRectF, QPoint + from PyQt5.QtGui import QPainter, QPen + from PyQt5.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ + QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget +except ImportError: + from PySide2.QtCore import Qt, QPointF, QRectF, QPoint + from PySide2.QtGui import QPainter, QPen + from PySide2.QtWidgets import QApplication, QGraphicsLineItem, QWidget, \ + QHBoxLayout, QLabel, QVBoxLayout, QGraphicsProxyWidget + from PySide2.QtCharts import QtCharts -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries + QLegend = QtCharts.QLegend + QCategoryAxis = QtCharts.QCategoryAxis class ToolTipItem(QWidget): @@ -44,7 +53,6 @@ class ToolTipItem(QWidget): class ToolTipWidget(QWidget): - Cache = {} def __init__(self, *args, **kwargs): @@ -130,7 +138,7 @@ class ChartView(QChartView): self.point_bottom = self._chart.mapToPosition( QPointF(self.min_x, self.min_y)) self.step_x = (self.max_x - self.min_x) / \ - (self._chart.axisX().tickCount() - 1) + (self._chart.axisX().tickCount() - 1) def mouseMoveEvent(self, event): super(ChartView, self).mouseMoveEvent(event) @@ -158,10 +166,10 @@ class ChartView(QChartView): t_height = self.toolTipWidget.height() # 如果鼠标位置离右侧的距离小于tip宽度 x = pos.x() - t_width if self.width() - \ - pos.x() - 20 < t_width else pos.x() + pos.x() - 20 < t_width else pos.x() # 如果鼠标位置离底部的高度小于tip高度 y = pos.y() - t_height if self.height() - \ - pos.y() - 20 < t_height else pos.y() + pos.y() - 20 < t_height else pos.y() self.toolTipWidget.show( title, points, QPoint(x, y)) else: @@ -173,7 +181,7 @@ class ChartView(QChartView): if not marker: return visible = not marker.series().isVisible() -# # 隐藏或显示series + # # 隐藏或显示series marker.series().setVisible(visible) marker.setVisible(True) # 要保证marker一直显示 # 透明度 diff --git a/QtChart/PercentBarChart.py b/QtChart/PercentBarChart.py index 1cd4d06..dcbf883 100644 --- a/QtChart/PercentBarChart.py +++ b/QtChart/PercentBarChart.py @@ -4,14 +4,28 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PercentBarChart @description: 百分比柱状图表 """ -from PyQt5.QtChart import QChartView, QChart, QBarSet, QPercentBarSeries, QBarCategoryAxis -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPainter + +try: + from PyQt5.QtChart import QChartView, QChart, QBarSet, QPercentBarSeries, QBarCategoryAxis + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QBarSet = QtCharts.QBarSet + QPercentBarSeries = QtCharts.QPercentBarSeries + QBarCategoryAxis = QtCharts.QBarCategoryAxis class Window(QChartView): @@ -72,7 +86,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/PieChart.py b/QtChart/PieChart.py index f3bb7a0..57fa5bd 100644 --- a/QtChart/PieChart.py +++ b/QtChart/PieChart.py @@ -4,13 +4,24 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: PieChart @description: 饼状图表 """ -from PyQt5.QtChart import QChartView, QChart, QPieSeries -from PyQt5.QtGui import QPainter, QColor + +try: + from PyQt5.QtChart import QChartView, QChart, QPieSeries + from PyQt5.QtGui import QPainter, QColor + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtGui import QPainter, QColor + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QPieSeries = QtCharts.QPieSeries class Window(QChartView): @@ -47,7 +58,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/ScatterChart.py b/QtChart/ScatterChart.py index e6d7b0a..d523e83 100644 --- a/QtChart/ScatterChart.py +++ b/QtChart/ScatterChart.py @@ -4,16 +4,27 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScatterChart @description: 散点图表 """ import random -from PyQt5.QtChart import QChartView, QChart, QScatterSeries -from PyQt5.QtCore import QPointF -from PyQt5.QtGui import QPainter +try: + from PyQt5.QtChart import QChartView, QChart, QScatterSeries + from PyQt5.QtCore import QPointF + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QPointF + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QScatterSeries = QtCharts.QScatterSeries class Window(QChartView): @@ -70,7 +81,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/SplineChart.py b/QtChart/SplineChart.py index 69a5436..9fe2eaf 100644 --- a/QtChart/SplineChart.py +++ b/QtChart/SplineChart.py @@ -4,14 +4,26 @@ """ Created on 2019/10/2 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: SplineChart @description: 样条图表 """ -from PyQt5.QtChart import QChartView, QChart, QSplineSeries -from PyQt5.QtCore import QPointF -from PyQt5.QtGui import QPainter + +try: + from PyQt5.QtChart import QChartView, QChart, QSplineSeries + from PyQt5.QtCore import QPointF + from PyQt5.QtGui import QPainter + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QPointF + from PySide2.QtGui import QPainter + from PySide2.QtWidgets import QApplication + from PySide2.QtCharts import QtCharts + + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QSplineSeries = QtCharts.QSplineSeries class Window(QChartView): @@ -49,7 +61,6 @@ class Window(QChartView): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = Window() diff --git a/QtChart/ToolTip.py b/QtChart/ToolTip.py index dc34a59..397254b 100644 --- a/QtChart/ToolTip.py +++ b/QtChart/ToolTip.py @@ -1,27 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月23日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ToolTip @description: -''' +""" import sys -from PyQt5.QtChart import QChartView, QChart, QLineSeries -from PyQt5.QtCore import Qt, QRectF, QPoint, QPointF -from PyQt5.QtGui import QPainter, QCursor -from PyQt5.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ - QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem +try: + from PyQt5.QtChart import QChartView, QChart, QLineSeries + from PyQt5.QtCore import Qt, QRectF, QPoint, QPointF + from PyQt5.QtGui import QPainter, QCursor + from PyQt5.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ + QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem +except ImportError: + from PySide2.QtCore import Qt, QRectF, QPoint, QPointF + from PySide2.QtGui import QPainter, QCursor + from PySide2.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ + QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem + from PySide2.QtCharts import QtCharts -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries -''' +""" class CircleWidget(QGraphicsProxyWidget): def __init__(self, color, *args, **kwargs): @@ -57,7 +64,7 @@ class GraphicsWidget(QGraphicsWidget): self.setGeometry(pos.x(), pos.y(), self.size().width(), self.size().height()) super(GraphicsWidget, self).show() -''' +""" class ToolTipItem(QWidget): @@ -161,7 +168,8 @@ class ChartView(QChartView): # print(x, pos_x, index, index * self.step_x + self.min_x) # 得到在坐标系中的所有series的类型和点 points = [(serie, serie.at(index)) - for serie in self._chart.series() if self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y] + for serie in self._chart.series() if + self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y] if points: # 永远在轴上的黑线条 self.lineItem.setLine(pos_x.x(), self.point_top.y(), diff --git a/QtChart/ToolTip2.py b/QtChart/ToolTip2.py index 349473e..3a8ca3d 100644 --- a/QtChart/ToolTip2.py +++ b/QtChart/ToolTip2.py @@ -1,27 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月23日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ToolTip2 @description: -''' +""" import sys -from PyQt5.QtChart import QChartView, QChart, QLineSeries -from PyQt5.QtCore import Qt, QRectF, QPoint, QPointF -from PyQt5.QtGui import QPainter, QCursor -from PyQt5.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ - QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem +try: + from PyQt5.QtChart import QChartView, QChart, QLineSeries + from PyQt5.QtCore import Qt, QRectF, QPoint, QPointF + from PyQt5.QtGui import QPainter, QCursor + from PyQt5.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ + QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem +except ImportError: + from PySide2.QtCore import Qt, QRectF, QPoint, QPointF + from PySide2.QtGui import QPainter, QCursor + from PySide2.QtWidgets import QApplication, QGraphicsProxyWidget, QLabel, \ + QWidget, QHBoxLayout, QVBoxLayout, QToolTip, QGraphicsLineItem + from PySide2.QtCharts import QtCharts -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" + QChartView = QtCharts.QChartView + QChart = QtCharts.QChart + QLineSeries = QtCharts.QLineSeries -''' +""" class CircleWidget(QGraphicsProxyWidget): def __init__(self, color, *args, **kwargs): @@ -57,7 +64,7 @@ class GraphicsWidget(QGraphicsWidget): self.setGeometry(pos.x(), pos.y(), self.size().width(), self.size().height()) super(GraphicsWidget, self).show() -''' +""" class ToolTipItem(QWidget): @@ -159,7 +166,8 @@ class ChartView(QChartView): # print(x, pos_x, index, index * self.step_x + self.min_x) # 得到在坐标系中的所有series的类型和点 points = [(serie, serie.at(index)) - for serie in self._chart.series() if self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y] + for serie in self._chart.series() if + self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y] if points: # 跟随鼠标的黑线条 self.lineItem.setLine(event.pos().x(), self.point_top.y(), diff --git a/QtDataVisualization/BarsVisualization.py b/QtDataVisualization/BarsVisualization.py index 6808b09..7fe583d 100644 --- a/QtDataVisualization/BarsVisualization.py +++ b/QtDataVisualization/BarsVisualization.py @@ -4,7 +4,7 @@ """ Created on 2019/10/4 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: BarsVisualization @description: 柱状图 diff --git a/QtDataVisualization/MagneticOfSun.py b/QtDataVisualization/MagneticOfSun.py index d4562f5..da9fa0d 100644 --- a/QtDataVisualization/MagneticOfSun.py +++ b/QtDataVisualization/MagneticOfSun.py @@ -4,7 +4,7 @@ """ Created on 2019/10/4 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: MagneticOfSun @description: diff --git a/QtDataVisualization/ScatterVisualization.py b/QtDataVisualization/ScatterVisualization.py index eff7fe0..69eeeb8 100644 --- a/QtDataVisualization/ScatterVisualization.py +++ b/QtDataVisualization/ScatterVisualization.py @@ -4,7 +4,7 @@ """ Created on 2019/10/4 @author: Irony -@site: https://pyqt5.com , https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ScatterVisualization @description: diff --git a/QtQuick/FlatStyle.py b/QtQuick/FlatStyle.py index c4e42b9..e11e984 100644 --- a/QtQuick/FlatStyle.py +++ b/QtQuick/FlatStyle.py @@ -4,7 +4,7 @@ """ Created on 2019年2月2日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtQuick.FlatStyle @description: @@ -12,14 +12,14 @@ Created on 2019年2月2日 import os import sys -from PyQt5.QtCore import QCoreApplication, Qt, QUrl -from PyQt5.QtQml import QQmlApplicationEngine -from PyQt5.QtWidgets import QApplication, QMessageBox - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' - +try: + from PyQt5.QtCore import QCoreApplication, Qt, QUrl + from PyQt5.QtQml import QQmlApplicationEngine + from PyQt5.QtWidgets import QApplication, QMessageBox +except ImportError: + from PySide2.QtCore import QCoreApplication, Qt, QUrl + from PySide2.QtQml import QQmlApplicationEngine + from PySide2.QtWidgets import QApplication, QMessageBox if __name__ == '__main__': try: @@ -32,7 +32,8 @@ if __name__ == '__main__': app = QApplication(sys.argv) engine = QQmlApplicationEngine() engine.objectCreated.connect( - lambda obj, _: (QMessageBox.critical(None, '错误', '运行失败,可能是当前PyQt版本不支持'), engine.quit) if not obj else 0) + lambda obj, _: ( + QMessageBox.critical(None, '错误', '运行失败,可能是当前PyQt版本不支持'), engine.quit) if not obj else 0) engine.addImportPath('imports') engine.load(QUrl('flatstyle.qml')) diff --git a/QtQuick/Signals.py b/QtQuick/Signals.py index 3ea5b81..7735c94 100644 --- a/QtQuick/Signals.py +++ b/QtQuick/Signals.py @@ -4,23 +4,25 @@ """ Created on 2019年9月18日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtQuick.Signals @description: 信号槽 """ -from time import time import sys +from time import time -from PyQt5.QtCore import QCoreApplication, Qt, pyqtSlot, pyqtSignal, QTimer -from PyQt5.QtQml import QQmlApplicationEngine -from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget, QVBoxLayout,\ - QPushButton, QTextBrowser - - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019' +try: + from PyQt5.QtCore import QCoreApplication, Qt, pyqtSlot, pyqtSignal, QTimer + from PyQt5.QtQml import QQmlApplicationEngine + from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget, QVBoxLayout, \ + QPushButton, QTextBrowser +except ImportError: + from PySide2.QtCore import QCoreApplication, Qt, Slot as pyqtSlot, Signal as pyqtSignal, QTimer + from PySide2.QtQml import QQmlApplicationEngine + from PySide2.QtWidgets import QApplication, QMessageBox, QWidget, QVBoxLayout, \ + QPushButton, QTextBrowser QML = """import QtQuick 2.0 import QtQuick.Controls 1.6 @@ -84,7 +86,6 @@ ApplicationWindow { class Window(QWidget): - # 定义一个时间信号 timerSignal = pyqtSignal(str) diff --git a/QtRemoteObjects/SyncUi/ClipboardMaster.py b/QtRemoteObjects/SyncUi/ClipboardMaster.py index b91d5f5..50aea69 100644 --- a/QtRemoteObjects/SyncUi/ClipboardMaster.py +++ b/QtRemoteObjects/SyncUi/ClipboardMaster.py @@ -4,21 +4,17 @@ """ Created on 2020/7/31 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ClipboardMaster @description: """ +import sys + from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal, QLoggingCategory, QVariant, QMimeData from PyQt5.QtRemoteObjects import QRemoteObjectHost from PyQt5.QtWidgets import QTextBrowser -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - -import sys - class WindowMaster(QTextBrowser): SignalUpdateMimeData = pyqtSignal( @@ -93,7 +89,7 @@ class WindowMaster(QTextBrowser): if __name__ == '__main__': import cgitb - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') from PyQt5.QtWidgets import QApplication QLoggingCategory.setFilterRules('qt.remoteobjects.debug=true\n' diff --git a/QtRemoteObjects/SyncUi/ClipboardSlave.py b/QtRemoteObjects/SyncUi/ClipboardSlave.py index 8fea8ab..2e271b1 100644 --- a/QtRemoteObjects/SyncUi/ClipboardSlave.py +++ b/QtRemoteObjects/SyncUi/ClipboardSlave.py @@ -4,7 +4,7 @@ """ Created on 2020/7/31 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ClipboardSlave @description: @@ -13,10 +13,6 @@ from PyQt5.QtCore import QUrl, pyqtSignal, QVariant, QMimeData from PyQt5.QtRemoteObjects import QRemoteObjectNode, QRemoteObjectReplica from PyQt5.QtWidgets import QTextBrowser -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - class WindowSlave(QTextBrowser): SignalUpdateMimeData = pyqtSignal( @@ -98,7 +94,7 @@ if __name__ == '__main__': import sys import cgitb - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) diff --git a/QtRemoteObjects/SyncUi/WindowMaster.py b/QtRemoteObjects/SyncUi/WindowMaster.py index 22ba0bc..d93e656 100644 --- a/QtRemoteObjects/SyncUi/WindowMaster.py +++ b/QtRemoteObjects/SyncUi/WindowMaster.py @@ -4,24 +4,18 @@ """ Created on 2019年8月7日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtRemoteObjects.SyncUi.WindowMaster @description: 主窗口 """ from PyQt5.QtCore import QUrl, QTimer, pyqtSignal, pyqtSlot from PyQt5.QtRemoteObjects import QRemoteObjectHost -from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout, QCheckBox,\ +from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout, QCheckBox, \ QProgressBar -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - - class WindowMaster(QWidget): - # 输入框内容变化信号 editValueChanged = pyqtSignal(str) # 勾选框变化信号 @@ -84,6 +78,7 @@ class WindowMaster(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = WindowMaster() w.show() diff --git a/QtRemoteObjects/SyncUi/WindowSlave.py b/QtRemoteObjects/SyncUi/WindowSlave.py index 44cfc14..dc3ea26 100644 --- a/QtRemoteObjects/SyncUi/WindowSlave.py +++ b/QtRemoteObjects/SyncUi/WindowSlave.py @@ -4,22 +4,17 @@ """ Created on 2019年8月7日 @author: Irony -@site: https://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: QtRemoteObjects.SyncUi.WindowSlave @description: 备窗口 """ from PyQt5.QtCore import QUrl from PyQt5.QtRemoteObjects import QRemoteObjectNode, QRemoteObjectReplica -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLineEdit, QCheckBox,\ +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLineEdit, QCheckBox, \ QProgressBar, QMessageBox -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2019 Irony' -__Version__ = 1.0 - - class WindowSlave(QWidget): def __init__(self, *args, **kwargs): @@ -65,13 +60,14 @@ class WindowSlave(QWidget): # Master进度条同步到Slave self.windowMaster.progressValueChanged.connect( self.progressBar.setValue) - + print('绑定信号槽完成') if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = WindowSlave() w.show() diff --git a/QtRemoteObjects/modelview/modelviewclient.py b/QtRemoteObjects/modelview/modelviewclient.py index 3ae7e6a..1dd65f9 100644 --- a/QtRemoteObjects/modelview/modelviewclient.py +++ b/QtRemoteObjects/modelview/modelviewclient.py @@ -52,15 +52,22 @@ import sys -from PyQt5.QtCore import QLoggingCategory, QUrl -from PyQt5.QtRemoteObjects import QRemoteObjectNode -from PyQt5.QtWidgets import QApplication, QTreeView +try: + from PyQt5.QtCore import QLoggingCategory, QUrl + from PyQt5.QtRemoteObjects import QRemoteObjectNode + from PyQt5.QtWidgets import QApplication, QTreeView +except ImportError: + from PySide2.QtCore import QUrl + from PySide2.QtRemoteObjects import QRemoteObjectNode + from PySide2.QtWidgets import QApplication, QTreeView - -QLoggingCategory.setFilterRules('qt.remoteobjects.debug=false\n' - 'qt.remoteobjects.warning=false\n' - 'qt.remoteobjects.models.debug=false\n' - 'qt.remoteobjects.models.debug=false') +try: + QLoggingCategory.setFilterRules('qt.remoteobjects.debug=false\n' + 'qt.remoteobjects.warning=false\n' + 'qt.remoteobjects.models.debug=false\n' + 'qt.remoteobjects.models.debug=false') +except NameError: + pass app = QApplication(sys.argv) @@ -73,6 +80,6 @@ view.resize(640, 480) model = node.acquireModel('RemoteModel') view.setModel(model) -view.show(); +view.show() sys.exit(app.exec_()) diff --git a/QtRemoteObjects/modelview/modelviewserver.py b/QtRemoteObjects/modelview/modelviewserver.py index 34cf04c..e2af99c 100644 --- a/QtRemoteObjects/modelview/modelviewserver.py +++ b/QtRemoteObjects/modelview/modelviewserver.py @@ -53,11 +53,16 @@ import sys -from PyQt5.QtCore import (pyqtSlot, QLoggingCategory, QModelIndex, QObject, Qt, - QTimer, QUrl) -from PyQt5.QtGui import QColor, QStandardItem, QStandardItemModel -from PyQt5.QtRemoteObjects import QRemoteObjectHost, QRemoteObjectRegistryHost -from PyQt5.QtWidgets import QApplication, QTreeView +try: + from PyQt5.QtCore import pyqtSlot, QLoggingCategory, QModelIndex, QObject, Qt, QTimer, QUrl + from PyQt5.QtGui import QColor, QStandardItem, QStandardItemModel + from PyQt5.QtRemoteObjects import QRemoteObjectHost, QRemoteObjectRegistryHost + from PyQt5.QtWidgets import QApplication, QTreeView +except ImportError: + from PySide2.QtCore import Slot as pyqtSlot, QModelIndex, QObject, Qt, QTimer, QUrl + from PySide2.QtGui import QColor, QStandardItem, QStandardItemModel + from PySide2.QtRemoteObjects import QRemoteObjectHost, QRemoteObjectRegistryHost + from PySide2.QtWidgets import QApplication, QTreeView class TimerHandler(QObject): @@ -71,7 +76,7 @@ class TimerHandler(QObject): def changeData(self): for i in range(10, 50): self._model.setData(self._model.index(i, 1), QColor(Qt.blue), - Qt.BackgroundRole) + Qt.BackgroundRole) @pyqtSlot() def insertData(self): @@ -79,9 +84,9 @@ class TimerHandler(QObject): for i in range(2, 11): self._model.setData(self._model.index(i, 1), QColor(Qt.green), - Qt.BackgroundRole) + Qt.BackgroundRole) self._model.setData(self._model.index(i, 1), "InsertedRow", - Qt.DisplayRole) + Qt.DisplayRole) @pyqtSlot() def removeData(self): @@ -108,7 +113,7 @@ def addChild(numChildren, nestingLevel): for i in range(numChildren): child = QStandardItem( - "Child num {}, nesting level {}".format(i + 1, nestingLevel)) + "Child num {}, nesting level {}".format(i + 1, nestingLevel)) if i == 0: child.appendRow(addChild(numChildren, nestingLevel - 1)) @@ -120,14 +125,17 @@ def addChild(numChildren, nestingLevel): if __name__ == '__main__': - QLoggingCategory.setFilterRules('qt.remoteobjects.debug=false\n' - 'qt.remoteobjects.warning=false') + try: + QLoggingCategory.setFilterRules('qt.remoteobjects.debug=false\n' + 'qt.remoteobjects.warning=false') + except NameError: + pass app = QApplication(sys.argv) sourceModel = QStandardItemModel() sourceModel.setHorizontalHeaderLabels( - ["First Column with spacing", "Second Column with spacing"]) + ["First Column with spacing", "Second Column with spacing"]) for i in range(10000): firstItem = QStandardItem("FancyTextNumber {}".format(i)) diff --git a/QtRemoteObjects/simpleswitch/directconnectdynamicclient.py b/QtRemoteObjects/simpleswitch/directconnectdynamicclient.py index 27fcb9f..abee848 100644 --- a/QtRemoteObjects/simpleswitch/directconnectdynamicclient.py +++ b/QtRemoteObjects/simpleswitch/directconnectdynamicclient.py @@ -58,7 +58,6 @@ from PyQt5.QtRemoteObjects import QRemoteObjectNode class DynamicClient(QObject): - # This signal is connected with server_slot() slot of the source object and # echoes back the switch state received from the source. echoSwitchState = pyqtSignal(bool) @@ -92,7 +91,6 @@ class DynamicClient(QObject): if __name__ == '__main__': - app = QCoreApplication(sys.argv) # Create the remote object node. diff --git a/QtRemoteObjects/simpleswitch/directconnectdynamicserver.py b/QtRemoteObjects/simpleswitch/directconnectdynamicserver.py index b7b0d05..256d63b 100644 --- a/QtRemoteObjects/simpleswitch/directconnectdynamicserver.py +++ b/QtRemoteObjects/simpleswitch/directconnectdynamicserver.py @@ -54,7 +54,7 @@ import sys from PyQt5.QtCore import (pyqtProperty, pyqtSignal, pyqtSlot, QCoreApplication, - QObject, QTimer, QUrl) + QObject, QTimer, QUrl) from PyQt5.QtRemoteObjects import QRemoteObjectHost @@ -98,7 +98,7 @@ class SimpleSwitch(QObject): # The property exposed to a remote client. currState = pyqtProperty(bool, fget=_get_currState, fset=_set_currState, - notify=currStateChanged) + notify=currStateChanged) # The slot exposed to a remote client. @pyqtSlot(bool) @@ -115,7 +115,6 @@ class SimpleSwitch(QObject): if __name__ == '__main__': - app = QCoreApplication(sys.argv) # Create the simple switch. diff --git a/QtRemoteObjects/simpleswitch/registryconnecteddynamicclient.py b/QtRemoteObjects/simpleswitch/registryconnecteddynamicclient.py index f836878..56b1d38 100644 --- a/QtRemoteObjects/simpleswitch/registryconnecteddynamicclient.py +++ b/QtRemoteObjects/simpleswitch/registryconnecteddynamicclient.py @@ -58,7 +58,6 @@ from PyQt5.QtRemoteObjects import QRemoteObjectNode class DynamicClient(QObject): - # This signal is connected with server_slot() slot of the source object and # echoes back the switch state received from the source. echoSwitchState = pyqtSignal(bool) @@ -92,7 +91,6 @@ class DynamicClient(QObject): if __name__ == '__main__': - app = QCoreApplication(sys.argv) # Create the remote object node. diff --git a/QtRemoteObjects/simpleswitch/registryconnecteddynamicserver.py b/QtRemoteObjects/simpleswitch/registryconnecteddynamicserver.py index 7745f94..c7760b4 100644 --- a/QtRemoteObjects/simpleswitch/registryconnecteddynamicserver.py +++ b/QtRemoteObjects/simpleswitch/registryconnecteddynamicserver.py @@ -54,7 +54,7 @@ import sys from PyQt5.QtCore import (pyqtProperty, pyqtSignal, pyqtSlot, QCoreApplication, - QObject, QTimer, QUrl) + QObject, QTimer, QUrl) from PyQt5.QtRemoteObjects import QRemoteObjectHost, QRemoteObjectRegistryHost @@ -98,7 +98,7 @@ class SimpleSwitch(QObject): # The property exposed to a remote client. currState = pyqtProperty(bool, fget=_get_currState, fset=_set_currState, - notify=currStateChanged) + notify=currStateChanged) # The slot exposed to a remote client. @pyqtSlot(bool) @@ -115,7 +115,6 @@ class SimpleSwitch(QObject): if __name__ == '__main__': - app = QCoreApplication(sys.argv) # Create the simple switch. diff --git a/QtWinExtras/TaskbarProgress.py b/QtWinExtras/TaskbarProgress.py index 56f151b..96b3a0a 100644 --- a/QtWinExtras/TaskbarProgress.py +++ b/QtWinExtras/TaskbarProgress.py @@ -4,22 +4,23 @@ """ Created on 2020/7/1 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: TaskbarProgress @description: """ -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' - import cgitb import sys -from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QWidget, QApplication, QGridLayout, QSpinBox, QPushButton, QLabel -from PyQt5.QtWinExtras import QWinTaskbarButton +try: + from PyQt5.QtCore import QTimer + from PyQt5.QtWidgets import QWidget, QApplication, QGridLayout, QSpinBox, QPushButton, QLabel + from PyQt5.QtWinExtras import QWinTaskbarButton +except ImportError: + from PySide2.QtCore import QTimer + from PySide2.QtWidgets import QWidget, QApplication, QGridLayout, QSpinBox, QPushButton, QLabel + from PySide2.QtWinExtras import QWinTaskbarButton class Window(QWidget): @@ -165,7 +166,7 @@ class Window(QWidget): if __name__ == '__main__': - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/QtWinExtras/ThumbnailToolBar.py b/QtWinExtras/ThumbnailToolBar.py index e2c0714..8aab7b7 100644 --- a/QtWinExtras/ThumbnailToolBar.py +++ b/QtWinExtras/ThumbnailToolBar.py @@ -4,21 +4,21 @@ """ Created on 2020/7/3 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ThumbnailToolBar @description: """ -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' - import cgitb import sys -from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QStyle, QVBoxLayout -from PyQt5.QtWinExtras import QWinThumbnailToolBar, QWinThumbnailToolButton +try: + from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QStyle, QVBoxLayout + from PyQt5.QtWinExtras import QWinThumbnailToolBar, QWinThumbnailToolButton +except ImportError: + from PySide2.QtWidgets import QWidget, QApplication, QLabel, QStyle, QVBoxLayout + from PySide2.QtWinExtras import QWinThumbnailToolBar, QWinThumbnailToolButton class Window(QWidget): @@ -86,7 +86,7 @@ class Window(QWidget): if __name__ == '__main__': - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) w = Window() w.show() diff --git a/Test/ButtomZoom.py b/Test/ButtomZoom.py index 0a2b482..ab61e77 100644 --- a/Test/ButtomZoom.py +++ b/Test/ButtomZoom.py @@ -4,21 +4,17 @@ """ Created on 2018年10月30日 @author: Irony -@site: http://pyqt5.com https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ButtomZoom @description: """ -from PyQt5.QtCore import QPropertyAnimation, QRect -from PyQt5.QtWidgets import QPushButton, QWidget, QHBoxLayout, QSpacerItem,\ - QSizePolicy - - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import QPropertyAnimation, QRect + from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout, QSpacerItem, QSizePolicy +except ImportError: + from PySide2.QtCore import QPropertyAnimation, QRect + from PySide2.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout, QSpacerItem, QSizePolicy class ZoomButton(QPushButton): @@ -70,11 +66,11 @@ class ZoomButton(QPushButton): super(ZoomButton, self).mousePressEvent(event) -class TestWindow(QWidget): +class Window(QWidget): # 测试窗口 def __init__(self, *args, **kwargs): - super(TestWindow, self).__init__(*args, **kwargs) + super(Window, self).__init__(*args, **kwargs) # 1. 加入布局中 layout = QHBoxLayout(self) layout.addSpacerItem(QSpacerItem( @@ -89,7 +85,7 @@ class TestWindow(QWidget): # 以下两个方法需要重写 def showEvent(self, event): - super(TestWindow, self).showEvent(event) + super(Window, self).showEvent(event) # 更新按钮的位置 self.button1.updatePos() # 针对不在控件中的按钮 @@ -98,7 +94,7 @@ class TestWindow(QWidget): self.button2.updatePos() def resizeEvent(self, event): - super(TestWindow, self).resizeEvent(event) + super(Window, self).resizeEvent(event) # 更新按钮的位置 self.button1.updatePos() # 针对不在控件中的按钮 @@ -109,7 +105,7 @@ class TestWindow(QWidget): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) app.setStyleSheet("""QPushButton { border: none; @@ -120,6 +116,6 @@ if __name__ == '__main__': min-height: 40px; background-color: white; }""") - w = TestWindow() + w = Window() w.show() sys.exit(app.exec_()) diff --git a/Test/C++中修改PyQt对象/Test.py b/Test/C++中修改PyQt对象/Test.py index f8be27f..1431c2f 100644 --- a/Test/C++中修改PyQt对象/Test.py +++ b/Test/C++中修改PyQt对象/Test.py @@ -1,33 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2020年3月2日 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: @description: 冷色调 -''' +""" import sys from ctypes import CDLL from time import time -# For PyQt5 try: - from PyQt5 import sip -except: - import sip -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QImage, QPixmap -from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout - -# For PySide2 -# import shiboken2 -# from PySide2.QtCore import Qt -# from PySide2.QtGui import QImage, QPixmap -# from PySide2.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout + # For PyQt5 + try: + from PyQt5 import sip + except ImportError: + import sip + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QImage, QPixmap + from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout +except ImportError: + # For PySide2 + import shiboken2 + from PySide2.QtCore import Qt + from PySide2.QtGui import QImage, QPixmap + from PySide2.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout class Window(QWidget): @@ -52,10 +53,12 @@ class Window(QWidget): def doChange(self, value): t = time() img = self.srcImg.copy() # 复制一份 - # For PyQt5 - self.dll.cold(sip.unwrapinstance(img), value) - # For PySide2 - # self.dll.cold(shiboken2.getCppPointer(img)[0], value) + if 'sip' in sys.modules: + # For PyQt5 + self.dll.cold(sip.unwrapinstance(img), value) + elif 'shiboken2' in sys.modules: + # For PySide2 + self.dll.cold(shiboken2.getCppPointer(img)[0], value) self.imgLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(800, Qt.SmoothTransformation)) print('use time:', time() - t) diff --git a/Test/C++中修改PyQt对象/src.jpg b/Test/C++中修改PyQt对象/src.jpg new file mode 100644 index 0000000..c455f6a Binary files /dev/null and b/Test/C++中修改PyQt对象/src.jpg differ diff --git a/Test/ChartView/ChartView.py b/Test/ChartView/ChartView.py index a23d749..2880867 100644 --- a/Test/ChartView/ChartView.py +++ b/Test/ChartView/ChartView.py @@ -1,24 +1,21 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月18日 -@author: Irony."[讽刺] -@site: http://alyl.vip, http://orzorz.vip, http://coding.net/u/892768447, http://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ChartView @description: -''' +""" import json import os +import chardet from PyQt5.QtChart import QChart, QChartView, QLineSeries, QCategoryAxis from PyQt5.QtCore import QMargins, Qt, QEasingCurve from PyQt5.QtGui import QColor, QBrush, QFont, QPainter, QPen, QPixmap -import chardet - - -__version__ = "0.0.1" # QEasingCurve 类型枚举 EasingCurve = dict( @@ -55,8 +52,8 @@ class ChartView(QChartView): data = data.decode(encoding.get("encoding") or "utf-8") self.__analysis(json.loads(data)) -# def onSeriesHoverd(self, point, state): -# print(point, state) + # def onSeriesHoverd(self, point, state): + # print(point, state) def mouseMoveEvent(self, event): super(ChartView, self).mouseMoveEvent(event) @@ -89,8 +86,8 @@ class ChartView(QChartView): return QColor(color) def __getPen(self, pen=None, default=QPen( - Qt.white, 1, Qt.SolidLine, - Qt.SquareCap, Qt.BevelJoin)): + Qt.white, 1, Qt.SolidLine, + Qt.SquareCap, Qt.BevelJoin)): ''' :param pen: pen json ''' @@ -112,13 +109,14 @@ class ChartView(QChartView): return getattr(Qt, "Align" + alignment.capitalize()) except: return Qt.AlignTop -# if alignment == "left": -# return Qt.AlignLeft -# if alignment == "right": -# return Qt.AlignRight -# if alignment == "bottom": -# return Qt.AlignBottom -# return Qt.AlignTop + + # if alignment == "left": + # return Qt.AlignLeft + # if alignment == "right": + # return Qt.AlignRight + # if alignment == "bottom": + # return Qt.AlignBottom + # return Qt.AlignTop def __setTitle(self, title=None): ''' diff --git a/Test/ChartView/ChatWidget.py b/Test/ChartView/ChatWidget.py index fedfa9c..a5f6622 100644 --- a/Test/ChartView/ChatWidget.py +++ b/Test/ChartView/ChatWidget.py @@ -1,33 +1,30 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月20日 -@author: Irony."[讽刺] -@site: http://alyl.vip, http://orzorz.vip, http://coding.net/u/892768447, http://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ChatWidget @description: -''' -from collections import OrderedDict +""" import json import os import sys +from collections import OrderedDict +import chardet from PyQt5.Qsci import QsciScintilla, QsciLexerJSON from PyQt5.QtChart import QChartView from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtGui import QColor, QFont, QFontMetrics, QKeySequence, QMovie -from PyQt5.QtWidgets import QSplitter, QTreeWidget, QApplication, QWidget,\ +from PyQt5.QtWidgets import QSplitter, QTreeWidget, QApplication, QWidget, \ QVBoxLayout, QPushButton, QTreeWidgetItem, QMessageBox, QShortcut, QLabel -import chardet from ChartView import ChartView # @UnresolvedImport -__version__ = "0.0.1" - - class LoadingWidget(QLabel): def __init__(self, *args, **kwargs): @@ -54,7 +51,6 @@ class LoadingWidget(QLabel): class ClassifyWidget(QTreeWidget): - fileSelected = pyqtSignal(str) def __init__(self, *args, **kwargs): @@ -135,7 +131,6 @@ class CodeScintilla(QsciScintilla): class CodeWidget(QWidget): - runSignal = pyqtSignal(str) def __init__(self, *args, **kwargs): diff --git a/Test/ColumnView.py b/Test/ColumnView.py index 5ce9859..da5e374 100644 --- a/Test/ColumnView.py +++ b/Test/ColumnView.py @@ -4,17 +4,18 @@ """ Created on 2020/9/14 @author: Irony -@site: https://pyqt.site https://github.com/PyQt5 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: ColumnView @description: """ -from PyQt5.QtWidgets import QComboBox, QFileSystemModel, QHBoxLayout, QSpacerItem, QSizePolicy - -__Author__ = 'Irony' -__Copyright__ = 'Copyright (c) 2020' -__Version__ = 'Version 1.0' +try: + from PyQt5.QtWidgets import QApplication, QComboBox, QFileSystemModel, QHBoxLayout, QSpacerItem, \ + QSizePolicy +except ImportError: + from PyQt5.QtWidgets import QApplication, QComboBox, QFileSystemModel, QHBoxLayout, QSpacerItem, \ + QSizePolicy class PathComboBox(QComboBox): @@ -34,12 +35,11 @@ class PathComboBox(QComboBox): self.setModel(self.f_model) def addWidget(self, widget): - self.layout().insertWidget(self.layout().count()-1, widget) + self.layout().insertWidget(self.layout().count() - 1, widget) if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) w = PathComboBox() diff --git a/Test/C和C++扩展/pydext/.vs/pydext/v15/.suo b/Test/C和C++扩展/pydext/.vs/pydext/v15/.suo deleted file mode 100644 index 9fa5922..0000000 Binary files a/Test/C和C++扩展/pydext/.vs/pydext/v15/.suo and /dev/null differ diff --git a/Test/C和C++扩展/pydext/.vs/pydext/v15/Browse.VC.db b/Test/C和C++扩展/pydext/.vs/pydext/v15/Browse.VC.db deleted file mode 100644 index 0839577..0000000 Binary files a/Test/C和C++扩展/pydext/.vs/pydext/v15/Browse.VC.db and /dev/null differ diff --git a/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/7828e06aa30c0d3c/PYDEXT.ipch b/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/7828e06aa30c0d3c/PYDEXT.ipch deleted file mode 100644 index b59817e..0000000 Binary files a/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/7828e06aa30c0d3c/PYDEXT.ipch and /dev/null differ diff --git a/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/d5916c660b4c4bac/PYDEXT.ipch b/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/d5916c660b4c4bac/PYDEXT.ipch deleted file mode 100644 index 76f9a76..0000000 Binary files a/Test/C和C++扩展/pydext/.vs/pydext/v15/ipch/AutoPCH/d5916c660b4c4bac/PYDEXT.ipch and /dev/null differ diff --git a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj b/Test/C和C++扩展/pydext/pydext/pydext.vcxproj deleted file mode 100644 index 6184a2a..0000000 --- a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj +++ /dev/null @@ -1,203 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {023C9F4B-FECC-430A-81D2-7044FAFF15D0} - pydext - 3.5 - 10.0.16299.0 - - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - RegistryView.Registry32 - RegistryView.Registry64 - $(PythonVersion)-32 - $(PythonVersion) - $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', null, null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', null, null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', 'ExecutablePath', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', 'ExecutablePath', null, $(RegistryView))) - $(PythonHome)python.exe - $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'dev', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'dev', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_pdb', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_pdb', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_d', null, $(RegistryView))) - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_d', null, $(RegistryView))) - _d - $([System.IO.Path]::GetDirectoryName($(PythonExe)))\python$(PythonDebugSuffix).exe - $(PythonExe) - - - - WindowsLocalDebugger - PythonDebugLaunchProvider - - - - - - - - - - - - - - - - - - - - pydext$(PythonDebugSuffix) - .pyd - $(PythonDExe) - -i -c "print('>>> import pydext'); import pydext" - PYTHONPATH=$(OutDir) - $(DefaultDebuggerFlavor) - - - pydext - .pyd - $(PythonExe) - -i -c "print('>>> import pydext'); import pydext" - PYTHONPATH=$(OutDir) - $(DefaultDebuggerFlavor) - - - pydext$(PythonDebugSuffix) - .pyd - $(PythonDExe) - -i -c "print('>>> import pydext'); import pydext" - PYTHONPATH=$(OutDir) - $(DefaultDebuggerFlavor) - - - pydext - .pyd - $(PythonExe) - -i -c "print('>>> import pydext'); import pydext" - PYTHONPATH=$(OutDir) - $(DefaultDebuggerFlavor) - - - - Level3 - Disabled - MultithreadedDLL - D:\soft\Python35\include;$(PythonHome)Include;%(AdditionalIncludeDirectories) - true - - - true - $(PythonHome)libs;%(AdditionalLibraryDirectories) - - - - - Level3 - Disabled - MultithreadedDLL - $(PythonHome)Include;%(AdditionalIncludeDirectories) - true - - - true - $(PythonHome)libs;%(AdditionalLibraryDirectories) - - - - - Level3 - MaxSpeed - true - true - Multithreaded - D:\soft\Python35\include;$(PythonHome)Include;%(AdditionalIncludeDirectories) - true - - - true - true - true - libucrt.lib;%(IgnoreSpecificDefaultLibraries) - ucrt.lib;%(AdditionalDependencies) - $(PythonHome)libs;%(AdditionalLibraryDirectories) - - - - - Level3 - MaxSpeed - true - true - Multithreaded - $(PythonHome)Include;%(AdditionalIncludeDirectories) - true - - - true - true - true - libucrt.lib;%(IgnoreSpecificDefaultLibraries) - ucrt.lib;%(AdditionalDependencies) - $(PythonHome)libs;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.filters b/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.filters deleted file mode 100644 index 2b20133..0000000 --- a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.user b/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.user deleted file mode 100644 index be25078..0000000 --- a/Test/C和C++扩展/pydext/pydext/pydext.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Test/C和C++扩展/pydext/pydext/setup.py b/Test/C和C++扩展/pydext/pydext/setup.py index 03ce03e..233046e 100644 --- a/Test/C和C++扩展/pydext/pydext/setup.py +++ b/Test/C和C++扩展/pydext/pydext/setup.py @@ -1,8 +1,8 @@ from distutils.core import setup, Extension - -module = Extension('pydext', sources = ['pydext.c']) - -setup (name = 'pydext', - version = '1.0.0', - description = 'This is pydext', - ext_modules = [module]) \ No newline at end of file + +module = Extension('pydext', sources=['pydext.c']) + +setup(name='pydext', + version='1.0.0', + description='This is pydext', + ext_modules=[module]) diff --git a/Test/C和C++扩展/pydext/pydext/test.py b/Test/C和C++扩展/pydext/pydext/test.py index 3a3d870..1306229 100644 --- a/Test/C和C++扩展/pydext/pydext/test.py +++ b/Test/C和C++扩展/pydext/pydext/test.py @@ -1,8 +1,8 @@ import sys sys.path.insert(0, - './build/lib.{0}-{1}.{2}'.format(sys.platform, sys.version_info.major, sys.version_info.minor)) - + './build/lib.{0}-{1}.{2}'.format(sys.platform, sys.version_info.major, + sys.version_info.minor)) import pydext diff --git a/Test/C和C++扩展/pydext/test.py b/Test/C和C++扩展/pydext/test.py index 38c6394..ecf2301 100644 --- a/Test/C和C++扩展/pydext/test.py +++ b/Test/C和C++扩展/pydext/test.py @@ -1,4 +1,5 @@ import sys + sys.path.insert(0, './Release') import pydext diff --git a/Test/C和C++扩展/pyx和c++/CalSpecSpea.pyx b/Test/C和C++扩展/pyx和c++/CalSpecSpea.pyx index 669ea11..bd6e390 100644 --- a/Test/C和C++扩展/pyx和c++/CalSpecSpea.pyx +++ b/Test/C和C++扩展/pyx和c++/CalSpecSpea.pyx @@ -20,8 +20,8 @@ def calspecaccel(np.ndarray[double, ndim=1, mode="c"] acc, int length, double dt cdef np.ndarray[double, ndim=1] Period = np.arange(0.0, maxPeriod + periodStep, periodStep) # 10.0 + 0.02, 0.02 Period[0] = 0.001 # 调用CalSpecSpeaLib.cpp定义的函数对数组进行处理 - cal_spec_accel( np.PyArray_DATA(acc), length, dt, maxPeriod, periodStep, dampRatio, - np.PyArray_DATA(Period), np.PyArray_DATA(Fre), - np.PyArray_DATA(MAcc), np.PyArray_DATA(MVel), + cal_spec_accel( np.PyArray_DATA(acc), length, dt, maxPeriod, periodStep, dampRatio, + np.PyArray_DATA(Period), np.PyArray_DATA(Fre), + np.PyArray_DATA(MAcc), np.PyArray_DATA(MVel), np.PyArray_DATA(MDis), numt) return Period, Fre, MAcc, MVel, MDis \ No newline at end of file diff --git a/Test/C和C++扩展/pyx和c++/setup.py b/Test/C和C++扩展/pyx和c++/setup.py index eb42160..0b689bf 100644 --- a/Test/C和C++扩展/pyx和c++/setup.py +++ b/Test/C和C++扩展/pyx和c++/setup.py @@ -1,11 +1,10 @@ from distutils.core import setup, Extension -from Cython.Distutils import build_ext import numpy - +from Cython.Distutils import build_ext setup( cmdclass={'build_ext': build_ext}, ext_modules=[Extension("CalSpecSpea", sources=[ - "CalSpecSpea.pyx", "CalSpecSpeaLib.cpp"], language="c++", include_dirs=[numpy.get_include()])] + "CalSpecSpea.pyx", "CalSpecSpeaLib.cpp"], language="c++", include_dirs=[numpy.get_include()])] ) diff --git a/Test/C和C++扩展/pyx和c++/test.py b/Test/C和C++扩展/pyx和c++/test.py index c078137..9ea580c 100644 --- a/Test/C和C++扩展/pyx和c++/test.py +++ b/Test/C和C++扩展/pyx和c++/test.py @@ -4,7 +4,6 @@ import time sys.path.append( './build/lib.{0}-{1}.{2}'.format(sys.platform, sys.version_info.major, sys.version_info.minor)) - from CalSpecSpea import calspecaccel import matplotlib.pyplot as plt import numpy as np diff --git a/Test/C和C++扩展/py转pyd/pydmod.py b/Test/C和C++扩展/py转pyd/pydmod.py index 810a5bf..50ed74b 100644 --- a/Test/C和C++扩展/py转pyd/pydmod.py +++ b/Test/C和C++扩展/py转pyd/pydmod.py @@ -1,18 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Created on 2018年5月6日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: -# description: - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 +""" +Created on 2018年5月6日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: +@description: +""" def sum(x, y): diff --git a/Test/C和C++扩展/py转pyd/setup.py b/Test/C和C++扩展/py转pyd/setup.py index d3cc302..b18bc64 100644 --- a/Test/C和C++扩展/py转pyd/setup.py +++ b/Test/C和C++扩展/py转pyd/setup.py @@ -2,7 +2,6 @@ from distutils.core import setup, Extension from Cython.Distutils import build_ext - setup( cmdclass={'build_ext': build_ext}, ext_modules=[Extension("pydmod", sources=["pydmod.py"])] diff --git a/Test/C和C++扩展/py转pyd/test.py b/Test/C和C++扩展/py转pyd/test.py index 3c45145..387314a 100644 --- a/Test/C和C++扩展/py转pyd/test.py +++ b/Test/C和C++扩展/py转pyd/test.py @@ -1,7 +1,10 @@ import sys + sys.path.insert(0, - './build/lib.{0}-{1}.{2}'.format(sys.platform, sys.version_info.major, sys.version_info.minor)) + './build/lib.{0}-{1}.{2}'.format(sys.platform, sys.version_info.major, + sys.version_info.minor)) import pydmod + print(pydmod) print(pydmod.sum(1, 5)) diff --git a/Test/Network/控制小车/server.py b/Test/Network/控制小车/server.py index 2a64261..485aefb 100644 --- a/Test/Network/控制小车/server.py +++ b/Test/Network/控制小车/server.py @@ -10,26 +10,11 @@ from tornado.iostream import StreamClosedError from tornado.options import options, define from tornado.tcpserver import TCPServer - try: import RPi.GPIO as GPIO # @UnusedImport @UnresolvedImport except: pass - -# Created on 2018年4月18日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: server -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - define("port", default=8888, help="TCP port to listen on") logger = logging.getLogger(__name__) @@ -41,7 +26,6 @@ PARAM = [int(cv2.IMWRITE_JPEG_QUALITY), FPS] class EchoServer(TCPServer): - IMAGE = None def __init__(self, cap, *args, **kwargs): @@ -104,7 +88,7 @@ class EchoServer(TCPServer): while True: try: data = yield stream.read_until(b"\n") -# logger.info("Received bytes: %s", data) + # logger.info("Received bytes: %s", data) if not data.endswith(b"\n"): data = data + b"\n" if data == b'getimage\n' and self.cap and self.cap.isOpened(): diff --git a/Test/Network/控制小车/控制小车.py b/Test/Network/控制小车/控制小车.py index e4b184e..6e5b431 100644 --- a/Test/Network/控制小车/控制小车.py +++ b/Test/Network/控制小车/控制小车.py @@ -7,21 +7,7 @@ from PyQt5.QtNetwork import QTcpSocket from PyQt5.QtWidgets import QWidget -# Created on 2018年4月18日 -# author: Irony -# site: https://pyqt5.com , https://github.com/892768447 -# email: 892768447@qq.com -# file: ControlCar -# description: -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = 'Copyright (c) 2018 Irony' -__Version__ = 1.0 - - class ControlCar(QWidget): - HOST = '127.0.0.1' PORT = 8888 @@ -156,6 +142,7 @@ class ControlCar(QWidget): if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) w = ControlCar() w.show() diff --git a/Test/Network/窗口配合异步Http/requirements.txt b/Test/Network/窗口配合异步Http/requirements.txt new file mode 100644 index 0000000..a17d8ae --- /dev/null +++ b/Test/Network/窗口配合异步Http/requirements.txt @@ -0,0 +1 @@ +quamash \ No newline at end of file diff --git a/Test/Network/窗口配合异步Http/窗口配合异步Http.py b/Test/Network/窗口配合异步Http/窗口配合异步Http.py index 3c47cdd..b3d63f9 100644 --- a/Test/Network/窗口配合异步Http/窗口配合异步Http.py +++ b/Test/Network/窗口配合异步Http/窗口配合异步Http.py @@ -4,27 +4,35 @@ """ Created on 2018年10月24日 @author: Irony -@site: https://github.com/892768447 +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: AsyncioUiClient @description: """ import asyncio +import os -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap, QMovie -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton,\ - QApplication, QListWidget, QListWidgetItem, QLabel, QMessageBox import aiohttp + +try: + from PyQt5.QtCore import Qt + from PyQt5.QtGui import QPixmap, QMovie + from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication, QListWidget, QListWidgetItem, \ + QLabel, QMessageBox +except ImportError: + from PySide2.QtCore import Qt + from PySide2.QtGui import QPixmap, QMovie + from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication, QListWidget, \ + QListWidgetItem, \ + QLabel, QMessageBox + + os.environ['QUAMASH_QTIMPL'] = 'PySide2' + from PySide2 import QtGui + + setattr(QtGui, 'QApplication', QApplication) + from quamash import QEventLoop - -__Author__ = """By: Irony -QQ: 892768447 -Email: 892768447@qq.com""" -__Copyright__ = "Copyright (c) 2018 Irony" -__Version__ = "Version 1.0" - Url = 'https://www.doutula.com/api/search?keyword=%E6%9C%80%E6%96%B0%E8%A1%A8%E6%83%85&mime=0&page={}' Headers = { ':authority': 'www.doutula.com', @@ -67,6 +75,7 @@ class Window(QWidget): # 初始化session self.session = aiohttp.ClientSession(loop=loop) print(self.session) + asyncio.ensure_future(_initSession(), loop=loop) async def _doDownloadImage(self, url): @@ -131,8 +140,9 @@ if __name__ == '__main__': import sys import cgitb import os + os.makedirs('tmp', exist_ok=True) - cgitb.enable(1, None, 5, '') + cgitb.enable(format='text') app = QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) diff --git a/Test/全局热键/HotKey.py b/Test/全局热键/HotKey.py index 0d2d240..b9b2f28 100644 --- a/Test/全局热键/HotKey.py +++ b/Test/全局热键/HotKey.py @@ -1,29 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年12月11日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: HotKey @description: -''' +""" import sys -from PyQt5.QtCore import pyqtSignal, Qt -from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QTextBrowser, QPushButton,\ - QMessageBox import keyboard - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +try: + from PyQt5.QtCore import pyqtSignal, Qt + from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QTextBrowser, QPushButton, QMessageBox +except ImportError: + from PySide2.QtCore import Signal as pyqtSignal, Qt + from PySide2.QtWidgets import QWidget, QApplication, QVBoxLayout, QTextBrowser, QPushButton, QMessageBox class Window(QWidget): - dialogShow = pyqtSignal() def __init__(self, *args, **kwargs): @@ -51,7 +49,8 @@ class Window(QWidget): 'ctrl+alt+del', lambda: self.logView.append('😏😏我知道你按了任务管理器😏😏')) # 这个函数类似while True,由于这里有界面GUI的loop事件,可以达到类似的效果 -# keyboard.wait()#Block forever, like `while True`.== + + # keyboard.wait()#Block forever, like `while True`.== def onShow(self): """显示""" diff --git a/Test/自动更新/mylibs/testlibs.py b/Test/自动更新/mylibs/testlibs.py index 431226e..6cd8103 100644 --- a/Test/自动更新/mylibs/testlibs.py +++ b/Test/自动更新/mylibs/testlibs.py @@ -1,18 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年5月7日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 自动更新.mylibs.testlibs @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" def version(): diff --git a/Test/自动更新/setup.py b/Test/自动更新/setup.py index 6e99472..7bca2a0 100644 --- a/Test/自动更新/setup.py +++ b/Test/自动更新/setup.py @@ -1,13 +1,11 @@ -from distutils.core import setup import glob import os import py_compile import site import sys +from distutils.core import setup from zipfile import ZipFile, ZIP_DEFLATED -import py2exe # @UnusedImport - sys.argv.append("py2exe") sitepackages = site.getsitepackages()[1] diff --git a/Test/自动更新/test.py b/Test/自动更新/test.py index b70643a..dd7a40a 100644 --- a/Test/自动更新/test.py +++ b/Test/自动更新/test.py @@ -1,26 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2017年5月7日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: 自动更新.test @description: -''' +""" import sys + sys.path.append("mylibs") import os from time import sleep from zipfile import ZipFile -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - - def update(): # 更新 from mylibs import testlibs # @UnresolvedImport @@ -50,6 +46,7 @@ def main(): os.startfile(sys.executable) # 重启 sys.exit() # 退出本身 + if __name__ == "__main__": main() input("press any key exit") diff --git a/Test/自定义import/IronyImporter.py b/Test/自定义import/IronyImporter.py index 1a67eef..d2b203f 100644 --- a/Test/自定义import/IronyImporter.py +++ b/Test/自定义import/IronyImporter.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: IronyImporter @description: -''' +""" import base64 import os import sys @@ -16,11 +16,6 @@ from types import ModuleType import xxtea # @UnresolvedImport - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" - KEY = base64.b85decode("HF5^hbNbOVOKM=(SB`7h") diff --git a/Test/自定义import/build.py b/Test/自定义import/build.py index 86aeba8..21eeb3a 100644 --- a/Test/自定义import/build.py +++ b/Test/自定义import/build.py @@ -1,23 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: build @description: -''' +""" -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" import base64 import xxtea # @UnresolvedImport - KEY = base64.b85decode("HF5^hbNbOVOKM=(SB`7h") with open("src/test.py", "rb") as fi: diff --git a/Test/自定义import/main.py b/Test/自定义import/main.py index cccc6cb..47ebb2e 100644 --- a/Test/自定义import/main.py +++ b/Test/自定义import/main.py @@ -1,25 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: main @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" # 首先要引入importer -import IronyImporter # @UnresolvedImport @UnusedImport - # 测试开始 import test + print(test) print(dir(test)) print(test.test(1, 5)) # @UndefinedVariable diff --git a/Test/自定义import/src/test.py b/Test/自定义import/src/test.py index 07d5d45..4049409 100644 --- a/Test/自定义import/src/test.py +++ b/Test/自定义import/src/test.py @@ -1,18 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -''' +""" Created on 2018年1月28日 -@author: Irony."[讽刺] -@site: https://pyqt5.com , https://github.com/892768447 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 @email: 892768447@qq.com @file: test @description: -''' - -__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" -__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]" -__Version__ = "Version 1.0" +""" def test(a, b):