Hello,
I have a GUI where I click a button and I want it to launch tmy "A.I" Assistant (BAXTER_V5.py) but when I click the button on my GUI I get stuck in this loop:
How do I fix my code so this loop doesn't happen?
What I want to happen is, once I click the Online Mode Button I want to close my GUI and Run BAXTER_V5.py.
Any ideas on why this happens and how to fix it?
Thanks in advance.
BX_MainMenuGUI.py
I have a GUI where I click a button and I want it to launch tmy "A.I" Assistant (BAXTER_V5.py) but when I click the button on my GUI I get stuck in this loop:
Output:Online Mode Engaged
B.A.X.T.E.R A.I System
Systems Started...
Defaulting to Keyboard Input...
B.A.X.T.E.R System Online
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
...
How do I fix my code so this loop doesn't happen?
What I want to happen is, once I click the Online Mode Button I want to close my GUI and Run BAXTER_V5.py.
Any ideas on why this happens and how to fix it?
Thanks in advance.
BX_MainMenuGUI.py
import sys from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5.QtSql import QSqlDatabase, QSqlTableModel from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QMainWindow, QLabel, QLineEdit, QTableWidget, QTableWidgetItem, QGridLayout, QVBoxLayout, QSizePolicy, QSpacerItem, QMessageBox,QSpinBox, QComboBox, QTableView,QStyledItemDelegate) from PyQt5.QtCore import Qt, QMetaObject, QCoreApplication from PyQt5.QtGui import QFont import sqlite3 class Ui_MainMenu(QMainWindow): def __init__(self, parent = None): super(Ui_MainMenu, self).__init__(parent) self.setObjectName("MainMenu") self.resize(808, 594) self.setStyleSheet("background-color: rgb(0, 0, 0);") self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName("verticalLayout") self.TitleLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setFamily("Android Insomnia") font.setPointSize(20) font.setBold(True) font.setWeight(75) self.TitleLabel.setFont(font) self.TitleLabel.setStyleSheet("color: rgb(0, 255, 0);") self.TitleLabel.setAlignment(QtCore.Qt.AlignCenter) self.TitleLabel.setObjectName("TitleLabel") self.verticalLayout.addWidget(self.TitleLabel) self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) font = QtGui.QFont() font.setFamily("Runlion") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.textBrowser.setFont(font) self.textBrowser.setLayoutDirection(QtCore.Qt.LeftToRight) self.textBrowser.setStyleSheet("color: rgb(255, 170, 0);") self.textBrowser.setObjectName("textBrowser") self.verticalLayout.addWidget(self.textBrowser) self.textBrowser_2 = QtWidgets.QTextBrowser(self.centralwidget) font = QtGui.QFont() font.setFamily("Runlion") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.textBrowser_2.setFont(font) self.textBrowser_2.setStyleSheet("color: rgb(0, 0, 255);") self.textBrowser_2.setObjectName("textBrowser_2") self.verticalLayout.addWidget(self.textBrowser_2) self.OnlineButton = QtWidgets.QPushButton(self.centralwidget) font = QtGui.QFont() font.setFamily("Lethal Injector") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.OnlineButton.setFont(font) self.OnlineButton.setStyleSheet("background-color: rgb(0, 255, 0);\n" "border-style: outset;\n" "border-width: 2px;\n" "border-color: black;\n" "padding: 4px;") self.OnlineButton.setObjectName("OnlineButton") self.verticalLayout.addWidget(self.OnlineButton) self.OfflineButton = QtWidgets.QPushButton(self.centralwidget) font = QtGui.QFont() font.setFamily("Lethal Injector") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.OfflineButton.setFont(font) self.OfflineButton.setStyleSheet("background-color: rgb(255, 0, 0);\n" "border-style: outset;\n" "border-width: 2px;\n" "border-color: black;\n" "padding: 4px;") self.OfflineButton.setObjectName("OfflineButton") self.verticalLayout.addWidget(self.OfflineButton) self.SettingsButton = QtWidgets.QPushButton(self.centralwidget) font = QtGui.QFont() font.setFamily("Lethal Injector") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.SettingsButton.setFont(font) self.SettingsButton.setStyleSheet("background-color: rgb(255, 170, 0);\n" "border-style: outset;\n" "border-width: 2px;\n" "border-color: black;\n" "padding: 4px;") self.SettingsButton.setObjectName("SettingsButton") self.verticalLayout.addWidget(self.SettingsButton) self.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(self) self.statusbar.setObjectName("statusbar") self.setStatusBar(self.statusbar) self.retranslateUi(self) QtCore.QMetaObject.connectSlotsByName(self) #---------------------------------------------------------------------------------------------------- # Button Actions #---------------------------------------------------------------------------------------------------- #------------------------------------------ # Online Mode Button #------------------------------------------ #When the Online Mode button is clicked -> OnlineClicked Function OnlineButton = self.OnlineButton OnlineButton.clicked.connect(self.OnlineClicked) #------------------------------------------ #---------------------------------- # Online Mode Function #---------------------------------- def OnlineClicked(self): #Print in terminal for testing: print("Online Mode Engaged") self.close() #Close this screen #Run Baxter from BAXTER_V5 import BAXTER BAXTER() #---------------------------------- #---------------------------------------------------------------------------------------------------- # Retranslate Ui #---------------------------------------------------------------------------------------------------- def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("MainWindow", "BAXTER Menu")) self.TitleLabel.setText(_translate("MainWindow", "B.A.X.T.E.R A.I System")) self.textBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Runlion\'; font-size:12pt; font-weight:600; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Reminders:</p></body></html>")) self.textBrowser_2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Runlion\'; font-size:12pt; font-weight:600; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Todo:</p></body></html>")) self.OnlineButton.setText(_translate("MainWindow", "Online Mode")) self.OfflineButton.setText(_translate("MainWindow", "Offline Mode")) self.SettingsButton.setText(_translate("MainWindow", "Settings")) #---------------------------------------------------------------------------------------------------- # Run this Program #---------------------------------------------------------------------------------------------------- def main(): app = QApplication(sys.argv) win = Ui_MainMenu() win.show() sys.exit(app.exec_()) if __name__ == "__main__": main() #----------------------------------------------------------------------------------------------------BAXTER_V5.py
#------------------------------------------------------------------------------------- # Imports #------------------------------------------------------------------------------------- import json import random import datetime import operator import os import subprocess import time import sys from unittest import result import webbrowser import requests from bs4 import BeautifulSoup import wikipedia import wolframalpha import pywhatkit import threading from BX_Intents import (greetings, farewell, thanks, noAnswer, youChoose) from BX_External_Functions import (autoTypeAnimation, StartupText, ShutdownText, UserInput, listen, speak, getRandomJoke, getFunFacts, setReminders, terminateTimers) from pairs import chat #------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------- # Commander Name (You) and A.I Name #------------------------------------------------------------------------------------- Commander = "Commander" AI_Name = 'Baxter' #------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------- # WishMe Function #------------------------------------------------------------------------------------- def wishMe(): hour = int(datetime.datetime.now().hour) if hour>=0 and hour<12: speak("Good Morning" + Commander) elif hour>=12 and hour<18: speak("Good Afternoon" + Commander) else: speak("Good Evening" + Commander) #------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------- # Main #------------------------------------------------------------------------------------- def BAXTER(): command = UserInput() command=str(command).lower() #------------------------------------------------------------------------------------- # General Conversation (From Intents.py) #------------------------------------------------------------------------------------- #Greetings patterns, responses = greetings() if (command in patterns): results = (random.choice(responses)) autoTypeAnimation(results) speak(results) #Farewell patterns, responses = farewell() if (command in patterns): results = (random.choice(responses)) autoTypeAnimation(results) speak(results) #Thanks patterns, responses = thanks() if (command in patterns): results = (random.choice(responses)) autoTypeAnimation(results) speak(results) #No Response patterns, responses = noAnswer() if (command in patterns): results = (random.choice(responses)) autoTypeAnimation(results) speak(results) #------------------------- # Tell a Joke #------------------------- if ('joke' in command): joke = getRandomJoke() autoTypeAnimation(joke) speak(joke) #------------------------- #------------------------- # Tell a Fun Fact #------------------------- if ('fact' in command): funFact = getFunFacts() autoTypeAnimation(funFact) speak(funFact) #------------------------- #------------------------------------------------------------------------------------- # Search Wikipedia (General Info) #------------------------------------------------------------------------------------- if ('weather' not in command): if ('who is' in command) or ('what is the' in command) or ('what is a' in command) or ("what is" in command): if ('time' not in command): if ('news' not in command): speak('Searching...') command = command.replace("who is","") command = command.replace("what is the","") command = command.replace("what is a","") command = command.replace("what is","") results = wikipedia.summary(command, sentences = 2) autoTypeAnimation(results) speak(results) #------------------------------------------------------------------------------------- # Search Wolfram Alpha (Math/Conversions, Definitions) #------------------------------------------------------------------------------------- if ('news' not in command): if ('weather' in command) or ('calculate' in command) or ("what's" in command) or ('define' in command) or ("what" in command): speak('Searching...') command = command.replace("calculate","") command = command.replace("what's","") command = command.replace("define","") # Wolframalpha App Id appId = 'JH9XHR-W9J76L7H5A' # Wolfram Instance client = wolframalpha.Client(appId) res = client.query(''.join(command)) results = next(res.results).text autoTypeAnimation(results) speak(results) #------------------------------------------------------------------------------------- # Open Stuff on the Internet #------------------------------------------------------------------------------------- #Open Youtube Videos (Ex: 'Play __ on youtube') if ('youtube' in command): autoTypeAnimation("Launching Youtube...") speak('Launching Youtube') command = command.replace("youtube","") pywhatkit.playonyt(command) #Open Google Maps and Find The Location of A You Want if ('where is' in command): command = command.replace("where is","") autoTypeAnimation("Locating" + command + "...") speak('Locating' + command) webbrowser.open_new_tab("https://www.google.com/maps/place/" + command) #Search Stuff on Google if ('search' in command): command = command.replace("search", "") autoTypeAnimation("Searching" + command + " on Google") speak('Searching' + command) pywhatkit.search(command) #Close Firefox if ('close firefox' in command): autoTypeAnimation("Terminating Firefox...") speak('Closing Firefox') command = command.replace("close firefox", "") browser = "firefox.exe" os.system("taskkill /f /im " + browser) #------------------------------------------------------------------------------------- # Open Stuff on the Computer #------------------------------------------------------------------------------------- #Open Windows Media Player and Auto Play the Playlist Called Music if ('play music' in command) or ('media player' in command) or ('drop the needle' in command): autoTypeAnimation("Launching music...") speak("Launching Music") command = command.replace("play music", "") command = command.replace("media player", "") command = command.replace("drop the needle", "") subprocess.Popen("C:\Program Files (x86)\Windows Media Player\wmplayer.exe /Playlist Music") #Close Windows Media Player if ('stop music' in command): autoTypeAnimation("Terminating music...") speak('Closing Music') command = command.replace("stop music", "") mediaPlayer = "wmplayer.exe" os.system("taskkill /f /im " + mediaPlayer) #------------------------------------------------------------------------------------- # Set Reminders #------------------------------------------------------------------------------------- if ('remind me' in command): command = command.replace("remind me", "") setReminders(command) #Call setReminders() from External Functions #------------------------------------------------------------------------------------- # Stop Program/Script Command #------------------------------------------------------------------------------------- if ('stop' in command) or ('shutdown' in command) or ('quit' in command): speak("Shutting Down...") results = "Terminating program..." autoTypeAnimation(results) ShutdownText() terminateTimers() exit() #------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------ # Run The Program #------------------------------------------------------------------------------------------ StartupText() wishMe() speak("How may I be of service?") while True: BAXTER() #------------------------------------------------------------------------------------------