productionbotscreen removed

This commit is contained in:
jothi
2025-08-06 13:42:30 +05:30
parent 1d554281e5
commit 904ca253c2

434
pds.py
View File

@@ -267,223 +267,223 @@ class ChatScrollArea(QScrollArea):
self.verticalScrollBar().setValue(self.verticalScrollBar().maximum()) self.verticalScrollBar().setValue(self.verticalScrollBar().maximum())
class ProductionBotScreen(QWidget): # class ProductionBotScreen(QWidget):
def __init__(self, back_action=None): # def __init__(self, back_action=None):
super().__init__() # super().__init__()
self.back_action = back_action # self.back_action = back_action
#
self.chart_map = {} # self.chart_map = {}
self.plant_map = {} # self.plant_map = {}
self.awaiting_plants = False # self.awaiting_plants = False
#
self.init_tts() # self.init_tts()
self._setup_ui() # self._setup_ui()
#
QTimer.singleShot(500, self._show_greeting) # QTimer.singleShot(500, self._show_greeting)
QTimer.singleShot(1500, self.load_charts) # QTimer.singleShot(1500, self.load_charts)
#
self.tts_queue = queue.Queue() # self.tts_queue = queue.Queue()
self.tts_thread = threading.Thread(target=self.tts_worker, daemon=True) # self.tts_thread = threading.Thread(target=self.tts_worker, daemon=True)
self.tts_thread.start() # self.tts_thread.start()
#
def init_tts(self): # def init_tts(self):
self.tts_engine = pyttsx3.init() # self.tts_engine = pyttsx3.init()
self.tts_engine.setProperty('rate', 170) # self.tts_engine.setProperty('rate', 170)
#
def _setup_ui(self): # def _setup_ui(self):
layout = QVBoxLayout(self) # layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0) # layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0) # layout.setSpacing(0)
#
header = QWidget() # header = QWidget()
header.setFixedHeight(70) # header.setFixedHeight(70)
# Fix indentation here: # # Fix indentation here:
header.setStyleSheet(""" # header.setStyleSheet("""
background: qlineargradient(x1:0,y1:0,x2:1,y2:0, # background: qlineargradient(x1:0,y1:0,x2:1,y2:0,
stop:0 #B0E0E6, stop:1 #F3C2C2); # stop:0 #B0E0E6, stop:1 #F3C2C2);
color: #333; # color: #333;
font-size: 22px; # font-size: 22px;
""") # """)
hlayout = QHBoxLayout(header) # hlayout = QHBoxLayout(header)
hlayout.setContentsMargins(10, 5, 10, 5) # hlayout.setContentsMargins(10, 5, 10, 5)
#
logo = QLabel() # logo = QLabel()
pix = QPixmap("cri_logo.png") # Corrected filename # pix = QPixmap("cri_logo.png") # Corrected filename
if pix and not pix.isNull(): # if pix and not pix.isNull():
logo.setPixmap(pix.scaled(60, 60, Qt.AspectRatioMode.KeepAspectRatio)) # logo.setPixmap(pix.scaled(60, 60, Qt.AspectRatioMode.KeepAspectRatio))
hlayout.addWidget(logo) # hlayout.addWidget(logo)
#
title = QLabel("PRODUCTION BOT") # title = QLabel("PRODUCTION BOT")
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #333;") # title.setStyleSheet("font-size: 24px; font-weight: bold; color: #333;")
hlayout.addWidget(title) # hlayout.addWidget(title)
hlayout.addStretch(1) # hlayout.addStretch(1)
#
self.back_btn = QPushButton("Back") # self.back_btn = QPushButton("Back")
self.back_btn.setStyleSheet(""" # self.back_btn.setStyleSheet("""
QPushButton { # QPushButton {
background: #C71585; # background: #C71585;
color: white; # color: white;
border-radius: 8px; # border-radius: 8px;
padding: 8px 14px; # padding: 8px 14px;
font-weight: bold; # font-weight: bold;
} # }
QPushButton:hover { # QPushButton:hover {
background: #b95975; # background: #b95975;
} # }
""") # """)
if self.back_action: # if self.back_action:
self.back_btn.clicked.connect(self.back_action) # self.back_btn.clicked.connect(self.back_action)
hlayout.addWidget(self.back_btn) # hlayout.addWidget(self.back_btn)
#
self.refresh_btn = QPushButton("Refresh") # self.refresh_btn = QPushButton("Refresh")
self.refresh_btn.setStyleSheet(""" # self.refresh_btn.setStyleSheet("""
QPushButton { # QPushButton {
background: #C71585; # background: #C71585;
color: white; # color: white;
border-radius: 8px; # border-radius: 8px;
padding: 8px 14px; # padding: 8px 14px;
font-weight: bold; # font-weight: bold;
} # }
QPushButton:hover { # QPushButton:hover {
background: #b95975; # background: #b95975;
} # }
""") # """)
hlayout.addWidget(self.refresh_btn) # hlayout.addWidget(self.refresh_btn)
#
layout.addWidget(header) # layout.addWidget(header)
#
self.chat_area = ChatScrollArea() # self.chat_area = ChatScrollArea()
self.chat_area.setStyleSheet(""" # self.chat_area.setStyleSheet("""
QScrollArea { # QScrollArea {
background: qlineargradient(x1:0,y1:0,x2:1,y2:1, # background: qlineargradient(x1:0,y1:0,x2:1,y2:1,
stop:0 #b0e6e6, stop:1 #f3c2c2); # stop:0 #b0e6e6, stop:1 #f3c2c2);
} # }
""") # """)
layout.addWidget(self.chat_area, stretch=1) # layout.addWidget(self.chat_area, stretch=1)
#
input_area = QWidget() # input_area = QWidget()
input_layout = QHBoxLayout(input_area) # input_layout = QHBoxLayout(input_area)
input_layout.setContentsMargins(10, 10, 10, 10) # input_layout.setContentsMargins(10, 10, 10, 10)
#
self.user_input = QLineEdit() # self.user_input = QLineEdit()
self.user_input.setPlaceholderText("Type your message...") # self.user_input.setPlaceholderText("Type your message...")
self.user_input.setStyleSheet(""" # self.user_input.setStyleSheet("""
QLineEdit { # QLineEdit {
font-size: 16px; # font-size: 16px;
padding: 8px; # padding: 8px;
border: 2px solid #db7093; # border: 2px solid #db7093;
border-radius: 4px; # border-radius: 4px;
} # }
QLineEdit:focus { # QLineEdit:focus {
border-color: #f3c2c2; # border-color: #f3c2c2;
background: #fff0f0; # background: #fff0f0;
} # }
""") # """)
self.send_btn = QPushButton("Send") # self.send_btn = QPushButton("Send")
self.send_btn.setStyleSheet(""" # self.send_btn.setStyleSheet("""
QPushButton { # QPushButton {
background: #006400; # background: #006400;
color: white; # color: white;
font-weight: bold; # font-weight: bold;
padding: 8px 20px; # padding: 8px 20px;
border-radius: 8px; # border-radius: 8px;
} # }
QPushButton:hover { # QPushButton:hover {
background: #a2136a; # background: #a2136a;
} # }
""") # """)
input_layout.addWidget(self.user_input) # input_layout.addWidget(self.user_input)
input_layout.addWidget(self.send_btn) # input_layout.addWidget(self.send_btn)
#
layout.addWidget(input_area) # layout.addWidget(input_area)
#
self.send_btn.clicked.connect(self._on_send) # self.send_btn.clicked.connect(self._on_send)
#
def _on_send(self): # def _on_send(self):
msg = self.user_input.text().strip() # msg = self.user_input.text().strip()
if not msg: # if not msg:
return # return
self.chat_area.add_bubble(msg, True) # self.chat_area.add_bubble(msg, True)
self.user_input.clear() # self.user_input.clear()
#
if msg.isdigit(): # if msg.isdigit():
idx = int(msg) # idx = int(msg)
if self.awaiting_plants: # if self.awaiting_plants:
plant = self.plant_map.get(idx) # plant = self.plant_map.get(idx)
if plant: # if plant:
self.plant_selected(plant) # self.plant_selected(plant)
else: # else:
self.chat_area.add_bubble("Invalid plant number. Please try again.", False) # self.chat_area.add_bubble("Invalid plant number. Please try again.", False)
self.speak("Invalid plant number. Please try again.") # self.speak("Invalid plant number. Please try again.")
else: # else:
chart = self.chart_map.get(idx) # chart = self.chart_map.get(idx)
if chart: # if chart:
self.chart_selected(chart) # self.chart_selected(chart)
else: # else:
self.chat_area.add_bubble("Invalid chart number. Please try again.", False) # self.chat_area.add_bubble("Invalid chart number. Please try again.", False)
self.speak("Invalid chart number. Please try again.") # self.speak("Invalid chart number. Please try again.")
else: # else:
self.chat_area.add_bubble("Please enter a valid number.", False) # self.chat_area.add_bubble("Please enter a valid number.", False)
self.speak("Please enter a valid number.") # self.speak("Please enter a valid number.")
#
def load_charts(self): # def load_charts(self):
url = "https://pds.iotsignin.com/api/get/modulechart-name/data" # url = "https://pds.iotsignin.com/api/get/modulechart-name/data"
headers = { # headers = {
"Authorization": "Bearer sb-eba140ab-74bb-44a4-8d92-70a636940def!b1182|it-rt-dev-cri-stjllphr!b68:616d8991-307b-4ab1-be37-7894a8c6db9d$0p0fE2I7w1Ve23-lVSKQF0ka3mKrTVcKPJYELr-i4nE=", # "Authorization": "Bearer sb-eba140ab-74bb-44a4-8d92-70a636940def!b1182|it-rt-dev-cri-stjllphr!b68:616d8991-307b-4ab1-be37-7894a8c6db9d$0p0fE2I7w1Ve23-lVSKQF0ka3mKrTVcKPJYELr-i4nE=",
"module-name": "Production DashBoard" # "module-name": "Production DashBoard"
} # }
#
try: # try:
response = requests.get(url, headers=headers, timeout=10) # response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status() # response.raise_for_status()
data = response.json() # data = response.json()
if data.get("status_code") == "SUCCESS": # if data.get("status_code") == "SUCCESS":
charts = data.get("status_description", []) # charts = data.get("status_description", [])
self.chart_map = {i + 1: c for i, c in enumerate(charts)} # self.chart_map = {i + 1: c for i, c in enumerate(charts)}
numbered = "\n".join(f"{num}. {name}" for num, name in self.chart_map.items()) # numbered = "\n".join(f"{num}. {name}" for num, name in self.chart_map.items())
self.chat_area.add_bubble("Please select a chart:\n\n" + numbered, False) # self.chat_area.add_bubble("Please select a chart:\n\n" + numbered, False)
self.speak("Please select a chart.") # self.speak("Please select a chart.")
else: # else:
self.chat_area.add_bubble("Failed to load charts.", False) # self.chat_area.add_bubble("Failed to load charts.", False)
self.speak("Failed to load charts.") # self.speak("Failed to load charts.")
except Exception as e: # except Exception as e:
self.chat_area.add_bubble(f"Error loading charts: {str(e)}", False) # self.chat_area.add_bubble(f"Error loading charts: {str(e)}", False)
self.speak("Error loading charts.") # self.speak("Error loading charts.")
#
def chart_selected(self, chart_name): # def chart_selected(self, chart_name):
self.chat_area.add_bubble(f"You selected: {chart_name}", False) # self.chat_area.add_bubble(f"You selected: {chart_name}", False)
self.speak(f"You selected {chart_name}") # self.speak(f"You selected {chart_name}")
self.awaiting_plants = True # self.awaiting_plants = True
QTimer.singleShot(500, self.load_plants) # QTimer.singleShot(500, self.load_plants)
#
def load_plants(self): # def load_plants(self):
url = "https://pds.iotsignin.com/api/get/moduleplant-name/data" # Correct API URL for plants # url = "https://pds.iotsignin.com/api/get/moduleplant-name/data" # Correct API URL for plants
headers = { # headers = {
"Authorization": "Bearer sb-eba140ab-74bb-44a4-8d92-70a636940def!b1182|it-rt-dev-cri-stjllphr!b68:616d8991-307b-4ab1-be37-7894a8c6db9d$0p0fE2I7w1Ve23-lVSKQF0ka3mKrTVcKPJYELr-i4nE=", # "Authorization": "Bearer sb-eba140ab-74bb-44a4-8d92-70a636940def!b1182|it-rt-dev-cri-stjllphr!b68:616d8991-307b-4ab1-be37-7894a8c6db9d$0p0fE2I7w1Ve23-lVSKQF0ka3mKrTVcKPJYELr-i4nE=",
"plant-name": "Plant List" # "plant-name": "Plant List"
} # }
#
try: # try:
response = requests.get(url, headers=headers, timeout=10) # response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status() # response.raise_for_status()
data = response.json() # data = response.json()
if data.get("status_code") == "SUCCESS": # if data.get("status_code") == "SUCCESS":
plants = data.get("status_description", []) # plants = data.get("status_description", [])
self.plant_map = {i + 1: p for i, p in enumerate(plants)} # self.plant_map = {i + 1: p for i, p in enumerate(plants)}
numbered = "\n".join(f"{num}. {name}" for num, name in self.plant_map.items()) # numbered = "\n".join(f"{num}. {name}" for num, name in self.plant_map.items())
self.chat_area.add_bubble("Please select a plant:\n\n" + numbered, False) # self.chat_area.add_bubble("Please select a plant:\n\n" + numbered, False)
self.speak("Please select a plant.") # self.speak("Please select a plant.")
else: # else:
self.chat_area.add_bubble("Failed to load plants.", False) # self.chat_area.add_bubble("Failed to load plants.", False)
self.speak("Failed to load plants.") # self.speak("Failed to load plants.")
except Exception as e: # except Exception as e:
self.chat_area.add_bubble(f"Error loading plants: {str(e)}", False) # self.chat_area.add_bubble(f"Error loading plants: {str(e)}", False)
self.speak("Error loading plants.") # self.speak("Error loading plants.")
#
def plant_selected(self, plant_name): # def plant_selected(self, plant_name):
self.chat_area.add_bubble(f"You selected plant: {plant_name}", False) # self.chat_area.add_bubble(f"You selected plant: {plant_name}", False)
self.speak(f"You selected plant {plant_name}") # self.speak(f"You selected plant {plant_name}")
self.awaiting_plants = False # self.awaiting_plants = False
# InvoiceBotScreen, independent UI and logic # InvoiceBotScreen, independent UI and logic
class InvoiceBotScreen(QWidget): class InvoiceBotScreen(QWidget):