You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.9 KiB
110 lines
2.9 KiB
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, resolution): #add parameters for Device class constructor
|
|
self.devices.append(Device(name, resolution))
|
|
|
|
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, resolution):
|
|
self.name = name
|
|
self.resolution = resolution
|
|
self.device_id = gen_id()
|
|
self.widgets = []
|
|
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.
|
|
def __init__(self):
|
|
#instantiate manager class
|
|
self.manager = Manager()
|
|
|
|
def test_manager(self):
|
|
manager_uuid = self.manager_uuid()
|
|
add_device = self.add_device()
|
|
device_uuid = self.device_uuid()
|
|
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):
|
|
dev = self.manager.devices[0]
|
|
uuid_test = dev.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", (1080, 1920))
|
|
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_manager()
|