本文整理汇总了Python中listener.Listener类的典型用法代码示例。如果您正苦于以下问题:Python Listener类的具体用法?Python Listener怎么用?Python Listener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Listener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
listener = Listener()
listener.start()
while True:
recv_queue_data = listener.queue.get()
recv_data = recv_queue_data.msgtype
distance = recv_queue_data.msg
if recv_data == 0x05: # Follower to move forward
totalMoves(distance)
print ("Received Follower move forward")
elif recv_data == 0x06: # Follower to move backward
totalMoves(distance)
print ("Received Follower move backward")
elif recv_data == 0x07: # Follower to move left
totalMoves(distance)
print ("Received Follower move left")
elif recv_data == 0x09: # Follower to move right
totalMoves(distance)
print ("Received Follower move right")
elif recv_data == 0x13: # Follower reports found token
followerTokenFND()
elif recv_data == 0x15: # Scanning Follower Servo
print ("Received Scanning Beginning")
elif recv_data == 0x16: # Scan returned Lead Found
scanServo()
elif recv_data == 0x17: # Scan returned Object Found
scanServo()
else:
# Something unexpected happened
print("Received unexpected data %d" % recv_data)
try:
cmdInput(listener.queue)
except KeyboardInterrupt:
pass
listener.close()
示例2: _listener
def _listener(arguments):
"""
Listener subcommand callback
"""
logging.info('Starting Listener')
listener = Listener(silence_time=arguments.silence_time, threshold=arguments.threshold, filename_prefix=arguments.filename_prefix)
listener.get_utterance()
示例3: BluetoothPlugin
class BluetoothPlugin(ConnectionPlugin):
ADDR_FILE = 'config/bluetooth_address'
def __init__(self):
super().__init__()
self.listener = Listener()
self.addr = self.__get_bluetooth_addr()
# API method
def broadcast(self, msg):
print("BROADCASTING")
NetworkScanner(msg).start()
# API method
def run(self):
self.listener.start()
# API method
def address(self):
return self.addr
def __get_bluetooth_addr(self):
with open(BluetoothPlugin.ADDR_FILE, 'r') as file:
addr = file.read()
print("Bluetooth Address: {}".format(addr))
return addr.strip()
示例4: __init__
def __init__(self):
Listener.__init__(self)
self.parser = Parser()
self.connection = Connection()
self.connection.add_listener("readline", self.readline_handler)
self.connection.add_listener("connect", self.connect_handler)
self.connection.add_listener("disconnect", self.disconnect_handler)
self.connection.connect()
示例5: main
def main(argv):
input = FileStream(argv[1])
lexer = aevumLexer(input)
stream = CommonTokenStream(lexer)
parser = aevumParser(stream)
tree = parser.top_level()
listener = Listener()
walker = ParseTreeWalker()
walker.walk(listener, tree)
listener.typecheck()
print(listener.emit())
示例6: DataGen
class DataGen(object):
def __init__(self):
conn1, conn2 = multiprocessing.Pipe()
self.conn = conn2
self.listener = Listener(debug_connection = conn1)
self.listener.start()
self.bpm_to_test = [0]
self.bpm_energies = [0]
def __iter__(self):
return self
def next(self):
while self.conn.poll():
self.bpm_to_test, self.bpm_energies = self.conn.recv()
return (self.bpm_to_test, self.bpm_energies)
示例7: __init__
def __init__(self):
conn1, conn2 = multiprocessing.Pipe()
self.conn = conn2
self.listener = Listener(debug_connection = conn1)
self.listener.start()
self.bpm_to_test = [0]
self.bpm_energies = [0]
示例8: loadLevel
def loadLevel(self):
if self.networkingEnabled:
self.broadcaster = Broadcaster()
self.listener = Listener()
self.listener.start()
self.broadcaster.start()
if self.server or not self.networkingEnabled:
self.remainingIDs.append([1,""])
self.remainingIDs.append([2,""])
示例9: __init__
def __init__(self):
threading.Thread.__init__(self)
self.devices = get_devices()
self.keyfile = ".keymap" # Arquivo padrão para o mapa de caracteres
self.keymap = KeyMap(self.devices)
self.listener = Listener(self.devices)
self.history = History()
self.lock = False
self.listen()
self.copy = False
示例10: main
def main():
"""
Allows Winston to be installed as a package and to be run from the command line.
This simply inits Winston using the config file.
"""
# Define and start a scheduler. These store tasks that are run at given times
scheduler = config.SCHEDULER
scheduler.start()
# Load the commands in the interpreter. These dispatch commands. See the Interpreter's doc for details.
interpreter = Interpreter(scheduler=config.SCHEDULER)
for command in config.COMMANDS:
interpreter.register(command)
# Create a listener for pocketsphinx. It forwards recognized strings to Interpreters. See Listener's doc for details.
listener = Listener(fsg_path=config.GRAMMAR_FILE, dict_path=config.DICT_FILE)
listener.register(interpreter)
# And wait...
raw_input()
示例11: __init__
class DIM:
def __init__(self, host, port):
# sageGate is the network connection with SAGE
self.sageGate = SageGate()
setSageGate(self.sageGate)
# the event manager takes care of properly dispatching events
self.evtMgr = EventManager()
setEvtMgr(self.evtMgr)
self.evtMgr.addHandlers()
# sageData keeps the current state of the SAGE windows/apps
self.sageData = SageData()
setSageData(self.sageData)
# overlay manager creates, destroys and updates overlays
self.overlayMgr = OverlayManager()
setOverlayMgr(self.overlayMgr)
# contains all the devices and takes care of loading plugins for them
# also, distributes HW messages to each device
self.devMgr = DeviceManager()
setDevMgr(self.devMgr)
# connect to SAGE
for i in range(5): # try to connect to SAGE for 5 seconds
if self.sageGate.connectToSage(host, port) != 0:
self.sageGate.registerSage()
break
time.sleep(1)
else: # we didn't manage to connect to sage in 5 seconds... so quit
exitApp()
# start listening for the device events
time.sleep(2) # wait till all the messages come in
self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage)
self.listener.serve_forever()
示例12: EmonHub
def EmonHub():
# Load settings
settings = ConfigObj("emonhub.conf", file_error=True)
# Create queue for node packets
queue = Queue.Queue(0)
# Create and start serial listener
a = Listener(queue,settings)
a.start()
# Create and start http dispatcher
b = Dispatcher(queue,settings)
b.start()
while 1:
try:
time.sleep(0.1)
except KeyboardInterrupt:
print "Stopping threads"
a.stop = True
b.stop = True
break
示例13: init_listener
def init_listener(self, address_list, msg_type_list):
'''Initialise listener that receives messages about new files
to be processed, etc.
'''
# Create Pipe connection
parent_conn, child_conn = Pipe()
self.listener_parent_conn = parent_conn
self.listener_child_conn = child_conn
# Create a Listener instance
self.listener = Listener(address_list=address_list,
msg_type_list=msg_type_list,
pipe=self.listener_child_conn)
#self.listener.add_address_list(address_list)
#self.listener.type_list = msg_type_list
# Create subscriber
#self.listener.create_subscriber()
print "Listener initialised"
示例14: __init__
def __init__(self):
QMainWindow.__init__(self)
# make variables
self.voltage = 0
self.current = 0
# load gui.ui
self.ui = loadUi('../gui/gui.ui')
self.ui.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.ui.destroyed.connect(self.shutdown)
# show window
self.ui.show()
# make new log object
self.log = Log(self.ui)
# make new sender object
self.sender = Sender(self.ui, self.log)
# set events
self.set_events()
# initial reset
self.sender.reset()
# new listener
self.listener = Listener()
# new_data_received signal
self.listener.data_received.connect(self.new_data_received)
# start listener
self.listener.start()
# new interpreter
self.interpreter = Interpreter(self.log, self.ui)
# add tree
self.add_tree()
示例15: play
def play(self, args, local):
# create an intial logger so we can log before args are processed
self.logger = Logger({"verbose": False})
self.drawLogo()
options = self.processArgs(args, local)
self.options = options
# set up the logger with the correct options
self.logger = Logger(self.options)
listener = Listener(self.logger)
listener.onChange(self.processFile)
if os.path.isdir(options['start']) and not os.path.isdir(options['end']):
os.mkdir(options['end'])
if self.options['listen']:
listener.watch(options['start'], options['end'])
else:
listener.process(options['start'], options['end'])
self.logger.log(self.logger.color('Done!', self.logger.PINK))
sys.exit(0)