Added setup py; buiuld system; and IPC and process detection

This commit is contained in:
itdominator 2021-11-25 00:44:12 -06:00
parent dc894f1245
commit 35cf150fbc
11 changed files with 133 additions and 37 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 KiB

After

Width:  |  Height:  |  Size: 456 KiB

View File

@ -13,6 +13,6 @@ function main() {
echo "Working Dir: " $(pwd)
source "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/bin/activate"
python .
python ./pyfm
}
main "$@";

View File

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

View File

@ -1,6 +1,13 @@
# Python imports
import builtins
class Builtins:
# Gtk imports
# Application imports
from signal_classes.DBusControllerMixin import DBusControllerMixin
class Builtins(DBusControllerMixin):
"""Docstring for __builtins__ extender"""
def __init__(self):
@ -9,6 +16,8 @@ class Builtins:
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
def _pop_gui_event(self):
@ -53,5 +62,5 @@ class Builtins:
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.event_system = Builtins()
builtins.event_sleep_time = 0.2
builtins.event_sleep_time = 0.5
builtins.debug = False

View File

@ -1,10 +1,8 @@
# Python imports
import inspect
import inspect, time
# Gtk imports
# Application imports
from utils import Settings
from signal_classes import Signals
@ -13,13 +11,24 @@ from __builtins__ import Builtins
class Main(Builtins):
def __init__(self, args):
event_system.create_ipc_server()
time.sleep(0.5)
if not event_system.is_ipc_alive:
if args.new_tab:
message = f"FILE|{args.new_tab}"
event_system.send_ipc_message(message)
raise Exception("IPC Server Exists: Will send message to it and close...")
settings = Settings()
settings.createWindow()
signals = Signals(args, settings)
if not signals:
raise Exception("Signals exited...")
# Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs.
classes = [Signals(settings)]
classes = [signals]
handlers = {}
for c in classes:
methods = None

View File

@ -12,7 +12,7 @@ tracemalloc.start()
# Gtk imports
import gi, faulthandler, traceback
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import Gtk
# Application imports
from __init__ import Main
@ -24,11 +24,14 @@ if __name__ == "__main__":
faulthandler.enable() # For better debug info
parser = argparse.ArgumentParser()
# Add long and short arguments
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
parser.add_argument("--new-tab", "-t", help="Open a file into new tab.")
parser.add_argument("--new-window", "-w", help="Open a file into a new window.")
# Read arguments (If any...)
args = parser.parse_args()
main = Main(args)
gtk.main()
Main(args)
Gtk.main()
except Exception as e:
traceback.print_exc()
event_system.keep_ipc_alive = False
if debug:
traceback.print_exc()

View File

@ -0,0 +1,52 @@
# Python imports
import threading, socket
from multiprocessing.connection import Listener, Client
# Gtk imports
# Application imports
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper
class DBusControllerMixin:
@threaded
def create_ipc_server(self):
listener = Listener(('127.0.0.1', 4848), authkey=b'pyfm-ipc')
self.is_ipc_alive = True
while event_system.keep_ipc_alive:
conn = listener.accept()
print(f"New Connection: {listener.last_accepted}")
while True:
msg = conn.recv()
print(msg)
if "FILE|" in msg:
file = msg.split("FILE|")[1].strip()
event_system.push_gui_event(["create_tab_from_ipc", None, file])
conn.close()
break
if msg == 'close connection':
conn.close()
break
if msg == 'close server':
conn.close()
event_system.keep_ipc_alive = False
break
listener.close()
def send_ipc_message(self, message="Empty Data..."):
try:
conn = Client(('127.0.0.1', 4848), authkey=b'pyfm-ipc')
conn.send(message)
conn.send('close connection')
except Exception as e:
print(repr(e))

View File

@ -21,7 +21,7 @@ def threaded(fn):
class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
def __init__(self, settings):
def __init__(self, args, settings):
self.settings = settings
self.builder = self.settings.builder
self.logger = self.settings.logger
@ -39,15 +39,15 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
self.to_copy_files = []
self.to_cut_files = []
self.single_click_open = False
self.is_pane1_hidden = False
self.is_pane2_hidden = False
self.is_pane3_hidden = False
self.is_pane4_hidden = False
self.single_click_open = False
self.is_pane1_hidden = False
self.is_pane2_hidden = False
self.is_pane3_hidden = False
self.is_pane4_hidden = False
self.ctrlDown = False
self.shiftDown = False
self.altDown = False
self.ctrlDown = False
self.shiftDown = False
self.altDown = False
self.window.show()
self.generate_windows(self.state)
@ -58,7 +58,8 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
def tear_down(self, widget=None, eve=None):
self.window_controller.save_state()
event_system.monitor_events = False
event_system.send_ipc_message("close server")
event_system.monitor_events = False
time.sleep(event_sleep_time)
Gtk.main_quit()
@ -136,6 +137,8 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
if "alt" in keyname:
self.altDown = False
if self.ctrlDown and keyname == "q":
self.tear_down()
if (self.ctrlDown and keyname == "slash") or keyname == "home":
self.builder.get_object("go_home").released()
if self.ctrlDown and keyname == "r":
@ -159,12 +162,9 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
if self.ctrlDown and keyname == "v":
self.paste_files()
if self.ctrlDown and keyname == "o":
pass
if keyname == "delete":
self.trash_files()
if keyname == "f4":
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
@ -217,14 +217,14 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
self.create_new_view_notebook(None, i, None)
def getClipboardData(self):
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
retcode = proc.wait()
data = proc.stdout.read()
return data.decode("utf-8").strip()
def setClipboardData(self, data):
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
proc.stdin.write(data)
proc.stdin.close()
retcode = proc.wait()
# def getClipboardData(self):
# proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
# retcode = proc.wait()
# data = proc.stdout.read()
# return data.decode("utf-8").strip()
#
# def setClipboardData(self, data):
# proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
# proc.stdin.write(data)
# proc.stdin.close()
# retcode = proc.wait()

View File

@ -2,4 +2,5 @@
Gtk Bound Signal Module
"""
from .mixins import *
from .DBusControllerMixin import DBusControllerMixin
from .Signals import Signals

View File

@ -9,6 +9,12 @@ from . import WidgetMixin
class TabMixin(WidgetMixin):
"""docstring for TabMixin"""
def create_tab_from_ipc(data):
self, path = data
wid, tid = self.window_controller.get_active_data()
self.create_tab(wid, path)
def create_tab(self, wid, path=None):
notebook = self.builder.get_object(f"window_{wid}")
path_entry = self.builder.get_object(f"path_entry")
@ -104,6 +110,7 @@ class TabMixin(WidgetMixin):
if action == "create_tab":
dir = view.get_current_directory()
self.create_tab(wid, dir)
self.window_controller.save_state()
return
if action == "path_entry":
path = widget.get_text()
@ -124,6 +131,7 @@ class TabMixin(WidgetMixin):
tab_label.set_label(view.get_end_of_path())
self.set_window_title()
self.set_file_watcher(view)
self.window_controller.save_state()
def keyboard_close_tab(self):

View File

@ -0,0 +1,11 @@
from setuptools import setup
setup(
name='pyfm',
version='0.0.1',
packages=['pyfm'],
install_requires=[
'setproctitle',
'PyGobject',
],
)