commited with removed gtk wrapper. Simple python run file with all requirements.

This commit is contained in:
2025-11-09 08:55:29 +01:00
parent 2b5ec1d9b1
commit 1e55305914
7 changed files with 8242 additions and 1748 deletions
-140
View File
@@ -1,140 +0,0 @@
# GTK Wrapper for Flask Application
This wrapper embeds your Flask web application in a native GTK window using WebKit2, providing a desktop application experience.
## Installation
### Prerequisites
- Python 3.6+
- GTK 3.0
- WebKit2 4.0
- PyGObject
### Automatic Setup (Linux)
Run the provided setup script:
```bash
bash setup_gtk_wrapper.sh
```
This will install all required system packages and Python dependencies.
### Manual Setup
If the automated script doesn't work for your system, install the packages manually:
**Ubuntu/Debian:**
```bash
sudo apt-get update
sudo apt-get install -y python3-gi gir1.2-gtk-3.0 gir1.2-webkit2-4.1 libgtk-3-0 libwebkit2gtk-4.1-0
pip3 install flask
```
**Fedora/RHEL:**
```bash
sudo dnf install python3-gobject gtk3 webkit2-gtk3
pip3 install flask
```
**Arch Linux:**
```bash
sudo pacman -S python-gobject gtk3 webkit2gtk
pip3 install flask
```
**macOS (via Homebrew):**
```bash
brew install gtk+3 webkit2gtk python3
pip3 install flask
```
## Usage
Run the GTK wrapper with:
```bash
python3 gtk_wrapper.py
```
Or make it executable and run directly:
```bash
chmod +x gtk_wrapper.py
./gtk_wrapper.py
```
## Features
- **Native GTK Window**: Runs your Flask app in a native GTK 3 window
- **WebKit2 Rendering**: Uses WebKit2 for modern web rendering
- **Background Flask Server**: Automatically starts your Flask app in a background thread
- **Developer Mode**: Developer tools are enabled for debugging (inspect element)
- **Responsive UI**: Window is resizable and responsive
## Configuration
You can customize the wrapper by editing `gtk_wrapper.py`:
### Window Size
```python
self.set_default_size(1200, 800) # Change to desired width, height
```
### Window Title
```python
self.set_title('Your App Title')
```
### Flask Server Port
```python
self.flask_port = 5000 # Change to desired port
```
### Developer Tools
To disable developer tools (inspect element), comment out:
```python
self.webview.get_settings().set_property('enable-developer-extras', True)
```
## Troubleshooting
### "No module named 'gi'"
Install PyGObject: `pip3 install PyGObject`
### "gi.repository.Gtk" not found
Install GTK bindings: `sudo apt-get install python3-gi gir1.2-gtk-3.0`
### "gi.repository.WebKit2" not found
Install WebKit2 bindings: `sudo apt-get install gir1.2-webkit2-4.0`
### Flask server won't start
- Check if port 5000 is already in use
- Ensure you're running from the correct directory
- Check Flask app for syntax errors
### Page shows "Unable to reach" error
- Wait a few seconds for the Flask server to start
- Check the terminal for Flask startup messages
- Ensure all Flask dependencies are installed
## File Structure
```
TV_APP_V1.0.0/
├── app.py # Your Flask application
├── gtk_wrapper.py # GTK wrapper (this file)
├── setup_gtk_wrapper.sh # Automated setup script
├── GTK_WRAPPER_README.md # This file
├── templates/ # Flask templates
├── static/ # Flask static files
└── locales/ # Language files
```
## Notes
- The Flask app runs in debug mode disabled to prevent auto-reloading conflicts with GTK
- The app uses threading to run Flask in the background without blocking GTK events
- All Flask features (routing, sessions, file uploads, etc.) work normally
## Support
For issues with the Flask app itself, see the main app documentation.
For GTK/WebKit issues, refer to the respective project documentation.
-107
View File
@@ -1,107 +0,0 @@
#!/usr/bin/env python3
"""
GTK Wrapper for Flask Application
Runs the Flask app in a separate thread and displays it in a GTK window using WebKit
"""
import sys
import threading
import time
import gi
import os
from pathlib import Path
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.1')
from gi.repository import Gtk, WebKit2, GLib
# Import the Flask app
from app import app as flask_app
class FlaskWindow(Gtk.ApplicationWindow):
def __init__(self, application):
super().__init__(application=application)
self.flask_thread = None
self.flask_port = 5000
self.flask_host = '127.0.0.1'
self.flask_url = f'http://{self.flask_host}:{self.flask_port}/'
# Configure window
self.set_title('Shooting Range Management System')
self.set_default_size(1200, 800)
self.set_position(Gtk.WindowPosition.CENTER)
# Create WebKit view
self.webview = WebKit2.WebView()
self.webview.get_settings().set_property('enable-developer-extras', True)
# Create container
container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
container.pack_start(self.webview, True, True, 0)
self.add(container)
self.connect('destroy', self.on_destroy)
# Start Flask server in background
self.start_flask_server()
# Load the Flask app in WebView after a short delay to ensure server is ready
GLib.timeout_add(2000, self.load_flask_url)
def start_flask_server(self):
"""Start Flask development server in a separate thread"""
def run_flask():
# Change to app directory to ensure relative paths work
app_dir = Path(__file__).parent
os.chdir(app_dir)
# Run Flask app
flask_app.run(
host=self.flask_host,
port=self.flask_port,
debug=False,
use_reloader=False,
threaded=True
)
self.flask_thread = threading.Thread(target=run_flask, daemon=True)
self.flask_thread.start()
print(f"Flask server starting on {self.flask_url}")
def load_flask_url(self):
"""Load the Flask application in the WebView"""
try:
self.webview.load_uri(self.flask_url)
print(f"Loading {self.flask_url}")
return False # Don't repeat
except Exception as e:
print(f"Error loading Flask URL: {e}")
return False
def on_destroy(self, widget):
"""Handle window close event"""
print("Closing application...")
Gtk.main_quit()
class FlaskGTKApp(Gtk.Application):
def __init__(self):
super().__init__(application_id='com.example.flaskgtk')
self.connect('activate', self.on_activate)
def on_activate(self, app):
window = FlaskWindow(app)
window.show_all()
window.present()
def main():
app = FlaskGTKApp()
return app.run(sys.argv)
if __name__ == '__main__':
sys.exit(main())
-23
View File
@@ -1,23 +0,0 @@
#!/bin/bash
# Setup script for GTK Wrapper dependencies
echo "Installing GTK wrapper dependencies..."
# Update package list
sudo apt-get update
# Install GTK3 and WebKit2 development libraries
echo "Installing GTK3 and WebKit2 libraries..."
sudo apt-get install -y \
python3-gi \
gir1.2-gtk-3.0 \
gir1.2-webkit2-4.0 \
libgtk-3-0 \
libwebkit2gtk-4.0-37
# Install pip packages if needed
echo "Checking Python dependencies..."
pip3 install flask
echo "Setup complete! You can now run the GTK wrapper with:"
echo " python3 gtk_wrapper.py"
Executable
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""
TV_APP V1.0.0 - One-Click Launcher
Automatically installs dependencies and starts the web application
"""
import os
import sys
import subprocess
import webbrowser
import time
import importlib.util
def check_python_version():
"""Check if Python 3.7+ is available"""
if sys.version_info < (3, 7):
print("ERROR: Python 3.7+ is required")
print(f"You have Python {sys.version}")
return False
return True
def check_and_install_flask():
"""Check if Flask is installed, install if not"""
flask_spec = importlib.util.find_spec("flask")
if flask_spec is not None:
import flask
print(f"✓ Flask is installed: v{flask.__version__}")
return True
print("⚠ Flask not found. Installing...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "flask", "-q"])
print("✓ Flask installed successfully")
return True
except subprocess.CalledProcessError:
print("ERROR: Failed to install Flask")
return False
def main():
"""Main installation and startup routine"""
print("\n" + "="*70)
print(" TV_APP V1.0.0 - Installation & Launcher")
print("="*70 + "\n")
# Check Python version
print("[1/4] Checking Python version...")
if not check_python_version():
print("\nPlease install Python 3.7 or higher")
input("Press Enter to exit...")
return False
import flask
print(f"✓ Python {sys.version.split()[0]} found\n")
# Check Flask
print("[2/4] Checking Flask installation...")
if not check_and_install_flask():
input("Press Enter to exit...")
return False
print()
# Verify app.py exists
print("[3/4] Verifying application files...")
app_path = os.path.join(os.path.dirname(__file__), "app.py")
if not os.path.exists(app_path):
print(f"ERROR: app.py not found at {app_path}")
input("Press Enter to exit...")
return False
print("✓ Application found: app.py\n")
# Start the app
print("[4/4] Starting web application...\n")
print("="*70)
print(" TV_APP is starting...")
print("="*70)
print("\nThe application will be available at: http://localhost:5000")
print("Press Ctrl+C to stop the server\n")
time.sleep(2)
# Open browser
try:
webbrowser.open("http://localhost:5000", new=1)
except:
pass
# Change to app directory and run
os.chdir(os.path.dirname(__file__))
try:
# Import and run the Flask app
import app
app.app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)
except ImportError as e:
print(f"ERROR: Could not import app.py: {e}")
input("Press Enter to exit...")
return False
except KeyboardInterrupt:
print("\n\nServer stopped by user")
return True
except Exception as e:
print(f"ERROR: {e}")
input("Press Enter to exit...")
return False
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1513 -1478
View File
File diff suppressed because it is too large Load Diff