Python-With-Gtk-Template/src/__builtins__.py

75 lines
2.0 KiB
Python
Raw Normal View History

2021-10-11 04:33:58 +00:00
import builtins
2022-01-23 22:56:27 +00:00
# Python imports
import builtins
# Lib imports
# Application imports
2022-03-08 00:32:22 +00:00
from utils.ipc_server import IPCServer
2022-01-23 22:56:27 +00:00
2022-02-25 23:53:58 +00:00
class EventSystem(IPCServer):
""" Inheret IPCServerMixin. Create an pub/sub systems. """
2022-01-23 22:56:27 +00:00
def __init__(self):
2022-02-25 23:53:58 +00:00
super(EventSystem, self).__init__()
# NOTE: The format used is list of [type, target, (data,)] Where:
2022-01-30 23:19:46 +00:00
# type is useful context for control flow,
# target is the method to call,
# data is the method parameters to give
2022-01-23 22:56:27 +00:00
# Where data may be any kind of data
self._gui_events = []
2022-02-01 06:03:04 +00:00
self._module_events = []
2022-02-25 23:53:58 +00:00
2022-01-23 22:56:27 +00:00
# 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
2022-02-01 06:03:04 +00:00
def _pop_module_event(self):
if len(self._module_events) > 0:
return self._module_events.pop(0)
2022-01-23 22:56:27 +00:00
return None
def push_gui_event(self, event):
if len(event) == 3:
self._gui_events.append(event)
return None
2022-02-25 23:53:58 +00:00
raise Exception("Invald event format! Please do: [type, target, (data,)]")
2022-01-23 22:56:27 +00:00
2022-02-01 06:03:04 +00:00
def push_module_event(self, event):
2022-01-23 22:56:27 +00:00
if len(event) == 3:
2022-02-01 06:03:04 +00:00
self._module_events.append(event)
2022-01-23 22:56:27 +00:00
return None
2022-02-25 23:53:58 +00:00
raise Exception("Invald event format! Please do: [type, target, (data,)]")
2022-01-23 22:56:27 +00:00
def read_gui_event(self):
return self._gui_events[0]
2022-02-01 06:03:04 +00:00
def read_module_event(self):
return self._module_events[0]
2022-01-23 22:56:27 +00:00
def consume_gui_event(self):
return self._pop_gui_event()
2022-02-01 06:03:04 +00:00
def consume_module_event(self):
return self._pop_module_event()
2021-10-11 04:28:19 +00:00
2021-10-11 04:33:58 +00:00
2021-10-11 04:28:19 +00:00
2022-01-23 22:56:27 +00:00
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.app_name = "<change_me>"
2022-02-25 23:53:58 +00:00
builtins.event_system = EventSystem()
2022-01-23 22:56:27 +00:00
builtins.event_sleep_time = 0.2
builtins.debug = False
builtins.trace_debug = False