0

使用运行 QML 引擎时,Blender 导致异常错误

self.load(os.fspath(Path(__file__).resolve().parent / "qml/main.qml"))

我需要代码在单独的线程上运行,同时仍与主 Blender 线程通信。我尝试过线程,导致 Blender 不让我访问它的区域。

class QtWindowEventLoop(bpy.types.Operator):
    """Allows PyQt or PySide to run inside Blender"""

    bl_idname = 'screen.qt_event_loop'
    bl_label = 'Qt Event Loop'

    def __init__(self, widget, *args, **kwargs):
        self._widget = widget
        self._args = args
        self._kwargs = kwargs


    def modal(self, context, event):
        # bpy.context.window_manager
        wm = context.window_manager
        #if not self.widget:
        #    # if widget is closed
        #    logger.debug('finish modal operator')
        #    wm.event_timer_remove(self._timer)
        #    return {'FINISHED'}
        #else:
        logger.debug('process the events for Qt window')
        self.event_loop.processEvents()
        self.app.sendPostedEvents(None, 0)
        
        return {'PASS_THROUGH'}

    def execute(self, context):
        logger.debug('execute operator')
        self.app = QtGui.QGuiApplication.instance()
        if not self.app:
            # create the first instance
            self.app = QtGui.QGuiApplication(sys.argv)
        self.event_loop = QtCore.QEventLoop()
        self.widget = self._widget(*self._args, **self._kwargs)
        wm = context.window_manager
        self._timer = wm.event_timer_add(1 / 120, window=context.window)
        context.window_manager.modal_handler_add(self)
        

        return {'RUNNING_MODAL'}

请帮助我,让我知道可以做什么以及我做错了什么

4

0 回答 0