backup as im working

This commit is contained in:
trav 2023-06-15 19:49:42 -04:00
parent 2c76f874c4
commit c9b1b99cc0
13 changed files with 972 additions and 6 deletions

Binary file not shown.

View File

@ -50,8 +50,7 @@ void displayMainMenu(int buttonY) {
}
void displayCreateItemScreen(int buttonY) {
textSize(64);
textFont(createFont("SansSerif", 64));
textFont(createFont("Serif", 40));
fill(0); // Black
text("do you have an existing Scuttlebutt account?", width/2, height/4);
@ -121,11 +120,11 @@ buttonNoPressed = false;
void checkButtonHover() {
int buttonY = height/2 + (height - height/2) / 2;
if(state == 0) {
button1Hovered = mouseX > width/3 - 100 && mouseX < width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
button2Hovered = mouseX > 2 * width/3 - 100 && mouseX < 2 * width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
button1Hovered = mouseX > width/3 - 100 && mouseX < width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
button2Hovered = mouseX > 2 * width/3 - 100 && mouseX < 2 * width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
} else if(state == 1) {
buttonYesHovered = mouseX > width/3 - 100 && mouseX < width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
buttonNoHovered = mouseX > 2 * width/3 - 100 && mouseX < 2 * width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
buttonYesHovered = mouseX > width/3 - 100 && mouseX < width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
buttonNoHovered = mouseX > 2 * width/3 - 100 && mouseX < 2 * width/3 + 100 && mouseY > buttonY - 50 && mouseY < buttonY + 50;
}
}

17
description for gpt.txt Normal file
View File

@ -0,0 +1,17 @@
hi. I wonder if you could write a python program for me. The program is a kiosk with a number of different screens. In addition to the buttons described below, each screen also needs a home button in the top left that returns to Screen 0 as well as a back button in the bottom left that goes to the previous screen. Below I've detailed each screen, please generate the corresponding full screen (1366 by 768 resolution) python program:
Screen 0: this is the title screen it has 2 buttons: create Item and Lookup Item. Create Item goes to Screen 1 and Lookup Item goes to Screen 14.
Screen 1: this screen has 2 buttons, Yes and No I Want to Make One Now. Yes goes to Screen 2, No I Want to Make One Now goes to Screen 7.
Screen 2: this screen contains a list that can be scrolled through and once an item from the list a Done button can be selected. The Done button goes to Screen 3.
Screen 3: this screen contains a live video feed from the webcam. There is a button, Take Photo, which causes a 3-2-1 countdown to appear and then the camera video feed is frozen. Once a photo has been taken in this way the Continue button may be pressed which takes us to Screen 5.
Screen 5: this screen contains a text box where the user can enter text. Once any text has been entered a Done button may be pressed which goes to Screen 8.
Screen 6: this screen contains some text and a button that says "I Understand" which goes to Screen 3.
Screen 7: this screen contains a texbox where a user can enter text. Once any text has been entered a Done button may be pressed which goes to Screen 6.
Screen 8: this screen has a rectangle (whose shape is of the ratio 2.25:1.25) where the user can draw. There is 1 button, Done, which when pressed goes to Screen 11.
Screen 9: this screen contains a text box which the user can enter text into. Once any text is entered they may click the Done button which takes us to Screen 10.
Screen 10: this screen says "thank you!" and has a big done button which goes to Screen 0.
Screen 11: this screen has 2 buttons, Sticker and Tag. A printType variable needs to be stored depending on which button is pressed. Both buttons take us to Screen 10.
Screen 12: this screen has 2 buttons, Re-print Tag, which takes us to Screen 8, and Post Update, which takes us to Screen 9.
Screen 14: this screen shows a live video feed. Once a QR code has been detected on the video, the QR code is decoded and stored to a variable. Then the screen changes to Screen 12.
thanks so much!

BIN
drawing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

112
kiosk.py Normal file
View File

@ -0,0 +1,112 @@
import pygame
import sys
# Colors
LIGHT_SKY_BLUE = (135, 206, 235)
BLACK = (0, 0, 0)
PEACH = (255, 218, 185)
# Screen dimensions
SCREEN_WIDTH = 1366
SCREEN_HEIGHT = 768
# Button dimensions
BUTTON_WIDTH = 200
BUTTON_HEIGHT = 100
# Initialize Pygame
pygame.init()
# Create the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.FULLSCREEN)
# Fonts
title_font = pygame.font.SysFont("sans-serif", 64)
subtitle_font = pygame.font.SysFont("serif", 32, italic=True)
button_font = pygame.font.SysFont("sans-serif", 24)
class Button:
def __init__(self, x, y, width, height, text, font, color, action=None):
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.font = font
self.color = color
self.action = action
def display(self):
pygame.draw.rect(screen, self.color, (self.x - self.width/2, self.y - self.height/2, self.width, self.height))
text_surface = self.font.render(self.text, True, BLACK)
text_rect = text_surface.get_rect(center=(self.x, self.y))
screen.blit(text_surface, text_rect)
def is_hovered(self):
mouse_pos = pygame.mouse.get_pos()
return pygame.Rect(self.x - self.width / 2, self.y - self.height / 2, self.width, self.height).collidepoint(mouse_pos)
def is_pressed(self):
return self.is_hovered() and pygame.mouse.get_pressed()[0]
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONUP and self.is_hovered():
if self.action:
self.action()
class Screen:
def __init__(self, buttons, background_color):
self.buttons = buttons
self.background_color = background_color
def handle_event(self, event):
for button in self.buttons:
button.handle_event(event)
def display(self):
screen.fill(self.background_color)
for button in self.buttons:
button.display()
# Define the buttons and screens
buttons_main_menu = [
Button(SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT, "create item", button_font, PEACH),
Button(2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT, "lookup item", button_font, PEACH),
Button(50, 50, 50, 50, "H", button_font, PEACH)
]
buttons_create_item_screen = [
Button(SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT, "yes", button_font, PEACH),
Button(2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT, "no", button_font, PEACH),
Button(50, SCREEN_HEIGHT - 50, 50, 50, "<", button_font, PEACH),
Button(50, 50, 50, 50, "H", button_font, PEACH)
]
main_menu_screen = Screen(buttons_main_menu, LIGHT_SKY_BLUE)
create_item_screen = Screen(buttons_create_item_screen, LIGHT_SKY_BLUE)
# Set the actions of the buttons
def go_to_create_item_screen():
global current_screen
current_screen = create_item_screen
buttons_main_menu[0].action = go_to_create_item_screen
# Game loop
clock = pygame.time.Clock()
running = True
current_screen = main_menu_screen
while running:
clock.tick(60) # Limit the frame rate to 60 FPS
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
else:
current_screen.handle_event(event)
# Render screen
current_screen.display()
pygame.display.flip()

181
kiosk2.py Normal file
View File

@ -0,0 +1,181 @@
import pygame
import sys
# Colors
LIGHT_SKY_BLUE = (135, 206, 235)
BLACK = (0, 0, 0)
PEACH = (255, 218, 185)
DARK_PEACH = (205, 175, 149)
DARKER_PEACH = (235, 200, 175)
YELLOW = (255, 223, 0)
# Screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
# Button dimensions
BUTTON_WIDTH = 200
BUTTON_HEIGHT = 100
# Initialize Pygame
pygame.init()
# Create the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.FULLSCREEN)
# Fonts
title_font = pygame.font.SysFont("sans-serif", 64)
subtitle_font = pygame.font.SysFont("serif", 32, italic=True)
button_font = pygame.font.SysFont("sans-serif", 24)
# Text
title_text = "custodisco"
subtitle_text = "hi, what do you want to do?"
button1_text = "create item"
button2_text = "lookup item"
button_yes_text = "yes"
button_no_text = "no, I'd like to create one now"
# Button states
button1_hovered = False
button2_hovered = False
button1_pressed = False
button2_pressed = False
button_yes_hovered = False
button_no_hovered = False
button_yes_pressed = False
button_no_pressed = False
back_button_hovered = False
back_button_pressed = False
home_button_hovered = False
home_button_pressed = False
# Function to calculate button text dimensions
def calculate_text_dimensions(text, font):
text_width, text_height = font.size(text)
return text_width, text_height
# Function to display text on the screen
def display_text(text, font, color, x, y):
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect(center=(x, y))
screen.blit(text_surface, text_rect)
# Function to display a button
def display_button(text, font, color, x, y, width, height):
pygame.draw.rect(screen, color, (x - width/2, y - height/2, width, height))
text_width, text_height = calculate_text_dimensions(text, font)
display_text(text, font, BLACK, x, y)
# Function to draw a sparkle
def draw_sparkle(x, y):
pygame.draw.line(screen, YELLOW, (x - 10, y - 10), (x + 10, y + 10), 2)
pygame.draw.line(screen, YELLOW, (x + 10, y - 10), (x - 10, y + 10), 2)
pygame.draw.line(screen, YELLOW, (x, y - 15), (x, y + 15), 2)
pygame.draw.line(screen, YELLOW, (x - 15, y), (x + 15, y), 2)
# Main menu screen
def display_main_menu():
screen.fill(LIGHT_SKY_BLUE)
# Title
display_text(title_text, title_font, BLACK, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 4)
draw_sparkle(SCREEN_WIDTH // 2 + 150, SCREEN_HEIGHT // 4 - 20)
# Subtitle
display_text(subtitle_text, subtitle_font, BLACK, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 3)
# Button 1
display_button(button1_text, button_font, PEACH, SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
# Button 2
display_button(button2_text, button_font, PEACH, 2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
# Home button
display_button("H", button_font, PEACH, 50, 50, 50, 50)
# Create item screen
def display_create_item_screen():
screen.fill(LIGHT_SKY_BLUE)
# Title
title_width, _ = calculate_text_dimensions("do you have an existing Scuttlebutt account?", subtitle_font)
title_x = SCREEN_WIDTH // 2
title_y = SCREEN_HEIGHT // 4
display_text("do you have an existing Scuttlebutt account?", subtitle_font, BLACK, title_x, title_y)
# Button "Yes"
display_button(button_yes_text, button_font, PEACH, SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
# Button "No"
display_button(button_no_text, button_font, PEACH, 2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
# Back button
display_button("<", button_font, PEACH, 50, SCREEN_HEIGHT - 50, 50, 50)
# Home button
display_button("H", button_font, PEACH, 50, 50, 50, 50)
# Game loop
clock = pygame.time.Clock()
running = True
state = "main_menu" # Initial state
while running:
clock.tick(60) # Limit the frame rate to 60 FPS
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if state == "main_menu":
if button1_hovered:
button1_pressed = True
elif button2_hovered:
button2_pressed = True
elif home_button_hovered:
state = "main_menu"
elif state == "create_item_screen":
if button_yes_hovered:
button_yes_pressed = True
elif button_no_hovered:
button_no_pressed = True
elif back_button_hovered:
state = "main_menu"
elif home_button_hovered:
state = "main_menu"
elif event.type == pygame.MOUSEBUTTONUP:
if state == "main_menu":
if button1_pressed and button1_hovered:
state = "create_item_screen"
print("Going to create item screen")
elif button2_pressed and button2_hovered:
print("Going to lookup item screen")
button1_pressed = False
button2_pressed = False
elif state == "create_item_screen":
if button_yes_pressed and button_yes_hovered:
print("You selected Yes")
elif button_no_pressed and button_no_hovered:
print("You selected No")
button_yes_pressed = False
button_no_pressed = False
# Update button states
mouse_pos = pygame.mouse.get_pos()
button1_hovered = pygame.Rect(SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
button2_hovered = pygame.Rect(2 * SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
button_yes_hovered = pygame.Rect(SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
button_no_hovered = pygame.Rect(2 * SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
back_button_hovered = pygame.Rect(50 - 25, SCREEN_HEIGHT - 50 - 25, 50, 50).collidepoint(mouse_pos)
home_button_hovered = pygame.Rect(50 - 25, 50 - 25, 50, 50).collidepoint(mouse_pos)
# Render screen based on state
if state == "main_menu":
display_main_menu()
elif state == "create_item_screen":
display_create_item_screen()
pygame.display.flip()

91
kiosk3.py Normal file
View File

@ -0,0 +1,91 @@
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.stacked_widget = QStackedWidget()
self.setCentralWidget(self.stacked_widget)
self.screens = {
"Screen0": Screen0(self),
"Screen1": Screen1(self),
"Screen2": Screen2(self),
"Screen3": Screen3(self),
"Screen5": Screen5(self),
"Screen6": Screen6(self),
"Screen7": Screen7(self),
"Screen8": Screen8(self),
"Screen9": Screen9(self),
"Screen10": Screen10(self),
"Screen11": Screen11(self),
"Screen12": Screen12(self),
"Screen14": Screen14(self),
}
for screen in self.screens.values():
self.stacked_widget.addWidget(screen)
self.stacked_widget.setCurrentWidget(self.screens["Screen0"])
def go_to_screen(self, screen_name):
self.stacked_widget.setCurrentWidget(self.screens[screen_name])
class BaseScreen(QWidget):
def __init__(self, main_window, parent=None):
super(BaseScreen, self).__init__(parent)
self.main_window = main_window
self.layout = QVBoxLayout()
self.home_button = QPushButton('Home')
self.home_button.clicked.connect(lambda: self.main_window.go_to_screen("Screen0"))
self.layout.addWidget(self.home_button)
self.back_button = QPushButton('Back')
# TODO: implement back functionality
self.layout.addWidget(self.back_button)
self.setLayout(self.layout)
class Screen0(BaseScreen):
def __init__(self, main_window, parent=None):
super(Screen0, self).__init__(main_window, parent)
self.create_item_button = QPushButton('Create Item')
self.create_item_button.clicked.connect(lambda: self.main_window.go_to_screen("Screen1"))
self.layout.addWidget(self.create_item_button)
self.lookup_item_button = QPushButton('Lookup Item')
self.lookup_item_button.clicked.connect(lambda: self.main_window.go_to_screen("Screen14"))
self.layout.addWidget(self.lookup_item_button)
class Screen1(BaseScreen):
def __init__(self, main_window, parent=None):
super(Screen1, self).__init__(main_window, parent)
self.yes_button = QPushButton('Yes')
self.yes_button.clicked.connect(lambda: self.main_window.go_to_screen("Screen2"))
self.layout.addWidget(self.yes_button)
self.no_button = QPushButton('No I Want to Make One Now')
self.no_button.clicked.connect(lambda: self.main_window.go_to_screen("Screen7"))
self.layout.addWidget(self.no_button)
# ... other screens ...
class Screen14(BaseScreen):
def __init__(self, main_window, parent=None):
super(Screen14, self).__init__(main_window, parent)
self.qr_button = QPushButton('QR')
# TODO: Implement QR functionality
self.layout.addWidget(self.qr_button)
if __name__ == '__main__':
app = QApplication([])
window = MainWindow()
window.showFullScreen()
app.exec_()

76
kiosk4.py Normal file
View File

@ -0,0 +1,76 @@
import pygame
import sys
class Button:
def __init__(self, x, y, w, h, text, callback):
self.rect = pygame.Rect(x, y, w, h)
self.text = text
self.callback = callback
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.callback()
def draw(self, screen):
pygame.draw.rect(screen, (255, 255, 255), self.rect)
font = pygame.font.Font(None, 36)
text_surf = font.render(self.text, True, (0, 0, 0))
screen.blit(text_surf, (self.rect.x + 10, self.rect.y + 10))
class Screen:
def __init__(self):
self.buttons = []
def handle_event(self, event):
for button in self.buttons:
button.handle_event(event)
def draw(self, screen):
for button in self.buttons:
button.draw(screen)
class Screen0(Screen):
def __init__(self, screens):
super().__init__()
self.buttons.append(Button(50, 50, 200, 100, "Create Item", lambda: screens.set_current("Screen1")))
self.buttons.append(Button(50, 200, 200, 100, "Lookup Item", lambda: screens.set_current("Screen14")))
# ... other screens ...
class Screens:
def __init__(self):
self.screens = {
"Screen0": Screen0(self),
# ... other screens ...
}
self.current = self.screens["Screen0"]
def set_current(self, name):
self.current = self.screens[name]
def handle_event(self, event):
self.current.handle_event(event)
def draw(self, screen):
self.current.draw(screen)
def main():
pygame.init()
screen = pygame.display.set_mode((1366, 768))
screens = Screens()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screens.handle_event(event)
screen.fill((0, 0, 0))
screens.draw(screen)
pygame.display.flip()
if __name__ == "__main__":
main()

107
kiosk5.py Normal file
View File

@ -0,0 +1,107 @@
import tkinter as tk
from tkinter import font as tkfont
class Kiosk(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.frame = None
self.frames_history = []
self.geometry('1366x768')
self.attributes('-fullscreen', True)
self.switch_frame(Screen0)
def switch_frame(self, frame_class, keep_history=True):
if keep_history and self.frame:
self.frames_history.append(type(self.frame))
new_frame = frame_class(self)
if self.frame is not None:
self.frame.destroy()
self.frame = new_frame
self.frame.pack(fill="both", expand=True)
def back_frame(self):
if self.frames_history:
self.switch_frame(self.frames_history.pop(), keep_history=False)
class Screen0(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
title_font = tkfont.Font(size=30, family='Helvetica')
tk.Label(self, text="Custodisco ✨", bg='#bcfef9', font=title_font).pack()
tk.Button(self, text="Create Item", command=lambda: master.switch_frame(Screen1)).pack()
tk.Button(self, text="Lookup Item", command=lambda: master.switch_frame(Screen14)).pack()
class Screen1(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Yes", command=lambda: master.switch_frame(Screen2)).pack()
tk.Button(self, text="No I Want to Make One Now", command=lambda: master.switch_frame(Screen7)).pack()
class Screen2(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="List Placeholder").pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen3)).pack()
class Screen3(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Take Photo", command=lambda: master.switch_frame(Screen5)).pack()
class Screen5(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="Text Entry Placeholder").pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen8)).pack()
class Screen6(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="Some Text").pack()
tk.Button(self, text="I Understand", command=lambda: master.switch_frame(Screen3)).pack()
class Screen7(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="Text Entry Placeholder").pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen6)).pack()
class Screen8(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen11)).pack()
class Screen9(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="Text Entry Placeholder").pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen10)).pack()
class Screen10(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="Thank you!").pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen0)).pack()
class Screen11(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Sticker", command=lambda: master.switch_frame(Screen10)).pack()
tk.Button(self, text="Tag", command=lambda: master.switch_frame(Screen10)).pack()
class Screen12(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Re-print Tag", command=lambda: master.switch_frame(Screen8)).pack()
tk.Button(self, text="Post Update", command=lambda: master.switch_frame(Screen9)).pack()
class Screen14(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen12)).pack()
if __name__ == "__main__":
app = Kiosk()
app.mainloop()

208
kiosk6.py Normal file
View File

@ -0,0 +1,208 @@
import tkinter as tk
from tkinter import font as tkfont
from tkinter import Canvas
from tkinter import ttk
from PIL import Image, ImageDraw
import tozpl
import subprocess
import json
class Kiosk(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.frame = None
self.frames_history = []
self.geometry('1366x768')
self.attributes('-fullscreen', True)
self.switch_frame(Screen0)
def switch_frame(self, frame_class, keep_history=True):
if keep_history and self.frame:
self.frames_history.append(type(self.frame))
new_frame = frame_class(self)
if self.frame is not None:
self.frame.destroy()
self.frame = new_frame
self.frame.pack(fill="both", expand=True)
def back_frame(self):
if self.frames_history:
self.switch_frame(self.frames_history.pop(), keep_history=False)
class Screen0(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
title_font = tkfont.Font(size=39, family='Helvetica') # 30% bigger
button_font = tkfont.Font(size=13, family='Helvetica') # 30% bigger
title_label = tk.Label(self, text="Custodisco", bg='#bcfef9', font=title_font)
title_label.pack(side='top', pady=20) # adjust to your needs
emoji_label = tk.Label(self, text="", fg='yellow', bg='#bcfef9', font=title_font)
emoji_label.pack(side='top')
tk.Button(self, text="Create Item", command=lambda: master.switch_frame(Screen1), height=4, width=39, bg='peach puff', font=button_font).pack(side='top', pady=30)
tk.Button(self, text="Lookup Item", command=lambda: master.switch_frame(Screen14), height=4, width=39, bg='peach puff', font=button_font).pack(side='top', pady=30)
class Screen1(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="Yes", command=lambda: master.switch_frame(Screen2), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="No I Want to Make One Now", command=lambda: master.switch_frame(Screen7), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen2(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
# Get list of Scuttlebutt users
users = self.get_scuttlebutt_users()
# Create a scrollable frame
container = ttk.Frame(self)
canvas = tk.Canvas(container)
scrollbar = ttk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
for user in users:
ttk.Label(scrollable_frame, text=user["id"]).pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff').pack(pady=10)
container.pack()
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
def get_scuttlebutt_users(self):
result = subprocess.run(['node', 'scuttlebot.js'], capture_output=True, text=True)
if result.returncode == 0:
users = json.loads(result.stdout)
return users
else:
raise Exception("Command failed: " + result.stderr)
class Screen3(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="Take Photo", command=lambda: master.switch_frame(Screen5), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen5(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
# Assume there's a method to manage the text entry
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen8), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen6(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="I Understand", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen7(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
# Assume there's a method to manage the text entry
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen6), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen8(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
self.drawing = Image.new('1', (300, 540), 1) # creating new Image of size 250x450 (1.25:2.25 ratio) and color white
self.draw = ImageDraw.Draw(self.drawing)
self.last_draw = None
# Creating the Canvas for drawing
self.canvas = Canvas(self, width=300, height=540, bg='white')
self.canvas.bind("<B1-Motion>", self.draw_line)
self.canvas.pack(pady=20)
self.canvas.bind("<ButtonRelease-1>", self.reset_last_draw)
tk.Button(self, text="Done", command=self.next, height=3, width=30, bg='peach puff').pack(pady=10)
def draw_line(self, event):
x, y = event.x, event.y
if self.last_draw:
self.canvas.create_line(*self.last_draw, x, y, fill='black')
self.draw.line([*self.last_draw, x, y], fill=0) # Draw black line on Image
self.last_draw = (x, y)
def next(self):
self.master.switch_frame(Screen11) # Switching to Screen11 after Done
# Save the drawing as a .png file
self.drawing.save("drawing.png")
def reset_last_draw(self, event):
self.last_draw = None
class Screen9(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
# Assume there's a method to manage the text entry
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen10), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen10(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Label(self, text="Thank you!", bg='#bcfef9').pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen0), height=3, width=30, bg='peach puff').pack(pady=10)
#sticker or tag? then print
class Screen11(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="Sticker", command=self.printy(2), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="Tag", command=self.printy(1), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="Done", command=self.printy, height=3, width=30, bg='peach puff').pack(pady=10)
# go ahead and print the thing
def printy(self, orientation):
self.master.switch_frame(Screen10) # Switching to Screen10 after Done
# Specify the path to your image file
path_to_image = "drawing.png"
# if sticker we gotta rotate 90 degrees.... I think
if orientation == 2:
image = Image.open(path_to_image)
rotated_image = image.rotate(-90)
rotated_image.save('drawing.png')
# Get the ZPL code for the image
zpl_code = toZPL.print_to_zpl(path_to_image)
# send the ZPL to the printer babeee
print(zpl_code)
class Screen12(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="Re-print Tag", command=lambda: master.switch_frame(Screen8), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="Post Update", command=lambda: master.switch_frame(Screen9), height=3, width=30, bg='peach puff').pack(pady=10)
class Screen14(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen12), height=3, width=30, bg='peach puff').pack(pady=10)
if __name__ == "__main__":
app = Kiosk()
app.mainloop()

1
pythonzpl.zpl Normal file

File diff suppressed because one or more lines are too long

39
scuttlebot.js Normal file
View File

@ -0,0 +1,39 @@
// scuttlebot.js
const ssbClient = require('ssb-client');
const ssbKeys = require('ssb-keys');
const pull = require('pull-stream');
const keys = ssbKeys.loadOrCreateSync('~/.ssb/secret');
ssbClient(keys, (err, sbot) => {
if (err) {
console.error(JSON.stringify({ "error": "Failed to connect to the Scuttlebot server. Is it running?" }));
console.error(err);
process.exit(1);
}
const authors = new Set();
pull(
sbot.createLogStream(),
pull.drain((msg) => {
authors.add(msg.value.author);
}, (err) => {
if (err) {
console.error(JSON.stringify({ "error": "Failed to retrieve messages." }));
console.error(err);
process.exit(1);
}
const feeds = Array.from(authors).map(author => { return { id: author } });
console.log(JSON.stringify(feeds));
try {
sbot.close(() => {});
} catch(err) {
console.error("Error closing SSB server connection: ", err);
}
})
);
});

135
tozpl.py Normal file
View File

@ -0,0 +1,135 @@
#this code was converted to python from http://www.jcgonzalez.com/java-image-to-zpl-example by chatgpt and trav. We modified it together a bit to only accept black and white images :)
from PIL import Image
import numpy as np
class ZPLConveter:
def __init__(self):
self.total = 0
self.width_bytes = 0
self.compress_hex = False
self.map_code = {1: 'G', 2: 'H', 3: 'I', 4: 'J', 5: 'K', 6: 'L', 7: 'M', 8: 'N',
9: 'O', 10: 'P', 11: 'Q', 12: 'R', 13: 'S', 14: 'T', 15: 'U', 16: 'V',
17: 'W', 18: 'X', 19: 'Y', 20: 'g', 40: 'h', 60: 'i', 80: 'j', 100: 'k',
120: 'l', 140: 'm', 160: 'n', 180: 'o', 200: 'p', 220: 'q', 240: 'r',
260: 's', 280: 't', 300: 'u', 320: 'v', 340: 'w', 360: 'x', 380: 'y',
400: 'z'}
def convert_from_img(self, img_path):
image = Image.open(img_path)
cuerpo = self.create_body(image)
if self.compress_hex:
cuerpo = self.encode_hex_ascii(cuerpo)
return self.head_doc() + cuerpo + self.foot_doc()
def create_body(self, image):
width, height = image.size
orginal_image = np.array(image)
index = 0
aux_binary_char = ['0', '0', '0', '0', '0', '0', '0', '0']
self.width_bytes = width // 8
if width % 8 > 0:
self.width_bytes = ((width // 8) + 1)
else:
self.width_bytes = width // 8
self.total = self.width_bytes * height
sb = []
for h in range(height):
for w in range(width):
pixel = orginal_image[h, w]
aux_char = '1' if pixel == 0 else '0' # 0 for black, 1 for white
aux_binary_char[index] = aux_char
index += 1
if index == 8 or w == (width - 1):
sb.append(self.four_byte_binary(''.join(aux_binary_char)))
aux_binary_char = ['0', '0', '0', '0', '0', '0', '0', '0']
index = 0
sb.append("\n")
return ''.join(sb)
@staticmethod
def four_byte_binary(binary_str):
decimal = int(binary_str, 2)
if decimal > 15:
return hex(decimal)[2:].upper()
else:
return "0" + hex(decimal)[2:].upper()
def encode_hex_ascii(self, code):
maxlinea = self.width_bytes * 2
sb_code = []
sb_linea = []
previous_line = None
counter = 1
aux = code[0]
first_char = False
for i in range(1, len(code)):
if first_char:
aux = code[i]
first_char = False
continue
if code[i] == '\n':
if counter >= maxlinea and aux == '0':
sb_linea.append(",")
elif counter >= maxlinea and aux == 'F':
sb_linea.append("!")
elif counter > 20:
multi20 = (counter // 20) * 20
resto20 = (counter % 20)
sb_linea.append(self.map_code[multi20])
if resto20 != 0:
sb_linea.append(self.map_code[resto20] + aux)
else:
sb_linea.append(aux)
else:
sb_linea.append(self.map_code[counter] + aux)
counter = 1
first_char = True
if ''.join(sb_linea) == previous_line:
sb_code.append(":")
else:
sb_code.append(''.join(sb_linea))
previous_line = ''.join(sb_linea)
sb_linea = []
continue
if aux == code[i]:
counter += 1
else:
if counter > 20:
multi20 = (counter // 20) * 20
resto20 = (counter % 20)
sb_linea.append(self.map_code[multi20])
if resto20 != 0:
sb_linea.append(self.map_code[resto20] + aux)
else:
sb_linea.append(aux)
else:
sb_linea.append(self.map_code[counter] + aux)
counter = 1
aux = code[i]
return ''.join(sb_code)
def head_doc(self):
return "^XA " + "^FO0,0^GFA," + str(self.total) + "," + str(self.total) + "," + str(self.width_bytes) + ", "
@staticmethod
def foot_doc():
return "^FS" + "^XZ"
def set_compress_hex(self, compress_hex):
self.compress_hex = compress_hex
def set_blackness_limit_percentage(self, percentage):
self.black_limit = (percentage * 768 // 100)
def print_to_zpl(img_path):
converter = ZPLConveter()
converter.set_compress_hex(True)
return converter.convert_from_img(img_path)
if __name__ == "__main__":
zp = ZPLConveter()
zp.set_compress_hex(True)
print(zp.convert_from_img("drawing.png"))