Browse Source

Move publisher topics to module level

doc-issue-template
MrS0m30n3 9 years ago
parent
commit
8cf53afba8
3 changed files with 35 additions and 15 deletions
  1. 19
      youtube_dl_gui/downloadmanager.py
  2. 17
      youtube_dl_gui/mainframe.py
  3. 14
      youtube_dl_gui/updatemanager.py

19
youtube_dl_gui/downloadmanager.py

@ -5,6 +5,13 @@
This module is responsible for managing the download process
and update the GUI interface.
Attributes:
MANAGER_PUB_TOPIC (string): wxPublisher subscription topic of the
DownloadManager thread.
WORKER_PUB_TOPIC (string): wxPublisher subscription topic of the
Worker thread.
Note:
It's not the actual module that downloads the urls
thats the job of the 'downloaders' module.
@ -26,12 +33,15 @@ from .downloaders import YoutubeDLDownloader
from .utils import YOUTUBEDL_BIN
MANAGER_PUB_TOPIC = 'dlmanager'
WORKER_PUB_TOPIC = 'dlworker'
class DownloadManager(Thread):
"""Manages the download process.
Attributes:
PUBLISHER_TOPIC (string): Subscription topic for the wxPublisher.
WORKERS_NUMBER (int): Size of custom thread pool.
WAIT_TIME (float): Time in seconds to sleep.
@ -48,7 +58,6 @@ class DownloadManager(Thread):
"""
PUBLISHER_TOPIC = 'dlmanager'
WORKERS_NUMBER = 3
WAIT_TIME = 0.1
@ -162,7 +171,7 @@ class DownloadManager(Thread):
3) finished: The download process was completed normally.
"""
CallAfter(Publisher.sendMessage, self.PUBLISHER_TOPIC, data)
CallAfter(Publisher.sendMessage, MANAGER_PUB_TOPIC, data)
def _check_youtubedl(self):
"""Check if youtube-dl binary exists. If not try to download it. """
@ -200,7 +209,6 @@ class Worker(Thread):
from the 'downloaders' module.
Attributes:
PUBLISHER_TOPIC (string): Subscription topic for the wxPublisher.
WAIT_TIME (float): Time in seconds to sleep.
Args:
@ -217,7 +225,6 @@ class Worker(Thread):
"""
PUBLISHER_TOPIC = 'dlworker'
WAIT_TIME = 0.1
def __init__(self, opt_manager, youtubedl, increase_succ, log_manager=None):
@ -299,7 +306,7 @@ class Worker(Thread):
def _talk_to_gui(self, data):
"""Send data back to the GUI after inserting the index. """
data['index'] = self._index
CallAfter(Publisher.sendMessage, self.PUBLISHER_TOPIC, data)
CallAfter(Publisher.sendMessage, WORKER_PUB_TOPIC, data)
if __name__ == '__main__':

17
youtube_dl_gui/mainframe.py

@ -9,8 +9,15 @@ from wx.lib.pubsub import pub as Publisher
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
from .optionsframe import OptionsFrame
from .updatemanager import UpdateThread
from .downloadmanager import DownloadManager
from .updatemanager import (
UPDATE_PUB_TOPIC,
UpdateThread
)
from .downloadmanager import (
MANAGER_PUB_TOPIC,
WORKER_PUB_TOPIC,
DownloadManager
)
from .utils import (
get_icon_file,
@ -141,9 +148,9 @@ class MainFrame(wx.Frame):
self._set_sizers()
# Set threads wxCallAfter handlers using subscribe
self._set_publisher(self._update_handler, 'update')
self._set_publisher(self._status_list_handler, 'dlworker')
self._set_publisher(self._download_manager_handler, 'dlmanager')
self._set_publisher(self._update_handler, UPDATE_PUB_TOPIC)
self._set_publisher(self._status_list_handler, WORKER_PUB_TOPIC)
self._set_publisher(self._download_manager_handler, MANAGER_PUB_TOPIC)
def _set_publisher(self, handler, topic):
"""Sets a handler for the given topic.

14
youtube_dl_gui/updatemanager.py

@ -1,6 +1,12 @@
#!/usr/bin/env python2
"""Youtubedlg module to update youtube-dl binary. """
"""Youtubedlg module to update youtube-dl binary.
Attributes:
UPDATE_PUB_TOPIC (string): wxPublisher subscription topic of the
UpdateThread thread.
"""
import os.path
from threading import Thread
@ -15,6 +21,8 @@ from .utils import (
check_path
)
UPDATE_PUB_TOPIC = 'update'
class UpdateThread(Thread):
@ -22,7 +30,6 @@ class UpdateThread(Thread):
Attributes:
LATEST_YOUTUBE_DL (string): URL with the latest youtube-dl binary.
PUBLISHER_TOPIC (string): Subscription topic for the wx Publisher.
DOWNLOAD_TIMEOUT (int): Download timeout in seconds.
Args:
@ -36,7 +43,6 @@ class UpdateThread(Thread):
"""
LATEST_YOUTUBE_DL = 'https://yt-dl.org/latest/'
PUBLISHER_TOPIC = 'update'
DOWNLOAD_TIMEOUT = 20
def __init__(self, download_path, quiet=False):
@ -84,4 +90,4 @@ class UpdateThread(Thread):
4) finish: The update thread is ready to join
"""
CallAfter(Publisher.sendMessage, self.PUBLISHER_TOPIC, (signal, data))
CallAfter(Publisher.sendMessage, UPDATE_PUB_TOPIC, (signal, data))
Loading…
Cancel
Save