diff --git a/drawing.png b/drawing.png index 0a7c71f..1f5c8e8 100644 Binary files a/drawing.png and b/drawing.png differ diff --git a/freeze_frame.jpg b/freeze_frame.jpg index e8500a6..eb23dff 100644 Binary files a/freeze_frame.jpg and b/freeze_frame.jpg differ diff --git a/kiosk6.py b/kiosk6.py index 2dd00de..d616451 100644 --- a/kiosk6.py +++ b/kiosk6.py @@ -32,6 +32,9 @@ class Kiosk(tk.Tk): self.geometry('1366x768') self.attributes('-fullscreen', True) self.config(cursor="crosshair") + self.QRX = None + self.QRY = None + self.QRscale = 1 globals()['BUTTON_FONT'] = tkfont.Font(size=24, family='Helvetica') globals()['TEXT_FONT'] = tkfont.Font(size=20, family='Helvetica') self.switch_frame(Screen0) @@ -340,7 +343,7 @@ class Screen4(tk.Frame): global TEXT_FONT # Configure column minsizes - self.grid_columnconfigure(0, minsize=665) # considering 675 width + 50 padding on each side + self.grid_columnconfigure(0, minsize=675) # considering 675 width + 50 padding on each side self.grid_columnconfigure(1, minsize=100) self.grid_columnconfigure(2, minsize=100) @@ -356,13 +359,13 @@ class Screen4(tk.Frame): tk.Button(self.left_frame, text="Import Image", command=self.import_image, height=2, width=15, bg='peach puff', font=BUTTON_FONT).pack(pady=10) # 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.", + 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 might have better results using thicker lines (see drawing tools on the right). The image you are drawing now will not be posted to Scuttlebutt.", wraplength=650, # adjust to suit needs font=TEXT_FONT) self.label.pack(pady=2) # is this the drawing area - self.drawing = Image.new('1', (635, 360), 1) + self.drawing = Image.new('1', (650, 360), 1) self.draw = ImageDraw.Draw(self.drawing) self.last_draw = None @@ -371,7 +374,7 @@ class Screen4(tk.Frame): self.draw_size = 1 # Creating the Canvas for drawing - self.canvas = Canvas(self.left_frame, width=635, height=360, bg='white') + self.canvas = Canvas(self.left_frame, width=650, height=360, bg='white') self.canvas.bind("", self.draw_line) self.image_on_canvas = None # To store imported image's reference self.canvas.pack(pady=20) @@ -382,6 +385,11 @@ class Screen4(tk.Frame): self.buttons_frame = tk.Frame(self.right_frame, bg='#bcfef9') self.buttons_frame.pack(pady=50) + # Define the info_label to display QRX, QRY, and QRscale values + self.info_label = tk.Label(self.right_frame, text="", bg='#bcfef9', font=TEXT_FONT) + self.info_label.pack(pady=5) # Use pack instead of grid + + # 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) @@ -403,7 +411,7 @@ class Screen4(tk.Frame): tk.Button(self.right_frame, text="Done", command=self.next, height=3, width=10, bg='peach puff', font=BUTTON_FONT).pack(pady=10) # Adding a home button - master.add_home_button(self.right_frame) + master.add_home_button(self) def draw_line(self, event): x, y = event.x, event.y @@ -430,49 +438,73 @@ class Screen4(tk.Frame): def clear_drawing(self): self.canvas.delete("all") # Clear canvas - self.drawing = Image.new('1', (635, 360), 1) # Create new blank drawing image + self.drawing = Image.new('1', (650, 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") + # add_qr_box to accept coordinates and size + def add_qr_box(self, x=506, y=217, size=1): + # Adjust the size based on QRscale + box_size = 37 * size + self.canvas.create_rectangle(x, y, x + box_size, y + box_size, outline='black', fill='white') + self.canvas.create_text(x + box_size/2, y + box_size/2, text="QR", fill="black") + def import_image(self): + # Open file dialog to select an image file - file_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.png")]) + file_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.jpeg *.png")]) - if file_path: - # Check if the selected file has a correct extension - if not (file_path.lower().endswith('.jpg') or file_path.lower().endswith('.png')): - tk.messagebox.showerror("Invalid file", "Please select a .jpg or .png file.") - return + if not file_path: # Exit the method if no file is selected + return - # Load the image - img = Image.open(file_path) + # Split the file path at hyphens and take the last three parts + file_parts = file_path.split('-')[-4:] - # Convert to 1-bit black and white - img = img.convert('1') + if len(file_parts) < 4: + messagebox.showerror("Filename Error", "The filename does not follow the expected pattern.") + return - # Resize or crop the image to fit the canvas - if img.size[0] > 635 or img.size[1] > 360: - img = img.crop((0, 0, 635, 360)) + try: + # Extract and convert the numeric parts + QRX = int(file_parts[1]) + QRY = int(file_parts[2]) + QRscale = int(file_parts[3].split('.')[0]) # Split at the dot and take the first part - # Paste the imported image onto the drawing image - self.drawing.paste(img) + # Update the main application's QR data + self.master.QRX = QRX + self.master.QRY = QRY + self.master.QRscale = QRscale - # Save image reference to avoid garbage collection - self.imported_img = ImageTk.PhotoImage(img) + # Display QRX, QRY, and QRscale values + self.info_label.config(text=f"QRX: {QRX}, QRY: {QRY}, QRscale: {QRscale}") + except ValueError as e: + messagebox.showerror("Filename Error", "The filename does not follow the expected pattern.") + return - # Clear the canvas - self.canvas.delete("all") + # Clear the canvas + self.canvas.delete("all") + # Load the image + img = Image.open(file_path) + # Convert to 1-bit black and white + img = img.convert('1') + # Resize or crop the image to fit the canvas + if img.size[0] > 675 or img.size[1] > 375: + img = img.crop((0, 0, 650, 360)) + self.add_qr_box(QRX, QRY, QRscale) - # Add image to the canvas - self.image_on_canvas = self.canvas.create_image(0, 0, image=self.imported_img, anchor='nw') + # Paste the imported image onto the drawing image + self.drawing.paste(img) - # Re-add QR box overlay - self.add_qr_box() + # Save image reference to avoid garbage collection + self.imported_img = ImageTk.PhotoImage(img) + # Add image to the canvas + self.image_on_canvas = self.canvas.create_image(0, 0, image=self.imported_img, anchor='nw') + + # add the QR box at the new position + self.add_qr_box(QRX, QRY, QRscale) + # typed description class Screen5(tk.Frame): @@ -505,6 +537,7 @@ class Screen5(tk.Frame): info_text = info_text.replace('\n', '\\n') self.master.switch_frame(Screen11) +# I understand class Screen6(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master, bg='#bcfef9') @@ -513,6 +546,7 @@ class Screen6(tk.Frame): master.add_home_button(self) 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) +# create user not implemented lol class Screen7(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master, bg='#bcfef9') @@ -530,6 +564,9 @@ class Screen8(tk.Frame): def __init__(self, master): global BUTTON_FONT global TEXT_FONT + + # default set QRscale to 8 + QRscale = 8 tk.Frame.__init__(self, master, bg='#bcfef9') # Creating a frame for the left side of the screen for drawing @@ -545,11 +582,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! 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) + 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).", wraplength=400, font=TEXT_FONT) + self.label.pack(pady=30) # the drawing area - self.drawing = Image.new('1', (475, 375), 1) + self.drawing = Image.new('1', (325, 179), 1) self.draw = ImageDraw.Draw(self.drawing) self.last_draw = None @@ -558,16 +595,20 @@ class Screen8(tk.Frame): self.draw_size = 1 # Creating the Canvas for drawing - self.canvas = Canvas(self.left_frame, width=475, height=375, bg='white') + self.canvas = Canvas(self.left_frame, width=325, height=179, bg='white') self.canvas.bind("", self.draw_line) self.canvas.pack(pady=20) self.canvas.bind("", self.reset_last_draw) - self.add_qr_box() # Add QR box to the canvas + # 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=10) + # Add Import Image Button + tk.Button(self.buttons_frame, text="Import Image", command=self.import_image, height=2, width=15, bg='peach puff', font=BUTTON_FONT).grid(row=4, column=0, columnspan=2, pady=10, sticky='ew') + + # 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) @@ -624,6 +665,44 @@ class Screen8(tk.Frame): self.canvas.create_rectangle(346, 229, 475, 358, outline='black', fill='white') self.canvas.create_text(355, 260, text="QR", fill="black") + + + def import_image(self): + # Open file dialog to select an image file + file_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.png")]) + + if file_path: + # Check if the selected file has a correct extension + if not (file_path.lower().endswith('.jpg') or file_path.lower().endswith('.png')): + tk.messagebox.showerror("Invalid file", "Please select a .jpg or .png file.") + return + + # Load the image + img = Image.open(file_path) + + # Convert to 1-bit black and white + img = img.convert('1') + + # Resize or crop the image to fit the canvas + if img.size[0] > 325 or img.size[1] > 179: + img = img.crop((0, 0, 325, 179)) + + # Paste the imported image onto the drawing image + self.drawing.paste(img) + + # Save image reference to avoid garbage collection + self.imported_img = ImageTk.PhotoImage(img) + + # Clear the canvas + self.canvas.delete("all") + + # Add image to the canvas + self.image_on_canvas = self.canvas.create_image(0, 0, image=self.imported_img, anchor='nw') + + # Re-add QR box overlay + # self.add_qr_box() + + # txt update class Screen9(tk.Frame): def __init__(self, master): @@ -691,6 +770,7 @@ class Screen13(tk.Frame): 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') @@ -705,11 +785,16 @@ class Screen13(tk.Frame): # go ahead and print the thing def printy(self): - global print_type + global print_type # Specify the path to your image file path_to_image = "/home/trav/Documents/custodiosk/freeze_frame.jpg" + # Get QR data from the main application + QRX = self.master.QRX + QRY = self.master.QRY + QRscale = self.master.QRscale + # make ssb post key = addtoDB.addToSSB(path_to_image,info_text,1) @@ -722,8 +807,8 @@ class Screen13(tk.Frame): qr = qrcode.QRCode( version = 1, error_correction = qrcode.constants.ERROR_CORRECT_H, - box_size = 3, - border = 1, + box_size = QRscale, + border = 0, ) # Add data qr.add_data(key) @@ -739,22 +824,27 @@ class Screen13(tk.Frame): qr = Image.open("qr.jpg") # qr #### 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)) + ## if we didn't custom set X/Y, set to defaults + if QRX is None and QRY is None: + QRX=506 + QRY=217 + merged_image = Image.new('L', (675, 375), "white") + merged_image.paste(drawing, (0, 8)) + merged_image.paste(qr, (QRX, QRY+8)) # we add 8 because this is slightly off from when we drew it merged_image.save("merged_image.png") - # if ribbon we gotta rotate 90 degrees and paste QR in different spot + # if ribbon if print_type == "ribbon": - merged_image.paste(drawing, (100, 0)) - merged_image.paste(qr, (446, 229)) # paste without mask + merged_image = Image.new('L', (375, 675), "white") + merged_image.paste(drawing, (25, 100)) # set it 25 in because that's the border + merged_image.paste(qr, (25, 279)) # 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") + # rotated_image = image.transpose(Image.ROTATE_270) # Transpose and rotate 90 degrees, old version when we weren't doing ribbon vertical + # rotated_image.save("merged_image.png") # Get the ZPL code for the image zpl_code = tozpl.print_to_zpl("merged_image.png") diff --git a/merged_image.png b/merged_image.png new file mode 100644 index 0000000..47d6c21 Binary files /dev/null and b/merged_image.png differ diff --git a/ssb-post.sh b/ssb-post.sh index 1053a15..76c131f 100755 --- a/ssb-post.sh +++ b/ssb-post.sh @@ -54,7 +54,7 @@ then ssb-server publish . <