qcc_kplugin.session =================== .. py:module:: qcc_kplugin.session .. autoapi-nested-parse:: The live editing session inside KLayout: which design is open, its sidecar, and how edits get rebuilt. Edits are written to ``design.json`` (never to the layout). A background ``qcc watch --no-klive`` process (started on demand, so KQC is imported once) rebuilds in ~0.1 s; without it each commit runs ``qcc build``. When the layout file changes after a commit the view reloads it in place, and the sidecar (``.qcc.json``) is re-read so the tool overlays follow the new geometry. Attributes ---------- .. autoapisummary:: qcc_kplugin.session.CFG_CAPTURE qcc_kplugin.session.CFG_DESIGN qcc_kplugin.session.CFG_DIALOG_COLUMNS qcc_kplugin.session.CFG_GRID qcc_kplugin.session.CFG_LABEL_HEIGHT qcc_kplugin.session.CFG_LOM_LIMIT qcc_kplugin.session.CFG_QCC qcc_kplugin.session.DEFAULT_LABEL_HEIGHT qcc_kplugin.session.ERRORS qcc_kplugin.session.LOG qcc_kplugin.session.SESSION Classes ------- .. autoapisummary:: qcc_kplugin.session.Session Functions --------- .. autoapisummary:: qcc_kplugin.session.build_error qcc_kplugin.session.clean_env qcc_kplugin.session.config qcc_kplugin.session.default_qcc qcc_kplugin.session.failure_summary qcc_kplugin.session.guard_error qcc_kplugin.session.label_args qcc_kplugin.session.label_height qcc_kplugin.session.log qcc_kplugin.session.message qcc_kplugin.session.ok_cancel qcc_kplugin.session.report_error qcc_kplugin.session.set_config Module Contents --------------- .. py:class:: Session Singleton (see :data:`SESSION`) shared by the menu actions and the tools. .. py:method:: attach_view(view=None) -> bool Pick up the design behind the layout shown in ``view`` (a qcc-written file with a sidecar). .. py:method:: check_external_edit() -> bool design.json was written by someone else since this session last wrote it. Sim groups are bookkeeping (``qcc sim auto`` / ``qcc sim subset`` write the group they simulate): they are kept as they are, and undo / redo carry them over, so undoing a drawing edit never drops the group the results belong to. Any other change becomes one undo step (Undo takes it back), and the layout is rebuilt when it can have changed. Returns True when the file changed. .. py:method:: chip_cell() The DesignChip cell of the layout in the view (its instances are the design's components). .. py:method:: commit(design: dict, what: str = '') -> None .. py:method:: design() -> dict .. py:method:: ensure_design() -> bool A design to edit: the one open, else the one behind the layout in the current view (its sidecar), else the last design used (reopened and rebuilt, e.g. after a KLayout restart). .. py:method:: find_view() (view, cellview index) showing the design's layout, or (None, None). .. py:method:: focus_chip() -> None Show the DesignChip cell as the view's cell: its components are then top-level instances, so KLayout's own select / move / rotate / properties work on them (each move is written back to design.json). .. py:method:: open(design_path) -> None Use ``design_path``; its layout is ``/build/.oas`` unless the sidecar says otherwise. .. py:method:: redo() -> bool .. py:method:: reload_sidecar(force: bool = False) -> bool .. py:method:: reload_view() -> None Reload the rebuilt layout in place. Reloading drops KLayout back to its select mode, so the Quantcore tool that was active (Connect, Route handles, Move/Snap) is switched on again: drawing goes on after each edit. .. py:method:: sidecar_path() -> pathlib.Path | None .. py:method:: start_watch() -> None .. py:method:: stop_watch() -> None .. py:method:: sync_live_pcells() -> None Settings > live PCells: Quantcore PCells placed with KLayout's Instance tool, or edited in its PCell dialog → design.json (one commit, so Undo takes it back), rebuilt. .. py:method:: sync_native_moves() -> None Components moved / rotated with KLayout's own tools (or its properties dialog) → design.json, rebuilt. .. py:method:: tick() -> None .. py:method:: undo() -> bool .. py:method:: watching() -> bool .. py:attribute:: builder :type: subprocess.Popen | None :value: None .. py:attribute:: built :type: dict .. py:property:: capture_px :type: float .. py:attribute:: data :type: dict | None :value: None .. py:attribute:: design_path :type: pathlib.Path | None :value: None .. py:attribute:: failed_routes :type: dict[str, str] .. py:attribute:: future :type: list[dict] :value: [] .. py:property:: grid :type: float Snap grid (µm): KLayout's editor grid (``edit-grid`` of the current view, else of the application), so the plugin's nodes snap like KLayout's own shapes; the plugin Settings grid when KLayout has none. .. py:attribute:: history :type: list[dict] :value: [] .. py:attribute:: last_error :type: str | None :value: None .. py:attribute:: layout_path :type: pathlib.Path | None :value: None .. py:attribute:: listeners :value: [] .. py:property:: qcc :type: str .. py:attribute:: timer :value: None .. py:attribute:: watcher :type: subprocess.Popen | None :value: None .. py:function:: build_error(out: str) -> str The line of a failed ``qcc build`` output worth showing: the last exception line (``RoutingError: route R2: ...``), else the last line that is not a warning (a ``FutureWarning`` is printed after the error at exit and would hide it). .. py:function:: clean_env() -> dict Environment for child processes, so ``qcc`` (conda Python + pip ``klayout``) starts as from a terminal. Drops KLayout's embedded-Python variables and removes KLayout's own folders from PATH: otherwise the pip ``klayout`` extension in the child can pick up the GUI's ``klayout_*.dll`` (another version) and hang. .. py:function:: config(key: str, default: str = '') -> str .. py:function:: default_qcc() -> str ``qcc`` when Settings has none: on PATH, else the conda env ``qcd`` (KLayout started from the Start menu does not see the conda env's Scripts folder). .. py:function:: failure_summary(failed: dict[str, str]) -> str Status-bar text for the routes a build left out: names and reasons, and where to fix them. .. py:function:: guard_error(what: str) -> None An exception escaped a mouse / key / timer handler: log it and put a one-line note in the status bar. Never a dialog (a mouse-move handler runs ~60 times a second) and never re-raised (KLayout would show a "Script Error"). The same error is logged once, then only counted. .. py:function:: label_args() -> list[str] ``qcc build`` / ``qcc watch`` arguments for the label height (an annotation layer only: the fab mask, the simulations and the design hash do not change). .. py:function:: label_height() -> float Settings ▸ instance name label height (µm, 0 = none): the plugin's builds pass it as ``--label-height``. .. py:function:: log(text: str) -> None Append to ``%TEMP%/qcc_kplugin.log``: KLayout started from the Start menu has no visible console. .. py:function:: message(text: str, secs: float = 6, log_it: bool = True) -> None Status-bar message (and console + log). Progress lines that repeat every timer tick pass ``log_it=False``. .. py:function:: ok_cancel(dialog) OK / Cancel buttons wired to ``dialog``. KLayout 0.30's pya has no ``QDialogButtonBox(buttons, parent)`` constructor (it reads the flags as an orientation and raises), so the buttons are set afterwards. .. py:function:: report_error(what: str) -> None A tool action failed: the traceback goes to the log, a message box tells the user (not silently lost). .. py:function:: set_config(key: str, value) -> None .. py:data:: CFG_CAPTURE :value: 'qcc-kplugin-capture-px' .. py:data:: CFG_DESIGN :value: 'qcc-kplugin-design' .. py:data:: CFG_DIALOG_COLUMNS :value: 'qcc-kplugin-dialog-columns' .. py:data:: CFG_GRID :value: 'qcc-kplugin-grid' .. py:data:: CFG_LABEL_HEIGHT :value: 'qcc-kplugin-label-height' .. py:data:: CFG_LOM_LIMIT :value: 'qcc-kplugin-lom-limit-min' .. py:data:: CFG_QCC :value: 'qcc-kplugin-qcc-exe' .. py:data:: DEFAULT_LABEL_HEIGHT :value: 70.0 .. py:data:: ERRORS :type: list[str] :value: [] .. py:data:: LOG .. py:data:: SESSION