Project structure cleanup; setting import changes
@ -8,7 +8,7 @@ SolarFM is a Gtk+ Python file manager.
|
||||
|
||||
<h6>Install Setup</h6>
|
||||
```
|
||||
sudo apt-get install python3 wget ffmpegthumbnailer steamcmd
|
||||
sudo apt-get install python3.8 wget python3-setproctitle python3-gi ffmpegthumbnailer steamcmd
|
||||
```
|
||||
|
||||
# TODO
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
function main() {
|
||||
# GTK_DEBUG=interactive python3 ./PyFM.py
|
||||
python3 ./PyFM.py
|
||||
find . -name "__pycache__" -exec rm -rf $1 {} \;
|
||||
find . -name "*.pyc" -exec rm -rf $1 {} \;
|
||||
}
|
||||
main $@;
|
||||
main
|
@ -1,8 +1,8 @@
|
||||
Package: pytop64
|
||||
Package: solarfm64
|
||||
Version: 0.0-1
|
||||
Section: python
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Depends: ffmpegthumbnailer (>= 2.0.10-0.1)
|
||||
Depends: python3.8, wget, ffmpegthumbnailer, python3-setproctitle, python3-gi, steamcmd
|
||||
Maintainer: Maxim Stewart <1itdominator@gmail.com>
|
||||
Description: SolarFM is a Gtk + Python file manager.
|
||||
|
@ -1,12 +1,14 @@
|
||||
# Python imports
|
||||
import builtins
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from signal_classes.DBusControllerMixin import DBusControllerMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class Builtins(DBusControllerMixin):
|
||||
"""Docstring for __builtins__ extender"""
|
||||
|
||||
@ -15,8 +17,6 @@ class Builtins(DBusControllerMixin):
|
||||
# Where data may be any kind of data
|
||||
self._gui_events = []
|
||||
self._fm_events = []
|
||||
self.monitor_events = True
|
||||
self.keep_ipc_alive = True
|
||||
self.is_ipc_alive = False
|
||||
|
||||
# Makeshift fake "events" type system FIFO
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Python imports
|
||||
import os, inspect, time
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from utils import Settings
|
||||
@ -9,6 +9,8 @@ from signal_classes import Controller
|
||||
from __builtins__ import Builtins
|
||||
|
||||
|
||||
|
||||
|
||||
class Main(Builtins):
|
||||
def __init__(self, args, unknownargs):
|
||||
event_system.create_ipc_server()
|
||||
@ -44,6 +46,6 @@ class Main(Builtins):
|
||||
methods = inspect.getmembers(c, predicate=inspect.ismethod)
|
||||
handlers.update(methods)
|
||||
except Exception as e:
|
||||
pass
|
||||
print(repr(e))
|
||||
|
||||
settings.builder.connect_signals(handlers)
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
|
||||
# Python imports
|
||||
import argparse
|
||||
import argparse, faulthandler, traceback
|
||||
from setproctitle import setproctitle
|
||||
|
||||
import tracemalloc
|
||||
tracemalloc.start()
|
||||
|
||||
|
||||
# Gtk imports
|
||||
import gi, faulthandler, traceback
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
@ -20,6 +20,9 @@ from __init__ import Main
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# import web_pdb
|
||||
# web_pdb.set_trace()
|
||||
|
||||
setproctitle('solarfm')
|
||||
faulthandler.enable() # For better debug info
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -33,7 +36,5 @@ if __name__ == "__main__":
|
||||
Main(args, unknownargs)
|
||||
Gtk.main()
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
event_system.keep_ipc_alive = False
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
traceback.print_exc()
|
||||
quit()
|
||||
|
@ -10,7 +10,7 @@ from . import Window
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ class WindowController:
|
||||
|
||||
@threaded
|
||||
def fm_event_observer(self):
|
||||
while event_system.monitor_events:
|
||||
while True:
|
||||
time.sleep(event_sleep_time)
|
||||
event = event_system.consume_fm_event()
|
||||
if event:
|
||||
|
@ -21,13 +21,14 @@ class Path:
|
||||
self.load_directory()
|
||||
|
||||
def pop_from_path(self):
|
||||
self.path.pop()
|
||||
if len(self.path) > 1:
|
||||
self.path.pop()
|
||||
|
||||
if not self.go_past_home:
|
||||
if self.get_home() not in self.get_path():
|
||||
self.set_to_home()
|
||||
if not self.go_past_home:
|
||||
if self.get_home() not in self.get_path():
|
||||
self.set_to_home()
|
||||
|
||||
self.load_directory()
|
||||
self.load_directory()
|
||||
|
||||
def set_path(self, path):
|
||||
if path == self.get_path():
|
||||
|
@ -160,6 +160,7 @@ class View(Settings, FileHandler, Launcher, Icon, Path):
|
||||
images = self.hash_set(self.images),
|
||||
desktops = self.hash_set(self.desktop),
|
||||
ungrouped = self.hash_set(self.ungrouped)
|
||||
hidden = self.hash_set(self.hidden)
|
||||
|
||||
return {
|
||||
'path_head': self.get_path(),
|
||||
@ -169,7 +170,8 @@ class View(Settings, FileHandler, Launcher, Icon, Path):
|
||||
'videos': videos,
|
||||
'images': images,
|
||||
'desktops': desktops,
|
||||
'ungrouped': ungrouped
|
||||
'ungrouped': ungrouped,
|
||||
'hidden': hidden
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
|
||||
# Python imports
|
||||
import os, shutil, subprocess, threading
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class FileHandler:
|
||||
def create_file(self, nFile, type):
|
||||
@ -51,7 +57,7 @@ class FileHandler:
|
||||
def move_file(self, fFile, tFile):
|
||||
try:
|
||||
print(f"Moving: {fFile} --> {tFile}")
|
||||
if os.path.exists(fFile) and os.path.exists(tFile):
|
||||
if os.path.exists(fFile) and not os.path.exists(tFile):
|
||||
if not tFile.endswith("/"):
|
||||
tFile += "/"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# System import
|
||||
import os, subprocess, threading
|
||||
import os, threading, subprocess
|
||||
|
||||
|
||||
# Lib imports
|
||||
@ -8,6 +8,12 @@ import os, subprocess, threading
|
||||
# Apoplication imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
class Launcher:
|
||||
def open_file_locally(self, file):
|
||||
lowerName = file.lower()
|
||||
@ -35,11 +41,24 @@ class Launcher:
|
||||
else:
|
||||
command = ["xdg-open", file]
|
||||
|
||||
self.logger.debug(command)
|
||||
DEVNULL = open(os.devnull, 'w')
|
||||
subprocess.Popen(command, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL, close_fds=True)
|
||||
self.execute(command, use_shell=False)
|
||||
|
||||
|
||||
def execute(self, command, start_dir=os.getenv("HOME"), use_os_system=None, use_shell=True):
|
||||
self.logger.debug(command)
|
||||
if use_os_system:
|
||||
os.system(command)
|
||||
else:
|
||||
subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True)
|
||||
|
||||
def execute_and_return_thread_handler(self, command, start_dir=os.getenv("HOME"), use_shell=True):
|
||||
DEVNULL = open(os.devnull, 'w')
|
||||
return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL, close_fds=True)
|
||||
|
||||
@threaded
|
||||
def app_chooser_exec(self, app_info, uris):
|
||||
app_info.launch_uris_async(uris)
|
||||
|
||||
def remux_video(self, hash, file):
|
||||
remux_vid_pth = self.REMUX_FOLDER + "/" + hash + ".mp4"
|
||||
self.logger.debug(remux_vid_pth)
|
||||
|
@ -13,22 +13,23 @@ from os import path
|
||||
class Settings:
|
||||
logger = None
|
||||
|
||||
USR_SOLARFM = "/usr/share/solarfm"
|
||||
USER_HOME = path.expanduser('~')
|
||||
CONFIG_PATH = USER_HOME + "/.config/solarfm"
|
||||
CONFIG_FILE = CONFIG_PATH + "/settings.json"
|
||||
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
|
||||
CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
|
||||
HIDE_HIDDEN_FILES = True
|
||||
|
||||
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
||||
DEFAULT_ICONS = CONFIG_PATH + "/icons"
|
||||
DEFAULT_ICON = DEFAULT_ICONS + "/text.png"
|
||||
FFMPG_THUMBNLR = CONFIG_PATH + "/ffmpegthumbnailer" # Thumbnail generator binary
|
||||
REMUX_FOLDER = USER_HOME + "/.remuxs" # Remuxed files folder
|
||||
DEFAULT_ICONS = f"{CONFIG_PATH}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|
||||
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
|
||||
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
|
||||
|
||||
STEAM_BASE_URL = "https://steamcdn-a.akamaihd.net/steam/apps/"
|
||||
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", USER_HOME + "/.icons" ,]
|
||||
BASE_THUMBS_PTH = USER_HOME + "/.thumbnails" # Used for thumbnail generation
|
||||
ABS_THUMBS_PTH = BASE_THUMBS_PTH + "/normal" # Used for thumbnail generation
|
||||
STEAM_ICONS_PTH = BASE_THUMBS_PTH + "/steam_icons"
|
||||
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,]
|
||||
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
|
||||
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
|
||||
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
|
||||
CONTAINER_ICON_WH = [128, 128]
|
||||
VIDEO_ICON_WH = [128, 64]
|
||||
SYS_ICON_WH = [56, 56]
|
||||
@ -69,6 +70,7 @@ class Settings:
|
||||
pdf_app = settings["pdf_app"]
|
||||
text_app = settings["text_app"]
|
||||
file_manager_app = settings["file_manager_app"]
|
||||
terminal_app = settings["terminal_app"]
|
||||
remux_folder_max_disk_usage = settings["remux_folder_max_disk_usage"]
|
||||
|
||||
# Filters
|
||||
@ -81,14 +83,18 @@ class Settings:
|
||||
|
||||
|
||||
# Dir structure check
|
||||
if path.isdir(REMUX_FOLDER) == False:
|
||||
if not path.isdir(REMUX_FOLDER):
|
||||
os.mkdir(REMUX_FOLDER)
|
||||
|
||||
if path.isdir(BASE_THUMBS_PTH) == False:
|
||||
if not path.isdir(BASE_THUMBS_PTH):
|
||||
os.mkdir(BASE_THUMBS_PTH)
|
||||
|
||||
if path.isdir(ABS_THUMBS_PTH) == False:
|
||||
if not path.isdir(ABS_THUMBS_PTH):
|
||||
os.mkdir(ABS_THUMBS_PTH)
|
||||
|
||||
if path.isdir(STEAM_ICONS_PTH) == False:
|
||||
if not path.isdir(STEAM_ICONS_PTH):
|
||||
os.mkdir(STEAM_ICONS_PTH)
|
||||
|
||||
if not os.path.exists(DEFAULT_ICONS):
|
||||
DEFAULT_ICONS = f"{USR_SOLARFM}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|
||||
|
@ -1,11 +1,10 @@
|
||||
# Python imports
|
||||
import sys, traceback, threading, subprocess, signal, inspect, os, time
|
||||
import sys, traceback, threading, signal, inspect, os, time
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gtk, GLib
|
||||
|
||||
# Application imports
|
||||
from .mixins import *
|
||||
@ -14,14 +13,16 @@ from . import ShowHideMixin, KeyboardSignalsMixin, Controller_Data
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, WidgetFileActionMixin, \
|
||||
PaneMixin, WindowMixin):
|
||||
|
||||
|
||||
class Controller(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin, \
|
||||
KeyboardSignalsMixin, Controller_Data):
|
||||
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()
|
||||
|
||||
@ -44,15 +45,15 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, WidgetFil
|
||||
|
||||
|
||||
def tear_down(self, widget=None, eve=None):
|
||||
event_system.monitor_events = False
|
||||
event_system.send_ipc_message("close server")
|
||||
self.window_controller.save_state()
|
||||
time.sleep(event_sleep_time)
|
||||
Gtk.main_quit()
|
||||
|
||||
|
||||
@threaded
|
||||
def gui_event_observer(self):
|
||||
while event_system.monitor_events:
|
||||
while True:
|
||||
time.sleep(event_sleep_time)
|
||||
event = event_system.consume_gui_event()
|
||||
if event:
|
||||
@ -64,7 +65,7 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, WidgetFil
|
||||
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()
|
||||
@ -82,32 +83,59 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, WidgetFil
|
||||
time.sleep(seconds)
|
||||
GLib.idle_add(self.message_widget.popdown)
|
||||
|
||||
def save_debug_alerts(self, widget=None, eve=None):
|
||||
start_itr, end_itr = self.message_buffer.get_bounds()
|
||||
save_location_prompt = Gtk.FileChooserDialog("Choose Save Folder", self.window, \
|
||||
action = Gtk.FileChooserAction.SAVE, \
|
||||
buttons = (Gtk.STOCK_CANCEL, \
|
||||
Gtk.ResponseType.CANCEL, \
|
||||
Gtk.STOCK_SAVE, \
|
||||
Gtk.ResponseType.OK))
|
||||
|
||||
text = self.message_buffer.get_text(start_itr, end_itr, False)
|
||||
resp = save_location_prompt.run()
|
||||
if (resp == Gtk.ResponseType.CANCEL) or (resp == Gtk.ResponseType.DELETE_EVENT):
|
||||
pass
|
||||
elif resp == Gtk.ResponseType.OK:
|
||||
target = save_location_prompt.get_filename();
|
||||
with open(target, "w") as f:
|
||||
f.write(text)
|
||||
|
||||
save_location_prompt.destroy()
|
||||
|
||||
|
||||
def do_edit_files(self, widget=None, eve=None):
|
||||
self.to_rename_files = self.selected_files
|
||||
self.rename_files()
|
||||
|
||||
def execute(self, option, start_dir=os.getenv("HOME")):
|
||||
DEVNULL = open(os.devnull, 'w')
|
||||
command = option.split()
|
||||
subprocess.Popen(command, cwd=start_dir, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL)
|
||||
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 do_action_from_menu_controls(self, imagemenuitem, eventbutton):
|
||||
action = imagemenuitem.get_name()
|
||||
def clear_children(self, widget):
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
|
||||
def get_current_state(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
return wid, tid, view, iconview, store
|
||||
|
||||
def do_action_from_menu_controls(self, widget, eventbutton):
|
||||
action = widget.get_name()
|
||||
self.ctrlDown = True
|
||||
self.hide_context_menu()
|
||||
self.hide_new_file_menu()
|
||||
self.hide_edit_file_menu()
|
||||
|
||||
if action == "create":
|
||||
self.create_file()
|
||||
self.hide_new_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 == "rename":
|
||||
self.to_rename_files = self.selected_files
|
||||
self.rename_files()
|
||||
if action == "cut":
|
||||
self.to_copy_files.clear()
|
||||
@ -117,34 +145,22 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, WidgetFil
|
||||
self.copy_files()
|
||||
if action == "paste":
|
||||
self.paste_files()
|
||||
if action == "archive":
|
||||
self.show_archiver_dialogue()
|
||||
if action == "delete":
|
||||
# self.delete_files()
|
||||
self.trash_files()
|
||||
self.delete_files()
|
||||
if action == "trash":
|
||||
self.trash_files()
|
||||
if action == "go_to_trash":
|
||||
self.builder.get_object("path_entry").set_text(self.trash_files_path)
|
||||
if action == "restore_from_trash":
|
||||
self.restore_trash_files()
|
||||
if action == "empty_trash":
|
||||
self.empty_trash()
|
||||
|
||||
|
||||
if action == "create":
|
||||
self.create_files()
|
||||
self.hide_new_file_menu()
|
||||
|
||||
self.ctrlDown = False
|
||||
|
||||
|
||||
|
||||
|
||||
def generate_windows(self, data = None):
|
||||
if data:
|
||||
for j, value in enumerate(data):
|
||||
i = j + 1
|
||||
isHidden = True if value[0]["window"]["isHidden"] == "True" else False
|
||||
object = self.builder.get_object(f"tggl_notebook_{i}")
|
||||
views = value[0]["window"]["views"]
|
||||
self.window_controller.create_window()
|
||||
object.set_active(True)
|
||||
|
||||
for view in views:
|
||||
self.create_new_view_notebook(None, i, view)
|
||||
|
||||
if isHidden:
|
||||
self.toggle_notebook_pane(object)
|
||||
else:
|
||||
for j in range(0, 4):
|
||||
i = j + 1
|
||||
self.window_controller.create_window()
|
||||
self.create_new_view_notebook(None, i, None)
|
||||
|
@ -1,9 +1,13 @@
|
||||
# Python imports
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from shellfm import WindowController
|
||||
from trasher.xdgtrash import XDGTrash
|
||||
|
||||
|
||||
|
||||
|
||||
class Controller_Data:
|
||||
@ -11,28 +15,67 @@ class Controller_Data:
|
||||
return callable(getattr(o, name, None))
|
||||
|
||||
def setup_controller_data(self):
|
||||
self.window_controller = WindowController()
|
||||
self.state = self.window_controller.load_state()
|
||||
self.window_controller = WindowController()
|
||||
self.trashman = XDGTrash()
|
||||
self.trashman.regenerate()
|
||||
|
||||
self.builder = self.settings.builder
|
||||
self.logger = self.settings.logger
|
||||
self.state = self.window_controller.load_state()
|
||||
self.builder = self.settings.builder
|
||||
self.logger = self.settings.logger
|
||||
|
||||
self.window = self.settings.getMainWindow()
|
||||
self.window1 = self.builder.get_object("window_1")
|
||||
self.window2 = self.builder.get_object("window_2")
|
||||
self.window3 = self.builder.get_object("window_3")
|
||||
self.window4 = self.builder.get_object("window_4")
|
||||
self.message_widget = self.builder.get_object("message_widget")
|
||||
self.message_view = self.builder.get_object("message_view")
|
||||
self.message_buffer = self.builder.get_object("message_buffer")
|
||||
self.window = self.settings.getMainWindow()
|
||||
self.window1 = self.builder.get_object("window_1")
|
||||
self.window2 = self.builder.get_object("window_2")
|
||||
self.window3 = self.builder.get_object("window_3")
|
||||
self.window4 = self.builder.get_object("window_4")
|
||||
self.message_widget = self.builder.get_object("message_widget")
|
||||
self.message_view = self.builder.get_object("message_view")
|
||||
self.message_buffer = self.builder.get_object("message_buffer")
|
||||
self.arc_command_buffer = self.builder.get_object("arc_command_buffer")
|
||||
|
||||
self.warning_alert = self.builder.get_object("warning_alert")
|
||||
self.edit_file_menu = self.builder.get_object("edit_file_menu")
|
||||
self.file_exists_dialog = self.builder.get_object("file_exists_dialog")
|
||||
self.exists_file_label = self.builder.get_object("exists_file_label")
|
||||
self.exists_file_field = self.builder.get_object("exists_file_field")
|
||||
self.path_menu = self.builder.get_object("path_menu")
|
||||
self.exists_file_rename_bttn = self.builder.get_object("exists_file_rename_bttn")
|
||||
|
||||
self.bottom_size_label = self.builder.get_object("bottom_size_label")
|
||||
self.bottom_file_count_label = self.builder.get_object("bottom_file_count_label")
|
||||
self.bottom_path_label = self.builder.get_object("bottom_path_label")
|
||||
|
||||
self.trash_files_path = GLib.get_user_data_dir() + "/Trash/files"
|
||||
self.trash_info_path = GLib.get_user_data_dir() + "/Trash/info"
|
||||
|
||||
# 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_rename_files = []
|
||||
self.to_copy_files = []
|
||||
self.to_cut_files = []
|
||||
|
||||
@ -42,6 +85,11 @@ class Controller_Data:
|
||||
self.is_pane3_hidden = False
|
||||
self.is_pane4_hidden = False
|
||||
|
||||
self.is_searching = False
|
||||
self.search_iconview = None
|
||||
self.search_view = None
|
||||
|
||||
|
||||
self.skip_edit = False
|
||||
self.cancel_edit = False
|
||||
self.ctrlDown = False
|
||||
|
@ -2,24 +2,26 @@
|
||||
import threading, socket, time
|
||||
from multiprocessing.connection import Listener, Client
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
class DBusControllerMixin:
|
||||
|
||||
@threaded
|
||||
def create_ipc_server(self):
|
||||
listener = Listener(('127.0.0.1', 4848), authkey=b'solarfm-ipc')
|
||||
self.is_ipc_alive = True
|
||||
while event_system.keep_ipc_alive:
|
||||
while True:
|
||||
conn = listener.accept()
|
||||
start_time = time.time()
|
||||
|
||||
@ -43,7 +45,6 @@ class DBusControllerMixin:
|
||||
break
|
||||
if msg == 'close server':
|
||||
conn.close()
|
||||
event_system.keep_ipc_alive = False
|
||||
break
|
||||
|
||||
# NOTE: Not perfect but insures we don't lockup the connection for too long.
|
||||
@ -56,7 +57,7 @@ class DBusControllerMixin:
|
||||
|
||||
def send_ipc_message(self, message="Empty Data..."):
|
||||
try:
|
||||
conn = Client(('127.0.0.1', 4848), authkey=b'solar-ipc')
|
||||
conn = Client(('127.0.0.1', 4848), authkey=b'solarfm-ipc')
|
||||
conn.send(message)
|
||||
conn.send('close connection')
|
||||
except Exception as e:
|
||||
|
@ -1,16 +1,25 @@
|
||||
# Python imports
|
||||
import re
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk, Gdk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
valid_keyvalue_pat = re.compile(r"[a-z0-9A-Z-_\[\]\(\)\| ]")
|
||||
|
||||
|
||||
class KeyboardSignalsMixin:
|
||||
def unset_keys_and_data(self, widget=None, eve=None):
|
||||
self.ctrlDown = False
|
||||
self.shiftDown = False
|
||||
self.altDown = False
|
||||
self.is_searching = False
|
||||
|
||||
def global_key_press_controller(self, eve, user_data):
|
||||
keyname = Gdk.keyval_name(user_data.keyval).lower()
|
||||
if "control" in keyname or "alt" in keyname or "shift" in keyname:
|
||||
@ -36,6 +45,31 @@ class KeyboardSignalsMixin:
|
||||
if "alt" in keyname:
|
||||
self.altDown = False
|
||||
|
||||
|
||||
if self.ctrlDown and self.shiftDown and keyname == "t":
|
||||
self.trash_files()
|
||||
|
||||
|
||||
if re.fullmatch(valid_keyvalue_pat, keyname):
|
||||
if not self.is_searching and not self.ctrlDown \
|
||||
and not self.shiftDown and not self.altDown:
|
||||
focused_obj = self.window.get_focus()
|
||||
if isinstance(focused_obj, Gtk.IconView):
|
||||
self.is_searching = True
|
||||
wid, tid, self.search_view, self.search_iconview, store = self.get_current_state()
|
||||
self.popup_search_files(wid, keyname)
|
||||
return
|
||||
|
||||
|
||||
if (self.ctrlDown and keyname in ["1", "kp_1"]):
|
||||
self.builder.get_object("tggl_notebook_1").released()
|
||||
if (self.ctrlDown and keyname in ["2", "kp_2"]):
|
||||
self.builder.get_object("tggl_notebook_2").released()
|
||||
if (self.ctrlDown and keyname in ["3", "kp_3"]):
|
||||
self.builder.get_object("tggl_notebook_3").released()
|
||||
if (self.ctrlDown and keyname in ["4", "kp_4"]):
|
||||
self.builder.get_object("tggl_notebook_4").released()
|
||||
|
||||
if self.ctrlDown and keyname == "q":
|
||||
self.tear_down()
|
||||
if (self.ctrlDown and keyname == "slash") or keyname == "home":
|
||||
@ -67,12 +101,20 @@ class KeyboardSignalsMixin:
|
||||
if self.ctrlDown and keyname == "n":
|
||||
self.show_new_file_menu()
|
||||
|
||||
|
||||
|
||||
if keyname in ["alt_l", "alt_r"]:
|
||||
top_main_menubar = self.builder.get_object("top_main_menubar")
|
||||
if top_main_menubar.is_visible():
|
||||
top_main_menubar.hide()
|
||||
else:
|
||||
top_main_menubar.show()
|
||||
if keyname == "delete":
|
||||
self.trash_files()
|
||||
self.delete_files()
|
||||
if keyname == "f2":
|
||||
self.do_edit_files()
|
||||
self.rename_files()
|
||||
if keyname == "f4":
|
||||
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)
|
||||
|
@ -3,7 +3,8 @@
|
||||
# Gtk imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk, Gdk, Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
@ -12,23 +13,77 @@ class ShowHideMixin:
|
||||
def show_messages_popup(self, type, text, seconds=None):
|
||||
self.message_widget.popup()
|
||||
|
||||
def stop_file_searching(self, widget=None, eve=None):
|
||||
self.is_searching = False
|
||||
|
||||
|
||||
def show_exists_page(self, widget=None, eve=None):
|
||||
response = self.file_exists_dialog.run()
|
||||
self.file_exists_dialog.hide()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
return "rename"
|
||||
if response == Gtk.ResponseType.ACCEPT:
|
||||
return "rename_auto"
|
||||
if response == Gtk.ResponseType.CLOSE:
|
||||
return "rename_auto_all"
|
||||
if response == Gtk.ResponseType.YES:
|
||||
return "overwrite"
|
||||
if response == Gtk.ResponseType.APPLY:
|
||||
return "overwrite_all"
|
||||
if response == Gtk.ResponseType.NO:
|
||||
return "skip"
|
||||
if response == Gtk.ResponseType.REJECT:
|
||||
return "skip_all"
|
||||
|
||||
def hide_exists_page_rename(self, widget=None, eve=None):
|
||||
self.file_exists_dialog.response(Gtk.ResponseType.OK)
|
||||
|
||||
def hide_exists_page_auto_rename(self, widget=None, eve=None):
|
||||
self.file_exists_dialog.response(Gtk.ResponseType.ACCEPT)
|
||||
|
||||
def hide_exists_page_auto_rename_all(self, widget=None, eve=None):
|
||||
self.file_exists_dialog.response(Gtk.ResponseType.CLOSE)
|
||||
|
||||
|
||||
def show_about_page(self, widget=None, eve=None):
|
||||
about_page = self.builder.get_object("about_page")
|
||||
response = about_page.run()
|
||||
if response == -4:
|
||||
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
|
||||
self.hide_about_page()
|
||||
|
||||
def hide_about_page(self, widget=None, eve=None):
|
||||
about_page = self.builder.get_object("about_page").hide()
|
||||
self.builder.get_object("about_page").hide()
|
||||
|
||||
|
||||
def show_archiver_dialogue(self, widget=None, eve=None):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
archiver_dialogue = self.builder.get_object("archiver_dialogue")
|
||||
archiver_dialogue.set_action(Gtk.FileChooserAction.SAVE)
|
||||
archiver_dialogue.set_current_folder(view.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")
|
||||
response = appchooser_menu.run()
|
||||
|
||||
resp = appchooser_menu.run()
|
||||
if resp == Gtk.ResponseType.CANCEL:
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
self.hide_appchooser_menu()
|
||||
if resp == Gtk.ResponseType.OK:
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self.open_with_files(appchooser_widget)
|
||||
self.hide_appchooser_menu()
|
||||
|
||||
@ -36,7 +91,9 @@ class ShowHideMixin:
|
||||
self.builder.get_object("appchooser_menu").hide()
|
||||
|
||||
def run_appchooser_launch(self, widget=None, eve=None):
|
||||
self.builder.get_object("appchooser_select_btn").pressed()
|
||||
dialog = widget.get_parent().get_parent()
|
||||
dialog.response(Gtk.ResponseType.OK)
|
||||
|
||||
|
||||
def show_context_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("context_menu").run()
|
||||
@ -44,22 +101,34 @@ class ShowHideMixin:
|
||||
def hide_context_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("context_menu").hide()
|
||||
|
||||
|
||||
def show_new_file_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("new_file_menu").run()
|
||||
|
||||
def hide_new_file_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("new_file_menu").hide()
|
||||
|
||||
|
||||
def show_edit_file_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("edit_file_menu").run()
|
||||
if widget:
|
||||
widget.grab_focus()
|
||||
|
||||
response = self.edit_file_menu.run()
|
||||
if response == Gtk.ResponseType.CLOSE:
|
||||
self.skip_edit = True
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
self.cancel_edit = True
|
||||
|
||||
def hide_edit_file_menu(self, widget=None, eve=None):
|
||||
self.builder.get_object("edit_file_menu").hide()
|
||||
|
||||
def hide_edit_file_menu_enter_key(self, widget=None, eve=None):
|
||||
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):
|
||||
self.skip_edit = True
|
||||
self.builder.get_object("edit_file_menu").hide()
|
||||
self.edit_file_menu.response(Gtk.ResponseType.CLOSE)
|
||||
|
||||
def hide_edit_file_menu_cancel(self, widget=None, eve=None):
|
||||
self.cancel_edit = True
|
||||
self.builder.get_object("edit_file_menu").hide()
|
||||
self.edit_file_menu.response(Gtk.ResponseType.CANCEL)
|
||||
|
@ -1,7 +1,13 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
# # TODO: Should rewrite to try and support more windows more naturally
|
||||
|
||||
# TODO: Should rewrite to try and support more windows more naturally
|
||||
class PaneMixin:
|
||||
"""docstring for PaneMixin"""
|
||||
|
||||
|
@ -1,11 +1,18 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk, Gdk
|
||||
|
||||
# Application imports
|
||||
from . import WidgetMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class TabMixin(WidgetMixin):
|
||||
"""docstring for TabMixin"""
|
||||
|
||||
@ -46,6 +53,8 @@ class TabMixin(WidgetMixin):
|
||||
notebook.show_all()
|
||||
notebook.set_current_page(index)
|
||||
|
||||
ctx = notebook.get_style_context()
|
||||
ctx.add_class("notebook-unselected-focus")
|
||||
notebook.set_tab_reorderable(scroll, True)
|
||||
self.load_store(view, store)
|
||||
self.set_window_title()
|
||||
@ -106,15 +115,21 @@ class TabMixin(WidgetMixin):
|
||||
return notebook.get_children()[1].get_children()[0]
|
||||
|
||||
def refresh_tab(data=None):
|
||||
self, ids = data
|
||||
wid, tid = ids.split("|")
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
store, tab_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
view.load_directory()
|
||||
self.load_store(view, store)
|
||||
|
||||
def update_view(self, tab_label, view, store, wid, tid):
|
||||
self.load_store(view, store)
|
||||
self.set_path_text(wid, tid)
|
||||
|
||||
char_width = len(view.get_end_of_path())
|
||||
tab_label.set_width_chars(char_width)
|
||||
tab_label.set_label(view.get_end_of_path())
|
||||
self.set_window_title()
|
||||
self.set_file_watcher(view)
|
||||
self.window_controller.save_state()
|
||||
|
||||
def do_action_from_bar_controls(self, widget, eve=None):
|
||||
action = widget.get_name()
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
@ -134,26 +149,56 @@ class TabMixin(WidgetMixin):
|
||||
self.window_controller.save_state()
|
||||
return
|
||||
if action == "path_entry":
|
||||
path = widget.get_text()
|
||||
dir = view.get_current_directory() + "/"
|
||||
if path == dir :
|
||||
focused_obj = self.window.get_focus()
|
||||
dir = f"{view.get_current_directory()}/"
|
||||
path = widget.get_text()
|
||||
|
||||
if isinstance(focused_obj, Gtk.Entry):
|
||||
button_box = self.path_menu.get_children()[0].get_children()[0].get_children()[0]
|
||||
query = widget.get_text().replace(dir, "")
|
||||
files = view.files + view.hidden
|
||||
|
||||
self.clear_children(button_box)
|
||||
show_path_menu = False
|
||||
for file in files:
|
||||
if os.path.isdir(f"{dir}{file}"):
|
||||
if query.lower() in file.lower():
|
||||
button = Gtk.Button(label=file)
|
||||
button.show()
|
||||
button.connect("clicked", self.set_path_entry)
|
||||
button_box.add(button)
|
||||
show_path_menu = True
|
||||
|
||||
if not show_path_menu:
|
||||
self.path_menu.popdown()
|
||||
else:
|
||||
self.path_menu.popup()
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
|
||||
if path.endswith(".") or path == dir:
|
||||
return
|
||||
|
||||
traversed = view.set_path(path)
|
||||
if not traversed:
|
||||
return
|
||||
|
||||
self.update_view(tab_label, view, store, wid, tid)
|
||||
|
||||
self.load_store(view, store)
|
||||
self.set_path_text(wid, tid)
|
||||
|
||||
char_width = len(view.get_end_of_path())
|
||||
tab_label.set_width_chars(char_width)
|
||||
tab_label.set_label(view.get_end_of_path())
|
||||
self.set_window_title()
|
||||
self.set_file_watcher(view)
|
||||
self.window_controller.save_state()
|
||||
try:
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def set_path_entry(self, button=None, eve=None):
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
path = f"{view.get_current_directory()}/{button.get_label()}"
|
||||
path_entry = self.builder.get_object("path_entry")
|
||||
path_entry.set_text(path)
|
||||
path_entry.grab_focus_without_selecting()
|
||||
path_entry.set_position(-1)
|
||||
self.path_menu.popdown()
|
||||
|
||||
def keyboard_close_tab(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
|
@ -2,13 +2,38 @@
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
from gi.repository import GObject, Gio
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, GObject, Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class WidgetFileActionMixin:
|
||||
def sizeof_fmt(self, num, suffix="B"):
|
||||
for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f} {unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f} Yi{suffix}"
|
||||
|
||||
def get_dir_size(self, sdir):
|
||||
"""Get the size of a directory. Based on code found online."""
|
||||
size = os.path.getsize(sdir)
|
||||
|
||||
for item in os.listdir(sdir):
|
||||
item = os.path.join(sdir, item)
|
||||
|
||||
if os.path.isfile(item):
|
||||
size = size + os.path.getsize(item)
|
||||
elif os.path.isdir(item):
|
||||
size = size + self.get_dir_size(item)
|
||||
|
||||
return size
|
||||
|
||||
|
||||
def set_file_watcher(self, view):
|
||||
if view.get_dir_watcher():
|
||||
watcher = view.get_dir_watcher()
|
||||
@ -16,10 +41,15 @@ class WidgetFileActionMixin:
|
||||
if debug:
|
||||
print(f"Watcher Is Cancelled: {watcher.is_cancelled()}")
|
||||
|
||||
dir_watcher = Gio.File.new_for_path(view.get_current_directory()) \
|
||||
.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES,
|
||||
Gio.Cancellable()
|
||||
)
|
||||
cur_dir = view.get_current_directory()
|
||||
# Temp updating too much with current events we are checking for.
|
||||
# Seems to cause invalid iter errors in WidbetMixin > update_store
|
||||
if cur_dir == "/tmp":
|
||||
watcher = None
|
||||
return
|
||||
|
||||
dir_watcher = Gio.File.new_for_path(cur_dir) \
|
||||
.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, Gio.Cancellable())
|
||||
|
||||
wid = view.get_wid()
|
||||
tid = view.get_tab_id()
|
||||
@ -27,11 +57,12 @@ class WidgetFileActionMixin:
|
||||
view.set_dir_watcher(dir_watcher)
|
||||
|
||||
def dir_watch_updates(self, file_monitor, file, other_file=None, eve_type=None, data=None):
|
||||
if eve_type == Gio.FileMonitorEvent.CREATED or \
|
||||
eve_type == Gio.FileMonitorEvent.DELETED or \
|
||||
eve_type == Gio.FileMonitorEvent.RENAMED or \
|
||||
eve_type == Gio.FileMonitorEvent.MOVED_IN or \
|
||||
eve_type == Gio.FileMonitorEvent.MOVED_OUT:
|
||||
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
|
||||
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
|
||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||
if debug:
|
||||
print(eve_type)
|
||||
|
||||
wid, tid = data[0].split("|")
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
@ -46,104 +77,100 @@ class WidgetFileActionMixin:
|
||||
|
||||
|
||||
|
||||
def popup_search_files(self, wid, keyname):
|
||||
entry = self.builder.get_object(f"win{wid}_search_field")
|
||||
self.builder.get_object(f"win{wid}_search").popup()
|
||||
entry.set_text(keyname)
|
||||
entry.grab_focus_without_selecting()
|
||||
entry.set_position(-1)
|
||||
|
||||
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()
|
||||
def do_file_search(self, widget, eve=None):
|
||||
query = widget.get_text()
|
||||
self.search_iconview.unselect_all()
|
||||
for i, file in enumerate(self.search_view.files):
|
||||
if query and query in file.lower():
|
||||
path = Gtk.TreePath().new_from_indices([i])
|
||||
self.search_iconview.select_path(path)
|
||||
|
||||
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()}"
|
||||
items = self.search_iconview.get_selected_items()
|
||||
if len(items) == 1:
|
||||
self.search_iconview.scroll_to_path(items[0], True, 0.5, 0.5)
|
||||
|
||||
if file_name != "":
|
||||
file_name = "file://" + target + "/" + file_name
|
||||
if type == True: # Create File
|
||||
self.handle_file([file_name], "create_file", target)
|
||||
else: # Create Folder
|
||||
self.handle_file([file_name], "create_dir")
|
||||
|
||||
fname_field.set_text("")
|
||||
|
||||
def open_files(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
|
||||
for file in uris:
|
||||
view.open_file_locally(file)
|
||||
|
||||
def open_with_files(self, appchooser_widget):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files)
|
||||
|
||||
f = Gio.File.new_for_uri(uris[0])
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
app_info = appchooser_widget.get_app_info()
|
||||
app_info.launch([f], None)
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
|
||||
def edit_files(self):
|
||||
pass
|
||||
view.app_chooser_exec(app_info, uris)
|
||||
|
||||
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"exec '{path}'" if not in_terminal else f"{view.terminal_app} -e '{path}'"
|
||||
view.execute(command, start_dir=view.get_current_directory(), use_os_system=False)
|
||||
|
||||
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, 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", save_target)
|
||||
pre_command = pre_command.replace("%N", ' '.join(paths))
|
||||
command = f"{view.terminal_app} -e '{pre_command}'"
|
||||
|
||||
view.execute(command, start_dir=None, use_os_system=True)
|
||||
|
||||
def rename_files(self):
|
||||
rename_label = self.builder.get_object("file_to_rename_label")
|
||||
rename_input = self.builder.get_object("new_rename_fname")
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.to_rename_files)
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
|
||||
# The rename button hides the rename dialog box which lets the loop continue.
|
||||
# Weirdly, the show at the end is needed to flow through all the list properly
|
||||
# than auto chosing the first rename entry you do.
|
||||
for uri in uris:
|
||||
entry = uri.split("/")[-1]
|
||||
rename_label.set_label(entry)
|
||||
rename_input.set_text(entry)
|
||||
if self.skip_edit:
|
||||
self.skip_edit = False
|
||||
self.show_edit_file_menu()
|
||||
|
||||
# Yes...this step is required even with the above... =/
|
||||
self.show_edit_file_menu()
|
||||
|
||||
self.show_edit_file_menu(rename_input)
|
||||
if self.skip_edit:
|
||||
self.skip_edit = False
|
||||
continue
|
||||
if self.cancel_edit:
|
||||
self.cancel_edit = False
|
||||
break
|
||||
|
||||
rname_to = rename_input.get_text().strip()
|
||||
target = f"file://{view.get_current_directory()}/{rname_to}"
|
||||
self.handle_file([uri], "edit", target)
|
||||
|
||||
self.show_edit_file_menu()
|
||||
target = f"{view.get_current_directory()}/{rname_to}"
|
||||
self.handle_files([uri], "rename", target)
|
||||
|
||||
|
||||
self.skip_edit = False
|
||||
self.cancel_edit = False
|
||||
self.hide_new_file_menu()
|
||||
self.to_rename_files.clear()
|
||||
|
||||
|
||||
|
||||
self.hide_edit_file_menu()
|
||||
self.selected_files.clear()
|
||||
|
||||
def cut_files(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files)
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
self.to_cut_files = uris
|
||||
|
||||
def copy_files(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files)
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
self.to_copy_files = uris
|
||||
|
||||
def paste_files(self):
|
||||
@ -152,107 +179,209 @@ class WidgetFileActionMixin:
|
||||
target = f"{view.get_current_directory()}"
|
||||
|
||||
if len(self.to_copy_files) > 0:
|
||||
self.handle_file(self.to_copy_files, "copy", target)
|
||||
self.handle_files(self.to_copy_files, "copy", target)
|
||||
elif len(self.to_cut_files) > 0:
|
||||
self.handle_file(self.to_cut_files, "move", target)
|
||||
|
||||
|
||||
|
||||
|
||||
def move_file(self, view, files, target):
|
||||
self.handle_file([files], "move", target)
|
||||
self.handle_files(self.to_cut_files, "move", target)
|
||||
|
||||
def delete_files(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files)
|
||||
self.handle_file(uris, "delete")
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
response = None
|
||||
|
||||
self.warning_alert.format_secondary_text(f"Do you really want to delete the {len(uris)} file(s)?")
|
||||
for uri in uris:
|
||||
file = Gio.File.new_for_path(uri)
|
||||
|
||||
if not response:
|
||||
response = self.warning_alert.run()
|
||||
self.warning_alert.hide()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
type = file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE)
|
||||
|
||||
if type == Gio.FileType.DIRECTORY:
|
||||
view.delete_file( file.get_path() )
|
||||
else:
|
||||
file.delete(cancellable=None)
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
def trash_files(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
store = iconview.get_model()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files)
|
||||
self.handle_file(uris, "trash")
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
for uri in uris:
|
||||
self.trashman.trash(uri, False)
|
||||
|
||||
def restore_trash_files(self):
|
||||
wid, tid, view, iconview, store = self.get_current_state()
|
||||
uris = self.format_to_uris(store, wid, tid, self.selected_files, True)
|
||||
for uri in uris:
|
||||
self.trashman.restore(filename=uri.split("/")[-1], verbose=False)
|
||||
|
||||
def empty_trash(self):
|
||||
self.trashman.empty(verbose=False)
|
||||
|
||||
|
||||
def create_files(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()}"
|
||||
|
||||
# NOTE: Gio moves files by generating the target file path with name in it
|
||||
# We can't just give a base target directory and run with it.
|
||||
# Also, the display name is UTF-8 safe and meant for displaying in GUIs
|
||||
def handle_file(self, paths, action, _target_path=None):
|
||||
paths = self.preprocess_paths(paths)
|
||||
target = None
|
||||
if file_name:
|
||||
path = f"{target}/{file_name}"
|
||||
|
||||
if type == True: # Create File
|
||||
self.handle_files([path], "create_file")
|
||||
else: # Create Folder
|
||||
self.handle_files([path], "create_dir")
|
||||
|
||||
fname_field.set_text("")
|
||||
|
||||
def move_files(self, files, target):
|
||||
self.handle_files(files, "move", target)
|
||||
|
||||
# NOTE: Gtk recommends using fail flow than pre check existence which is more
|
||||
# race condition proof. They're right; but, they can't even delete
|
||||
# directories properly. So... f**k them. I'll do it my way.
|
||||
def handle_files(self, paths, action, _target_path=None):
|
||||
target = None
|
||||
_file = None
|
||||
response = None
|
||||
overwrite_all = False
|
||||
rename_auto_all = False
|
||||
|
||||
for path in paths:
|
||||
try:
|
||||
f = Gio.File.new_for_uri(path)
|
||||
|
||||
if action == "create_file":
|
||||
f.create(Gio.FileCreateFlags.NONE, cancellable=None)
|
||||
break
|
||||
if action == "create_dir":
|
||||
f.make_directory(cancellable=None)
|
||||
break
|
||||
|
||||
if "file://" in path:
|
||||
path = path.split("file://")[1]
|
||||
|
||||
file = Gio.File.new_for_path(path)
|
||||
if _target_path:
|
||||
if os.path.isdir(_target_path):
|
||||
info = f.query_info("standard::display-name", 0, cancellable=None)
|
||||
_target = f"file://{_target_path}/{info.get_display_name()}"
|
||||
target = Gio.File.new_for_uri(_target)
|
||||
info = file.query_info("standard::display-name", 0, cancellable=None)
|
||||
_target = f"{_target_path}/{info.get_display_name()}"
|
||||
_file = Gio.File.new_for_path(_target)
|
||||
else:
|
||||
target = Gio.File.new_for_uri(_target_path)
|
||||
|
||||
# See if dragging to same directory then break
|
||||
if action not in ["trash", "delete", "edit"] and \
|
||||
(f.get_parent().get_path() == target.get_parent().get_path()):
|
||||
break
|
||||
|
||||
type = f.query_file_type(flags=Gio.FileQueryInfoFlags.NONE, cancellable=None)
|
||||
if not type == Gio.FileType.DIRECTORY:
|
||||
if action == "delete":
|
||||
f.delete(cancellable=None)
|
||||
if action == "trash":
|
||||
f.trash(cancellable=None)
|
||||
if action == "copy":
|
||||
f.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
||||
if action == "move" or action == "edit":
|
||||
f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
||||
_file = Gio.File.new_for_path(_target_path)
|
||||
else:
|
||||
# Yes, life is hopeless and there is no God. Blame Gio for this sinful shitshow. =/
|
||||
_file = Gio.File.new_for_path(path)
|
||||
|
||||
|
||||
if _file.query_exists():
|
||||
if not overwrite_all and not rename_auto_all:
|
||||
self.exists_file_label.set_label(_file.get_basename())
|
||||
self.exists_file_field.set_text(_file.get_basename())
|
||||
response = self.show_exists_page()
|
||||
|
||||
if response == "overwrite_all":
|
||||
overwrite_all = True
|
||||
if response == "rename_auto_all":
|
||||
rename_auto_all = True
|
||||
|
||||
if response == "rename":
|
||||
base_path = _file.get_parent().get_path()
|
||||
new_name = self.exists_file_field.get_text().strip()
|
||||
rfPath = f"{base_path}/{new_name}"
|
||||
_file = Gio.File.new_for_path(rfPath)
|
||||
|
||||
if response == "rename_auto" or rename_auto_all:
|
||||
_file = self.rename_proc(_file)
|
||||
|
||||
if response == "overwrite" or overwrite_all:
|
||||
type = _file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE)
|
||||
|
||||
if type == Gio.FileType.DIRECTORY:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
view.delete_file( _file.get_path() )
|
||||
else:
|
||||
_file.delete(cancellable=None)
|
||||
|
||||
if response == "skip":
|
||||
continue
|
||||
if response == "skip_all":
|
||||
break
|
||||
|
||||
if _target_path:
|
||||
target = _file
|
||||
else:
|
||||
file = _file
|
||||
|
||||
|
||||
if action == "create_file":
|
||||
file.create(flags=Gio.FileCreateFlags.NONE, cancellable=None)
|
||||
continue
|
||||
if action == "create_dir":
|
||||
file.make_directory(cancellable=None)
|
||||
continue
|
||||
|
||||
|
||||
type = file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE)
|
||||
if type == Gio.FileType.DIRECTORY:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
fPath = f.get_path()
|
||||
tPath = None
|
||||
fPath = file.get_path()
|
||||
tPath = target.get_path()
|
||||
state = True
|
||||
|
||||
if target:
|
||||
tPath = target.get_path()
|
||||
|
||||
|
||||
if action == "delete":
|
||||
state = view.delete_file(fPath)
|
||||
if action == "trash":
|
||||
f.trash(cancellable=None)
|
||||
if action == "copy":
|
||||
state = view.copy_file(fPath, tPath)
|
||||
if action == "move" or action == "edit":
|
||||
tPath = target.get_parent().get_path()
|
||||
state = view.move_file(fPath, tPath)
|
||||
view.copy_file(fPath, tPath)
|
||||
if action == "move" or action == "rename":
|
||||
view.move_file(fPath, tPath)
|
||||
else:
|
||||
if action == "copy":
|
||||
file.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
||||
if action == "move" or action == "rename":
|
||||
file.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
||||
|
||||
if not state:
|
||||
raise GObject.GError("Failed to perform requested dir/file action!")
|
||||
except GObject.GError as e:
|
||||
raise OSError(e)
|
||||
|
||||
def preprocess_paths(self, paths):
|
||||
if not isinstance(paths, list):
|
||||
paths = [paths]
|
||||
# Convert items such as pathlib paths to strings
|
||||
paths = [path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths]
|
||||
return paths
|
||||
self.exists_file_rename_bttn.set_sensitive(False)
|
||||
|
||||
|
||||
|
||||
def rename_proc(self, gio_file):
|
||||
full_path = gio_file.get_path()
|
||||
base_path = gio_file.get_parent().get_path()
|
||||
file_name = os.path.splitext(gio_file.get_basename())[0]
|
||||
extension = os.path.splitext(full_path)[-1]
|
||||
target = Gio.File.new_for_path(full_path)
|
||||
start = "-copy"
|
||||
|
||||
if debug:
|
||||
print(f"Path: {full_path}")
|
||||
print(f"Base Path: {base_path}")
|
||||
print(f'Name: {file_name}')
|
||||
print(f"Extension: {extension}")
|
||||
|
||||
i = 2
|
||||
while target.query_exists():
|
||||
try:
|
||||
value = file_name[(file_name.find(start)+len(start)):]
|
||||
int(value)
|
||||
file_name = file_name.split(start)[0]
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
target = Gio.File.new_for_path(f"{base_path}/{file_name}-copy{i}{extension}")
|
||||
i += 1
|
||||
|
||||
return target
|
||||
|
||||
|
||||
def exists_rename_field_changed(self, widget):
|
||||
nfile_name = widget.get_text().strip()
|
||||
ofile_name = self.exists_file_label.get_label()
|
||||
|
||||
if nfile_name:
|
||||
if nfile_name == ofile_name:
|
||||
self.exists_file_rename_bttn.set_sensitive(False)
|
||||
else:
|
||||
self.exists_file_rename_bttn.set_sensitive(True)
|
||||
else:
|
||||
self.exists_file_rename_bttn.set_sensitive(False)
|
||||
|
@ -6,22 +6,19 @@ import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gio
|
||||
from gi.repository import GdkPixbuf
|
||||
from gi.repository import Gtk, Gdk, GLib, Gio, GdkPixbuf
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
class WidgetMixin:
|
||||
|
||||
def load_store(self, view, store, save_state=False):
|
||||
@ -41,12 +38,22 @@ class WidgetMixin:
|
||||
@threaded
|
||||
def create_icon(self, i, view, store, dir, file):
|
||||
icon = view.create_icon(dir, file)
|
||||
fpath = dir + "/" + file
|
||||
fpath = f"{dir}/{file}"
|
||||
GLib.idle_add(self.update_store, (i, store, icon, view, fpath,))
|
||||
|
||||
# NOTE: Might need to keep an eye on this throwing invalid iters when too
|
||||
# many updates are happening to a folder. Example: /tmp
|
||||
def update_store(self, item):
|
||||
i, store, icon, view, fpath = item
|
||||
itr = store.get_iter(i)
|
||||
itr = None
|
||||
|
||||
try:
|
||||
itr = store.get_iter(i)
|
||||
except Exception as e:
|
||||
print(":Invalid Itr detected: (Potential race condition...)")
|
||||
print(f"Index Requested: {i}")
|
||||
print(f"Store Size: {len(store)}")
|
||||
return
|
||||
|
||||
if not icon:
|
||||
icon = self.get_system_thumbnail(fpath, view.SYS_ICON_WH[0])
|
||||
@ -76,14 +83,13 @@ class WidgetMixin:
|
||||
return None
|
||||
except Exception as e:
|
||||
print("System icon generation issue:")
|
||||
print( repr(e) )
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
def create_tab_widget(self, view):
|
||||
tab = Gtk.Box()
|
||||
tab = Gtk.ButtonBox()
|
||||
label = Gtk.Label()
|
||||
tid = Gtk.Label()
|
||||
close = Gtk.Button()
|
||||
@ -91,10 +97,7 @@ class WidgetMixin:
|
||||
|
||||
label.set_label(f"{view.get_end_of_path()}")
|
||||
label.set_width_chars(len(view.get_end_of_path()))
|
||||
label.set_margin_start(5)
|
||||
label.set_margin_end(15)
|
||||
label.set_xalign(0.0)
|
||||
# label.set_ellipsize(2) #PANGO_ELLIPSIZE_MIDDLE
|
||||
tid.set_label(f"{view.id}")
|
||||
|
||||
close.add(icon)
|
||||
@ -126,8 +129,8 @@ class WidgetMixin:
|
||||
grid.set_spacing(12)
|
||||
grid.set_column_spacing(18)
|
||||
|
||||
grid.connect("button_release_event", self.grid_icon_single_left_click)
|
||||
grid.connect("item-activated", self.grid_icon_double_left_click)
|
||||
grid.connect("button_release_event", self.grid_icon_single_click)
|
||||
grid.connect("item-activated", self.grid_icon_double_click)
|
||||
grid.connect("selection-changed", self.grid_set_selected_items)
|
||||
grid.connect("drag-data-get", self.grid_on_drag_set)
|
||||
grid.connect("drag-data-received", self.grid_on_drag_data_received)
|
||||
@ -175,8 +178,8 @@ class WidgetMixin:
|
||||
grid.set_headers_visible(False)
|
||||
grid.set_enable_tree_lines(False)
|
||||
|
||||
grid.connect("button_release_event", self.grid_icon_single_left_click)
|
||||
grid.connect("row-activated", self.grid_icon_double_left_click)
|
||||
grid.connect("button_release_event", self.grid_icon_single_click)
|
||||
grid.connect("row-activated", self.grid_icon_double_click)
|
||||
grid.connect("drag-data-get", self.grid_on_drag_set)
|
||||
grid.connect("drag-data-received", self.grid_on_drag_data_received)
|
||||
grid.connect("drag-motion", self.grid_on_drag_motion)
|
||||
|
@ -3,18 +3,58 @@ import copy
|
||||
from os.path import isdir, isfile
|
||||
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
import gi
|
||||
from gi.repository import Gdk
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gdk, Gio
|
||||
|
||||
# Application imports
|
||||
from . import TabMixin
|
||||
from . import WidgetMixin
|
||||
from . import TabMixin, WidgetMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class WindowMixin(TabMixin):
|
||||
"""docstring for WindowMixin"""
|
||||
def generate_windows(self, data = None):
|
||||
if data:
|
||||
for j, value in enumerate(data):
|
||||
i = j + 1
|
||||
isHidden = True if value[0]["window"]["isHidden"] == "True" else False
|
||||
object = self.builder.get_object(f"tggl_notebook_{i}")
|
||||
views = value[0]["window"]["views"]
|
||||
self.window_controller.create_window()
|
||||
object.set_active(True)
|
||||
|
||||
for view in views:
|
||||
self.create_new_view_notebook(None, i, view)
|
||||
|
||||
if isHidden:
|
||||
self.toggle_notebook_pane(object)
|
||||
|
||||
try:
|
||||
if not self.is_pane4_hidden:
|
||||
icon_view = self.window4.get_children()[1].get_children()[0]
|
||||
icon_view.event(Gdk.Event().new(type=Gdk.EventType.BUTTON_RELEASE))
|
||||
elif not self.is_pane3_hidden:
|
||||
icon_view = self.window3.get_children()[1].get_children()[0]
|
||||
icon_view.event(Gdk.Event().new(type=Gdk.EventType.BUTTON_RELEASE))
|
||||
elif not self.is_pane2_hidden:
|
||||
icon_view = self.window2.get_children()[1].get_children()[0]
|
||||
icon_view.event(Gdk.Event().new(type=Gdk.EventType.BUTTON_RELEASE))
|
||||
elif not self.is_pane1_hidden:
|
||||
icon_view = self.window1.get_children()[1].get_children()[0]
|
||||
icon_view.event(Gdk.Event().new(type=Gdk.EventType.BUTTON_RELEASE))
|
||||
except Exception as e:
|
||||
print("\n: The saved session might be missing window data! :\nLocation: ~/.config/solarfm/session.json\nFix: Back it up and delete it to reset.\n")
|
||||
print(repr(e))
|
||||
else:
|
||||
for j in range(0, 4):
|
||||
i = j + 1
|
||||
self.window_controller.create_window()
|
||||
self.create_new_view_notebook(None, i, None)
|
||||
|
||||
|
||||
def get_fm_window(self, wid):
|
||||
return self.window_controller.get_window_by_nickname(f"window_{wid}")
|
||||
|
||||
@ -39,7 +79,43 @@ class WindowMixin(TabMixin):
|
||||
|
||||
|
||||
def set_bottom_labels(self, view):
|
||||
self.bottom_size_label.set_label("TBD")
|
||||
_wid, _tid, _view, iconview, store = self.get_current_state()
|
||||
selected_files = iconview.get_selected_items()
|
||||
current_directory = view.get_current_directory()
|
||||
path_file = Gio.File.new_for_path( current_directory)
|
||||
mount_file = path_file.query_filesystem_info(attributes="filesystem::*", cancellable=None)
|
||||
formatted_mount_free = self.sizeof_fmt( int(mount_file.get_attribute_as_string("filesystem::free")) )
|
||||
formatted_mount_size = self.sizeof_fmt( int(mount_file.get_attribute_as_string("filesystem::size")) )
|
||||
|
||||
if self.trash_files_path == current_directory:
|
||||
self.builder.get_object("restore_from_trash").show()
|
||||
self.builder.get_object("empty_trash").show()
|
||||
else:
|
||||
self.builder.get_object("restore_from_trash").hide()
|
||||
self.builder.get_object("empty_trash").hide()
|
||||
|
||||
# If something selected
|
||||
self.bottom_size_label.set_label(f"{formatted_mount_free} free / {formatted_mount_size}")
|
||||
self.bottom_path_label.set_label(view.get_current_directory())
|
||||
if len(selected_files) > 0:
|
||||
uris = self.format_to_uris(store, _wid, _tid, selected_files, True)
|
||||
combined_size = 0
|
||||
for uri in uris:
|
||||
file_info = Gio.File.new_for_path(uri).query_info(attributes="standard::size",
|
||||
flags=Gio.FileQueryInfoFlags.NONE,
|
||||
cancellable=None)
|
||||
file_size = file_info.get_size()
|
||||
combined_size += file_size
|
||||
|
||||
formatted_size = self.sizeof_fmt(combined_size)
|
||||
if view.hide_hidden:
|
||||
self.bottom_path_label.set_label(f" {len(uris)} / {view.get_files_count()} ({formatted_size})")
|
||||
else:
|
||||
self.bottom_path_label.set_label(f" {len(uris)} / {view.get_not_hidden_count()} ({formatted_size})")
|
||||
|
||||
return
|
||||
|
||||
# If nothing selected
|
||||
if view.hide_hidden:
|
||||
if view.get_hidden_count() > 0:
|
||||
self.bottom_file_count_label.set_label(f"{view.get_not_hidden_count()} visible ({view.get_hidden_count()} hidden)")
|
||||
@ -47,7 +123,7 @@ class WindowMixin(TabMixin):
|
||||
self.bottom_file_count_label.set_label(f"{view.get_files_count()} items")
|
||||
else:
|
||||
self.bottom_file_count_label.set_label(f"{view.get_files_count()} items")
|
||||
self.bottom_path_label.set_label(view.get_current_directory())
|
||||
|
||||
|
||||
|
||||
def set_window_title(self):
|
||||
@ -57,10 +133,12 @@ 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.add_class("notebook-unselected-focus")
|
||||
|
||||
ctx = notebook.get_style_context()
|
||||
ctx = notebook.get_style_context()
|
||||
ctx.remove_class("notebook-unselected-focus")
|
||||
ctx.add_class("notebook-selected-focus")
|
||||
|
||||
self.window.set_title("SolarFM ~ " + dir)
|
||||
@ -74,16 +152,18 @@ class WindowMixin(TabMixin):
|
||||
def grid_set_selected_items(self, iconview):
|
||||
self.selected_files = iconview.get_selected_items()
|
||||
|
||||
def grid_icon_single_left_click(self, iconview, eve):
|
||||
def grid_icon_single_click(self, iconview, eve):
|
||||
try:
|
||||
self.path_menu.popdown()
|
||||
wid, tid = iconview.get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
|
||||
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1: # l-click
|
||||
if self.single_click_open: # FIXME: need to find a way to pass the model index
|
||||
self.grid_icon_double_left_click(iconview)
|
||||
self.grid_icon_double_click(iconview)
|
||||
elif eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 3: # r-click
|
||||
self.show_context_menu()
|
||||
|
||||
@ -91,33 +171,29 @@ class WindowMixin(TabMixin):
|
||||
print(repr(e))
|
||||
self.display_message(self.error, f"{repr(e)}")
|
||||
|
||||
def grid_icon_double_left_click(self, iconview, item, data=None):
|
||||
def grid_icon_double_click(self, iconview, item, data=None):
|
||||
try:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
if self.ctrlDown and self.shiftDown:
|
||||
self.execute_files(in_terminal=True)
|
||||
return
|
||||
elif self.ctrlDown:
|
||||
self.execute_files()
|
||||
return
|
||||
|
||||
|
||||
wid, tid, view, _iconview, store = self.get_current_state()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
path_entry = self.builder.get_object(f"path_entry")
|
||||
tab_label = self.get_tab_label(notebook, iconview)
|
||||
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
model = iconview.get_model()
|
||||
|
||||
fileName = model[item][1]
|
||||
fileName = store[item][1]
|
||||
dir = view.get_current_directory()
|
||||
file = dir + "/" + fileName
|
||||
refresh = True
|
||||
file = f"{dir}/{fileName}"
|
||||
|
||||
if isdir(file):
|
||||
view.set_path(file)
|
||||
elif isfile(file):
|
||||
refresh = False
|
||||
view.open_file_locally(file)
|
||||
|
||||
if refresh == True:
|
||||
self.load_store(view, model)
|
||||
tab_label.set_label(view.get_end_of_path())
|
||||
path_entry.set_text(view.get_current_directory())
|
||||
self.set_file_watcher(view)
|
||||
self.set_bottom_labels(view)
|
||||
self.update_view(tab_label, view, store, wid, tid)
|
||||
else:
|
||||
self.open_files()
|
||||
except Exception as e:
|
||||
self.display_message(self.error, f"{repr(e)}")
|
||||
|
||||
@ -128,9 +204,13 @@ class WindowMixin(TabMixin):
|
||||
wid, tid = action.split("|")
|
||||
store = iconview.get_model()
|
||||
treePaths = iconview.get_selected_items()
|
||||
# NOTE: Need URIs as URI format for DnD to work. Will strip 'file://'
|
||||
# further down call chain when doing internal fm stuff.
|
||||
uris = self.format_to_uris(store, wid, tid, treePaths)
|
||||
uris_text = '\n'.join(uris)
|
||||
|
||||
data.set_uris(uris)
|
||||
data.set_text(uris_text, -1)
|
||||
|
||||
def grid_on_drag_motion(self, iconview, drag_context, x, y, data):
|
||||
wid, tid = iconview.get_name().split("|")
|
||||
@ -143,17 +223,13 @@ class WindowMixin(TabMixin):
|
||||
store, tab_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
|
||||
uris = data.get_uris()
|
||||
dest = view.get_current_directory()
|
||||
|
||||
uris = data.get_uris()
|
||||
dest = f"{view.get_current_directory()}"
|
||||
if len(uris) > 0:
|
||||
if debug:
|
||||
print(f"Target Move Path: {dest}")
|
||||
|
||||
for uri in uris:
|
||||
if debug:
|
||||
print(f"URI: {uri}")
|
||||
self.move_file(view, uri, dest)
|
||||
self.move_files(uris, dest)
|
||||
else:
|
||||
uris = data.get_text().split("\n")
|
||||
self.move_files(uris, dest)
|
||||
|
||||
def create_new_view_notebook(self, widget=None, wid=None, path=None):
|
||||
self.create_tab(wid, path)
|
||||
|
@ -1,18 +0,0 @@
|
||||
#!/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() {
|
||||
SCRIPTPATH="$( cd "$(dirname "")" >/dev/null 2>&1 ; pwd -P )"
|
||||
cd "${SCRIPTPATH}"
|
||||
echo "Working Dir: " $(pwd)
|
||||
|
||||
source "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/bin/activate"
|
||||
python ../solarfm "$@"
|
||||
}
|
||||
main "$@";
|
@ -1,5 +1,6 @@
|
||||
# Python imports
|
||||
import os
|
||||
from os import path
|
||||
|
||||
# Gtk imports
|
||||
import gi, cairo
|
||||
@ -16,30 +17,47 @@ from . import Logger
|
||||
|
||||
class Settings:
|
||||
def __init__(self):
|
||||
self.SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
self.gladefile = self.SCRIPT_PTH + "/../resources/Main_Window.glade"
|
||||
self.cssFile = self.SCRIPT_PTH + '/../resources/stylesheet.css'
|
||||
self.logger = Logger().get_logger()
|
||||
self.logger = Logger().get_logger()
|
||||
self.builder = gtk.Builder()
|
||||
|
||||
self.builder = gtk.Builder()
|
||||
self.builder.add_from_file(self.gladefile)
|
||||
self.mainWindow = None
|
||||
self.SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
self.USER_HOME = path.expanduser('~')
|
||||
self.CONFIG_PATH = f"{self.USER_HOME}/.config/solarfm"
|
||||
self.USR_SOLARFM = "/usr/share/solarfm"
|
||||
|
||||
self.cssFile = f"{self.CONFIG_PATH}/stylesheet.css"
|
||||
self.windows_glade = f"{self.CONFIG_PATH}/Main_Window.glade"
|
||||
self.DEFAULT_ICONS = f"{self.CONFIG_PATH}/icons"
|
||||
self.window_icon = f"{self.DEFAULT_ICONS}/solarfm.png"
|
||||
self.main_window = None
|
||||
|
||||
if not os.path.exists(self.windows_glade):
|
||||
self.windows_glade = f"{self.USR_SOLARFM}/Main_Window.glade"
|
||||
if not os.path.exists(self.cssFile):
|
||||
self.cssFile = f"{self.USR_SOLARFM}/stylesheet.css"
|
||||
if not os.path.exists(self.window_icon):
|
||||
self.window_icon = f"{self.USR_SOLARFM}/icons/solarfm.png"
|
||||
if not os.path.exists(self.DEFAULT_ICONS):
|
||||
self.DEFAULT_ICONS = f"{self.USR_SOLARFM}/icons"
|
||||
|
||||
self.builder.add_from_file(self.windows_glade)
|
||||
|
||||
|
||||
|
||||
def createWindow(self):
|
||||
# Get window and connect signals
|
||||
self.mainWindow = self.builder.get_object("Main_Window")
|
||||
self.main_window = self.builder.get_object("Main_Window")
|
||||
self.setWindowData()
|
||||
|
||||
def setWindowData(self):
|
||||
screen = self.mainWindow.get_screen()
|
||||
self.main_window.set_icon_from_file(self.window_icon)
|
||||
screen = self.main_window.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
|
||||
if visual != None and screen.is_composited():
|
||||
self.mainWindow.set_visual(visual)
|
||||
self.mainWindow.set_app_paintable(True)
|
||||
self.mainWindow.connect("draw", self.area_draw)
|
||||
self.main_window.set_visual(visual)
|
||||
self.main_window.set_app_paintable(True)
|
||||
self.main_window.connect("draw", self.area_draw)
|
||||
|
||||
# bind css file
|
||||
cssProvider = gtk.CssProvider()
|
||||
@ -54,7 +72,7 @@ class Settings:
|
||||
cr.paint()
|
||||
cr.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def getMainWindow(self): return self.mainWindow
|
||||
def getMainWindow(self): return self.main_window
|
||||
|
||||
|
||||
def getMonitorData(self):
|
||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 858 B After Width: | Height: | Size: 858 B |
Before Width: | Height: | Size: 850 B After Width: | Height: | Size: 850 B |
Before Width: | Height: | Size: 702 B After Width: | Height: | Size: 702 B |
Before Width: | Height: | Size: 925 B After Width: | Height: | Size: 925 B |
Before Width: | Height: | Size: 882 B After Width: | Height: | Size: 882 B |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 707 B After Width: | Height: | Size: 707 B |
Before Width: | Height: | Size: 798 B After Width: | Height: | Size: 798 B |
Before Width: | Height: | Size: 989 B After Width: | Height: | Size: 989 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -1,38 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# Gtk Imports
|
||||
import gi, faulthandler, signal
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('WebKit2', '4.0')
|
||||
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gdk as gdk
|
||||
from gi.repository import WebKit2 as webkit
|
||||
from gi.repository import GLib
|
||||
|
||||
# Python imports
|
||||
from utils import Settings, Events
|
||||
|
||||
gdk.threads_init()
|
||||
class Main:
|
||||
def __init__(self):
|
||||
faulthandler.enable()
|
||||
webkit.WebView() # Needed for glade file to load...
|
||||
|
||||
self.builder = gtk.Builder()
|
||||
self.settings = Settings()
|
||||
self.settings.attachBuilder(self.builder)
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
|
||||
self.builder.connect_signals(Events(self.settings))
|
||||
|
||||
window = self.settings.createWindow()
|
||||
window.fullscreen()
|
||||
window.show_all()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main = Main()
|
||||
gtk.main()
|
||||
except Exception as e:
|
||||
print(e)
|
@ -1,88 +0,0 @@
|
||||
viewport,
|
||||
treeview,
|
||||
treeview > header,
|
||||
notebook > stack,
|
||||
notebook > header {
|
||||
background-color: rgba(0, 0, 0, 0.24);
|
||||
}
|
||||
|
||||
|
||||
notebook > header {
|
||||
background-color: rgba(0, 0, 0, 0.24);
|
||||
border-color: rgba(0, 232, 255, 0.64);
|
||||
}
|
||||
|
||||
box,
|
||||
iconview {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
treeview,
|
||||
treeview.view {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
cell {
|
||||
margin: 0em;
|
||||
padding: 0em;
|
||||
/* float: left; */
|
||||
}
|
||||
|
||||
cell:focus {
|
||||
outline-style: solid;
|
||||
outline-color: rgba(0, 232, 255, 0.64);
|
||||
}
|
||||
|
||||
|
||||
/* Ivonview and children default color */
|
||||
.view {
|
||||
background-color: rgba(0, 0, 0, 0.22);
|
||||
color: #ebebeb;
|
||||
}
|
||||
|
||||
|
||||
/* Hover over color when not selected */
|
||||
.view:hover {
|
||||
box-shadow: inset 0 0 0 9999px alpha(rgba(0, 232, 255, 0.64), 0.54);
|
||||
}
|
||||
|
||||
/* Handles the icon selection hover and selected hover color. */
|
||||
.view:selected,
|
||||
.view:selected:hover {
|
||||
box-shadow: inset 0 0 0 9999px rgba(15, 134, 13, 0.49);
|
||||
}
|
||||
|
||||
/* Rubberband coloring */
|
||||
.rubberband,
|
||||
rubberband,
|
||||
flowbox rubberband,
|
||||
treeview.view rubberband,
|
||||
.content-view rubberband,
|
||||
.content-view .rubberband,
|
||||
XfdesktopIconView.view .rubberband {
|
||||
border: 1px solid #6c6c6c;
|
||||
background-color: rgba(21, 158, 167, 0.57);
|
||||
}
|
||||
|
||||
XfdesktopIconView.view:active {
|
||||
background-color: rgba(172, 102, 21, 1);
|
||||
}
|
||||
|
||||
|
||||
XfdesktopIconView.view {
|
||||
border-radius: 4px;
|
||||
background-color: transparent;
|
||||
color: white;
|
||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
||||
}
|
||||
|
||||
XfdesktopIconView.view:active {
|
||||
box-shadow: none;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
XfdesktopIconView.view .rubberband {
|
||||
border-radius: 0;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
import os, gi
|
||||
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GObject
|
||||
|
||||
|
||||
class Dragging:
|
||||
def __init__(self):
|
||||
# higher values make movement more performant
|
||||
# lower values make movement smoother
|
||||
self.SENSITIVITY = 1
|
||||
self.desktop = None
|
||||
self.EvMask = Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON1_MOTION_MASK
|
||||
self.offsetx = 0
|
||||
self.offsety = 0
|
||||
self.px = 0
|
||||
self.py = 0
|
||||
self.maxx = 0
|
||||
self.maxy = 0
|
||||
|
||||
def connectEvents(self, desktop, widget):
|
||||
self.desktop = desktop
|
||||
widget.set_events(self.EvMask)
|
||||
widget.connect("button_press_event", self.press_event)
|
||||
widget.connect("motion_notify_event", self.draggingEvent)
|
||||
widget.show()
|
||||
|
||||
def press_event(self, w, event):
|
||||
if event.button == 1:
|
||||
p = w.get_parent()
|
||||
# offset == distance of parent widget from edge of screen ...
|
||||
self.offsetx, self.offsety = p.get_window().get_position()
|
||||
# plus distance from pointer to edge of widget
|
||||
self.offsetx += event.x
|
||||
self.offsety += event.y
|
||||
# self.maxx, self.maxy both relative to the parent
|
||||
# note that we're rounding down now so that these max values don't get
|
||||
# rounded upward later and push the widget off the edge of its parent.
|
||||
self.maxx = self.RoundDownToMultiple(p.get_allocation().width - w.get_allocation().width, self.SENSITIVITY)
|
||||
self.maxy = self.RoundDownToMultiple(p.get_allocation().height - w.get_allocation().height, self.SENSITIVITY)
|
||||
|
||||
|
||||
def draggingEvent(self, widget, event):
|
||||
# x_root,x_root relative to screen
|
||||
# x,y relative to parent (fixed widget)
|
||||
# self.px,self.py stores previous values of x,y
|
||||
|
||||
# get starting values for x,y
|
||||
x = event.x_root - self.offsetx
|
||||
y = event.y_root - self.offsety
|
||||
# make sure the potential coordinates x,y:
|
||||
# 1) will not push any part of the widget outside of its parent container
|
||||
# 2) is a multiple of self.SENSITIVITY
|
||||
x = self.RoundToNearestMultiple(self.Max(self.Min(x, self.maxx), 0), self.SENSITIVITY)
|
||||
y = self.RoundToNearestMultiple(self.Max(self.Min(y, self.maxy), 0), self.SENSITIVITY)
|
||||
if x != self.px or y != self.py:
|
||||
self.px = x
|
||||
self.py = y
|
||||
self.desktop.move(widget, x, y)
|
||||
|
||||
def Min(self, a, b):
|
||||
if b < a:
|
||||
return b
|
||||
return a
|
||||
|
||||
def Max(self, a, b):
|
||||
if b > a:
|
||||
return b
|
||||
return a
|
||||
|
||||
def RoundDownToMultiple(self, i, m):
|
||||
return i/m*m
|
||||
|
||||
def RoundToNearestMultiple(self, i, m):
|
||||
if i % m > m / 2:
|
||||
return (i/m+1)*m
|
||||
return i/m*m
|
@ -1,72 +0,0 @@
|
||||
|
||||
# Gtk Imports
|
||||
|
||||
# Python imports
|
||||
from .Grid import Grid
|
||||
from .Dragging import Dragging
|
||||
|
||||
class Events:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
self.builder = self.settings.returnBuilder()
|
||||
self.desktop = self.builder.get_object("Desktop")
|
||||
self.webview = self.builder.get_object("webview")
|
||||
self.desktopPath = self.settings.returnDesktopPath()
|
||||
|
||||
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
|
||||
self.webview.load_uri(self.settings.returnWebHome())
|
||||
|
||||
# Add filter to allow only folders to be selected
|
||||
selectedDirDialog = self.builder.get_object("selectedDirDialog")
|
||||
filefilter = self.builder.get_object("Folders")
|
||||
selectedDirDialog.add_filter(filefilter)
|
||||
selectedDirDialog.set_filename(self.desktopPath)
|
||||
|
||||
self.grid = None
|
||||
self.setIconViewDir(selectedDirDialog)
|
||||
|
||||
def setIconViewDir(self, widget, data=None):
|
||||
newPath = widget.get_filename()
|
||||
Grid(self.desktop, self.settings, newPath)
|
||||
|
||||
|
||||
|
||||
# File control events
|
||||
def createFile(self):
|
||||
pass
|
||||
|
||||
def updateFile(self, widget, data=None):
|
||||
newName = widget.get_text().strip()
|
||||
if data and data.keyval == 65293: # Enter key event
|
||||
self.grid.updateFile(newName)
|
||||
elif data == None: # Save button 'event'
|
||||
self.grid.updateFile(newName)
|
||||
|
||||
def deleteFile(self, widget, data=None):
|
||||
self.grid.deleteFile()
|
||||
|
||||
def copyFile(self):
|
||||
pass
|
||||
|
||||
def cutFile(self):
|
||||
pass
|
||||
|
||||
def pasteFile(self):
|
||||
pass
|
||||
|
||||
# Webview events
|
||||
def showWebview(self, widget):
|
||||
self.builder.get_object("webViewer").popup()
|
||||
|
||||
def loadHome(self, widget):
|
||||
self.webview.load_uri(self.settings.returnWebHome())
|
||||
|
||||
def runSearchWebview(self, widget, data=None):
|
||||
if data.keyval == 65293:
|
||||
self.webview.load_uri(widget.get_text().strip())
|
||||
|
||||
def refreshPage(self, widget, data=None):
|
||||
self.webview.load_uri(self.webview.get_uri())
|
||||
|
||||
def setUrlBar(self, widget, data=None):
|
||||
self.builder.get_object("webviewSearch").set_text(widget.get_uri())
|
@ -1,93 +0,0 @@
|
||||
|
||||
import os, shutil, subprocess, threading
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
return wrapper
|
||||
|
||||
class FileHandler:
|
||||
def __init__(self):
|
||||
# 'Filters'
|
||||
self.office = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx' '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
|
||||
self.vids = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
|
||||
self.txt = ('.txt', '.text', '.sh', '.cfg', '.conf')
|
||||
self.music = ('.psf', '.mp3', '.ogg' , '.flac')
|
||||
self.images = ('.png', '.jpg', '.jpeg', '.gif')
|
||||
self.pdf = ('.pdf')
|
||||
|
||||
# Args
|
||||
self.MEDIAPLAYER = "mpv";
|
||||
self.IMGVIEWER = "mirage";
|
||||
self.MUSICPLAYER = "/opt/deadbeef/bin/deadbeef";
|
||||
self.OFFICEPROG = "libreoffice";
|
||||
self.TEXTVIEWER = "leafpad";
|
||||
self.PDFVIEWER = "evince";
|
||||
self.FILEMANAGER = "spacefm";
|
||||
self.MPLAYER_WH = " -xy 1600 -geometry 50%:50% ";
|
||||
self.MPV_WH = " -geometry 50%:50% ";
|
||||
|
||||
@threaded
|
||||
def openFile(self, file):
|
||||
print("Opening: " + file)
|
||||
if file.lower().endswith(self.vids):
|
||||
subprocess.Popen([self.MEDIAPLAYER, self.MPV_WH, file])
|
||||
elif file.lower().endswith(self.music):
|
||||
subprocess.Popen([self.MUSICPLAYER, file])
|
||||
elif file.lower().endswith(self.images):
|
||||
subprocess.Popen([self.IMGVIEWER, file])
|
||||
elif file.lower().endswith(self.txt):
|
||||
subprocess.Popen([self.TEXTVIEWER, file])
|
||||
elif file.lower().endswith(self.pdf):
|
||||
subprocess.Popen([self.PDFVIEWER, file])
|
||||
elif file.lower().endswith(self.office):
|
||||
subprocess.Popen([self.OFFICEPROG, file])
|
||||
else:
|
||||
subprocess.Popen(['xdg-open', file])
|
||||
|
||||
|
||||
def createFile(self, newFileName):
|
||||
pass
|
||||
|
||||
def updateFile(self, oldFileName, newFileName):
|
||||
try:
|
||||
print("Renaming...")
|
||||
print(oldFileName + " --> " + newFileName)
|
||||
os.rename(oldFileName, newFileName)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("An error occured renaming the file:")
|
||||
print(e)
|
||||
return 1
|
||||
|
||||
def deleteFile(self, toDeleteFile):
|
||||
try:
|
||||
print("Deleting...")
|
||||
print(toDeleteFile)
|
||||
if os.path.exists(toDeleteFile):
|
||||
if os.path.isfile(toDeleteFile):
|
||||
os.remove(toDeleteFile)
|
||||
elif os.path.isdir(toDeleteFile):
|
||||
shutil.rmtree(toDeleteFile)
|
||||
else:
|
||||
print("An error occured deleting the file:")
|
||||
return 1
|
||||
else:
|
||||
print("The folder/file does not exist")
|
||||
return 1
|
||||
except Exception as e:
|
||||
print("An error occured deleting the file:")
|
||||
print(e)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
def copyFile(self):
|
||||
pass
|
||||
|
||||
def cutFile(self):
|
||||
pass
|
||||
|
||||
def pasteFile(self):
|
||||
pass
|
@ -1,214 +0,0 @@
|
||||
|
||||
|
||||
# Gtk Imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gdk as gdk
|
||||
from gi.repository import GLib as glib
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
# Python imports
|
||||
import os, threading, time
|
||||
from os.path import isdir, isfile, join
|
||||
from os import listdir
|
||||
from .Icon import Icon
|
||||
from .FileHandler import FileHandler
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
return wrapper
|
||||
|
||||
class Grid:
|
||||
def __init__(self, desktop, settings, newPath):
|
||||
self.desktop = desktop
|
||||
self.settings = settings
|
||||
self.filehandler = FileHandler()
|
||||
|
||||
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
|
||||
self.usrHome = settings.returnUserHome()
|
||||
self.builder = settings.returnBuilder()
|
||||
self.ColumnSize = settings.returnColumnSize()
|
||||
self.currentPath = ""
|
||||
self.selectedFile = ""
|
||||
|
||||
self.desktop.set_model(self.store)
|
||||
self.desktop.set_pixbuf_column(0)
|
||||
self.desktop.set_text_column(1)
|
||||
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
||||
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
|
||||
self.desktop.connect("selection-changed", self.setIconSelectionArray, (self.desktop,))
|
||||
|
||||
self.vidsList = settings.returnVidsExtensionList()
|
||||
self.imagesList = settings.returnImagesExtensionList()
|
||||
self.gtkLock = False # Thread checks for gtkLock
|
||||
self.threadLock = False # Gtk checks for thread lock
|
||||
self.helperThread = None # Helper thread object
|
||||
self.toWorkPool = [] # Thread fills pool and gtk empties it
|
||||
self.copyCutArry = []
|
||||
|
||||
self.setIconViewDir(newPath)
|
||||
|
||||
def setIconViewDir(self, path):
|
||||
self.store.clear()
|
||||
|
||||
self.currentPath = path
|
||||
dirPaths = ['.', '..']
|
||||
vids = []
|
||||
images = []
|
||||
desktop = []
|
||||
files = []
|
||||
|
||||
for f in listdir(path):
|
||||
file = join(path, f)
|
||||
if self.settings.isHideHiddenFiles():
|
||||
if f.startswith('.'):
|
||||
continue
|
||||
if isfile(file):
|
||||
if file.lower().endswith(self.vidsList):
|
||||
vids.append(f)
|
||||
elif file.lower().endswith(self.imagesList):
|
||||
images.append(f)
|
||||
elif file.lower().endswith((".desktop",)):
|
||||
desktop.append(f)
|
||||
else:
|
||||
files.append(f)
|
||||
else:
|
||||
dirPaths.append(f)
|
||||
|
||||
dirPaths.sort()
|
||||
vids.sort()
|
||||
images.sort()
|
||||
desktop.sort()
|
||||
files.sort()
|
||||
files = dirPaths + vids + images + desktop + files
|
||||
|
||||
if self.helperThread:
|
||||
self.helperThread.terminate()
|
||||
self.helperThread = None
|
||||
|
||||
# Run helper thread...
|
||||
self.threadLock = True
|
||||
self.helperThread = threading.Thread(target=self.generateDirectoryGridIcon, args=(path, files)).start()
|
||||
glib.idle_add(self.addToGrid, (file,)) # This must stay in the main thread b/c
|
||||
# gtk isn't thread safe/aware So, we
|
||||
# make a sad lil thread hot potato 'game'
|
||||
# out of this process.
|
||||
|
||||
|
||||
# @threaded
|
||||
def generateDirectoryGridIcon(self, dirPath, files):
|
||||
# NOTE: We'll be passing pixbuf after retreval to keep Icon.py file more
|
||||
# universaly usable. We can just remove get_pixbuf to get a gtk.Image type
|
||||
for file in files:
|
||||
image = Icon(self.settings).createIcon(dirPath, file)
|
||||
self.toWorkPool.append([image.get_pixbuf(), file])
|
||||
self.threadLock = False
|
||||
self.gtkLock = True
|
||||
|
||||
|
||||
def addToGrid(self, args):
|
||||
# NOTE: Returning true tells gtk to check again in the future when idle.
|
||||
# False ends checks and "continues normal flow"
|
||||
files = args[0]
|
||||
|
||||
if len(self.toWorkPool) > 0:
|
||||
for dataSet in self.toWorkPool:
|
||||
self.store.append(dataSet)
|
||||
|
||||
if len(self.store) == len(files): # Confirm processed all files and cleanup
|
||||
self.gtkLock = False
|
||||
self.threadLock = False
|
||||
self.toWorkPool.clear()
|
||||
return False
|
||||
# Check again when idle; If nothing else is updating, this function
|
||||
# gets called immediatly. So, we play hot potato by passing lock to Thread
|
||||
else:
|
||||
self.toWorkPool.clear()
|
||||
self.gtkLock = False
|
||||
self.threadLock = True
|
||||
time.sleep(.005) # Fixes refresh and up icon not being added.
|
||||
return True
|
||||
|
||||
def setIconSelectionArray(self, widget, data=None):
|
||||
pass
|
||||
# os.system('cls||clear')
|
||||
# print(data)
|
||||
|
||||
def iconLeftClickEventManager(self, widget, item):
|
||||
try:
|
||||
model = widget.get_model()
|
||||
fileName = model[item][1]
|
||||
dir = self.currentPath
|
||||
file = dir + "/" + fileName
|
||||
|
||||
if fileName == ".":
|
||||
self.setIconViewDir(dir)
|
||||
elif fileName == "..":
|
||||
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
|
||||
self.currentPath = parentDir
|
||||
self.setIconViewDir(parentDir)
|
||||
elif isdir(file):
|
||||
self.currentPath = file
|
||||
self.setIconViewDir(self.currentPath)
|
||||
elif isfile(file):
|
||||
self.filehandler.openFile(file)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def iconRightClickEventManager(self, widget, eve, params):
|
||||
try:
|
||||
if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
|
||||
popover = self.builder.get_object("iconControlsWindow")
|
||||
popover.show_all()
|
||||
popover.popup()
|
||||
# # NOTE: Need to change name of listview box...
|
||||
# children = widget.get_children()[0].get_children()
|
||||
# fileName = children[1].get_text()
|
||||
# dir = self.currentPath
|
||||
# file = dir + "/" + fileName
|
||||
#
|
||||
# input = self.builder.get_object("iconRenameInput")
|
||||
# popover = self.builder.get_object("iconControlsWindow")
|
||||
# self.selectedFile = file # Used for return to caller
|
||||
#
|
||||
# input.set_text(fileName)
|
||||
# popover.set_relative_to(widget)
|
||||
# popover.set_position(gtk.PositionType.RIGHT)
|
||||
# popover.show_all()
|
||||
# popover.popup()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
# Passthrough file control events
|
||||
def createFile(arg):
|
||||
pass
|
||||
|
||||
def updateFile(self, file):
|
||||
newName = self.currentPath + "/" + file
|
||||
status = self.filehandler.updateFile(self.selectedFile, newName)
|
||||
|
||||
if status == 0:
|
||||
self.selectedFile = newName
|
||||
self.setIconViewDir(self.currentPath)
|
||||
|
||||
def deleteFile(self):
|
||||
status = self.filehandler.deleteFile(self.selectedFile)
|
||||
|
||||
if status == 0:
|
||||
self.selectedFile = ""
|
||||
self.setIconViewDir(self.currentPath)
|
||||
|
||||
def copyFile(self):
|
||||
pass
|
||||
|
||||
def cutFile(self):
|
||||
pass
|
||||
|
||||
def pasteFile(self):
|
||||
pass
|
@ -1,167 +0,0 @@
|
||||
|
||||
# Gtk Imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gio as gio
|
||||
from gi.repository import GdkPixbuf
|
||||
from xdg.DesktopEntry import DesktopEntry
|
||||
|
||||
# Python Imports
|
||||
import os, subprocess, hashlib, threading
|
||||
|
||||
from os.path import isdir, isfile, join
|
||||
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||
return wrapper
|
||||
|
||||
class Icon:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
self.thubnailGen = settings.getThumbnailGenerator()
|
||||
self.vidsList = settings.returnVidsExtensionList()
|
||||
self.imagesList = settings.returnImagesExtensionList()
|
||||
self.GTK_ORIENTATION = settings.returnIconImagePos()
|
||||
self.usrHome = settings.returnUserHome()
|
||||
self.iconContainerWH = settings.returnContainerWH()
|
||||
self.systemIconImageWH = settings.returnSystemIconImageWH()
|
||||
self.viIconWH = settings.returnVIIconWH()
|
||||
|
||||
|
||||
def createIcon(self, dir, file):
|
||||
fullPath = dir + "/" + file
|
||||
return self.getIconImage(file, fullPath)
|
||||
|
||||
|
||||
def getIconImage(self, file, fullPath):
|
||||
try:
|
||||
thumbnl = None
|
||||
|
||||
# Video thumbnail
|
||||
if file.lower().endswith(self.vidsList):
|
||||
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
|
||||
hashImgPth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
|
||||
|
||||
if isfile(hashImgPth) == False:
|
||||
self.generateVideoThumbnail(fullPath, hashImgPth)
|
||||
|
||||
thumbnl = self.createIconImageBuffer(hashImgPth, self.viIconWH)
|
||||
# Image Icon
|
||||
elif file.lower().endswith(self.imagesList):
|
||||
thumbnl = self.createIconImageBuffer(fullPath, self.viIconWH)
|
||||
# .desktop file parsing
|
||||
elif fullPath.lower().endswith( ('.desktop',) ):
|
||||
thumbnl = self.parseDesktopFiles(fullPath)
|
||||
# System icons
|
||||
else:
|
||||
thumbnl = self.getSystemThumbnail(fullPath, self.systemIconImageWH[0])
|
||||
|
||||
if thumbnl == None: # If no icon, try stock file icon...
|
||||
thumbnl = gtk.Image.new_from_icon_name("gtk-file", gtk.IconSize.LARGE_TOOLBAR)
|
||||
|
||||
if thumbnl == None: # If no icon whatsoever, return internal default
|
||||
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png")
|
||||
|
||||
return thumbnl
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return gtk.Image.new_from_file("resources/icons/bin.png")
|
||||
|
||||
|
||||
def parseDesktopFiles(self, fullPath):
|
||||
try:
|
||||
xdgObj = DesktopEntry(fullPath)
|
||||
icon = xdgObj.getIcon()
|
||||
iconsDirs = "/usr/share/icons"
|
||||
altIconPath = ""
|
||||
|
||||
if "steam" in icon:
|
||||
steamIconsDir = self.usrHome + "/.thumbnails/steam_icons/"
|
||||
name = xdgObj.getName()
|
||||
fileHash = hashlib.sha256(str.encode(name)).hexdigest()
|
||||
|
||||
if isdir(steamIconsDir) == False:
|
||||
os.mkdir(steamIconsDir)
|
||||
|
||||
hashImgPth = steamIconsDir + fileHash + ".jpg"
|
||||
if isfile(hashImgPth) == True:
|
||||
# Use video sizes since headers are bigger
|
||||
return self.createIconImageBuffer(hashImgPth, self.viIconWH)
|
||||
|
||||
execStr = xdgObj.getExec()
|
||||
parts = execStr.split("steam://rungameid/")
|
||||
id = parts[len(parts) - 1]
|
||||
|
||||
# NOTE: Can try this logic instead...
|
||||
# if command exists use it instead of header image
|
||||
# if "steamcmd app_info_print id":
|
||||
# proc = subprocess.Popen(["steamcmd", "app_info_print", id])
|
||||
# proc.wait()
|
||||
# else:
|
||||
# use the bottom logic
|
||||
|
||||
imageLink = "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/header.jpg"
|
||||
proc = subprocess.Popen(["wget", "-O", hashImgPth, imageLink])
|
||||
proc.wait()
|
||||
|
||||
# Use video sizes since headers are bigger
|
||||
return self.createIconImageBuffer(hashImgPth, self.viIconWH)
|
||||
elif os.path.exists(icon):
|
||||
return self.createIconImageBuffer(icon, self.systemIconImageWH)
|
||||
else:
|
||||
for (dirpath, dirnames, filenames) in os.walk(iconsDirs):
|
||||
for file in filenames:
|
||||
appNM = "application-x-" + icon
|
||||
if appNM in file:
|
||||
altIconPath = dirpath + "/" + file
|
||||
break
|
||||
|
||||
return self.createIconImageBuffer(altIconPath, self.systemIconImageWH)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
def getSystemThumbnail(self, filename, size):
|
||||
try:
|
||||
iconPath = None
|
||||
if os.path.exists(filename):
|
||||
file = gio.File.new_for_path(filename)
|
||||
info = file.query_info('standard::icon' , 0 , gio.Cancellable())
|
||||
icon = info.get_icon().get_names()[0]
|
||||
iconTheme = gtk.IconTheme.get_default()
|
||||
iconFile = iconTheme.lookup_icon(icon , size , 0)
|
||||
|
||||
if iconFile != None:
|
||||
iconPath = iconFile.get_filename()
|
||||
return self.createIconImageBuffer(iconPath, self.systemIconImageWH)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
def createIconImageBuffer(self, path, wxh):
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], False)
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
return gtk.Image.new_from_pixbuf(pixbuf)
|
||||
|
||||
|
||||
def generateVideoThumbnail(self, fullPath, hashImgPth):
|
||||
try:
|
||||
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPath, "-o", hashImgPth])
|
||||
proc.wait()
|
||||
except Exception as e:
|
||||
print(e)
|
@ -1,139 +0,0 @@
|
||||
|
||||
# Gtk Imports
|
||||
import gi, cairo, os
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gdk as gdk
|
||||
|
||||
class Settings:
|
||||
def __init__(self):
|
||||
self.builder = None
|
||||
self.hideHiddenFiles = True
|
||||
|
||||
|
||||
self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
||||
self.THUMB_GENERATOR = "ffmpegthumbnailer"
|
||||
self.DEFAULTCOLOR = gdk.RGBA(0.0, 0.0, 0.0, 0.0) # ~#00000000
|
||||
self.MOUSEOVERCOLOR = gdk.RGBA(0.0, 0.9, 1.0, 0.64) # ~#00e8ff
|
||||
self.SELECTEDCOLOR = gdk.RGBA(0.4, 0.5, 0.1, 0.84)
|
||||
|
||||
self.ColumnSize = 8
|
||||
self.usrHome = os.path.expanduser('~')
|
||||
self.desktopPath = self.usrHome + "/Desktop"
|
||||
self.webHome = 'http://webfm.com/'
|
||||
self.iconContainerWxH = [128, 128]
|
||||
self.systemIconImageWxH = [72, 72]
|
||||
self.viIconWxH = [256, 128]
|
||||
self.vidsExtensionList = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
|
||||
self.imagesExtensionList = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga')
|
||||
|
||||
|
||||
def attachBuilder(self, builder):
|
||||
self.builder = builder
|
||||
self.builder.add_from_file("resources/PyFM.glade")
|
||||
|
||||
def createWindow(self):
|
||||
# Get window and connect signals
|
||||
window = self.builder.get_object("Window")
|
||||
window.connect("delete-event", gtk.main_quit)
|
||||
self.setWindowData(window)
|
||||
return window
|
||||
|
||||
def setWindowData(self, window):
|
||||
screen = window.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
if visual != None and screen.is_composited():
|
||||
window.set_visual(visual)
|
||||
|
||||
# bind css file
|
||||
cssProvider = gtk.CssProvider()
|
||||
cssProvider.load_from_path('resources/stylesheet.css')
|
||||
screen = gdk.Screen.get_default()
|
||||
styleContext = gtk.StyleContext()
|
||||
styleContext.add_provider_for_screen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||
|
||||
window.set_app_paintable(True)
|
||||
monitors = self.getMonitorData(screen)
|
||||
window.resize(monitors[0].width, monitors[0].height)
|
||||
|
||||
def getMonitorData(self, screen):
|
||||
monitors = []
|
||||
for m in range(screen.get_n_monitors()):
|
||||
monitors.append(screen.get_monitor_geometry(m))
|
||||
|
||||
for monitor in monitors:
|
||||
print(str(monitor.width) + "x" + str(monitor.height) + "+" + str(monitor.x) + "+" + str(monitor.y))
|
||||
|
||||
return monitors
|
||||
|
||||
|
||||
def returnBuilder(self): return self.builder
|
||||
def returnUserHome(self): return self.usrHome
|
||||
def returnDesktopPath(self): return self.usrHome + "/Desktop"
|
||||
def returnIconImagePos(self): return self.GTK_ORIENTATION
|
||||
def getThumbnailGenerator(self): return self.THUMB_GENERATOR
|
||||
def returnColumnSize(self): return self.ColumnSize
|
||||
def returnContainerWH(self): return self.iconContainerWxH
|
||||
def returnSystemIconImageWH(self): return self.systemIconImageWxH
|
||||
def returnVIIconWH(self): return self.viIconWxH
|
||||
def returnWebHome(self): return self.webHome
|
||||
def isHideHiddenFiles(self): return self.hideHiddenFiles
|
||||
def returnVidsExtensionList(self): return self.vidsExtensionList
|
||||
def returnImagesExtensionList(self): return self.imagesExtensionList
|
||||
|
||||
def setDefaultWebviewSettings(self, widget, settings=None):
|
||||
# Usability
|
||||
settings.set_property('enable-fullscreen', True)
|
||||
settings.set_property('print-backgrounds', True)
|
||||
settings.set_property('enable-frame-flattening', False)
|
||||
settings.set_property('enable-plugins', True)
|
||||
settings.set_property('enable-java', False)
|
||||
settings.set_property('enable-resizable-text-areas', True)
|
||||
settings.set_property('zoom-text-only', False)
|
||||
settings.set_property('enable-smooth-scrolling', True)
|
||||
settings.set_property('enable-back-forward-navigation-gestures', False)
|
||||
settings.set_property('media-playback-requires-user-gesture', False)
|
||||
settings.set_property('enable-tabs-to-links', True)
|
||||
settings.set_property('enable-caret-browsing', False)
|
||||
|
||||
# Security
|
||||
settings.set_property('user-agent','Mozilla/5.0 (X11; Generic; Linux x86-64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Safari/605.1.15')
|
||||
settings.set_property('enable-private-browsing', False)
|
||||
settings.set_property('enable-xss-auditor', True)
|
||||
settings.set_property('enable-hyperlink-auditing', False)
|
||||
settings.set_property('enable-site-specific-quirks', True)
|
||||
settings.set_property('enable-offline-web-application-cache', True)
|
||||
settings.set_property('enable-page-cache', True)
|
||||
settings.set_property('allow-modal-dialogs', False)
|
||||
settings.set_property('enable-html5-local-storage', True)
|
||||
settings.set_property('enable-html5-database', True)
|
||||
settings.set_property('allow-file-access-from-file-urls', False)
|
||||
settings.set_property('allow-universal-access-from-file-urls', False)
|
||||
settings.set_property('enable-dns-prefetching', False)
|
||||
|
||||
# Media stuff
|
||||
# settings.set_property('hardware-acceleration-policy', 'on-demand')
|
||||
settings.set_property('enable-webgl', False)
|
||||
settings.set_property('enable-webaudio', True)
|
||||
settings.set_property('enable-accelerated-2d-canvas', True)
|
||||
settings.set_property('auto-load-images', True)
|
||||
settings.set_property('enable-media-capabilities', True)
|
||||
settings.set_property('enable-media-stream', True)
|
||||
settings.set_property('enable-mediasource', True)
|
||||
settings.set_property('enable-encrypted-media', True)
|
||||
settings.set_property('media-playback-allows-inline', True)
|
||||
|
||||
# JS
|
||||
settings.set_property('enable-javascript', True)
|
||||
settings.set_property('enable-javascript-markup', True)
|
||||
settings.set_property('javascript-can-access-clipboard', False)
|
||||
settings.set_property('javascript-can-open-windows-automatically', False)
|
||||
|
||||
# Debugging
|
||||
settings.set_property('enable-developer-extras', False)
|
||||
settings.set_property('enable-write-console-messages-to-stdout', False)
|
||||
settings.set_property('draw-compositing-indicators', False)
|
||||
settings.set_property('enable-mock-capture-devices', False)
|
||||
settings.set_property('enable-spatial-navigation', False)
|
@ -1,6 +0,0 @@
|
||||
from utils.Dragging import Dragging
|
||||
from utils.Settings import Settings
|
||||
from utils.Events import Events
|
||||
from utils.Grid import Grid
|
||||
from utils.Icon import Icon
|
||||
from utils.FileHandler import FileHandler
|
@ -13,22 +13,23 @@ from os import path
|
||||
class Settings:
|
||||
logger = None
|
||||
|
||||
USR_SOLARFM = "/usr/share/solarfm"
|
||||
USER_HOME = path.expanduser('~')
|
||||
CONFIG_PATH = USER_HOME + "/.config/solarfm"
|
||||
CONFIG_FILE = CONFIG_PATH + "/settings.json"
|
||||
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
|
||||
CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
|
||||
HIDE_HIDDEN_FILES = True
|
||||
|
||||
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
||||
DEFAULT_ICONS = CONFIG_PATH + "/icons"
|
||||
DEFAULT_ICON = DEFAULT_ICONS + "/text.png"
|
||||
FFMPG_THUMBNLR = CONFIG_PATH + "/ffmpegthumbnailer" # Thumbnail generator binary
|
||||
REMUX_FOLDER = USER_HOME + "/.remuxs" # Remuxed files folder
|
||||
DEFAULT_ICONS = f"{CONFIG_PATH}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|
||||
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
|
||||
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
|
||||
|
||||
STEAM_BASE_URL = "https://steamcdn-a.akamaihd.net/steam/apps/"
|
||||
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,]
|
||||
BASE_THUMBS_PTH = USER_HOME + "/.thumbnails" # Used for thumbnail generation
|
||||
ABS_THUMBS_PTH = BASE_THUMBS_PTH + "/normal" # Used for thumbnail generation
|
||||
STEAM_ICONS_PTH = BASE_THUMBS_PTH + "/steam_icons"
|
||||
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
|
||||
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
|
||||
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
|
||||
CONTAINER_ICON_WH = [128, 128]
|
||||
VIDEO_ICON_WH = [128, 64]
|
||||
SYS_ICON_WH = [56, 56]
|
||||
@ -82,14 +83,18 @@ class Settings:
|
||||
|
||||
|
||||
# Dir structure check
|
||||
if path.isdir(REMUX_FOLDER) == False:
|
||||
if not path.isdir(REMUX_FOLDER):
|
||||
os.mkdir(REMUX_FOLDER)
|
||||
|
||||
if path.isdir(BASE_THUMBS_PTH) == False:
|
||||
if not path.isdir(BASE_THUMBS_PTH):
|
||||
os.mkdir(BASE_THUMBS_PTH)
|
||||
|
||||
if path.isdir(ABS_THUMBS_PTH) == False:
|
||||
if not path.isdir(ABS_THUMBS_PTH):
|
||||
os.mkdir(ABS_THUMBS_PTH)
|
||||
|
||||
if path.isdir(STEAM_ICONS_PTH) == False:
|
||||
if not path.isdir(STEAM_ICONS_PTH):
|
||||
os.mkdir(STEAM_ICONS_PTH)
|
||||
|
||||
if not os.path.exists(DEFAULT_ICONS):
|
||||
DEFAULT_ICONS = f"{USR_SOLARFM}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|