Merge Stable Changesto Master #9

Merged
itdominator merged 30 commits from develop into master 2022-11-29 04:58:09 +00:00
11 changed files with 304 additions and 231 deletions
Showing only changes of commit 49ed89201a - Show all commits

View File

@ -0,0 +1,3 @@
"""
Pligin Module
"""

View File

@ -0,0 +1,3 @@
"""
Pligin Package
"""

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkTextBuffer" id="arc_command_buffer">
<property name="text" translatable="yes">$(which 7za || echo 7zr) a %o %N</property>
</object>
<object class="GtkFileChooserDialog" id="archiver_dialogue">
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="window-position">center</property>
<property name="type-hint">dialog</property>
<property name="gravity">center</property>
<property name="do-overwrite-confirmation">True</property>
<property name="select-multiple">True</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button21">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</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="button22">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Compress Commands:</property>
<property name="xalign">0.20000000298023224</property>
<attributes>
<attribute name="gravity" value="west"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Archive Format:</property>
<property name="xalign">1</property>
<attributes>
<attribute name="gravity" value="east"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<property name="active-id">0</property>
<items>
<item id="0" translatable="yes">7Zip (*.7z)</item>
<item id="1" translatable="yes">Zip (*.zip *.ZIP)</item>
<item id="2" translatable="yes">RAR (*.rar *.RAR)</item>
<item id="3" translatable="yes">Tar (*.tar)</item>
<item id="4" translatable="yes">Tar bzip2 (*.tar.bz2)</item>
<item id="5" translatable="yes">Tar Gzip (*.tar.gz *.tgz)</item>
<item id="6" translatable="yes">Tar xz (*.tar.xz *.txz)</item>
<item id="7" translatable="yes">Gzip (*.gz)</item>
<item id="8" translatable="yes">XZ (*.xz)</item>
</items>
<signal name="changed" handler="set_arc_buffer_text" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTextView" id="arc_command">
<property name="height-request">72</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="buffer">arc_command_buffer</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button21</action-widget>
<action-widget response="-5">button22</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -0,0 +1,12 @@
{
"manifest": {
"name": "Archiver",
"author": "ITDominator",
"version": "0.0.1",
"support": "",
"requests": {
"ui_target": "context_menu",
"pass_fm_events": "true"
}
}
}

122
plugins/archiver/plugin.py Normal file
View File

@ -0,0 +1,122 @@
# Python imports
import os, threading, subprocess, inspect, shlex
# 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._GLADE_FILE = f"{self.path}/archiver.glade"
self.name = "Archiver" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
# where self.name should not be needed for message comms
self._archiver_dialogue = None
self._arc_command_buffer = None
# In compress commands:
# %n: First selected filename/dir to archive
# %N: All selected filenames/dirs to archive, or (with %O) a single filename
# %o: Resulting single archive file
# %O: Resulting archive per source file/directory (use changes %N meaning)
#
# In extract commands:
# %x: Archive file to extract
# %g: Unique extraction target filename with optional subfolder
# %G: Unique extraction target filename, never with subfolder
#
# In list commands:
# %x: Archive to list
#
# Plus standard bash variables are accepted.
self.arc_commands = [ '$(which 7za || echo 7zr) a %o %N',
'zip -r %o %N',
'rar a -r %o %N',
'tar -cvf %o %N',
'tar -cvjf %o %N',
'tar -cvzf %o %N',
'tar -cvJf %o %N',
'gzip -c %N > %O',
'xz -cz %N > %O'
]
def generate_reference_ui_element(self):
self._builder = Gtk.Builder()
self._builder.add_from_file(self._GLADE_FILE)
classes = [self]
handlers = {}
for c in classes:
methods = None
try:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
except Exception as e:
print(repr(e))
self._builder.connect_signals(handlers)
self._archiver_dialogue = self._builder.get_object("archiver_dialogue")
self._arc_command_buffer = self._builder.get_object("arc_command_buffer")
button = Gtk.Button(label=self.name)
button.connect("button-release-event", self.show_archiver_dialogue)
return button
def run(self):
...
def show_archiver_dialogue(self, widget=None, eve=None):
self._event_system.emit("get_current_state")
state = self._fm_state
self._archiver_dialogue.set_action(Gtk.FileChooserAction.SAVE)
self._archiver_dialogue.set_current_folder(state.tab.get_current_directory())
self._archiver_dialogue.set_current_name("arc.7z")
response = self._archiver_dialogue.run()
if response == Gtk.ResponseType.OK:
save_target = self._archiver_dialogue.get_filename()
self.archive_files(save_target, state)
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
pass
self._archiver_dialogue.hide()
def archive_files(self, save_target, state):
paths = [shlex.quote(p) for p in state.selected_files]
sItr, eItr = self._arc_command_buffer.get_bounds()
pre_command = self._arc_command_buffer.get_text(sItr, eItr, False)
pre_command = pre_command.replace("%o", shlex.quote(save_target))
pre_command = pre_command.replace("%N", ' '.join(paths))
command = f"{state.tab.terminal_app} -e {shlex.quote(pre_command)}"
current_dir = state.tab.get_current_directory()
state.tab.execute(shlex.split(command), start_dir=shlex.quote(current_dir))
def set_arc_buffer_text(self, widget=None, eve=None):
sid = widget.get_active_id()
self.arc_command_buffer.set_text(self.arc_commands[int(sid)])

View File

@ -128,8 +128,6 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
self.copy_files()
if action == "paste":
self.paste_files()
if action == "archive":
self.show_archiver_dialogue()
if action == "create":
self.create_files()
if action in ["save_session", "save_session_as", "load_session"]:

View File

@ -64,32 +64,6 @@ class Controller_Data:
self.trash_info_path = f"{GLib.get_user_data_dir()}/Trash/info"
self.icon_theme = settings.get_icon_theme()
# In compress commands:
# %n: First selected filename/dir to archive
# %N: All selected filenames/dirs to archive, or (with %O) a single filename
# %o: Resulting single archive file
# %O: Resulting archive per source file/directory (use changes %N meaning)
#
# In extract commands:
# %x: Archive file to extract
# %g: Unique extraction target filename with optional subfolder
# %G: Unique extraction target filename, never with subfolder
#
# In list commands:
# %x: Archive to list
#
# Plus standard bash variables are accepted.
self.arc_commands = [ '$(which 7za || echo 7zr) a %o %N',
'zip -r %o %N',
'rar a -r %o %N',
'tar -cvf %o %N',
'tar -cvjf %o %N',
'tar -cvzf %o %N',
'tar -cvJf %o %N',
'gzip -c %N > %O',
'xz -cz %N > %O'
]
self.notebooks = [self.window1, self.window2, self.window3, self.window4]
self.selected_files = []
self.to_copy_files = []

View File

@ -51,8 +51,3 @@ class ExceptionHookMixin:
f.write(text)
save_location_prompt.destroy()
def set_arc_buffer_text(self, widget=None, eve=None):
sid = widget.get_active_id()
self.arc_command_buffer.set_text(self.arc_commands[int(sid)])

View File

@ -55,26 +55,6 @@ class ShowHideMixin:
self.builder.get_object("about_page").hide()
def show_archiver_dialogue(self, widget=None, eve=None):
wid, tid = self.fm_controller.get_active_wid_and_tid()
tab = self.get_fm_window(wid).get_tab_by_id(tid)
archiver_dialogue = self.builder.get_object("archiver_dialogue")
archiver_dialogue.set_action(Gtk.FileChooserAction.SAVE)
archiver_dialogue.set_current_folder(tab.get_current_directory())
archiver_dialogue.set_current_name("arc.7z")
response = archiver_dialogue.run()
if response == Gtk.ResponseType.OK:
self.archive_files(archiver_dialogue)
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
pass
archiver_dialogue.hide()
def hide_archiver_dialogue(self, widget=None, eve=None):
self.builder.get_object("archiver_dialogue").hide()
def show_appchooser_menu(self, widget=None, eve=None):
appchooser_menu = self.builder.get_object("appchooser_menu")
appchooser_widget = self.builder.get_object("appchooser_widget")

View File

@ -143,19 +143,6 @@ class WidgetFileActionMixin:
command = f"{shlex.quote(path)}" if not in_terminal else f"{state.tab.terminal_app} -e {shlex.quote(path)}"
state.tab.execute(shlex.split(command), start_dir=state.tab.get_current_directory())
def archive_files(self, archiver_dialogue):
state = self.get_current_state()
paths = [shlex.quote(p) for p in self.format_to_uris(state.store, state.wid, state.tid, self.selected_files, True)]
save_target = archiver_dialogue.get_filename();
sItr, eItr = self.arc_command_buffer.get_bounds()
pre_command = self.arc_command_buffer.get_text(sItr, eItr, False)
pre_command = pre_command.replace("%o", shlex.quote(save_target))
pre_command = pre_command.replace("%N", ' '.join(paths))
command = f"{state.tab.terminal_app} -e {shlex.quote(pre_command)}"
state.tab.execute(shlex.split(command), start_dir=shlex.quote(state.tab.get_current_directory()))
def rename_files(self):
rename_label = self.builder.get_object("file_to_rename_label")
rename_input = self.builder.get_object("new_rename_fname")

View File

@ -452,170 +452,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe
<action-widget response="-5">appchooser_select_btn</action-widget>
</action-widgets>
</object>
<object class="GtkTextBuffer" id="arc_command_buffer">
<property name="text" translatable="yes">$(which 7za || echo 7zr) a %o %N</property>
</object>
<object class="GtkFileChooserDialog" id="archiver_dialogue">
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="window-position">center</property>
<property name="type-hint">dialog</property>
<property name="gravity">center</property>
<property name="do-overwrite-confirmation">True</property>
<property name="select-multiple">True</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button21">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</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="button22">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Compress Commands:</property>
<property name="xalign">0.20000000298023224</property>
<attributes>
<attribute name="gravity" value="west"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Archive Format:</property>
<property name="xalign">1</property>
<attributes>
<attribute name="gravity" value="east"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<property name="active-id">0</property>
<items>
<item id="0" translatable="yes">7Zip (*.7z)</item>
<item id="1" translatable="yes">Zip (*.zip *.ZIP)</item>
<item id="2" translatable="yes">RAR (*.rar *.RAR)</item>
<item id="3" translatable="yes">Tar (*.tar)</item>
<item id="4" translatable="yes">Tar bzip2 (*.tar.bz2)</item>
<item id="5" translatable="yes">Tar Gzip (*.tar.gz *.tgz)</item>
<item id="6" translatable="yes">Tar xz (*.tar.xz *.txz)</item>
<item id="7" translatable="yes">Gzip (*.gz)</item>
<item id="8" translatable="yes">XZ (*.xz)</item>
</items>
<signal name="changed" handler="set_arc_buffer_text" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTextView" id="arc_command">
<property name="height-request">72</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="buffer">arc_command_buffer</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button21</action-widget>
<action-widget response="-5">button22</action-widget>
</action-widgets>
</object>
<object class="GtkImage" id="archive_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-save-as</property>
</object>
<object class="GtkImage" id="create_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -912,7 +748,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="tooltip-text" translatable="yes">Archive...</property>
<property name="image">archive_img</property>
<property name="always-show-image">True</property>
<signal name="button-release-event" handler="do_action_from_menu_controls" swapped="no"/>
</object>