예제 #1
0
    def reset(self, reset_drink=True):
        if reset_drink:
            DrinksManager.get_instance().set_selected_drink(None)
            self.timeout.stop()

        self.barcode_label.text = None
        self.show_scanned_info(False)
예제 #2
0
    def reset(self, reset_drink=True):
        if reset_drink:
            DrinksManager.get_instance().set_selected_drink(None)
            self.timeout.stop()

        self.barcode_label.text = None
        self.show_scanned_info(False)
예제 #3
0
 def stat_drink(self, args, pos):
     drink = DrinksManager.get_instance().get_selected_drink()
     if drink:
         session = get_session()
         ev = ScanEvent(drink['ean'], 0, datetime.datetime.now())
         session.add(ev)
         session.commit()
         DrinksManager.get_instance().set_selected_drink(None)
     self.reset()
 def on_barcode(self, barcode):
     if not barcode:
         return
     drink = get_by_ean(barcode)
     if drink and ('tags' not in drink or 'unknown' not in drink['tags']):
         from .profile import ProfileScreen
         DrinksManager.get_instance().set_selected_drink(drink)
         ScreenManager.get_instance().set_active(
             ProfileScreen(self.screen, self.user))
         return
     self.set_id(barcode)
 def on_barcode(self, barcode):
     if not barcode:
         return
     drink = get_by_ean(barcode)
     if drink and ('tags' not in drink or 'unknown' not in drink['tags']):
         from .profile import ProfileScreen
         DrinksManager.get_instance().set_selected_drink(drink)
         ScreenManager.get_instance().set_active(
             ProfileScreen(self.screen, self.user)
         )
         return
     self.set_id(barcode)
예제 #6
0
 def stat_drink(self):
     drink = DrinksManager.get_instance().get_selected_drink()
     if drink:
         session = get_session()
         ev = ScanEvent(
             drink['ean'],
             0,
             datetime.datetime.now()
         )
         session.add(ev)
         session.commit()
         DrinksManager.get_instance().set_selected_drink(None)
     self.reset()
예제 #7
0
 def on_barcode(self, barcode):
     if not barcode:
         return
     self.processing.is_visible = True
     user = Users.get_by_id_card(barcode)
     if user:
         ScreenManager.get_instance().set_active(
             ProfileScreen(self.screen, user))
         self.processing.is_visible = False
         return
     drink = get_by_ean(barcode)
     DrinksManager.get_instance().set_selected_drink(drink)
     self.barcode_label.text = drink['name']
     self.show_scanned_info(True)
     self.processing.is_visible = False
     self.timeout.start()
예제 #8
0
 def on_barcode(self, barcode):
     if not barcode:
         return
     self.processing.is_visible = True
     user = Users.get_by_id_card(barcode)
     if user:
         ScreenManager.get_instance().set_active(
             ProfileScreen(self.screen, user)
         )
         self.processing.is_visible = False
         return
     drink = get_by_ean(barcode)
     DrinksManager.get_instance().set_selected_drink(drink)
     self.barcode_label.text = drink['name']
     self.show_scanned_info(True)
     self.processing.is_visible = False
     self.timeout.start()
예제 #9
0
    def save_drink(self, args, pos):
        session = get_session()
        drink = DrinksManager.get_instance().get_selected_drink()
        if not drink:
            return
        ev = ScanEvent(
            drink['ean'],
            self.user['id'],
            datetime.datetime.now()
        )
        session.add(ev)
        session.commit()
        DrinksManager.get_instance().set_selected_drink(None)
        Users.delete_if_nomoney(self.user)

        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(SuccessScreen(self.screen, self.user, drink,
            "getrunken: %s" % drink['name'], session))
예제 #10
0
 def on_barcode(self, barcode):
     if not barcode:
         return
     self.processing.is_visible = True
     user = Users.get_by_id_card(barcode)
     if user:
         ScreenManager.get_instance().set_active(
             ProfileScreen(self.screen, user)
         )
         self.processing.is_visible = False
         return
     drink = get_by_ean(barcode)
     DrinksManager.get_instance().set_selected_drink(drink)
     self.drink_info.text = drink['name']
     if self.zuordnen not in self.objects:
         self.objects.extend([self.zuordnen, self.drink_info])
     if self.btn_aufladungen in self.objects:
         self.objects.remove(self.btn_aufladungen)
     if self.btn_drinks in self.objects:
         self.objects.remove(self.btn_drinks)
     self.processing.is_visible = False
     self.timeout.start()
예제 #11
0
def main(argv):
    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')

    if "--webserver" in argv:
        run_webserver()
        return 0

    if "--stats" in argv:
        stats_send()
        return 0

    screen = get_screen()
    clock = pygame.time.Clock()

    drinks_manager = DrinksManager()
    DrinksManager.set_instance(drinks_manager)

    global screen_manager
    screen_manager = ScreenManager(screen)
    ScreenManager.set_instance(screen_manager)

    init_db()

    # Barcode Scanner #
    barcode_worker = BarcodeWorker()
    barcode_thread = threading.Thread(
        target=run_barcode_reader,
        args=(barcode_worker,)
    )
    barcode_thread.daemon = True
    barcode_thread.start()

    # webserver needs to be a main thread #
    web_thread = subprocess.Popen([sys.argv[0], "--webserver"])

    event_thread = threading.Thread(
        target=handle_events
    )
    event_thread.daemon = True
    event_thread.start()

    stats_thread = threading.Thread(
        target=stats_loop
    )
    stats_thread.daemon = True
    stats_thread.start()

    if env.is_pi():
        os.system("rsync -a sounds/ pi@pixelfun:sounds/ &")

    t = 0
    done = False

    while not done:
        dt = clock.tick(config.FPS) / 1000.0
        t += dt

        current_screen = screen_manager.get_active()

        screen.fill((0, 0, 0))
        current_screen.render(dt)

        pygame.display.flip()

        events = pygame.event.get()
        for e in events:
            e.t = t
            e.dt = dt
            if e.type == pygame.QUIT or (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE):
                done = True
                break
            event_queue.put(e, True)

    web_thread.terminate()
    web_thread.wait()

    return 0
예제 #12
0
    def __init__(self, screen, user, **kwargs):
        super(ProfileScreen, self).__init__(screen)

        self.user = user

        self.objects.append(Button(
            self.screen,
            text = "BACK",
            pos=(30,30),
            font = monospace,
            click=self.back
        ))

        self.objects.append(Button(
            self.screen,
            text = "ID card",
            pos=(340,30),
            font = monospace,
            click=self.id_card
        ))

        self.objects.append(Label(
            self.screen,
            text =self.user["name"],
            pos=(30, 120),
            size=70,
            max_width=335 - 30 - 10,  # balance.x - self.x - margin
        ))

        self.objects.append(Label(
            self.screen,
            text = 'Guthaben',
            pos=(330, 120),
            size=30
        ))

        self.label_verbrauch = Label(
            self.screen,
            text='Bisheriger Verbrauch:',
            pos=(30, 180),
            size=30
        )
        self.label_aufladungen = Label(
            self.screen,
            text='Aufladungen:',
            pos=(30, 180),
            size=30
        )

        self.processing = Label(
            self.screen,
            text="Moment bitte...",
            size=40,
            pos=(150, 750)
        )
        self.processing.is_visible = False
        self.objects.append(self.processing)

        self.timeout = Progress(
            self.screen,
            pos=(200, 50),
            speed=1/30.0,
            on_elapsed=self.time_elapsed,
            click=self.btn_home,
        )
        self.objects.append(self.timeout)
        self.timeout.start()

        drink = DrinksManager.get_instance().get_selected_drink()
        self.drink_info = Label(
            self.screen,
            text=drink['name'] if drink else "",
            size=60,
            pos=(30, 630)
        )

        self.zuordnen = Button(
            self.screen,
            text='Trinken',
            pos=(30, 690),
            size=50,
            click=self.save_drink
        )
        self.btn_aufladungen = Button(
            self.screen,
            text='Aufladungen',
            pos=(30, 700),
            click=self.show_aufladungen
        )
        self.btn_drinks = Button(
            self.screen,
            text='Buchungen',
            pos=(20, 700),
            click=self.show_drinks
        )
        self.btn_abbrechen = Button(
            self.screen,
            text='Abbrechen',
            pos=(290, 700),
            size=30,
            click=self.btn_home,
        )
        self.btn_aufladen = Button(
            self.screen,
            text='Jetzt Aufladen',
            pos=(210, 700),
            size=30,
            click=self.recharge,
        )

        self.elements_aufladungen = [self.btn_drinks, self.label_aufladungen,
            self.btn_aufladen]
        self.elements_drinks = [self.label_verbrauch, self.btn_abbrechen]
        if drink:
            self.elements_drinks.extend([self.zuordnen, self.drink_info])
        else:
            self.elements_drinks.append(self.btn_aufladungen)


        balance = Users.get_balance(self.user['id'])
        self.objects.append(Label(
            self.screen,
            text = str(balance),
            pos=(335, 145),
            size=40
        ))

        drinks = self.get_stats()
        for i, drinks in enumerate(drinks):
            x = 30
            if i == 11:
                self.elements_drinks.append(Label(
                    self.screen,
                    text = "...",
                    pos=(x, 210 + (i * 35))
                ))
                continue
            if i > 11:
                continue
            text = get_by_ean(drinks["name"])['name']
            count_width = 80
            margin_right = 10
            self.elements_drinks.append(Label(
                self.screen,
                text = text,
                pos=(x, 210 + (i * 35)),
                max_width=480-x-margin_right-count_width
            ))
            self.elements_drinks.append(Label(
                self.screen,
                text = str(drinks["count"]),
                align_right=True,
                pos=(480-margin_right, 210 + (i * 35)),
                max_width=count_width
            ))

        self.objects.extend(self.elements_drinks)

        self.render_aufladungen()
예제 #13
0
def main(argv):
    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')

    if "--webserver" in argv:
        run_webserver()
        return 0

    if "--stats" in argv:
        stats_send()
        return 0

    screen = get_screen()
    clock = pygame.time.Clock()

    drinks_manager = DrinksManager()
    DrinksManager.set_instance(drinks_manager)

    global screen_manager
    screen_manager = ScreenManager(screen)
    ScreenManager.set_instance(screen_manager)

    init_db()

    ##### Barcode Scanner #####
    barcode_worker = BarcodeWorker()
    barcode_thread = threading.Thread(target=run_barcode_reader,
                                      args=(barcode_worker, ))
    barcode_thread.daemon = True
    barcode_thread.start()

    ##### webserver needs to be a main thread #####
    web_thread = subprocess.Popen([sys.argv[0], "--webserver"])

    event_thread = threading.Thread(target=handle_events)
    event_thread.daemon = True
    event_thread.start()

    stats_thread = threading.Thread(target=stats_loop)
    stats_thread.daemon = True
    stats_thread.start()

    os.system("rsync -a sounds/ pi@pixelfun:sounds/ &")

    t = 0
    dt = 0
    done = False
    while not done:
        dt = clock.tick(config.FPS) / 1000.0
        t += dt

        current_screen = screen_manager.get_active()

        screen.fill((0, 0, 0))
        current_screen.render(t, dt)

        pygame.display.flip()

        events = pygame.event.get()
        for e in events:
            e.t = t
            e.dt = dt
            if e.type == pygame.QUIT or (e.type == pygame.KEYDOWN
                                         and e.key == pygame.K_ESCAPE):
                done = True
                break
            event_queue.put(e, True)
    web_thread.terminate()
    web_thread.wait()
    return 0