Commit a5e81325 authored by dmMaze's avatar dmMaze
Browse files

disable combobox scrolling in config panel #229

parent da7a26df
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@ def main():

    if C.SCREEN_W > 1707:   # higher than 2560 (1440p) / 1.5
        # https://github.com/dmMaze/BallonsTranslator/issues/220
        BT.comicTransSplitter.setHandleWidth(12)
        BT.comicTransSplitter.setHandleWidth(10)

    ballontrans.setWindowIcon(QIcon(C.ICON_PATH))
    ballontrans.show()
+5 −5
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class ConfigBlock(Widget):
        self.subblock_list.append(sublock)

    def addCombobox(self, sel: List[str], name: str, discription: str = None, vertical_layout: bool = False, target_block: QWidget = None, fix_size: bool = True) -> Tuple[ConfigComboBox, QWidget]:
        combox = ConfigComboBox(fix_size=fix_size)
        combox = ConfigComboBox(fix_size=fix_size, scrollWidget=self)
        combox.addItems(sel)
        if target_block is None:
            sublock = ConfigSubBlock(combox, name, discription, vertical_layout=vertical_layout)
@@ -302,19 +302,19 @@ class ConfigPanel(Widget):
        ])

        dlConfigPanel.addTextLabel(label_text_det)
        self.detect_config_panel = TextDetectConfigPanel(self.tr('Detector'))
        self.detect_config_panel = TextDetectConfigPanel(self.tr('Detector'), scrollWidget=self)
        self.detect_sub_block = dlConfigPanel.addBlockWidget(self.detect_config_panel)
        
        dlConfigPanel.addTextLabel(label_text_ocr)
        self.ocr_config_panel = OCRConfigPanel(self.tr('OCR'))
        self.ocr_config_panel = OCRConfigPanel(self.tr('OCR'), scrollWidget=self)
        self.ocr_sub_block = dlConfigPanel.addBlockWidget(self.ocr_config_panel)

        dlConfigPanel.addTextLabel(label_inpaint)
        self.inpaint_config_panel = InpaintConfigPanel(self.tr('Inpainter'))
        self.inpaint_config_panel = InpaintConfigPanel(self.tr('Inpainter'), scrollWidget=self)
        self.inpaint_sub_block = dlConfigPanel.addBlockWidget(self.inpaint_config_panel)

        dlConfigPanel.addTextLabel(label_translator)
        self.trans_config_panel = TranslatorConfigPanel(label_translator)
        self.trans_config_panel = TranslatorConfigPanel(label_translator, scrollWidget=self)
        self.trans_sub_block = dlConfigPanel.addBlockWidget(self.trans_config_panel)

        generalConfigPanel.addTextLabel(label_startup)
+21 −21
Original line number Diff line number Diff line
from typing import List
from typing import List, Callable

from modules import GET_VALID_INPAINTERS, GET_VALID_TEXTDETECTORS, GET_VALID_TRANSLATORS, GET_VALID_OCR, \
    BaseTranslator, DEFAULT_DEVICE
from utils.logger import logger as LOGGER
from .stylewidgets import ConfigComboBox, NoBorderPushBtn
from .stylewidgets import ConfigComboBox, NoBorderPushBtn, CustomComboBox
from .constants import CONFIG_FONTSIZE_CONTENT, CONFIG_COMBOBOX_MIDEAN, CONFIG_COMBOBOX_LONG, CONFIG_COMBOBOX_SHORT, CONFIG_COMBOBOX_HEIGHT

from qtpy.QtWidgets import QPlainTextEdit, QHBoxLayout, QVBoxLayout, QWidget, QLabel, QComboBox, QCheckBox, QLineEdit
@@ -68,10 +68,10 @@ class ParamEditor(QPlainTextEdit):
        return self.toPlainText()


class ParamComboBox(QComboBox):
class ParamComboBox(CustomComboBox):
    paramwidget_edited = Signal(str, str)
    def __init__(self, param_key: str, options: List[str], size=CONFIG_COMBOBOX_SHORT, *args, **kwargs) -> None:
        super().__init__( *args, **kwargs)
    def __init__(self, param_key: str, options: List[str], size=CONFIG_COMBOBOX_SHORT, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(scrollWidget=scrollWidget, *args, **kwargs)
        self.param_key = param_key
        self.setFixedWidth(size)
        self.setFixedHeight(CONFIG_COMBOBOX_HEIGHT)
@@ -118,7 +118,7 @@ class ParamCheckBox(QCheckBox):
class ParamWidget(QWidget):

    paramwidget_edited = Signal(str, dict)
    def __init__(self, params, *args, **kwargs) -> None:
    def __init__(self, params, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        param_layout = QVBoxLayout(self)
        param_layout.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
@@ -155,7 +155,7 @@ class ParamWidget(QWidget):
                        size = CONFIG_COMBOBOX_MIDEAN
                    else:
                        size = CONFIG_COMBOBOX_SHORT
                    param_widget = ParamComboBox(param_key, param_dict['options'], size=size)
                    param_widget = ParamComboBox(param_key, param_dict['options'], size=size, scrollWidget=scrollWidget)

                    # if cuda is not available, disable combobox 'cuda' item
                    # https://stackoverflow.com/questions/38915001/disable-specific-items-in-qcombobox
@@ -194,10 +194,10 @@ class ParamWidget(QWidget):
class ModuleConfigParseWidget(QWidget):
    module_changed = Signal(str)
    paramwidget_edited = Signal(str, dict)
    def __init__(self, module_name: str, get_valid_module_keys, *args, **kwargs) -> None:
    def __init__(self, module_name: str, get_valid_module_keys: Callable, scrollWidget: QWidget, *args, **kwargs) -> None:
        super().__init__( *args, **kwargs)
        self.get_valid_module_keys = get_valid_module_keys
        self.module_combobox = ConfigComboBox()
        self.module_combobox = ConfigComboBox(scrollWidget=scrollWidget)
        self.params_layout = QHBoxLayout()
        self.params_layout.setContentsMargins(0, 0, 0, 0)

@@ -214,7 +214,7 @@ class ModuleConfigParseWidget(QWidget):
        layout.setSpacing(30)
        self.vlayout = layout

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

@@ -232,7 +232,7 @@ class ModuleConfigParseWidget(QWidget):
            self.module_combobox.addItem(module)
            params = module_dict[module]
            if params is not None:
                param_widget = ParamWidget(params)
                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)
@@ -271,13 +271,13 @@ class TranslatorConfigPanel(ModuleConfigParseWidget):

    show_MT_keyword_window = Signal()

    def __init__(self, module_name, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_TRANSLATORS, *args, **kwargs)
    def __init__(self, module_name, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_TRANSLATORS, scrollWidget=scrollWidget, *args, **kwargs)
        self.translator_combobox = self.module_combobox
        self.translator_changed = self.module_changed
    
        self.source_combobox = ConfigComboBox()
        self.target_combobox = ConfigComboBox()
        self.source_combobox = ConfigComboBox(scrollWidget=scrollWidget)
        self.target_combobox = ConfigComboBox(scrollWidget=scrollWidget)
        self.replaceMTkeywordBtn = NoBorderPushBtn(self.tr("Keyword substitution for machine translation"), self)
        self.replaceMTkeywordBtn.clicked.connect(self.show_MT_keyword_window)
        self.replaceMTkeywordBtn.setFixedWidth(500)
@@ -313,8 +313,8 @@ class TranslatorConfigPanel(ModuleConfigParseWidget):


class InpaintConfigPanel(ModuleConfigParseWidget):
    def __init__(self, module_name: str, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_INPAINTERS, *args, **kwargs)
    def __init__(self, module_name: str, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_INPAINTERS, scrollWidget = scrollWidget, *args, **kwargs)
        self.inpainter_changed = self.module_changed
        self.inpainter_combobox = self.module_combobox
        self.setInpainter = self.setModule
@@ -322,8 +322,8 @@ class InpaintConfigPanel(ModuleConfigParseWidget):
        self.vlayout.addWidget(self.needInpaintChecker)

class TextDetectConfigPanel(ModuleConfigParseWidget):
    def __init__(self, module_name: str, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_TEXTDETECTORS, *args, **kwargs)
    def __init__(self, module_name: str, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_TEXTDETECTORS, scrollWidget = scrollWidget, *args, **kwargs)
        self.detector_changed = self.module_changed
        self.detector_combobox = self.module_combobox
        self.setDetector = self.setModule
@@ -333,8 +333,8 @@ class OCRConfigPanel(ModuleConfigParseWidget):
    
    show_OCR_keyword_window = Signal()

    def __init__(self, module_name: str, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_OCR, *args, **kwargs)
    def __init__(self, module_name: str, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(module_name, GET_VALID_OCR, scrollWidget = scrollWidget, *args, **kwargs)
        self.ocr_changed = self.module_changed
        self.ocr_combobox = self.module_combobox
        self.setOCR = self.setModule
+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)
        translator_panel.addModulesParamWidgets(translator_params, config_panel)
        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)
        inpainter_panel.addModulesParamWidgets(inpainter_params, config_panel)
        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)
        textdetector_panel.addModulesParamWidgets(textdetector_params, config_panel)
        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)
        ocr_panel.addModulesParamWidgets(ocr_params, config_panel)
        ocr_panel.paramwidget_edited.connect(self.on_ocrparam_edited)
        ocr_panel.ocr_changed.connect(self.setOCR)
        self.ocr_postprocess = ocr_postprocess
+17 −3
Original line number Diff line number Diff line
@@ -314,10 +314,24 @@ class PaintQSlider(QSlider):
            painter.setBrush(QColor(*C.SLIDERHANDLE_COLOR,200))
            painter.drawRoundedRect(rect, r, r)

class ConfigComboBox(QComboBox):

    def __init__(self, fix_size=True, *args, **kwargs) -> None:
class CustomComboBox(QComboBox):
    # https://stackoverflow.com/questions/3241830/qt-how-to-disable-mouse-scrolling-of-qcombobox
    def __init__(self, scrollWidget=None, *args, **kwargs):
        super().__init__(*args, **kwargs)  
        self.scrollWidget=scrollWidget
        self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)

    def wheelEvent(self, *args, **kwargs):
        if self.scrollWidget is None or self.hasFocus():
            return super().wheelEvent(*args, **kwargs)
        else:
            return self.scrollWidget.wheelEvent(*args, **kwargs)
        

class ConfigComboBox(CustomComboBox):

    def __init__(self, fix_size=True, scrollWidget: QWidget = None, *args, **kwargs) -> None:
        super().__init__(scrollWidget, *args, **kwargs)
        self.fix_size = fix_size
        self.adjustSize()