Changing to pythonic imports, restructured mixins layout

This commit is contained in:
itdominator 2022-11-28 22:34:13 -06:00
parent 9bd5697677
commit f2090a7d46
40 changed files with 190 additions and 113 deletions

View File

@ -1,5 +1,9 @@
# Python imports # Python imports
import os, threading, subprocess, inspect, shlex import os
import threading
import subprocess
import inspect
import shlex
# Lib imports # Lib imports
import gi import gi

View File

@ -1,5 +1,8 @@
# Python imports # Python imports
import os, subprocess, time, inspect import os
import subprocess
import time
import inspect
# Lib imports # Lib imports
import gi import gi

View File

@ -1,5 +1,7 @@
# Python imports # Python imports
import os, inspect, json import os
import inspect
import json
# Lib imports # Lib imports
import gi import gi

View File

@ -1,11 +1,18 @@
# Python imports # Python imports
import os, threading, subprocess, time, pwd, grp import os
import threading
import subprocess
import time
import pwd
import grp
from datetime import datetime from datetime import datetime
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gio from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Gio
# Application imports # Application imports
from plugins.plugin_base import PluginBase from plugins.plugin_base import PluginBase

View File

@ -1,11 +1,18 @@
# Python imports # Python imports
import os, threading, subprocess, inspect, requests, shutil import os
import threading
import subprocess
import inspect
import requests
import shutil
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('GdkPixbuf', '2.0') gi.require_version('GdkPixbuf', '2.0')
from gi.repository import Gtk, GLib, GdkPixbuf from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GdkPixbuf
# Application imports # Application imports
from plugins.plugin_base import PluginBase from plugins.plugin_base import PluginBase

View File

@ -1,10 +1,15 @@
# Python imports # Python imports
import threading, subprocess, signal, json, shlex import threading
import subprocess
import signal
import json
import shlex
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from ..widgets.file_preview_widget import FilePreviewWidget from ..widgets.file_preview_widget import FilePreviewWidget

View File

@ -1,11 +1,17 @@
# Python imports # Python imports
import ctypes, threading, subprocess, signal, json, shlex import ctypes
import threading
import subprocess
import signal
import json
import shlex
libgcc_s = ctypes.CDLL('libgcc_s.so.1') libgcc_s = ctypes.CDLL('libgcc_s.so.1')
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from ..widgets.grep_preview_widget import GrepPreviewWidget from ..widgets.grep_preview_widget import GrepPreviewWidget

View File

@ -1,10 +1,14 @@
# Python imports # Python imports
import os, threading, inspect, time import os
import threading
import inspect
import time
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from plugins.plugin_base import PluginBase from plugins.plugin_base import PluginBase

View File

@ -2,7 +2,14 @@
# Python imports # Python imports
import os, traceback, argparse, threading, json, base64, time, pickle import os
import traceback
import argparse
import threading
import json
import base64
import time
import pickle
from setproctitle import setproctitle from setproctitle import setproctitle
from multiprocessing.connection import Client from multiprocessing.connection import Client

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import base64, re import base64
import re
# Lib imports # Lib imports
import gi import gi

View File

@ -1,5 +1,8 @@
# Python imports # Python imports
import os, threading, subprocess, time import os
import threading
import subprocess
import ime
# Lib imports # Lib imports
import gi import gi

View File

@ -1,10 +1,15 @@
# Python imports # Python imports
import os, threading, subprocess, inspect import os
import threading
import subprocess
import inspect
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gio from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Gio
# Application imports # Application imports
from plugins.plugin_base import PluginBase from plugins.plugin_base import PluginBase

View File

@ -1,12 +1,20 @@
# Python imports # Python imports
import os, threading, subprocess, time, inspect, hashlib import os
import threading
import subprocess
import time
import inspect
import hashlib
from datetime import datetime from datetime import datetime
# Gtk imports # Gtk imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('GdkPixbuf', '2.0') gi.require_version('GdkPixbuf', '2.0')
from gi.repository import Gtk, GLib, Gio, GdkPixbuf from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Gio
from gi.repository import GdkPixbuf
# Application imports # Application imports
from plugins.plugin_base import PluginBase from plugins.plugin_base import PluginBase

View File

@ -1,7 +1,9 @@
#!/usr/bin/python3 #!/usr/bin/python3
# Python imports # Python imports
import argparse, faulthandler, traceback import argparse
import faulthandler
import traceback
from setproctitle import setproctitle from setproctitle import setproctitle
import tracemalloc import tracemalloc

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import os, inspect import os
import inspect
# Lib imports # Lib imports

View File

@ -7,24 +7,22 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib from gi.repository import Gtk, GLib
# Application imports # Application imports
from widgets.context_menu_widget import ContextMenuWidget
from .mixins.exception_hook_mixin import ExceptionHookMixin
from .mixins.ui_mixin import UIMixin
from .signals.ipc_signals_mixin import IPCSignalsMixin
from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
from .controller_data import Controller_Data from .controller_data import Controller_Data
from .mixins.signals_mixins import SignalsMixins
from .ui import UI
from widgets.context_menu_widget import ContextMenuWidget
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin, Controller_Data):
class Controller(UI, SignalsMixins, Controller_Data):
""" Controller coordinates the mixins and is somewhat the root hub of it all. """ """ Controller coordinates the mixins and is somewhat the root hub of it all. """
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
self._subscribe_to_events() self._subscribe_to_events()
self.setup_controller_data() self.setup_controller_data()
self.generate_windows(self.fm_controller_data) self.generate_windows(self.fm_controller_data)
cm = ContextMenuWidget() ContextMenuWidget().build_context_menu()
cm.build_context_menu()
if args.no_plugins == "false": if args.no_plugins == "false":
self.plugins.launch_plugins() self.plugins.launch_plugins()

View File

@ -1,3 +1,3 @@
""" """
Mixins module Mixins module
""" """

View File

@ -1,10 +1,12 @@
# Python imports # Python imports
import traceback, time import traceback
import time
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports

View File

@ -4,7 +4,8 @@
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk from gi.repository import Gtk
from gi.repository import Gdk
# Application imports # Application imports

View File

@ -0,0 +1,3 @@
"""
Signals module
"""

View File

@ -1,19 +1,24 @@
# Python imports # Python imports
import os, time, shlex import os
import time
import shlex
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, GLib, Gio from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
# Application imports # Application imports
from widgets.io_widget import IOWidget from widgets.io_widget import IOWidget
class FileActionSignalsMixin:
class WidgetFileActionMixin: """docstring for FileActionSignalsMixin"""
"""docstring for WidgetFileActionMixin"""
def sizeof_fmt(self, num, suffix="B"): def sizeof_fmt(self, num, suffix="B"):
for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]: for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]:

View File

@ -5,11 +5,12 @@
# Application imports # Application imports
class IPCSignalsMixin: class IPCSignalsMixin:
""" IPCSignalsMixin handle messages from another starting solarfm process. """ """ IPCSignalsMixin handle messages from another starting solarfm process. """
def print_to_console(self, message=None): def print_to_console(self, message=None):
print(self)
print(message) print(message)
def handle_file_from_ipc(self, path): def handle_file_from_ipc(self, path):

View File

@ -5,7 +5,8 @@ import re
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk from gi.repository import Gtk
from gi.repository import Gdk
# Application imports # Application imports
@ -13,6 +14,8 @@ from gi.repository import Gtk, Gdk
valid_keyvalue_pat = re.compile(r"[a-z0-9A-Z-_\[\]\(\)\| ]") valid_keyvalue_pat = re.compile(r"[a-z0-9A-Z-_\[\]\(\)\| ]")
class KeyboardSignalsMixin: class KeyboardSignalsMixin:
""" KeyboardSignalsMixin keyboard hooks controller. """ """ KeyboardSignalsMixin keyboard hooks controller. """

View File

@ -0,0 +1,15 @@
# Python imports
# Lib imports
from .exception_hook_mixin import ExceptionHookMixin
from .signals.file_action_signals_mixin import FileActionSignalsMixin
from .signals.ipc_signals_mixin import IPCSignalsMixin
from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
# Application imports
class SignalsMixins(FileActionSignalsMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin):
...

View File

@ -1,3 +1,3 @@
""" """
UI module UI module
""" """

View File

@ -6,45 +6,18 @@ import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk, GLib, Gio, GdkPixbuf 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
# Application imports # Application imports
from widgets.tab_header import TabHeader from widgets.tab_header_widget import TabHeaderWidget
from widgets.icon_grid_widget import IconGridWidget from widgets.icon_grid_widget import IconGridWidget
from widgets.icon_tree_widget import IconTreeWidget from widgets.icon_tree_widget import IconTreeWidget
# NOTE: Consider trying to use Gtk.TreeView with css that turns it into a grid...
# Can possibly use this to dynamicly load icons instead...
class Icon(Gtk.HBox):
def __init__(self, tab, dir, file):
super(Icon, self).__init__()
self.load_icon(tab, dir, file)
@threaded
def load_icon(self, tab, dir, file):
icon = tab.create_icon(dir, file)
if not icon:
path = f"{dir}/{file}"
icon = self.get_system_thumbnail(path, tab.sys_icon_wh[0])
if not icon:
icon = GdkPixbuf.Pixbuf.new_from_file(tab.DEFAULT_ICON)
self.add(Gtk.Image.new_from_pixbuf(icon))
self.show_all()
def get_system_thumbnail(self, file, size):
try:
gio_file = Gio.File.new_for_path(file)
info = gio_file.query_info('standard::icon' , 0, None)
icon = info.get_icon().get_names()[0]
icon_path = self.icon_theme.lookup_icon(icon , size , 0).get_filename()
return GdkPixbuf.Pixbuf.new_from_file(icon_path)
except Exception as e:
return None
class GridMixin: class GridMixin:
@ -96,7 +69,7 @@ class GridMixin:
def create_tab_widget(self, tab): def create_tab_widget(self, tab):
return TabHeader(tab, self.close_tab) return TabHeaderWidget(tab, self.close_tab)
def create_scroll_and_store(self, tab, wid, use_tree_view=False): def create_scroll_and_store(self, tab, wid, use_tree_view=False):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()

View File

@ -6,7 +6,8 @@ from os.path import isdir
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gdk, Gio from gi.repository import Gdk
from gi.repository import Gio
# Application imports # Application imports
from .tab_mixin import TabMixin from .tab_mixin import TabMixin

View File

@ -1,14 +0,0 @@
# Python imports
# Gtk imports
# Application imports
from .show_hide_mixin import ShowHideMixin
from .ui.widget_file_action_mixin import WidgetFileActionMixin
from .ui.pane_mixin import PaneMixin
from .ui.window_mixin import WindowMixin
from .show_hide_mixin import ShowHideMixin
class UIMixin(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin):
...

View File

@ -1,3 +0,0 @@
"""
Signals module
"""

View File

@ -0,0 +1,12 @@
# Python imports
# Gtk imports
# Application imports
from .mixins.show_hide_mixin import ShowHideMixin
from .mixins.ui.pane_mixin import PaneMixin
from .mixins.ui.window_mixin import WindowMixin
class UI(PaneMixin, WindowMixin, ShowHideMixin):
...

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import os, json import os
import json
from os.path import join from os.path import join
# Lib imports # Lib imports

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import os, time import os
import time
# Lib imports # Lib imports

View File

@ -1,14 +1,20 @@
# Python imports # Python imports
import os, sys, importlib, traceback import os
from os.path import join, isdir import sys
import importlib
import traceback
from os.path import join
from os.path import isdir
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio from gi.repository import Gtk
from gi.repository import Gio
# Application imports # Application imports
from .manifest import PluginInfo, ManifestProcessor from .manifest import PluginInfo
from .manifest import ManifestProcessor

View File

@ -1,6 +1,7 @@
# Python imports # Python imports
import os, threading, time import os, threading, time
from multiprocessing.connection import Listener, Client from multiprocessing.connection import Client
from multiprocessing.connection import Listener
# Lib imports # Lib imports

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import os, logging import os
import logging
# Application imports # Application imports

View File

@ -1,16 +1,15 @@
# Python imports # Python imports
import os, json import os
import json
from os import path from os import path
# Gtk imports # Gtk imports
import gi, cairo import gi, cairo
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
# Application imports # Application imports
from .logger import Logger from .logger import Logger
from .keybindings import Keybindings from .keybindings import Keybindings

View File

@ -4,7 +4,9 @@
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
# Application imports # Application imports

View File

@ -4,7 +4,9 @@
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
# Application imports # Application imports

View File

@ -3,7 +3,8 @@
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio from gi.repository import Gtk
from gi.repository import Gio
# Application imports # Application imports
@ -64,7 +65,7 @@ class IOWidget(Gtk.Box):
self.progress.set_fraction(current/total) self.progress.set_fraction(current/total)
def finish_callback(self, file, task=None, eve=None): def finish_callback(self, file, task=None, eve=None):
if self._action == "move" and self._action == "rename": if self._action == "move" or self._action == "rename":
status = self._file.move_finish(task) status = self._file.move_finish(task)
if self._action == "copy": if self._action == "copy":
status = self._file.copy_finish(task) status = self._file.copy_finish(task)

View File

@ -3,16 +3,17 @@
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio from gi.repository import Gtk
from gi.repository import Gio
# Application imports # Application imports
class TabHeader(Gtk.ButtonBox): class TabHeaderWidget(Gtk.ButtonBox):
"""docstring for TabHeader""" """docstring for TabHeaderWidget"""
def __init__(self, tab, close_tab): def __init__(self, tab, close_tab):
super(TabHeader, self).__init__() super(TabHeaderWidget, self).__init__()
self._tab = tab self._tab = tab
self._close_tab = close_tab # NOTE: Close method in tab_mixin self._close_tab = close_tab # NOTE: Close method in tab_mixin