threading test
This commit is contained in:
parent
28a3da7e52
commit
fa3a15f5bc
@ -27,11 +27,11 @@ class commandManager():
|
||||
|
||||
def executeCommand(self, environment, currCommand, section = 'commands'):
|
||||
if self.isCommandDefined(environment):
|
||||
#try:
|
||||
environ = environment['commands'][section][currCommand].run(environment)
|
||||
if environ != None:
|
||||
environment = environ
|
||||
#except:
|
||||
try:
|
||||
environ = environment['commands'][section][currCommand].run(environment)
|
||||
if environ != None:
|
||||
environment = environ
|
||||
except:
|
||||
pass
|
||||
environment['commandInfo']['currCommand'] = ''
|
||||
return environment
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/bin/python
|
||||
#from commands import curr_line
|
||||
#from commands import shut_up
|
||||
import time
|
||||
|
||||
commandInfo = {
|
||||
'currCommand': '',
|
||||
'commandCueue':[]
|
||||
'commandCueue':[],
|
||||
'lastCommandTime': time.time()
|
||||
}
|
||||
|
||||
commands = {
|
||||
|
@ -11,15 +11,19 @@ class inputManager():
|
||||
#for dev in self.devices.values(): print(dev)
|
||||
|
||||
def getKeyPressed(self, environment):
|
||||
r, w, x = select(self.devices, [], [])
|
||||
r, w, x = select(self.devices, [], [],0)
|
||||
currShortcut = environment['input']['currShortcut']
|
||||
for fd in r:
|
||||
for event in self.devices[fd].read():
|
||||
if event.type == evdev.ecodes.EV_KEY:
|
||||
if event.value != 0:
|
||||
currShortcut[str(event.code)] = event.value
|
||||
else:
|
||||
del(currShortcut[str(event.code)])
|
||||
if r != []:
|
||||
for fd in r:
|
||||
for event in self.devices[fd].read():
|
||||
if event.type == evdev.ecodes.EV_KEY:
|
||||
if event.value != 0:
|
||||
currShortcut[str(event.code)] = event.value
|
||||
else:
|
||||
try:
|
||||
del(currShortcut[str(event.code)])
|
||||
except:
|
||||
pass
|
||||
environment['input']['currShortcut'] = currShortcut
|
||||
environment['input']['currShortcutString'] = self.getShortcutString(environment)
|
||||
return environment
|
||||
|
@ -41,30 +41,37 @@ class fenrir():
|
||||
self.threadUpdateScreen = Thread(target=self.updateScreen, args=())
|
||||
self.threadHandleInput = Thread(target=self.handleInput, args=())
|
||||
self.threadCommands = Thread(target=self.handleCommands, args=())
|
||||
self.threadUpdateScreen.start()
|
||||
self.threadHandleInput.start()
|
||||
self.threadCommands.start()
|
||||
#self.threadUpdateScreen.start()
|
||||
#self.threadHandleInput.start()
|
||||
#self.threadCommands.start()
|
||||
while(self.environment['generalInformation']['running']):
|
||||
time.sleep(0.2)
|
||||
#starttime = time.time()
|
||||
#time.sleep(0.2)
|
||||
self.updateScreen()
|
||||
self.handleInput()
|
||||
self.handleCommands()
|
||||
#print(time.time() -starttime)
|
||||
self.shutdown()
|
||||
|
||||
def handleInput(self):
|
||||
while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
|
||||
if self.environment['input']['currShortcutString'] == '':
|
||||
self.environment['commandInfo']['currCommand'] = ''
|
||||
#while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
|
||||
#if self.environment['input']['currShortcutString'] == '':
|
||||
# self.environment['commandInfo']['currCommand'] = ''
|
||||
|
||||
def updateScreen(self):
|
||||
while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
||||
#while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
||||
|
||||
def handleCommands(self):
|
||||
while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
|
||||
#self.environment['input']['currShortcut'] = {}
|
||||
if self.environment['commandInfo']['currCommand'] != '':
|
||||
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
||||
time.sleep(0.5)
|
||||
#while(self.environment['generalInformation']['running']):
|
||||
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
|
||||
#self.environment['input']['currShortcut'] = {}
|
||||
print( self.environment['commandInfo']['currCommand'] )
|
||||
if (self.environment['commandInfo']['currCommand'] != '') and \
|
||||
(time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4):
|
||||
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
||||
#time.sleep(0.5)
|
||||
|
||||
def shutdown(self):
|
||||
self.environment['generalInformation']['running'] = False
|
||||
|
@ -10,7 +10,8 @@ import re
|
||||
class screenManager():
|
||||
def __init__(self, device='/dev/vcsa'):
|
||||
self.vcsaDevicePath = device
|
||||
|
||||
self.textWrapper = textwrap.TextWrapper()
|
||||
self.textWrapper.drop_whitespace = False
|
||||
def analyzeScreen(self, environment):
|
||||
# read screen
|
||||
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||
@ -36,10 +37,12 @@ class screenManager():
|
||||
environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('WINDOWS-1250'))
|
||||
#environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('cp1252')).encode('utf-8')[2:]
|
||||
environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2]
|
||||
#environment['screenData']['newContentText'] = '\n'.join(textwrap.wrap(environment['screenData']['newContentText'], environment['screenData']['columns']))[:-2]
|
||||
environment['screenData']['newContentText'] = re.sub("(.{"+ str(environment['screenData']['columns'])+"})", "\\1\n", str(environment['screenData']['newContentText']), 0, re.DOTALL)
|
||||
# environment['screenData']['newContentText'] = '\n'.join(textwrap.wrap(environment['screenData']['newContentText'], environment['screenData']['columns']))[:-2]
|
||||
#environment['screenData']['newContentText'] = re.sub("(.{"+ str(environment['screenData']['columns'])+"})", "\\1\n", str(environment['screenData']['newContentText']), 0, re.DOTALL)
|
||||
environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2]
|
||||
|
||||
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
|
||||
self.textWrapper.width = environment['screenData']['columns']
|
||||
environment['screenData']['oldContentBytes'] = b''
|
||||
environment['screenData']['oldContentAttrib'] = b''
|
||||
environment['screenData']['oldContentText'] = ''
|
||||
|
Loading…
Reference in New Issue
Block a user