[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] A Hopefully Silly Question from a Beginner
From: Ryan Hanson <crossrocker () gmail ! com>
Date: 2013-09-16 17:34:52
Message-ID: CAGHrRC71BLBdOTm9L4AmwMNTq4PmCXgv2fqJaogH6ruFo6S0BQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On Mon, Sep 16, 2013 at 12:18 PM, Patrick Barrett <patrick@mkii.org> wrote:
> On 09/16/2013 10:58 AM, Ryan Hanson wrote:
>
> On Mon, Sep 16, 2013 at 10:19 AM, Patrick Barrett <patrick@mkii.org>wrote:
>
>> I'm trying to write a small app the generates a few QWebView windows and
>> then rotates the page that is displayed on a set interval.
>>
>> Code: https://gist.github.com/Azdle/6556433
>>
>> I've run into an issue that I don't understand. When I try to generate a
>> `PageWindow` (Class based on QWebView) from within my `MainWindow` class
>> nothing appears. (See the code in 29-30) However, when I copy and paste
>> that code outside of any classes the window appears as it should. (See the
>> commented code in 56-57)
>>
>> Even when I can make the QWebView window appear, the QTimer object that I
>> create in the `PageWindow` never seems to timeout. I think this is being
>> caused by the same issue as the first problem.
>>
>> I'm not sure if the issues are me doing the python wrong or just not
>> understanding something about how the Qt-specfic aspects work. I have this
>> application already working in C++, but want to get it working in Python.
>>
>> Thanks
>> --Patrick
>>
>>
> Here you go Patrick, you want to move your timer into your main class
> and then call your new page function on the instance of PageWindow that you
> create inside that class.
>
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from PyQt4.QtWebKit import *
>
> pages = [
> "https://portals.exosite.com/views/3819798770/3579834479",
> "https://portals.exosite.com/views/2562112089/4128069106",
> "https://portals.exosite.com/views/2060811893/1760385000",
> "https://exosite:AKYQhkDqj4@logs.exosite.com:444"
> ]
>
> class MainWindow(QMainWindow):
>
> def __init__(self, *args):
> QMainWindow.__init__(self)
>
> self.quitButton = QPushButton("Quit")
> vbox = QVBoxLayout()
> vbox.addWidget(self.quitButton)
> centralWidget = QWidget()
> centralWidget.setLayout(vbox)
> self.setCentralWidget(centralWidget)
>
> self.quitButton.clicked.connect(self.close)
>
> self.pageView = PageWindow()
> self.pageView.show()
>
> self.pageTimer = QTimer()
> self.pageTimer.timeout.connect(self.pageView.nextPage)
> self.pageTimer.start(5000)
>
> def closeEvent(self, event):
> self.pageTimer.stop()
> self.pageView.close()
> event.accept()
>
> class PageWindow(QWebView):
> def __init__(self):
> QWebView.__init__(self)
>
> self.pageIndex = 0
> self.nextPage()
> self.setGeometry(QApplication.desktop().screenGeometry(1))
> self.showFullScreen()
>
> def nextPage(self):
> print("Loading:"+pages[self.pageIndex])
> self.load(QUrl(pages[self.pageIndex]))
> self.pageIndex = self.pageIndex + 1
> if self.pageIndex >= len(pages):
> self.pageIndex = 0
>
> def main(args):
> app = QApplication(args)
> win = MainWindow()
> win.show()
> app.connect(app, SIGNAL("lastWindowClosed()"),
> app, SLOT("quit()"))
> app.exec_()
>
> if __name__=="__main__":
> main(sys.argv)
>
>
> Thanks Ryan. I ended up moving the timer object back into the `PageWindow`
> class.
>
> Added a new revision to the old Gist:
> https://gist.github.com/Azdle/6556433
>
> I see from your code that my issue was that I was putting object in local
> scope instead of putting them in the object (using var instead of self.var,
> my terminology is probably wrong) so the objects were getting garbage
> collected right after getting created.
>
> Thanks for your help!
>
> --Patrick
>
Glad you got it working
[Attachment #5 (text/html)]
<div dir="ltr">On Mon, Sep 16, 2013 at 12:18 PM, Patrick Barrett <span \
dir="ltr"><<a href="mailto:patrick@mkii.org" \
target="_blank">patrick@mkii.org</a>></span> wrote:<br><div \
class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><div><div class="h5">
<div>On 09/16/2013 10:58 AM, Ryan Hanson
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">On Mon, Sep 16, 2013 at 10:19 AM, Patrick Barrett <span \
dir="ltr"><<a href="mailto:patrick@mkii.org" \
target="_blank">patrick@mkii.org</a>></span> wrote:<br>
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I'm
trying to write a small app the generates a few QWebView
windows and then rotates the page that is displayed on a
set interval.<br>
<br>
Code: <a href="https://gist.github.com/Azdle/6556433" \
target="_blank">https://gist.github.com/Azdle/6556433</a><br> <br>
I've run into an issue that I don't understand. When I try
to generate a `PageWindow` (Class based on QWebView) from
within my `MainWindow` class nothing appears. (See the
code in 29-30) However, when I copy and paste that code
outside of any classes the window appears as it should.
(See the commented code in 56-57)<br>
<br>
Even when I can make the QWebView window appear, the
QTimer object that I create in the `PageWindow` never
seems to timeout. I think this is being caused by the same
issue as the first problem.<br>
<br>
I'm not sure if the issues are me doing the python wrong
or just not understanding something about how the
Qt-specfic aspects work. I have this application already
working in C++, but want to get it working in Python.<br>
<br>
Thanks<br>
--Patrick<br>
<br>
</blockquote>
<div><br>
</div>
<div>Here you go Patrick, you want to move your timer into
your main class and then call your new page function on
the instance of PageWindow that you create inside that
class.</div>
<div><br>
</div>
<div>
<div>import sys</div>
<div>from PyQt4.QtCore import *</div>
<div>from PyQt4.QtGui import *</div>
<div>from PyQt4.QtWebKit import *</div>
<div> </div>
<div>pages = [</div>
<div> "<a \
href="https://portals.exosite.com/views/3819798770/3579834479" \
target="_blank">https://portals.exosite.com/views/3819798770/3579834479</a>",</div>
<div> "<a href="https://portals.exosite.com/views/2562112089/4128069106" \
target="_blank">https://portals.exosite.com/views/2562112089/4128069106</a>",</div>
<div> "<a href="https://portals.exosite.com/views/2060811893/1760385000" \
target="_blank">https://portals.exosite.com/views/2060811893/1760385000</a>",</div>
<div> "<a href="https://exosite:AKYQhkDqj4@logs.exosite.com:444" \
target="_blank">https://exosite:AKYQhkDqj4@logs.exosite.com:444</a>"</div> \
<div>]</div> <div> </div>
<div>class MainWindow(QMainWindow):</div>
<div> </div>
<div>
def __init__(self, *args):</div>
<div> QMainWindow.__init__(self)</div>
<div> </div>
<div> self.quitButton = QPushButton("Quit")</div>
<div> vbox = QVBoxLayout()</div>
<div> vbox.addWidget(self.quitButton)</div>
<div> centralWidget = QWidget()</div>
<div> centralWidget.setLayout(vbox)</div>
<div> self.setCentralWidget(centralWidget)</div>
<div> </div>
<div> self.quitButton.clicked.connect(self.close)</div>
<div> </div>
<div> self.pageView = PageWindow()</div>
<div> self.pageView.show()</div>
<div> </div>
<div> self.pageTimer = QTimer()</div>
<div>
self.pageTimer.timeout.connect(self.pageView.nextPage)</div>
<div> self.pageTimer.start(5000)</div>
<div>
</div>
<div> def closeEvent(self, event):</div>
<div> self.pageTimer.stop()</div>
<div> self.pageView.close()</div>
<div> event.accept()</div>
<div> </div>
<div>class PageWindow(QWebView):</div>
<div>
def __init__(self):</div>
<div> QWebView.__init__(self)</div>
<div> </div>
<div> self.pageIndex = 0</div>
<div> self.nextPage()</div>
<div>
self.setGeometry(QApplication.desktop().screenGeometry(1))</div>
<div> self.showFullScreen()</div>
<div> </div>
<div> def nextPage(self):</div>
<div> print("Loading:"+pages[self.pageIndex])</div>
<div> self.load(QUrl(pages[self.pageIndex]))</div>
<div> self.pageIndex = self.pageIndex + 1</div>
<div> if self.pageIndex >= len(pages):</div>
<div> self.pageIndex = 0</div>
<div> </div>
<div>def main(args):</div>
<div> app = QApplication(args)</div>
<div> win = MainWindow()</div>
<div> win.show()</div>
<div> app.connect(app, SIGNAL("lastWindowClosed()"),</div>
<div> app, SLOT("quit()"))</div>
<div> app.exec_()</div>
<div> </div>
<div>if __name__=="__main__":</div>
<div> main(sys.argv)</div>
</div>
</div>
</div>
</div>
</blockquote>
<br></div></div>
Thanks Ryan. I ended up moving the timer object back into the
`PageWindow` class. <br>
<br>
Added a new revision to the old Gist:
<a href="https://gist.github.com/Azdle/6556433" \
target="_blank">https://gist.github.com/Azdle/6556433</a><br> <br>
I see from your code that my issue was that I was putting object in
local scope instead of putting them in the object (using var instead
of self.var, my terminology is probably wrong) so the objects were
getting garbage collected right after getting created.<br>
<br>
Thanks for your help!<span class="HOEnZb"><font color="#888888"><br>
<br>
--Patrick<br>
</font></span></div>
</blockquote></div><br></div><div class="gmail_extra">Glad you got it \
working</div></div>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic