MCPcopy Create free account
hub / github.com/Apress/modern-pyqt / setupWindow

Method setupWindow

ch05_computer_vision/image_processing.py:41–106  ·  view source on GitHub ↗

Set up widgets in the main window.

(self)

Source from the content-addressed store, hash-verified

39 self.show()
40
41 def setupWindow(self):
42 """Set up widgets in the main window."""
43 self.image_label = QLabel()
44 self.image_label.setObjectName("ImageLabel")
45
46 # Create various widgets for image processing in the side panel
47 contrast_label = QLabel("Contrast [Range: 0.0:4.0]")
48 self.contrast_spinbox = QDoubleSpinBox()
49 self.contrast_spinbox.setMinimumWidth(100)
50 self.contrast_spinbox.setRange(0.0, 4.0)
51 self.contrast_spinbox.setValue(1.0)
52 self.contrast_spinbox.setSingleStep(.10)
53 self.contrast_spinbox.valueChanged.connect(self.adjustContrast)
54
55 brightness_label = QLabel("Brightness [Range: -127:127]")
56 self.brightness_spinbox = QSpinBox()
57 self.brightness_spinbox.setMinimumWidth(100)
58 self.brightness_spinbox.setRange(-127, 127)
59 self.brightness_spinbox.setValue(0)
60 self.brightness_spinbox.setSingleStep(1)
61 self.brightness_spinbox.valueChanged.connect(self.adjustBrightness)
62
63 smoothing_label = QLabel("Image Smoothing Filters")
64 self.filter_2D_cb = QCheckBox("2D Convolution")
65 self.filter_2D_cb.stateChanged.connect(self.imageSmoothingFilter)
66
67 edges_label = QLabel("Detect Edges")
68 self.canny_cb = QCheckBox("Canny Edge Detector")
69 self.canny_cb.stateChanged.connect(self.edgeDetection)
70
71 self.apply_process_button = QPushButton("Apply Processes")
72 self.apply_process_button.setEnabled(False)
73 self.apply_process_button.clicked.connect(self.applyImageProcessing)
74
75 reset_button = QPushButton("Reset Image Settings")
76 reset_button.clicked.connect(self.resetImageAndSettings)
77
78 # Create horizontal and vertical layouts for the side panel and main window
79 side_panel_v_box = QVBoxLayout()
80 side_panel_v_box.setAlignment(Qt.AlignTop)
81 side_panel_v_box.addWidget(contrast_label)
82 side_panel_v_box.addWidget(self.contrast_spinbox)
83 side_panel_v_box.addWidget(brightness_label)
84 side_panel_v_box.addWidget(self.brightness_spinbox)
85 side_panel_v_box.addSpacing(15)
86 side_panel_v_box.addWidget(smoothing_label)
87 side_panel_v_box.addWidget(self.filter_2D_cb)
88 side_panel_v_box.addWidget(edges_label)
89 side_panel_v_box.addWidget(self.canny_cb)
90 side_panel_v_box.addWidget(self.apply_process_button)
91 side_panel_v_box.addStretch(1)
92 side_panel_v_box.addWidget(reset_button)
93
94 side_panel_frame = QFrame()
95 side_panel_frame.setMinimumWidth(200)
96 side_panel_frame.setFrameStyle(QFrame.WinPanel)
97 side_panel_frame.setLayout(side_panel_v_box)
98

Callers 1

initializeUIMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected