-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanageterms-gui.py
executable file
·75 lines (64 loc) · 2.49 KB
/
manageterms-gui.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
74
75
#!/usr/bin/env python3
import os
import signal
import sys
import glob
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication, QErrorMessage, QShortcut
from PyQt5.QtGui import QKeySequence
from SyntaxAutoFix.utils import open_typo_file, save_typo_data
from ui_manageterms import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
# Load the ui
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Connect the function with the signal
self.ui.save.clicked.connect(self.store_new_argument)
self.ui.save.clicked.connect(self.save_and_clear)
self.ui.save_close.clicked.connect(self.save_close)
# When the software are closed on console the software are closed
signal.signal(signal.SIGINT, signal.SIG_DFL)
self.script_path = os.path.dirname(os.path.realpath(__file__)) + '/../words/'
for filepath in sorted(glob.glob(os.path.join(self.script_path, '*.json'))):
language = os.path.splitext(os.path.basename(filepath))[0]
self.ui.languages.addItem(language)
enter = QShortcut(QKeySequence(QtCore.Qt.Key_Return), self)
enter.activated.connect(self.save_close)
self.show()
def store_new_argument(self):
wrong = self.ui.wrong.text()
right = self.ui.right.text()
lang = self.ui.languages.currentText()
# Check argument is not circular
if right == wrong:
msg = QErrorMessage(self)
msg.setWindowModality(QtCore.Qt.WindowModal)
msg.showMessage('You can’t replace a word with itself. It will create a loop.')
return
lang_path = self.script_path + lang + '.json'
typo_data = open_typo_file(lang_path)
if right in typo_data:
if wrong not in typo_data[right]:
typo_data[right].append(wrong)
else:
typo_data[right] = [wrong]
save_typo_data(lang_path, typo_data)
def save_close(self):
self.store_new_argument()
self.close()
# Clear the text fields on save issue #39
def save_and_clear(self):
self.ui.wrong.clear()
self.ui.right.clear()
def main():
# Start the software
app = QApplication(sys.argv)
MainWindow_ = QMainWindow()
ui = MainWindow()
ui.setupUi(MainWindow_)
# Add the close feature at the program with the X
sys.exit(app.exec_())
# Execute the software
main()