-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
hacktribe_app_gui.py
107 lines (75 loc) · 3.31 KB
/
hacktribe_app_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
from hacktribe_gui_autogen import *
from hacktribe_app_backend import *
from hacktribe_app_log import *
import sys
from pathlib import Path
import logging
def main():
# Initialise logging
HacktribeAppLog()
# Run App GUI
a = HacktribeAppGUI()
class HacktribeAppGUI:
def __init__(self):
logging.debug('Initialising App')
# Initialise backend
self.be = HacktribeAppBackend()
# Initialise GUI
self.init_gui()
def init_gui(self):
logging.debug('Initialising GUI')
self.app = QtWidgets.QApplication(sys.argv)
self.MainWindow = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.MainWindow)
self.ui.edit_src_path.setText(str(self.be.fw_patcher.src_path))
self.ui.edit_patch_path.setText(str(self.be.fw_patcher.patch_path))
self.ui.edit_dest_path.setText(str(self.be.fw_patcher.dest_path))
self.ui.browse_src_path.clicked.connect(self.select_src_path)
self.ui.edit_src_path.textChanged.connect(self.edit_src_path)
self.ui.browse_patch_path.clicked.connect(self.select_patch_path)
self.ui.edit_patch_path.textChanged.connect(self.edit_patch_path)
self.ui.browse_dest_path.clicked.connect(self.select_dest_path)
self.ui.edit_dest_path.textChanged.connect(self.edit_dest_path)
self.ui.check_edit_header.clicked.connect(self.select_edit_header)
self.ui.check_prefix_filename.clicked.connect(self.select_prefix_filename)
self.ui.patch_firmware.clicked.connect(self.click_patch_firmware)
# Initialise GUI log display
self.gui_log = QTextEditLogger(self.ui)
logging.getLogger().addHandler(self.gui_log)
self.gui_log.setLevel(logging.INFO)
self.MainWindow.show()
self.be.welcome_msg()
sys.exit(self.app.exec())
def select_src_path(self):
path = QtWidgets.QFileDialog.getOpenFileName()[0]
self.ui.edit_src_path.setText(path)
def edit_src_path(self):
self.be.fw_patcher.src_path = Path(self.ui.edit_src_path.text())
def select_patch_path(self):
path = QtWidgets.QFileDialog.getOpenFileName()[0]
self.ui.edit_patch_path.setText(path)
def edit_patch_path(self):
self.be.fw_patcher.patch_path = Path(self.ui.edit_patch_path.text())
def select_dest_path(self):
path = QtWidgets.QFileDialog.getExistingDirectory()
self.ui.edit_dest_path.setText(path)
def edit_dest_path(self):
self.be.fw_patcher.dest_path = Path(self.ui.edit_dest_path.text())
def select_edit_header(self):
self.be.fw_patcher.edit_header = self.ui.check_edit_header.isChecked()
def select_prefix_filename(self):
self.be.fw_patcher.prefix_filename = self.ui.check_prefix_filename.isChecked()
def click_patch_firmware(self):
self.be.fw_patcher.apply_patch()
# Logging handler for GUI log_text
class QTextEditLogger(logging.Handler):
def __init__(self, parent):
super().__init__()
self.widget = parent.log_text
self.widget.setReadOnly(True)
def emit(self, record):
msg = self.format(record)
self.widget.append(msg)
if __name__ == "__main__":
main()