Metadata-Version: 2.4
Name: py-gui-free
Version: 1.0.0
Summary: A small Qt (PySide6) application framework in the Turbo Vision style: application, desktop, menus, status line, dialogs, commands, panels
Author-email: Peter Kokosharov <peter.kokosharov@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/peterkokosharov/py-gui-free
Project-URL: Source, https://github.com/peterkokosharov/py-gui-free
Project-URL: Changelog, https://github.com/peterkokosharov/py-gui-free/blob/main/CHANGELOG.md
Keywords: gui,qt,pyside6,mdi,application-framework,turbo-vision,owl
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: X11 Applications :: Qt
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: MacOS X
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: User Interfaces
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE.md
Requires-Dist: PySide6<7,>=6.6
Requires-Dist: py-vision-free<2,>=1.0
Dynamic: license-file

# py-gui-free

A small desktop application framework for Python on Qt (PySide6): an application with a menu
bar, a status line, a desktop of numbered windows, dialogs, commands and dockable panels.
Python 3.12 or newer, on Windows, Linux and macOS.

It is built the way Borland's application frameworks were (Turbo Vision, ObjectWindows), and
it uses the same model as its text-mode sibling
[py-vision-free](https://pypi.org/project/py-vision-free/): the same command ids, the same
menu and status-line data, the same validators. A program written for one reads like a program
written for the other.

## Install

    pip install py-gui-free

The import name is `py_gui_free`. It installs PySide6 (LGPL) and py-vision-free.

## A first program

```python
from py_gui_free import CMD_USER, Application, Command, MenuItem, StatusItem, SubMenu
from py_gui_free import Window, message_box
from PySide6.QtWidgets import QLabel

CM_GREETING = CMD_USER + 1


class Hello(Application):
    title = "Hello"

    def setup(self) -> None:
        self.set_menu_bar([
            SubMenu("~F~ile", [
                MenuItem("~G~reeting...", CM_GREETING, shortcut="Alt-G"),
                MenuItem("-"),
                MenuItem("E~x~it", Command.QUIT, shortcut="Alt-X"),
            ]),
            SubMenu("~W~indow", [
                MenuItem("~T~ile", Command.TILE),
                MenuItem("C~a~scade", Command.CASCADE),
                MenuItem("~N~ext", Command.NEXT, shortcut="F6"),
            ]),
        ])
        self.set_status_line([StatusItem("~Alt-X~ Exit", "Alt+X", Command.QUIT)])
        self.insert_window(Window("Hello", QLabel("Hello, desktop!")), (300, 160))

    def handle_event(self, ev) -> None:
        if ev.command == CM_GREETING:
            message_box(self, "Hello, World!", "Hello")
            ev.clear()


Hello().run()
```

## The pieces

| Name | What it is |
|---|---|
| `Application` | the main window: menu bar, tool bar (`add_tool`), status line, desktop, panels; `setup()`, `handle_event(ev)`, `exec_view(dialog)`, `gui_call(fn)` |
| `Desktop`, `Window` | numbered windows over QMdiArea: `tile`, `cascade`, `select_next_window`, `select_previous_window`, `zoom`, `close_current`; `Window.valid(command)` |
| `Dialog` | named fields (`add_field`), command buttons (`add_buttons`), `get_data` / `set_data`, `valid(command)` |
| `message_box`, `input_box` | the two everyday dialogs, with the text-mode signatures (`default=`, `input_grace_ms=`, `max_length`; `validator=` keyword-only) |
| `QtValidator` | a py-vision-free validator as a QValidator |
| `Panel` | a widget docked at one side of the main window, shown and hidden by a command |
| `Transcript`, `Entry`, `EntryKind` | a scrolling read-only record of entries (kind, heading, body) with an optional input box; `begin(kind, heading)` returns an `Entry` to `write` into from any thread |
| `gui_call(fn)` | run `fn` on the GUI thread soon, from any thread |
| `Document`, `DocView`, `DocManager` | New, Open, Save, Save As and "save changes?" |
| `Command`, `CMD_USER`, `SubMenu`, `MenuItem`, `StatusItem`, `OK`, `OK_CANCEL`, `YES_NO`, the validators | shared with py-vision-free: the same objects |

**Commands** are integers. The standard ones are `Command.QUIT`, `Command.TILE`,
`Command.CASCADE`, `Command.NEXT`, `Command.PREV`, `Command.ZOOM`, `Command.CLOSE`,
`Command.SAVE`, ...; an application numbers its own from `CMD_USER`. A command from a menu
item, a status item, a tool button or `app.command(id)` goes to the active window's
`handle_event`, then to the application's, then to the standard handler.
`disable_commands([...])` greys every item and button of those commands;
`enable_state(id) -> (enabled, checked)` lets the application answer per command (it is asked
at idle and before a menu opens; a `checked` value makes a menu item a check item).

**Labels and keys** use the text-mode notation: `"~F~ile"` marks the hot key, `"Alt-X"`,
`"Ctrl+S"`, `"Shift-F6"` name the keys.

**Threads**: only the GUI thread may touch widgets. A worker calls `gui_call(fn)` (or
`app.gui_call(fn)`, the same function) and `fn` runs on the GUI thread on a later turn of the
event loop, in call order. `Entry.write(text)` does this by itself when it is called off the
GUI thread; the other `Transcript` methods (`begin`, `add`, `note`, `clear`, `set_busy`) raise
`RuntimeError` there.

**Transcript**: a record of entries for logs and conversations.

```python
from py_gui_free import EntryKind, Transcript

record = Transcript(prompt=True, on_submit=lambda text: print("sent:", text))
record.note("Ready.")                                   # a one-line remark
record.add(EntryKind.LOCAL, "You", "hello")              # a whole entry
answer = record.begin(EntryKind.REMOTE, "Bot")           # an open entry ...
answer.write("hel").write("lo")                          # ... filled piece by piece
answer.close()
record.set_busy(True)                                    # Send and Ctrl+Enter refused
```

Text goes in as plain text, never as markup. The view follows new text only while it is
scrolled to the bottom. Kinds are `LOCAL`, `REMOTE`, `SYSTEM` and `FAULT` (or the strings
`"local"`, ...); each has its own heading colour.

## Examples

    python examples/hello.py     # three windows; Window menu: tile, cascade, next, previous, zoom
    python examples/dialogs.py   # a form with validators and get_data / set_data
    python examples/panels.py    # dock panels, tool bar, checked View items, documents
    python examples/mirror.py    # a Transcript fed word by word from a worker thread

Each example takes `--shot picture.png` to save a picture of its window and exit; with
`QT_QPA_PLATFORM=offscreen` this works without a display.

## Publishing (maintainers)

Releases go to PyPI from GitHub Actions with Trusted Publishing (no token): add a pending
publisher on PyPI for project `py-gui-free`, workflow `publish.yml`, environment `pypi`;
create the environment `pypi` in the GitHub repository; then push a tag `vX.Y.Z` equal to the
version in `pyproject.toml` and `py_gui_free.__version__`.

## Links

- [NOTICE](https://github.com/peterkokosharov/py-gui-free/blob/main/NOTICE.md) (credits; PySide6 / Qt LGPL note)
- [License](https://github.com/peterkokosharov/py-gui-free/blob/main/LICENSE) (MIT)
- [py-vision-free](https://pypi.org/project/py-vision-free/), the text-mode sibling
