我正在尝试将一个 blob 保存到 localforage,然后检索它并显示它。它在一段时间内工作正常,但在几次页面刷新或浏览器关闭后,我在某些 blob 上收到错误。完整错误如下:
\nFailed to load resource: The operation couldn\xe2\x80\x99t be completed. (WebKitBlobResource error 1.)\nRun Code Online (Sandbox Code Playgroud)\n这是我的其余代码。将项目保存到 localforage:
\ncanvas.toBlob(function(blob){\n allItems.push({"string":string,"blob":blob});\n localforage.setItem("savedItems",allItems);\n},"image/jpeg",0.02);\nRun Code Online (Sandbox Code Playgroud)\n从 localforage 加载项目:
\nlocalforage.getItem("savedItems").then(function(jsonData){\n if(jsonData==null){allItems=[];}\n else{allItems=jsonData;}\n});\nRun Code Online (Sandbox Code Playgroud)\n将 blob 添加到图像源:
\nlet thisURL = window.URL || window.webkitURL;\nlet url=thisURL.createObjectURL(allItems[k]['blob']);\nimg.src=url;\nRun Code Online (Sandbox Code Playgroud)\n这似乎是 Safari 特有的问题,因为我无法在 Chrome 中复制它。
\n我正在尝试模拟鼠标动画。我想动态设置位置,然后用 css 过渡移动它。到目前为止,我能够得到一个移动鼠标的程序。但是,我无法使用 javascript 动态设置初始位置。我的代码如下所示:
这是CSS
.cursorDiv {
width: 30px;
height: 30px;
transform: translate(0px,0px);
transition: 2s ease;
}
.cursorDivMoved {
transform: translate(100px,200px);
}
Run Code Online (Sandbox Code Playgroud)
这是javascript:
var cursorDiv = document.createElement("img");
cursorDiv.className = "cursorDiv";
cursorDiv.src="https://cdn2.iconfinder.com/data/icons/windows-8-metro- style/512/cursor.png";
document.body.appendChild(cursorDiv);
setTimeout(function() {
$(".cursorDiv").toggleClass("cursorDivMoved");
}, 1000);
//cursorDiv.style.transform="translate(100px,50px)";
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它工作正常。但是,当我尝试使用 javascript(取消注释最后一行)更改初始位置时,不再发生转换。
这是一个演示:
我正在尝试在 python 枕头中进行一些图像堆叠。我想做的是拍摄大量图像(比如 10 张),然后对于每个像素,取这样的中值:http : //petapixel.com/2013/05/29/a-look-at -减少照片中的噪点-使用中值混合/。
现在,我可以以令人难以置信的蛮力方式(使用 getpixel 和 put pixel)来完成它,但这需要很长时间。
这是我到目前为止所拥有的:
import os
from PIL import Image
files = os.listdir("./")
new_im = Image.new('RGB', (4000,3000))
ims={}
for i in range(10,100):
ims[i]={}
im=Image.open("./"+files[i])
for x in range(400):
ims[i][x]={}
for y in range(300):
ims[i][x][y]=im.getpixel((x,y))
for x in range(400):
for y in range(300):
these1=[]
these2=[]
these3=[]
for i in ims:
these1.append(ims[i][x][y][0])
these2.append(ims[i][x][y][1])
these3.append(ims[i][x][y][2])
these1.sort()
these2.sort()
these3.sort()
new_im.putpixel((x,y),(these1[len(these1)/2],these2[len(these2)/2],these3[len(these3)/2]))
new_im.show()
Run Code Online (Sandbox Code Playgroud) 我正在处理大型嵌套词典,并试图删除嵌套的子词典。我想知道为什么会发生以下行为。
当我设置对字典 d 的引用(称为 ref),然后更改 ref 并打印 d 时,它会显示添加了第三个元素的 d 的更新版本。
input:
d={"a":1,"b":2}
ref=d
ref["c"]=3
print(d)
output:
{'a': 1, 'b': 2, 'c': 3}
Run Code Online (Sandbox Code Playgroud)
鉴于这种行为,我希望能够通过 delete 删除字典
input:
d={"a":1,"b":2}
ref=d
del ref
print(d)
output:
{'a': 1, 'b': 2}
Run Code Online (Sandbox Code Playgroud)
我想知道删除引用时是否有删除原始对象的方法(意味着第二个程序的输出将是错误的,因为d被删除了。
我有一个简单的例子,用户开始在触摸屏上滚动,然后一秒钟后,我想禁用滚动。我认为 event.preventDefault() 会停止滚动,但在滚动开始后它似乎不起作用
这是一个例子:https : //jsfiddle.net/7s5m8c6L/30/
let allowScroll=true;
function TS(e){//touchstart handler
setTimeout(function(){
allowScroll=false;
},1000)
}
function TM(e){//touchmove handler
if(!allowScroll){
e.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,你可以开始滚动,一秒钟后,我希望滚动停止,但它没有。我知道有很多方法可以让它与 CSS 一起工作(添加溢出:隐藏),但我特别想知道为什么 preventDefault 不起作用。
我是Tkinter的新手,所以如果这很容易我道歉,但我已经搜索了几个小时而无法弄明白.我想要做的是在mainloop空闲之后,我总是想调用函数checkForGroupUpdates().当我运行下面的代码时,它只运行一次.我不知道每次主循环空闲时它都会运行.我很感激帮助.
from Tkinter import *
import random
class Network(Frame):
""" Implements a stop watch frame widget. """
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
self.makeWidgets()
def makeWidgets(self):
""" Make the time label. """
self._canvas = Canvas(self, width=600, height=400)
self._canvas.pack()
def checkForGroupUpdates(self):
print "checking"
h=0
this=10
while this>.0001:
this=random.random()
print h
h=h+1
print "checked"
def main():
root = Tk()
nw = Network(root)
nw.pack(side=TOP)
root.after_idle(nw.checkForGroupUpdates)
root.mainloop()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud) 我无法使文本溢出省略号在CSS网格中工作。文本被截断,但省略号不显示。这是我的CSS:
.grid {
display: grid;
margin: auto;
width: 90%;
grid-template-columns: 2fr 15fr
}
.gridItem {
border: 1px solid red;
display: flex;
height: calc(50px + 2vw);
align-items: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}Run Code Online (Sandbox Code Playgroud)
<div class="grid">
<div class="gridItem">Why no ellipsis on this div?</div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
<div class="gridItem"></div>
</div>Run Code Online (Sandbox Code Playgroud)
我在终端中运行以下行:
say "hello, this is the computer talking" --interactive
Run Code Online (Sandbox Code Playgroud)
当我运行此命令时,计算机会说出带引号的单词,并在说出单词时突出显示这些单词。我想做的是获取每个口语的时间。例如:
我想知道是否有任何方法可以编写与行的输出进行交互的bash脚本。
我在 pyqt 中有一个 python 程序,其中有一个带有以下按钮的按钮:
this=[1,k]
button.clicked.connect(lambda x=this:self.testFunction(str(x)))
Run Code Online (Sandbox Code Playgroud)
当我按下按钮,我得到testFunction(False)相当testFunction(str([1,k]))。任何想法为什么?提前致谢。
我有几个python脚本都以相同的行开头,我希望能够只更改一次行.
例如这样的事情:
import pickle
import sys
sys.path.append("/Users/user/folder/")
import someOtherModules
x=someOtherModules.function()
Run Code Online (Sandbox Code Playgroud)
我知道我可以将其保存为字符串,然后加载字符串并运行exec()命令,但我想知道是否有更好的方法来执行此操作.
换句话说,我想导入一个模块列表并在每个脚本的开头运行一些函数.