aboutsummaryrefslogtreecommitdiff
path: root/core.py
diff options
context:
space:
mode:
authortassaron2017-06-08 09:56:57 -0400
committertassaron2017-06-08 09:56:57 -0400
commit6079c4fd24aecf2ecfed0528c1427a74d596993f (patch)
treea987cf925b460f786a953880a2cf1f75158082e4 /core.py
parent292d21c20372634f4d0cabf43611d0e50386bc4c (diff)
drag'n'drop componentList, move component code to core.py
FIXME: finish implementing drag'n'drop, Down button
Diffstat (limited to 'core.py')
-rw-r--r--core.py32
1 files changed, 32 insertions, 0 deletions
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: