Metadata-Version: 2.1
Name: medics-ext-graphicpy
Version: 202609020339
Summary: Visual node-based programming extension for MedICS
Author-email: MedICS <medics.support@gmail.com>
License: MIT
Project-URL: Homepage, https://Medical-Image-Computing-Suite.github.io
Project-URL: Documentation, https://github.com/Medical-Image-Computing-Suite/Community/wiki
Project-URL: Repository, https://github.com/Medical-Image-Computing-Suite/medics-ext-graphicpy.git
Project-URL: Issues, https://github.com/Medical-Image-Computing-Suite/Community/issues
Keywords: medical,python,graph editor,node,extension
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: medics
Requires-Dist: vtk>=9.3.1
Requires-Dist: itk>=5.4.0
Requires-Dist: pandas>=2.2.0
Requires-Dist: SimpleITK>=2.3.0
Requires-Dist: NodeGraphQt>=0.6.43
Requires-Dist: seaborn>=0.13.2
Requires-Dist: polars>=1.36.1
Requires-Dist: plotly>=6.5.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-qt>=4.0.0; extra == "dev"

# GraphicPy

GraphicPy is a MedICS extension for **visual, node-based Python programming**. You assemble a graph of nodes on a canvas, connect outputs to inputs, run the graph, and optionally export it as Python code.

Use it to prototype image-processing and data pipelines without writing boilerplate wiring by hand.

---

## Open GraphicPy

1. Start **MedICS**.
2. Open GraphicPy from the extensions / toolboxes list (category **Visual Programming**).
3. GraphicPy opens as a tab with three main areas:
   - **Nodes Explorer** (left) — available node types
   - **Canvas** (center) — the graph you build
   - **Properties** (right, hidden until you double-click a node)

The top toolbar has **Graph**, **Edit**, and code actions (**Show Code**, **Refresh Code**, **Run Code**, **Open in PyEditor**). GraphicPy follows the MedICS **light** and **dark** themes.

---

## Build a graph

### Add nodes

Use any of these:

| Action | How |
| --- | --- |
| Drag from the explorer | Drag a node name from **Nodes Explorer** onto the canvas |
| Double-click in the explorer | Drops the node at the center of the view |
| Search | Press **Shift+A**, type a name, press Enter |

The explorer is grouped by category (Basic Nodes, Custom Nodes, Math & Arrays, Image Processing, and so on). Use the filter box to search. Hover a node name to see its signature and docstring.

### Connect nodes

- Drag from an **output port** (right side of a node) to an **input port** (left side).
- Disconnect by dragging the pipe away, or use **Edit → Clear Connections**.
- Pipe style: right-click the canvas → **Pipes** → Curved / Straight / Angle.

### Select, move, and pan

| Gesture | Result |
| --- | --- |
| Left-click a node | Select |
| Left-drag a node | Move |
| Left-drag on empty canvas | Pan |
| Left-click empty canvas | Clear selection |
| Middle-drag, or **Alt+left-drag** | Marquee-select / move |
| **Alt+middle-drag** | Zoom |
| **Alt+Shift+left-drag** | Cut pipes (slicer) |
| Mouse wheel | Zoom |

### Layout and view

- **Ctrl+L** — auto-layout (top to bottom)
- **L** — auto-layout (bottom to top)
- **F** — fit selection in view
- **=** / **-** — zoom in / out
- **H** — reset zoom

---

## Run a graph

Most function nodes have **Run** and **AutoRun** on the node itself.

1. Wire inputs (or type values in the node’s fields).
2. Click **Run** on that node.
3. Downstream nodes that need the result stay **stale** until you run them (or turn AutoRun on).

**AutoRun (on)** re-runs the node when its inputs change. Use it for small, fast nodes; leave it off for slow image or ML calls.

Status icons on a node show success, error, or stale output. Hover the info icon on a canvas node (or an explorer item) for documentation. Double-click a node to open **Properties** (values, ports, and Info).

### Typical first graph

1. Add a **VAR** node and set a value (number, string, or expression).
2. Add a **Print** node and connect VAR’s output to Print’s input.
3. Click **Run** on Print — the value appears in the MedICS console / status.

For images, try **Open File Dialog** → an image-processing node (for example from `cv2` or `skimage`) → **ImageDisplay**.

---

## Built-in nodes

These always appear under **Basic Nodes**:

| Node | Role |
| --- | --- |
| **VAR** | Constant or typed value |
| **Print** | Print a value |
| **If-Else** / **If-Else-End** | Branching |
| **For Loop** / **For Loop Collector** | Iteration |
| **Unpack** | Split a sequence into ports |
| **Kwargs** | Build a `key = value` dict for `**kwargs` ports |
| **IntSlider** / **FloatSlider** | Interactive numeric input |
| **Open / Save File or Folder Dialog** | Paths from the OS file dialog |
| **ImageDisplay** | Preview an image |
| **Save to ws** | Write a value into the MedICS workspace |
| **BackDrop** | Visual grouping on the canvas |

---

## Custom nodes

Turn a Python function into a node:

1. In Nodes Explorer, click **Create Node**.
2. Write one or more top-level functions (parameters become **inputs**, the return value becomes the **output**).
3. Click **Test** to check syntax.
4. **Create** saves the file under `customNodes/` and refreshes the Custom Nodes list. **Create && Add** also drops the first new node on the canvas.

To change an existing custom node, **right-click it in the Nodes Explorer** and choose **Edit**.

Example:

```python
def scale_image(image, gain=1.0):
    """Multiply image intensity by gain."""
    return image * gain
```

That becomes a node with ports `image` and `gain`, and one output.

---

## Package nodes (auto-wrapper)

GraphicPy can wrap functions from installed Python packages (NumPy, OpenCV, scikit-image, SciPy, pandas, and others) so they appear as nodes.

- **Manage Packages** in the explorer opens the package list.
- Enable only the packages you need, then **Reload**.
- **Add Package** installs a pip package and adds it to the wrapper config.
- Disabled packages are not registered, which keeps startup faster.

If a package is not installed in the MedICS environment, its nodes will not load. Install the library first, then reload nodes.

---

## Generated Python code

The graph can be turned into a Python script.

| Toolbar | What it does |
| --- | --- |
| **Show Code** | Opens a code panel under the canvas (with line numbers) |
| **Refresh Code** | Regenerates the script from the current graph |
| **Run Code** | Sends the script to the MedICS Jupyter console |
| **Open in PyEditor** | Opens the script in the PyEditor toolbox |

From the **Graph** menu you can also **Preview**, **Export to Python Code**, or **Import from Python Code**.

Shortcuts: **Ctrl+Shift+P** preview, **Ctrl+Shift+E** export, **Ctrl+Shift+I** import.

---

## Save and load sessions

Use the **Graph** menu (or shortcuts):

| Action | Shortcut |
| --- | --- |
| Open session | **Ctrl+O** |
| Save | **Ctrl+S** |
| Save As | **Ctrl+Shift+S** |
| Import session | Graph → Import… |
| Clear session | Graph → Clear Session… |

Session files store node positions, connections, and property values so you can continue later.

---

## Keyboard shortcuts

### Canvas

| Shortcut | Action |
| --- | --- |
| **Shift+A** | Search and add a node |
| **Del** | Delete selected nodes / pipes |
| **Ctrl+C / X / V** | Copy / cut / paste |
| **Alt+C** | Duplicate |
| **Ctrl+A** | Select all |
| **Ctrl+Shift+A** | Unselect all |
| **D** | Enable / disable selected nodes |
| **Ctrl+D** | Clear connections on selection |
| **Ctrl+Shift+X** | Extract selected nodes |
| **Ctrl+L** | Auto-layout (down) |
| **F** | Fit to selection |
| **Ctrl+1 / 2 / 3** | Curved / straight / angled pipes |

### Graph and view

| Shortcut | Action |
| --- | --- |
| **Ctrl+S** / **Ctrl+Shift+S** / **Ctrl+O** | Save / Save As / Open |
| **=** / **-** / **H** | Zoom in / out / reset |
| **Alt+1 / 2 / 3** | Grid: none / lines / dots |
| **Shift+1 / 2** | Horizontal / vertical layout mode |

---

## Tips

- Filter the explorer instead of scrolling long package lists.
- Keep **AutoRun** off on expensive nodes; run them explicitly.
- Hover explorer items or the canvas info icon for docs without opening Properties.
- After changing custom node files or package settings, click **Reload**.
- Light and dark appearance follow MedICS **Settings → Theme**.

---

## Requirements

GraphicPy runs **inside MedICS** as an extension (Python 3.11+). It uses [NodeGraphQt](https://github.com/jchanvfx/NodeGraphQt) for the canvas. Package nodes need the corresponding libraries installed in the same environment as MedICS (for example `numpy`, `opencv-python`, `scikit-image`).

Install or update the extension with your usual MedICS extension workflow (or `uv pip install` / `pip install` from this repository when developing).

---

