Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19529
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!news.mixmin.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jjposner@optimum.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'url:mit': 0.07; '__name__': 0.09; 'header:In-reply-to:1': 0.09; 'pages.': 0.09; 'resp': 0.09; 'def': 0.13; 'gui': 0.13; 'subject:application': 0.15; '"__main__":': 0.16; 'me"': 0.16; 'received:167.206.4': 0.16; 'received:cv.net': 0.16; 'received:hcvlny.cv.net': 0.16; 'received:srv.hcvlny.cv.net': 0.16; 'retrieves': 0.16; 'subject:PyQt': 0.16; 'twice.': 0.16; 'url:pastebin': 0.16; 'wrote:': 0.16; 'instance': 0.18; 'once,': 0.18; 'to:2**1': 0.21; 'skip:m 30': 0.24; 'code': 0.25; 'module': 0.26; 'import': 0.27; 'url:edu': 0.27; 'script.': 0.28; 'print': 0.29; 'skip:b 20': 0.29; 'times.': 0.30; 'fails.': 0.30; "i've": 0.31; 'app': 0.31; "can't": 0.32; 'done': 0.33; 'header:User-Agent:1': 0.33; 'to:addr :python-list': 0.33; 'object': 0.33; 'creates': 0.34; 'loop': 0.34; 'hi,': 0.34; 'question': 0.35; 'file': 0.35; 'ajax': 0.36; 'to:name:python-list': 0.36; 'but': 0.37; 'using': 0.37; '2nd': 0.38; 'event': 0.38; 'several': 0.38; 'put': 0.38; 'think': 0.38; 'received:192': 0.38; 'why': 0.39; 'either': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'john': 0.62; 'fact,': 0.63; 'below.': 0.63; 'here': 0.64; 'click': 0.79; 'webkit': 0.84; 'yielded': 0.84; 'click.': 0.91; 'url:test': 0.91 |
| Date | Fri, 27 Jan 2012 18:42:24 -0500 |
| From | John Posner <jjposner@optimum.net> |
| Subject | Re: calling a simple PyQt application more than once |
| In-reply-to | <CAOuJsMmyDArFXXCbNFPCiXPytPBOg8X5DHXRHxot8dmrwrwUjg@mail.gmail.com> |
| To | Jabba Laci <jabba.laci@gmail.com>, python-list <python-list@python.org> |
| MIME-version | 1.0 |
| Content-type | text/plain; charset=ISO-8859-1 |
| Content-transfer-encoding | 7BIT |
| X-Enigmail-Version | 1.3.5 |
| References | <CAOuJsMmyDArFXXCbNFPCiXPytPBOg8X5DHXRHxot8dmrwrwUjg@mail.gmail.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5161.1327709549.27778.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1327709549 news.xs4all.nl 6891 [2001:888:2000:d::a6]:60778 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19529 |
Show key headers only | View raw
Jabba Laci wrote:
> Hi,
>
> I have a simple PyQt application that creates a webkit instance to
> scrape AJAX web pages. It works well but I can't call it twice. I
> think the application is not closed correctly, that's why the 2nd call
> fails. Here is the code below. I also put it on pastebin:
> http://pastebin.com/gkgSSJHY .
>
> The question is: how to call this code several times within a script.
You want to create/execute/quit a QApplication just once, not multiple
times.
I don't know either WebKit or AJAX. In fact, I've never done any
networking with PyQt. But a little playing with the QtNetwork module
yielded this, using the QNetworkAccessManager and QNetworkRequest classes:
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QApplication, QPushButton
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
def process_page(reply_obj):
resp = reply_obj.readAll()
reply_obj.close()
print str(resp).strip()
def do_click():
req = QNetworkRequest(QUrl(MYURL))
mgr.finished.connect(process_page)
mgr.get(req)
MYURL = 'http://simile.mit.edu/crowbar/test.html'
if __name__ == "__main__":
# we need only one application object and one net-access mgr
app = QApplication([])
mgr = QNetworkAccessManager()
# the entire GUI is one button
btn = QPushButton("Press me")
btn.clicked.connect(do_click)
btn.show()
# start the event loop
app.exec_()
You can click the "Press me" button as many times as you wish; it
retrieves and displays/prints the same HTML file on each click.
HTH,
John
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: calling a simple PyQt application more than once John Posner <jjposner@optimum.net> - 2012-01-27 18:42 -0500
csiph-web