Esempio n. 1
0
def on_message(client, userdata, msg):
    logger.debug("Got message:")
    logger.debug(msg.topic + " " + str(msg.payload))

    receipt_printer = get_printer()

    if msg.topic == get_topic("cash_drawer"):
        logger.info("Opening cashdrawer...")
        receipt_printer.cashdraw(settings.CASH_DRAWER_PIN)

    # Commands past here expect a JSON payload:
    try:
        payload = json.loads(msg.payload)
    except json.decoder.JSONDecodeError as e:
        logger.error(e)
        logger.error("Unable to decode message payload from server:")
        logger.error(msg.payload)
        return

    if msg.topic == get_topic("print_cash"):
        print_receipt(receipt_printer, payload, settings.BOTTOM_TEXT_CASH)

    if msg.topic == get_topic("print_credit"):
        print_receipt(receipt_printer, payload, settings.BOTTOM_TEXT_CREDIT)

    # preview badge command chan
    if msg.topic == get_topic("preview"):
        badge_printer = printing.Main(local=True)

        if settings.THEME == "":
            settings.THEME == "apis"
        try:
            badge_printer.nametags(payload.get("badge"), theme=settings.THEME)
            badge_printer.preview()
        except Exception as e:
            logger.error(e)
            logger.error(f"Error on preview")
            logger.error(msg.payload)

    # print badge command chan
    if msg.topic == get_topic("print"):
        badge_printer = printing.Main(local=True)

        if settings.THEME == "":
            settings.THEME == "apis"
        try:
            badge_printer.nametags(payload.get("badges"), theme=settings.THEME)
            badge_printer.printout()
        except Exception as e:
            logger.error(e)
            logger.error(f"Error on print")
            logger.error(msg.payload)

    receipt_printer.close()
Esempio n. 2
0
def print_staff_badges(modeladmin, request, queryset):
    con = printing.Main(local=True)
    tags = []
    for badge in queryset:
        #print the badge
        if badge.badgeNumber is None:
            badgeNumber = ''
        else:
            badgeNumber = 'S{:03}'.format(badge.badgeNumber)
        staff = Staff.objects.get(attendee=badge.attendee,event=badge.event)
        tags.append({
            'name'   : badge.badgeName,
            'number' : badgeNumber,
            'level'  : staff.title,
            'title'  : ''
        })
        badge.printed = True
        badge.save()
    con.nametags(tags, theme='apis')
    # serve up this file
    pdf_path = con.pdf.split('/')[-1]
    response = HttpResponseRedirect(reverse(views.printNametag))
    url_params = {
        'file' : pdf_path,
        'next' : request.get_full_path()
    }
    response['Location'] += '?{}'.format(urlencode(url_params))
    return response
Esempio n. 3
0
def assign_numbers_and_print(modeladmin, request, queryset):
    nonstaff = Attendee.objects.filter(staff=None)
    firstBadge = queryset[0]
    badges = Badge.objects.filter(attendee__in=nonstaff, event=firstBadge.event)
    highest = badges.aggregate(Max('badgeNumber'))['badgeNumber__max']

    for badge in queryset.order_by('registeredDate'):
        if badge.badgeNumber: continue
        if badge.effectiveLevel() == None: continue
        highest = highest + 1
        badge.badgeNumber = highest
        badge.save()

    con = printing.Main(local=True)
    tags = []
    for badge in queryset:
        #print the badge
        if badge.badgeNumber is None:
            badgeNumber = ''
        else:
            badgeNumber = '{:04}'.format(badge.badgeNumber)
        tags.append({
            'name'   : badge.badgeName,
            'number' : badgeNumber,
            'level'  : str(badge.effectiveLevel()),
            'title'  : ''
        })
        badge.printed = True
        badge.save()
    con.nametags(tags, theme='apis')
    # serve up this file
    pdf_path = con.pdf.split('/')[-1]
    response = HttpResponseRedirect(reverse(views.printNametag))
    url_params = {
        'file' : pdf_path,
        'next' : request.get_full_path()
    }
    response['Location'] += '?{}'.format(urlencode(url_params))
    return response
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        self.Bind(wx.EVT_CLOSE, self.close)
        self.Bind(EVT_MQTT_MESSAGE_WAITING, self.processMqtt)

        sizer = wx.BoxSizer(wx.VERTICAL)
        bold = wx.Font(20, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD, False)

        self.snipsBtn = wx.Button(self, wx.ID_ANY, "Idle")
        self.snipsBtn.Bind(wx.EVT_BUTTON, self.close)

        self.dateBtn = wx.Button(self, wx.ID_ANY, "Date Label")
        self.dateBtn.SetFont(bold)
        self.dateBtn.Bind(wx.EVT_BUTTON, self.print_date)

        self.outsideBtn = wx.Button(self, wx.ID_ANY, "Outside Label")
        self.outsideBtn.SetFont(bold)
        self.outsideBtn.Bind(wx.EVT_BUTTON, self.print_outside)

        self.nameBtn = wx.Button(self, wx.ID_ANY, "Name Label")
        self.nameBtn.SetFont(bold)
        self.nameBtn.Bind(wx.EVT_BUTTON, self.show_name_menu)

        music_icon = wx.Bitmap(
            "resources/images/emblem-music-symbolic.symbolic.png")

        self.soundBtn = wx.Button(self, wx.ID_ANY, "Music")
        self.soundBtn.SetFont(bold)
        self.soundBtn.SetBitmap(music_icon)
        self.soundBtn.Bind(wx.EVT_BUTTON, self.show_music_menu)

        self.kitchenBtn = wx.Button(self, wx.ID_ANY, "Kitchen Lights")
        self.kitchenBtn.SetFont(bold)
        self.kitchenBtn.Bind(wx.EVT_BUTTON, self.toggle_kitchen)
        self.kitchenBtn.SetBackgroundColour("#275DAD")
        self.kitchenBtn.SetForegroundColour("white")

        self.diningBtn = wx.Button(self, wx.ID_ANY, "Dining Lights")
        self.diningBtn.SetFont(bold)
        self.diningBtn.Bind(wx.EVT_BUTTON, self.toggle_dining)
        self.diningBtn.SetBackgroundColour("#C1292E")
        self.diningBtn.SetForegroundColour("white")

        self.SetBackgroundColour("black")

        vsizer_left = wx.BoxSizer(wx.VERTICAL)
        vsizer_left.Add(self.dateBtn, -1, wx.ALL | wx.EXPAND, 0)
        vsizer_left.Add(self.outsideBtn, -1, wx.ALL | wx.EXPAND, 0)

        vsizer_right = wx.BoxSizer(wx.VERTICAL)
        vsizer_right.Add(self.nameBtn, -1, wx.ALL | wx.EXPAND, 0)
        vsizer_right.Add(self.soundBtn, -1, wx.ALL | wx.EXPAND, 0)

        hsizer_top = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_top.Add(vsizer_left, -1, wx.ALL | wx.EXPAND, 0)
        hsizer_top.Add(vsizer_right, -1, wx.ALL | wx.EXPAND, 0)

        sizer.Add(self.snipsBtn, -1, wx.ALL | wx.EXPAND, 0)
        sizer.Add(hsizer_top, 2, wx.ALL | wx.EXPAND, 10)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)

        sizer.Add(hsizer, 1, wx.ALL | wx.EXPAND, 10)
        hsizer.Add(self.kitchenBtn, -1, wx.ALL | wx.EXPAND, 0)
        hsizer.Add(self.diningBtn, -1, wx.ALL | wx.EXPAND, 0)
        self.SetSizer(sizer)

        self.namePanel = NamePanel(self)
        self.namePanel.Hide()
        self._bindNameButtons()

        self.musicPanel = MusicPanel(self)
        self.musicPanel.Hide()
        self._bindMusicButtons()
        self.musicPanel.browser.LoadURL(NOW_PLAYING_URI)

        self.printer = printing.Main(False)

        Notify.init("Snips")

        if MQTT_ENABLE:
            self.mqtt = paho.Client()
            self.mqtt.connect("10.0.10.11")
            self.mqtt.on_publish = Controls.on_publish
            self.MQTT_EXIT = threading.Event()
            self.thread = threading.Thread(target=self._mqttWorkerThread)
            self.thread.start()

            self.mqtt.subscribe("homeassistant/light/kitchen/state")
            self.mqtt.subscribe("homeassistant/light/dining_room/state")

        self.buttons = {
            "homeassistant/light/kitchen/state": self.kitchenBtn,
            "homeassistant/light/dining_room/state": self.diningBtn,
        }
Esempio n. 5
0
 def __init__(self):
     self.printer = printing.Main()