<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 09/16/2013 10:58 AM, Ryan Hanson
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAGHrRC5dQusC+zoLw6H1Vh=ai=V94G6ePFgN35TYGv1SFaHqRw@mail.gmail.com"
      type="cite">
      <div dir="ltr">On Mon, Sep 16, 2013 at 10:19 AM, Patrick Barrett <span
          dir="ltr"><<a moz-do-not-send="true"
            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 moz-do-not-send="true"
                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 moz-do-not-send="true"
                  href="https://portals.exosite.com/views/3819798770/3579834479">https://portals.exosite.com/views/3819798770/3579834479</a>",</div>
              <div>      "<a moz-do-not-send="true"
                  href="https://portals.exosite.com/views/2562112089/4128069106">https://portals.exosite.com/views/2562112089/4128069106</a>",</div>
              <div>      "<a moz-do-not-send="true"
                  href="https://portals.exosite.com/views/2060811893/1760385000">https://portals.exosite.com/views/2060811893/1760385000</a>",</div>
              <div>      "<a moz-do-not-send="true"
                  href="https://exosite:AKYQhkDqj4@logs.exosite.com:444">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>
    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 class="moz-txt-link-freetext" href="https://gist.github.com/Azdle/6556433">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!<br>
    <br>
    --Patrick<br>
  </body>
</html>