Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
892768447 committed Feb 1, 2019
1 parent 9feec8f commit c84d218
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 37 additions & 7 deletions Demo/AutoRestart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,48 @@
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))
Empty file added QAxWidget/README.en.md
Empty file.
Empty file added QChart/README.en.md
Empty file.
11 changes: 5 additions & 6 deletions QFont/README.md
Original file line number Diff line number Diff line change
@@ -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)
![AwesomeFont](ScreenShot/AwesomeFont.png)
Binary file removed QFont/ScreenShot/2.png
Binary file not shown.
File renamed without changes
Empty file added QMenu/README.en.md
Empty file.
1 change: 1 addition & 0 deletions QScrollBar/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# QScrollBar

## 1、滚动条样式美化
[运行 StyleScrollBar.py](StyleScrollBar.py)

使用QSS和图片对滚动条进行美化(horizontal 横向、vertical 纵向)

Expand Down
2 changes: 1 addition & 1 deletion QSerialPort/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# QSerialPort

## 1、串口调试小助手
[运行 SerialDebugAssistant.py](SerialDebugAssistant.py)
Expand Down
Empty file added QSplitter/README.en.md
Empty file.
2 changes: 0 additions & 2 deletions QThread/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# QThread

PyQt多线程的简单使用例子

## 1、继承QThread
[运行 InheritQThread.py](InheritQThread.py)

Expand Down
31 changes: 29 additions & 2 deletions QWebEngineView/GetCookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'''
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: [email protected]"
Expand All @@ -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/"))
Expand Down
33 changes: 31 additions & 2 deletions QWebView/GetCookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
@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: [email protected]"
Expand All @@ -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())
Expand All @@ -40,6 +68,7 @@ def onLoadFinished(self):


if __name__ == "__main__":
sys.excepthook = cgitb.enable(1, None, 5, '')
app = QApplication(sys.argv)
w = WebView()
w.show()
Expand Down
1 change: 1 addition & 0 deletions QWebView/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1、梦幻树
[运行 DreamTree.py](DreamTree.py)

在桌面上显示透明html效果,使用`QWebkit`加载html实现,采用窗口背景透明和穿透方式

![DreamTree](ScreenShot/DreamTree.png)
Expand Down

0 comments on commit c84d218

Please sign in to comment.