Creating a fully customizable GUI for a laser cutting bed using PyQt6 involves a significant amount of code. Below is a simplified version of how you might structure such a GUI, including the main components you've requested. This example will focus on the layout and functionality, but it won't be a complete implementation. You can build upon this foundation to add more features and refine the design.
First, make sure you have PyQt6 installed:
pip install PyQt6
Here’s a basic implementation of the GUI you described:
import sys
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QPushButton, QSlider, QTabWidget, QGridLayout, QToolTip
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QColor
class LaserCuttingBedGUI(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Laser Cutting Bed Control")
self.setGeometry(100, 100, 1200, 800)
self.tabs = QTabWidget()
self.setCentralWidget(self.tabs)
self.settings_tab = QWidget()
self.control_tab = QWidget()
self.tabs.addTab(self.settings_tab, "Settings")
self.tabs.addTab(self.control_tab, "Control")
self.init_settings_tab()
self.init_control_tab()
def init_settings_tab(self):
layout = QVBoxLayout()
# Material Size Input
self.material_size_label = QLabel("Material Size (mm):")
self.material_size_input = QSlider(Qt.Orientation.Horizontal)
self.material_size_input.setRange(1, 1000)
self.material_size_input.setValue(500)
self.material_size_input.valueChanged.connect(self.update_material_size)
# Optimal Settings Display
self.optimal_power_label = QLabel("Optimal Power:")
self.optimal_power_value = QLabel("50 W")
self.optimal_power_value.setStyleSheet("color: green;") # Default to optimal
# Sliders for settings
self.power_slider = QSlider(Qt.Orientation.Horizontal)
self.power_slider.setRange(0, 100)
self.power_slider.setValue(50)
self.power_slider.valueChanged.connect(self.update_power_setting)
# Lights Display
self.lights_layout = QHBoxLayout()
self.lights = [QLabel(" ") for _ in range(9)]
for light in self.lights:
light.setFixedSize(20, 20)
light.setStyleSheet("background-color: gray; border-radius: 10px;")
self.lights_layout.addWidget(light)
layout.addWidget(self.material_size_label)
layout.addWidget(self.material_size_input)
layout.addWidget(self.optimal_power_label)
layout.addWidget(self.optimal_power_value)
layout.addWidget(QLabel("Power Setting:"))
layout.addWidget(self.power_slider)
layout.addLayout(self.lights_layout)
self.settings_tab.setLayout(layout)
def init_control_tab(self):
layout = QVBoxLayout()
self.laser_status_label = QLabel("Laser Status:")
self.laser_status_value = QLabel("Deactivated")
self.laser_status_value.setStyleSheet("color: red;")
self.control_button = QPushButton("Activate Laser")
self.control_button.clicked.connect(self.toggle_laser)
layout.addWidget(self.laser_status_label)
layout.addWidget(self.laser_status_value)
layout.addWidget(self.control_button)
self.control_tab.setLayout(layout)
def update_material_size(self):
size = self.material_size_input.value()
# Logic to update design based on material size can be added here
def update_power_setting(self):
power = self.power_slider.value()
if power < 40:
self.optimal_power_value.setStyleSheet("color: blue;") # Too low
elif power > 60:
self.optimal_power_value.setStyleSheet("color: red;") # Too high
else:
self.optimal_power_value.setStyleSheet("color: green;") # Optimal
# Update lights based on power setting
self.update_lights(power)
def update_lights(self, power):
for i in range(9):
self.lights[i].setStyleSheet("background-color: gray;") # Reset lights
if power < 40:
self.lights[0].setStyleSheet("background-color: blue;") # Too low
self.lights[1].setStyleSheet("background-color: blue;")
elif power > 60:
self.lights[7].setStyleSheet("background-color: red;") # Too high
self.lights[8].setStyleSheet("background-color: red;")
else:
self.lights[4].setStyleSheet("background-color: green;") # Optimal
def toggle_laser(self):
if self.laser_status_value.text() == "Deactivated":
self.laser_status_value.setText("Activated")
self.laser_status_value.setStyleSheet("color: green;")
self.control_button.setText("Deactivate Laser")
else:
self.laser_status_value.setText("Deactivated")
self.laser_status_value.setStyleSheet("color: red;")
self.control_button.setText("Activate Laser")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = LaserCuttingBedGUI()
window.show()
sys.exit(app.exec())
Explanation of the Code:
-
Main Window: The LaserCuttingBedGUI class inherits from QMainWindow and initializes the main window layout with two tabs: "Settings" and "Control".
-
Settings Tab:
- Contains sliders for adjusting material size and power settings.
- Displays the optimal power level and changes its color based on the current setting (green for optimal, red for too high, blue for too low).
- Includes a light display that visually indicates the status of the settings.
-
Control Tab:
- Displays the current status of the laser and a button to activate/deactivate it.
-
Dynamic Updates:
- The GUI updates in real-time as the user adjusts the sliders. The color of the optimal power label changes based on the current setting.
-
Light Indicators:
- Visual indicators that change based on the power setting.
Next Steps:
- Implement the design display and import section.
- Add mapping functionality for resizing and positioning designs.
- Include a real-time display of the laser's sensors.
- Enhance the visual representation of the laser bed.
- Add pop-up tooltips for more information about each setting.
This code provides a foundational structure for your laser cutting bed GUI. You can expand upon it by adding the additional functionalities you mentioned.