python - Why doesn't this pyside window disappear? -


i looking way cross-platform notification, here code cross-platform desktop notifier in python , modification make runable:

# uitoast.py pyside import qtcore, qtgui class ui_mainwindow(object):     def setupui(self, mainwindow):         mainwindow.resize(547, 96)         palette = qtgui.qpalette()         brush = qtgui.qbrush(qtgui.qcolor(255, 255, 255))         brush.setstyle(qtcore.qt.solidpattern)         palette.setbrush(qtgui.qpalette.active, qtgui.qpalette.base, brush)         brush = qtgui.qbrush(qtgui.qcolor(255, 170, 0))         brush.setstyle(qtcore.qt.solidpattern)         palette.setbrush(qtgui.qpalette.active, qtgui.qpalette.window, brush)         mainwindow.setpalette(palette)         self.centralwidget = qtgui.qwidget(mainwindow)         self.display = qtgui.qtextbrowser(self.centralwidget)         self.display.setgeometry(qtcore.qrect(0, 0, 551, 101))         palette = qtgui.qpalette()         brush = qtgui.qbrush(qtgui.qcolor(255, 170, 0))         brush.setstyle(qtcore.qt.solidpattern)         palette.setbrush(qtgui.qpalette.active, qtgui.qpalette.base, brush)         self.display.setpalette(palette)         font = qtgui.qfont()         font.setpointsize(12)         self.display.setfont(font)         mainwindow.setcentralwidget(self.centralwidget)   #!/usr/bin/env python3 import sys, time pyside import qtcore, qtgui import uitoast  window = none   # global  # usage: toast('message') class toast(qtgui.qmainwindow):     def __init__(self, msg):         global window               # space outside local stack         window = self               # save pointer till killed avoid gc         qtgui.qmainwindow.__init__(self)         self.setwindowflags(qtcore.qt.framelesswindowhint)         self.ui = uitoast.ui_mainwindow()         self.ui.setupui(self)          self.ui.display.settext(msg)          self.toastthread = toastthread()    # start thread remove display         self.connect(self.toastthread, qtcore.signal("finished()"), self.toastdone)         self.toastthread.start()         self.show()      def toastdone(self):         global window         window = none               # kill pointer window object close , gc  class toastthread(qtcore.qthread):     def __init__(self):         qtcore.qthread.__init__(self)      def run(self):         time.sleep(2.0)             # wait , die    if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     program = toast("hi")     program.show()     sys.exit(app.exec_()) 

the problem pop window, supposed disappear in 2 seconds, hanging forever.

the window isn't "hanging" - it's code attempts close window pure nonsense.

setting window none not delete object, because assigned name program when created, , reference continue exist after toastdone method called.

what should instead connect thread's finished signal window's close slot. try this:

class toast(qtgui.qmainwindow):     def __init__(self, msg):         qtgui.qmainwindow.__init__(self)         self.setwindowflags(qtcore.qt.framelesswindowhint)         self.ui = uitoast.ui_mainwindow()         self.ui.setupui(self)         self.ui.display.settext(msg)         self.toastthread = toastthread()         self.toastthread.finished.connect(self.close)         self.toastthread.start()  class toastthread(qtcore.qthread):     def run(self):         time.sleep(2.0) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -