jithurjacob / Windows-10-Toast-Notifications

Python library to display Windows 10 Toast Notifications
MIT License
970 stars 168 forks source link

PyQt5 Windows closes with notification close #19

Open studiozeroseven opened 7 years ago

studiozeroseven commented 7 years ago

I have a simple Qt window it has a button and when you click the button it opens a explorer window for a specific location, when the notification fades out the window closes as well.

Entire Example Script `class Example(QWidget):

def __init__(self):
    super().__init__()
    self.initUI()

@pyqtSlot()
def on_click(self):
    print('PyQt5 button click')
    subprocess.Popen(r'explorer /open,"C:\WB Resources\"')
    toaster = ToastNotifier()
    toaster.show_toast("TITLE",
                       "Python is 10 seconds awsm! and I think that this is the way to go for all information going forward",
                       icon_path="wbicon.ico",
                       duration=3)
    print('Finished?')

def on_click_cache(self):
    path = "C:/Users/XXXXX/AppData/Local/Packages/XXXXXXXXXXXX_XXXXXXXXXXXX/LocalState/cacheddata/"
    try:
        shutil.rmtree(path)
    except:
        print('No folder')

    self.btn_clearcache.setStyleSheet("background-color: green")

def initUI(self):

    QToolTip.setFont(QFont('SansSerif', 10))

    btn = QPushButton('Open WBR',self)
    btn.setToolTip('This is a <b>QPushButton</b> widget')
    btn.resize(150,50)
    btn.move(0, 0)
    btn.clicked.connect(self.on_click)

    self.btn_clearcache = QPushButton('Clear Cache', self)
    self.btn_clearcache.setToolTip('Clear the WB App Cache<br><b>THIS IS DESTRUCTIVE</b>')
    self.btn_clearcache.resize(150,50)
    self.btn_clearcache.move(151, 0)
    self.btn_clearcache.setStyleSheet("QPushButton:focus:pressed { background-color: red }")
    self.btn_clearcache.clicked.connect(self.on_click_cache)

    self.setGeometry(500, 350, 900, 500)
    self.setWindowTitle('WB-TOOL')
    self.setWindowIcon(QIcon('arrow.png'))
    self.show()

if name == 'main': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())`

jithurjacob commented 7 years ago

Hi @studiozeroseven thank you for raising the issue.

I will look look into this and revert back.

jithurjacob commented 7 years ago

@studiozeroseven Apologies for the delay I was caught up in work.

Please confirm if you still facing the issue and need help.

I'm not able to recreate this in my Python 3.5 environment. If you need help, could you please provide the PyQt version you are using and also the imports.

ayy1337 commented 7 years ago

Hi, I'm getting the same thing. PyQt5 is latest version from pip, on python3. Imports look as follows:

from PyQt5 import QtGui, QtCore, QtWidgets import sys, os, shelve, time, threading, random, operator, copy, datetime, os, collections from operator import attrgetter, itemgetter from random import randint from win10toast import ToastNotifier from playsound import playsound

jithurjacob commented 7 years ago

Hi guys, I've sourced the issue in line 136 init.py in the library. Disabling PostQuitMessage(0) seems to fix the issue. I'm not sure of how this will affect the usage. If you have any experience in this please give your suggestion. I'll be investigating this further before pushing a change.

ayy1337 commented 7 years ago

Heyo. Commenting out that line seemed to fix the crashing. The sleep(duration) a few lines before that hangs the program for a few seconds so I commented that out also.

MolotovCherry commented 5 years ago

Just want to add my 2 cents. I'm using PySide2 (which is basically PyQt5, so what I say should apply to PyQt5), and I was getting this problem as well with it crashing the app. Using multithreaded option works perfectly.

Please verify this. The issue should be fixed already.

Use threaded = True to fix the issue

-- Probably the issue here is that this module doesn't interface with the Qt event loop. @author, you might be able to fix this blocking issue by periodically taking breaks in a loop (that ultimately waits the entire 5 seconds, or however long) to call QApplication.processEvents().

-- But there's no need to try to make it Qt compatible. The correct way this should be done is by using another thread, and this is already the case. So this issue is now solved