-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNEWGUI4
269 lines (213 loc) · 8.77 KB
/
NEWGUI4
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
from PyQt6.QtWidgets import QListWidget,QApplication,QMainWindow,QPushButton,QFileDialog,QTextEdit,QPlainTextEdit,QComboBox,QVBoxLayout,QLabel
from PyQt6.QtGui import QIcon
from PyQt6 import QtCore
from PyQt6 import uic
from PyQt6 import QtGui
import sys
from Functions import *
from bs4 import BeautifulSoup
class Ui(QMainWindow):
global count2
count2 =0
def __init__(self):
super(Ui, self).__init__()
self.myset = set()
self.count1 = 0
self.count3 = 0
uic.loadUi('NewGUI2.ui', self)
combos = ['combo1']
lists = ['list1', 'list2', 'list3','list4']
buttons = ['button1', 'button2', 'button4','button5','button6','button7','button8']
for items in combos: self.items = self.findChild(QLabel, items)
for items in combos: self.items = self.findChild(QComboBox, items)
for items in lists: self.items = self.findChild(QListWidget, items)
for items in buttons: self.items = self.findChild(QPushButton, items)
for items in buttons: self.items = self.findChild(QPushButton, items)
self.textedit = self.findChild(QTextEdit,'textedit')
self.label5 = self.findChild(QLabel,'label_5')
self.textedit2 = self.findChild(QTextEdit,'textedit2')
self.button1.clicked.connect(self.button1click)
self.button2.clicked.connect(self.button2click)
self.button4.clicked.connect(self.button4click)
self.button5.clicked.connect(self.button5click)
self.button6.clicked.connect(self.button6click)
self.button7.clicked.connect(self.button7click)
self.button8.clicked.connect(self.button8click)
self.combo1.currentTextChanged.connect(self.combo1changed)
self.list1.clicked.connect(self.list1clicked)
self.list2.clicked.connect(self.list2clicked)
self.list4.clicked.connect(self.list4clicked)
self.button1.setEnabled(False)
self.button2.setEnabled(False)
self.button4.setEnabled(False)
self.button5.setEnabled(False)
self.button6.setEnabled(False)
self.button7.setEnabled(False)
self.combo1.setEnabled(False)
self.mode = self.combo1.currentText()
self.show()
def button1click(self):
list1selection = (self.list1.currentItem().text())
self.myset.add(('U1:' + list1selection).lower())
self.list4.clear()
for items in self.myset: self.list4.addItem(items)
self.button1.setEnabled(False)
self.button2.setEnabled(False)
self.Commonupdate()
def button2click(self):
list1selection = (self.list1.currentItem().text())
self.myset.add(('D1:' + list1selection).lower())
self.list4.clear()
for items in self.myset: self.list4.addItem(items)
self.button1.setEnabled(False)
self.button2.setEnabled(False)
self.Commonupdate()
def button4click(self):
path2 = '/users/williamcorney/downloads/master/'
if self.count1 > 1:
self.count1 -= 1
self.fname = path2 + self.csvfilelist[self.count1]
self.label5.setText(self.fname)
self.soup = SoupFILEimport(self.fname)
self.Commonupdate()
def button5click(self):
path2 = '/users/williamcorney/downloads/master/'
self.count1 += 1
self.fname = path2 + self.csvfilelist[self.count1]
self.label5.setText(self.fname)
self.soup = SoupFILEimport(self.fname)
self.Commonupdate()
def button6click(self):
list4selection = (self.list4.currentItem().text())
self.myset.discard(list4selection)
self.list4.clear()
for items in self.myset: self.list4.addItem(items)
self.soup = SoupFILEimport(self.fname)
if len(self.myset) < 1:
self.button6.setEnabled(False)
self.button7.setEnabled(False)
self.Commonupdate()
def button7click(self):
self.list4.clear()
self.myset.clear()
self.soup = SoupFILEimport(self.fname)
self.button6.setEnabled(False)
self.button7.setEnabled(False)
self.Commonupdate()
def button8click(self):
self.textedit.clear()
self.combo1.setEnabled(True)
self.list1.clear()
self.list2.clear()
self.list3.clear()
self.list4.clear()
self.myset.clear()
self.home_dir = str('/Users/williamcorney/PycharmProjects/pythonProject')
self.fname = QFileDialog.getOpenFileName(self, 'Open file', self.home_dir)
try:
filetype = (str((os.path.basename(self.fname[0]))).split('.')[1])
except:
return
if filetype == 'html':
self.button4.setEnabled(False)
self.button5.setEnabled(False)
self.fname = self.fname[0]
self.soup = SoupFILEimport(self.fname)
self.Commonupdate()
if filetype == 'csv':
with open(str(self.fname[0]), mode='r') as infile:
reader = csv.reader(infile)
csvdict = {rows[0]: rows[1] for rows in reader}
self.csvfilelist = []
for filename, volno in csvdict.items():
self.csvfilelist.append(filename)
self.button4.setEnabled(True)
self.button5.setEnabled(True)
self.button4click()
return
def combo1changed(self):
self.mode = self.combo1.currentText()
self.soup = Soupify(self.soup)
self.Commonupdate()
def Commonupdate(self):
for instruction in self.myset:
A = instruction.split(':')[0]
B = instruction.split(':')[1]
if len(instruction.split(':')) > 2: C = instruction.split(':')[2]
if len(instruction.split(':')) > 3: D = instruction.split(':')[3]
if len(instruction.split(':')) > 4: E = instruction.split(':')[4]
# Decompose/Unwrap by tag
if A == 'd1':
for items in self.soup.find_all(B): items.decompose()
if A == 'u1':
for items in self.soup.find_all(B): items.unwrap()
if A == 'f1':
for items in self.soup.find_all(B, {C: D}): print(items)
if A == 'f2':
result = self.soup.find_all(B, C)
for items in result: print(items)
if A == 'r1':
for items in self.soup.find_all(B):
new_tag = self.soup.new_tag(C)
new_tag.string = items.getText()
items.replace_with(new_tag)
if A == 'r2':
for items in self.soup.find_all(B, {C: D}):
new_tag = self.soup.new_tag(E)
new_tag.string = items.getText()
items.replace_with(new_tag)
self.list1.clear()
self.textedit.clear()
self.tags = (SoupALLtags(self.soup))
for items in self.tags: self.list1.addItem(items)
if self.mode == 'HTML':
for items in self.soup:
self.textedit.append(str(items))
# self.textedit.setText(str(self.soup))
if self.mode == 'RAW':
for items in self.soup:
self.textedit.insertPlainText(str(items))
def list1clicked(self):
self.button1.setEnabled(True)
self.button2.setEnabled(True)
# list1selection = (self.list1.currentItem().text())
item = self.list1.currentItem().text()
self.soup = Soupify(self.soup)
filter = SoupSPECIFICtag(self.soup, item)
# attributes = []
# self.list2.clear()
# for element in filter:
# for item in element.attrs:
# if item not in attributes:
# attributes.append(item)
# attributes.reverse()
# for atts in attributes:
# self.list2.addItem(atts)
self.textedit.clear()
if self.mode == 'HTML':
for x in filter: self.textedit.insertHtml(str(x))
if self.mode == 'RAW':
for x in filter: self.textedit.insertPlainText(str(x))
def list2clicked(self):
pass
# for tags in self.soup.find_all(self.list1.currentItem().text()):
# # print(str(tags) + 'should be here ')
# valueslist = []
#
# if tags.has_attr(self.list2.currentItem().text()):
#
# items = (tags.attrs[self.list2.currentItem().text()])
# self.list3.clear()
#
# if items not in valueslist:
# valueslist.append(str(items))
#
# for items in valueslist:
# self.list3.addItem(items)
def list4clicked(self):
if len(self.myset) > 0:
self.button6.setEnabled(True)
self.button7.setEnabled(True)
app = QApplication(sys.argv)
window = Ui()
app.exec()