Massive structure rewrite
This commit is contained in:
2
objects/__init__.py
Normal file
2
objects/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import display
|
||||
from . import glob
|
||||
@@ -1,24 +1,64 @@
|
||||
displays = {}
|
||||
windows = {}
|
||||
tabs = {}
|
||||
from datetime import datetime
|
||||
|
||||
from . import glob
|
||||
from helpers.uuid import generate as generate_uuid
|
||||
|
||||
class Display:
|
||||
def __init__(self, uuid):
|
||||
self.uuid = uuid
|
||||
self.connections = [] # maybe set()?
|
||||
self.windows = [] # maybe set()?
|
||||
|
||||
def attach(self, connection):
|
||||
self.connections.append(connection)
|
||||
if uuid in glob.displays.keys():
|
||||
raise Exception("Display with this UUID already exists!")
|
||||
glob.displays[uuid] = self
|
||||
|
||||
def detach(self, connection):
|
||||
self.connections.remove(connection)
|
||||
self.uuid = uuid
|
||||
self.connections = set() # maybe set()?
|
||||
self.windows = [] # maybe set()?
|
||||
|
||||
self.title = None
|
||||
self.start_time = int( datetime.now().timestamp() )
|
||||
self.kill_time = self.start_time + glob.config["display"]["timeout"]
|
||||
|
||||
def attach(self, sid):
|
||||
self.connections.add(sid)
|
||||
glob.connections[sid].add(self)
|
||||
|
||||
self.kill_time = None
|
||||
|
||||
def detach(self, sid):
|
||||
self.connections.remove(sid)
|
||||
glob.connections[sid].remove(self)
|
||||
|
||||
if len(self.connections) == 0:
|
||||
self.kill_time = int( datetime.now().timestamp() ) + glob.config["display"]["timeout"]
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
"uuid": self.uuid,
|
||||
"connections": len(self.connections),
|
||||
"title": self.title,
|
||||
"start_time": self.start_time,
|
||||
"kill_time": self.kill_time
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return self.uuid
|
||||
|
||||
@staticmethod
|
||||
def generate():
|
||||
while True:
|
||||
uuid = generate_uuid()
|
||||
if uuid not in glob.displays.keys():
|
||||
break
|
||||
return Display(uuid)
|
||||
|
||||
class Window:
|
||||
def __init__(self, uuid,
|
||||
title = "__unnamed__",
|
||||
grid_column = (0, 0),
|
||||
grid_row = (0, 0)):
|
||||
if uuid in glob.windows.keys():
|
||||
raise Exception("Window with this UUID already exists!")
|
||||
glob.windows[uuid] = self
|
||||
|
||||
self.uuid = uuid
|
||||
self.title = title
|
||||
|
||||
@@ -53,6 +93,10 @@ class Window:
|
||||
class Tab:
|
||||
def __init__(self, uuid,
|
||||
title = "__unnamed__"):
|
||||
if uuid in glob.tabs.keys():
|
||||
raise Exception("Tab with this UUID already exists!")
|
||||
glob.tabs[uuid] = self
|
||||
|
||||
self.uuid = uuid
|
||||
self.content = ""
|
||||
|
||||
|
||||
@@ -2,8 +2,13 @@ import json
|
||||
from flask import Flask
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
app = Flask("__main__")
|
||||
websocket = SocketIO(app)
|
||||
|
||||
with open("config.json", "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
app = Flask("__main__")
|
||||
websocket = SocketIO(app, **config["socket"])
|
||||
|
||||
connections = {}
|
||||
displays = {}
|
||||
windows = {}
|
||||
tabs = {}
|
||||
|
||||
Reference in New Issue
Block a user