From 81a88a73dba871c8685118e60a83cbb72b931a3a Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 7 Jan 2023 14:15:06 -0600 Subject: [PATCH] Limiting thread spawns --- plugins/git_clone/__init__.py | 3 ++ plugins/git_clone/__main__.py | 3 ++ plugins/git_clone/download.sh | 20 +++++++ plugins/git_clone/manifest.json | 12 +++++ plugins/git_clone/plugin.py | 53 +++++++++++++++++++ .../solarfm/core/mixins/ui/grid_mixin.py | 8 ++- 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 plugins/git_clone/__init__.py create mode 100644 plugins/git_clone/__main__.py create mode 100755 plugins/git_clone/download.sh create mode 100644 plugins/git_clone/manifest.json create mode 100644 plugins/git_clone/plugin.py diff --git a/plugins/git_clone/__init__.py b/plugins/git_clone/__init__.py new file mode 100644 index 0000000..d36fa8c --- /dev/null +++ b/plugins/git_clone/__init__.py @@ -0,0 +1,3 @@ +""" + Pligin Module +""" diff --git a/plugins/git_clone/__main__.py b/plugins/git_clone/__main__.py new file mode 100644 index 0000000..a576329 --- /dev/null +++ b/plugins/git_clone/__main__.py @@ -0,0 +1,3 @@ +""" + Pligin Package +""" diff --git a/plugins/git_clone/download.sh b/plugins/git_clone/download.sh new file mode 100755 index 0000000..0062195 --- /dev/null +++ b/plugins/git_clone/download.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# . CONFIG.sh + +# set -o xtrace ## To debug scripts +# set -o errexit ## To exit on error +# set -o errunset ## To exit if a variable is referenced but not set + + +function main() { + cd "$(dirname "")" + echo "Working Dir: " $(pwd) + + TARGETDIR="${1}" + LINK=`xclip -selection clipboard -o` + + cd "${TARGETDIR}" + git clone "${LINK}" +} +main "$@"; diff --git a/plugins/git_clone/manifest.json b/plugins/git_clone/manifest.json new file mode 100644 index 0000000..ff04e03 --- /dev/null +++ b/plugins/git_clone/manifest.json @@ -0,0 +1,12 @@ +{ + "manifest": { + "name": "Git Clone", + "author": "ITDominator", + "version": "0.0.1", + "support": "", + "requests": { + "ui_target": "plugin_control_list", + "pass_fm_events": "true" + } + } +} diff --git a/plugins/git_clone/plugin.py b/plugins/git_clone/plugin.py new file mode 100644 index 0000000..bfa2e80 --- /dev/null +++ b/plugins/git_clone/plugin.py @@ -0,0 +1,53 @@ +# Python imports +import os, threading, subprocess, time + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports +from plugins.plugin_base import PluginBase + + +# NOTE: Threads WILL NOT die with parent's destruction. +def threaded(fn): + def wrapper(*args, **kwargs): + threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start() + return wrapper + +# NOTE: Threads WILL die with parent's destruction. +def daemon_threaded(fn): + def wrapper(*args, **kwargs): + threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start() + return wrapper + + + + +class Plugin(PluginBase): + def __init__(self): + super().__init__() + + self.path = os.path.dirname(os.path.realpath(__file__)) + self.name = "Git Clone" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus + # where self.name should not be needed for message comms + + def generate_reference_ui_element(self): + button = Gtk.Button(label=self.name) + button.connect("button-release-event", self._do_download) + return button + + def run(self): + ... + + + def _do_download(self, widget=None, eve=None): + self._event_system.emit("get_current_state") + + dir = self._fm_state.tab.get_current_directory() + self._download(dir) + + @threaded + def _download(self, dir): + subprocess.Popen([f'{self.path}/download.sh', dir]) diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/mixins/ui/grid_mixin.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/mixins/ui/grid_mixin.py index 92bfb59..f56e7ac 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/mixins/ui/grid_mixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/mixins/ui/grid_mixin.py @@ -31,14 +31,18 @@ class GridMixin: for file in files: store.append([None, file[0]]) - for i, file in enumerate(files): - self.create_icon(i, tab, store, dir, file[0]) + self.load_icons(tab, store, dir, files) # NOTE: Not likely called often from here but it could be useful if save_state and not trace_debug: self.fm_controller.save_state() + @threaded + def load_icons(self, tab, store, dir, files): + for i, file in enumerate(files): + self.create_icon(i, tab, store, dir, file[0]) + def create_icon(self, i, tab, store, dir, file): icon = tab.create_icon(dir, file) GLib.idle_add(self.update_store, *(i, store, icon, tab, dir, file,))