W
W
w0lkolak2020-10-25 19:02:54
PyQt
w0lkolak, 2020-10-25 19:02:54

The text highlighting function passed to QThread is not executed. CHADNT?

Salt: I am writing a text editor with highlighting. Sometimes there are large files, so I want to organize the flow so as not to block the GUI.
There is

class MyEdit(QPlainTextEdit):
    def __init__(self, text, base, existing, *args, **kwargs):
        super().__init__(*args, **kwargs)
        ...
        def set_syntax(self):
            print('set syntax1')
            self.highlight = HLSyntax.HL_Syntax.GMHighlighter(self.document())
            print('set syntax2')

there is
class ParentOfMyEdit(QWidget):
    def __init__(self, text, base, existing):
        super().__init__()
        self.editor = MyEdit(text, existing=existing, base=base)
        ...
       self.flow = flow.ThreadClass(func_to_execute=self.editor.set_syntax, percent_panel=self.progress_bar)
              self.flow.stastSignal.connect(self.stast_process)
        self.flow.finishSignal.connect(self.finishSignal_process)

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.timeout_func)
        self.exec_in_thread()

    def stast_process(self, val):
        self.value = val // 100
        self.timer.start(1000)

    def finishSignal_process(self, val):
        self.progress_bar.setValue(100)
        self.timer.stop()
        print(val)

    def timeout_func(self):
        self.progress_bar.setValue(self.value)
        self.value += 10

    def exec_in_thread(self):
        self.progress_bar.setProperty("value", 0)
        self.flow.start()


Finally there is the thread class
class ThreadClass(QThread):
    stastSignal = pyqtSignal(int)
    finishSignal = pyqtSignal(str)

    def __init__(self, func_to_execute, percent_panel):
        super().__init__()
        self.func = func_to_execute


    def run(self):
        print('start running')
        value = 1000
        print(self.func)
        self.stastSignal.emit(value)
        self.func()
        print('vse')


The set_syntax passed to QThread is executed because print('set syntax1') and print('set syntax2') inside it work, but for some reason self.highlight = HLSyntax.HL_Syntax.GMHighlighter(self.document()) does nothing. Moreover, self.exec_in_thread() in ParentOfMyEdit will disable syntax highlighting if I include it elsewhere directly without threads.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question