Adding to events system

This commit is contained in:
itdominator 2021-10-13 21:30:08 -05:00
parent 97bf901684
commit 67eed1f87d
3 changed files with 97 additions and 34 deletions

View File

@ -1,34 +1,56 @@
import builtins
class Builtins:
# Makeshift "events" type system FIFO
def push_gui_event(event):
gui_events.append(event)
"""Docstring for __builtins__ extender"""
def push_fm_event(event):
fm_events.append(event)
def __init__(self):
# NOTE: The format used is list of [type, target, data]
# Where data may be any kind of data
self._gui_events = []
self._fm_events = []
def pop_gui_event():
gui_events.pop(0)
# Makeshift fake "events" type system FIFO
def _pop_gui_event(self):
if len(self._gui_events) > 0:
return self._gui_events.pop(0)
return None
def pop_fm_event():
fm_events.pop(0)
def read_gui_event():
return gui_events[0]
def read_fm_event():
return fm_events[0]
def _pop_fm_event(self):
if len(self._fm_events) > 0:
return self._fm_events.pop(0)
return None
builtins.gui_events = []
builtins.fm_events = []
def push_gui_event(self, event):
if len(event) == 3:
self._gui_events.append(event)
return None
# NOTE: Just reminding myself we can add to builtins two different ways...
__builtins__.update({"push_gui_event": push_gui_event})
__builtins__.update({"push_fm_event": push_fm_event})
raise Exception("Invald event format! Please do: [type, target, data]")
builtins.pop_gui_event = pop_gui_event
builtins.pop_fm_event = pop_fm_event
builtins.read_gui_event = read_gui_event
builtins.read_fm_event = read_fm_event
def push_fm_event(self, event):
if len(event) == 3:
self._fm_events.append(event)
return None
raise Exception("Invald event format! Please do: [type, target, data]")
def read_gui_event(self):
return self._gui_events[0]
def read_fm_event(self):
return self._fm_events[0]
def consume_gui_event(self):
return self._pop_gui_event()
def consume_fm_event(self):
return self._pop_fm_event()
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.event_system = Builtins()
builtins.monitor_events = True
builtins.event_sleep_time = 1

View File

@ -1,24 +1,39 @@
# Python imports
import json
import threading, subprocess, time, json
from os import path
# Lib imports
# Application imports
from . import Window
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper
class WindowController:
def __init__(self):
USER_HOME = path.expanduser('~')
CONFIG_PATH = USER_HOME + "/.config/pyfm"
self.session_file = CONFIG_PATH + "/session.json"
USER_HOME = path.expanduser('~')
CONFIG_PATH = USER_HOME + "/.config/pyfm"
self.session_file = CONFIG_PATH + "/session.json"
self.active_window_id = ""
self.active_tab_id = ""
self.windows = []
self._event_sleep_time = 1
self.active_window_id = ""
self.active_tab_id = ""
self.windows = []
self.fm_event_observer()
@threaded
def fm_event_observer(self):
while monitor_events:
time.sleep(event_sleep_time)
event = event_system.consume_fm_event()
print("fm")
if event:
print(event)
def set_active_data(self, wid, tid):
self.active_window_id = str(wid)

View File

@ -1,7 +1,10 @@
# Python imports
import threading, subprocess, os
import threading, subprocess, os, time
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# Application imports
from .mixins import *
@ -13,7 +16,6 @@ from shellfm import WindowController
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper
@ -33,6 +35,12 @@ class Signals(WindowMixin, PaneMixin):
self.window4 = self.builder.get_object("window4")
self.notebooks = [self.window1, self.window2, self.window3, self.window4]
event_system.push_gui_event(["update", "window_1", []])
event_system.push_gui_event(["update", "window_2", []])
event_system.push_fm_event(["update", "window_fm_1", []])
event_system.push_fm_event(["update", "window_fm_2", []])
self.single_click_open = False
self.is_pane1_hidden = False
self.is_pane2_hidden = False
@ -42,6 +50,24 @@ class Signals(WindowMixin, PaneMixin):
self.window.show()
self.generate_windows(self.state)
self.window.connect("delete-event", self.tear_down)
self.gui_event_observer()
@threaded
def gui_event_observer(self):
while monitor_events:
time.sleep(event_sleep_time)
event = event_system.consume_gui_event()
print("gui")
if event:
print(event)
def tear_down(self, widget, eve):
monitor_events = False
time.sleep(2)
gtk.main_quit()
def generate_windows(self, data = None):
if data: