Esempio n. 1
0
    def Loop(self):
        """Main program loop.

    Looks for any new event in the main progrem Queue and processes them.
    """
        while True:
            event = self._events_queue.get()
            if event:
                try:
                    self._HandleEvent(event)
                except Exception as e:  #pylint: disable=broad-except
                    logging.error(e)
                    err_event = events.ErrorEvent('{0!s}'.format(e))
                    self.PushEvent(err_event)

            time.sleep(0.05)
            self.ui.Update()
Esempio n. 2
0
  def ReadTag(self, tag):
    """Reads a tag from the NFC reader.

    Args:
      tag(nfc.tag): the tag object to read.

    Returns:
      bytearray: True if the read operation was successful,
        or None if it wasn't.
    """
    if isinstance(tag, nfc.tag.tt2.Type2Tag):
      uid = NFC215.ReadUIDFromTag(tag)
      try:
        if uid:
          event = NFCEvent(uid=uid)
          self._AddToQueue(event)
        return self._should_beep
      except nfc.tag.tt2.Type2TagCommandError as e:
        event = events.ErrorEvent('{0!s}'.format(e))
    return False
Esempio n. 3
0
    def _HandleEvent(self, event):
        """Does something with an Event.

    Args:
      event(BaseEvent): the event to handle.
    Raises:
      BeerLogError: if an error is detected when handling the event.
    """
        # TODO : have a UI class of events, and let the ui object deal with them
        self.ResetTimers()
        if event.type == constants.EVENTTYPES.NFCSCANNED:
            name = self.db.GetNameFromHexID(event.uid)
            if not name:
                raise errors.BeerLogError(
                    'Could not find the corresponding name for tag id "{0!s}" '
                    'in "{1:s}"'.format(event.uid, self._known_tags))
            character = self.db.GetCharacterFromHexID(event.uid)
            self.db.AddEntry(event.uid, self._last_taken_picture)
            self.ui.machine.scan(who=name, character=character)
            self.AddDelayedEvent(events.UIEvent(constants.EVENTTYPES.ESCAPE),
                                 2)
        elif event.type == constants.EVENTTYPES.KEYUP:
            self.ui.machine.up()
        elif event.type == constants.EVENTTYPES.KEYDOWN:
            self.ui.machine.down()
        elif event.type == constants.EVENTTYPES.ESCAPE:
            self.ui.machine.back()
        elif event.type == constants.EVENTTYPES.KEYMENU1:
            self.ui.machine.back()
        elif event.type == constants.EVENTTYPES.ERROR:
            self.ui.machine.error(error=str(event))
        else:
            err_msg = 'Unknown Event: {0!s}'.format(event)
            print(err_msg)
            self.PushEvent(events.ErrorEvent(err_msg))
            #self.AddDelayedEvent(UIEvent(constants.EVENTTYPES.ESCAPE), 3)

        self.db.Close()