示例#1
0
    def _OnUIButtonClicked(self, button):
        """Handle button clicks.

    Args:
      button(GtkButton): the pressed button.
    """
        label = button.get_label()
        event_type = self._BUTTON_DICT.get(label, None)
        if event_type:
            new_event = events.UIEvent(event_type)
            self.queue.put(new_event)
        else:
            logging.warning(
                'Not implemented button: {0:s} (check self._BUTTON_DICT'.
                format(label))
示例#2
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:
            too_soon = False
            name = self.db.GetNameFromHexID(event.uid)
            delta = constants.SCAN_RATE_LIMIT * 2
            if name in self._last_scanned_names:
                delta = (datetime.datetime.now() -
                         self._last_scanned_names.get(name))
                delta = delta.total_seconds()
            self._last_scanned_names[name] = datetime.datetime.now()

            if delta < constants.SCAN_RATE_LIMIT:
                too_soon = True
            else:
                self.db.AddEntry(event.uid, self._last_taken_picture)
            self.ui.machine.scan(who=name, too_soon=too_soon)
            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.KEYLEFT:
            self.ui.machine.left()
        elif event.type == constants.EVENTTYPES.KEYRIGHT:
            self.ui.machine.right()
        elif event.type == constants.EVENTTYPES.ESCAPE:
            self.ui.machine.back()
        elif event.type == constants.EVENTTYPES.KEYMENU1:
            self.ui.machine.menu1()
        elif event.type == constants.EVENTTYPES.KEYMENU2:
            self.ui.machine.menu2()
        elif event.type == constants.EVENTTYPES.ERROR:
            self.ui.machine.error(error=str(event))
        elif event.type == constants.EVENTTYPES.NOEVENT:
            self.ui.Update()

        self.db.Close()
示例#3
0
文件: sh1106.py 项目: djdeath/beerlog
  def _AddEvent(self, channel):
    """Adds a new events.UIEvent to the Queue.

    Args:
      channel(int): the pin that was detected.
    """

    event_type = self._BUTTON_DICT.get(channel, None)
    if event_type:
      new_event = events.UIEvent(event_type)
      if self._last_event:
        delta = new_event.timestamp - self._last_event.timestamp
        delta_ms = delta.total_seconds() * 1000
        if delta_ms > self.BOUNCE_MS:
          self.queue.put(new_event)
      else:
        self.queue.put(new_event)
      self._last_event = new_event
示例#4
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()