quantcore_circuits.live.klayout

Start KLayout from Python when it is not running, so qcc.show / live designs always have a window to draw in.

open_klayout() launches the KLayout GUI (editor mode) if nothing answers on the klive port, optionally with the Quantcore KLayout plugin loaded straight from this repository (for users who have not linked it into their Salt folder yet), with the layout as its argument (so it shows even before klive listens), waits until klive is listening and brings the window to the front. The executable is found via QCC_KLAYOUT or the usual install locations (%APPDATA%\KLayout\klayout_app.exe, %ProgramFiles%\KLayout, klayout on PATH).

Switch: QCC_KLAYOUT_GUI (use_gui(True/False), the tutorials’ KLAYOUT_GUI; default on). Off: a live design only redraws a KLayout that is already open (klive), and never starts one.

Why the window seemed not to open (2026-11-13): KLayout was started (detached, cmd /c start) but its window came up behind the editor / browser (Windows gives the foreground only to the process that has it), or klive reloaded the layout in a KLayout window that was open but hidden; and a Designer tried to start KLayout only once, so after the window was closed a rebuild never reopened it. Now the window is raised (restore + SetForegroundWindow with the foreground thread’s input attached + a topmost toggle) on the first live build and whenever qcc starts KLayout, and a closed window is reopened on the next build. KLayout with the KQC Salt package takes ≈ 15–20 s to start; the wait is 60 s (the layout is on the command line, so it opens either way).

Attributes

Functions

bring_to_front([pid, layout]) → bool

Raise a KLayout window (of pid, else of any KLayout; the one showing layout first): restore it if

find_klayout() → pathlib.Path | None

gui_enabled() → bool

QCC_KLAYOUT_GUI (default on): may qcc start the KLayout window and bring it to the front?

klayout_pids() → list[int]

PIDs of running KLayout GUI processes (psutil if installed, else tasklist / pgrep).

open_klayout([layout, with_plugin, timeout, front]) → dict

Make sure a KLayout GUI with klive is running (start one if needed). Returns what was done.

plugin_installed() → bool

Whether the Quantcore KLayout plugin is linked into the user's KLayout Salt folder.

use_gui([flag]) → bool

Set (True / False) or read (None) the KLayout-window switch; also seen by subprocesses.

Module Contents

quantcore_circuits.live.klayout.bring_to_front(pid: int | None = None, layout: str | pathlib.Path | None = None) → bool

Raise a KLayout window (of pid, else of any KLayout; the one showing layout first): restore it if minimised, give it the foreground, and put it on top. Returns whether a window was found (Windows only).

quantcore_circuits.live.klayout.find_klayout() → pathlib.Path | None
quantcore_circuits.live.klayout.gui_enabled() → bool

QCC_KLAYOUT_GUI (default on): may qcc start the KLayout window and bring it to the front?

quantcore_circuits.live.klayout.klayout_pids() → list[int]

PIDs of running KLayout GUI processes (psutil if installed, else tasklist / pgrep).

quantcore_circuits.live.klayout.open_klayout(layout: str | pathlib.Path | None = None, with_plugin: bool = True, timeout: float = 60.0, front: bool = True) → dict

Make sure a KLayout GUI with klive is running (start one if needed). Returns what was done.

with_plugin: if the Quantcore plugin is not installed in Salt, load it from the repo in the new window. front: raise the KLayout window (the one qcc started, or the one already open). With QCC_KLAYOUT_GUI=0 nothing is started.

quantcore_circuits.live.klayout.plugin_installed() → bool

Whether the Quantcore KLayout plugin is linked into the user’s KLayout Salt folder.

quantcore_circuits.live.klayout.use_gui(flag: bool | None = None) → bool

Set (True / False) or read (None) the KLayout-window switch; also seen by subprocesses.

quantcore_circuits.live.klayout.GUI_ENV = 'QCC_KLAYOUT_GUI'
quantcore_circuits.live.klayout.PLUGIN_LOADER