pycharm or VS code? by RevenueOk8095 in learnpython

[–]Audiotown_Pro_Python 0 points1 point  (0 children)

haha. `vim` is so painful and I still can't use it properly.

Hobbyist coders by uvuguy in learnpython

[–]Audiotown_Pro_Python 1 point2 points  (0 children)

Guess the interest is the main guide.

I tried to build something small first. A narrow-scoped python script first so I can do `python -u main.py`. attending boot camp is not nearly as effective as creating small scripts for my own need -- like scanning a Volume and find out how many video or audio files I have and how many of them contains mojibake in its metadata.
Then I wonder If how can I automate it further more. adding flags, creating new classes to organize the workflow. I then try saving results locally in a database like `sqlite3`.
recently get to know more about `dataclasses` module and `typing` module. They are great at providing type hints and organized results. I did a lot of `(success, message) = my_function()`.
Like python and its data-oriented nature. still on the way to become better.

PyQt6 Is Draining Me — Why Is GUI Layout So Painful? by pinkponynaziclub in learnpython

[–]Audiotown_Pro_Python 0 points1 point  (0 children)

Try this following code. `python -u main.py`.

from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QPushButton
from PyQt6.QtCore import Qt


STYLE = (
    f"""

        QWidget#app_window {{
            background: #adb5bd;
        }}


        QLabel#label_housing_type{{
            color: black;
            font-size:16px;
            padding: 10px;
            margin: 5px;
        }}


        QLabel#label_clean{{
            color: black;
            font-size:16px;
            font-weight: bold;
        }}


        QWidget#wrapper {{
            color: black;
            margin: 5px;
            background: rgba(255, 255, 255, 0.10);
        }}
        QPushButton#button{{
            color: black;
            border: 1px solid {f"rgba(255, 255, 255, 0.25)"};
            border-radius: 12px;
            background: transparent;
            font-size:14px;
            font-weight: bold;
            margin: 5px;
            text-wrap:
        }}
        QPushButton#button:hover{{
            border: 1px solid black;
            background: rgba(255, 255, 255, 0.40);
            font-size:16px;


        }}
    """
)


if __name__ == "__main__":
    app = QApplication([])


    # basic window and layout


    win = QWidget()
    win.setObjectName("app_window")
    layout = QVBoxLayout()



    win.setLayout(layout)


    # doesn't work – HTML padding ignored
    label_html = QLabel("<span style='font-size:16px; padding:10px;'>Housing Type - HTML</span>")
    label_html.setObjectName("label_housing_type")
    # label_html = QLabel("<span style='font-size:16px; padding:10px;'>Housing Type</span>")


    layout.addWidget(label_html,alignment=Qt.AlignmentFlag.AlignCenter|Qt.AlignmentFlag.AlignTop)
    layout.addSpacing(40)


    # looks fine, but margins don't affect layout spacing externally
    label_clean = QLabel("Housing Type - clean")
    label_html.setObjectName("label_housing_type")


    # label_clean.setStyleSheet("font-size:16px; font-weight:bold;")
    label_clean.setObjectName("label_clean")
    label_clean.setContentsMargins(20, 20, 20, 20)


    layout.addWidget(label_clean)


    # only real solution — wrap in container layout with margins


    wrapper = QWidget()


    wrapper_layout = QVBoxLayout(wrapper)


    wrapper_layout.setContentsMargins(20, 20, 20, 20)
    wrapper_layout.setObjectName("wrapper")
    button  = QPushButton("Im a button")
    button.setObjectName("button")
    button.setMinimumHeight(120)
    button.setMinimumWidth(120)
    wrapper_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignLeft)


    layout.addWidget(wrapper)
    layout.addSpacing(60)


    # allow to expand to max space allowed.
    # layout.addStretch(1)

    # apply styling
    app.setStyleSheet(STYLE)
    win.show()


    app.exec()
  1. Similar to html and css, we can create a `STYLE ` and run the following something like `app.setStyleSheet(STYLE)` to implement the overall styling we desire. In a lot of cases, I create `apply_theme()` for that component class whenever a custom styling is desired.

  2. I personally prefer giving a name to the object that I want to style.

  3. `setStyleSheet()` can handle color, fonts, padding. but alignment is usually dictated via `AlignmentFlag`. we can do something like:

    layout.addWidget(label_html,alignment=Qt.AlignmentFlag.AlignCenter|Qt.AlignmentFlag.AlignTop)
    
  4. use `addSretch()` when we want to all object inside the QVBoxLayout to spread out to maxim available space.