current working version

This commit is contained in:
trav 2023-07-23 02:24:42 -04:00
parent 63c868e6ca
commit f52a97f0fe
10 changed files with 369 additions and 89 deletions

Binary file not shown.

View File

@ -59,7 +59,7 @@ def addToSSB(pathToImage,description,mintOrGive):
json_object = json.loads(newssb)
except json.JSONDecodeError:
print("Invalid JSON")
return "blouch" # Return the blouch
return "offline" # Return the blouch
# get the key for the post we just made
key = json_object["key"]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 37 KiB

450
kiosk6.py
View File

@ -16,6 +16,14 @@ import cv2
import time
import qrcode
import addtoDB
from pyzbar.pyzbar import decode
qr_code_value = None # global variable to store QR code value
print_type = "neither" # print type when printing
class GlobalVars:
selected_user = None
@ -27,8 +35,11 @@ class Kiosk(tk.Tk):
self.geometry('1366x768')
self.attributes('-fullscreen', True)
self.config(cursor="crosshair")
globals()['BUTTON_FONT'] = tkfont.Font(size=24, family='Helvetica')
globals()['TEXT_FONT'] = tkfont.Font(size=20, family='Helvetica')
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))
@ -44,61 +55,89 @@ class Kiosk(tk.Tk):
def add_home_button(self, frame):
# Create the "Start Over" button
button_font = tkfont.Font(size=16, family='Helvetica') # 16 point font
home_button = tk.Button(frame, text="Start Over", command=lambda: self.switch_frame(Screen0), bg='peach puff', font=button_font)
home_button = tk.Button(frame, text="Start Over", command=lambda: self.switch_frame(Screen0), bg='peach puff', font=BUTTON_FONT)
home_button.place(x=0, y=0) # top-left corner
# home screen
class Screen0(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
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=('Helvetica', 48))
title_font = tkfont.Font(size=42, family='Helvetica') # 30% bigger
# Split the screen into two frames
left_frame = tk.Frame(self, bg='#bcfef9')
right_frame = tk.Frame(self, bg='#bcfef9', padx=40) # 40px padding on the right side
left_frame.grid(row=0, column=0, sticky='nsew')
right_frame.grid(row=0, column=1, sticky='nsew')
self.grid_columnconfigure(0, weight=1, minsize=800) # For left frame
self.grid_columnconfigure(1, weight=1) # For right frame
# Title and buttons on the left side
title_label = tk.Label(left_frame, text="Custodisco", bg='#bcfef9', fg='#800080', font=('Helvetica', 48)) # dark purple color
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)
# Welcome message on the left side
welcome_text = """If you have an item that is special to you, this kiosk allows you to create a tag for your item.
Build your relationship with your item by committing to mend and care for it.
If you put your contact info on the tag the item may be returned to you if lost.
You can use your fingers to interact with the kiosk but also there is a stylus that can help with drawing.
More info at https://teafry.me/custodisco"""
welcome_label = tk.Label(left_frame, text=welcome_text, bg='#bcfef9', font=TEXT_FONT, justify='left', wraplength=650)
welcome_label.pack(side='top', padx=20, pady=20)
tk.Button(right_frame, text="Create Item", command=lambda: master.switch_frame(Screen1), height=4, width=75, bg='peach puff', font=BUTTON_FONT).pack(side='top', pady=30)
tk.Button(right_frame, text="Lookup Item", command=lambda: master.switch_frame(Screen14), height=4, width=75, bg='peach puff', font=BUTTON_FONT).pack(side='top', pady=30)
# Create the quit button
tk.Button(self, text="Quit", command=self.quit_program, height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(right_frame, text="Quit", command=self.quit_program, height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
def quit_program(self):
self.master.destroy()
# do you have ssb?
class Screen1(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
# Create the label widget with the text
label = tk.Label(self, text="Do you have a Scuttlebutt account?", font=('Helvetica', 16))
label.pack(pady=10)
label = tk.Label(self, text="Do you have a Scuttlebutt account? If no just tap Yes and then Done on the next screen, it's fine.", font=TEXT_FONT)
label.pack(pady=60)
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)
tk.Button(self, text="Yes", command=lambda: master.switch_frame(Screen2), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=50)
tk.Button(self, text="No, I Want to Make One Now (not implemented yet)", command=lambda: master.switch_frame(Screen7), height=3, width=50, bg='peach puff', font=BUTTON_FONT).pack(pady=50)
# find yourself in list of ssb users
class Screen2(tk.Frame):
selected_user = None # This is the global variable to store selected user
selected_label = None # This is the global variable to store selected label
global BUTTON_FONT
global TEXT_FONT
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
self.selected_label = None # This is the global variable to store selected label
# Create a new frame at the top for the label and text box
self.top_frame = tk.Frame(self)
self.top_frame.pack(side="top", fill="x", pady=40)
self.top_frame.pack(side="top", fill="x", pady=60)
# Add a label and text box to the top frame
self.label = tk.Label(self.top_frame, text="Start typing your public key to find yourself in the list then click on your key to select it.", font=('Helvetica', 16))
self.label = tk.Label(self.top_frame, text="Start typing your public key to find yourself in the list then click on your key to select it.\n\nIf you can't find your name it might help to follow the Custodisco Scuttlebutt account.", font=TEXT_FONT)
self.label.pack(side="left")
self.entry = tk.Entry(self.top_frame, font=('Helvetica', 16))
self.entry = tk.Entry(self.top_frame, font=TEXT_FONT)
self.entry.bind('<KeyRelease>', lambda e: self.update_users_list())
self.entry.pack(side="left")
@ -109,16 +148,24 @@ class Screen2(tk.Frame):
self.container = ttk.Frame(self, height=500) # Define a height here
self.container.pack(fill='both', expand=True, padx=20, pady=20)
# Initialize users list from users.json
# Initialize users list from users.json
self.users = self.get_users_from_file()
self.update_users_list()
# Highlight selected user if one exists
if GlobalVars.selected_user is not None:
for widget in self.container.winfo_children():
if isinstance(widget, tk.Button) and widget['text'] == GlobalVars.selected_user:
widget.configure(relief=tk.SUNKEN, bg="light blue")
self.selected_label = widget
# The 'Done' button to navigate to next screen
self.done_button = tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff', font=('Helvetica', 16))
self.done_button = tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff', font=BUTTON_FONT)
self.done_button.pack(side="bottom", padx=20, pady=10)
# The 'Refresh List' button
self.refresh_button = tk.Button(self, text="Refresh List (takes a minute)", command=self.refresh_users, height=3, width=30, bg='peach puff', font=('Helvetica', 16))
self.refresh_button = tk.Button(self, text="Refresh List (takes 30 seconds or so)", command=self.refresh_users, height=3, width=30, bg='peach puff', font=BUTTON_FONT)
self.refresh_button.pack(side="bottom", padx=20, pady=10)
master.add_home_button(self)
@ -194,15 +241,15 @@ class Screen2(tk.Frame):
def on_user_clicked(self, button, user):
# Remove highlight from previously selected user
if Screen2.selected_label is not None and self.widget_exists(Screen2.selected_label):
Screen2.selected_label.configure(relief=tk.FLAT, bg='SystemButtonFace') # default color
if self.selected_label is not None and self.widget_exists(self.selected_label):
self.selected_label.configure(relief=tk.FLAT, bg='SystemButtonFace') # default color
# Store selected user and button
Screen2.selected_user = user['id']
Screen2.selected_label = button
GlobalVars.selected_user = user['id']
self.selected_label = button
# Highlight clicked label
Screen2.selected_label.configure(relief=tk.SUNKEN, bg="light blue")
self.selected_label.configure(relief=tk.SUNKEN, bg="light blue")
@ -211,7 +258,12 @@ class Screen2(tk.Frame):
class Screen3(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
global BUTTON_FONT
global TEXT_FONT
# Create the "Start Over" button
home_button = tk.Button(text="Start Over", command=self.homer, bg='peach puff', font=BUTTON_FONT)
home_button.place(x=0, y=0) # top-left corner
self.vid = cv2.VideoCapture(0)
self.is_capturing = True
@ -224,15 +276,19 @@ class Screen3(tk.Frame):
# Info and button on the right
self.text_frame = tk.Frame(self, bg='#bcfef9')
self.text_frame.pack(side="right", fill="both", expand=True)
tk.Label(self.text_frame, text="Now we will take a picture of your item to show up on Scuttlebutt", font=("Helvetica", 16), bg='#bcfef9').pack(pady=10)
self.button = tk.Button(self.text_frame, text="Take Photo", command=self.take_photo, font=("Helvetica", 32), height=3, width=37, bg='peach puff')
tk.Label(self.text_frame, text="Now we will take a picture of your item to show up on Scuttlebutt.\n\nIf you tap Take Photo a second time it will re-take the photo\nbut wont show you a preview during the countdown (this is a bug)", font=("Helvetica", 16), bg='#bcfef9').pack(pady=10)
self.button = tk.Button(self.text_frame, text="Take Photo", command=self.take_photo, height=3, width=37, bg='peach puff', font=BUTTON_FONT)
self.button.pack(pady=10)
self.done_button = tk.Button(self, text="Done", command=self.done, height=3, width=30, bg='peach puff')
self.done_button = tk.Button(self, text="Done", command=self.done, height=3, width=30, bg='peach puff', font=BUTTON_FONT)
self.done_button.place(relx=0.9, rely=0.9, anchor='se')
self.update_image()
def homer(self):
self.__del__()
self.master.switch_frame(Screen0)
def update_image(self):
if self.is_capturing:
ret, frame = self.vid.read()
@ -279,15 +335,128 @@ class Screen3(tk.Frame):
if self.vid.isOpened():
self.vid.release()
# draw a sticker
class Screen4(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
global BUTTON_FONT
global TEXT_FONT
# Configure column minsizes
self.grid_columnconfigure(0, minsize=665) # considering 675 width + 50 padding on each side
self.grid_columnconfigure(1, minsize=100)
self.grid_columnconfigure(2, minsize=100)
# Creating a frame for the left side of the screen for drawing
self.left_frame = tk.Frame(self, bg='#bcfef9')
self.left_frame.grid(row=0, column=0, padx=20)
# Frame for the instructions
self.center_frame = tk.Frame(self, bg='#bcfef9')
self.center_frame.grid(row=0, column=1, padx=20)
# Frame for the tools
self.right_frame = tk.Frame(self, bg='#bcfef9')
self.right_frame.grid(row=0, column=2, padx=60)
# Add instructions
self.label = tk.Label(self.left_frame, text="You may now draw your sticker :) This will be printed ~ 1.25 by 2.25 inches. You can include contact info for yourself, the name of the item, a drawing, or whatever you want, it's your artistic expression. You might have better results using thicker lines (see drawing tools on the right). In the bottom right of the sticker will be a small QR code which links to the Scuttlebutt post for your item. The image you are drawing now will not be posted to Scuttlebutt.",
wraplength=600, # adjust to suit needs
font=TEXT_FONT)
self.label.pack(pady=10)
# is this the drawing area
self.drawing = Image.new('1', (635, 360), 1)
self.draw = ImageDraw.Draw(self.drawing)
self.last_draw = None
# Set initial drawing color to black and size to 1
self.draw_color = 'black'
self.draw_size = 1
# Creating the Canvas for drawing
self.canvas = Canvas(self.left_frame, width=635, height=360, bg='white')
self.canvas.bind("<B1-Motion>", self.draw_line)
self.canvas.pack(pady=20)
self.canvas.bind("<ButtonRelease-1>", self.reset_last_draw)
self.add_qr_box() # Add QR box to the canvas
#Create a frame for the buttons grid
self.buttons_frame = tk.Frame(self.right_frame, bg='#bcfef9')
self.buttons_frame.pack(pady=50)
# Add Draw Size buttons
tk.Button(self.buttons_frame, text=".", command=lambda: self.set_draw_size(1), height=3, width=10, bg='peach puff').grid(row=0, column=0, padx=5, pady=5)
tk.Button(self.buttons_frame, text="*", command=lambda: self.set_draw_size(2), height=3, width=10, bg='peach puff').grid(row=1, column=0, padx=5, pady=5)
tk.Button(self.buttons_frame, text="", command=lambda: self.set_draw_size(3), height=3, width=10, bg='peach puff').grid(row=2, column=0, padx=5, pady=5)
tk.Button(self.buttons_frame, text="", command=lambda: self.set_draw_size(4), height=3, width=10, bg='peach puff').grid(row=3, column=0, padx=5, pady=5)
# Creating color buttons
tk.Button(self.buttons_frame, height=5, width=10, bg='black', command=lambda: self.set_draw_color('black')).grid(row=0, column=1, padx=5, pady=5)
tk.Button(self.buttons_frame, height=5, width=10, bg='white', command=lambda: self.set_draw_color('white')).grid(row=1, column=1, padx=5, pady=5)
# Add label for pen color buttons
self.color_label = tk.Label(self.right_frame, text="^ drawing tools ^", font=TEXT_FONT)
self.color_label.pack(pady=5)
# Add Clear Drawing Button
tk.Button(self.right_frame, text="clear drawing", command=self.clear_drawing, height=3, width=20, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
# Done button
tk.Button(self.right_frame, text="Done", command=self.next, height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
# Adding a home button
master.add_home_button(self.right_frame)
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=self.draw_color, width=self.draw_size)
self.draw.line([*self.last_draw, x, y], fill=0 if self.draw_color == 'black' else 1, width=self.draw_size)
self.last_draw = (x, y)
def next(self):
# Save the drawing as a .png file
self.drawing.save("drawing.png")
# next screen
self.master.switch_frame(Screen13)
def reset_last_draw(self, event):
self.last_draw = None
def set_draw_color(self, color):
self.draw_color = color
def set_draw_size(self, size):
self.draw_size = size
def clear_drawing(self):
self.canvas.delete("all") # Clear canvas
self.drawing = Image.new('1', (635, 360), 1) # Create new blank drawing image
self.draw = ImageDraw.Draw(self.drawing) # Prepare to draw on the new blank image
self.add_qr_box() # Add QR box to the canvas
def add_qr_box(self):
self.canvas.create_rectangle(506, 217, 627, 346, outline='black', fill='white')
self.canvas.create_text(540, 260, text="QR", fill="black")
# typed description
class Screen5(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
global BUTTON_FONT
global TEXT_FONT
# Adding the information label
self.info_label = tk.Label(self, text="Please enter any information you'd like about your item. This can be make/model of the itme, a name for the item, diagnostic information, provenance, historical context, contact info, stories, whatever. Along with the photo, this will be posted on Scuttlebutt forever and cannot be deleted. You can always add more information later via any Scuttlebutt client.", font=("Helvetica", 16), wraplength=500)
self.info_label = tk.Label(self, text="Please enter any information you'd like about your item. This can be make/model of the item, a name for the item, diagnostic information, provenance, historical context, contact info, stories, whatever. Along with the photo, this will be posted on Scuttlebutt forever and cannot be deleted. You can always add more information later via any Scuttlebutt client.", font=TEXT_FONT, wraplength=500)
self.info_label.pack(pady=10)
# Adding the text entry field
@ -295,7 +464,7 @@ class Screen5(tk.Frame):
self.info_entry.pack(pady=10)
# Adding the done button
self.done_button = tk.Button(self, text="Done", command=self.save_info_and_switch, height=3, width=30, bg='peach puff')
self.done_button = tk.Button(self, text="Done", command=self.save_info_and_switch, height=3, width=30, bg='peach puff', font=BUTTON_FONT)
self.done_button.pack(pady=10)
# Setting the focus to the text entry field
@ -307,25 +476,33 @@ class Screen5(tk.Frame):
info_text = self.info_entry.get("1.0", "end-1c")
# escape the newlines!:
info_text = info_text.replace('\n', '\\n')
self.master.switch_frame(Screen8)
self.master.switch_frame(Screen11)
class Screen6(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
global BUTTON_FONT
global TEXT_FONT
master.add_home_button(self)
tk.Button(self, text="I Understand", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="I Understand", command=lambda: master.switch_frame(Screen3), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
class Screen7(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
global BUTTON_FONT
global TEXT_FONT
master.add_home_button(self)
# 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)
self.info_label = tk.Label(self, text="Hiii sorry this hasn't been implemented yet!", font=("Helvetica", 16), wraplength=500)
self.info_label.pack()
#tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen6), height=3, width=30, bg='peach puff').pack(pady=10)
# draw the tag! :)
# draw a ribbon tag
class Screen8(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
tk.Frame.__init__(self, master, bg='#bcfef9')
# Creating a frame for the left side of the screen for drawing
@ -341,13 +518,11 @@ class Screen8(tk.Frame):
self.right_frame.pack(side='left', padx=50)
# Add instructions
self.label = tk.Label(self.center_frame, text="You may now draw your tag! This will be printed as either a sticker or a ribbon, both of which are 1.25 by 2.25 inches. You can include contact info for yourself, the name of the item, a drawing, or whatever you want, it's your artistic expression. In the bottom right will be a small QR code which links to the Scuttlebutt post for your item. The image you are drawing now will not be posted to Scuttlebutt.",
wraplength=400, # adjust to suit needs
font=("Helvetica", 16))
self.label = tk.Label(self.center_frame, text="You may now draw your tag! You might like to include contact info for yourself, the name of the item, a drawing, or whatever you want, it's your artistic expression. Thin lines might not show up well (try different drawing tools on the right). In the bottom right of your tag will be a small QR code which links to the Scuttlebutt post for your item. The image you are drawing now will not be posted to Scuttlebutt.", wraplength=400, font=TEXT_FONT)
self.label.pack(pady=50)
# is this the drawing area?
self.drawing = Image.new('1', (361, 675), 1)
# the drawing area
self.drawing = Image.new('1', (475, 375), 1)
self.draw = ImageDraw.Draw(self.drawing)
self.last_draw = None
@ -356,7 +531,7 @@ class Screen8(tk.Frame):
self.draw_size = 1
# Creating the Canvas for drawing
self.canvas = Canvas(self.left_frame, width=361, height=675, bg='white')
self.canvas = Canvas(self.left_frame, width=475, height=375, bg='white')
self.canvas.bind("<B1-Motion>", self.draw_line)
self.canvas.pack(pady=20)
self.canvas.bind("<ButtonRelease-1>", self.reset_last_draw)
@ -381,10 +556,10 @@ class Screen8(tk.Frame):
self.color_label.pack(pady=5)
# Add Clear Drawing Button
tk.Button(self.right_frame, text="clear drawing", command=self.clear_drawing, height=3, width=20, bg='peach puff').pack(pady=10)
tk.Button(self.right_frame, text="clear drawing", command=self.clear_drawing, height=3, width=20, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
# Done button
tk.Button(self.right_frame, text="Done", command=self.next, height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self.right_frame, text="Done", command=self.next, height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
# Adding a home button
master.add_home_button(self.center_frame)
@ -401,7 +576,7 @@ class Screen8(tk.Frame):
self.drawing.save("drawing.png")
# next screen
self.master.switch_frame(Screen11)
self.master.switch_frame(Screen13)
def reset_last_draw(self, event):
self.last_draw = None
@ -414,51 +589,96 @@ class Screen8(tk.Frame):
def clear_drawing(self):
self.canvas.delete("all") # Clear canvas
self.drawing = Image.new('1', (361, 675), 1) # Create new blank drawing image
self.drawing = Image.new('1', (475, 375), 1) # Create new blank drawing image
self.draw = ImageDraw.Draw(self.drawing) # Prepare to draw on the new blank image
self.add_qr_box() # Add QR box to the canvas
def add_qr_box(self):
self.canvas.create_rectangle(232, 546, 361, 667, outline='black', fill='white')
self.canvas.create_text(300, 600, text="QR", fill="black")
self.canvas.create_rectangle(346, 229, 475, 358, outline='black', fill='white')
self.canvas.create_text(355, 260, text="QR", fill="black")
# txt update
class Screen9(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
# 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)
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen10), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
#THX BYE
class Screen10(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
GlobalVars.selected_user = None # Reset the selected user
tk.Frame.__init__(self, master, bg='#bcfef9')
tk.Label(self, text="Thank you!", bg='#bcfef9', font=('Helvetica', 48)).pack()
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen0), height=3, width=30, bg='peach puff').pack(pady=10)
tk.Button(self, text="Done", command=lambda: master.switch_frame(Screen0), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
#sticker or tag? then print
# Sticker or tag?
class Screen11(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
# Instructions
self.label = tk.Label(self, text="Do you want to design a sticker or a ribbon? The sticker is suitable for hard surfaces and the ribbon is a tag suitable for sewing into textiles.",
wraplength=400, # adjust to suit needs
font=("Helvetica", 16))
self.label.pack(pady=50)
# Button functions
def select_ribbon():
global print_type
print_type = 'ribbon'
master.switch_frame(Screen8)
def select_sticker():
global print_type
print_type = 'sticker'
master.switch_frame(Screen4)
# Buttons
tk.Button(self, text="Sticker", command=select_sticker, height=4, width=39, bg='peach puff', font=BUTTON_FONT).pack(side='top', pady=30)
tk.Button(self, text="Ribbon tag", command=select_ribbon, height=4, width=39, bg='peach puff', font=BUTTON_FONT).pack(side='top', pady=30)
# after QR scanned for lookup
class Screen12(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
tk.Button(self, text="not implemented yet", command=lambda: master.switch_frame(Screen8), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
tk.Button(self, text="Post Update (also not implemented)", command=lambda: master.switch_frame(Screen9), height=3, width=30, bg='peach puff', font=BUTTON_FONT).pack(pady=10)
#time to print
class Screen13(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
# Create a container to hold the widgets
container = tk.Frame(self)
container.place(relx=0.5, rely=0.5, anchor='center')
# instructions
tk.Label(container, text="Wonderful! It is now time to post your item to Scuttlebutt and to print your tag. You can still cancel by hitting Start Over if you like. Otherwise choose whether you'd like a sticker or a fabric tag printed!", wraplength=600, font=('Helvetica', 16)).grid(row=0, column=0, columnspan=2)
tk.Label(container, text="Wonderful! It is now time to post your item to Scuttlebutt and to print your tag. You can still cancel by hitting Start Over if you like.", wraplength=600, font=TEXT_FONT).grid(row=0, column=0, columnspan=2)
# buttons
master.add_home_button(self)
tk.Button(container, text="Sticker", command=lambda: self.printy(2), height=3, width=30, bg='peach puff').grid(row=2, column=0, pady=20)
tk.Button(container, text="Tag", command=lambda: self.printy(1), height=3, width=30, bg='peach puff').grid(row=2, column=1, pady=20)
tk.Button(container, text="Print", command=self.printy, height=3, width=30, bg='peach puff', font=BUTTON_FONT).grid(row=2, column=0, pady=20)
# go ahead and print the thing
def printy(self, orientation):
def printy(self):
global print_type
# Specify the path to your image file
path_to_image = "/home/trav/Documents/custodiosk/freeze_frame.jpg"
@ -467,8 +687,8 @@ class Screen11(tk.Frame):
key = addtoDB.addToSSB(path_to_image,info_text,1)
# ssb give! (make sure we have a UID to give to first)
if Screen2.selected_user != "":
nothing = addtoDB.addToSSB(Screen2.selected_user,key,2)
if GlobalVars.selected_user and GlobalVars.selected_user.strip() != "":
nothing = addtoDB.addToSSB(GlobalVars.selected_user,key,2)
# Create qr code
#from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python
@ -481,6 +701,7 @@ class Screen11(tk.Frame):
# Add data
qr.add_data(key)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image()
whereToSaveQR = 'qr.jpg'
@ -490,43 +711,46 @@ class Screen11(tk.Frame):
drawing = Image.open("drawing.png") # drawing
qr = Image.open("qr.jpg") # qr
# merge em
merged_image = Image.new('L', (367, 725), "white")
merged_image.paste(drawing, (0, 25))
merged_image.paste(qr, (232, 571)) # paste without mask
merged_image.save("merged_image.png")
#### merge em
merged_image = Image.new('L', (675, 375), "white")
## if sticker
if print_type == "sticker":
merged_image.paste(drawing, (0, 0))
merged_image.paste(qr, (506, 217))
merged_image.save("merged_image.png")
# if sticker we gotta rotate 90 degrees.... I think
if orientation == 2:
# if ribbon we gotta rotate 90 degrees and paste QR in different spot
if print_type == "ribbon":
merged_image.paste(drawing, (100, 0))
merged_image.paste(qr, (446, 229)) # paste without mask
merged_image.save("merged_image.png")
image = Image.open("merged_image.png")
rotated_image = image.transpose(Image.ROTATE_270) # Transpose and rotate 90 degrees
rotated_image.save("merged_image.png")
# Get the ZPL code for the image
zpl_code = tozpl.print_to_zpl("merged_image.png")
# send the ZPL to the printer babeee
#print(zpl_code) #only needed for testing
#save the zpl
# Open the file in write mode
with open("to_print.zpl", "w") as file:
# Write the string to the file
file.write(zpl_code)
#print(zpl_code) #only needed for testing
#print (print_type)
# print to sticker printer
if orientation == 2:
if print_type == "sticker":
try:
result = subprocess.Popen('lpr -P sticker_printer -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE, )
except:
print('traceback.format_exc():\n%s' % traceback.format_exc())
exit()
# or print to tag printer:
elif orientation == 1:
if print_type == "ribbon":
try:
result = subprocess.Popen('lpr -P tag-printer -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE, )
except:
@ -535,19 +759,75 @@ class Screen11(tk.Frame):
self.master.switch_frame(Screen10) # Switching to Screen10 after Done
class Screen12(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, bg='#bcfef9')
master.add_home_button(self)
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)
# lookup item
class Screen14(tk.Frame):
def __init__(self, master):
global BUTTON_FONT
global TEXT_FONT
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)
# divide the screen into two halves
left_frame = tk.Frame(self, bg='#bcfef9') # updated background color
right_frame = tk.Frame(self, bg='#bcfef9') # updated background color
left_frame.pack(side='left', fill='both', expand=True)
right_frame.pack(side='right', fill='both', expand=True)
# add the home button to the right frame
master.add_home_button(right_frame)
# setup the instruction on the right side, with wraplength to avoid running off the screen
instruction = tk.Label(right_frame, text="Please hold the QR code of a Custodisco tag up to the camera to be scanned. This isn't currently working! Sorry! If you download a Scuttlebutt client and follow the Custodisco Kiosk account you can look up Custodisco items on your own device. Ask someone who knows about Scuttlebutt for help ;)", font=("Helvetica", 16), bg='#bcfef9', wraplength=300) # updated wraplength
instruction.pack(pady=100) # increased padding to avoid overlap with the button
# setup the video feed on the left side
self.video = tk.Label(left_frame, bg='#bcfef9') # updated background color
self.video.pack(pady=10)
# Open the camera for video capture
self.cap = cv2.VideoCapture(0)
self.master.after(10, self.update_frame)
def update_frame(self):
global qr_code_value
# Capture frame-by-frame
ret, frame = self.cap.read()
# Check if the frame is not None
if not ret or frame is None:
print("Failed to capture frame")
return
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Look for QR codes in the frame
codes = decode(gray)
for code in codes:
# If a QR code is detected, store its value and switch to Screen12
qr_code_value = code.data.decode('utf-8')
self.cap.release() # Close the video capture
self.master.switch_frame(Screen12)
return
# Display the resulting frame
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
self.video.imgtk = imgtk
self.video.configure(image=imgtk)
self.master.after(10, self.update_frame) # Call the update_frame function after 10 milliseconds
def destroy(self):
self.cap.release() # Close the video capture when the frame is destroyed
super().destroy() # Call the parent class's destroy method
if __name__ == "__main__":
app = Kiosk()
BUTTON_FONT = tkfont.Font(size=24, family='Helvetica')
TEXT_FONT = tkfont.Font(size=20, family='Helvetica')
app.mainloop()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
qr.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 690 B

After

Width:  |  Height:  |  Size: 685 B

View File

@ -16,7 +16,7 @@ ssbClient(keys, (err, sbot) => {
const authors = new Set();
pull(
sbot.createLogStream(),
sbot.messagesByType("contact"),
pull.drain((msg) => {
authors.add(msg.value.author);
}, (err) => {

View File

@ -54,7 +54,7 @@ then
ssb-server publish . <<BLAAB
{
"type":"post",
"text":"I'm giving this item to $account!",
"text":"This item is owned by $account",
"custodisco":"true",
"nft": "give",
"target": "$account",

File diff suppressed because one or more lines are too long