Skip to content

Instantly share code, notes, and snippets.

@redstoneleo
redstoneleo / mouse.on_pressed
Last active February 10, 2020 04:40
mouse.on_pressed
def on_pressed(callback, args=()):
""" Invokes `callback` with `args` when the left button is pressed. """
return on_button(callback, args, [LEFT], [DOWN])
@redstoneleo
redstoneleo / platform Download icon
Created October 25, 2019 13:55
svg_icon_iphone svg_icon_win svg_icon_mac svg_icon_ipad svg_icon_tv
<style type="text/css">
.dl_list{color: #666;}
</style>
<div class="dl_list">
<a class="item" target="_blank" href="http://v.qq.com/download.html#phone" _stat="page_footer:download_1">
<svg class="svg_icon svg_icon_iphone" viewBox="0 0 50 50" width="50" height="50"> <path d="M34 3h-18c-1.657 0-3 1.343-3 3v38c0 1.657 1.343 3 3 3h18c1.657 0 3-1.343 3-3v-38c0-1.657-1.343-3-3-3zm1 38h-20v-32h20v32z"></path> <!--[if lte IE 8 ]><image src="//puui.qpic.cn/vupload/0/20190105_svg_icon_iphone.png/0" xlink:href="" /><![endif]--> </svg>
<span class="text_icon">手机版</span>
@redstoneleo
redstoneleo / PyQt5WithPIL.py
Created June 25, 2019 14:00
used to test Nuitka issues
import sys
from PIL import ImageGrab
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
app = QApplication(sys.argv)
btn = QPushButton()
btn.clicked.connect(lambda: ImageGrab.grab(bbox=(0, 0, 900, 900)))
@redstoneleo
redstoneleo / gist:d18c575febd195034fec7bc3389fdb02
Created April 29, 2019 05:12
the expected behavior of QCompleter.UnfilteredPopupCompletion is so slow
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtNetwork import *
class Window(QMainWindow):
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
@redstoneleo
redstoneleo / MediaDownload
Created February 28, 2018 02:22
MediaDownload
// console.log('tabTitle----onClicked----',tab.title,hostname);
fileExt = tabId2DownloadInfo[tab.id][1]; //{tabId:[targetUrl,fileExt]} ------->fileExt
np = nameParser[hostname];
fileName = (np ? np(tabTitle) : tabTitle) + fileExt; //必须在三元运算符外加括号才会成为一个值,不然直接return
// console.log('downloadInfo fileName ' ,fileName.replace(/[\\/:*?"<>|]/g, '_'));
tabId2DownloadInfo[tabId][1] = fileName.replace(/[\\/:*?"<>|~]/g, '_'); //{tabId:[targetUrl,fileName]} 替换网页标题里不能包含于文件名(以Windows的文件命名为准)中的非法字符\/:*?"<>|
@redstoneleo
redstoneleo / invalid baiduTranslate
Created December 31, 2017 06:54
invalid baiduTranslate----
def baiduTranslate(self, queryText):
queryUrl = 'http://fanyi.baidu.com/v2transapi'
response = requests.post(queryUrl, data={'from': 'en', 'to': 'zh', 'query': queryText, 'transtype': 'realtime', 'simple_means_flag': 3,'sign':'498118.235959','token':'40a25d2a0d533f7cc897a454a0a86812'})
repliedJson = response.json()
print(repliedJson)
dictResult = repliedJson["dict_result"]
if not dictResult: # 句子的时候字典没结果,teaching posts也没有结果
print('baiduTranslate 翻译', queryText) # , repliedJson["trans_result"]["data"][0]["dst"]
return repliedJson["trans_result"]["data"][0]["dst"]
# Credits go to the Qt Centre forum.
# import logging
# import sys
# logging.basicConfig(filename='LYYDownloader.log')
# def uncaughtExceptionHandler(type_, value, traceback):
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyFileSystemModel(QFileSystemModel):
def __init__(self, h_align=Qt.AlignLeft, v_align=Qt.AlignLeft, parent=None):
super().__init__(parent)
self.alignments = {Qt.Horizontal: h_align, Qt.Vertical: v_align}
# print('(QProcess)---------------',self.findChildren(QProcess))
arguments = ['-f', 'concat', '-safe', '-1', '-i', fp.name, '-y', '-c', 'copy', absoluteFileName]
# print(os.path.join(os.getcwd(), 'ffmpeg'), ' '.join(arguments))
# self.process.finished.connect(self.mergeFinished(self.process))
# process.destroyed.connect(self.onProcessDestroyed)
if self.process.state()==QProcess.NotRunning:
self.process.start(os.path.join(os.getcwd(), 'ffmpeg'), arguments)
else:
self.process.tasks.add(sourceUrl)
#I write the slot of QClipboard::dataChanged() as this to avoid the bug,
@pyqtSlot()
def detectClipboardUrl(self):
clipboardText = self.clipboard.text()
if getattr(self.clipboard, 'lastClipboardUrl', None) != clipboardText:
url = clipboardText
setattr(self.clipboard, 'lastClipboardUrl', url)
QTimer.singleShot(400, lambda:setattr(self.clipboard, 'lastClipboardUrl', None))#the interval of successive call of this slot is less than 400ms, after 400ms this line would allow you copy the same Text again