diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 141fb3c..1e72ae6 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +encoding//Demo/AutoRestart.py=utf-8 encoding//Demo/EmbedWindow.py=utf-8 encoding//Demo/FacePoints.py=utf-8 encoding//Demo/FollowWindow.py=utf-8 @@ -36,7 +37,9 @@ encoding//QSlider/QssQSlider.py=utf-8 encoding//QSplitter/RewriteHandle.py=utf-8 encoding//QThread/moveToThread.py=utf-8 encoding//QTreeWidget/ParsingJson.py=utf-8 +encoding//QWebEngineView/GetCookie.py=utf-8 encoding//QWebView/DreamTree.py=utf-8 +encoding//QWebView/GetCookie.py=utf-8 encoding//QWidget/Lib/CustomPaintWidget.py=utf-8 encoding//QWidget/Lib/CustomWidget.py=utf-8 encoding//QWidget/WidgetStyle.py=utf-8 diff --git a/Demo/AutoRestart.py b/Demo/AutoRestart.py index 23a3ff1..7037595 100644 --- a/Demo/AutoRestart.py +++ b/Demo/AutoRestart.py @@ -13,18 +13,48 @@ Created on 2017年3月31日 from optparse import OptionParser import os import sys -import time + +from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout + + +canRestart = True def restart(twice): os.execl(sys.executable, sys.executable, *[sys.argv[0], "-t", twice]) + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + self.resize(400, 400) + layout = QHBoxLayout(self) + + self.buttonRestart = QPushButton( + "app start...%s...twice\napp pid: %s\n点击按钮重启...\n" % + (options.twice, os.getpid()), self) + self.buttonRestart.clicked.connect(self.close) + + self.buttonExit = QPushButton('退出', self, clicked=self.doExit) + + layout.addWidget(self.buttonRestart) + layout.addWidget(self.buttonExit) + + def doExit(self): + global canRestart + canRestart = False + self.close() + + if __name__ == "__main__": parser = OptionParser(usage="usage:%prog [optinos] filepath") - parser.add_option("-t", "--twice", type="int", dest="twice", default=1, help="运行次数") + parser.add_option("-t", "--twice", type="int", + dest="twice", default=1, help="运行次数") options, _ = parser.parse_args() - print("app start...%s...twice\n" % options.twice) - print("app pid: ",os.getpid()) - print("3秒后自动重启...\n") - time.sleep(3) - restart(str(options.twice + 1)) + app = QApplication(sys.argv) + w = Window() + w.show() + app.exec_() + if canRestart: + restart(str(options.twice + 1)) diff --git a/QAxWidget/README.en.md b/QAxWidget/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QChart/README.en.md b/QChart/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QFont/README.md b/QFont/README.md index 6cbd493..489a9e2 100644 --- a/QFont/README.md +++ b/QFont/README.md @@ -1,9 +1,8 @@ -# 字体测试 +# QFont -### [Python3.4.4 or Python3.5][PyQt5] +## 1、加载自定义字体 +[运行 AwesomeFont.py](AwesomeFont.py) -### 其中Roboto字体通过TTF编辑器修改了family,方便QFont加载 +通过`QFontDatabase.addApplicationFont`加载字体文件 -# 截图 -![截图](ScreenShot/1.png) -![截图](ScreenShot/2.png) \ No newline at end of file +![AwesomeFont](ScreenShot/AwesomeFont.png) \ No newline at end of file diff --git a/QFont/ScreenShot/2.png b/QFont/ScreenShot/2.png deleted file mode 100644 index c5f4b9d..0000000 Binary files a/QFont/ScreenShot/2.png and /dev/null differ diff --git a/QFont/ScreenShot/1.png b/QFont/ScreenShot/AwesomeFont.png similarity index 100% rename from QFont/ScreenShot/1.png rename to QFont/ScreenShot/AwesomeFont.png diff --git a/QMenu/README.en.md b/QMenu/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QScrollBar/README.md b/QScrollBar/README.md index 190ff2a..3d7cbe7 100644 --- a/QScrollBar/README.md +++ b/QScrollBar/README.md @@ -1,6 +1,7 @@ # QScrollBar ## 1、滚动条样式美化 +[运行 StyleScrollBar.py](StyleScrollBar.py) 使用QSS和图片对滚动条进行美化(horizontal 横向、vertical 纵向) diff --git a/QSerialPort/README.md b/QSerialPort/README.md index 6e97a66..bc86980 100644 --- a/QSerialPort/README.md +++ b/QSerialPort/README.md @@ -1,4 +1,4 @@ -# +# QSerialPort ## 1、串口调试小助手 [运行 SerialDebugAssistant.py](SerialDebugAssistant.py) diff --git a/QSplitter/README.en.md b/QSplitter/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QThread/README.md b/QThread/README.md index 6f52c7c..85a00a5 100644 --- a/QThread/README.md +++ b/QThread/README.md @@ -1,7 +1,5 @@ # QThread -PyQt多线程的简单使用例子 - ## 1、继承QThread [运行 InheritQThread.py](InheritQThread.py) diff --git a/QWebEngineView/GetCookie.py b/QWebEngineView/GetCookie.py index 11a4755..81aa259 100644 --- a/QWebEngineView/GetCookie.py +++ b/QWebEngineView/GetCookie.py @@ -11,9 +11,9 @@ Created on 2017年12月10日 ''' import sys -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QUrl, QByteArray from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile -from PyQt5.QtWidgets import QApplication +from PyQt5.QtWidgets import QApplication, QTextEdit __Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" @@ -28,14 +28,41 @@ class WebEngineView(QWebEngineView): def __init__(self, *args, **kwargs): super(WebEngineView, self).__init__(*args, **kwargs) + self.cookieView = QTextEdit() + self.cookieView.resize(800, 400) + self.cookieView.move(400, 400) + self.cookieView.setWindowTitle('Cookies') + self.cookieView.show() # 绑定cookie被添加的信号槽 QWebEngineProfile.defaultProfile().cookieStore( ).cookieAdded.connect(self.onCookieAdd) self.loadFinished.connect(self.onLoadFinished) + def closeEvent(self, event): + self.cookieView.close() + super(WebEngineView, self).closeEvent(event) + + def bytestostr(self, data): + if isinstance(data, str): + return data + if isinstance(data, QByteArray): + data = data.data() + if isinstance(data, bytes): + data = data.decode(errors='ignore') + else: + data = str(data) + return data + def onLoadFinished(self): print("*****AllDomainCookies:", self.getAllDomainCookies()) print("*****AllPathCookies:", self.getAllPathCookies()) + self.cookieView.append( + "AllDomainCookies: " + self.bytestostr(self.getAllDomainCookies())) + self.cookieView.append('') + self.cookieView.append( + "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/")) diff --git a/QWebView/GetCookie.py b/QWebView/GetCookie.py index 41aa88a..090b4f6 100644 --- a/QWebView/GetCookie.py +++ b/QWebView/GetCookie.py @@ -9,11 +9,12 @@ Created on 2017年12月10日 @file: GetCookie @description: ''' +import cgitb import sys -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QUrl, QByteArray from PyQt5.QtWebKitWidgets import QWebView -from PyQt5.QtWidgets import QApplication +from PyQt5.QtWidgets import QApplication, QTextEdit __Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com" @@ -25,13 +26,40 @@ class WebView(QWebView): def __init__(self, *args, **kwargs): super(WebView, self).__init__(*args, **kwargs) + self.cookieView = QTextEdit() + self.cookieView.resize(800, 400) + self.cookieView.move(400, 400) + self.cookieView.setWindowTitle('Cookies') + self.cookieView.show() self.loadFinished.connect(self.onLoadFinished) + def closeEvent(self, event): + self.cookieView.close() + super(WebView, self).closeEvent(event) + + def bytestostr(self, data): + if isinstance(data, str): + return data + if isinstance(data, QByteArray): + data = data.data() + if isinstance(data, bytes): + data = data.decode(errors='ignore') + else: + data = str(data) + return data + def onLoadFinished(self): allCookies = self.page().networkAccessManager().cookieJar().allCookies() print("allCookies:", allCookies) for cookie in allCookies: # if cookie.domain() == ".pyqt5.com": + self.cookieView.append( + "domain: " + self.bytestostr(cookie.domain())) + self.cookieView.append("path: " + self.bytestostr(cookie.path())) + self.cookieView.append("name: " + self.bytestostr(cookie.name())) + self.cookieView.append( + "value: " + self.bytestostr(cookie.value())) + self.cookieView.append('') print("domain:", cookie.domain()) print("path:", cookie.path()) print("name:", cookie.name()) @@ -40,6 +68,7 @@ class WebView(QWebView): if __name__ == "__main__": + sys.excepthook = cgitb.enable(1, None, 5, '') app = QApplication(sys.argv) w = WebView() w.show() diff --git a/QWebView/README.md b/QWebView/README.md index 182c10e..c86d897 100644 --- a/QWebView/README.md +++ b/QWebView/README.md @@ -2,6 +2,7 @@ ## 1、梦幻树 [运行 DreamTree.py](DreamTree.py) + 在桌面上显示透明html效果,使用`QWebkit`加载html实现,采用窗口背景透明和穿透方式 ![DreamTree](ScreenShot/DreamTree.png)