|
|
|
|
@ -3,7 +3,6 @@ from collections import namedtuple
|
|
|
|
|
import uuid
|
|
|
|
|
import os
|
|
|
|
|
import toml
|
|
|
|
|
#from preserve import preservable, preserve, restore
|
|
|
|
|
|
|
|
|
|
mydir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
@ -11,22 +10,33 @@ mydir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
# Classes
|
|
|
|
|
#
|
|
|
|
|
class Manager():
|
|
|
|
|
# Manager class to manage a notiframe session.
|
|
|
|
|
"""
|
|
|
|
|
Manager class to manage a notiframe session.
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.manager_id = gen_id()
|
|
|
|
|
self.devices = []
|
|
|
|
|
#widget class register list - updated with available widget classes
|
|
|
|
|
|
|
|
|
|
def add_device(self, name, resolution): # add parameters for Device class constructor
|
|
|
|
|
def add_device(self, name, resolution):
|
|
|
|
|
"""
|
|
|
|
|
Adds a new device to the manager's device list
|
|
|
|
|
"""
|
|
|
|
|
self.devices.append(Device(name, resolution))
|
|
|
|
|
|
|
|
|
|
def remove_device(self, dev_id):
|
|
|
|
|
"""
|
|
|
|
|
Removes a device from the manager's device list
|
|
|
|
|
"""
|
|
|
|
|
for dev in self.devices:
|
|
|
|
|
if dev.device_id == dev_id:
|
|
|
|
|
self.devices.remove(dev)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
def import_config_file(self, path):
|
|
|
|
|
"""
|
|
|
|
|
Loads a config from file into the manager, reconstructs manager state from config
|
|
|
|
|
"""
|
|
|
|
|
# get toml config file, convert to named tuple
|
|
|
|
|
# return named tuple containing all layouts
|
|
|
|
|
config = toml.load(path)
|
|
|
|
|
@ -34,29 +44,15 @@ class Manager():
|
|
|
|
|
self.devices = [Device.load(device_data) for device_data in config['devices']]
|
|
|
|
|
|
|
|
|
|
def export_config_file(self, path):
|
|
|
|
|
"""
|
|
|
|
|
Save the current manager state to file
|
|
|
|
|
"""
|
|
|
|
|
# take tuple containing all layouts and dump as toml
|
|
|
|
|
preserved_data = [device.save() for device in self.devices]
|
|
|
|
|
with open(path, "w+") as config_file:
|
|
|
|
|
config_file.write(toml.dumps({'devices': preserved_data}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def update_config(self, new_config_tuple):
|
|
|
|
|
# new_device_list = []
|
|
|
|
|
# for dev in devices:
|
|
|
|
|
# conf_dev = Conf_device(dev.name, dev.resolution, dev.device_id)
|
|
|
|
|
# new_device_list.append(conf_dev)
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# self.export_config_file(new_config_tuple)
|
|
|
|
|
# #self.update_layout() update devices layouts that need to be updated
|
|
|
|
|
|
|
|
|
|
def update_layout(self, new_layout, device):
|
|
|
|
|
device.layout = new_layout
|
|
|
|
|
|
|
|
|
|
def clear_layout(self, device):
|
|
|
|
|
device.layout = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Device():
|
|
|
|
|
"""
|
|
|
|
|
Device class to contain a device's properties, layout and widgets
|
|
|
|
|
@ -65,6 +61,7 @@ class Device():
|
|
|
|
|
@staticmethod
|
|
|
|
|
def load(saved_state):
|
|
|
|
|
"""
|
|
|
|
|
Loads a device from saved state dict of the device
|
|
|
|
|
"""
|
|
|
|
|
new_device = Device(
|
|
|
|
|
name=saved_state['name'], resolution=saved_state['resolution'], device_id=saved_state['device_id'])
|
|
|
|
|
@ -99,22 +96,25 @@ class Device():
|
|
|
|
|
self.device_image = None
|
|
|
|
|
|
|
|
|
|
def add_widget(self, widget):
|
|
|
|
|
"""
|
|
|
|
|
Adds a new widget to the device's widget list
|
|
|
|
|
"""
|
|
|
|
|
self.widgets.append(widget)
|
|
|
|
|
|
|
|
|
|
class Widget():
|
|
|
|
|
"""
|
|
|
|
|
test
|
|
|
|
|
Widget class to hold properties common to all widgets.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def load(saved_state):
|
|
|
|
|
"""
|
|
|
|
|
test
|
|
|
|
|
Loads a widget from saved state dict of the widget
|
|
|
|
|
"""
|
|
|
|
|
widget_classes = {'Widget': Widget, 'BasicTextWidget': BasicTextWidget} # this list maintained in the module or manager...
|
|
|
|
|
new_widget_class = widget_classes[saved_state['w_type']]
|
|
|
|
|
new_widget = new_widget_class(
|
|
|
|
|
position=saved_state['position'], dimensions=saved_state['dimensions'], widg_id=saved_state['widget_id'])
|
|
|
|
|
position=saved_state['position'], dimensions=saved_state['dimensions'], widget_id=saved_state['widget_id'])
|
|
|
|
|
return new_widget
|
|
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
@ -130,7 +130,7 @@ class Widget():
|
|
|
|
|
|
|
|
|
|
def render(self):
|
|
|
|
|
"""
|
|
|
|
|
returns image of widget
|
|
|
|
|
Returns image of widget
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@ -144,30 +144,36 @@ class Widget():
|
|
|
|
|
|
|
|
|
|
class BasicTextWidget(Widget):
|
|
|
|
|
"""
|
|
|
|
|
test
|
|
|
|
|
A widget that displays a simple string of text
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def load(saved_state):
|
|
|
|
|
"""
|
|
|
|
|
test
|
|
|
|
|
Loads a widget from dict saved state of the widget
|
|
|
|
|
"""
|
|
|
|
|
new_widget = BasicTextWidget(
|
|
|
|
|
position=saved_state['position'], dimensions=saved_state['dimensions'], widg_id=saved_state['widget_id'], text=saved_state['text'])
|
|
|
|
|
position=saved_state['position'], dimensions=saved_state['dimensions'], widget_id=saved_state['widget_id'], text=saved_state['text'])
|
|
|
|
|
return new_widget
|
|
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns a dict with saved state of the widget
|
|
|
|
|
"""
|
|
|
|
|
return_state = super().save()
|
|
|
|
|
return_state['text'] = self.text
|
|
|
|
|
return_state['w_type'] = 'BasicTextWidget'
|
|
|
|
|
return return_state
|
|
|
|
|
|
|
|
|
|
def __init__(self, position, dimensions, widg_id, text):
|
|
|
|
|
super().__init__(position, dimensions, widg_id)
|
|
|
|
|
def __init__(self, position, dimensions, widget_id, text):
|
|
|
|
|
super().__init__(position, dimensions, widget_id)
|
|
|
|
|
|
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
|
|
# Global Functions
|
|
|
|
|
#
|
|
|
|
|
def gen_id():
|
|
|
|
|
"""
|
|
|
|
|
Generates a uuid (v4) string
|
|
|
|
|
"""
|
|
|
|
|
return str(uuid.uuid4())
|
|
|
|
|
|