Files
signage-player/test_touch.py
2025-08-06 02:27:50 +03:00

231 lines
8.9 KiB
Python

#!/usr/bin/env python3
"""
Touch Display Test - Test the touch-optimized interface with virtual keyboard
"""
import tkinter as tk
import sys
import os
sys.path.append('tkinter_app/src')
def test_touch_interface():
"""Test the touch-optimized settings interface"""
try:
from tkinter_simple_player import SettingsWindow
# Create main window
root = tk.Tk()
root.title("🎮 Touch Display Test")
root.geometry("1024x768")
root.configure(bg='#2c3e50')
# Create welcome screen
welcome_frame = tk.Frame(root, bg='#2c3e50', padx=40, pady=40)
welcome_frame.pack(fill=tk.BOTH, expand=True)
# Title
title_label = tk.Label(welcome_frame,
text="🎬 Touch Display Digital Signage",
font=('Segoe UI', 24, 'bold'),
fg='white', bg='#2c3e50')
title_label.pack(pady=30)
# Description
desc_text = (
"Touch-Optimized Features:\n\n"
"📱 Virtual On-Screen Keyboard\n"
"🎯 Larger Touch-Friendly Buttons\n"
"⌨️ Auto-Show Keyboard on Input Focus\n"
"👆 Enhanced Touch Feedback\n"
"🎨 Dark Theme Optimized for Displays\n\n"
"Click the button below to test the settings interface:"
)
desc_label = tk.Label(welcome_frame, text=desc_text,
font=('Segoe UI', 14),
fg='#ecf0f1', bg='#2c3e50',
justify=tk.CENTER)
desc_label.pack(pady=20)
# Create mock app for testing
class MockApp:
def __init__(self):
self.playlist = []
self.current_index = 0
def play_current_media(self):
print("Mock: play_current_media called")
mock_app = MockApp()
# Test button to open touch-optimized settings
def open_touch_settings():
try:
settings = SettingsWindow(root, mock_app)
print("✅ Touch-optimized settings window opened successfully!")
except Exception as e:
print(f"❌ Error opening settings: {e}")
import traceback
traceback.print_exc()
# Large touch-friendly button
settings_btn = tk.Button(welcome_frame,
text="🔧 Open Touch Settings",
command=open_touch_settings,
bg='#3498db', fg='white',
font=('Segoe UI', 16, 'bold'),
relief=tk.FLAT, padx=40, pady=20,
cursor='hand2')
settings_btn.pack(pady=30)
# Instructions
instructions = (
"Touch Instructions:\n"
"• Tap input fields to show virtual keyboard\n"
"• Use large buttons for easy touch interaction\n"
"• Virtual keyboard stays on top for easy access\n"
"• Click outside input fields to hide keyboard"
)
instr_label = tk.Label(welcome_frame, text=instructions,
font=('Segoe UI', 11),
fg='#bdc3c7', bg='#2c3e50',
justify=tk.LEFT)
instr_label.pack(pady=20)
# Exit button
exit_btn = tk.Button(welcome_frame,
text="❌ Exit Test",
command=root.quit,
bg='#e74c3c', fg='white',
font=('Segoe UI', 12, 'bold'),
relief=tk.FLAT, padx=30, pady=15,
cursor='hand2')
exit_btn.pack(pady=20)
# Add touch feedback to buttons
def add_touch_feedback(button):
def on_press(e):
button.configure(relief=tk.SUNKEN)
def on_release(e):
button.configure(relief=tk.FLAT)
def on_enter(e):
button.configure(relief=tk.RAISED)
def on_leave(e):
button.configure(relief=tk.FLAT)
button.bind("<Button-1>", on_press)
button.bind("<ButtonRelease-1>", on_release)
button.bind("<Enter>", on_enter)
button.bind("<Leave>", on_leave)
add_touch_feedback(settings_btn)
add_touch_feedback(exit_btn)
print("🎮 Touch Display Test Started")
print("=" * 50)
print("Features being tested:")
print("- Virtual keyboard integration")
print("- Touch-optimized input fields")
print("- Large, finger-friendly buttons")
print("- Enhanced visual feedback")
print("- Dark theme for displays")
print("\nClick 'Open Touch Settings' to test the interface!")
root.mainloop()
except Exception as e:
print(f"❌ Error in touch interface test: {e}")
import traceback
traceback.print_exc()
def test_virtual_keyboard_standalone():
"""Test just the virtual keyboard component"""
try:
from virtual_keyboard import VirtualKeyboard, TouchOptimizedEntry, TouchOptimizedButton
root = tk.Tk()
root.title("🎹 Virtual Keyboard Test")
root.geometry("800x500")
root.configure(bg='#2f3136')
# Create virtual keyboard
vk = VirtualKeyboard(root, dark_theme=True)
# Test interface
test_frame = tk.Frame(root, bg='#2f3136', padx=30, pady=30)
test_frame.pack(fill=tk.BOTH, expand=True)
tk.Label(test_frame, text="🎹 Virtual Keyboard Test",
font=('Segoe UI', 20, 'bold'),
bg='#2f3136', fg='white').pack(pady=20)
tk.Label(test_frame, text="Click on the input fields below to test the virtual keyboard:",
font=('Segoe UI', 12),
bg='#2f3136', fg='#b9bbbe').pack(pady=10)
# Test input fields
tk.Label(test_frame, text="Server IP:", bg='#2f3136', fg='white',
font=('Segoe UI', 11, 'bold')).pack(anchor=tk.W, pady=(20, 5))
entry1 = TouchOptimizedEntry(test_frame, vk, width=40, bg='#36393f',
fg='white', insertbackground='white')
entry1.pack(pady=5, fill=tk.X)
tk.Label(test_frame, text="Device Name:", bg='#2f3136', fg='white',
font=('Segoe UI', 11, 'bold')).pack(anchor=tk.W, pady=(15, 5))
entry2 = TouchOptimizedEntry(test_frame, vk, width=40, bg='#36393f',
fg='white', insertbackground='white')
entry2.pack(pady=5, fill=tk.X)
tk.Label(test_frame, text="Password:", bg='#2f3136', fg='white',
font=('Segoe UI', 11, 'bold')).pack(anchor=tk.W, pady=(15, 5))
entry3 = TouchOptimizedEntry(test_frame, vk, width=40, bg='#36393f',
fg='white', insertbackground='white', show='*')
entry3.pack(pady=5, fill=tk.X)
# Control buttons
btn_frame = tk.Frame(test_frame, bg='#2f3136')
btn_frame.pack(pady=30)
TouchOptimizedButton(btn_frame, text="🎹 Show Keyboard",
command=lambda: vk.show_keyboard(entry1),
bg='#7289da', fg='white').pack(side=tk.LEFT, padx=10)
TouchOptimizedButton(btn_frame, text="❌ Hide Keyboard",
command=vk.hide_keyboard,
bg='#ed4245', fg='white').pack(side=tk.LEFT, padx=10)
TouchOptimizedButton(btn_frame, text="🔄 Clear All",
command=lambda: [e.delete(0, tk.END) for e in [entry1, entry2, entry3]],
bg='#faa61a', fg='white').pack(side=tk.LEFT, padx=10)
print("🎹 Virtual Keyboard Test Started")
print("- Click input fields to auto-show keyboard")
print("- Type using virtual or physical keyboard")
print("- Test touch-friendly interface")
root.mainloop()
except Exception as e:
print(f"❌ Error in virtual keyboard test: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Touch Display Tests")
parser.add_argument("--keyboard-only", action="store_true",
help="Test only the virtual keyboard component")
args = parser.parse_args()
print("🎮 Touch Display Digital Signage Tests")
print("=" * 50)
if args.keyboard_only:
test_virtual_keyboard_standalone()
else:
test_touch_interface()
print("\n✅ Touch display tests completed!")