wx python 3.0.2 经典 SetFocus 打击 [英] wx python 3.0.2 classic SetFocus blows
问题描述
我有一个在 2.8.12.1 unicode 中运行良好的 Progress 类:
I had a Progress class that was working fine in 2.8.12.1 unicode:
class Progress(bolt.Progress):
"""Progress as progress dialog."""
def __init__(self,title=_(u'Progress'),message=u' '*60,parent=None,
style=wx.PD_APP_MODAL|wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_SMOOTH,
abort=False, onAbort=None):
if abort:
style |= wx.PD_CAN_ABORT
self.fnAbort = onAbort
self.dialog = wx.ProgressDialog(title,message,100,parent,style)
self.dialog.SetFocus() #### line 1295 in the traceback is here ####
bolt.Progress.__init__(self)
self.message = message
self.isDestroyed = False
self.prevMessage = u''
self.prevState = -1
self.prevTime = 0
(bolt.Progress 中没有 wx)
(bolt.Progress has no wx in it)
然而在 3.02 中却出现了:
In 3.02 however blows with:
Traceback (most recent call last):
...
File "bash\basher\__init__.py", line 2670, in _refresh_installers_if_needed
with balt.Progress(_(u'Refreshing Installers...'),u'\n'+u' '*60, abort=canCancel) as progress:
File "bash\balt.py", line 1295, in __init__
self.dialog.SetFocus()
File "C:\_\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 10129, in SetFocus
return _core_.Window_SetFocus(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "hWnd" failed at ..\..\src\msw\window.cpp(562) in wxWindow::SetFocus(): can't set focus to invalid window
现在有人能发现这个窗口的无效之处吗?正如所见,Progress 在以下位置实例化:
Now can anyone spot what is invalid about this window ? As seen the Progress is instantiated in:
with balt.Progress(_(u'Refreshing Installers...'),u'\n'+u' '*60, abort=canCancel) as progress:
所以 parent 是 None - 是因为那个吗?但是,为什么 3.0.2 中的行为发生了变化?好吧,不 - 传入一个非 None 的父级没有任何区别
so parent is None - is it because of that ? However why the change in behavior in 3.0.2 ? well no - passing a non None parent in makes no difference
顺便说一句,如果我删除 SetFocus 调用,它会在稍后继续调用另一个 setFocus 调用:
Incidentally if I remove the SetFocus call it goes on to blow in another setFocus call later on:
def doProgress(self,state,message):
if not self.dialog:
raise StateError(u'Dialog already destroyed.')
elif (state == 0 or state == 1 or (message != self.prevMessage) or
(state - self.prevState) > 0.05 or (time.time() - self.prevTime) > 0.5):
self.dialog.SetFocus() #### blows here, this self.dialog is really, really invalid ####
if message != self.prevMessage:
ret = self.dialog.Update(int(state*100),message)
if not ret[0]:
if self.onAbort():
raise CancelError
else:
ret = self.dialog.Update(int(state*100))
if not ret[0]:
if self.onAbort():
raise CancelError
self.prevMessage = message
self.prevState = state
self.prevTime = time.time()
不确定是否需要所有这些骗局,或者是否可以简化,但我最关心的是为什么窗口无效.
Not sure if all this hocus pocus is needed or if it could be simplified, but my immediate concern is why the window is invalid.
推荐答案
在 Windows 上,ProgressDialog
现在是一个常用控件(如 MessageDialog
、FileDialog
等)而不是像以前那样在 wx 中实现的通用对话框.所以它不再是一个真正的原生窗口,而只是一个平台 API 的包装器.因此,这意味着它没有本机窗口句柄,并且大多数非 ProgressDialog
特定的 API(如 SetFocus
)将无法工作.
On Windows the ProgressDialog
is now a stock common control (like MessageDialog
, FileDialog
, etc.) instead of a generic dialog implemented in wx like it used to be. So it is not a real native window any longer but just a wrapper around a platform API. So this means that it has no native window handle, and most non-ProgressDialog
-specific APIs like SetFocus
will not work.
这篇关于wx python 3.0.2 经典 SetFocus 打击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!