ECOSYSTEM / START HERE

Build your own package

The public extension points of the core: the same ones janelkit-router, janelkit-store and janelkit-desktop are built with.

ECOSYSTEMPackages that add navigation, shared data, system services, translations and editor support. Each one is installed on its own and uses only the public API of the core.
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.

The rules every package follows

The packages of the ecosystem have no private access to the core. Everything they do, a package of yours can do too, with three rules.

  1. Use only the public API: the names exported by janelkit, and those of janelkit.compiler, janelkit.diagnostics, janelkit.inspect and janelkit.ext. Being importable does not make a module public.
  2. Share the series: version your package E.S.x.x and require the same series of the core, such as janelkit>=0.2,<0.3.
  3. Never make the core depend on you: an application that does not install your package must not notice it.

Learn morePython API reference ↗

Ship components and elements

An installed package can ship .janel components and .qml elements in its Python package folder. Applications import them by the package name, like any component: from my_package import Card uses Card.janel (or Card.qml) from the folder of my_package when it is not in the project’s src/. janel build writes their QML in build/qml/_paquetes/. Write them with a capital letter in templates, as every imported tag.

python
# my_package/__init__.py ships Card.janel next to it.
# In an application:
from my_package import Card      # then <Card title="Hello" /> in the template
Copy

Mount components from Python: hosts

A .qml element whose root is a JkDeck (import Janel) shows one of its children at a time and grows to fill its place. If it also declares a property JkHost name, then <Element name={obj} /> hands the element to obj, a janelkit.ext.Host, which mounts components inside it. This is how <Pages> and <Sections> of janelkit-router are made.

NameWhat it is
HostBase of a host. obj.attach(container) is called when the element exists, and obj.detach(container) when it is destroyed.
ContainerWhat attach receives: item (the Qt object), visibility (the gate of where it is, or None), mount(Component, visibility=None, context=None, **props_and_on_events) and nested(item).
ChildWhat mount returns: name, instance (its namespace), item, visibility, leave_guards() and dispose().
GateA visibility gate: Gate(parent=None), set_open(bool), reactive visible. While it, or one outside it, is closed, what its components show waits, and is_visible() reads it.
ask_to_leaveask_to_leave(guards, proceed, refuse=None) asks the before_leave guards in order and calls proceed if none returns False.
is_componentis_component(value): whether value is a component imported from a .janel, what mount and open_window accept.

Keep data per application: session and writes

Data that belongs to an application, not to the Python process, lives in its session: one per run() and a new one per inspect.mount(), each with its own data folder, so a test never sees what the previous one left. To know who changes what, a package can watch every state write before it happens. This is how janelkit-store is made.

NameWhat it is
session / Sessionsession() returns the running application’s session, or None: name, data_dir, data (a dictionary for packages, one key each) and on_end(fn).
on_writeon_write(fn) calls fn(target, owner, before) just before every state write; if fn raises, the write does not happen. Returns a function that removes it. Costs nothing while nobody listens.
ownown(target, owner) marks a State or reactive collection, and everything inside it, as belonging to owner; what is inserted later inherits it.
ScopeA scope for what belongs to no component: Scope(); with scope.active(): makes what is created inside its own; dispose() releases it all.
__jk_bind__If the attribute at the end of bind:value={obj.field} is managed by a descriptor that defines __jk_bind__(self, obj, value), bind: writes through it and may refuse.
appapp() returns the running application, or None: engine (the QQmlEngine), qt_app and main_window().

Extend tests and the janel command

@inspector("name") on fn(app, *args) adds the method MountedApp.name to janelkit.inspect; janelkit-desktop adds dialogs() and answer_dialog() this way, and janelkit-store adds store() and mutations().

A package declares janel subcommands as entry points of the janelkit.commands group. The entry point’s name is the command’s, and it points at configure(parser), which adds its arguments and sets parser.set_defaults(func=run); run(args) returns the exit code, and the first line of configure’s docstring is the help. A plugin that fails to load, or tries to redefine a JanelKit command, is ignored with a warning.

shell
# pyproject.toml of your package
[project.entry-points."janelkit.commands"]
package = "janelkit_package.cli:configure"
Copy

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