Closed czqhurricnae closed 1 year ago
把选项 popweb-enable-developer-tools
打开, 看看是不是 JavaScript 调试器能否打开?
我们先看看是不是 JavaScript Console 没有错误, 再来看看是不是 PyQt 的问题?
popweb-enable-developer-tools
设置为 t,调试器能打开,但是主窗口还是空白。
说明和 show_handler https://github.com/manateelazycat/popweb/blob/f023f4550f0d199959544e6074331a1ef57a9656/popweb.py#L239-L250 没有关系。
我把 https://github.com/manateelazycat/popweb/blob/f023f4550f0d199959544e6074331a1ef57a9656/popweb.py#L177-L183 中关于 showEvent 的代码注释掉后:
class WebView(QWebEngineView):
shown = QtCore.pyqtSignal(object)
# def showEvent(self, event) -> None:
# self.shown.emit(self)
# event.accept()
主窗口可以正常显示内容了。
我猜测是主窗口内容还没完全显示出来,showEvent 中 self.shown.emit(self)
就通知 self.webview.shown.connect(self.show_handler)
去打开调试器,导致主窗口的后续渲染被中断?。
你这个估计不是平台问题,我linux也偶尔白屏,你可以print一下showevent的 event 变量,看看白屏的event和正常的有啥差别?
你找的这个showevent应该是根本原因。
不好意思,在出差,手机调试有点麻烦,还麻烦你看一看,找到原因,我这两天就可以修复。
没有办法对比两种状况的 event 的区别。
只要:
class WebView(QWebEngineView):
shown = QtCore.pyqtSignal(object)
# def showEvent(self, event) -> None:
# self.shown.emit(self)
# event.accept()
def showEvent 这个事件没有注释,就会白屏。
也就是说,只要有定义 showEvent,就算 showEvent 函数内没有任何代码,没有 self.shown.emit(self),没有 event.accept() 也会白屏。
但是打印 event 变量需要在 showEevent 事件中,这样就无法打印正常情况下的 event。
我把只能白屏情况下的 event 打印:
popweb.py -> 181 -> WebView -> showEvent -> dir(event)
['Type', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'accept', 'clone', 'ignore', 'isAccepted', 'isInputEvent', 'isPointerEvent', 'isSinglePointEvent', 'registerEventType', 'setAccepted', 'spontaneous', 'type']
popweb.py -> 182 -> WebView -> showEvent -> event.isAccepted()
True
popweb.py -> 183 -> WebView -> showEvent -> event.isInputEvent()
False
popweb.py -> 184 -> WebView -> showEvent -> event.isPointerEvent()
False
popweb.py -> 185 -> WebView -> showEvent -> event.isSinglePointEvent()
False
popweb.py -> 186 -> WebView -> showEvent -> event.registerEventType()
65533
popweb.py -> 187 -> WebView -> showEvent -> event.setAccepted
<built-in method setAccepted of QShowEvent object at 0x11d8ce0e0>
popweb.py -> 188 -> WebView -> showEvent -> event.spontaneous()
False
popweb.py -> 189 -> WebView -> showEvent -> event.type()
Type.Show
可以正常使用。
System Info :computer:
问题
如题
Debug
经过一个一个版本回退发现:在版本:https://github.com/manateelazycat/popweb/commit/738c4c9ae140c7b3c8ede9f249c405732574f76f 之后的都无法正常工作。
甚至修复了 https://github.com/manateelazycat/popweb/commit/738c4c9ae140c7b3c8ede9f249c405732574f76f 引入 bug 的https://github.com/manateelazycat/popweb/commit/147ba530c4d8a7260930d44c17dd34b71b22c757 版本也是无法正常工作:
直至回退到 https://github.com/manateelazycat/popweb/commit/8524a1f7ec6e28f951beefc99728ffae141e42aa 版本才能正常工作。
将这段代码:https://github.com/manateelazycat/popweb/blob/f023f4550f0d199959544e6074331a1ef57a9656/popweb.py#L210-L215
改成如下,注意第 210,215 行:
可以正常。
我猜想是新增加的调试器功能导致在 MacOS 上无法正常工作。但是我不懂 PyQT 不知道如何修改。