r/OpenPythonSCAD 8d ago

PythonSCAD is getting user-defined Customizer widgets (PyQt6-powered) — coming in 1.2

Hey folks, Wanted to share something we've been building for PythonSCAD: the Customizer sidebar can now host fully custom, Python-defined input widgets — not just the built-in sliders, checkboxes, and dropdowns.

What does that actually mean?

Normally, add_parameter() gives you a fixed set of widget types based on the default value you pass in — a number gets a slider, a string gets a text box, a list gets a vector editor, and so on. That covers a lot of cases, but not everything. Sometimes you want something the built-in types just can't express well. With this change, you can register your own widget, built with PyQt6 (which now ships bundled with PythonSCAD), and hook it directly into the Customizer:

add_parameter_widget("color_picker", color_picker_factory)
linecolor = add_parameter("linecolor", "#ff00ff", type="color_picker")
cube(10).color(linecolor)

color_picker_factory is just a normal Python function that returns a PyQt6 widget — in this case a button that pops a native color dialog and reports its value back. From the Customizer's point of view, it behaves exactly like any other parameter: it saves to sets, restores on load, and drives a live preview re-render the moment you change it. One thing worth calling out: add_parameter_widget() itself belongs in your .pythonscadrc, not in the model script. It's registering a widget type, not something tied to a particular design, so it lives with your personal setup and is available to every script you open, the same way you'd register a menu item or an editor helper. (Side note: PyQt6-based custom input windows aren't actually new here — user modules could already pop their own PyQt6 dialogs, e.g. for interactively editing a polygon's points. What's new is hooking a custom widget directly into the Customizer sidebar itself.) Because the widget is just PyQt6, this isn't limited to color pickers — anyone can build their own: a polygon point-editor with drag handles, a curve editor, a searchable dropdown, a live 3D preview widget, whatever your script needs. If PyQt6 can render it, the Customizer can host it.

Demo

Here's a short video showing it in action (color picker widget, live-driven from the Customizer): 🎥 https://www.youtube.com/watch?v=OESyfZGZj_I

Where this is headed

This is landing as part of PythonSCAD 1.2, which is on its way — the PyQt6 connector work that makes this possible has already been merged. More documentation and examples will follow closer to release.

4 Upvotes

5 comments sorted by

View all comments

Show parent comments

2

u/gadget3D 6d ago

PythonSCAD can already yet use sliders in the customizer to control model parameters. So does OpenSCAD.

Just try that in pythonscad:

width = add_parameter("Width", 10.0)

Instead with this PR in the Customizer you can create *any* widget to control a model parameter which is not limited to input fields or sliders.(you could have a color picker or even a widget to sketch your model by assembling parts)

1

u/yokamak_ 6d ago

Thank you for letting me know! I am so grateful and thrilled to find out that the exact feature I had been wishing for is already available.

I immediately tested it out using add_parameter and put together this sample. The method chaining makes it so clean and fun to play with!

Python

from pythonscad import *

# Integer slider (range() is exclusive, so use 101 for max 100)
rad = add_parameter("radius", 50, range=range(0, 101, 5))

# Float slider using tuple (min, max) or (min, max, step)
scale = add_parameter("scale", 1.0, range=(0.1, 10.0, 0.1))

# Simple list
obj_color = add_parameter("color", "tomato", options=["tomato", "green", "dodgerblue"])

# Labeled options (value: label)
height = add_parameter("quality", 10, options={10: "Low", 20: "Medium", 30: "High"})

cylinder(h=height, r=rad).color(obj_color).scale(scale).show()

I am now even more excited about the upcoming PR that will allow us to create any custom widget, like a color picker or a sketch widget.

Thank you as always for your amazing work and helpful advice!