我可以将我的事件处理程序附加到React组件.有没有办法在事件处理程序中获取对此组件的引用?
var Foobar = React.createClass({
action: function () {
// ...
},
render: function () {
var child = React.Children.only(this.props.children),
props = _.omit(this.props, 'children');
return React.addons.cloneWithProps(child, props);
}
});
var App = React.createClass({
handleMouseEnter: function (event) {
// How to get reference to Foobar without using this.refs['foo']?
// I need to call *action* on it.
},
render: function () {
return (
<div>
<Foobar ref="foo" onMouseEnter={this.handleMouseEnter}>
...
</Foobar>
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud) 我正在使用PIL1.1.7在Python 2.7中对图像处理器进行原型设计,我希望所有图像都以JPG结尾.输入文件类型将包括透明和没有的tiff,gif,png.我一直在尝试组合两个脚本,我发现1.将其他文件类型转换为JPG和2.通过创建空白图像并将原始图像粘贴到白色背景上来消除透明度.我的搜索是垃圾邮件,人们试图产生或保持透明度,而不是相反.
我正在使用这个:
#!/usr/bin/python
import os, glob
import Image
images = glob.glob("*.png")+glob.glob("*.gif")
for infile in images:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
if infile != outfile:
#try:
im = Image.open(infile)
# Create a new image with a solid color
background = Image.new('RGBA', im.size, (255, 255, 255))
# Paste the image on top of the background
background.paste(im, im)
#I suspect that the problem is the line below
im = background.convert('RGB').convert('P', palette=Image.ADAPTIVE)
im.save(outfile)
#except IOError:
# print "cannot convert", …Run Code Online (Sandbox Code Playgroud) 在Java中,我会做类似的事情:
Thread t = new MyThread();
t.start();
Run Code Online (Sandbox Code Playgroud)
我通过调用start()方法启动线程.所以后来我可以这样做:
for (int i = 0; i < limit; ++i)
{
Thread t = new MyThread();
t.start();
}
Run Code Online (Sandbox Code Playgroud)
创建一组线程并在run()方法中执行代码.
但是,在C++中,没有start()方法.使用Boost,如果我想要一个线程开始运行,我必须调用join()方法才能使线程运行.
#include <iostream>
#include <boost/thread.hpp>
class Worker
{
public:
Worker()
{
// the thread is not-a-thread until we call start()
}
void start(int N)
{
m_Thread = boost::thread(&Worker::processQueue, this, N);
}
void join()
{
m_Thread.join();
}
void processQueue(unsigned N)
{
float ms = N * 1e3;
boost::posix_time::milliseconds workTime(ms);
std::cout << "Worker: started, will work …Run Code Online (Sandbox Code Playgroud) 我遇到Qt4到Qt5的麻烦.在我的应用程序中,当用户点击打印按钮时,应该发生两件事,一件是PDF写入磁盘(在新版本中仍能正常工作,因此我知道某些打印功能正常工作)而另一件是一个QPrintDialog应该exec()然后发送到连接的打印机.
我从开发机器启动时看到对话框.应用程序在已部署的计算机上启动,但QPrintDialog从不显示,文档永远不会打印.
我包括印刷支持.
QT += core gui network webkitwidgets widgets printsupport
Run Code Online (Sandbox Code Playgroud)
我一直在使用Process Explorer来查看应用程序在我的开发机器上使用的DLL,我相信一切都存在.我的应用程序包包括:
以下是相关的代码段:
void PrintableForm::printFile()
{
//Writes the PDF to disk in every environment
pdfCopy();
//Paper Copy only works on my dev machine
QPrinter paperPrinter;
QPrintDialog printDialog(&paperPrinter,this);
if( printDialog.exec() == QDialog::Accepted ) {
view->print(&paperPrinter);
}
this->accept();
}
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是没有找到相关的DLL到打印时间,这意味着我的应用程序文件系统不正确,但我没有发现任何显示我不同的文件结构.我是在正确的轨道上还是这个设置还有其他问题?