【问题标题】:wxpython problems with binding windows toast notification handlerwxpython绑定windows toast通知处理程序的问题
【发布时间】:2020-05-31 15:08:46
【问题描述】:

我正在尝试制作一个 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'

【问题讨论】:

  • 你是从哪里得到那个event的名字的?我不相信它存在。您可能会将wx.adv.NotificationMessagenotify2 混淆,这是一个允许您添加操作的单独包。
  • @RolfofSaxony 我在 wxpython 网站 here 的文档中的“此类发出的事件”部分中找到了它。我可能误解了我对 python 还是新手的文档,所以我很有可能将它与一些我也想使用的 AddAction 命令混合在一起,但我找不到任何关于它的信息,它只写在文档中它需要一个 actionID 和一个标签,但我什至不知道什么是 actionID

标签: python notifications wxpython


【解决方案1】:

不想肯定地说NotificationMessage 是未完成的事情,我将建议它。

我怀疑它基于 notifynotify2 声称支持 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()

【讨论】:

  • welp 我发现微软网站上有docs 我得到了它的工作,但我对c#或c++一无所知,所以我必须做更多的研究才能让它工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-17
  • 1970-01-01
  • 1970-01-01
  • 2015-04-20
  • 2013-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多