Commit e03ac90b authored by dmMaze's avatar dmMaze
Browse files

lazy load param widgets

parent 4cdcafc5
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -214,7 +214,10 @@ class ModuleConfigParseWidget(QWidget):
        layout.setSpacing(30)
        self.vlayout = layout

    def addModulesParamWidgets(self, module_dict: dict, scrollWidget: QWidget = None):
        self.visibleWidget: QWidget = None
        self.module_dict: dict = {}

    def addModulesParamWidgets(self, module_dict: dict):
        invalid_module_keys = []
        valid_modulekeys = self.get_valid_module_keys()

@@ -232,17 +235,15 @@ class ModuleConfigParseWidget(QWidget):
            self.module_combobox.addItem(module)
            params = module_dict[module]
            if params is not None:
                param_widget = ParamWidget(params, scrollWidget=scrollWidget)
                param_widget.paramwidget_edited.connect(self.paramwidget_edited)
                self.param_widget_map[module] = param_widget
                self.params_layout.addWidget(param_widget)
                param_widget.hide()
                self.param_widget_map[module] = None

        if len(invalid_module_keys) > 0:
            LOGGER.warning(F'Invalid module keys: {invalid_module_keys}')
            for ik in invalid_module_keys:
                module_dict.pop(ik)

        self.module_dict = module_dict

        num_widgets_after = len(self.param_widget_map)
        if num_widgets_before == 0 and num_widgets_after > 0:
            self.on_module_changed()
@@ -256,11 +257,20 @@ class ModuleConfigParseWidget(QWidget):

    def updateModuleParamWidget(self):
        module = self.module_combobox.currentText()
        for key in self.param_widget_map:
            if key == module:
                self.param_widget_map[key].show()
        if self.visibleWidget is not None:
            self.visibleWidget.hide()
        if module in self.param_widget_map:
            widget: QWidget = self.param_widget_map[module]
            if widget is None:
                # lazy load widgets
                params = self.module_dict[module]
                param_widget = ParamWidget(params, scrollWidget=self)
                param_widget.paramwidget_edited.connect(self.paramwidget_edited)
                self.param_widget_map[module] = param_widget
                self.params_layout.addWidget(param_widget)
            else:
                self.param_widget_map[key].hide()
                widget.show()
            self.visibleWidget = widget

    def on_module_changed(self):
        self.updateModuleParamWidget()
+4 −4
Original line number Diff line number Diff line
@@ -507,7 +507,7 @@ class ModuleManager(QObject):

        self.translator_panel = translator_panel = config_panel.trans_config_panel        
        translator_params = merge_config_module_params(cfg_module.translator_params, GET_VALID_TRANSLATORS(), TRANSLATORS.get)
        translator_panel.addModulesParamWidgets(translator_params, config_panel)
        translator_panel.addModulesParamWidgets(translator_params)
        translator_panel.translator_changed.connect(self.setTranslator)
        translator_panel.source_combobox.currentTextChanged.connect(self.on_translatorsource_changed)
        translator_panel.target_combobox.currentTextChanged.connect(self.on_translatortarget_changed)
@@ -516,7 +516,7 @@ class ModuleManager(QObject):

        self.inpaint_panel = inpainter_panel = config_panel.inpaint_config_panel
        inpainter_params = merge_config_module_params(cfg_module.inpainter_params, GET_VALID_INPAINTERS(), INPAINTERS.get)
        inpainter_panel.addModulesParamWidgets(inpainter_params, config_panel)
        inpainter_panel.addModulesParamWidgets(inpainter_params)
        inpainter_panel.paramwidget_edited.connect(self.on_inpainterparam_edited)
        inpainter_panel.inpainter_changed.connect(self.setInpainter)
        inpainter_panel.needInpaintChecker.checker_changed.connect(self.on_inpainter_checker_changed)
@@ -524,13 +524,13 @@ class ModuleManager(QObject):

        self.textdetect_panel = textdetector_panel = config_panel.detect_config_panel
        textdetector_params = merge_config_module_params(cfg_module.textdetector_params, GET_VALID_TEXTDETECTORS(), TEXTDETECTORS.get)
        textdetector_panel.addModulesParamWidgets(textdetector_params, config_panel)
        textdetector_panel.addModulesParamWidgets(textdetector_params)
        textdetector_panel.paramwidget_edited.connect(self.on_textdetectorparam_edited)
        textdetector_panel.detector_changed.connect(self.setTextDetector)

        self.ocr_panel = ocr_panel = config_panel.ocr_config_panel
        ocr_params = merge_config_module_params(cfg_module.ocr_params, GET_VALID_OCR(), OCR.get)
        ocr_panel.addModulesParamWidgets(ocr_params, config_panel)
        ocr_panel.addModulesParamWidgets(ocr_params)
        ocr_panel.paramwidget_edited.connect(self.on_ocrparam_edited)
        ocr_panel.ocr_changed.connect(self.setOCR)
        self.ocr_postprocess = ocr_postprocess