无法在 wxPython 中正确使用 wx.NotificationMessage
我最近升级到了 wxPython 的开发版本(wxPython 2.9.2.4),因为我需要在我的应用程序中使用 wx.NotificationMessage 的功能。由于我认为可能是一个错误,我一直在尝试在某些用户事件上创建通知气泡,但没有成功。在提交这样的错误之前,我想继续询问邮件列表中的人们他们认为可能是什么问题,并希望从我的代码中找到解决方案。
以下是我使用的代码:
import wx, sys
app = wx.PySimpleApp()
class TestTaskBarIcon(wx.TaskBarIcon):
def __init__(self):
wx.TaskBarIcon.__init__(self)
# create a test icon
bmp = wx.EmptyBitmap(16, 16)
dc = wx.MemoryDC(bmp)
dc.SetBrush(wx.RED_BRUSH)
dc.Clear()
dc.SelectObject(wx.NullBitmap)
testicon = wx.EmptyIcon()
testicon.CopyFromBitmap(bmp)
self.SetIcon(testicon)
self.Bind(wx.EVT_TASKBAR_LEFT_UP, lambda e: (self.RemoveIcon(),sys.exit()))
wx.NotificationMessage("", "Hello world!").Show()
icon = TestTaskBarIcon()
app.MainLoop()
在我的 Windows 7 计算机上,该代码创建一个白色的小任务栏图标,并创建一个带有短语“Hello World!”的弹出窗口。问题?该消息不在我的图标上。正在创建另一个图标,并将消息放置在那里。 看这张图片: http://www.pasteall.org/pic/18068">
我的想法是,这可能是由于我在第 22 行没有传递任何父参数:
wx.NotificationMessage("", "Hello world!").Show()
这是我将其更改为:
wx.NotificationMessage("", "Hello world!", self).Show()
Where 'self ' 指的是任务栏图标。当我这样做时,我得到一个错误:
Traceback (most recent call last):
File "C:\Python27\testnotificationmessage.py", line 24, in <module>
icon = TestTaskBarIcon()
File "C:\Python27\testnotificationmessage.py", line 22, in __init__
wx.NotificationMessage("", "Hello world!", self).Show()
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\_misc.py", line 1213, in __init__
_misc_.NotificationMessage_swiginit(self,_misc_.new_NotificationMessage(*args))
TypeError: in method 'new_NotificationMessage', expected argument 3 of type 'wxWindow *'
这是怎么回事?如果我删除该参数,我不会得到结果,如果我添加该参数,我会得到一个错误!应该使用wx.NotificationMessage 与 wx.TaskBarIcon!
请帮忙!如果您需要更多信息,请发表评论!
I recently upgraded to the development release of wxPython (wxPython 2.9.2.4) since I needed the functionality of wx.NotificationMessage within my application. I have been trying unsuccessfully to create notification bubbles on certain user events due to something I think might be a possible bug. Before submitting such bug, I wanted to go ahead and ask the people of the mailing list what they think might be the problem and hopefully find a solution from within my code.
Here is the code I have used:
import wx, sys
app = wx.PySimpleApp()
class TestTaskBarIcon(wx.TaskBarIcon):
def __init__(self):
wx.TaskBarIcon.__init__(self)
# create a test icon
bmp = wx.EmptyBitmap(16, 16)
dc = wx.MemoryDC(bmp)
dc.SetBrush(wx.RED_BRUSH)
dc.Clear()
dc.SelectObject(wx.NullBitmap)
testicon = wx.EmptyIcon()
testicon.CopyFromBitmap(bmp)
self.SetIcon(testicon)
self.Bind(wx.EVT_TASKBAR_LEFT_UP, lambda e: (self.RemoveIcon(),sys.exit()))
wx.NotificationMessage("", "Hello world!").Show()
icon = TestTaskBarIcon()
app.MainLoop()
On my Windows 7 computer, the code creates a small white task bar icon and creates a popup with the phrase "Hello World!". The problem? The message is not on my icon. Another icon is being created and the message is being placed there.
See this image:
http://www.pasteall.org/pic/18068">
What I thought was that this is probably due to the fact that I have passed no parent parameter on line 22:
wx.NotificationMessage("", "Hello world!").Show()
Here is what I changed it to:
wx.NotificationMessage("", "Hello world!", self).Show()
Where 'self' refers to the task bar icon. When I do that, I get an error:
Traceback (most recent call last):
File "C:\Python27\testnotificationmessage.py", line 24, in <module>
icon = TestTaskBarIcon()
File "C:\Python27\testnotificationmessage.py", line 22, in __init__
wx.NotificationMessage("", "Hello world!", self).Show()
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\_misc.py", line 1213, in __init__
_misc_.NotificationMessage_swiginit(self,_misc_.new_NotificationMessage(*args))
TypeError: in method 'new_NotificationMessage', expected argument 3 of type 'wxWindow *'
What's going on? If I remove that argument, I don't get my result, if I add the argument, I get an error! How am I supposed to use wx.NotificationMessage with a wx.TaskBarIcon!
Please help! I hope I've provided enough details. Please comment if you need more!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我目前还不建议使用 2.9。我在尝试时遇到了一些奇怪的错误。
您可以在 2.8 中拥有相同的功能。我正在使用一段时间前发现的经过修改的代码。
I would not recommend using 2.9 just yet. I have encountered some strange bugs when trying it out.
You can have the same functionality in 2.8. I am using somewhat modified code that I have found some time ago.
TaskBarIcon
中有一个未公开的隐藏方法,名为ShowBalloon
,仅针对 Windows 实现。来自来源:
我在 Windows 上使用 wxPython 2.9.4.0 进行了测试,效果很好。
There is an undocumented hidden method in
TaskBarIcon
calledShowBalloon
which is only implemented for Windows.From the source:
I tested it on Windows with wxPython 2.9.4.0 and it works well.