update all

This commit is contained in:
Irony 2017-04-07 09:20:04 +08:00
parent 98b4ae7650
commit 5cecfef0b8
15 changed files with 6721 additions and 5 deletions

17
.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PyQtGithub</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

8
.pydevproject Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
</pydev_project>

View file

@ -3,12 +3,16 @@
### [Python3.4.4 or Python3.5][PyQt5]
### 1.<a href="右下角弹出框/">右下角弹出框</a><br />
### 1.<a href="右下角弹出框">右下角弹出框</a><br />
### 2.<a href="单实例应用/">单实例应用</a><br />
### 2.<a href="单实例应用">单实例应用</a><br />
### 3.<a href="字体测试/">字体测试</a><br />
### 3.<a href="字体测试">字体测试</a><br />
### 4.<a href="程序重启/">程序重启</a><br />
### 4.<a href="程序重启">程序重启</a><br />
### 5.<a href="验证码控件/">验证码控件</a><br />
### 5.<a href="验证码控件">验证码控件</a><br />
### 6.<a href="表格复制">表格复制</a><br />
### 7.<a href="梦幻树">梦幻树</a><br />

70
梦幻树/DreamTree.py Normal file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2017年4月6日
@author: Irony."[讽刺]
@site: alyl.vip, orzorz.vip, irony.coding.me , irony.iask.in , mzone.iask.in
@email: 892768447@qq.com
@file: DreamTree
@description:
'''
import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QPalette
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
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作为父控件
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setAttribute(Qt.WA_TranslucentBackground, True) # 设置父控件Widget背景透明
self.setWindowFlags(Qt.FramelessWindowHint) # 去掉边框
palette = self.palette()
palette.setBrush(QPalette.Base, Qt.transparent) # 父控件背景透明
self.setPalette(palette)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
# QWebSettings.globalSettings().setAttribute(
# QWebSettings.DeveloperExtrasEnabled, True)# web开发者工具
self.webView = QWebView(self) # 网页控件
layout.addWidget(self.webView)
self.webView.setContextMenuPolicy(Qt.NoContextMenu) # 去掉右键菜单
self.mainFrame = self.webView.page().mainFrame()
self.mainFrame.setScrollBarPolicy(
Qt.Vertical, Qt.ScrollBarAlwaysOff) # 去掉滑动条
self.mainFrame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
# 最大化
rect = app.desktop().availableGeometry()
self.resize(rect.size())
self.webView.resize(rect.size())
def load(self):
self.webView.load(QUrl('qrc:/tree.html')) # 加载网页
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Window()
w.show()
w.load()
sys.exit(app.exec_())

10
梦幻树/README.md Normal file
View file

@ -0,0 +1,10 @@
# 梦幻树
<br />
### [Python3.4.4][PyQt5]
# 截图
<img src="ScreenShot/1.png" />
# 说明
使用QWebkit加载html实现,采用窗口背景透明和穿透方式

BIN
梦幻树/ScreenShot/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

6
梦幻树/data.qrc Normal file
View file

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>tree.html</file>
<file>jquery.js</file>
</qresource>
</RCC>

6225
梦幻树/data_rc.py Normal file

File diff suppressed because it is too large Load diff

4
梦幻树/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

257
梦幻树/tree.html Normal file
View file

@ -0,0 +1,257 @@
<!DOCTYPE html><html slick-uniqueid="1">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
梦幻树-PlasmaTree
</title>
<meta name="author" content="mhepekka">
<meta name="robots" content="index,follow">
<meta name="copyright" content="Copyright 2010 mhepekka">
<style type="text/css">
.footer{pointer-events: none;position:absolute;bottom:0;width:100%;height:50px;background-color: rgba(255,255,255,0.5);}
</style>
<script src="qrc:/jquery.js"></script>
<script type="text/javascript">
(function($) {
var Vector = function(x, y) {
this.x = x || 0;
this.y = y || 0;
};
Vector.prototype = {
add: function(v) {
this.x += v.x;
this.y += v.y;
return this;
},
length: function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
},
rotate: function(theta) {
var x = this.x;
var y = this.y;
this.x = Math.cos(theta) * this.x - Math.sin(theta) * this.y;
this.y = Math.sin(theta) * this.x + Math.cos(theta) * this.y;
//this.x = Math.cos(theta) * x - Math.sin(theta) * y;
//this.y = Math.sin(theta) * x + Math.cos(theta) * y;
return this;
},
mult: function(f) {
this.x *= f;
this.y *= f;
return this;
}
};
var Leaf = function(p, r, c, ctx) {
this.p = p || null;
this.r = r || 0;
this.c = c || 'rgba(255,255,255,1.0)';
this.ctx = ctx;
}
Leaf.prototype = {
render: function() {
var that = this;
var ctx = this.ctx;
var f = Branch.random(1, 2)
for (var i = 0; i < 5; i++) {
(function(r) {
setTimeout(function() {
ctx.beginPath();
ctx.fillStyle = that.color;
ctx.moveTo(that.p.x, that.p.y);
ctx.arc(that.p.x, that.p.y, r, 0, Branch.circle, true);
ctx.fill();
},
r * 60);
})(i);
}
}
}
var Branch = function(p, v, r, c, t) {
this.p = p || null;
this.v = v || null;
this.r = r || 0;
this.length = 0;
this.generation = 1;
this.tree = t || null;
this.color = c || 'rgba(255,255,255,1.0)';
this.register();
};
Branch.prototype = {
register: function() {
this.tree.addBranch(this);
},
draw: function() {
var ctx = this.tree.ctx;
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.moveTo(this.p.x, this.p.y);
ctx.arc(this.p.x, this.p.y, this.r, 0, Branch.circle, true);
ctx.fill();
},
modify: function() {
var angle = 0.18 - (0.10 / this.generation);
this.p.add(this.v);
this.length += this.v.length();
this.r *= 0.99;
this.v.rotate(Branch.random( - angle, angle)); //.mult(0.996);
if (this.r < 0.8 || this.generation > 10) {
this.tree.removeBranch(this);
var l = new Leaf(this.p, 10, this.color, this.tree.ctx);
l.render();
}
},
grow: function() {
this.draw();
this.modify();
this.fork();
},
fork: function() {
var p = this.length - Branch.random(100, 200); // + (this.generation * 10);
if (p > 0) {
var n = Math.round(Branch.random(1, 3));
this.tree.stat.fork += n - 1;
for (var i = 0; i < n; i++) {
Branch.clone(this);
}
this.tree.removeBranch(this);
}
}
};
Branch.circle = 2 * Math.PI;
Branch.random = function(min, max) {
return Math.random() * (max - min) + min;
};
Branch.clone = function(b) {
var r = new Branch(new Vector(b.p.x, b.p.y), new Vector(b.v.x, b.v.y), b.r, b.color, b.tree);
r.generation = b.generation + 1;
return r;
};
Branch.rgba = function(r, g, b, a) {
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
};
Branch.randomrgba = function(min, max, a) {
return Branch.rgba(Math.round(Branch.random(min, max)), Math.round(Branch.random(min, max)), Math.round(Branch.random(min, max)), a);
};
var Tree = function() {
var branches = [];
var timer;
this.stat = {
fork: 0,
length: 0
};
this.addBranch = function(b) {
branches.push(b);
};
this.removeBranch = function(b) {
for (var i = 0; i < branches.length; i++) {
if (branches[i] === b) {
branches.splice(i, 1);
return;
}
}
};
this.render = function(fn) {
var that = this;
timer = setInterval(function() {
fn.apply(that, arguments);
if (branches.length > 0) {
for (var i = 0; i < branches.length; i++) {
branches[i].grow();
}
}
else {
//clearInterval(timer);
}
},
1000 / 30);
};
this.init = function(ctx) {
this.ctx = ctx;
};
this.abort = function() {
branches = [];
this.stat = {
fork: 0,
length: 0
}
};
};
function init() {
// init
var $window = $(window);
var $body = $("body");
var canvas_width = $window.width();
var canvas_height = $window.height() - 0;
var center_x = canvas_width / 2;
var stretch_factor = 600 / canvas_height;
var y_speed = 3 / stretch_factor;
var $statMsg = $("#statMsg");
// tx
var canvas = $('#canvas')[0];
canvas.width = canvas_width;
canvas.height = canvas_height;
var ctx = canvas.getContext("2d");
ctx.globalCompositeOperation = "lighter";
// tree
var t = new Tree();
t.init(ctx);
for (var i = 0; i < 3; i++) {
new Branch(new Vector(center_x, canvas_height), new Vector(Math.random( - 1, 1), -y_speed), 15 / stretch_factor, Branch.randomrgba(0, 255, 0.3), t);
}
t.render(function() {
$statMsg.html(this.stat.fork);
});
// events
$("#drawArea").click(function(e) {
//e.preventDefault();
var x, y;
x = e.pageX - this.offsetLeft;
y = e.pageY - this.offsetTop;
new Branch(new Vector(x, canvas_height), new Vector(0, -y_speed), 15 / stretch_factor, Branch.randomrgba(0, 255, 0.3), t);
});
$("#btnClear").click(function(e) {
e.stopPropagation();
t.abort();
ctx.clearRect(0, 0, canvas_width, canvas_height);
$statMsg.html("0");
});
$("#btnReload").click(function(e) {
e.stopPropagation();
window.location.reload();
});
$("#btnNewExperiment").click(function(e) {
window.location = "http://alyl.vip";
});
}
$(function() {
init();
});
})(jQuery);
</script>
</head>
<body huaban_screen_capture_injected="true" style="">
<div id="drawArea">
<div id="buttonArea">
</div>
<canvas id="canvas" width="1642" height="593">
</canvas>
</div>
<div class="footer"><center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</center></div>
<script charset="utf-8">
(function(w, d, g, J) {
var e = J.stringify || J.encode;
d[g] = d[g] || {};
d[g]['showValidImages'] = d[g]['showValidImages'] ||
function() {
w.postMessage(e({
'msg': {
'g': g,
'm': 's'
}
}), location.href);
}
})(window, document, '__huaban', JSON);
</script>
</body>
</html>

8
表格复制/README.md Normal file
View file

@ -0,0 +1,8 @@
# 表格复制
<br />
### [Python3.4.4 or Python3.5][PyQt5]
# 截图
<img src="ScreenShot/1.png" />
<img src="ScreenShot/2.png" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

107
表格复制/TableView.py Normal file
View file

@ -0,0 +1,107 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2017年4月6日
@author: Irony."[讽刺]
@site: alyl.vip, orzorz.vip, irony.coding.me , irony.iask.in , mzone.iask.in
@email: 892768447@qq.com
@file: TableView
@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"
class TableView(QTableView):
def __init__(self, parent=None):
super(TableView, self).__init__(parent)
self.resize(800, 600)
self.setContextMenuPolicy(Qt.ActionsContextMenu) # 右键菜单
self.setEditTriggers(self.NoEditTriggers) # 禁止编辑
self.doubleClicked.connect(self.onDoubleClick)
self.addAction(QAction("复制", self, triggered=self.copyData))
self.myModel = QStandardItemModel() # model
self.initHeader() # 初始化表头
self.setModel(self.myModel)
self.initData() # 初始化模拟数据
def onDoubleClick(self, index):
print(index.row(), index.column(), index.data())
def keyPressEvent(self, event):
super(TableView, self).keyPressEvent(event)
# Ctrl + C
if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_C:
self.copyData()
def copyData(self):
count = len(self.selectedIndexes())
if count == 0:
return
if count == 1: # 只复制了一个
QApplication.clipboard().setText(
self.selectedIndexes()[0].data()) # 复制到剪贴板中
QMessageBox.information(self, "提示", "已复制一个数据")
return
rows = set()
cols = set()
for index in self.selectedIndexes(): # 得到所有选择的
rows.add(index.row())
cols.add(index.column())
# print(index.row(),index.column(),index.data())
if len(rows) == 1: # 一行
QApplication.clipboard().setText("\t".join(
[index.data() for index in self.selectedIndexes()])) # 复制
QMessageBox.information(self, "提示", "已复制一行数据")
return
if len(cols) == 1: # 一列
QApplication.clipboard().setText("\r\n".join(
[index.data() for index in self.selectedIndexes()])) # 复制
QMessageBox.information(self, "提示", "已复制一列数据")
return
mirow, marow = min(rows), max(rows) # 最(少/多)行
micol, macol = min(cols), max(cols) # 最(少/多)列
print(mirow, marow, micol, macol)
arrays = [
[
"" for _ in range(macol - micol + 1)
] for _ in range(marow - mirow + 1)
] # 创建二维数组(并排除前面的空行和空列)
print(arrays)
# 填充数据
for index in self.selectedIndexes(): # 遍历所有选择的
arrays[index.row() - mirow][index.column() - micol] = index.data()
print(arrays)
data = "" # 最后的结果
for row in arrays:
data += "\t".join(row) + "\r\n"
print(data)
QApplication.clipboard().setText(data) # 复制到剪贴板中
QMessageBox.information(self, "提示", "已复制")
def initHeader(self):
for i in range(5):
self.myModel.setHorizontalHeaderItem(
i, QStandardItem("表头" + str(i + 1)))
def initData(self):
for row in range(100):
for col in range(5):
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()
w.show()
sys.exit(app.exec_())