-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGUI.py
More file actions
267 lines (218 loc) · 9.8 KB
/
GUI.py
File metadata and controls
267 lines (218 loc) · 9.8 KB
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
from appJar import gui
from UniteArticles import Merger
from SemanticScholarMetaCrawler import Crawler
from PDFDownloader import PDFDownloader
import os
import sys
def restart_program():
"""Restarts the current program."""
python = sys.executable
os.execl(python, python, * sys.argv)
class GUI:
def __init__(self, root_directory):
self.root_directory = root_directory
self.app = gui('Semantic Scholar Crawler', '800x400')
self.app.setGuiPadding(20, 20)
self.app.setLocation('CENTER')
self.app.setFont(16)
self.search_phrase = ''
self.input_pages = 0
self.crawler = Crawler(self.root_directory)
self.folders_text = ''
self.folders_list = []
self.single_or_merge = False
self.merger = None
self.crawler.gui = self
def menus_pressed(self, menu):
if menu == 'New Search':
restart_program()
if menu == "Close":
self.app.stop()
if menu == "Help":
self.app.startSubWindow('Help', 'Help', True, )
self.app.showSubWindow('Help')
self.help_screen()
self.app.stopSubWindow()
if menu == "About":
self.app.startSubWindow('About', 'About this program', True, )
self.app.showSubWindow('About')
self.about_screen()
self.app.stopSubWindow()
def menus(self):
file_menus = ["New Search", "-", "Close"]
about_menus = ["Help", "About"]
self.app.addMenuList("File", file_menus, self.menus_pressed)
self.app.addMenuList("About", about_menus, self.menus_pressed)
def main_search(self):
self.app.setStretch('column')
self.app.setSticky('we')
self.app.addLabel('Label_Search', 'Enter your search phrase:', row=0)
self.app.addEntry('Entry_Search', row=1)
self.app.addLabel('label_space', '', row=2)
self.app.addLabel('Label_Pages_Quantity', 'Select how many articles you would like to search:', row=3)
self.app.addScale('Quantity_scale', row=4)
self.app.setScaleRange('Quantity_scale', 0, 100, 100)
self.app.showScaleIntervals('Quantity_scale', 5)
self.app.showScaleValue('Quantity_scale', True)
self.app.setStretch('both')
self.app.setSticky('se')
self.app.addNamedButton('Next', 'Next1', self.press)
def show_search_done_alert(self, time, quantity):
self.app.stopAnimation('loading')
self.app.hideImage('loading')
self.app.infoBox('DONE', 'Search Completed in ' + str(time.seconds) + ' second(s) with ' +
quantity + ' articles successfully gathered.')
self.app.setButtonState('Next2', 'normal')
def show_download_done_alert(self, time, quantity):
self.app.infoBox('DONE', 'Downloads Completed in ' + str(time.seconds) + ' second(s) with ' +
quantity + ' articles successfully downloaded.')
self.app.setButtonState('Next3', 'normal')
def show_saved_alert(self, saved_path):
answer = self.app.yesNoBox('SAVED', 'Your search is saved at this location ' + saved_path +
'.\nWould you like to end the program?')
if answer:
self.app.stop()
def progress_bar(self):
self.app.setStretch('column')
self.app.setSticky('nwe')
self.app.addLabel('progress_bar_label', 'Press "Start Search!"')
self.app.setStretch('both')
self.app.setSticky('nswe')
self.app.setSticky('')
self.app.addButton('Start Search!', self.press, column=0, row=2)
self.app.setStretch('both')
self.app.addImage("loading", "Images/book.gif")
self.app.setAnimationSpeed("loading", 100)
self.app.stopAnimation("loading")
self.app.hideImage('loading')
self.app.setSticky('se')
self.app.addNamedButton('Next', 'Next2', self.press)
self.app.setButtonState('Next2', 'disabled')
def progress_bar2(self):
self.app.setStretch('column')
self.app.setSticky('nwe')
self.app.addLabel('progress_bar_2_label', 'Press "Start Downloads!"')
self.app.setStretch('both')
self.app.setSticky('nswe')
self.app.addMeter('progress_bar2', column=0, row=1)
self.app.setMeterFill('progress_bar2', 'blue')
self.app.setSticky('')
self.app.addButton('Start Downloads!', self.press, column=0, row=2)
self.app.setStretch('both')
self.app.setSticky('se')
self.app.addNamedButton('Skip', 'Skip_download', self.press, row=3)
self.app.addNamedButton('Next', 'Next3', self.press, row=4)
self.app.setButtonState('Next3', 'disabled')
def save_menu(self):
self.app.setStretch('column')
self.app.setSticky('we')
self.app.addLabel('Label_Save_options', 'How would you like your search to be ordered?')
self.app.setSticky('w')
self.app.addRadioButton('Save_option_radioButton', "Importance Rate (RECOMMENDED)")
self.app.addRadioButton('Save_option_radioButton', "Number of Citations")
self.app.addRadioButton('Save_option_radioButton', "Newer Articles")
self.app.addRadioButton('Save_option_radioButton', "Alphabetically, by Article's Title")
self.app.setSticky('')
self.app.addButton('Save!', self.press)
def option_page(self):
self.app.setStretch('column')
self.app.addLabel('Label_Option_page', 'What would you like to do?')
self.app.addLabel('spacing_label1', '')
self.app.addLabel('spacing_label2', '')
self.app.setSticky('nsew')
self.app.addButton('New Search', self.press)
self.app.addLabel('spacing_label3', '')
self.app.addButton('Merge Old Searches', self.press)
def external_folders(self, list_folder):
folders = list_folder.split("} {")
for text_folder in folders:
folder = text_folder.strip("{}")
self.app.addListItem("folders_list", folder)
self.folders_list.append(folder)
def merge_searches(self):
self.app.setStretch('both')
self.app.setSticky('n')
self.app.addLabel('Label_merge_searches',
'Drag and drop directories you would like to merge.', colspan=2)
self.app.addListBox("folders_list", colspan=2)
self.app.setListBoxDropTarget("folders_list", self.external_folders)
self.app.setListBoxWidth("folders_list", 50)
self.app.setStretch('both')
self.app.setSticky('nsew')
self.app.setStretch('')
self.app.setSticky('s')
self.app.addButton('Merge Searches', self.press, row=3)
def main_page(self):
self.menus()
self.app.startFrameStack("Pages")
self.app.startFrame('Initial Option')
self.option_page()
self.app.stopFrame()
self.app.startFrame('Search Menu')
self.main_search()
self.app.stopFrame()
self.app.startFrame('Progress')
self.progress_bar()
self.app.stopFrame()
#self.app.startFrame('Downloading Progress')
#self.progress_bar2()
#self.app.stopFrame()
self.app.startFrame('Saving Options')
self.save_menu()
self.app.stopFrame()
self.app.startFrame('Merge Searches')
self.merge_searches()
self.app.stopFrame()
self.app.stopFrameStack()
self.app.firstFrame('Pages')
self.app.go()
def about_screen(self):
self.app.addImage('Alphas', os.path.join(self.root_directory, 'Images', 'About.gif'))
self.app.setSticky('n')
self.app.addButton('Close', self.press)
def help_screen(self):
self.app.addWebLink('GitHub link for help!', 'https://github.com/EvertonCa/SeleniumSemanticScraper')
self.app.addButton('Close!', self.press)
def create_crawler(self):
self.crawler.update_search_parameters(self.search_phrase, self.input_pages)
self.crawler.start_search()
def start_downloads(self):
downloader = PDFDownloader(self.search_phrase, self.root_directory, self)
downloader.start()
def press(self, btn):
if btn == "Next1" or btn == "Next2":
self.search_phrase = self.app.getEntry('Entry_Search')
self.input_pages = self.app.getScale('Quantity_scale')
if self.input_pages == 0:
self.app.errorBox('Error!', 'Selecting 0 articles will end up with a empty search!')
else:
self.app.nextFrame("Pages")
elif btn == 'Next3':
self.app.nextFrame("Pages")
elif btn == 'Skip_download':
self.app.nextFrame("Pages")
elif btn == "Start Search!":
self.app.setLabel('progress_bar_label', 'Getting Ready...')
self.app.setButtonState('Start Search!', 'disabled')
self.app.showImage('loading')
self.app.startAnimation('loading')
self.app.thread(self.create_crawler)
elif btn == "Start Downloads!":
self.app.setLabel('progress_bar_2_label', 'Getting Ready...')
self.app.setButtonState('Start Downloads!', 'disabled')
self.app.setButtonState('Skip_download', 'disabled')
self.app.thread(self.start_downloads)
elif btn == 'Save!':
self.crawler.saves_excel(self.app.getRadioButton('Save_option_radioButton'))
elif btn == 'New Search':
self.app.selectFrame('Pages', 1)
elif btn == 'Merge Old Searches':
self.app.selectFrame('Pages', 4)
elif btn == 'Merge Searches':
self.single_or_merge = True
self.merger = Merger(self.folders_list)
self.app.selectFrame('Pages', 3)
elif btn == 'Close':
self.app.destroySubWindow('About')
elif btn == 'Close!':
self.app.destroySubWindow('Help')