How it works
Follow a .janel file from source to window, and one click from the mouse to the updated screen.
janelkit Included with janelkit. Nothing extra to install. What you will learn
- The stages a .janel file goes through before a window appears.
- Which parts run in Python and which in Qt.
- What happens, step by step, between a click and the updated text.
- How to inspect each stage when something goes wrong.
The whole journey in one picture
You can build applications without knowing any of this. It becomes useful when you need to understand an error, a performance question or why a value did not update. The journey has two halves: compiling the file once, and running it while the window is open.
| Stage | What happens | Where |
|---|---|---|
| 1. Parse | The file is split into script, template and style, and the template becomes a tree with source locations. | Compiler (Python) |
| 2. Analyze and lower | Names are checked, imported components are found, and the tree becomes an intermediate representation. | Compiler (Python) |
| 3. Generate | QML for Qt Quick is generated, plus tables describing bindings, handlers and dynamic regions. | Compiler (Python) |
| 4. Run the script | Each component instance runs its script once and gets its own namespace. | Runtime (Python) |
| 5. Bind and draw | Every {expression} is evaluated in Python; Qt Quick draws the controls from the generated QML. | Runtime and Qt |
| 6. React | Input arrives, handlers change state, and only the affected bindings are recalculated. | Runtime and Qt |
Compilation and evaluation are different jobs
The compiler checks the component, analyzes its script and lowers the template into an intermediate representation: a description convenient for generating the interface. It produces QML plus tables that tell the Python runtime about bindings, handlers and dynamic regions. Imported .janel components are resolved and compiled too. QML is generated interface machinery, not a translation of your Python application logic into JavaScript.
Qt Quick loads the generated QML and draws the controls. Meanwhile, the Python runtime evaluates template expressions and executes your functions. A bridge exposes the resulting values to Qt through properties that announce changes. This division explains why you can inspect generated QML without needing to write QML to build an ordinary app.
Creation runs the script once
Creating an instance executes its script in a fresh namespace, the collection of names belonging to that instance, then activates its bindings. Defining a function does not execute its body; a later event calls it.
One component file can describe many instances with independent state. Removing a child through a conditional and showing it again creates a new instance and reruns its script. An ordinary click that changes state does not.
Trace one click through the event loop
An event loop waits for work such as keyboard input, pointer input and timers, then dispatches it to the appropriate code. Qt supplies that loop; JanelKit integrates asynchronous Python work through qasync. A button click reaches the Python handler through the bridge. The handler changes state, and the bindings that read that state become candidates for recalculation. The affected bridge properties notify Qt, which updates the visible result.
Changes made by an event handler are batched, meaning they are grouped instead of treating every assignment as an unrelated interface update. You do not need a manual redraw call. A long blocking function still prevents the interface thread from processing input; automatic reactivity does not turn slow synchronous work into background work.
How it works
- Qt receives the mouse click and finds the <button> under the pointer.
- The bridge calls the Python handler connected with on:click.
- The handler writes count.value; every binding that read count is marked for recalculation.
- When the handler returns, the batch ends: each affected binding is evaluated once in Python.
- Only the bridge properties whose values changed notify Qt, which redraws those controls.
Common mistakes
- Do not add your own infinite while loop to keep the window alive; run already runs the event loop.
- Do not put slow disk or network work directly in a click handler and expect the window to remain responsive.
- Do not expect a state update to execute the entire component script again.
Inspect one layer at a time
janel parse shows the parsed tree or the structural errors, with line and column; janel compile shows the generated QML. janel build validates every component of the project and writes the QML to build/qml, but does not produce an executable. You still need to run the application to exercise its behavior.
Each layer catches different mistakes. Parsing checks structure: unclosed tags, misplaced blocks. Compiling also checks meaning: unknown elements, properties and names. Try it: misspell <button> as <buton> in the counter, run parse, then compile.
janel parse src/App.janel
janel compile src/App.janel
janel buildCopyWhat you should see
With <buton>, parse still prints the tree, because the structure is valid. compile stops with an error at the exact line and column, suggests <button> and lists the built-in elements. Diagnostics are written in Spanish for now: error: elemento desconocido <buton> … sugerencia: ¿quisiste decir <button>?
Common mistakes
- A successful parse does not mean the file is correct; compile or build checks much more.
- Generated QML is machinery, not a file to edit or depend on. Your template is the source.
Key points
- The compiler turns a .janel file into QML plus binding tables; your logic stays in Python.
- Each instance runs its script once; clicks call handlers and update only affected bindings.
- janel parse, compile and build let you inspect each stage.
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.