lpcmanager

Moved command evaluator code to LPCCommand.py.
revamp
2018-02-05, Edouard Tisserant
2faf6a91e2d8
Parents a5bf111fe358
Children 163b46d0412b
Moved command evaluator code to LPCCommand.py.
--- a/LPCCommand.py Mon Feb 05 15:45:38 2018 +0100
+++ b/LPCCommand.py Mon Feb 05 15:47:22 2018 +0100
@@ -1,11 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
-from threading import Timer
import cmd
+from threading import Thread, Semaphore, Lock, Timer
from types import StringType, UnicodeType
import wx
+from LPCBus import *
+
+build_lock = Lock()
+wx_eval_lock = Semaphore(0)
+eval_res = None
+
+# Command log for debug, for viewing from wxInspector
+# __builtins__.cmdlog = []
+
+def wx_evaluator(callable, *args, **kwargs):
+ global eval_res
+ eval_res = None
+ try:
+ eval_res = callable(*args, **kwargs)
+ finally:
+ wx_eval_lock.release()
+
+
+def evaluator(callable, *args, **kwargs):
+ global eval_res
+ wx.CallAfter(wx_evaluator, callable, *args, **kwargs)
+ wx_eval_lock.acquire()
+ return eval_res
+
+
def location(loc):
return tuple(map(int, loc.split(".")))
@@ -189,13 +214,8 @@
for child in self.CTR.IterChildren():
if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
- if wx.GetApp() is None:
- self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
- str(new_iec_channel))
- else:
- self.CTR.UpdateProjectVariableLocation(
- str(old_iec_channel),
- str(new_iec_channel))
+ self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
+ str(new_iec_channel))
bus.BaseParams.setIEC_Channel(new_iec_channel)
self.RestartTimer()
--- a/LPCManager.py Mon Feb 05 15:45:38 2018 +0100
+++ b/LPCManager.py Mon Feb 05 15:47:22 2018 +0100
@@ -983,32 +983,6 @@
# slave.BaseParams.setEnabled(False)
slave.CTNRequestSave()
-# -------------------------------------------------------------------------------
-
-from threading import Thread, Semaphore, Lock
-import cmd
-
-build_lock = Lock()
-wx_eval_lock = Semaphore(0)
-eval_res = None
-
-
-def wx_evaluator(callable, *args, **kwargs):
- global eval_res
- eval_res = None
- try:
- eval_res = callable(*args, **kwargs)
- finally:
- wx_eval_lock.release()
-
-
-def evaluator(callable, *args, **kwargs):
- global eval_res
- wx.CallAfter(wx_evaluator, callable, *args, **kwargs)
- wx_eval_lock.acquire()
- return eval_res
-
-
if __name__ == '__main__':