-1

I have written the following code that parses a text file, breaks it into tokens and inserts these tokens into the database. I want to show the current status of the process using the progress bar but the following code isn't working.

I wrote the following code based on this How to connect pyqtSignal between classes in PyQT

yast_gui.py

class YastGui(QtGui.QMainWindow):
    incrementTokenSignal = QtCore.pyqtSignal(int)
    ...

    def __init__(self):
        self.incrementTokenSignal.connect(self.increment_token_count)
        ...

    def increment_token_count(self, val):
       msg = "{}/{}".format(val, self.total_db_records)
       self.ui.records_processed_value_label.setText(msg)

yast.py

class LogFile(object):
    def __init__(self, file_path, YastGui_object):
        super(LogFile, self).__init__()

        # Gui object
        self.gui = YastGui_object
        self.total_db_records = 0
        ...

    def tokenize(self):
        for i, record in enumerate(myfile):
            ...            
            self.gui.incrementFilterSignal.emit(i + 1)
            settings.session.commit()

According to this PYQT and progress Bar during Long Process, I should create QTheads to deal with the progress bar but I'm not sure on how to do it. Here is the entire Gui file and main file.

Community
  • 1
  • 1
Ibrahim
  • 287
  • 1
  • 3
  • 13

1 Answers1

0

I found the solution to my problem here Change the value of the progress bar from a class other than my GUI class PyQt4.

The trick is to pass the progressBar object to the function as a parameter and then use progressBar.setValue() inside that function.

Community
  • 1
  • 1
Ibrahim
  • 287
  • 1
  • 3
  • 13