From 1fca6884eabc4378f71c30f84eead93c9e3bbc7b Mon Sep 17 00:00:00 2001 From: Josef Date: Wed, 11 Dec 2019 18:14:11 +0800 Subject: [PATCH] complete issue 11 added layout class --- notiframe/Notiframe 2.py | 88 ++++++++++++++++++++++++++++++++++++++++ notiframe/Notiframe.py | 18 +++++++- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 notiframe/Notiframe 2.py diff --git a/notiframe/Notiframe 2.py b/notiframe/Notiframe 2.py new file mode 100644 index 0000000..c835d8c --- /dev/null +++ b/notiframe/Notiframe 2.py @@ -0,0 +1,88 @@ +import uuid + +# Classes +# +class Manager(): + # Manager class to manage a notiframe session. + def __init__(self): + self.devices = [] + self.manager_id = gen_id() + + def add_device(self, name): #add parameters for Device class constructor + self.devices.append(Device(name)) + + def remove_device(self, dev_id): + for dev in self.devices: + if dev.device_id == dev_id: + self.devices.remove(dev) + break + +class Device(): + # Device class to contain a device's properties, layout and widgets + def __init__(self, name): + self.name = name + self.device_id = gen_id() + self.widgets = [] + +class Test(): + # Test class to test other classes and their functions. + def __init__(self): + #instantiate manager class + self.manager = Manager() + + def test_all(self): + manager_uuid = self.manager_uuid() + device_uuid = self.device_uuid() + add_device = self.add_device() + remove_device = self.remove_device() + + print("manager id is valid: " + str(manager_uuid)) + print("device id is valid: " + str(device_uuid)) + print("added device: " + str(add_device)) + print("removed device: " + str(remove_device)) + + # Note: Do function wrapper here for tests functions, to say "test_function_name" success/failure + def manager_uuid(self): + uuid_test = self.manager.manager_id + return self.is_valid_uuid(uuid_test) + + def device_uuid(self): + uuid_test = self.device.device_id + return self.is_valid_uuid(uuid_test) + + # Test if manager class's gen_id function produces a valid uuid + def is_valid_uuid(self, val): + try: + uuid.UUID(str(val)) + return True + except ValueError: + return False + + def add_device(self): + len1 = len(self.manager.devices) + self.manager.add_device("test") + len2 = len(self.manager.devices) + if len2 == len1 + 1: + return True + else: + return False + + def remove_device(self): + id = self.manager.devices[0].device_id + len1 = len(self.manager.devices) + self.manager.remove_device(id) + len2 = len(self.manager.devices) + if len2 == len1 - 1: + return True + else: + return False + + +# Global Functions +# +def gen_id(): + return uuid.uuid4() + + +test = Test() +test.test_all() diff --git a/notiframe/Notiframe.py b/notiframe/Notiframe.py index cabda75..ae5e6d0 100644 --- a/notiframe/Notiframe.py +++ b/notiframe/Notiframe.py @@ -24,9 +24,25 @@ class Device(): self.resolution = resolution self.device_id = gen_id() self.widgets = [] - self.layout = None + self.layout = Layout() self.device_image = None +class Layout(): + # Layout class to contain a layout and functions to manipulate that layout. + def __init__(self): + self.layout = {} + + def import_file(self): + return None + + def save_to_file(self): + return None + + def update_layout(self, new_layout): + self.layout = new_layout + + def clear_layout(self): + self.layout = {} class Test(): # Test class to test other classes and their functions.