-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyqt_code_template_load_ui.py
133 lines (101 loc) · 2.65 KB
/
pyqt_code_template_load_ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Type Checking Imports
# ---------------------
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
# Standard Library Imports
# ------------------------
from pathlib import Path
# Third Party Imports
# -------------------
from qtpy import QtCore, QtGui, QtWidgets, uic
# Local Imports
# -------------
# Constant Definitions
# --------------------
PACKAGE_ROOT = Path(__file__).parent
# UI file path
RELATIVE_UI_PATH = "path/to/your/ui/file.ui"
UI_PATH = PACKAGE_ROOT / RELATIVE_UI_PATH
# Class Definitions
# -----------------
class MyWidget(QtWidgets.QWidget):
"""A Qt widget with a user interface created from a .ui file.
Attributes:
...
"""
# Initialization and Setup
# ------------------------
def __init__(self, parent: QtWidgets.QWidget = None):
"""Initialize the widget and set up the UI, signal connections, and icons.
Args:
...
"""
# Initialize the super class
super().__init__(parent)
# Load the .ui file using the uic module
uic.loadUi(UI_PATH.as_posix(), self)
# Store the arguments
...
# Initialize setup
self.__init_attributes()
self.__init_ui()
self.__init_signal_connections()
def __init_attributes(self):
"""Initialize the attributes.
"""
# Attributes
# ----------
...
# Private Attributes
# ------------------
...
def __init_ui(self):
"""Initialize the UI of the widget.
"""
# Create Layouts
# --------------
...
# Create Widgets
# --------------
...
# Add Widgets to Layouts
# ----------------------
...
def __init_signal_connections(self):
"""Initialize signal-slot connections.
"""
# Connect signals to slots
...
# Public Methods
# --------------
# Class Properties
# ----------------
# Utility Methods
# ---------------
# Private Methods
# ---------------
# Special Methods
# ---------------
# Overridden Methods
# ------------------
# Main Function
# -------------
def main():
"""Create the application, and show the widget.
"""
import sys
# Argument Parsing
# ----------------
...
# Application Setup and Execution
# -------------------------------
# Create the application and the main window
app = QtWidgets.QApplication(sys.argv)
# Create and show the widget
widget = MyWidget()
widget.show()
# Run the application
sys.exit(app.exec_())
if __name__ == '__main__':
main()