forked from MalloyDelacroix/DownloaderForReddit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (67 loc) · 3.1 KB
/
main.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
"""
Downloader for Reddit takes a list of reddit users and subreddits and downloads content posted to reddit either by the
users or on the subreddits.
Copyright (C) 2017, Kyle Hickey
This file is part of the Downloader for Reddit.
Downloader for Reddit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Downloader for Reddit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Downloader for Reddit. If not, see <http://www.gnu.org/licenses/>.
"""
import ctypes
import sys
from PyQt5 import QtWidgets, QtCore
import logging
from DownloaderForReddit.gui.downloader_for_reddit_gui import DownloaderForRedditGUI
from DownloaderForReddit.messaging.message_receiver import MessageReceiver
from DownloaderForReddit.database.migration import Migrator
from DownloaderForReddit.utils import injector
from DownloaderForReddit.local_logging import logger
from DownloaderForReddit.version import __version__
if sys.platform == 'win32':
myappid = 'SomeGuySoftware.DownloaderForReddit.%s' % __version__
AppUserModelID = ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
def log_unhandled_exception(exc_type, value, traceback):
logger = logging.getLogger('DownloaderForReddit.%s' % __name__)
logger.critical('Unhandled exception', exc_info=(exc_type, value, traceback))
sys.exit(-1)
def check_migration():
migrator = Migrator()
migrator.check_migration()
def main():
logger.make_logger()
sys.excepthook = log_unhandled_exception
check_migration()
app = QtWidgets.QApplication(sys.argv)
queue = injector.get_message_queue()
message_thread = QtCore.QThread()
receiver = MessageReceiver(queue)
scheduler = injector.get_scheduler()
window = DownloaderForRedditGUI(queue, receiver, scheduler)
receiver.text_output.connect(window.output_view_model.handle_message)
receiver.non_text_output.connect(window.handle_progress)
receiver.moveToThread(message_thread)
message_thread.started.connect(receiver.run)
receiver.finished.connect(message_thread.quit)
receiver.finished.connect(receiver.deleteLater)
message_thread.finished.connect(message_thread.deleteLater)
message_thread.start()
schedule_thread = QtCore.QThread()
scheduler.moveToThread(schedule_thread)
scheduler.run_task.connect(window.run_scheduled_download)
scheduler.countdown.connect(window.update_scheduled_download)
scheduler.finished.connect(schedule_thread.quit)
scheduler.finished.connect(scheduler.deleteLater)
schedule_thread.finished.connect(schedule_thread.deleteLater)
schedule_thread.started.connect(scheduler.run)
schedule_thread.start()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()