-
Notifications
You must be signed in to change notification settings - Fork 0
/
pydic.py
executable file
·73 lines (65 loc) · 2.32 KB
/
pydic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor
from PyQt5 import uic
from pathlib import Path
import logo_rc
import csv
class GUI(QMainWindow):
def __init__(self):
super(GUI, self).__init__()
uic.loadUi("pydic.ui", self)
self.show()
self.Search.clicked.connect(self.search)
def search(self):
if self.stex.text().isalpha():
b = self.stex.text() + " "
root_folder = Path(__file__).parents[1]
s = "pydic/Dict/" + b[0].upper() + ".csv" # To conserve memory
S = root_folder / s
A = open(S, "r")
R = csv.reader(A, delimiter=",")
global tex
tex = ""
for row in R:
if row == []:
continue
elif b in row[0][0 : len(b)]:
tex += row[0]
tex += "\n"
self.output.setText(tex)
else:
message = QMessageBox()
message.setText("Invalid input, Please enter valid words")
message.exec_()
tex = "error"
if tex == "":
message = QMessageBox()
message.setText("Word is not available on the dictionary")
message.exec_()
A.close()
# Main function calls the Application
def main():
app = QApplication([])
window = GUI()
# Force the style to be the same on all OSs:
app.setStyle("Fusion")
# Now a palette to switch to dark colors:
palette = QPalette()
palette.setColor(QPalette.Window, QColor(53, 53, 53))
palette.setColor(QPalette.WindowText, Qt.white)
palette.setColor(QPalette.Base, QColor(25, 25, 25))
palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
palette.setColor(QPalette.ToolTipBase, Qt.black)
palette.setColor(QPalette.ToolTipText, Qt.white)
palette.setColor(QPalette.Text, Qt.white)
palette.setColor(QPalette.Button, QColor(53, 53, 53))
palette.setColor(QPalette.ButtonText, Qt.white)
palette.setColor(QPalette.BrightText, Qt.red)
palette.setColor(QPalette.Link, QColor(42, 130, 218))
palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
palette.setColor(QPalette.HighlightedText, Qt.black)
app.setPalette(palette)
app.exec_()
if __name__ == "__main__":
main()