【发布时间】:2021-09-09 09:27:34
【问题描述】:
我正在开发一个 pyqt5 Trayicon 应用程序,需要添加一个更新功能,我使用 python apscheduler 创建了一个调度程序,该调度程序在后台运行并检查更新。我面临的问题是当更新可用时,我需要显示一个弹出窗口以征得用户同意安装更新,但是每当调用弹出功能时,控制台中都会显示此消息并且应用程序崩溃或停止工作。
NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future.
我的代码sn-p供参考:
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
....
def show_popup(self,message):
msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Information)
msgBox.setText(message)
msgBox.setWindowTitle("QMessageBox Example")
msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msgBox.buttonClicked.connect(self.msgButtonClick)
returnValue = msgBox.exec()
if returnValue == QMessageBox.Ok:
return True
return False
def startUpdateScheduler(self):
scheduler = BackgroundScheduler()
scheduler.add_job(checkUpdate, 'interval', seconds=5)
scheduler.start()
def checkUpdate(self):
if(updatesAvailable):
installUpdates(self.show_popup("DeviceHub updates are available\n Do you want to install?")
【问题讨论】:
标签: python macos pyqt5 python-3.8 apscheduler