Closes #22 python docstring documentation

master
Josef Dabrowski 6 years ago
parent 3d236bd02d
commit 09f61f0015

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

Loading…
Cancel
Save