This commit is contained in:
Irony 2019-02-01 23:41:22 +08:00
parent 9feec8fe34
commit c84d2181e8
15 changed files with 108 additions and 20 deletions

View file

@ -1,4 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//Demo/AutoRestart.py=utf-8
encoding//Demo/EmbedWindow.py=utf-8 encoding//Demo/EmbedWindow.py=utf-8
encoding//Demo/FacePoints.py=utf-8 encoding//Demo/FacePoints.py=utf-8
encoding//Demo/FollowWindow.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//QSplitter/RewriteHandle.py=utf-8
encoding//QThread/moveToThread.py=utf-8 encoding//QThread/moveToThread.py=utf-8
encoding//QTreeWidget/ParsingJson.py=utf-8 encoding//QTreeWidget/ParsingJson.py=utf-8
encoding//QWebEngineView/GetCookie.py=utf-8
encoding//QWebView/DreamTree.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/CustomPaintWidget.py=utf-8
encoding//QWidget/Lib/CustomWidget.py=utf-8 encoding//QWidget/Lib/CustomWidget.py=utf-8
encoding//QWidget/WidgetStyle.py=utf-8 encoding//QWidget/WidgetStyle.py=utf-8

View file

@ -13,18 +13,48 @@ Created on 2017年3月31日
from optparse import OptionParser from optparse import OptionParser
import os import os
import sys import sys
import time
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout
canRestart = True
def restart(twice): def restart(twice):
os.execl(sys.executable, sys.executable, *[sys.argv[0], "-t", 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__": if __name__ == "__main__":
parser = OptionParser(usage="usage:%prog [optinos] filepath") 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() options, _ = parser.parse_args()
print("app start...%s...twice\n" % options.twice) app = QApplication(sys.argv)
print("app pid: ",os.getpid()) w = Window()
print("3秒后自动重启...\n") w.show()
time.sleep(3) app.exec_()
restart(str(options.twice + 1)) if canRestart:
restart(str(options.twice + 1))

0
QAxWidget/README.en.md Normal file
View file

0
QChart/README.en.md Normal file
View file

View file

@ -1,9 +1,8 @@
# 字体测试 # QFont
### [Python3.4.4 or Python3.5][PyQt5] ## 1、加载自定义字体
[运行 AwesomeFont.py](AwesomeFont.py)
### 其中Roboto字体通过TTF编辑器修改了family,方便QFont加载 通过`QFontDatabase.addApplicationFont`加载字体文件
# 截图 ![AwesomeFont](ScreenShot/AwesomeFont.png)
![截图](ScreenShot/1.png)
![截图](ScreenShot/2.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

View file

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 127 KiB

0
QMenu/README.en.md Normal file
View file

View file

@ -1,6 +1,7 @@
# QScrollBar # QScrollBar
## 1、滚动条样式美化 ## 1、滚动条样式美化
[运行 StyleScrollBar.py](StyleScrollBar.py)
使用QSS和图片对滚动条进行美化horizontal 横向、vertical 纵向) 使用QSS和图片对滚动条进行美化horizontal 横向、vertical 纵向)

View file

@ -1,4 +1,4 @@
# # QSerialPort
## 1、串口调试小助手 ## 1、串口调试小助手
[运行 SerialDebugAssistant.py](SerialDebugAssistant.py) [运行 SerialDebugAssistant.py](SerialDebugAssistant.py)

0
QSplitter/README.en.md Normal file
View file

View file

@ -1,7 +1,5 @@
# QThread # QThread
PyQt多线程的简单使用例子
## 1、继承QThread ## 1、继承QThread
[运行 InheritQThread.py](InheritQThread.py) [运行 InheritQThread.py](InheritQThread.py)

View file

@ -11,9 +11,9 @@ Created on 2017年12月10日
''' '''
import sys import sys
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl, QByteArray
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile 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" __Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
@ -28,14 +28,41 @@ class WebEngineView(QWebEngineView):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(WebEngineView, self).__init__(*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被添加的信号槽 # 绑定cookie被添加的信号槽
QWebEngineProfile.defaultProfile().cookieStore( QWebEngineProfile.defaultProfile().cookieStore(
).cookieAdded.connect(self.onCookieAdd) ).cookieAdded.connect(self.onCookieAdd)
self.loadFinished.connect(self.onLoadFinished) 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): def onLoadFinished(self):
print("*****AllDomainCookies:", self.getAllDomainCookies()) print("*****AllDomainCookies:", self.getAllDomainCookies())
print("*****AllPathCookies:", self.getAllPathCookies()) 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 cookie:", self.getDomainCookies(".pyqt5.com"))
print("*****pyqt5.com / path cookie:", print("*****pyqt5.com / path cookie:",
self.getPathCookies(".pyqt5.com/")) self.getPathCookies(".pyqt5.com/"))

View file

@ -9,11 +9,12 @@ Created on 2017年12月10日
@file: GetCookie @file: GetCookie
@description: @description:
''' '''
import cgitb
import sys import sys
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl, QByteArray
from PyQt5.QtWebKitWidgets import QWebView 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" __Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
@ -25,13 +26,40 @@ class WebView(QWebView):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(WebView, self).__init__(*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) 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): def onLoadFinished(self):
allCookies = self.page().networkAccessManager().cookieJar().allCookies() allCookies = self.page().networkAccessManager().cookieJar().allCookies()
print("allCookies:", allCookies) print("allCookies:", allCookies)
for cookie in allCookies: for cookie in allCookies:
# if cookie.domain() == ".pyqt5.com": # 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("domain:", cookie.domain())
print("path:", cookie.path()) print("path:", cookie.path())
print("name:", cookie.name()) print("name:", cookie.name())
@ -40,6 +68,7 @@ class WebView(QWebView):
if __name__ == "__main__": if __name__ == "__main__":
sys.excepthook = cgitb.enable(1, None, 5, '')
app = QApplication(sys.argv) app = QApplication(sys.argv)
w = WebView() w = WebView()
w.show() w.show()

View file

@ -2,6 +2,7 @@
## 1、梦幻树 ## 1、梦幻树
[运行 DreamTree.py](DreamTree.py) [运行 DreamTree.py](DreamTree.py)
在桌面上显示透明html效果使用`QWebkit`加载html实现,采用窗口背景透明和穿透方式 在桌面上显示透明html效果使用`QWebkit`加载html实现,采用窗口背景透明和穿透方式
![DreamTree](ScreenShot/DreamTree.png) ![DreamTree](ScreenShot/DreamTree.png)