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