Adding to events system
This commit is contained in:
parent
97bf901684
commit
67eed1f87d
@ -1,34 +1,56 @@
|
|||||||
import builtins
|
import builtins
|
||||||
|
|
||||||
class Builtins:
|
class Builtins:
|
||||||
# Makeshift "events" type system FIFO
|
"""Docstring for __builtins__ extender"""
|
||||||
def push_gui_event(event):
|
|
||||||
gui_events.append(event)
|
|
||||||
|
|
||||||
def push_fm_event(event):
|
def __init__(self):
|
||||||
fm_events.append(event)
|
# 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():
|
# Makeshift fake "events" type system FIFO
|
||||||
gui_events.pop(0)
|
def _pop_gui_event(self):
|
||||||
|
if len(self._gui_events) > 0:
|
||||||
|
return self._gui_events.pop(0)
|
||||||
|
return None
|
||||||
|
|
||||||
def pop_fm_event():
|
def _pop_fm_event(self):
|
||||||
fm_events.pop(0)
|
if len(self._fm_events) > 0:
|
||||||
|
return self._fm_events.pop(0)
|
||||||
def read_gui_event():
|
return None
|
||||||
return gui_events[0]
|
|
||||||
|
|
||||||
def read_fm_event():
|
|
||||||
return fm_events[0]
|
|
||||||
|
|
||||||
|
|
||||||
builtins.gui_events = []
|
def push_gui_event(self, event):
|
||||||
builtins.fm_events = []
|
if len(event) == 3:
|
||||||
|
self._gui_events.append(event)
|
||||||
|
return None
|
||||||
|
|
||||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
raise Exception("Invald event format! Please do: [type, target, data]")
|
||||||
__builtins__.update({"push_gui_event": push_gui_event})
|
|
||||||
__builtins__.update({"push_fm_event": push_fm_event})
|
|
||||||
|
|
||||||
builtins.pop_gui_event = pop_gui_event
|
def push_fm_event(self, event):
|
||||||
builtins.pop_fm_event = pop_fm_event
|
if len(event) == 3:
|
||||||
builtins.read_gui_event = read_gui_event
|
self._fm_events.append(event)
|
||||||
builtins.read_fm_event = read_fm_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
|
||||||
|
@ -1,24 +1,39 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import json
|
import threading, subprocess, time, json
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from . import Window
|
from . import Window
|
||||||
|
|
||||||
|
|
||||||
|
def threaded(fn):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class WindowController:
|
class WindowController:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
USER_HOME = path.expanduser('~')
|
USER_HOME = path.expanduser('~')
|
||||||
CONFIG_PATH = USER_HOME + "/.config/pyfm"
|
CONFIG_PATH = USER_HOME + "/.config/pyfm"
|
||||||
self.session_file = CONFIG_PATH + "/session.json"
|
self.session_file = CONFIG_PATH + "/session.json"
|
||||||
|
|
||||||
self.active_window_id = ""
|
self._event_sleep_time = 1
|
||||||
self.active_tab_id = ""
|
self.active_window_id = ""
|
||||||
self.windows = []
|
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):
|
def set_active_data(self, wid, tid):
|
||||||
self.active_window_id = str(wid)
|
self.active_window_id = str(wid)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import threading, subprocess, os
|
import threading, subprocess, os, time
|
||||||
|
|
||||||
# Gtk imports
|
# Gtk imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk as gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from .mixins import *
|
from .mixins import *
|
||||||
@ -13,7 +16,6 @@ from shellfm import WindowController
|
|||||||
def threaded(fn):
|
def threaded(fn):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +35,12 @@ class Signals(WindowMixin, PaneMixin):
|
|||||||
self.window4 = self.builder.get_object("window4")
|
self.window4 = self.builder.get_object("window4")
|
||||||
self.notebooks = [self.window1, self.window2, self.window3, self.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.single_click_open = False
|
||||||
self.is_pane1_hidden = False
|
self.is_pane1_hidden = False
|
||||||
self.is_pane2_hidden = False
|
self.is_pane2_hidden = False
|
||||||
@ -42,6 +50,24 @@ class Signals(WindowMixin, PaneMixin):
|
|||||||
self.window.show()
|
self.window.show()
|
||||||
self.generate_windows(self.state)
|
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):
|
def generate_windows(self, data = None):
|
||||||
if data:
|
if data:
|
||||||
|
Loading…
Reference in New Issue
Block a user