Newer
Older
from PyQt6.QtCore import Qt
import RegressionModel
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget,
QVBoxLayout, QHBoxLayout, QGridLayout,
QLabel, QPushButton, QSlider, QDateTimeEdit,
QLineEdit, QComboBox, QDateEdit, QTabWidget, QCheckBox)
from PyQt6.QtGui import QPalette, QColor, QIcon
class MyTabs(QMainWindow):
def __init__(self):
super().__init__()
# Create your custom pages (e.g., TradeView and OrderView)
trade_view = MainWindow()
order_view = Advanced()
# Create a tab widget
tab_widget = QTabWidget(self)
tab_widget.addTab(trade_view, "Main")
tab_widget.addTab(order_view, "Advanced")
# Set the central widget
self.setCentralWidget(tab_widget)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setMinimumSize(720, 640)
# Create a central widget
central_widget = QWidget(self)
self.setCentralWidget(central_widget)
# Create a grid layout and set it to the central widget
grid_layout = QGridLayout(central_widget)
# Create labels and input fields
self.labels_text = ['Cut', 'Colour', 'Clarity', 'Carat', 'Depth', 'Table', 'X', 'Y', 'Z']
self.input_fields = [QComboBox(self), QComboBox(self), QComboBox(self), QLineEdit(self),
QLineEdit(self), QLineEdit(self), QLineEdit(self), QLineEdit(self),
QLineEdit(self)]
self.input_fields[0].addItems(RegressionModel.cut)
self.input_fields[1].addItems(RegressionModel.colors)
self.input_fields[2].addItems(RegressionModel.clarity)
# add a button to capture all the data
self.calculate_button = QPushButton('Calculate Price', self)
self.calculate_button.clicked.connect(self.update_values)
# Add labels and input fields to the grid layout
for i in range(len(self.labels_text)):
label = QLabel(self.labels_text[i], self)
grid_layout.addWidget(label, 0, i)
grid_layout.addWidget(self.input_fields[i], 1, i)
# Create a plot widget
graphWidget = pg.PlotWidget(self)
graphWidget.setBackground('w')
graphWidget.plot(RegressionModel.diamonds['carat'], RegressionModel.diamonds['price'])
# Add the plot widget to the grid layout
grid_layout.addWidget(self.calculate_button, 2, 0, 1, 2)
grid_layout.addWidget(graphWidget, 3, 0, 1, 9)
grid_layout.addWidget(QLabel("Predicted Price: ", self), 4, 0, 1, 1)
grid_layout.addWidget(QLabel(str(RegressionModel.price), self), 4, 2, 1, 1)
# Remember to add the predicted price
self.setWindowTitle('Assistance Systems')
self.show()
def update_values(self):
menu_items = {0: 'cut', 1: 'color', 2: 'clarity', 3: 'carat', 4: 'depth', 5: 'table',
6: 'x', 7: 'y', 8: 'z'}
for key, value in menu_items.items():
print(key)
if key < 3:
RegressionModel.GUI_selections[value] = self.input_fields[key].currentText()
else:
RegressionModel.GUI_selections[value] = self.input_fields[key].text()
print(RegressionModel.GUI_selections)
class Advanced(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowIcon(QIcon("icon.ico"))
self.setMinimumSize(720, 640)
central_widget = QWidget(self)
self.setCentralWidget(central_widget)
# Create a grid layout and set it to the central widget
grid_layout = QGridLayout(central_widget)
self.graph_selector_X = QComboBox(self)
self.graph_selector_Y = QComboBox(self)
self.regression_model = QComboBox(self)
self.check_labels = ['Cut', 'Colour', 'Clarity', 'Carat', 'Depth', 'Table', 'X', 'Y', 'Z']
self.graph_selector_X.addItems((self.check_labels + ['price']))
self.graph_selector_Y.addItems((self.check_labels + ['price']))
self.regression_model.addItems(["Linear Regression", "Gradient Descent", "Random Forest"])
grid_layout.addWidget(QLabel("select features to include in Modelling"), 0, 0, 1, 0)
# grid_layout.addWidget(self.graph_selector_X, 1, 2)
# grid_layout.addWidget(self.graph_selector_Y, 1, 3)
grid_layout.addWidget(self.regression_model, 2, 1)
# grid_layout.addWidget(QLabel("X-PLOT", self), 0, 2)
# grid_layout.addWidget(QLabel("Y-PLOT", self), 0, 3)
grid_layout.addWidget(QLabel("Regression Model : ", self), 2, 0,1,1)
for i, label in enumerate(self.check_labels):
checkbox = QCheckBox(label, self)
checkbox.setChecked(True)
checkbox.stateChanged.connect(self.handle_checkbox_state) # Connect signal
grid_layout.addWidget(checkbox, 1, i)
self.checkboxes.append(checkbox) # Store checkboxes in the list
def handle_checkbox_state(self):
for i, checkbox in enumerate(self.checkboxes):
state = checkbox.checkState()
RegressionModel.Advanced_selections[checkbox.text()] = (state == Qt.CheckState.Checked)
app = QApplication(sys.argv)