wx python 3.0.2经典的SetFocus打击

时间:2016-06-24 11:52:30

标签: python python-2.7 wxpython

我有一个Progress类在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)

在3.02中,然而打击:

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

现在有人能发现这个窗口无效吗?正如所见,进展实例化于:

with balt.Progress(_(u'Refreshing Installers...'),u'\n'+u' '*60, abort=canCancel) as progress:

所以父母是无 - 是不是因为那个?但是为什么3.0.2中的行为改变了? 编辑:没有 - 传递非无父母没有区别

顺便提一下,如果我删除了SetFocus调用,它会继续打开另一个setFocus调用:

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()

不确定是否需要所有这些hocus pocus或是否可以简化,但我的直接关注是窗口无效的原因。

1 个答案:

答案 0 :(得分:2)

在Windows上,ProgressDialog现在是股票公共控件(如MessageDialogFileDialog等),而不是像以前那样在wx中实现的通用对话框。所以它不再是一个真正的本机窗口,而只是一个平台API的包装器。所以这意味着它没有本机窗口句柄,并且大多数非ProgressDialog特定的API(如SetFocus)都不起作用。