d
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
import memory_Context
|
|
||||||
|
|
||||||
class ContextController:
|
|
||||||
def __init__(self):
|
|
||||||
self.c = memory_createContext()
|
|
||||||
|
|
||||||
def executeFunctions(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def reportCallbacks(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set(self, field, value):
|
|
||||||
setattr(self.c, field, value)
|
|
||||||
self.c.recentField = field
|
|
||||||
self.executeFunctions()
|
|
||||||
self.reportCallbacks()
|
|
||||||
|
|
||||||
ctrl = ContextController()
|
|
||||||
ctrl.callback(printOutput)
|
|
||||||
|
|
||||||
ctrl.set("didLaunch", True)
|
|
||||||
44
v4/Controller.py
Normal file
44
v4/Controller.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import copy
|
||||||
|
|
||||||
|
class Controller:
|
||||||
|
def __init__(self, c):
|
||||||
|
self.callbacks = []
|
||||||
|
self.context = c
|
||||||
|
self.functions = []
|
||||||
|
self.isProcessingQueue = False
|
||||||
|
self.queue = []
|
||||||
|
|
||||||
|
def executeFunctions(self):
|
||||||
|
c = self.queue.pop(0)
|
||||||
|
for f in self.functions:
|
||||||
|
ctx = f(c)
|
||||||
|
if ctx.recentField != "none":
|
||||||
|
self.queue.append(ctx)
|
||||||
|
self.context = c
|
||||||
|
self.reportContext()
|
||||||
|
|
||||||
|
def processQueue(self):
|
||||||
|
# Decline recursion.
|
||||||
|
if self.isProcessingQueue:
|
||||||
|
return
|
||||||
|
self.isProcessingQueue = True
|
||||||
|
while len(self.queue) > 0:
|
||||||
|
self.executeFunctions()
|
||||||
|
self.isProcessingQueue = False
|
||||||
|
|
||||||
|
def registerCallback(self, cb):
|
||||||
|
self.callbacks.append(cb)
|
||||||
|
|
||||||
|
def registerFunction(self, f):
|
||||||
|
self.functions.append(f)
|
||||||
|
|
||||||
|
def reportContext(self):
|
||||||
|
for cb in self.callbacks:
|
||||||
|
cb(self.context)
|
||||||
|
|
||||||
|
def set(self, fieldName, value):
|
||||||
|
c = copy.deepcopy(self.context)
|
||||||
|
setattr(c, fieldName, value)
|
||||||
|
c.recentField = fieldName
|
||||||
|
self.queue.append(c)
|
||||||
|
self.processQueue()
|
||||||
18
v4/main.py
18
v4/main.py
@@ -1,6 +1,7 @@
|
|||||||
from cli import *
|
from cli import *
|
||||||
from cli_test import *
|
from cli_test import *
|
||||||
from memory_test import *
|
from memory_test import *
|
||||||
|
from Controller import *
|
||||||
#from shell import *
|
#from shell import *
|
||||||
#import sys
|
#import sys
|
||||||
|
|
||||||
@@ -20,14 +21,15 @@ print(cli_test_greetUser())
|
|||||||
#print(cli_test_showHelp_h())
|
#print(cli_test_showHelp_h())
|
||||||
#print(cli_test_showHelp_help())
|
#print(cli_test_showHelp_help())
|
||||||
|
|
||||||
|
|
||||||
|
ctrl = Controller(memory_createContext())
|
||||||
|
ctrl.registerFunction(cli_greetUser)
|
||||||
|
ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'"))
|
||||||
|
|
||||||
def printOutput(c):
|
def printOutput(c):
|
||||||
if c.recentField.startswith("output")):
|
if c.recentField.startswith("output"):
|
||||||
print(getatter(c, c.recentField))
|
print(getattr(c, c.recentField))
|
||||||
|
ctrl.registerCallback(printOutput)
|
||||||
ctrl = ContextController()
|
|
||||||
ctrl.callback(printOutput)
|
|
||||||
|
|
||||||
ctrl.set("didLaunch", True)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -46,3 +48,5 @@ ctrl.set("didLaunch", True)
|
|||||||
# if c.exit:
|
# if c.exit:
|
||||||
# break
|
# break
|
||||||
# print(c.output)
|
# print(c.output)
|
||||||
|
|
||||||
|
ctrl.set("didLaunch", True)
|
||||||
|
|||||||
Reference in New Issue
Block a user