-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-gui.py
115 lines (88 loc) · 3.72 KB
/
python-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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
from os import listdir, remove
from os.path import isfile, join
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
self.bind_views()
self.reloadFiles()
self.setWindowTitle('Api-proxy GUI')
self.show()
def bind_views(self):
self.override_checkbox.stateChanged.connect(self.override_checked)
self.qlist.itemSelectionChanged.connect(self.item_click)
self.reload_text_button.clicked.connect(self.item_click)
self.reload_button.clicked.connect(self.reloadFiles)
self.save_button.clicked.connect(self.save_text_to_file)
def reloadFiles(self):
self.qlist.clear()
files = [f for f in list(set(listdir("output")+listdir("override"))) if isfile(join("output",f)) or isfile(join("override",f))] #combined both folders and list all uniqe
for f in files:
self.qlist.addItem(f)
def override_checked(self):
if len(self.qlist.selectedItems()) == 1:
item = self.qlist.selectedItems()[0]
path = "override/" + item.text()
if self.override_checkbox.isChecked():
text_file = open(path, "w")
text_file.write(self.textbox.toPlainText())
text_file.close()
elif isfile(path):
remove(path)
self.save_button.setEnabled(self.override_checkbox.isChecked())
def save_text_to_file():
item = self.qlist.selectedItems()[0]
path = "override/" + item.text()
text_file = open(path, "w")
text_file.write(self.textbox.toPlainText())
text_file.close()
def item_click(self):
if len(self.qlist.selectedItems()) == 1:
item = self.qlist.selectedItems()[0]
path = "override/" + item.text()
if not isfile(path):
path = "output/" + item.text()
with open(path, 'rb') as f:
content = f.read()
self.textbox.setText(content)
self.override_checkbox.setChecked(isfile("override/" + item.text()))
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.qlist = QtGui.QListWidget()
self.qlist.setWindowTitle('Example List')
self.qlist.setMinimumSize(100, 600)
self.qlist.setFixedWidth(200)
self.qlist.setSortingEnabled(True);
self.reload_button = QtGui.QPushButton('Reload')
self.reload_button.setFixedWidth(200)
self.textbox = QtGui.QTextEdit()
self.textbox.setMinimumSize(800, 600)
self.override_checkbox = QtGui.QCheckBox("Override Response")
self.save_button = QtGui.QPushButton('Save')
self.save_button.setFixedWidth(200)
self.reload_text_button = QtGui.QPushButton('Reload Text')
self.reload_text_button.setFixedWidth(200)
listVbox = QtGui.QVBoxLayout()
listVbox.addWidget(self.qlist)
listVbox.addWidget(self.reload_button)
actionshbox = QtGui.QHBoxLayout()
actionshbox.addWidget(self.override_checkbox)
actionshbox.addWidget(self.reload_text_button)
actionshbox.addWidget(self.save_button)
textboxVbox = QtGui.QVBoxLayout()
textboxVbox.addWidget(self.textbox)
textboxVbox.addLayout(actionshbox)
hbox = QtGui.QHBoxLayout()
hbox.addLayout(listVbox)
hbox.addLayout(textboxVbox)
self.setLayout(hbox)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()