Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. pyqt5 GUI has alot of code lines
Forum Updated to NodeBB v4.3 + New Features

pyqt5 GUI has alot of code lines

Scheduled Pinned Locked Moved Solved Qt for Python
10 Posts 4 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prophet_lolo
    wrote on last edited by
    #1

    Hey everybody,

    I Develop a GUI using pyqt5, is based on this structure::

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(292, 98)
            self.widget = QtWidgets.QWidget(Dialog)
            self.widget.setGeometry(QtCore.QRect(40, 40, 217, 27))
            self.widget.setObjectName("widget")
            self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
            self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.label = QtWidgets.QLabel(self.widget)
            self.label.setObjectName("label")
            self.horizontalLayout.addWidget(self.label)
            self.lineEdit = QtWidgets.QLineEdit(self.widget)
            self.lineEdit.setObjectName("lineEdit")
            self.horizontalLayout.addWidget(self.lineEdit)
    
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            _translate = QtCore.QCoreApplication.translate
            Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
            self.label.setText(_translate("Dialog", "TextLabel"))
    
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    

    My application uses a lot of parameters, each parameter has Qlables, QLineEdits, few others use RadioButtons etc...
    Eventually after generating all the relevant code line for each parameter i end up with a lot of code lines - the problem mainly interferes while trying to Debug through PyCharm - results with PyCharm work very slowly, and low memory notifications pops up.

    What is the right way to manage that many parameters being held by one Ui_MainWindow class?

    JonBJ 1 Reply Last reply
    0
    • P prophet_lolo

      Hey everybody,

      I Develop a GUI using pyqt5, is based on this structure::

      from PyQt5 import QtCore, QtGui, QtWidgets
      
      
      class Ui_Dialog(object):
          def setupUi(self, Dialog):
              Dialog.setObjectName("Dialog")
              Dialog.resize(292, 98)
              self.widget = QtWidgets.QWidget(Dialog)
              self.widget.setGeometry(QtCore.QRect(40, 40, 217, 27))
              self.widget.setObjectName("widget")
              self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
              self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
              self.horizontalLayout.setObjectName("horizontalLayout")
              self.label = QtWidgets.QLabel(self.widget)
              self.label.setObjectName("label")
              self.horizontalLayout.addWidget(self.label)
              self.lineEdit = QtWidgets.QLineEdit(self.widget)
              self.lineEdit.setObjectName("lineEdit")
              self.horizontalLayout.addWidget(self.lineEdit)
      
              self.retranslateUi(Dialog)
              QtCore.QMetaObject.connectSlotsByName(Dialog)
      
          def retranslateUi(self, Dialog):
              _translate = QtCore.QCoreApplication.translate
              Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
              self.label.setText(_translate("Dialog", "TextLabel"))
      
      
      if __name__ == "__main__":
          import sys
          app = QtWidgets.QApplication(sys.argv)
          Dialog = QtWidgets.QDialog()
          ui = Ui_Dialog()
          ui.setupUi(Dialog)
          Dialog.show()
          sys.exit(app.exec_())
      

      My application uses a lot of parameters, each parameter has Qlables, QLineEdits, few others use RadioButtons etc...
      Eventually after generating all the relevant code line for each parameter i end up with a lot of code lines - the problem mainly interferes while trying to Debug through PyCharm - results with PyCharm work very slowly, and low memory notifications pops up.

      What is the right way to manage that many parameters being held by one Ui_MainWindow class?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @prophet_lolo
      Just how many "parameters" --- whatever you mean by that --- i.e. labels, line edits etc. do you mean you have?

      I used PyCharm with PyQt5, and it would not matter (within reason) how many widgets you have, the debugger works fine. It should not result in "low memory notifications pops up". That would indicate you just don't have enough memory to reasonably run PyCharm to debug a Qt program, so how much (free) memory do you have? PyCharm itself, plus the debugger, will need a fair amount of memory, you will not be able to use it reasonably if you don't have a lot of free memory.

      P 1 Reply Last reply
      0
      • JonBJ JonB

        @prophet_lolo
        Just how many "parameters" --- whatever you mean by that --- i.e. labels, line edits etc. do you mean you have?

        I used PyCharm with PyQt5, and it would not matter (within reason) how many widgets you have, the debugger works fine. It should not result in "low memory notifications pops up". That would indicate you just don't have enough memory to reasonably run PyCharm to debug a Qt program, so how much (free) memory do you have? PyCharm itself, plus the debugger, will need a fair amount of memory, you will not be able to use it reasonably if you don't have a lot of free memory.

        P Offline
        P Offline
        prophet_lolo
        wrote on last edited by
        #3

        @JonB
        I have around 480 parameters, each parameter has at minimum the following lines:

        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.qlabel = QtWidgets.QLabel()
        self.qlabel.setObjectName("qlabel")
        self.qlabel.setFixedSize(self.width, self.height)
        self.horizontalLayout.addWidget(self.qlabel)
        self._spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.horizontalLayout.addItem(self._spacerItem)
        self.qlineEdit = QtWidgets.QLineEdit()
        self.qlineEdit.setObjectName("qlineEdit")
        self.qlineEdit.setFixedSize(self.source_qline_width, self.source_qline_height)
        self.horizontalLayout.addWidget(self.qlineEdit)
        self.vertical_layout.addLayout(self.horizontalLayout)
        

        so only for the parameters, it sums to around 6240 lines, without additional functions...

        jsulmJ JonBJ 2 Replies Last reply
        0
        • P prophet_lolo

          @JonB
          I have around 480 parameters, each parameter has at minimum the following lines:

          self.horizontalLayout = QtWidgets.QHBoxLayout()
          self.horizontalLayout.setObjectName("horizontalLayout")
          self.qlabel = QtWidgets.QLabel()
          self.qlabel.setObjectName("qlabel")
          self.qlabel.setFixedSize(self.width, self.height)
          self.horizontalLayout.addWidget(self.qlabel)
          self._spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
          self.horizontalLayout.addItem(self._spacerItem)
          self.qlineEdit = QtWidgets.QLineEdit()
          self.qlineEdit.setObjectName("qlineEdit")
          self.qlineEdit.setFixedSize(self.source_qline_width, self.source_qline_height)
          self.horizontalLayout.addWidget(self.qlineEdit)
          self.vertical_layout.addLayout(self.horizontalLayout)
          

          so only for the parameters, it sums to around 6240 lines, without additional functions...

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @prophet_lolo Well, you can put code which is repeated again and again in functions and pass needed information as parameters. The usual thing one does in a programming language like Python.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          1
          • P prophet_lolo

            @JonB
            I have around 480 parameters, each parameter has at minimum the following lines:

            self.horizontalLayout = QtWidgets.QHBoxLayout()
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.qlabel = QtWidgets.QLabel()
            self.qlabel.setObjectName("qlabel")
            self.qlabel.setFixedSize(self.width, self.height)
            self.horizontalLayout.addWidget(self.qlabel)
            self._spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
            self.horizontalLayout.addItem(self._spacerItem)
            self.qlineEdit = QtWidgets.QLineEdit()
            self.qlineEdit.setObjectName("qlineEdit")
            self.qlineEdit.setFixedSize(self.source_qline_width, self.source_qline_height)
            self.horizontalLayout.addWidget(self.qlineEdit)
            self.vertical_layout.addLayout(self.horizontalLayout)
            

            so only for the parameters, it sums to around 6240 lines, without additional functions...

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @prophet_lolo
            As per @jsulm, you can and should indeed do whatever shared-factoring on your code.

            However, this has nothing to do with 6,240 lines of code ought not have any great effect on PyCharm, and certainly should not result in "low memory notifications pops up". I asked you a couple of times how much free memory you have on your PC --- before and after entering PyCharm --- but you did not respond.

            P 1 Reply Last reply
            0
            • JonBJ JonB

              @prophet_lolo
              As per @jsulm, you can and should indeed do whatever shared-factoring on your code.

              However, this has nothing to do with 6,240 lines of code ought not have any great effect on PyCharm, and certainly should not result in "low memory notifications pops up". I asked you a couple of times how much free memory you have on your PC --- before and after entering PyCharm --- but you did not respond.

              P Offline
              P Offline
              prophet_lolo
              wrote on last edited by
              #6

              @JonB
              Before running PyCharm:
              2.4GB used out of 16.6GB

              After running PyCharm:
              4.9GB used out of 16.6GB

              I notice also that when opening this pyqt5 GUI file in PyCharm, all the cores (8) goes up to between 90%-100% -> this happens only with this file, the moment i close it all the cores goes back to around 10%-20%.

              JonBJ 1 Reply Last reply
              0
              • P prophet_lolo

                @JonB
                Before running PyCharm:
                2.4GB used out of 16.6GB

                After running PyCharm:
                4.9GB used out of 16.6GB

                I notice also that when opening this pyqt5 GUI file in PyCharm, all the cores (8) goes up to between 90%-100% -> this happens only with this file, the moment i close it all the cores goes back to around 10%-20%.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @prophet_lolo
                You have masses of free memory. So why are you getting "low memory notifications pops up".?

                I notice also that when opening this pyqt5 GUI file in PyCharm, all the cores (8) goes up to between 90%-100% -> this happens only with this file

                Depressing :(

                It is then unclear whether this behaviour is caused by the volume of 6K lines of code --- ought not be the case --- or by some particular lines in the file --- more likely. You should also be clear whether the difference about "this file" is that it is the only one which imports Qt stuff, or the amount of Qt stuff, if you mean that "other files" do no do any Qt/PyQt.

                When I started on PyCharm there was really bad behaviour upon opening projects --- the IDE went off doing massive searching for imported & system files doing its "indexing", which it does. People complained and over time it did get better. BTW, if you load in this file and go away for a cup of coffee for, say, as much as half an hour, does it then settle down on its own?

                At the moment your Qt/PyQt usage seems fine to me. 6K lines should not be enough to kill your PC. It looks like you have a PyCharm issue here.... (Make sure you are on the latest version of PyCharm, and check their forums etc. for any reports.)

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  prophet_lolo
                  wrote on last edited by
                  #8

                  Hey,

                  I tried to leave it open for a few minutes, and indeed the cores for back to normal after 2-4 minutes,. its probably as you said above, PyCharm doing massive searching over imported files and scanning the whole code.
                  If i open the same file with visual studio code, it does not happen, interesting.

                  Thank you guys.

                  JonBJ 1 Reply Last reply
                  0
                  • P prophet_lolo

                    Hey,

                    I tried to leave it open for a few minutes, and indeed the cores for back to normal after 2-4 minutes,. its probably as you said above, PyCharm doing massive searching over imported files and scanning the whole code.
                    If i open the same file with visual studio code, it does not happen, interesting.

                    Thank you guys.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @prophet_lolo said in pyqt5 GUI has alot of code lines:

                    I tried to leave it open for a few minutes, and indeed the cores for back to normal after 2-4 minutes,.

                    Yes, and maybe it shows "Indexing" (or similar) on its status line at the bottom of the screen?

                    VS, and Qt Creator, are both "fast" on startup. PyCharm is, or can be, unbelievably slow, while it does this "indexing". It ought not need to do this every time one starts up, but it seems to do so. At least with older versions, and who knows what they have/have not corrected now. There are various posts on the web about "PyCharm startup/indexing slow", or similar.

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @prophet_lolo Well, you can put code which is repeated again and again in functions and pass needed information as parameters. The usual thing one does in a programming language like Python.

                      S Offline
                      S Offline
                      StarterKit
                      wrote on last edited by
                      #10

                      @jsulm said in pyqt5 GUI has alot of code lines:

                      Well, you can put code which is repeated again and again in functions and pass needed information as parameters. The usual thing one does in a programming language like Python.

                      Sorry for posting an answer not for initial topic but this comment spotted my attention and flashed 'small red lamp' in my mind :)
                      The reason is when I started with PySide some time ago for a rather complex GUI window I found myself with a lot of similar declarations very fast. And without good Qt knowledge I went this way - wrapping it into functions, creating lists of linked lists of parameters... Indeed it had a result and I got stable code, but its structure was a bit hard to understand for "unprepared mind". After half a year with Qt I got an insight that everything I did may be done with proper subclassing. So I spent sometime and re-wrote it in classes - the complexity and stability remained but I found that now it is much easier to maintain and extend.
                      So, my advice would be to spend sometime and understand how Qt works and then go not with functions but with subclassing.

                      And for the topic itself - I'm working with PyCharm and can't say it is slow. Yes, it makes indexing sometimes, but for me it happens for max 5 min in background and takes only share of CPU, I still able to do things. Maybe I should say thanks to SSD - I see this operation is disk expensive, maybe it matters.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved