From 6079c4fd24aecf2ecfed0528c1427a74d596993f Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 8 Jun 2017 09:56:57 -0400 Subject: drag'n'drop componentList, move component code to core.py FIXME: finish implementing drag'n'drop, Down button --- core.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'core.py') diff --git a/core.py b/core.py index 7b3c69a..0fa5ec5 100644 --- a/core.py +++ b/core.py @@ -12,6 +12,7 @@ import atexit import time from collections import OrderedDict import json +from importlib import import_module class Core(): @@ -26,6 +27,37 @@ class Core(): self.wd = os.path.dirname(os.path.realpath(__file__)) self.loadEncoderOptions() + self.modules = self.findComponents() + self.selectedComponents = [] + + def findComponents(self): + def findComponents(): + srcPath = os.path.join(self.wd, 'components') + if os.path.exists(srcPath): + for f in sorted(os.listdir(srcPath)): + name, ext = os.path.splitext(f) + if name.startswith("__"): + continue + elif ext == '.py': + yield name + return [ + import_module('components.%s' % name) + for name in findComponents()] + + def insertComponent(self, compPos, moduleIndex): + self.selectedComponents.insert( + compPos, + self.modules[moduleIndex].Component()) + return compPos #if compPos > -1 else len(self.selectedComponents)-1 + + def moveComponent(self, startI, endI): + comp = self.selectedComponents.pop(startI) + i = self.selectedComponents.insert(endI, comp) + return i + + def updateComponent(self, i): + self.selectedComponents[i].update() + def loadEncoderOptions(self): file_path = os.path.join(self.wd, 'encoder-options.json') with open(file_path) as json_file: -- cgit v1.2.3