python - wxpython绑定windows toast通知处理程序的问题
问题描述
我正在尝试制作一个 Windows 10 toast 通知,如果它被点击,它将运行代码,但我的代码只显示通知并在我点击它时给我一个错误
import os
import wx
import wx.adv
class MyApp(wx.App):
def OnInit(self):
sTitle = 'test'
sMsg = 'test'
nmsg = wx.adv.NotificationMessage(title=sTitle, message=sMsg)
nmsg.SetFlags(wx.ICON_INFORMATION)
nmsg.Show(timeout=wx.adv.NotificationMessage.Timeout_Auto)
self.Bind(wx.EVT_NOTIFICATION_MESSAGE_CLICK, self.notifclicked)
return True
def _notifclicked(self, evt):
print("notification has been clicked")
app = MyApp()
app.MainLoop()
错误代码:AttributeError:模块'wx'没有属性'EVT_NOTIFICATION_MESSAGE_CLICK'
解决方案
不想肯定地说那NotificationMessage
是未完成的事情,我将建议它。
我怀疑它基于notify
并且notify2
声称支持action
回调但不支持。
他们应该依赖 Dbus 发送东西,但它看起来不像它,或者你必须跳过箍来实现它。(例如 Dbus MainLoop 设置)
我决定稍微修改你的代码,只是为了展示如何添加action
按钮,尽管它们只是吸引眼球,并展示我认为事件回调应该如何工作,如果它成为现实的话。
当然,如果它目前确实有效并且我还没有弄清楚如何去做,我会很高兴地吃掉这些话。我专门在 Linux 上编写代码,因此需要注意。
import wx
import wx.adv
Act_Id_1 = wx.NewIdRef()
Act_Id_2 = wx.NewIdRef()
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=wx.ID_ANY, title="", size=(360,100)):
super(MyFrame, self).__init__(parent, id, title, size)
self.m_no = 0
self.panel = wx.Panel(self)
self.Mbutton = wx.Button(self.panel, wx.ID_ANY, label="Fire off a message", pos=(10,10))
self.Bind(wx.EVT_BUTTON, self.OnFire, self.Mbutton)
#self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_CLICK, self._notifclicked)
#self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_DISMISSED, self._notifdismissed)
#self.Bind(wx.adv.EVT_NOTIFICATION_MESSAGE_ACTION, self._notifaction, id=Act_Id_1)
self.Show()
def OnFire(self, event):
self.m_no +=1
sTitle = 'Test heading'
sMsg = 'Test message No '
nmsg = wx.adv.NotificationMessage(title=sTitle, message=sMsg+str(self.m_no))
nmsg.SetFlags(wx.ICON_INFORMATION)
nmsg.AddAction(Act_Id_1, "Cancel")
nmsg.AddAction(Act_Id_2, "Hold")
nmsg.Show(timeout=10)
def _notifclicked(self, event):
print("notification has been clicked")
def _notifdismissed(self, event):
print("notification dismissed")
def _notifaction(self, event):
print("Action")
app = wx.App()
frame = MyFrame()
app.MainLoop()
推荐阅读
- osgi - 如何在 Apache Felix 中安排服务?
- html - 自闭元素的另一种说法是什么(2个词)(第一个字母以e开头)
- junit - 参数化单例类测试
- python - 如何退出while循环?
- javascript - 为什么使用 codekit 和基础 zurb 时 javascript 停止工作?
- c++ - 具有可分离程序的 OpenGL 统一块绑定
- jupyter-notebook - 如何保存 Jupyter Notebook 的输出?
- c# - dotnet core OData 3.1 - 不返回正确的记录
- javascript - 遍历嵌套数组对象
- algorithm - 如何以某种方式对随机数进行评分,数字越低,它给出的分数就越多?