-
Notifications
You must be signed in to change notification settings - Fork 5
/
PyDoc.py
416 lines (363 loc) · 22.3 KB
/
PyDoc.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
from Managers import DocsetManager, ServerManager, CheatsheetManager , UserContributedManager, DBManager, ThemeManager, StackOverflowManager, WebSearchManager, TransferManager, MigrationManager, SettingsManager
from Views import DocsetManagementView, SettingsView, DocsetListView, DocsetView, DocsetIndexView, DocsetWebView, CheatsheetManagementView, UserContributedManagementView, StackOverflowManagementView, TransferManagementView, DocsetManagementVersionView, UserContributedManagementVersionView
from Utilities import UISearchControllerWrapper
import ui
import console
import os
import time
class PyDoc(object):
def __init__(self):
console.show_activity('Loading...')
self.docsetFolder = 'Docsets'
self.setup()
self.dbmanager = DBManager.DBManager()
self.migration_manager = MigrationManager.MigrationManager(self.dbmanager, self.docsetFolder)
self.perform_migrations()
self.theme_manager = ThemeManager.ThemeManager('Themes')
self.docset_manager = DocsetManager.DocsetManager('Images/icons', 'Images/types', ServerManager.ServerManager())
self.cheatsheet_manager = CheatsheetManager.CheatsheetManager(ServerManager.ServerManager(), 'Images/icons', 'Images/types')
self.usercontributed_manager = UserContributedManager.UserContributedManager(ServerManager.ServerManager(), 'Images/icons','Images/types')
self.stackoverflow_manager = StackOverflowManager.StackOverflowManager(ServerManager.ServerManager(), 'Images/icons','Images/types')
self.webSearchManager = WebSearchManager.WebSearchManager('Images/types')
self.transfer_manager = TransferManager.TransferManager('Images/icons','Images/types')
self.settings_manager = SettingsManager.SettingsManager()
self.main_view = self.setup_main_view()
self.navigation_view = self.setup_navigation_view()
self.docset_management_version_view = self.setup_docset_management_version_view()
self.docset_management_view = self.setup_docset_management_view()
self.cheatsheet_management_view = self.setup_cheatsheetmanagement_view()
self.usercontributed_management_version_view = self.setup_usercontributed_management_version_view()
self.usercontributed_management_view = self.setup_usercontributedmanagement_view()
self.stackoverflow_management_view = self.setup_stackoverflowmanagement_view()
self.transfer_management_view = self.setup_transfermanagement_view()
self.settings_view = self.setup_settings_view()
self.docsetView = self.setup_docset_view()
self.docsetIndexView = self.setup_docsetindex_view()
self.docsetWebView = self.setup_docsetweb_view()
UISearchControllerWrapper.Theme_manager = self.theme_manager
console.hide_activity()
def perform_migrations(self):
console.show_activity('Performing Migrations')
self.migration_manager.perform_migrations()
console.hide_activity()
def setup(self):
if not os.path.exists(self.docsetFolder):
os.mkdir(self.docsetFolder)
def setup_navigation_view(self):
nav_view = ui.NavigationView(self.main_view)
nav_view.border_color = self.theme_manager.currentTheme.borderColour
nav_view.background_color = self.theme_manager.currentTheme.backgroundColour
nav_view.bar_tint_color = self.theme_manager.currentTheme.toolbarBackgroundColour
nav_view.bg_color = self.theme_manager.currentTheme.backgroundColour
nav_view.tint_color = self.theme_manager.currentTheme.tintColour
nav_view.title_color = self.theme_manager.currentTheme.textColour
return nav_view
def setup_main_view(self):
docsets = self.docset_manager.getDownloadedDocsets()
cheatsheets = self.cheatsheet_manager.getDownloadedCheatsheets()
usercontributed = self.usercontributed_manager.getDownloadedUserContributed()
stackoverflows = self.stackoverflow_manager.getDownloadedStackOverflows()
transfers = self.transfer_manager.getInstalledDocsets()
main_view = UISearchControllerWrapper.get_view(DocsetListView.get_view(docsets, cheatsheets, usercontributed, stackoverflows, transfers, self.docset_selected_for_viewing, self.cheatsheet_selected_for_viewing, self.usercontributed_selected_for_viewing, self.stackoverflow_selected_for_viewing, self.transfer_selected_for_viewing, self.theme_manager), self.search_all_docsets, self.docset_index_selected_for_viewing, self.theme_manager, self.build_offline_index_stackoverflow_selected_for_viewing)
settings_button = ui.ButtonItem(title='Settings')
settings_button.action = self.show_settings_view
main_view.left_button_items = [settings_button]
return main_view
def setup_docset_management_view(self):
docsets = self.docset_manager.getAvailableDocsets()
docset_management_view = DocsetManagementView.get_view(docsets, self.docset_manager.downloadDocset, self.docset_manager.getAvailableDocsets, self.docset_manager.deleteDocset, self.refresh_main_view_data, self.theme_manager, self.show_docset_versions_view)
docset_management_view.right_button_items = [ui.ButtonItem(action=self.checkStandardDocsetsForUpdate, title='Check for Update')]
docset_management_view.background_color = self.theme_manager.currentTheme.backgroundColour
docset_management_view.bar_tint_color = self.theme_manager.currentTheme.tintColour
docset_management_view.bg_color = self.theme_manager.currentTheme.backgroundColour
docset_management_view.tint_color = self.theme_manager.currentTheme.tintColour
docset_management_view.title_color = self.theme_manager.currentTheme.textColour
return docset_management_view
def setup_docset_management_version_view(self):
docset_management_view = DocsetManagementVersionView.get_view([], self.docset_manager.downloadDocset, self.docset_manager.getOnlineVersions, self.docset_manager.deleteDocset, self.refresh_main_view_data, self.theme_manager, None)
docset_management_view.background_color = self.theme_manager.currentTheme.backgroundColour
docset_management_view.bar_tint_color = self.theme_manager.currentTheme.tintColour
docset_management_view.bg_color = self.theme_manager.currentTheme.backgroundColour
docset_management_view.tint_color = self.theme_manager.currentTheme.tintColour
docset_management_view.title_color = self.theme_manager.currentTheme.textColour
return docset_management_view
def setup_usercontributed_management_version_view(self):
view = UserContributedManagementVersionView.get_view([], self.usercontributed_manager.downloadUserContributed, self.usercontributed_manager.getOnlineVersions, self.usercontributed_manager.deleteUserContributed, self.refresh_main_view_data, self.theme_manager, None)
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def refresh_main_view_data(self):
docsets = self.docset_manager.getDownloadedDocsets()
cheatsheets = self.cheatsheet_manager.getDownloadedCheatsheets()
usercontributed = self.usercontributed_manager.getDownloadedUserContributed()
stackoverflows = self.stackoverflow_manager.getDownloadedStackOverflows()
transfers = self.transfer_manager.getInstalledDocsets()
DocsetListView.refresh_view(docsets, cheatsheets, usercontributed, stackoverflows, transfers)
def setup_cheatsheetmanagement_view(self):
view = CheatsheetManagementView.get_view(self.cheatsheet_manager.downloadCheatsheet, self.refresh_main_view_data, self.cheatsheet_manager.deleteCheatsheet, self.cheatsheet_manager.getAvailableCheatsheets, self.theme_manager)
view.right_button_items = [ui.ButtonItem(action=self.checkCheatsheetsForUpdate, title='Check for Update')]
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def show_docset_versions_view(self, docset):
versions = self.docset_manager.getOnlineVersions(docset)
self.docset_management_version_view.data_source.data = versions
self.docset_management_version_view.reload_data()
self.navigation_view.push_view(self.docset_management_version_view)
def show_usercontributed_versions_view(self, docset):
versions = self.usercontributed_manager.getOnlineVersions(docset)
self.usercontributed_management_version_view.data_source.data = versions
self.usercontributed_management_version_view.reload_data()
self.navigation_view.push_view(self.usercontributed_management_version_view)
def show_docset_management_view(self):
self.navigation_view.push_view(self.docset_management_view)
def show_cheatsheetmanagement_view(self):
self.cheatsheet_management_view.data_source.data = self.cheatsheet_manager.getAvailableCheatsheets()
self.cheatsheet_management_view.reload()
self.navigation_view.push_view(self.cheatsheet_management_view)
console.hide_activity()
def setup_usercontributedmanagement_view(self):
view = UserContributedManagementView.get_view(self.usercontributed_manager.downloadUserContributed, self.refresh_main_view_data, self.usercontributed_manager.deleteUserContributed, self.usercontributed_manager.getAvailableUserContributed, self.theme_manager, self.show_usercontributed_versions_view)
view.right_button_items = [ui.ButtonItem(action=self.checkUserContributedForUpdate, title='Check for Update')]
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def setup_stackoverflowmanagement_view(self):
view = StackOverflowManagementView.get_view(self.stackoverflow_manager.downloadStackOverflow, self.refresh_main_view_data, self.stackoverflow_manager.deleteStackOverflow, self.stackoverflow_manager.getAvailableStackOverflows, self.theme_manager)
view.right_button_items = [ui.ButtonItem(action=self.checkStackOverflowForUpdate, title='Check for Update')]
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def show_stackoverflowmanagement_view(self):
self.stackoverflow_management_view.data_source.data = self.stackoverflow_manager.getAvailableStackOverflows()
self.stackoverflow_management_view.reload()
self.navigation_view.push_view(self.stackoverflow_management_view)
console.hide_activity()
def show_usercontributedmanagement_view(self):
self.usercontributed_management_view.data_source.data = self.usercontributed_manager.getAvailableUserContributed()
self.usercontributed_management_view.reload()
self.navigation_view.push_view(self.usercontributed_management_view)
console.hide_activity()
def setup_transfermanagement_view(self):
view = TransferManagementView.get_view(self.transfer_manager.installDocset, self.refresh_main_view_data, self.transfer_manager.deleteDocset, self.transfer_manager.getAvailableDocsets, self.theme_manager, self.transfer_manager)
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def show_transfermanagement_view(self):
self.transfer_management_view.data = self.transfer_manager.getAvailableDocsets()
self.transfer_management_view.reload()
self.navigation_view.push_view(self.transfer_management_view)
def setup_settings_view(self):
settings_view = SettingsView.get_view(self.show_docset_management_view, self.show_cheatsheetmanagement_view, self.show_usercontributedmanagement_view, self.theme_manager, self.show_stackoverflowmanagement_view,self.webSearchManager, self.show_transfermanagement_view, self.settings_manager)
settings_view.background_color = self.theme_manager.currentTheme.settingsBackgroundColour
settings_view.bg_color = self.theme_manager.currentTheme.settingsBackgroundColour
settings_view.tint_color = self.theme_manager.currentTheme.tintColour
return settings_view
def setup_docset_view(self):
v = UISearchControllerWrapper.get_view(DocsetView.get_view(self.theme_manager), self.search_docset, self.docset_index_selected_for_viewing, self.theme_manager, self.build_offline_index_stackoverflow_selected_for_viewing)
return v
def setup_docsetindex_view(self):
view = DocsetIndexView.get_view(self.theme_manager, self.stackoverflow_manager.buildOfflineDocsetHtml)
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def setup_docsetweb_view(self):
view = DocsetWebView.get_view(self.theme_manager)
view.background_color = self.theme_manager.currentTheme.backgroundColour
view.bar_tint_color = self.theme_manager.currentTheme.tintColour
view.bg_color = self.theme_manager.currentTheme.backgroundColour
view.tint_color = self.theme_manager.currentTheme.tintColour
view.title_color = self.theme_manager.currentTheme.textColour
return view
def show_settings_view(self, sender):
self.navigation_view.push_view(self.settings_view)
def docset_selected_for_viewing(self, docset):
types = self.docset_manager.getTypesForDocset(docset)
self.docsetView.tv.data_source.update_with_docset(docset, types, self.docset_type_selected_for_viewing)
self.docsetView.tv.filterData = self.docset_manager.getIndexesbyNameForDocsetSearch
self.docsetView.name = docset['name']
self.docsetView.tv.reload()
self.navigation_view.push_view(self.docsetView)
def docset_type_selected_for_viewing(self, docset, type):
indexes = self.docset_manager.getIndexesbyTypeForDocset(docset, type)
self.docsetIndexView.data_source.update_with_docset(docset, indexes, self.docset_index_selected_for_viewing, 'docset')
self.docsetView.name = docset['name']
self.docsetIndexView.reload()
self.navigation_view.push_view(self.docsetIndexView)
def cheatsheet_selected_for_viewing(self, cheatsheet):
types = self.cheatsheet_manager.getTypesForCheatsheet(cheatsheet)
self.docsetView.tv.data_source.update_with_docset(cheatsheet, types, self.cheatsheet_type_selected_for_viewing)
self.docsetView.tv.filterData = self.cheatsheet_manager.getIndexesbyNameForDocsetSearch
self.docsetView.name = cheatsheet.name
self.docsetView.tv.reload()
self.navigation_view.push_view(self.docsetView)
def cheatsheet_type_selected_for_viewing(self, cheatsheet, type):
indexes = self.cheatsheet_manager.getIndexesbyTypeForCheatsheet(cheatsheet, type)
self.docsetIndexView.data_source.update_with_docset(cheatsheet, indexes, self.docset_index_selected_for_viewing, 'cheatsheet')
self.docsetView.name = cheatsheet.name
self.docsetIndexView.reload()
self.navigation_view.push_view(self.docsetIndexView)
def usercontributed_selected_for_viewing(self, usercontributed):
types = self.usercontributed_manager.getTypesForUserContributed(usercontributed)
self.docsetView.tv.data_source.update_with_docset(usercontributed, types, self.usercontributed_type_selected_for_viewing)
self.docsetView.tv.filterData = self.usercontributed_manager.getIndexesbyNameForDocsetSearch
self.docsetView.name = usercontributed.name
self.docsetView.tv.reload()
self.navigation_view.push_view(self.docsetView)
def usercontributed_type_selected_for_viewing(self, usercontributed, type):
indexes = self.usercontributed_manager.getIndexesbyTypeForUserContributed(usercontributed, type)
self.docsetIndexView.data_source.update_with_docset(usercontributed, indexes, self.docset_index_selected_for_viewing, 'usercontributed')
self.docsetView.name = usercontributed.name
self.docsetIndexView.reload()
self.navigation_view.push_view(self.docsetIndexView)
def stackoverflow_selected_for_viewing(self, stackoverflow):
types = self.stackoverflow_manager.getTypesForStackOverflow(stackoverflow)
self.docsetView.tv.data_source.update_with_docset(stackoverflow, types, self.stackoverflow_type_selected_for_viewing)
self.docsetView.tv.filterData = self.stackoverflow_manager.getIndexesbyNameForDocsetSearch
head, _sep, tail = stackoverflow.name.rpartition(stackoverflow.type)
self.docsetView.name = head + tail + ' (' +stackoverflow.type + ')'
self.docsetView.tv.reload()
self.navigation_view.push_view(self.docsetView)
def stackoverflow_type_selected_for_viewing(self, stackoverflow, type):
indexes = self.stackoverflow_manager.getIndexesbyTypeForStackOverflow(stackoverflow, type)
index_callback = self.docset_index_selected_for_viewing
if stackoverflow.type == 'Offline':
index_callback = self.docset_index_for_offline_stackoverflow_selected_for_viewing
self.docsetIndexView.data_source.update_with_docset(stackoverflow, indexes, index_callback, 'stackoverflow')
self.docsetView.name = stackoverflow.name
self.docsetIndexView.reload()
self.navigation_view.push_view(self.docsetIndexView)
def transfer_selected_for_viewing(self, docset):
types = self.transfer_manager.getTypesForDocset(docset)
self.docsetView.tv.data_source.update_with_docset(docset, types, self.transfer_type_selected_for_viewing)
self.docsetView.tv.filterData = self.transfer_manager.getIndexesbyNameForDocsetSearch
self.docsetView.name = docset.name
self.docsetView.tv.reload()
self.navigation_view.push_view(self.docsetView)
def transfer_type_selected_for_viewing(self, docset, type):
indexes = self.transfer_manager.getIndexesbyTypeForDocset(docset, type)
self.docsetIndexView.data_source.update_with_docset(docset, indexes, self.docset_index_selected_for_viewing, 'transfer')
self.docsetView.name = docset.name
self.docsetIndexView.reload()
self.navigation_view.push_view(self.docsetIndexView)
def docset_index_selected_for_viewing(self, url):
self.docsetWebView.load_url(url)
self.docsetWebView.delegate.buttonHandler.showButtons = True
self.navigation_view.push_view(self.docsetWebView)
def build_offline_index_stackoverflow_selected_for_viewing(self, entry, docset):
html = self.stackoverflow_manager.buildOfflineDocsetHtml(entry, docset)
self.docset_index_for_offline_stackoverflow_selected_for_viewing(html)
def docset_index_for_offline_stackoverflow_selected_for_viewing(self, data):
self.docsetWebView.load_html(data)
self.docsetWebView.delegate.buttonHandler.showButtons = False
self.navigation_view.push_view(self.docsetWebView)
def search_docset(self, name):
if len(name) < 3:
return []
data = self.docsetView.tv.filterData(self.docsetView.tv.data_source.docset, name)
r = []
r.extend(data['first'])
r.extend(data['second'])
r.extend(data['third'])
r.extend(data['fourth'])
return r
def search_all_docsets(self, name):
if len(name) < 3:
return self.webSearchManager.GetAllWebSearches(name)
ret = []
retEnd = []
standard = self.docset_manager.getIndexesbyNameForAllDocset(name)
cheatsheet = self.cheatsheet_manager.getIndexesbyNameForAllCheatsheet(name)
usercontributed = self.usercontributed_manager.getIndexesbyNameForAllUserContributed(name)
stackoverflow = self.stackoverflow_manager.getIndexesbyNameForAllStackOverflow(name)
transfers = self.transfer_manager.getIndexesbyNameForAllDocsets(name)
webSearches = self.webSearchManager.GetAllWebSearches(name)
r = []
if 'first' in standard.keys():
r.extend(standard['first'])
if 'first' in cheatsheet.keys():
r.extend(cheatsheet['first'])
if 'first' in usercontributed.keys():
r.extend(usercontributed['first'])
if 'first' in stackoverflow.keys():
r.extend(stackoverflow['first'])
if 'first' in transfers.keys():
r.extend(transfers['first'])
if 'second' in standard.keys():
r.extend(standard['second'])
if 'second' in cheatsheet.keys():
r.extend(cheatsheet['second'])
if 'second' in usercontributed.keys():
r.extend(usercontributed['second'])
if 'second' in stackoverflow.keys():
r.extend(stackoverflow['second'])
if 'second' in transfers.keys():
r.extend(transfers['second'])
if 'third' in standard.keys():
r.extend(standard['third'])
if 'third' in cheatsheet.keys():
r.extend(cheatsheet['third'])
if 'third' in usercontributed.keys():
r.extend(usercontributed['third'])
if 'third' in stackoverflow.keys():
r.extend(stackoverflow['third'])
if 'third' in transfers.keys():
r.extend(transfers['third'])
if 'fourth' in standard.keys():
r.extend(standard['fourth'])
if 'fourth' in cheatsheet.keys():
r.extend(cheatsheet['fourth'])
if 'fourth' in usercontributed.keys():
r.extend(usercontributed['fourth'])
if 'fourth' in stackoverflow.keys():
r.extend(stackoverflow['fourth'])
if 'fourth' in transfers.keys():
r.extend(transfers['fourth'])
r.extend(webSearches)
return r
@ui.in_background
def checkStandardDocsetsForUpdate(self, sender):
self.docset_manager.checkDocsetsForUpdates(self.docset_management_view.data_source.data)
self.docset_management_view.reload()
console.hide_activity()
@ui.in_background
def checkCheatsheetsForUpdate(self, sender):
self.cheatsheet_manager.checkDocsetsForUpdates(self.cheatsheet_management_view.data_source.data)
self.cheatsheet_management_view.reload()
console.hide_activity()
@ui.in_background
def checkUserContributedForUpdate(self, sender):
self.usercontributed_manager.checkDocsetsForUpdates(self.usercontributed_management_view.data_source.data)
self.usercontributed_management_view.reload()
console.hide_activity()
@ui.in_background
def checkStackOverflowForUpdate(self, sender):
self.stackoverflow_manager.checkDocsetsForUpdates(self.stackoverflow_management_view.data_source.data)
self.stackoverflow_management_view.reload()
console.hide_activity()
if __name__ == '__main__':
try:
py = PyDoc()
style = py.settings_manager.settings['ui_style']
py.navigation_view.present(hide_title_bar=True,style=style)
except Exception as e:
console.hide_activity()
console.alert('Error occured', str(e), 'Ok', hide_cancel_button=True)