Cleanup of widgets, fixing or updating plugins

This commit is contained in:
2023-03-04 21:45:29 -06:00
parent cbcdeaa037
commit 3c72ad2801
40 changed files with 355 additions and 914 deletions

View File

@@ -64,6 +64,8 @@ class FileSearchMixin:
break
def _stop_fsearch_query(self, widget=None, eve=None):
self._spinner.stop()
# NOTE: Freeze IPC consumption
self.pause_fifo_update = True
self.search_query = ""
@@ -86,10 +88,10 @@ class FileSearchMixin:
self.search_query = query
target_dir = shlex.quote( self._fm_state.tab.get_current_directory() )
command = ["python", f"{self.path}/utils/search.py", "-t", "file_search", "-d", f"{target_dir}", "-q", f"{query}"]
self._spinner.start()
self._list_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
def _load_file_ui(self, data):
Gtk.main_iteration()

View File

@@ -64,6 +64,8 @@ class GrepSearchMixin:
break
def _stop_grep_query(self, widget=None, eve=None):
self._spinner.stop()
# NOTE: Freeze IPC consumption
self.pause_fifo_update = True
self.grep_query = ""
@@ -88,6 +90,7 @@ class GrepSearchMixin:
target_dir = shlex.quote( self._fm_state.tab.get_current_directory() )
command = ["python", f"{self.path}/utils/search.py", "-t", "grep_search", "-d", f"{target_dir}", "-q", f"{query}"]
self._spinner.start()
self._grep_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
def _load_grep_ui(self, data):

View File

@@ -28,6 +28,7 @@ class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase):
self.update_list_ui_buffer = ()
self._search_dialog = None
self._spinner = None
self._active_path = None
self.file_list_parent = None
self.grep_list_parent = None
@@ -55,6 +56,7 @@ class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase):
self._search_dialog = self._builder.get_object("search_dialog")
self.fsearch = self._builder.get_object("fsearch")
self._spinner = self._builder.get_object("spinner")
self.grep_list_parent = self._builder.get_object("grep_list_parent")
self.file_list_parent = self._builder.get_object("file_list_parent")
@@ -72,6 +74,10 @@ class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase):
item.set_always_show_image(True)
return item
def stop_spinner(self, ret_code):
print(f"Return Code: {ret_code}")
self._spinner.stop()
def _show_page(self, widget=None, eve=None):
self._event_system.emit("get_current_state")

View File

@@ -25,6 +25,17 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkSpinner" id="spinner">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property>
@@ -37,7 +48,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@@ -52,7 +63,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@@ -260,6 +271,12 @@
<child type="tab">
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>

View File

@@ -59,23 +59,27 @@ class IPCServer:
while True:
msg = conn.recv()
if "SEARCH|" in msg:
ts, file = msg.split("SEARCH|")[1].strip().split("|", 1)
try:
try:
if "SEARCH_DONE|" in msg:
ts, ret_code = msg.split("SEARCH_DONE|")[1].strip().split("|", 1)
timestamp = float(ts)
if timestamp > self.fsearch_time_stamp and file:
GLib.idle_add(self._load_file_ui, file, priority=GLib.PRIORITY_LOW)
except Exception as e:
...
if self.fsearch_time_stamp or self.grep_time_stamp:
if (timestamp > self.fsearch_time_stamp) or (timestamp > self.grep_time_stamp):
GLib.idle_add(self.stop_spinner, (ret_code,), priority=GLib.PRIORITY_HIGH_IDLE)
if "GREP|" in msg:
ts, data = msg.split("GREP|")[1].strip().split("|", 1)
try:
if "SEARCH|" in msg:
ts, file = msg.split("SEARCH|")[1].strip().split("|", 1)
timestamp = float(ts)
if timestamp > self.grep_time_stamp and data:
GLib.idle_add(self._load_grep_ui, data, priority=GLib.PRIORITY_LOW)
except Exception as e:
...
if file and (timestamp > self.fsearch_time_stamp):
GLib.idle_add(self._load_file_ui, file, priority=GLib.PRIORITY_HIGH_IDLE)
if "GREP|" in msg:
ts, data = msg.split("GREP|")[1].strip().split("|", 1)
timestamp = float(ts)
if data and (timestamp > self.grep_time_stamp):
GLib.idle_add(self._load_grep_ui, data, priority=GLib.PRIORITY_HIGH_IDLE)
except Exception as e:
print( repr(e) )
conn.close()

View File

@@ -82,12 +82,11 @@ def grep_search(target=None, query=None):
collection[f"{b64_file}"] = {}
collection[f"{b64_file}"] = { f"{line_no}": b64_data}
data = f"GREP|{ts}|{json.dumps(collection, separators=(',', ':'), indent=4)}"
send_ipc_message(data)
except Exception as e:
traceback.print_exc()
data = f"GREP|{ts}|{json.dumps(collection, separators=(',', ':'), indent=4)}"
send_ipc_message(data)
collection = {}
@@ -112,5 +111,11 @@ if __name__ == "__main__":
# Read arguments (If any...)
args = parser.parse_args()
search(args)
data = f"SEARCH_DONE|{ts}|0"
send_ipc_message(data)
except Exception as e:
traceback.print_exc()
data = f"SEARCH_DONE|{ts}|1"
send_ipc_message(data)

View File

@@ -60,7 +60,7 @@ class Plugin(PluginBase):
self._queue_translate = False
self._watcher_running = False
self._vqd_attrib = None
self.from_trans = "jp"
self.from_trans = "ja"
self.to_trans = "en"
self.translate_tries = 0
@@ -138,14 +138,14 @@ class Plugin(PluginBase):
self.translate_tries += 1
tlink = f"https://duckduckgo.com/translation.js?vqd={self._vqd_attrib}&query=translate&from={self.from_trans}&to={self.to_trans}"
response = requests.post(self.tlink, headers=self._headers, data=from_translate)
response = requests.post(tlink, headers=self._headers, data=from_translate)
if response.status_code == 200:
data = response.json()
self._translate_to_buffer.set_text(data["translated"])
self.translate_tries = 0
if "detected_language" in data.keys():
if data["detected_language"]:
self._detected_language_lbl.set_label(f"Detected Language: {data['detected_language']}")
else:
self._detected_language_lbl.set_label(f"Selected Language: {self.from_trans}")
@@ -157,7 +157,7 @@ class Plugin(PluginBase):
msg = f"Could not translate... Response Code: {response.status_code}"
self._translate_to_buffer.set_text(msg)
# NOTE: https://github.com/deedy5/duckduckgo_search/blob/72acb900a346be576f0917dd3d6c0fbd618a71bf/duckduckgo_search/utils.py
def get_vqd(self):
response = requests.post(self.vqd_link, headers=self.vqd_headers, data=self.vqd_data, timeout=10)
if response.status_code == 200:

View File

@@ -13,7 +13,7 @@ function main() {
LINK=`xclip -selection clipboard -o`
python "${HOME}/.config/solarfm/plugins/youtube_download/yt_dlp/__main__.py" \
--cookies-from-browser firefox --write-sub --embed-sub --sub-langs en \
--write-sub --embed-sub --sub-langs en \
-o "${1}/%(title)s.%(ext)s" "${LINK}"
}
main "$@";