0

i try to show the progress using this code in pyQt5 Widget :

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QProgressBar, QVBoxLayout
from PyQt5.QtCore import QObject, pyqtSignal
import git

class Progress(QObject, git.remote.RemoteProgress):
    progress_updated = pyqtSignal(int)

    def __init__(self, update_frequency=1):
        git.remote.RemoteProgress.__init__(self)
        self._update_frequency = update_frequency
        self._cur_count = 0

    def update(self, op_code, cur_count, max_count=None, message=''):
        if cur_count > self._cur_count + self._update_frequency or cur_count == max_count:
            self._cur_count = cur_count
            progress = int(cur_count / max_count * 100)
            self.progress_updated.emit(progress)

but it shows me this error :

PS C:\Users\xxx\Desktop\VCSP\src> & C:/Users/sd94277/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/sd94277/Desktop/VCSP/src/TEST/clone process 2.py"
Traceback (most recent call last):
  File "c:\Users\sd94277\Desktop\VCSP\src\control\clone.py", line 6, in <module>
    class Progress(QObject, git.remote.RemoteProgress):
TypeError: multiple bases have instance lay-out conflict

and this is the entire code :

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QProgressBar, QVBoxLayout
from PyQt5.QtCore import QObject, pyqtSignal
import git

class Progress(QObject, git.remote.RemoteProgress):
    progress_updated = pyqtSignal(int)

    def __init__(self, update_frequency=1):
        git.remote.RemoteProgress.__init__(self)
        self._update_frequency = update_frequency
        self._cur_count = 0

    def update(self, op_code, cur_count, max_count=None, message=''):
        if cur_count > self._cur_count + self._update_frequency or cur_count == max_count:
            self._cur_count = cur_count
            progress = int(cur_count / max_count * 100)
            self.progress_updated.emit(progress)


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.label = QLabel("Starting...", self)
        self.progressbar = QProgressBar(self)
        self.progressbar.setValue(0)

        vbox = QVBoxLayout()
        vbox.addWidget(self.label)
        vbox.addWidget(self.progressbar)
        self.setLayout(vbox)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Git Progress')
        self.show()

    def update_progress(self, progress):
        self.progressbar.setValue(progress)
        self.label.setText(f"Progress: {progress}%")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()

    progress = Progress()
    progress.progress_updated.connect(ex.update_progress)

    # Some git operation that will trigger progress updates
    repo = git.Repo('.')
    repo.git.pull(progress=progress)

    sys.exit(app.exec_())

can any one tell me what is the source of the probleme ?

i tried switch the order i tried import each constructor of each supper separated ect but i don't know it still does not work

i expect to get the progress of the clone push or pull

  • Why does the `Progress` class need to *inherit* `git.remote.RemoteProgress`? That seems completely unnecessary. Use [compostion](https://stackoverflow.com/q/49002/984421) instead. – ekhumoro Apr 11 '23 at 17:41
  • the Progress inherent from 'git.remote.RemoteProgress' because the progress it's an interface to the update the `repo.git.pull(progress=progress)` need the class to be like that other wise it does not work at least for me – Ahbar Abdellah Apr 13 '23 at 11:39
  • That's not a valid reason. The instance of `git.remote.RemoteProgress` should be an attribute of the `Progress class`. Then you can simply do: `repo.git.pull( progress=progress.my_git_progress)`. Inheritance is not necessary at all - use composition instead. – ekhumoro Apr 13 '23 at 12:27

0 Answers0