-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_interface.py
198 lines (168 loc) · 7.89 KB
/
gui_interface.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import os
from PyQt5 import QtWidgets, uic, QtCore, QtGui
from PyQt5.QtWidgets import QFileDialog
from src.code import concateneteLogs, mergeLogs, getHeaders, loadLogs, findExtension, resource_path
from gui_interface import *
class Ui(QtWidgets.QDialog):
"""
Main gui-Window class
"""
def __init__(self):
"""
init function for the gui window
"""
super(Ui, self).__init__()
gui_full_path = resource_path('gui_design.ui')
icon_full_path = resource_path('src\images\icon.png')
# uic.loadUi(r'src\gui_design.ui', self)
uic.loadUi(gui_full_path, self)
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
# self.setWindowIcon(QtGui.QIcon(r"images\icon.png"))
self.setWindowIcon(QtGui.QIcon(icon_full_path))
self.output_path = ""
self.listof_concatFiles = list()
self.listof_mergeFiles = list()
self.ConcatNow_button = self.findChild(QtWidgets.QPushButton, 'Concat_Now')
self.ConcatNow_button.setToolTip('Execute concatenation on selected files')
self.ConcatNow_button.clicked.connect(
lambda: self.concatNow())
self.Search_2_button = self.findChild(QtWidgets.QPushButton, 'Search_2')
self.Search_2_button.setToolTip('Select input files names')
self.Search_2_button.clicked.connect(
lambda: self.fileDialog())
self.merge_input_text = self.findChild(QtWidgets.QTextEdit, 'text_merge').setToolTip(
'Selected input files path')
self.Save_2_button = self.findChild(QtWidgets.QPushButton, 'Save_2')
self.Save_2_button.setToolTip('Select output file name')
self.Save_2_button.clicked.connect(
lambda: self.fileDialogSave())
self.merge_output_text = self.findChild(QtWidgets.QTextEdit, 'text_merge_2').setToolTip(
'Selected output file path')
self.MergeNow_button = self.findChild(QtWidgets.QPushButton, 'Merge_Now')
self.MergeNow_button.setToolTip('Execute merge on selected files')
self.MergeNow_button.clicked.connect(
lambda: self.mergeNow())
self.comboBox_leftKey.setToolTip('Key header from file 1')
self.comboBox_rightKey.setToolTip('Key header from file 2')
self.comboBox_mergeType.setToolTip('Select the type of merge to perform')
self.design.setToolTip('https://github.com/Chrism1c/Logs-Manager')
self.show()
def fileDialog(self):
"""
Procedure useful to select input files
:return: none
"""
try:
# Clear console labels
self.Console.setText("")
self.Console.setStyleSheet("background-color: none;")
filenames, x = QFileDialog.getOpenFileNames(self, "Select input files (2+ Concat | Only 2 Merge)", "",
"CSV (Delimitato dal separatore di elenco) (*.csv);;"
"Cartella di lavoro Excel (*.xlsx);;"
"Cartella di lavoro Excel 97-2003 (*.xls)")
self.listof_concatFiles = filenames
self.listof_mergeFiles = filenames
self.text_merge.setPlainText(" -- ".join(self.path_leaf(filenames)))
ext_in = findExtension(x)
frames = loadLogs(filenames, ext_in)
leftColumns, rightColumns = getHeaders(frames)
mergeTypes = ['left', 'right', 'outer', 'inner']
for elem in leftColumns:
self.comboBox_leftKey.addItem(elem)
for elem in rightColumns:
self.comboBox_rightKey.addItem(elem)
for elem in mergeTypes:
self.comboBox_mergeType.addItem(elem)
print(filenames)
except:
print("***** exception in fileDialog")
# Clear all data
self.text_merge.setPlainText("")
self.listof_concatFiles.clear
self.listof_mergeFiles.clear
def fileDialogSave(self):
"""
Procedure useful to select name and directory of the output file
:param value: boolean value to choose merge/concat operation
:return: none
"""
# Clear console labels
self.Console.setText("")
self.Console.setStyleSheet("background-color: none;")
try:
filename, x = QFileDialog.getSaveFileName(self, "Save file as:", "",
"CSV (Delimitato dal separatore di elenco) (*.csv);;"
"Cartella di lavoro Excel (*.xlsx);;"
"Cartella di lavoro Excel 97-2003 (*.xls)")
self.text_merge_2.setPlainText(os.path.basename(filename))
self.output_path = filename
print(filename)
except:
print("***** exception in fileDialogSave")
# Clear all data
self.text_merge_2.setPlainText("")
self.output_path = ""
def concatNow(self):
"""
Procedure useful to control inputs value before concat operation
:return:
"""
try:
if len(self.listof_concatFiles) > 1 and len(self.output_path) > 1:
ext_in = findExtension(self.listof_concatFiles[0])
ext_out = findExtension(self.output_path)
concateneteLogs(self.listof_concatFiles, self.output_path, ext_in, ext_out)
print('Concat succesful !')
self.Console.setText("Concat succesful !")
self.Console.setStyleSheet("background-color: lightgreen;")
else:
print('Concat failed !\n NB:\n- Select two ore more input files [OPEN] \n- Define one output file ['
'SAVE]')
self.Console.setText("Concat failed !")
self.Console.setStyleSheet("background-color: red;")
except:
print("***** exception in concatNow")
# Clear all data
self.listof_concatFiles.clear()
self.output_path = ""
self.text_merge.setPlainText("")
self.text_merge_2.setPlainText("")
self.comboBox_leftKey.clear()
self.comboBox_rightKey.clear()
self.comboBox_mergeType.clear()
def mergeNow(self):
"""
Procedure useful to control inputs value before merge operation
:return: none
"""
try:
# Keys control
lkey = self.comboBox_leftKey.currentText()
rkey = self.comboBox_rightKey.currentText()
how_merge = self.comboBox_mergeType.currentText()
if len(self.listof_mergeFiles) == 2 and len(self.output_path) > 0:
ext_in = findExtension(self.listof_mergeFiles[0])
ext_out = findExtension(self.output_path)
mergeLogs(how_merge, lkey, rkey, self.listof_mergeFiles, self.output_path, ext_in, ext_out)
print('Merge succesful !')
self.Console.setText("Merge succesful !")
self.Console.setStyleSheet("background-color: lightgreen;")
else:
print('Merge failed !\n NB:\n- Select only two input files [OPEN] \n- Define one output file [SAVE]')
self.Console.setText("Merge failed !")
self.Console.setStyleSheet("background-color: red;")
except:
print("***** exception in mergeNow")
# Clear all data
self.listof_mergeFiles.clear()
self.output_path = ""
self.text_merge.setPlainText("")
self.text_merge_2.setPlainText("")
self.comboBox_leftKey.clear()
self.comboBox_rightKey.clear()
self.comboBox_mergeType.clear()
def path_leaf(self, listofpath):
base = list()
for path in listofpath:
base.append(os.path.basename(path))
return base