diff --git a/gui/database/postgresql.py b/gui/database/postgresql.py
index 156c66c..78a9ce4 100644
--- a/gui/database/postgresql.py
+++ b/gui/database/postgresql.py
@@ -21,7 +21,7 @@ class Postgres:
self.get_schema()
def __str__(self):
- return f'PostgreSQL Server: {self.db_ip}:{self.db_port} as {self.db_username} on database {self.db_name}'
+ return f'PostgreSQL'
def get_schema(self) -> dict:
fetch = self.fetchall("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';")
diff --git a/gui/gui/Window.py b/gui/gui/Window.py
index 0e72770..a7b2456 100644
--- a/gui/gui/Window.py
+++ b/gui/gui/Window.py
@@ -50,7 +50,7 @@ class Ui_MainWindow(object):
self.outputTableLabel.setGeometry(QtCore.QRect(20, 250, 49, 16))
self.outputTableLabel.setObjectName("outputTableLabel")
self.shellInput = QtWidgets.QTextEdit(self.centralwidget)
- self.shellInput.setGeometry(QtCore.QRect(410, 80, 375, 111))
+ self.shellInput.setGeometry(QtCore.QRect(410, 80, 371, 111))
self.shellInput.setObjectName("shellInput")
self.statementOutput = QtWidgets.QTextEdit(self.centralwidget)
self.statementOutput.setEnabled(True)
@@ -81,7 +81,14 @@ class Ui_MainWindow(object):
self.menubar.addAction(self.menuSettings.menuAction())
self.retranslateUi(MainWindow)
+ self.textInput.returnPressed.connect(self.convertButton.click) # type: ignore
QtCore.QMetaObject.connectSlotsByName(MainWindow)
+ MainWindow.setTabOrder(self.textInput, self.convertButton)
+ MainWindow.setTabOrder(self.convertButton, self.pasteButton)
+ MainWindow.setTabOrder(self.pasteButton, self.shellInput)
+ MainWindow.setTabOrder(self.shellInput, self.executeButton)
+ MainWindow.setTabOrder(self.executeButton, self.outputTable)
+ MainWindow.setTabOrder(self.outputTable, self.statementOutput)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
diff --git a/gui/gui/Window.ui b/gui/gui/Window.ui
index c96be20..3fa8049 100644
--- a/gui/gui/Window.ui
+++ b/gui/gui/Window.ui
@@ -143,7 +143,7 @@
410
80
- 375
+ 371
111
@@ -214,6 +214,32 @@ p, li { white-space: pre-wrap; }
+
+ textInput
+ convertButton
+ pasteButton
+ shellInput
+ executeButton
+ outputTable
+ statementOutput
+
-
+
+
+ textInput
+ returnPressed()
+ convertButton
+ click()
+
+
+ 262
+ 69
+
+
+ 724
+ 67
+
+
+
+
diff --git a/gui/gui/apikey.py b/gui/gui/apikey.py
index 3ec31f0..52bd8c6 100644
--- a/gui/gui/apikey.py
+++ b/gui/gui/apikey.py
@@ -32,6 +32,7 @@ class Ui_ApiKey(object):
self.outputLabel.setObjectName("outputLabel")
self.retranslateUi(ApiKey)
+ self.apikeyInput.returnPressed.connect(self.testButton.click) # type: ignore
QtCore.QMetaObject.connectSlotsByName(ApiKey)
def retranslateUi(self, ApiKey):
diff --git a/gui/gui/apikey.ui b/gui/gui/apikey.ui
index 177deb5..30d946b 100644
--- a/gui/gui/apikey.ui
+++ b/gui/gui/apikey.ui
@@ -77,5 +77,22 @@
-
+
+
+ apikeyInput
+ returnPressed()
+ testButton
+ click()
+
+
+ 153
+ 27
+
+
+ 91
+ 53
+
+
+
+
diff --git a/gui/gui/connection.py b/gui/gui/connection.py
index 165b06e..6ade67a 100644
--- a/gui/gui/connection.py
+++ b/gui/gui/connection.py
@@ -68,7 +68,19 @@ class Ui_Connection(object):
self.dbtypeCombo.setObjectName("dbtypeCombo")
self.retranslateUi(Connection)
+ self.ipInput.returnPressed.connect(self.portInput.setFocus) # type: ignore
+ self.portInput.returnPressed.connect(self.usernameInput.setFocus) # type: ignore
+ self.usernameInput.returnPressed.connect(self.passwordInput.setFocus) # type: ignore
+ self.passwordInput.returnPressed.connect(self.databaseInput.setFocus) # type: ignore
+ self.databaseInput.returnPressed.connect(self.testButton.click) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Connection)
+ Connection.setTabOrder(self.dbtypeCombo, self.ipInput)
+ Connection.setTabOrder(self.ipInput, self.portInput)
+ Connection.setTabOrder(self.portInput, self.usernameInput)
+ Connection.setTabOrder(self.usernameInput, self.passwordInput)
+ Connection.setTabOrder(self.passwordInput, self.databaseInput)
+ Connection.setTabOrder(self.databaseInput, self.testButton)
+ Connection.setTabOrder(self.testButton, self.saveButton)
def retranslateUi(self, Connection):
_translate = QtCore.QCoreApplication.translate
diff --git a/gui/gui/connection.ui b/gui/gui/connection.ui
index 2716bb3..7c827fc 100644
--- a/gui/gui/connection.ui
+++ b/gui/gui/connection.ui
@@ -209,6 +209,97 @@
+
+ dbtypeCombo
+ ipInput
+ portInput
+ usernameInput
+ passwordInput
+ databaseInput
+ testButton
+ saveButton
+
-
+
+
+ ipInput
+ returnPressed()
+ portInput
+ setFocus()
+
+
+ 167
+ 43
+
+
+ 167
+ 87
+
+
+
+
+ portInput
+ returnPressed()
+ usernameInput
+ setFocus()
+
+
+ 200
+ 83
+
+
+ 205
+ 111
+
+
+
+
+ usernameInput
+ returnPressed()
+ passwordInput
+ setFocus()
+
+
+ 140
+ 117
+
+
+ 138
+ 137
+
+
+
+
+ passwordInput
+ returnPressed()
+ databaseInput
+ setFocus()
+
+
+ 187
+ 143
+
+
+ 184
+ 167
+
+
+
+
+ databaseInput
+ returnPressed()
+ testButton
+ click()
+
+
+ 157
+ 173
+
+
+ 84
+ 205
+
+
+
+
diff --git a/gui/main.py b/gui/main.py
index 59cb62c..6d08429 100644
--- a/gui/main.py
+++ b/gui/main.py
@@ -3,7 +3,7 @@ import os
import sys
from PyQt5.QtCore import QObject, QThread, pyqtSignal
-from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog
+from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QTableWidgetItem, QTableWidget
import modules.aisql as aisql
@@ -98,6 +98,7 @@ class Worker(QObject):
test = False
db = None
tableschema = []
+ result = ""
def __init__(self):
super().__init__()
@@ -121,24 +122,40 @@ class Worker(QObject):
def connect_db_worker(self):
self.db, self.tableschema = connect_db()
-
- def testing(self):
- self.connect_db_worker()
- print('test')
- self.finished.emit()
-
-# TODO: Add a translation Worker and a SQL Worker
def translate(self, text):
- print("Translating...")
+ # Load Config
+ self.connect_db_worker()
+ dbtype, dbip, dbport, dbuser, dbpassword, dbname, apikey = load_config()
+ ai = aisql.AI(apikey)
+ self.result = ai.humantosql(text, str(self.db), self.tableschema)
self.finished.emit()
def run_sql(self, sql):
print("Running SQL...")
+ db, tableschema = connect_db()
+ ai = aisql.AI(api_key=load_config()[6])
+ choice = ai.decide(sql)
+
+ print(choice)
+
+ if "fetchall".casefold() in choice.casefold():
+ self.result = db.fetchall(sql)
+ elif "fetchone".casefold() in choice.casefold():
+ self.result = db.fetchone(sql)
+ elif "execute".casefold() in choice.casefold():
+ self.result = db.execute(sql)
+ else:
+ print("error")
+
+ print(self.result)
self.finished.emit()
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
+ self.setupUi()
+
+ def setupUi(self):
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.tableschema = []
@@ -153,13 +170,19 @@ class MainWindow(QMainWindow):
self.ui.actionConnect_API_Key.triggered.connect(self.open_apikey)
# Pressed Convert Button
- self.ui.convertButton.clicked.connect(self.on_convert_button_clicked)
+ # FIXME: UI still freezes when clicked, QThreads not working properly
+ self.ui.convertButton.clicked.connect(self.convert)
# Pressed Paste Button
self.ui.pasteButton.clicked.connect(self.on_paste_button_clicked)
+ # TODO: Functioning Execute Button
# Pressed Execute Button
- self.ui.executeButton.clicked.connect(self.on_execute_button_clicked)
+ self.ui.executeButton.clicked.connect(self.execute)
+
+ self.ui.outputTable.setColumnCount(2)
+ self.ui.outputTable.setHorizontalHeaderLabels(["Column", "Value"])
+
def try_to_connect(self):
# TODO: Rewrite to use a Worker
@@ -179,71 +202,59 @@ class MainWindow(QMainWindow):
self.apikey_window = ApiKeyWindow(self)
self.apikey_window.show()
- def on_execute_button_clicked(self):
+ # TODO: Make this work
+ def execute(self):
self.ui.outputLabel.setText("Executing...")
self.ui.outputLabel.show()
self.ui.executeButton.setEnabled(False)
- sql = self.ui.shellInput.toPlainText()
-
- self.thread = QThread()
self.worker = Worker()
+ self.thread = QThread()
self.worker.moveToThread(self.thread)
- self.thread.started.connect(self.worker.testing)
- self.worker.finished.connect(self.execute_finish)
+ self.worker.finished.connect(self.thread.quit)
+ self.worker.finished.connect(self.worker.deleteLater)
+ self.thread.finished.connect(self.thread.deleteLater)
+
+ self.thread.started.connect(lambda: self.worker.run_sql(self.ui.shellInput.toPlainText()))
+ self.worker.finished.connect(self.execute_finished)
self.thread.start()
- def execute_finish(self):
+ def execute_finished(self):
+ self.data = self.worker.result
self.ui.outputLabel.setText("Finished!")
self.ui.outputLabel.show()
self.ui.executeButton.setEnabled(True)
- print("finished")
- self.worker.deleteLater()
- self.thread.deleteLater()
- print("deleted")
- def on_convert_button_clicked(self):
+
+ def convert(self):
self.ui.outputLabel.setText("Converting...")
self.ui.outputLabel.show()
self.ui.convertButton.setEnabled(False)
- # def start_db_test_thread(self):
- # self.ui.returnLabel.setText("Testing...")
- # self.ui.returnLabel.setStyleSheet("color: black;")
- # self.ui.testButton.setEnabled(False)
- #
- # dbtype = self.ui.dbtypeCombo.currentIndex()
- # ip = self.ui.ipInput.text()
- # port = self.ui.portInput.text()
- # user = self.ui.usernameInput.text()
- # password = self.ui.passwordInput.text()
- # database = self.ui.databaseInput.text()
- #
- # self.thread = QThread()
- # self.worker = Worker()
- # self.worker.moveToThread(self.thread)
- #
- # self.thread.started.connect(
- # lambda: self.worker.test_db_connection(dbtype, ip, port, user, password, database))
- # self.worker.finished.connect(self.thread.quit)
- # self.thread.finished.connect(self.thread_complete)
- #
- # self.thread.start()
- #
- # def thread_complete(self):
- # if self.worker.test:
- # self.ui.returnLabel.setText("Connection Success!")
- # self.ui.returnLabel.setStyleSheet("color: green;")
- # else:
- # self.ui.returnLabel.setText("Connection Failed!")
- # self.ui.returnLabel.setStyleSheet("color: red;")
- #
- # self.ui.testButton.setEnabled(True)
- # self.worker.deleteLater()
- # self.thread.deleteLater()
+ self.worker = Worker()
+ self.thread = QThread()
+ self.worker.moveToThread(self.thread)
+
+ self.worker.finished.connect(self.thread.quit)
+ self.worker.finished.connect(self.worker.deleteLater)
+ self.thread.finished.connect(self.thread.deleteLater)
+
+ self.thread.started.connect(lambda: self.worker.translate(self.ui.textInput.text()))
+ self.worker.finished.connect(self.convert_finished)
+
+ self.thread.start()
+
+ def convert_finished(self):
+ self.ui.statementOutput.setText(self.worker.result)
+ self.ui.outputLabel.setText("Finished!")
+ self.ui.outputLabel.show()
+ self.ui.convertButton.setEnabled(True)
+
+ # TODO: Convert Function Threading
+ # FIXME: Still freezing UI even with threading
### Connection Window ###
@@ -252,10 +263,9 @@ class ConnectionWindow(QDialog):
super().__init__(parent)
self.ui = ConnectionForm()
self.ui.setupUi(self)
- self.ui.saveButton.setEnabled(False)
- self.ui.testButton.setEnabled(False)
self.ui.returnLabel.setText("")
+
# Load DB Config from file
with open(os.path.join(configfolder, configfile), "r") as f:
self.config = json.load(f)
@@ -274,6 +284,12 @@ class ConnectionWindow(QDialog):
self.ui.passwordInput.setText(self.dbpass)
self.ui.databaseInput.setText(self.dbname)
+ if (self.ui.ipInput or self.ui.portInput or self.ui.databaseInput) == "":
+ self.ui.saveButton.setEnabled(False)
+ self.ui.testButton.setEnabled(False)
+ else:
+ self.ui.saveButton.setEnabled(True)
+ self.ui.testButton.setEnabled(True)
# Unlock Buttons if ip, port and database is not empty
self.ui.ipInput.textChanged.connect(self.on_text_changed)