def __init__(self, screen):
        super(NewIDScreen, self).__init__(screen)

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

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

        self.objects.append(Label(
            self.screen,
            text="Wirf EURO in die Kasse!",
            pos=(30, 120),
            size=50
        ))
        self.objects.append(Label(
            self.screen,
            text="Wie viel hast du eingeworfen?",
            pos=(30, 220),
            size=40
        ))
        self.message = Label(
            self.screen,
            text="",
            pos=(50, 320),
            size=40
        )
        self.objects.append(self.message)

        for i, euro in enumerate([5, 10, 20, 50]):
            self.objects.append(Button(
                self.screen,
                text="EUR " + str(euro),
                pos=((i % 2) * 200 + 30, 600 + (i / 2 * 80)),
                size=30,
                click_func=partial(self.btn_euro, euro)
            ))

        self.progress = Progress(
            self.screen,
            pos=(200, 420),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed
        )
        self.progress.stop()
        self.objects.append(self.progress)
Example #2
0
class SuccessScreen(Screen):
    def __init__(self, screen, user, drink, text, session, **kwargs):
        super(SuccessScreen, self).__init__(screen)

        self.user = user

        self.objects.append(
            Label(self.screen, text='Danke,', pos=(30, 120), size=70))
        self.objects.append(
            Label(self.screen, text=user['name'] + "!", pos=(30, 170),
                  size=70))
        self.objects.append(
            Label(self.screen, text=text, size=45, pos=(30, 250)))

        self.objects.append(
            Label(self.screen, text='Verbleibendes Guthaben: ', pos=(30, 350)))
        self.objects.append(
            Label(
                self.screen,
                text=str(Users.get_balance(self.user['id'], session=session)) +
                ' EUR',
                pos=(50, 400)))

        self.objects.append(
            Button(self.screen,
                   text='OK',
                   pos=(50, 600),
                   size=50,
                   click=self.btn_home))

        self.progress = Progress(self.screen,
                                 pos=(400, 500),
                                 size=80,
                                 on_elapsed=self.home)
        self.objects.append(self.progress)
        self.progress.start()
        balance = Users.get_balance(user['id'])
        if balance >= 0:
            sound = "smb_coin.wav"
        elif balance < -10:
            sound = "alarm.wav"
        else:
            sound = "smb_bowserfalls.wav"
        os.system(
            "ssh -o StrictHostKeyChecking=no pi@pixelfun aplay sounds/%s >/dev/null 2>&1 &"
            % sound)

        if drink:
            send_drink(user, drink, True)

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def btn_home(self, param, pos):
        self.home()
Example #3
0
    def __init__(self, screen, char, **kwargs):
        super(NamesScreen, self).__init__(screen)

        self.char = char

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

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

        self.objects.append(
            Label(
                self.screen,
                text='Wer bist du?',
                pos=(20, 110),
            ))

        users = Users.get_all(self.char)

        btns_y = 7
        num_cols = int(math.ceil(len(users) / float(btns_y)))
        for i, user in enumerate(users):
            padding = 20
            xoff, yoff = 30, 190
            btn_ypos = 90
            i_y = i % btns_y
            i_x = i // btns_y
            x = i_x * (screen.get_width() / num_cols)
            y = i_y * btn_ypos
            self.objects.append(
                Button(self.screen,
                       text=user["name"],
                       pos=(xoff + x, y + yoff),
                       click=self.switch_to_screen,
                       click_param=user,
                       padding=padding))
            i += 1
Example #4
0
    def __init__(self, screen, **kwargs):
        super(MainScreen, self).__init__(screen)

        self.objects.append(Image(self.screen, pos=(30, 20)))

        self.objects.append(
            Label(self.screen,
                  text=u'member auswählen',
                  pos=(65, 250),
                  size=50))

        all_users = Users.get_all()
        i = 0
        for c in range(97, 97 + 26):
            text = str(chr(c))
            users = filter(lambda u: u["name"].lower().startswith(text),
                           all_users)
            if len(users) == 0:
                continue
            self.objects.append(
                Button(
                    self.screen,
                    text=text,
                    pos=self.__get_pos(i),
                    click=self.switch_to_screen,
                    click_param=text,
                    force_width=440 / 6,
                    force_height=440 / 6,
                ))

            i += 1

        self.objects.append(
            Button(
                self.screen,
                text='Abbrechen',
                pos=(150, 700),
                size=30,
                click=self.home,
            ))
        self.timeout = Progress(
            self.screen,
            pos=(380, 715),
            speed=1 / 15.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)
        self.timeout.start()
    def __init__(self, screen, **kwargs):
        super(NewIDScreen, self).__init__(screen)

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

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

        self.objects.append(
            Label(self.screen,
                  text="Wirf EURO in die Kasse!",
                  pos=(30, 120),
                  size=50))
        self.objects.append(
            Label(self.screen,
                  text="Wie viel hast du eingeworfen?",
                  pos=(30, 220),
                  size=40))
        self.message = Label(self.screen, text="", pos=(50, 320), size=40)
        self.objects.append(self.message)

        for i, euro in enumerate([5, 10, 20, 50]):
            self.objects.append(
                Button(self.screen,
                       text="EUR " + str(euro),
                       pos=((i % 2) * 200 + 30, 600 + (i / 2 * 80)),
                       size=30,
                       click=partial(self.btn_euro, euro)))

        self.progress = Progress(self.screen,
                                 pos=(200, 420),
                                 size=100,
                                 speed=1 / 10.0,
                                 on_elapsed=self.time_elapsed)
        self.progress.stop()
        self.objects.append(self.progress)
    def __init__(self, screen, user, drink, text, session):
        super(SuccessScreen, self).__init__(screen)

        self.user = user

        self.objects.append(Label(
            self.screen,
            text='Danke,',
            pos=(30, 120),
            size=70
        ))
        self.objects.append(Label(
            self.screen,
            text=user['name'] + "!",
            pos=(30, 170),
            size=70
        ))
        self.objects.append(Label(
            self.screen,
            text=text,
            size=45,
            pos=(30, 250)
        ))

        self.objects.append(Label(
            self.screen,
            text='Verbleibendes Guthaben: ',
            pos=(30, 350)
        ))
        self.objects.append(Label(
            self.screen,
            text=str(Users.get_balance(self.user['id'], session=session)) + ' EUR',
            pos=(50, 400)
        ))

        self.objects.append(Button(
            self.screen,
            text='OK',
            pos=(50, 600),
            size=50,
            click_func=self.btn_home
        ))

        self.progress = Progress(
            self.screen,
            pos=(400, 500),
            size=80,
            on_elapsed=self.home
        )
        self.objects.append(self.progress)
        self.progress.start()
        balance = Users.get_balance(user['id'])
        if balance >= 0:
            sound = "smb_coin.wav"
        elif balance < -10:
            sound = "alarm.wav"
        else:
            sound = "smb_bowserfalls.wav"
        os.system("ssh -o StrictHostKeyChecking=no pi@pixelfun aplay sounds/%s >/dev/null 2>&1 &" % sound)

        if drink:
            send_drink(user, drink, True)
class NewIDScreen(Screen):
    def __init__(self, screen, **kwargs):
        super(NewIDScreen, self).__init__(screen)

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

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

        self.objects.append(
            Label(self.screen,
                  text="Wirf EURO in die Kasse!",
                  pos=(30, 120),
                  size=50))
        self.objects.append(
            Label(self.screen,
                  text="Wie viel hast du eingeworfen?",
                  pos=(30, 220),
                  size=40))
        self.message = Label(self.screen, text="", pos=(50, 320), size=40)
        self.objects.append(self.message)

        for i, euro in enumerate([5, 10, 20, 50]):
            self.objects.append(
                Button(self.screen,
                       text="EUR " + str(euro),
                       pos=((i % 2) * 200 + 30, 600 + (i / 2 * 80)),
                       size=30,
                       click=partial(self.btn_euro, euro)))

        self.progress = Progress(self.screen,
                                 pos=(200, 420),
                                 size=100,
                                 speed=1 / 10.0,
                                 on_elapsed=self.time_elapsed)
        self.progress.stop()
        self.objects.append(self.progress)

    def back(self, param, pos):
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_euro(self, euro, param, pos):
        try:
            self.message.text = "Konto wird erzeugt..."
            self.progress.speed = 1 / 20.0
            self.progress.start()
            self.progress.on_elapsed = None
            self.progress.value = 0
            user = Users.create_temp_user()
            print "Created temp %s with EUR %d" % (user['id_card'], euro)
            self.progress.value = 0.2
            self.message.text = "Guthaben wird gespeichert..."
            self.aufladen(user, euro)

            barcode = user['id_card']

            self.message.text = "ID-Card wird generiert..."
            code_img = self.generate_barcode(euro, barcode)
            self.progress.value = 0.4
            self.message.text = "reticulating splines..."
            receipt_img = self.generate_receipt(euro, code_img)
            self.progress.value = 0.6
            self.message.text = "reloading fobblewobbles..."
            png = self.to_png(receipt_img)
            self.progress.value = 0.8
            self.message.text = "ID-Card wird gedruckt..."
            self.print_png(png)
            self.progress.on_elapsed = self.time_elapsed
            self.progress.stop()
            ScreenManager.get_instance().set_active(
                ProfileScreen(self.screen, user))
        except Exception as e:
            self.message.text = "Fehler: " + str(e)
            self.progress.value = 0
            self.progress.speed = 1 / 5.0

    def aufladen(self, user, euro):
        session = get_session()
        ev = RechargeEvent(user["id"], user["id"], euro)
        session.add(ev)
        session.commit()

    def generate_barcode(self, euro, barcode):
        enc = Code128Encoder(barcode)
        enc.height = 300
        png = enc.get_imagedata()
        return Image.open(StringIO(png))

    def generate_receipt(self, euro, code_img):
        #width = 136
        width = 500
        #height = int(width*1.4)
        height = int(width * 1)
        img = Image.new("L", (width, height), "white")
        #code_img = code_img.transpose(Image.ROTATE_90)
        code_img = code_img.resize((int(width * 1.13), int(height * 0.5)),
                                   Image.ANTIALIAS)
        #code_img = code_img.resize((int(width * 0.5), int(height * 1.0)), Image.ANTIALIAS)
        #img.paste(code_img, (int(0.4*width), int(0.0*height)))
        img.paste(code_img, (int(-0.07 * width), int(0.2 * height)))

        draw = ImageDraw.Draw(img)
        font = ImageFont.truetype(
            font="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
            size=width / 10)
        draw.text((int(0.05 * width), int(0.0 * height)),
                  "flipdot ID-Card",
                  fill="#000",
                  font=font)
        draw.text((int(0.05 * width), int(0.1 * height)),
                  "Wert: EUR " + str(euro),
                  fill="#000",
                  font=font)
        return img

    def to_png(self, img):
        img.show()
        imgIO = StringIO()
        img.save(imgIO, format="PNG")
        img_data = imgIO.getvalue()
        imgIO.close()
        return img_data

    def print_png(self, img):
        p = subprocess.Popen(['lp', '-d', 'bondrucker', '-'],
                             stdin=subprocess.PIPE)
        p.communicate(input=img)
Example #8
0
class NamesScreen(Screen):
    def __init__(self, screen, char, **kwargs):
        super(NamesScreen, self).__init__(screen)

        self.char = char

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

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

        self.objects.append(
            Label(
                self.screen,
                text='Wer bist du?',
                pos=(20, 110),
            ))

        users = Users.get_all(self.char)

        btns_y = 7
        num_cols = int(math.ceil(len(users) / float(btns_y)))
        for i, user in enumerate(users):
            padding = 20
            xoff, yoff = 30, 190
            btn_ypos = 90
            i_y = i % btns_y
            i_x = i // btns_y
            x = i_x * (screen.get_width() / num_cols)
            y = i_y * btn_ypos
            self.objects.append(
                Button(self.screen,
                       text=user["name"],
                       pos=(xoff + x, y + yoff),
                       click=self.switch_to_screen,
                       click_param=user,
                       padding=padding))
            i += 1

    def back(self, param, pos):
        ScreenManager.get_instance().go_back()

    def switch_to_screen(self, param, pos):
        ScreenManager.get_instance().set_active(
            ProfileScreen(self.screen, param))

    def home(self):
        ScreenManager.get_instance().set_default()

    def time_elapsed(self):
        self.home()

    def on_barcode(self, barcode):
        if not barcode:
            return
        user = Users.get_by_id_card(barcode)
        if user:
            ScreenManager.get_instance().set_active(
                ProfileScreen(self.screen, user))
Example #9
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()
class IDCardScreen(Screen):
    def __init__(self, screen, user, **kwargs):
        super(IDCardScreen, self).__init__(screen)

        self.user = user

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

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

        self.objects.append(
            Button(self.screen,
                   text='Reset',
                   pos=(350, 30),
                   size=30,
                   click=self.reset_id))

        self.objects.append(
            Label(self.screen, text=self.user["name"], pos=(30, 120), size=70))

        self.objects.append(
            Label(self.screen, text="Momentan zugeordnet:", pos=(30, 300)))

        self.id_label = Label(self.screen,
                              text=self.user['id_card'],
                              pos=(50, 400),
                              size=70,
                              font="Serif")
        self.objects.append(self.id_label)

        self.objects.append(
            Label(self.screen, text="Scanne deine ID,", pos=(30, 550),
                  size=60))
        self.objects.append(
            Label(self.screen,
                  text="um sie zuzuweisen.",
                  pos=(30, 600),
                  size=60))

        self.objects.append(
            Button(self.screen,
                   text='OK bye',
                   pos=(330, 700),
                   size=30,
                   click=self.btn_home))

        self.objects.append(
            Button(self.screen,
                   text='Drucken',
                   pos=(30, 700),
                   size=30,
                   click=self.print_id))
        self.progress = Progress(self.screen, pos=(200, 720), speed=1 / 15.0)
        self.progress.stop()
        self.objects.append(self.progress)

    def back(self, param, pos):
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_home(self, param, pos):
        self.home()

    def set_id(self, ean):
        ean = ean.upper() if ean else ean
        self.user['id_card'] = ean
        Users.save(self.user)
        self.id_label.text = self.user['id_card']

    def reset_id(self, param, pos):
        self.set_id(None)

    def print_id(self, param, pos):
        self.progress.start()
        if not self.user['id_card']:
            self.set_id("fd_" + self.user['name'])
        enc = Code128Encoder(self.user['id_card'])
        enc.height = 300
        png = enc.get_imagedata()
        p = subprocess.Popen(['lp', '-d', 'labeldrucker', '-'],
                             stdin=subprocess.PIPE)
        p.communicate(input=png)
        time.sleep(10)

    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)
Example #11
0
class MainScreen(Screen):
    def __init__(self, screen, **kwargs):
        super(MainScreen, self).__init__(screen)

        self.objects.append(Image(self.screen, pos=(30, 20)))

        self.objects.append(
            Label(self.screen,
                  text=u'member auswählen',
                  pos=(65, 250),
                  size=50))

        all_users = Users.get_all()
        i = 0
        for c in range(97, 97 + 26):
            text = str(chr(c))
            users = filter(lambda u: u["name"].lower().startswith(text),
                           all_users)
            if len(users) == 0:
                continue
            self.objects.append(
                Button(
                    self.screen,
                    text=text,
                    pos=self.__get_pos(i),
                    click=self.switch_to_screen,
                    click_param=text,
                    force_width=440 / 6,
                    force_height=440 / 6,
                ))

            i += 1

        self.objects.append(
            Button(
                self.screen,
                text='Abbrechen',
                pos=(150, 700),
                size=30,
                click=self.home,
            ))
        self.timeout = Progress(
            self.screen,
            pos=(380, 715),
            speed=1 / 15.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)
        self.timeout.start()

    def switch_to_screen(self, param, pos):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(NamesScreen(self.screen, param))

    def home(self, param, pos):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance().set_default()

    def time_elapsed(self):
        self.home(None, None)

    def on_barcode(self, barcode):
        from .screen_manager import ScreenManager
        from .profile import ProfileScreen
        if not barcode:
            return
        user = Users.get_by_id_card(barcode)
        if user:
            ScreenManager.get_instance().set_active(
                ProfileScreen(self.screen, user))

    def __get_pos(self, i):

        row = int(i / 6)
        col = int(i % 6)

        return (col * 80 + 30, row * 80 + 350)
    def __init__(self, screen):
        super(WaitScanScreen, self).__init__(screen)

        self.barcode_label = Label(
            self.screen,
            pos=(60, 400),
        )

        self.scanned_info = [
            self.barcode_label,
            Button(
                self.screen,
                pos=(50, 600),
                text="drink buchen",
                size=52,
                click_func=self.set_member
            ),
            Button(
                self.screen,
                pos=(50, 700),
                text="Nur Statistik",
                click_func=self.stat_drink
            ),
            Button(
                self.screen,
                pos=(350, 700),
                text="nope",
                click_func=self.btn_reset
            )
        ]
        self.empty_info = [
            Button(
                self.screen,
                pos=(30, 700),
                text="Benutzer",
                click_func=self.set_member
            ),
            Button(
                self.screen,
                pos=(210, 700),
                text="Geld einwerfen",
                click_func=self.btn_new_id
            )
        ]

        self.objects.append(Image(
            self.screen,
            pos=(30, 20)
        ))

        self.objects.append(Label(
            self.screen,
            text=u"Scanne dein Getränk",
            pos=(60, 240),
        ))
        self.objects.append(Label(
            self.screen,
            text=u"oder deine ID-Card :)",
            pos=(70, 280),
        ))

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

        self.timeout = Progress(
            self.screen,
            pos=(400, 500),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)

        for o in self.scanned_info + self.empty_info:
            self.objects.append(o)

        self.reset()
class RechargeScreen(Screen):
    def __init__(self, screen, user, **kwargs):
        super(RechargeScreen, self).__init__(screen)

        self.user = user

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

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

        qr_file = make_sepa_qr(20,
                               self.user['name'],
                               self.user['id'],
                               pixel_width=7,
                               border=4,
                               color="black",
                               bg="yellow")
        self.select_objects = [
            Button(self.screen,
                   text='EUR 5',
                   pos=(30, 300),
                   size=30,
                   click=partial(self.verify_payment, 5)),
            Button(self.screen,
                   text='EUR 10',
                   pos=(250, 300),
                   size=30,
                   click=partial(self.verify_payment, 10)),
            Button(self.screen,
                   text='EUR 20',
                   pos=(30, 400),
                   size=30,
                   click=partial(self.verify_payment, 20)),
            Button(self.screen,
                   text='EUR 50',
                   pos=(250, 400),
                   size=30,
                   click=partial(self.verify_payment, 50)),
            Label(self.screen,
                  text="Wirf Geld in die Kasse,",
                  pos=(30, 100),
                  size=50),
            Label(self.screen,
                  text=u"und drück den passenden",
                  pos=(30, 150),
                  size=50),
            Label(self.screen, text="Knopf.", pos=(30, 200), size=50),
            Image(self.screen, src=qr_file, pos=(70, 470), size=(300, 330))
        ]
        self.objects.extend(self.select_objects)

        self.verify_objects = [
            Label(self.screen, text="Hast du", pos=(30, 150), size=55),
            Label(self.screen,
                  text="in die Kasse geworfen?",
                  pos=(30, 250),
                  size=55),
            Button(self.screen,
                   text='Ja',
                   pos=(250, 400),
                   size=30,
                   click=self.save_payment)
        ]
        self.verify_amount = Label(self.screen,
                                   text="EUR X",
                                   pos=(30, 200),
                                   size=60)
        self.verify_objects.append(self.verify_amount)

    def back(self, param, pos):
        if self.verify_amount in self.objects:
            for o in self.verify_objects:
                if o in self.objects:
                    self.objects.remove(o)
            self.objects.extend(self.select_objects)
        else:
            screen_manager = ScreenManager.get_instance()
            screen_manager.go_back()

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_home(self, param, pos):
        self.home()

    def verify_payment(self, amount, param, pos):
        amount = int(amount)
        self.payment_amount = amount
        for o in self.select_objects:
            if o in self.objects:
                self.objects.remove(o)
        self.objects.extend(self.verify_objects)
        self.verify_amount.text = "EUR " + str(amount)

    def save_payment(self, param, pos):
        session = get_session()
        ev = RechargeEvent(self.user['id'], 'DISPLAY', self.payment_amount)
        session.add(ev)
        session.commit()

        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(
            SuccessScreen(self.screen, self.user, None,
                          "EUR %s aufgeladen" % self.payment_amount, session))
        self.payment_amount = None
    def __init__(self, screen, user):
        super(EnterPinScreen, self).__init__(screen)
        self.user = user

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

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

        self.objects.append(Button(
            self.screen,
            text="UNLOCK!",
            pos=(100, 680),
            click_func=self.btn_ok,
            font=monospace,
            size=70
        ))

        self.objects.append(Label(
            self.screen,
            text='/s Barcode oder /e PIN:',
            pos=(40, 110),
        ))

        self.input = Label(
            self.screen,
            text='_',
            pos=(100, 180),
        )
        self.objects.append(self.input)

        keys = [
            ['1', '2', '3'],
            ['4', '5', '6'],
            ['7', '8', '9'],
            ['#', '0', '*']
        ]

        x = 0
        y = 0
        for row in keys:
            for label in row:
                self.render_digit_btn(label, x, y)
                x += 1
            x = 0
            y += 1

        self.objects.append(Button(
            self.screen,
            text='DEL',
            pos=(200, 580),
            font=monospace,
            click_func=self.del_char,
            size=50
        ))
class WaitScanScreen(Screen):
    def __init__(self, screen):
        super(WaitScanScreen, self).__init__(screen)

        self.barcode_label = Label(
            self.screen,
            pos=(60, 400),
        )

        self.scanned_info = [
            self.barcode_label,
            Button(
                self.screen,
                pos=(50, 600),
                text="drink buchen",
                size=52,
                click_func=self.set_member
            ),
            Button(
                self.screen,
                pos=(50, 700),
                text="Nur Statistik",
                click_func=self.stat_drink
            ),
            Button(
                self.screen,
                pos=(350, 700),
                text="nope",
                click_func=self.btn_reset
            )
        ]
        self.empty_info = [
            Button(
                self.screen,
                pos=(30, 700),
                text="Benutzer",
                click_func=self.set_member
            ),
            Button(
                self.screen,
                pos=(210, 700),
                text="Geld einwerfen",
                click_func=self.btn_new_id
            )
        ]

        self.objects.append(Image(
            self.screen,
            pos=(30, 20)
        ))

        self.objects.append(Label(
            self.screen,
            text=u"Scanne dein Getränk",
            pos=(60, 240),
        ))
        self.objects.append(Label(
            self.screen,
            text=u"oder deine ID-Card :)",
            pos=(70, 280),
        ))

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

        self.timeout = Progress(
            self.screen,
            pos=(400, 500),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)

        for o in self.scanned_info + self.empty_info:
            self.objects.append(o)

        self.reset()

    def time_elapsed(self):
        self.reset()

    def show_scanned_info(self, show):
        for o in self.scanned_info:
            o.is_visible = show
        for o in self.empty_info:
            o.is_visible = not show

    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()

    def set_member(self):
        main = MainScreen(self.screen)
        ScreenManager.get_instance().set_active(main)
        self.reset(False)

    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()

    def btn_reset(self):
        self.reset()

    def btn_new_id(self):
        new_id = NewIDScreen(self.screen)
        ScreenManager.get_instance().set_active(new_id)

    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)

    @staticmethod
    def back():
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()
class EnterPinScreen(Screen):
    def __init__(self, screen, user):
        super(EnterPinScreen, self).__init__(screen)
        self.user = user

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

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

        self.objects.append(Button(
            self.screen,
            text="UNLOCK!",
            pos=(100, 680),
            click_func=self.btn_ok,
            font=monospace,
            size=70
        ))

        self.objects.append(Label(
            self.screen,
            text='/s Barcode oder /e PIN:',
            pos=(40, 110),
        ))

        self.input = Label(
            self.screen,
            text='_',
            pos=(100, 180),
        )
        self.objects.append(self.input)

        keys = [
            ['1', '2', '3'],
            ['4', '5', '6'],
            ['7', '8', '9'],
            ['#', '0', '*']
        ]

        x = 0
        y = 0
        for row in keys:
            for label in row:
                self.render_digit_btn(label, x, y)
                x += 1
            x = 0
            y += 1

        self.objects.append(Button(
            self.screen,
            text='DEL',
            pos=(200, 580),
            font=monospace,
            click_func=self.del_char,
            size=50
        ))

    def render_digit_btn(self, label, x, y):
        width = 480 / 6
        cord_x = width * 1.8 + x * width
        cord_y = 250 + y * width
        self.objects.append(Button(
            self.screen,
            text=label,
            pos=(cord_x, cord_y),
            click_func_param=self.add_char,
            click_param=label,
            font=monospace,
            size=50,
            force_width=width,
            force_height=width,
        ))

    def add_char(self, param):
        self.input.text = self.input.text.split('_')[0] + param
        self.input.text += '_'

    def del_char(self):
        self.input.text = self.input.text[:len(self.input.text) - 2]
        self.input.text += '_'

    def btn_ok(self):
        # TODO check the pin using
        # self.get_pin() and self.user

        from .screen_manager import ScreenManager
        ScreenManager.get_instance().set_active(
            ProfileScreen(self.screen, self.user)
        )

    def get_pin(self):
        return self.input.text[:len(self.input.text) - 1]

    @staticmethod
    def back():
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    def switch_to_screen(self, param):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(
            ProfileScreen(self.screen, param)
        )

    def on_barcode(self, barcode):
        for c in barcode:
            self.add_char(c)

    @staticmethod
    def home():
        from .screen_manager import ScreenManager
        ScreenManager.get_instance().set_default()

    def time_elapsed(self):
        self.home()
    def __init__(self, screen, user):
        super(RechargeScreen, self).__init__(screen)

        self.user = user
        self.payment_amount = 0

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

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

        qr_file = make_sepa_qr(20, self.user['name'], self.user['id'],
                               pixel_width=7, border=4, color="black", bg="yellow")
        self.select_objects = [
            Button(
                self.screen,
                text='EUR 5',
                pos=(30, 300),
                size=30,
                click_func=partial(self.verify_payment, 5)
            ), Button(
                self.screen,
                text='EUR 10',
                pos=(250, 300),
                size=30,
                click_func=partial(self.verify_payment, 10)
            ), Button(
                self.screen,
                text='EUR 20',
                pos=(30, 400),
                size=30,
                click_func=partial(self.verify_payment, 20)
            ), Button(
                self.screen,
                text='EUR 50',
                pos=(250, 400),
                size=30,
                click_func=partial(self.verify_payment, 50)
            ), Label(
                self.screen,
                text="Wirf Geld in die Kasse,",
                pos=(30, 100),
                size=50
            ), Label(
                self.screen,
                text=u"und drück den passenden",
                pos=(30, 150),
                size=50
            ), Label(
                self.screen,
                text="Knopf.",
                pos=(30, 200),
                size=50
            ), Image(
                self.screen,
                src=qr_file,
                pos=(70, 470),
                size=(300, 330)
            )
        ]
        self.objects.extend(self.select_objects)

        self.verify_objects = [
            Label(
                self.screen,
                text="Hast du",
                pos=(30, 150),
                size=55
            ),
            Label(
                self.screen,
                text="in die Kasse geworfen?",
                pos=(30, 250),
                size=55
            ), Button(
                self.screen,
                text='Ja',
                pos=(250, 400),
                size=30,
                click_func=self.save_payment
            )
        ]
        self.verify_amount = Label(
            self.screen,
            text="EUR X",
            pos=(30, 200),
            size=60
        )
        self.verify_objects.append(self.verify_amount)
class RechargeScreen(Screen):
    def __init__(self, screen, user):
        super(RechargeScreen, self).__init__(screen)

        self.user = user
        self.payment_amount = 0

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

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

        qr_file = make_sepa_qr(20, self.user['name'], self.user['id'],
                               pixel_width=7, border=4, color="black", bg="yellow")
        self.select_objects = [
            Button(
                self.screen,
                text='EUR 5',
                pos=(30, 300),
                size=30,
                click_func=partial(self.verify_payment, 5)
            ), Button(
                self.screen,
                text='EUR 10',
                pos=(250, 300),
                size=30,
                click_func=partial(self.verify_payment, 10)
            ), Button(
                self.screen,
                text='EUR 20',
                pos=(30, 400),
                size=30,
                click_func=partial(self.verify_payment, 20)
            ), Button(
                self.screen,
                text='EUR 50',
                pos=(250, 400),
                size=30,
                click_func=partial(self.verify_payment, 50)
            ), Label(
                self.screen,
                text="Wirf Geld in die Kasse,",
                pos=(30, 100),
                size=50
            ), Label(
                self.screen,
                text=u"und drück den passenden",
                pos=(30, 150),
                size=50
            ), Label(
                self.screen,
                text="Knopf.",
                pos=(30, 200),
                size=50
            ), Image(
                self.screen,
                src=qr_file,
                pos=(70, 470),
                size=(300, 330)
            )
        ]
        self.objects.extend(self.select_objects)

        self.verify_objects = [
            Label(
                self.screen,
                text="Hast du",
                pos=(30, 150),
                size=55
            ),
            Label(
                self.screen,
                text="in die Kasse geworfen?",
                pos=(30, 250),
                size=55
            ), Button(
                self.screen,
                text='Ja',
                pos=(250, 400),
                size=30,
                click_func=self.save_payment
            )
        ]
        self.verify_amount = Label(
            self.screen,
            text="EUR X",
            pos=(30, 200),
            size=60
        )
        self.verify_objects.append(self.verify_amount)

    def back(self):
        if self.verify_amount in self.objects:
            for o in self.verify_objects:
                if o in self.objects:
                    self.objects.remove(o)
            self.objects.extend(self.select_objects)
        else:
            screen_manager = ScreenManager.get_instance()
            screen_manager.go_back()

    @staticmethod
    def home():
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_home(self):
        self.home()

    def verify_payment(self, amount):
        amount = int(amount)
        self.payment_amount = amount
        for o in self.select_objects:
            if o in self.objects:
                self.objects.remove(o)
        self.objects.extend(self.verify_objects)
        self.verify_amount.text = "EUR " + str(amount)

    def save_payment(self):
        session = get_session()
        ev = RechargeEvent(
            self.user['id'],
            'DISPLAY',
            self.payment_amount
        )
        session.add(ev)
        session.commit()

        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(
            SuccessScreen(self.screen, self.user, None,
                          "EUR %s aufgeladen" % self.payment_amount, session))
        self.payment_amount = None
Example #19
0
class EnterPinScreen(Screen):
    def __init__(self, screen, user, **kwargs):
        super(EnterPinScreen, self).__init__(screen)
        self.user = user

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

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

        self.objects.append(
            Button(self.screen,
                   text="UNLOCK!",
                   pos=(100, 680),
                   click=self.btn_ok,
                   font=monospace,
                   size=70))

        self.objects.append(
            Label(
                self.screen,
                text='/s Barcode oder /e PIN:',
                pos=(40, 110),
            ))

        self.input = Label(
            self.screen,
            text='_',
            pos=(100, 180),
        )
        self.objects.append(self.input)

        keys = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'],
                ['#', '0', '*']]

        x = 0
        y = 0
        for row in keys:
            for label in row:
                self.render_digit_btn(label, x, y)
                x += 1
            x = 0
            y += 1

        self.objects.append(
            Button(self.screen,
                   text='DEL',
                   pos=(200, 580),
                   font=monospace,
                   click=self.del_char,
                   size=50))

    def render_digit_btn(self, label, x, y):
        width = 480 / 6
        cord_x = width * 1.8 + x * width
        cord_y = 250 + y * width
        self.objects.append(
            Button(
                self.screen,
                text=label,
                pos=(cord_x, cord_y),
                click=self.add_char,
                click_param=label,
                font=monospace,
                size=50,
                force_width=width,
                force_height=width,
            ))

    def add_char(self, param, pos):
        self.input.text = self.input.text.split('_')[0] + param
        self.input.text += '_'

    def del_char(self, param, pos):
        self.input.text = self.input.text[:len(self.input.text) - 2]
        self.input.text += '_'

    def btn_ok(self, param, pos):
        # TODO check the pin using
        # self.get_pin() and self.user

        from .screen_manager import ScreenManager
        ScreenManager.get_instance().set_active(
            ProfileScreen(self.screen, self.user))

    def get_pin(self):
        return self.input.text[:len(self.input.text) - 1]

    def back(self, param, pos):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    def switch_to_screen(self, param, pos):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(ProfileScreen(self.screen, param))

    def on_barcode(self, barcode):
        for c in barcode:
            self.add_char(c, None)

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance().set_default()

    def time_elapsed(self):
        self.home()
class WaitScanScreen(Screen):
    def __init__(self, screen, **kwargs):
        super(WaitScanScreen, self).__init__(screen)

        self.barcode_label = Label(
            self.screen,
            pos=(60, 400),
        )

        self.scanned_info = [
            self.barcode_label,
            Button(self.screen,
                   pos=(50, 600),
                   text="drink buchen",
                   size=52,
                   click=self.set_member),
            Button(self.screen,
                   pos=(50, 700),
                   text="Nur Statistik",
                   click=self.stat_drink),
            Button(self.screen,
                   pos=(350, 700),
                   text="nope",
                   click=self.btn_reset)
        ]
        self.empty_info = [
            Button(self.screen,
                   pos=(30, 700),
                   text="Benutzer",
                   click=self.set_member),
            Button(self.screen,
                   pos=(210, 700),
                   text="Geld einwerfen",
                   click=self.btn_new_id)
        ]

        self.objects.append(Image(self.screen, pos=(30, 20)))

        self.objects.append(
            Label(
                self.screen,
                text=u"Scanne dein Getränk",
                pos=(60, 240),
            ))
        self.objects.append(
            Label(
                self.screen,
                text=u"oder deine ID-Card :)",
                pos=(70, 280),
            ))

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

        self.timeout = Progress(
            self.screen,
            pos=(400, 500),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)

        for o in self.scanned_info + self.empty_info:
            self.objects.append(o)

        self.reset()

    def time_elapsed(self):
        self.reset()

    def show_scanned_info(self, show):
        for o in self.scanned_info:
            o.is_visible = show
        for o in self.empty_info:
            o.is_visible = not show

    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()

    def set_member(self, args, pos):
        main = MainScreen(self.screen)
        ScreenManager.get_instance().set_active(main)
        self.reset(False)

    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 btn_reset(self, args, pos):
        self.reset()

    def btn_new_id(self, args, pos):
        new_id = NewIDScreen(self.screen)
        ScreenManager.get_instance().set_active(new_id)

    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)

    def back(self, param, pos):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()
Example #21
0
    def __init__(self, screen, user, **kwargs):
        super(EnterPinScreen, self).__init__(screen)
        self.user = user

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

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

        self.objects.append(
            Button(self.screen,
                   text="UNLOCK!",
                   pos=(100, 680),
                   click=self.btn_ok,
                   font=monospace,
                   size=70))

        self.objects.append(
            Label(
                self.screen,
                text='/s Barcode oder /e PIN:',
                pos=(40, 110),
            ))

        self.input = Label(
            self.screen,
            text='_',
            pos=(100, 180),
        )
        self.objects.append(self.input)

        keys = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'],
                ['#', '0', '*']]

        x = 0
        y = 0
        for row in keys:
            for label in row:
                self.render_digit_btn(label, x, y)
                x += 1
            x = 0
            y += 1

        self.objects.append(
            Button(self.screen,
                   text='DEL',
                   pos=(200, 580),
                   font=monospace,
                   click=self.del_char,
                   size=50))
    def __init__(self, screen, user):
        super(IDCardScreen, self).__init__(screen)

        self.user = user

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

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

        self.objects.append(Button(
            self.screen,
            text='Reset',
            pos=(350, 30),
            size=30,
            click_func=self.reset_id
        ))

        self.objects.append(Label(
            self.screen,
            text=self.user["name"],
            pos=(30, 120),
            size=70
        ))

        self.objects.append(Label(
            self.screen,
            text="Momentan zugeordnet:",
            pos=(30, 300)
        ))

        self.id_label = Label(
            self.screen,
            text=self.user['id_card'],
            pos=(50, 400),
            size=70,
            font="Serif"
        )
        self.objects.append(self.id_label)

        self.objects.append(Label(
            self.screen,
            text="Scanne deine ID,",
            pos=(30, 550),
            size=60
        ))
        self.objects.append(Label(
            self.screen,
            text="um sie zuzuweisen.",
            pos=(30, 600),
            size=60
        ))

        self.objects.append(Button(
            self.screen,
            text='OK bye',
            pos=(330, 700),
            size=30,
            click_func=self.btn_home
        ))

        self.objects.append(Button(
            self.screen,
            text='Drucken',
            pos=(30, 700),
            size=30,
            click_func=self.print_id
        ))
        self.progress = Progress(
            self.screen,
            pos=(200, 720),
            speed=1 / 15.0
        )
        self.progress.stop()
        self.objects.append(self.progress)
    def __init__(self, screen, user, **kwargs):
        super(IDCardScreen, self).__init__(screen)

        self.user = user

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

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

        self.objects.append(
            Button(self.screen,
                   text='Reset',
                   pos=(350, 30),
                   size=30,
                   click=self.reset_id))

        self.objects.append(
            Label(self.screen, text=self.user["name"], pos=(30, 120), size=70))

        self.objects.append(
            Label(self.screen, text="Momentan zugeordnet:", pos=(30, 300)))

        self.id_label = Label(self.screen,
                              text=self.user['id_card'],
                              pos=(50, 400),
                              size=70,
                              font="Serif")
        self.objects.append(self.id_label)

        self.objects.append(
            Label(self.screen, text="Scanne deine ID,", pos=(30, 550),
                  size=60))
        self.objects.append(
            Label(self.screen,
                  text="um sie zuzuweisen.",
                  pos=(30, 600),
                  size=60))

        self.objects.append(
            Button(self.screen,
                   text='OK bye',
                   pos=(330, 700),
                   size=30,
                   click=self.btn_home))

        self.objects.append(
            Button(self.screen,
                   text='Drucken',
                   pos=(30, 700),
                   size=30,
                   click=self.print_id))
        self.progress = Progress(self.screen, pos=(200, 720), speed=1 / 15.0)
        self.progress.stop()
        self.objects.append(self.progress)
Example #24
0
class ProfileScreen(Screen):
    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()

    def render_aufladungen(self):
        aufladungen = Users.get_recharges(self.user['id'], limit=12)
        y = 210
        prev_date = None
        for i, aufladung in enumerate(aufladungen):
            x = 30
            if y + 45 * 2 >= self.btn_drinks.pos[1]:
                self.elements_aufladungen.append(Label(self.screen,
                    text="...",
                    pos=(x, y)
                ))
                break
            date = aufladung.timestamp.strftime("%a, %-d.%-m.%Y")
            time = aufladung.timestamp.strftime("%H:%M")
            text = time
            helper = aufladung.helper_user_id
            if helper:
                user = Users.get_by_id(aufladung.helper_user_id)
                if user:
                    helper = user['name']
                text += " mit " + helper
            if date != prev_date:
                prev_date = date
                self.elements_aufladungen.append(Label(self.screen,
                    text=date, size=35,
                    pos=(x, y + 15)
                ))
                y += 45
            count_width = 120
            margin_right = 10
            self.elements_aufladungen.append(Label(self.screen,
                text=text,
                pos=(x + 10, y), size=45,
                max_width=480 - x - margin_right - count_width
            ))
            self.elements_aufladungen.append(Label(
                self.screen,
                text=str(aufladung.amount),
                align_right=True,
                pos=(480 - margin_right, y - 5),
                max_width=count_width
            ))
            y += 35

    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))

    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()

    def back(self, param, pos):
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    def id_card(self, params, pos):
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(IDCardScreen(self.screen, self.user))

    def home(self):
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def btn_home(self, param, pos):
        self.home()

    def time_elapsed(self):
        self.home()

    def recharge(self, params, pos):
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_active(RechargeScreen(self.screen, self.user))

    def show_aufladungen(self, param, pos):
        for d in self.elements_drinks:
            self.objects.remove(d)
        self.objects.extend(self.elements_aufladungen)
        self.timeout.start()

    def show_drinks(self, param, pos):
        for d in self.elements_aufladungen:
            self.objects.remove(d)
        self.objects.extend(self.elements_drinks)
        self.timeout.start()

    def get_stats(self):
        session = get_session()
        sql = text("""
            SELECT COUNT(*) as count, barcode as name
            FROM scanevent
            WHERE user_id = :userid
            GROUP BY barcode
            ORDER by count DESC
        """)
        userid=self.user['id']
        result = session.connection().execute(sql, userid=userid).fetchall()

        return result
    def __init__(self, screen, user, **kwargs):
        super(RechargeScreen, self).__init__(screen)

        self.user = user

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

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

        qr_file = make_sepa_qr(20,
                               self.user['name'],
                               self.user['id'],
                               pixel_width=7,
                               border=4,
                               color="black",
                               bg="yellow")
        self.select_objects = [
            Button(self.screen,
                   text='EUR 5',
                   pos=(30, 300),
                   size=30,
                   click=partial(self.verify_payment, 5)),
            Button(self.screen,
                   text='EUR 10',
                   pos=(250, 300),
                   size=30,
                   click=partial(self.verify_payment, 10)),
            Button(self.screen,
                   text='EUR 20',
                   pos=(30, 400),
                   size=30,
                   click=partial(self.verify_payment, 20)),
            Button(self.screen,
                   text='EUR 50',
                   pos=(250, 400),
                   size=30,
                   click=partial(self.verify_payment, 50)),
            Label(self.screen,
                  text="Wirf Geld in die Kasse,",
                  pos=(30, 100),
                  size=50),
            Label(self.screen,
                  text=u"und drück den passenden",
                  pos=(30, 150),
                  size=50),
            Label(self.screen, text="Knopf.", pos=(30, 200), size=50),
            Image(self.screen, src=qr_file, pos=(70, 470), size=(300, 330))
        ]
        self.objects.extend(self.select_objects)

        self.verify_objects = [
            Label(self.screen, text="Hast du", pos=(30, 150), size=55),
            Label(self.screen,
                  text="in die Kasse geworfen?",
                  pos=(30, 250),
                  size=55),
            Button(self.screen,
                   text='Ja',
                   pos=(250, 400),
                   size=30,
                   click=self.save_payment)
        ]
        self.verify_amount = Label(self.screen,
                                   text="EUR X",
                                   pos=(30, 200),
                                   size=60)
        self.verify_objects.append(self.verify_amount)
class NewIDScreen(Screen):
    def __init__(self, screen):
        super(NewIDScreen, self).__init__(screen)

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

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

        self.objects.append(Label(
            self.screen,
            text="Wirf EURO in die Kasse!",
            pos=(30, 120),
            size=50
        ))
        self.objects.append(Label(
            self.screen,
            text="Wie viel hast du eingeworfen?",
            pos=(30, 220),
            size=40
        ))
        self.message = Label(
            self.screen,
            text="",
            pos=(50, 320),
            size=40
        )
        self.objects.append(self.message)

        for i, euro in enumerate([5, 10, 20, 50]):
            self.objects.append(Button(
                self.screen,
                text="EUR " + str(euro),
                pos=((i % 2) * 200 + 30, 600 + (i / 2 * 80)),
                size=30,
                click_func=partial(self.btn_euro, euro)
            ))

        self.progress = Progress(
            self.screen,
            pos=(200, 420),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed
        )
        self.progress.stop()
        self.objects.append(self.progress)

    @staticmethod
    def back():
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    @staticmethod
    def home():
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_euro(self, euro):
        try:
            self.message.text = "Konto wird erzeugt..."
            self.progress.speed = 1 / 20.0
            self.progress.start()
            self.progress.on_elapsed = None
            self.progress.value = 0
            user = Users.create_temp_user()
            print("Created temp %s with EUR %d" % (user['id_card'], euro))
            self.progress.value = 0.2
            self.message.text = "Guthaben wird gespeichert..."
            self.aufladen(user, euro)

            barcode = user['id_card']

            self.message.text = "ID-Card wird generiert..."
            code_img = self.generate_barcode(barcode)
            self.progress.value = 0.4
            self.message.text = "reticulating splines..."
            receipt_img = self.generate_receipt(euro, code_img)
            self.progress.value = 0.6
            self.message.text = "reloading fobblewobbles..."
            png = self.to_png(receipt_img)
            self.progress.value = 0.8
            self.message.text = "ID-Card wird gedruckt..."
            self.print_png(png)
            self.progress.on_elapsed = self.time_elapsed
            self.progress.stop()
            ScreenManager.get_instance().set_active(
                ProfileScreen(self.screen, user)
            )
        except Exception as e:
            self.message.text = "Fehler: " + str(e)
            self.progress.value = 0
            self.progress.speed = 1 / 5.0

    @staticmethod
    def aufladen(user, euro):
        session = get_session()
        ev = RechargeEvent(
            user["id"],
            user["id"],
            euro
        )
        session.add(ev)
        session.commit()

    @staticmethod
    def generate_barcode(barcode):
        enc = Code128Encoder(barcode)
        enc.height = 300
        png = enc.get_imagedata()
        return Image.open(StringIO(png))

    @staticmethod
    def generate_receipt(euro, code_img):
        # width = 136
        width = 500
        # height = int(width*1.4)
        height = int(width * 1)
        img = Image.new("L", (width, height), "white")
        # code_img = code_img.transpose(Image.ROTATE_90)
        code_img = code_img.resize((int(width * 1.13), int(height * 0.5)), Image.ANTIALIAS)
        # code_img = code_img.resize((int(width * 0.5), int(height * 1.0)), Image.ANTIALIAS)
        # img.paste(code_img, (int(0.4*width), int(0.0*height)))
        img.paste(code_img, (int(-0.07 * width), int(0.2 * height)))

        draw = ImageDraw.Draw(img)
        font = ImageFont.truetype(font="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", size=width / 10)
        draw.text((int(0.05 * width), int(0.0 * height)),
                  "flipdot ID-Card", fill="#000", font=font)
        draw.text((int(0.05 * width), int(0.1 * height)),
                  "Wert: EUR " + str(euro), fill="#000", font=font)
        return img

    @staticmethod
    def to_png(img):
        img.show()
        img_io = StringIO()
        img.save(img_io, format="PNG")
        img_data = img_io.getvalue()
        img_io.close()
        return img_data

    @staticmethod
    def print_png(img):
        p = subprocess.Popen(['lp', '-d', 'bondrucker', '-'], stdin=subprocess.PIPE)
        p.communicate(input=img)
    def __init__(self, screen, **kwargs):
        super(WaitScanScreen, self).__init__(screen)

        self.barcode_label = Label(
            self.screen,
            pos=(60, 400),
        )

        self.scanned_info = [
            self.barcode_label,
            Button(self.screen,
                   pos=(50, 600),
                   text="drink buchen",
                   size=52,
                   click=self.set_member),
            Button(self.screen,
                   pos=(50, 700),
                   text="Nur Statistik",
                   click=self.stat_drink),
            Button(self.screen,
                   pos=(350, 700),
                   text="nope",
                   click=self.btn_reset)
        ]
        self.empty_info = [
            Button(self.screen,
                   pos=(30, 700),
                   text="Benutzer",
                   click=self.set_member),
            Button(self.screen,
                   pos=(210, 700),
                   text="Geld einwerfen",
                   click=self.btn_new_id)
        ]

        self.objects.append(Image(self.screen, pos=(30, 20)))

        self.objects.append(
            Label(
                self.screen,
                text=u"Scanne dein Getränk",
                pos=(60, 240),
            ))
        self.objects.append(
            Label(
                self.screen,
                text=u"oder deine ID-Card :)",
                pos=(70, 280),
            ))

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

        self.timeout = Progress(
            self.screen,
            pos=(400, 500),
            size=100,
            speed=1 / 10.0,
            on_elapsed=self.time_elapsed,
        )
        self.objects.append(self.timeout)

        for o in self.scanned_info + self.empty_info:
            self.objects.append(o)

        self.reset()
class IDCardScreen(Screen):
    def __init__(self, screen, user):
        super(IDCardScreen, self).__init__(screen)

        self.user = user

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

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

        self.objects.append(Button(
            self.screen,
            text='Reset',
            pos=(350, 30),
            size=30,
            click_func=self.reset_id
        ))

        self.objects.append(Label(
            self.screen,
            text=self.user["name"],
            pos=(30, 120),
            size=70
        ))

        self.objects.append(Label(
            self.screen,
            text="Momentan zugeordnet:",
            pos=(30, 300)
        ))

        self.id_label = Label(
            self.screen,
            text=self.user['id_card'],
            pos=(50, 400),
            size=70,
            font="Serif"
        )
        self.objects.append(self.id_label)

        self.objects.append(Label(
            self.screen,
            text="Scanne deine ID,",
            pos=(30, 550),
            size=60
        ))
        self.objects.append(Label(
            self.screen,
            text="um sie zuzuweisen.",
            pos=(30, 600),
            size=60
        ))

        self.objects.append(Button(
            self.screen,
            text='OK bye',
            pos=(330, 700),
            size=30,
            click_func=self.btn_home
        ))

        self.objects.append(Button(
            self.screen,
            text='Drucken',
            pos=(30, 700),
            size=30,
            click_func=self.print_id
        ))
        self.progress = Progress(
            self.screen,
            pos=(200, 720),
            speed=1 / 15.0
        )
        self.progress.stop()
        self.objects.append(self.progress)

    @staticmethod
    def back():
        screen_manager = ScreenManager.get_instance()
        screen_manager.go_back()

    @staticmethod
    def home():
        from .screen_manager import ScreenManager
        screen_manager = ScreenManager.get_instance()
        screen_manager.set_default()

    def time_elapsed(self):
        self.home()

    def btn_home(self):
        self.home()

    def set_id(self, ean):
        ean = ean.upper() if ean else ean
        self.user['id_card'] = ean
        Users.save(self.user)
        self.id_label.text = self.user['id_card']

    def reset_id(self):
        self.set_id(None)

    def print_id(self):
        self.progress.start()
        if not self.user['id_card']:
            self.set_id("fd_" + self.user['name'])
        enc = Code128Encoder(self.user['id_card'])
        enc.height = 300
        png = enc.get_imagedata()
        p = subprocess.Popen(['lp', '-d', 'labeldrucker', '-'], stdin=subprocess.PIPE)
        p.communicate(input=png)
        time.sleep(10)

    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)