-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
64 lines (50 loc) · 2.02 KB
/
UI.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
from Finder import find_key
from StringToDIct import string_to_dict
__author__ = 'varg'
import sys
from PyQt4 import QtCore, QtGui, uic
form_class = uic.loadUiType("finder.ui")[0]
class FinderWindowClass(QtGui.QMainWindow, form_class):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.action_Open.setShortcut('Ctrl+O')
self.action_Open.triggered.connect(self.open_action)
self.resultLineEdit.mousePressEvent = lambda _ : self.resultLineEdit.selectAll()
self.pushButton.clicked.connect(self.pushButton_clicked)
self.finder.returnPressed.connect(self.pushButton_clicked)
self.finder.textChanged.connect(self.pushButton_clicked)
self.textEdit.selectionChanged.connect(self.get_selected)
def open_action(self):
fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
if fname:
with open(fname, 'r') as f:
data = f.read()
self.textEdit.setText(data)
def get_selected(self):
cursor = self.textEdit.textCursor()
selected = cursor.selectedText()
self.finder.setText(selected)
def pushButton_clicked(self):
text = str(self.textEdit.toPlainText())
text = text.replace('true', 'True')
text = text.replace('false', 'False')
text = text.replace('null', 'None')
data_structure = string_to_dict(text)
if not data_structure:
self.resultLineEdit.setText('Incorrect data structure')
return
key = str(self.finder.text())
if not key:
self.resultLineEdit.setText('Incorrect key structure')
return
key_path = find_key(data_structure, key)
if not key_path:
self.resultLineEdit.setText('Key not found')
return
self.resultLineEdit.setText(key_path)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myWindow = FinderWindowClass(None)
myWindow.show()
app.exec_()