2022-01-31 02:29:57 +00:00
|
|
|
# Python imports
|
2022-06-15 04:03:04 +00:00
|
|
|
import os, threading, subprocess, time
|
2022-01-31 02:29:57 +00:00
|
|
|
|
2022-07-21 04:57:06 +00:00
|
|
|
# Lib imports
|
2022-01-31 02:29:57 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
# Application imports
|
2022-09-06 02:21:04 +00:00
|
|
|
from plugins.plugin_base import PluginBase
|
2022-01-31 02:29:57 +00:00
|
|
|
|
|
|
|
|
2022-06-19 03:27:17 +00:00
|
|
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
2022-01-31 02:29:57 +00:00
|
|
|
def threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
2022-02-01 07:43:09 +00:00
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
2022-01-31 02:29:57 +00:00
|
|
|
return wrapper
|
|
|
|
|
2022-06-19 03:27:17 +00:00
|
|
|
# NOTE: Threads WILL die with parent's destruction.
|
2022-06-15 04:03:04 +00:00
|
|
|
def daemon_threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-31 02:29:57 +00:00
|
|
|
|
2022-09-06 02:21:04 +00:00
|
|
|
class Plugin(PluginBase):
|
2022-07-07 04:19:41 +00:00
|
|
|
def __init__(self):
|
2022-09-06 02:21:04 +00:00
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.path = os.path.dirname(os.path.realpath(__file__))
|
2022-08-13 03:54:16 +00:00
|
|
|
self.name = "Youtube Download" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
|
|
|
|
# where self.name should not be needed for message comms
|
2022-02-25 07:29:37 +00:00
|
|
|
|
2022-06-15 04:03:04 +00:00
|
|
|
|
2022-07-07 04:19:41 +00:00
|
|
|
def get_ui_element(self):
|
|
|
|
button = Gtk.Button(label=self.name)
|
2022-02-11 06:58:49 +00:00
|
|
|
button.connect("button-release-event", self._do_download)
|
2022-07-07 04:19:41 +00:00
|
|
|
return button
|
2022-02-25 07:29:37 +00:00
|
|
|
|
2022-07-07 04:19:41 +00:00
|
|
|
def run(self):
|
2022-09-29 22:22:33 +00:00
|
|
|
...
|
2022-06-19 03:27:17 +00:00
|
|
|
|
|
|
|
|
2022-07-16 07:33:25 +00:00
|
|
|
def _do_download(self, widget=None, eve=None):
|
2022-10-01 04:30:38 +00:00
|
|
|
self._event_system.emit("get_current_state
|
2022-09-29 22:22:33 +00:00
|
|
|
|
|
|
|
dir = self._fm_state.tab.get_current_directory()
|
|
|
|
self._download(dir)
|
2022-07-16 07:33:25 +00:00
|
|
|
|
2022-09-29 22:22:33 +00:00
|
|
|
@threaded
|
|
|
|
def _download(self, dir):
|
|
|
|
subprocess.Popen([f'{self.path}/download.sh', dir])
|