From 64080620f3df3f3f30a889a72c115d05243e5233 Mon Sep 17 00:00:00 2001 From: Daniel Carta <79732052+immortaldan10@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:15:25 -0600 Subject: [PATCH] Lunch Added the button editor and changed the main script --- README.md | 3 +++ buttonEditor.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 35 +++++++++++++++++++++++++------- 3 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 buttonEditor.py diff --git a/README.md b/README.md index 7d3f103..9046cd5 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,6 @@ python3 ./main.py - Click export, and save to a file ### Known Bugs: + +- Smoothing function is janky (I want to completely redo it) +- Sometimes the control points spawn in random locations but I cant seem to replicate it? \ No newline at end of file diff --git a/buttonEditor.py b/buttonEditor.py new file mode 100644 index 0000000..cfb2a81 --- /dev/null +++ b/buttonEditor.py @@ -0,0 +1,53 @@ +import sys +import os +import numpy as np +from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QHBoxLayout, QWidget, QMessageBox +from PySide6.QtGui import QPixmap, QMouseEvent, QPainter, QPen, QColor, QPainterPath, QPolygon, QFont +from PySide6.QtCore import Qt, QPoint, QRect + +class ButtonEditor(QMainWindow): + def __init__(self, path_planner): + super().__init__() + self.setWindowTitle("Button Editor") + self.path_planner = path_planner + + #Set background image to the field + self.image_label = QLabel(self) + + script_dir = os.path.dirname(os.path.abspath(__file__)) + image_path = os.path.join(script_dir, "images", "Field.png") + self.pixmap = QPixmap(image_path) + + if self.pixmap.isNull(): + self.image_label.setText(f"Image not found at: {image_path}") + else: + self.image_label.setPixmap(self.pixmap) + + #Layout stuff + self.path_planner_button = QPushButton("Main Window") + self.path_planner_button.clicked.connect(self.show_path_planner) + self.button_editor_button = QPushButton("Button Editor") + self.button_editor_button.clicked.connect(self.show_button_editor) + + button_layout = QHBoxLayout() + button_layout.addWidget(self.path_planner_button) + button_layout.addWidget(self.button_editor_button) + + #Layout of the auto planner + layout = QVBoxLayout() + layout.addLayout(button_layout) + layout.addWidget(self.image_label) + + container = QWidget() + container.setLayout(layout) + self.setCentralWidget(container) + + self.resize(self.pixmap.width(), self.pixmap.height() + 60) + + def show_button_editor(self): + self.show() + self.path_planner.hide() + + def show_path_planner(self): + self.hide() + self.path_planner.show() \ No newline at end of file diff --git a/main.py b/main.py index d5f1c53..aef07a2 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,13 @@ import sys import os import numpy as np -from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget, QMessageBox +from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QHBoxLayout, QWidget, QMessageBox from PySide6.QtGui import QPixmap, QMouseEvent, QPainter, QPen, QColor, QPainterPath, QPolygon, QFont from PySide6.QtCore import Qt, QPoint, QRect -class MainWindow(QMainWindow): +from buttonEditor import ButtonEditor + +class PathPlanner(QMainWindow): def __init__(self): super().__init__() @@ -23,15 +25,26 @@ class MainWindow(QMainWindow): else: self.image_label.setPixmap(self.pixmap) - #Buttons - self.clear_button = QPushButton("Clear Auto") - self.clear_button.clicked.connect(self.show_clear_warning) + #I want to put these in a side toolbar + #self.clear_button = QPushButton("Clear Auto") + #self.clear_button.clicked.connect(self.show_clear_warning) + + self.main_window_button = QPushButton("Main Window") + self.main_window_button.clicked.connect(self.show_main_window) + self.button_editor_button = QPushButton("Button Editor") + self.button_editor_button.clicked.connect(self.show_button_editor) + + button_layout = QHBoxLayout() + button_layout.addWidget(self.main_window_button) + button_layout.addWidget(self.button_editor_button) #Layout of the auto planner layout = QVBoxLayout() - layout.addWidget(self.clear_button) + layout.addLayout(button_layout) layout.addWidget(self.image_label) + self.button_editor = ButtonEditor(self) + container = QWidget() container.setLayout(layout) self.setCentralWidget(container) @@ -314,8 +327,16 @@ class MainWindow(QMainWindow): if reply == QMessageBox.Yes: self.clear_points() + def show_main_window(self): + self.show() + self.button_editor.hide() + + def show_button_editor(self): + self.hide() + self.button_editor.show() + if __name__ == "__main__": app = QApplication(sys.argv) - window = MainWindow() + window = PathPlanner() window.show() sys.exit(app.exec()) \ No newline at end of file