ToasterBox 的问题,你能 join() 一个计时器或强制一个线程等待计时器在 python 中完成吗
基本上我使用的是烤面包机,我希望代码运行一次,假设每 30 秒运行一次。每 30 秒烤面包机就会弹出一次。代码看起来像这样
event = threading.Event()
#############################################
bWidth = 200
bHeight = 100
tb = TB.ToasterBox(self, TB.TB_COMPLEX, TB.DEFAULT_TB_STYLE, TB.TB_ONTIME)
tb.SetPopupSize((bWidth,bHeight))
tb.SetPopupPosition((1600-bWidth,900-bHeight))
tb.SetPopupPauseTime(4000)
tb.SetPopupScrollSpeed(8)
##############################################
while true:
showPopup(tb,name,amount,progress,link)
tb.Play()
event.wait(30)
这应该会给你一个想法。无论如何,出现的问题是,烤面包机弹出,但 tb.play() 不会阻塞,因为它生成一个计时器来处理动画,因此线程立即继续等待函数并阻塞,因此烤面包机永远不会关闭。有没有办法更改播放代码以使其阻塞?或者有更好的方法来做到这一点。我尝试创建一个新线程来运行 tb.play() ,但它抛出了一个只能从主线程运行的错误。有关烤面包机盒的更多信息,包括此处的来源:Toasterbox
Basically I am using toasterbox and I want code to run, lets say every 30 seconds. Well every 30 seconds the toasterbox should pop up. The code looks like this
event = threading.Event()
#############################################
bWidth = 200
bHeight = 100
tb = TB.ToasterBox(self, TB.TB_COMPLEX, TB.DEFAULT_TB_STYLE, TB.TB_ONTIME)
tb.SetPopupSize((bWidth,bHeight))
tb.SetPopupPosition((1600-bWidth,900-bHeight))
tb.SetPopupPauseTime(4000)
tb.SetPopupScrollSpeed(8)
##############################################
while true:
showPopup(tb,name,amount,progress,link)
tb.Play()
event.wait(30)
That should give you an idea. Anyway the problem that occurs is, the toasterbox pops up but tb.play() isn't blocking because it spawns a timer to handle animation so the thread immediately continues to the wait function and blocks, so the toasterbox never closes. Is there a way to change the code for play to make it blocking? Or is there a better way to do this. I tried creating a new thread to run tb.play() in but it threw an error about only being able to run from the main thread. More info about toaster box including the source found here: Toasterbox
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用的这个烤面包机是什么? wxPython 中包含了一个。请参阅此处 http://xoomer.virgilio.it/infinity77/AGW_Docs/toasterbox_module.html #toasterbox 或这里http://www.wxpython.org/docs/api /wx.lib.agw.toasterbox.ToasterBox-class.html
我不认为 agw 支持阻塞,我猜你正在使用的也不支持。您可以在 wxPython 邮件列表上询问他们是否可以修补其版本或有更好的建议。就我个人而言,我会使用 wx.Timer 来弹出烤面包机。这应该可以在没有线程的情况下解决你的问题。这里有一个如何使用计时器的示例: http: //www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/
What is this toasterbox you're using? There's one included with wxPython. See here http://xoomer.virgilio.it/infinity77/AGW_Docs/toasterbox_module.html#toasterbox or here http://www.wxpython.org/docs/api/wx.lib.agw.toasterbox.ToasterBox-class.html
I don't think the agw one supports blocking and I'm guessing the one you're using doesn't either. You can ask on the wxPython mailing list to see if they can patch their version or have a better suggestion. Personally, I would use a wx.Timer to pop up the toaster. That should take care of your problem without threads. There's an example of how to use timers here: http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/