Build your own package
The public extension points of the core: the same ones janelkit-router, janelkit-store and janelkit-desktop are built with.
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.
- 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.
- 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.
- 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.
# my_package/__init__.py ships Card.janel next to it.
# In an application:
from my_package import Card # then <Card title="Hello" /> in the templateCopyMount 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.
| Name | What it is |
|---|---|
| Host | Base of a host. obj.attach(container) is called when the element exists, and obj.detach(container) when it is destroyed. |
| Container | What 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). |
| Child | What mount returns: name, instance (its namespace), item, visibility, leave_guards() and dispose(). |
| Gate | A 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_leave | ask_to_leave(guards, proceed, refuse=None) asks the before_leave guards in order and calls proceed if none returns False. |
| is_component | is_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.
| Name | What it is |
|---|---|
| session / Session | session() returns the running application’s session, or None: name, data_dir, data (a dictionary for packages, one key each) and on_end(fn). |
| on_write | on_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. |
| own | own(target, owner) marks a State or reactive collection, and everything inside it, as belonging to owner; what is inserted later inherits it. |
| Scope | A 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. |
| app | app() 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.
# pyproject.toml of your package
[project.entry-points."janelkit.commands"]
package = "janelkit_package.cli:configure"CopyEnglish documentation based on the JanelKit source. For additional details, browse the source docs ↗.