Форум сайта python.su
Помогите пожалуйста разобраться в чем ошибка, необходимо получать URL через rabbit, рендерить его и печатать pdf
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import sys, pika, threading
class RabThread(threading.Thread):
def run(self):
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='pdf_render')
def callback(ch, method, properties, body):
print "[x] callback Received %r" % (body,)
url_load(body)
channel.basic_consume(callback,queue='pdf_render',no_ack=True)
channel.start_consuming()
if __name__=="__main__":
def url_load(url_str):
print "[+] rabbit taken url:",url_str
web.load(QUrl(url_str))
return 0
def printIt():
print "[*] Page print"
web.print_(printer)
return 0
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("http://gmail.com"))
web.show()
printer = QPrinter()
printer.setPageSize(QPrinter.A4)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("tmp.pdf")
RabThread().start()
QObject.connect(web, SIGNAL("loadFinished(bool)"), printIt)
sys.exit(app.exec_())
[*] Page print
[x] callback Received 'http://site.com'
QObject: Cannot create children for a parent that is in a different thread.
[+] rabbit taken url: http://site.com
(Parent is QNetworkAccessManager(0x2e60aa0), parent's thread is QThread(0x2a42ef0), current thread is QThread(0x331a0e0)
Отредактировано (Июнь 12, 2011 14:03:15)
Офлайн