Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1483

Hello world in pep8 style doesn't work (snake_case & true_property)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.1.0
    • 5.15.2, 6.0.0
    • PySide
    • None

    Description

      Hi everyone,

      I've tried to port one Pyside hello world of your documentation to the PEP8 style with snake_case & true_property.

      Here is the hello world with no PEP8 style

       

      import sys
      import random
      
      from PySide2 import QtCore, QtWidgets
      
      
      class MyWidget(QtWidgets.QWidget):
          def __init__(self):
              super().__init__()
              self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]
              self.button = QtWidgets.QPushButton("Click me!")
              self.text = QtWidgets.QLabel("Hello World",
                                           alignment=QtCore.Qt.AlignCenter)
              self.layout = QtWidgets.QVBoxLayout()
              self.layout.addWidget(self.text)
              self.layout.addWidget(self.button)
              self.setLayout(self.layout)
              self.button.clicked.connect(self.magic)
      
          @QtCore.Slot()
          def magic(self):
              self.text.setText(random.choice(self.hello))
      
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication([])
      
          widget = MyWidget()
          widget.resize(800, 600)
          widget.show()
      
          sys.exit(app.exec_())
      
      

       

       

      Here is the hello world in PEP8 style.

       

      import sys
      import random
      
      from PySide2 import QtCore, QtWidgets
      from __feature__ import snake_case, true_property
      
      
      class MyWidget(QtWidgets.QWidget):
          def __init__(self):
              super().__init__()
              self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]
              self.button = QtWidgets.QPushButton("Click me!")
              # self.text = QtWidgets.QLabel("Hello World",
              #                             alignment=QtCore.Qt.AlignCenter)
              self.label = QtWidgets.QLabel("Hello World")
              self.label.alignment = QtCore.Qt.AlignCenter
              self.layout = QtWidgets.QVBoxLayout()
              self.layout.add_widget(self.label)
              self.layout.add_widget(self.button)
              self.set_layout(self.layout)
              self.button.clicked.connect(self.magic)
      
          @QtCore.Slot()
          def magic(self):
              self.label.text = random.choice(self.hello)
      
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication([])
      
          widget = MyWidget()
          # widget.resize(800, 600)
          widget.show()
      
          sys.exit(app.exec_())
      
      

      There is commented 2 lines that don't work:

      • I can't initialize the atribute / object self.label in one line because you have an error like "alignment is not a property". I don't know why because there isn't any information about snake_case + true_property and how they affected the code.
      • I can't resize my widget (window) because it shows an error like "widget doesn't have resize method"

      Other confusing thing is (due to lack of documentation about snake_case & true_property I believe) it's in the class with setLayout. We use set_layout but snake_case & true_property it makes you think that you never going to use set..._ more .

      Thanks in advance

       

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              crisconru Cristóbal Contreras Rubio
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes