Refactoring stuff

This commit is contained in:
itdominator 2021-12-04 18:23:00 -06:00
parent 8c69cdebe5
commit cbf5706845
7 changed files with 86 additions and 77 deletions

View File

@ -4,11 +4,16 @@
SolarFM is a Gtk+ Python file manager.
# Notes
```sudo apt-get install python3 wget ffmpegthumbnailer steamcmd```
<b>Still Work in progress! Use at own risk!</b>
<h6>Install Setup</h6>
```
sudo apt-get install python3 wget ffmpegthumbnailer steamcmd
```
# TODO
<ul>
<li>Add prompt guards for actions.</li>
<li><b>Fix the wonky file handler situation and add prompt guards for actions.</b></li>
<li>Add path bar search dropdown.</li>
<li>Add "clear trash", "restore from trash" options.</li>
<li>Add drive size free and consumed info to bottom bar.</li>

View File

@ -35,9 +35,16 @@ class Launcher:
else:
command = ["xdg-open", file]
self.execute(command)
def execute(self, command, start_dir=os.getenv("HOME"), use_os_system=None):
self.logger.debug(command)
DEVNULL = open(os.devnull, 'w')
subprocess.Popen(command, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL, close_fds=True)
if use_os_system:
os.system(command)
else:
DEVNULL = open(os.devnull, 'w')
subprocess.Popen(command, cwd=start_dir, shell=False, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL, close_fds=True)
def remux_video(self, hash, file):

View File

@ -21,7 +21,7 @@ def threaded(fn):
class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
WidgetFileActionMixin, PaneMixin, WindowMixin):
def __init__(self, args, unknownargs, _settings):
sys.excepthook = self.my_except_hook
# sys.excepthook = self.custom_except_hook
self.settings = _settings
self.setup_controller_data()
@ -65,7 +65,7 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
print(repr(e))
def my_except_hook(self, exctype, value, _traceback):
def custom_except_hook(self, exctype, value, _traceback):
trace = ''.join(traceback.format_tb(_traceback))
data = f"Exectype: {exctype} <--> Value: {value}\n\n{trace}\n\n\n\n"
start_itr = self.message_buffer.get_start_iter()
@ -104,22 +104,12 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
save_location_prompt.destroy()
def do_edit_files(self, widget=None, eve=None):
self.to_rename_files = self.selected_files
self.rename_files()
def set_arc_buffer_text(self, widget=None, eve=None):
id = widget.get_active_id()
self.arc_command_buffer.set_text(self.arc_commands[int(id)])
def execute(self, _command, start_dir=os.getenv("HOME"), use_os_system=None):
if use_os_system:
os.system(_command)
else:
DEVNULL = open(os.devnull, 'w')
command = _command.split()
subprocess.Popen(command, cwd=start_dir, shell=False, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL)
def do_action_from_menu_controls(self, widget, eventbutton):
action = widget.get_name()
@ -128,15 +118,14 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
self.hide_new_file_menu()
self.hide_edit_file_menu()
if action == "open":
self.open_files()
if action == "open_with":
self.show_appchooser_menu()
if action == "execute":
self.execute_files()
if action == "execute_in_terminal":
self.execute_files(in_terminal=True)
if action == "create":
self.create_file()
self.hide_new_file_menu()
if action == "open":
self.open_files()
if action == "rename":
self.to_rename_files = self.selected_files
self.rename_files()
@ -157,6 +146,11 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
if action == "go_to_trash":
self.builder.get_object("path_entry").set_text(self.trash_files_path)
if action == "create":
self.create_file()
self.hide_new_file_menu()
self.ctrlDown = False

View File

@ -78,4 +78,4 @@ class KeyboardSignalsMixin:
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
dir = view.get_current_directory()
self.execute("terminator", dir)
view.execute(f"{view.terminal_app}", dir)

View File

@ -106,10 +106,10 @@ class ShowHideMixin:
name = widget.get_name()
if name == "rename":
self.builder.get_object("edit_file_menu").hide()
keyname = Gdk.keyval_name(eve.keyval).lower()
if "return" in keyname or "enter" in keyname:
self.builder.get_object("edit_file_menu").hide()
else:
keyname = Gdk.keyval_name(eve.keyval).lower()
if "return" in keyname or "enter" in keyname:
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_skip(self, widget=None, eve=None):

View File

@ -52,28 +52,6 @@ class WidgetFileActionMixin:
tab_label.set_label(view.get_end_of_path())
self.set_bottom_labels(view)
def create_file(self):
fname_field = self.builder.get_object("context_menu_fname")
file_name = fname_field.get_text().strip()
type = self.builder.get_object("context_menu_type_toggle").get_state()
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
target = f"{view.get_current_directory()}"
if file_name:
file_name = "file://" + target + "/" + file_name
if type == True: # Create File
self.handle_file([file_name], "create_file")
else: # Create Folder
self.handle_file([file_name], "create_dir")
fname_field.set_text("")
def get_current_state(self):
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
@ -81,15 +59,7 @@ class WidgetFileActionMixin:
store = iconview.get_model()
return wid, tid, view, iconview, store
def execute_files(self, in_terminal=False):
wid, tid, view, iconview, store = self.get_current_state()
paths = self.format_to_uris(store, wid, tid, self.selected_files, True)
current_dir = view.get_current_directory()
command = None
for path in paths:
command = f"sh -c '{path}'" if not in_terminal else f"{view.terminal_app} -e '{path}'"
self.execute(command, current_dir)
def open_files(self):
@ -107,6 +77,26 @@ class WidgetFileActionMixin:
app_info.launch([file], None)
def execute_files(self, in_terminal=False):
wid, tid, view, iconview, store = self.get_current_state()
paths = self.format_to_uris(store, wid, tid, self.selected_files, True)
current_dir = view.get_current_directory()
command = None
for path in paths:
command = f"sh -c '{path}'" if not in_terminal else f"{view.terminal_app} -e '{path}'"
view.execute(command.split(), current_dir)
##################################################################################################
# NOTE: Everything below is trash and needs yet another rewrite because it doesn't work properly.
##################################################################################################
def rename_files(self):
rename_label = self.builder.get_object("file_to_rename_label")
rename_input = self.builder.get_object("new_rename_fname")
@ -143,21 +133,6 @@ class WidgetFileActionMixin:
self.hide_new_file_menu()
self.to_rename_files.clear()
def archive_files(self, archiver_dialogue):
wid, tid, view, iconview, store = self.get_current_state()
paths = self.format_to_uris(store, wid, tid, self.selected_files)
save_target = archiver_dialogue.get_filename();
start_itr, end_itr = self.arc_command_buffer.get_bounds()
command = self.arc_command_buffer.get_text(start_itr, end_itr, False)
command = command.replace("%o", save_target)
command = command.replace("%N", ' '.join(paths))
final_command = f"terminator -e '{command}'"
self.execute(final_command, start_dir=None, use_os_system=True)
def cut_files(self):
wid, tid, view, iconview, store = self.get_current_state()
uris = self.format_to_uris(store, wid, tid, self.selected_files)
@ -180,11 +155,18 @@ class WidgetFileActionMixin:
elif len(self.to_cut_files) > 0:
self.handle_file(self.to_cut_files, "move", target)
def archive_files(self, archiver_dialogue):
wid, tid, view, iconview, store = self.get_current_state()
paths = self.format_to_uris(store, wid, tid, self.selected_files)
save_target = archiver_dialogue.get_filename();
start_itr, end_itr = self.arc_command_buffer.get_bounds()
command = self.arc_command_buffer.get_text(start_itr, end_itr, False)
def move_files(self, files, target):
self.handle_file(files, "move", target)
command = command.replace("%o", save_target)
command = command.replace("%N", ' '.join(paths))
final_command = f"terminator -e '{command}'"
self.execute(final_command, start_dir=None, use_os_system=True)
def delete_files(self):
wid, tid, view, iconview, store = self.get_current_state()
@ -199,6 +181,27 @@ class WidgetFileActionMixin:
def create_file(self):
fname_field = self.builder.get_object("context_menu_fname")
file_name = fname_field.get_text().strip()
type = self.builder.get_object("context_menu_type_toggle").get_state()
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
target = f"{view.get_current_directory()}"
if file_name:
file_name = "file://" + target + "/" + file_name
if type == True: # Create File
self.handle_file([file_name], "create_file")
else: # Create Folder
self.handle_file([file_name], "create_dir")
fname_field.set_text("")
def move_files(self, files, target):
self.handle_file(files, "move", target)
# NOTE: While not fully race condition proof, we happy path it first
# and then handle anything after as a conflict for renaming before
# copy, move, or edit. This is literally the oppopsite of what Gtk says to do.

View File

@ -57,10 +57,10 @@ class WindowMixin(TabMixin):
dir = view.get_current_directory()
for _notebook in self.notebooks:
ctx = _notebook.get_style_context()
ctx = _notebook.get_style_context()
ctx.remove_class("notebook-selected-focus")
ctx = notebook.get_style_context()
ctx = notebook.get_style_context()
ctx.add_class("notebook-selected-focus")
self.window.set_title("SolarFM ~ " + dir)