Add screenshot functionality

This commit is contained in:
csd4ni3l
2025-10-13 18:46:48 +02:00
parent 80e6025d7a
commit 00fdbf7fe6

View File

@@ -1,8 +1,10 @@
import arcade, arcade.gui, random
import arcade, arcade.gui, random, datetime
from utils.utils import cubic_bezier_points, get_gate_port_position
from utils.constants import dropdown_style, LOGICAL_GATES
from datetime import datetime
class LogicalGate(arcade.gui.UIBoxLayout):
def __init__(self, id, x, y, gate_type):
super().__init__(x=x, y=y, space_between=2, vertical=False)
@@ -65,9 +67,26 @@ class Game(arcade.gui.UIView):
evaluate_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Evaluate", style=dropdown_style))
evaluate_button.on_click = lambda event: self.run_logic()
screenshot_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Screenshot", style=dropdown_style))
screenshot_button.on_click = lambda event: self.screenshot()
hide_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Hide", style=dropdown_style))
hide_button.on_click = lambda event: self.hide_show_panel()
def screenshot(self):
image = arcade.get_image()
now = datetime.now()
timestamp = now.strftime("%Y-%m-%d_%H-%M-%S")
image.save(f"{timestamp}.png")
self.add_widget(arcade.gui.UIMessageBox(
width=self.window.width / 2,
height=self.window.height / 2,
message_text=f"Screenshot was succesfully saved as {timestamp}.png in the current directory!",
title="Screenshot successful.",
buttons=("OK",)
))
def hide_show_panel(self):
new_state = not self.tools_box.children[0].visible
hide_button = None