ECOSYSTEM / DESKTOP

janelkit-desktop

Native file and message dialogs and the system clipboard, awaited without blocking your window.

Ecosystem package janelkit-desktop System services: native file and message dialogs, and the clipboard. It adds no interface controls. pip install janelkit-desktop
DESKTOP · PAGE 1 / 4~2 min read
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

What it adds, and what it does not

janelkit-desktop gives your application two system services that almost every desktop application needs: native dialogs to open, save, choose a folder, show a message and confirm; and the clipboard. Dialogs are awaited with await, so the window keeps responding while the user decides, and the result arrives as a Path, a list, a bool or None when the user cancels.

Despite its name, it is not "the desktop part" of JanelKit. The whole framework is for desktop applications: windows, layout and every control are in the core. If you are looking for <button>, <textfield> or <list>, you already have them.

In one minute: open and copy a note

Install it next to janelkit with pip install janelkit-desktop. This component opens a text file with a native dialog, shows it in an editable area, and copies it to the clipboard. Replace src/App.janel in a project where janelkit-desktop is installed.

janel
<script lang="python">
from janelkit import state, background
from janelkit_desktop import clipboard, dialogs

text = state("")

async def open_note():
    path = await dialogs.open_file("Open note", filters=["Text (*.txt *.md)", "All files (*)"])
    if path is not None:
        text.value = await background(path.read_text, encoding="utf-8")

def copy_note():
    clipboard.copy(text.value)
</script>

<window title="Notes" width={520} height={360}>
  <column padding={24} gap={12}>
    <row gap={8}>
      <button on:click={open_note}>Open…</button>
      <button on:click={copy_note} enabled={len(text) > 0}>Copy</button>
    </row>
    <textarea bind:value={text} placeholder="Open a file or type here" label="Note" flex={1} />
    <text>On the clipboard: {clipboard.paste()}</text>
  </column>
</window>
Copy

Complete component · Save as src/App.janel in a scaffolded project.

How it works

  1. open_note is an async def handler, because dialogs are awaited. The window stays responsive while the dialog is open.
  2. open_file returns a Path, or None if the user cancels. Always check for None before using the result.
  3. Reading the file runs in background so a large file does not freeze the window.
  4. clipboard.paste() is reactive, so the last line follows the clipboard, also when another application changes it.

What you should see

Open… shows the system file dialog. Choosing a file fills the text area; canceling leaves it unchanged. Copy is enabled once there is text and places it on the clipboard, and the last line shows it.

Built on the public API

janelkit-desktop uses janelkit and janelkit.ext only, nothing internal to the core; a repository test checks it. Its test helpers are added to janelkit.inspect with janelkit.ext.inspector.

Learn moreBuild your own package ↗

Versions and changes

janelkit-desktop shares the series with the core: 0.2.x.x works with janelkit 0.2.x.x, and 0.1.x with janelkit 0.1.x, both with Python 3.10 or later.

In 0.2.0.0 notifications were removed: notify, the system tray icon and app.notifications() in janelkit.inspect. The package keeps what almost every desktop application needs: file, folder, message and confirmation dialogs, and the clipboard. To tell the user something inside the application, show a notice in the window itself, for example with an {#if} and a timeout. Importing notify raises an error that explains this.

In 0.1.0 these services left the core: change from janelkit import dialogs, clipboard to from janelkit_desktop import dialogs, clipboard.

Learn moreChanges and migration ↗

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.