StockManager is a web application at its core, but it ships with a native desktop wrapper powered by PyWebView. When you runDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/InnoDev69/StockManager/llms.txt
Use this file to discover all available pages before exploring further.
python main.py, the application starts the Waitress WSGI server in a background thread and then opens a platform-native window that points to http://127.0.0.1:5000 — giving users a full desktop experience without requiring a separate browser. No web server setup, no exposed port visible to the network.
How It Works
main.py orchestrates the entire startup sequence in a single script. Waitress runs as a daemon thread so that the process stays alive only while the PyWebView window is open; closing the window triggers the cleanup() function, which stops the scheduler, shuts down Waitress, and closes all database connections.
Window Configuration
The native window is created withwebview.create_window() using these settings:
| Setting | Value |
|---|---|
| Title | "Stockly" |
| Default width | 1200 px |
| Default height | 800 px |
| Minimum width | 800 px |
| Minimum height | 600 px |
| URL | http://127.0.0.1:5000 |
Startup Sequence
Scheduler starts
Before any server thread is launched, the background
Scheduler registers and starts
its periodic tasks: log cleanup every 24 hours and root-user integrity check every
30 minutes. Both run in separate daemon threads.Waitress starts in a daemon thread
run_waitress() is called in a threading.Thread(daemon=True) named "waitress".
Because it is a daemon thread, it is automatically terminated when the main thread
(the PyWebView event loop) exits.Health check waits for port 5000
Rather than sleeping for a fixed delay,
main.py calls wait_for_server(), which
polls the TCP port every 50 ms until a connection succeeds or a 15-second timeout
is reached. A RuntimeError is raised if the server does not become ready in time.PyWebView window opens
Once the health check succeeds,
webview.create_window() is called and
webview.start() enters the native GUI event loop. The application is now fully
running. On Linux, if the resolved icon path exists, the icon is passed to
webview.start(icon=icon_path); on Windows and macOS the icon is embedded in the
executable at build time.Running in Development Mode
To run the Flask server directly without PyWebView (useful for browser-based development and hot-reload), userun-dev.py:
DEBUG=1 in the environment and calls app.run(host="127.0.0.1", port=5000, debug=True), which enables Werkzeug’s reloader and interactive debugger. The PyWebView window is not opened.
Platform Notes
Linux
Linux requires GTK3 and WebKit2GTK to be installed on the host system before runningmain.py:
main.py sets PYWEBVIEW_GTK=1 and WEBKIT_DISABLE_DMABUF_RENDERER=1 automatically via os.environ.setdefault, so both flags are active without any manual configuration.
Windows and macOS
No additional system dependencies are required. PyWebView uses the platform’s built-in web engine (WebView2 / EdgeChromium on Windows, WKWebView on macOS).Building a Standalone Executable
StockManager uses PyInstaller to produce a self-contained distributable. The build is fully described inbuild.spec at the project root.
dist/stockly/. On Windows the entry point is dist/stockly/stockly.exe; on Linux it is dist/stockly/stockly.
When the application is running from the compiled bundle,
getattr(sys, "frozen", False)
returns True. This sets IS_EXECUTABLE = True and causes the APP_MODE template
variable to display "Ejecutable" instead of "Desarrollo". The database and log paths
are also redirected to user-writable directories (see the Database
page for the exact paths).What build.spec Bundles
The spec file explicitly includes:
templates/andstatic/directories- The
bd/andapi/packages - The
.envfile (for SMTP credentials in the distributed build) - PyWebView data files and, on Linux, GObject Introspection typelibs
- Hidden imports for Flask, Waitress, Jinja2, SQLite3, PyWebView, barcode, Pillow, and ReportLab
tkinter, numpy, pandas, matplotlib, scipy) are explicitly excluded to keep the bundle size small.
GitHub Actions Build
The repository includes a workflow at.github/workflows/build.yml that automatically produces release artifacts for three platforms when a v*.*.* tag is pushed:
| Artifact | Runner | Format |
|---|---|---|
Stockly-windows-x64.zip | windows-latest | ZIP containing stockly\stockly.exe |
Stockly-ubuntu-x64.tar.gz | ubuntu-latest | Tarball containing stockly/stockly |
Stockly-arch-x64.tar.gz | ubuntu-latest (Arch container) | Tarball containing stockly/stockly |
PyGObject and pycairo are installed from pip; on the Windows runner, pythonnet is added for the WinForms backend. The workflow uses PyInstaller 6.19.0 pinned to ensure reproducible builds.