| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | from typing import Optional |
| | import FreeCADGui |
| | from functools import partial |
| | from PySide import QtGui |
| | from ...camassets import cam_assets |
| | from .. import ToolBitShape |
| | from .flowlayout import FlowLayout |
| | from .shapebutton import ShapeButton |
| |
|
| |
|
| | class ShapeSelector: |
| | def __init__(self): |
| | self.shape = None |
| | self.form = FreeCADGui.PySideUic.loadUi(":/panels/ShapeSelector.ui") |
| |
|
| | self.form.buttonBox.clicked.connect(self.form.close) |
| |
|
| | self.flows = {} |
| |
|
| | self.update_shapes() |
| |
|
| | def _add_shape_group(self, toolbox): |
| | if toolbox in self.flows: |
| | return self.flows[toolbox] |
| | flow = FlowLayout(toolbox, orientation=QtGui.Qt.Horizontal) |
| | flow.widthChanged.connect(lambda x: toolbox.setMinimumWidth(x)) |
| | self.flows[toolbox] = flow |
| | return flow |
| |
|
| | def _add_shapes(self, toolbox, shapes): |
| | flow = self._add_shape_group(toolbox) |
| |
|
| | |
| | for i in reversed(range(flow.count())): |
| | flow.itemAt(i).widget().setParent(None) |
| |
|
| | |
| | for shape in sorted(shapes, key=lambda x: x.label): |
| | button = ShapeButton(shape) |
| | flow.addWidget(button) |
| | cb = partial(self.on_shape_button_clicked, shape) |
| | button.clicked.connect(cb) |
| |
|
| | def update_shapes(self): |
| | |
| | builtin = cam_assets.fetch(asset_type="toolbitshape", store="builtin") |
| | builtin = {c.id: c for c in builtin} |
| | custom = cam_assets.fetch(asset_type="toolbitshape", store="local") |
| | for shape in custom: |
| | builtin.pop(shape.id, None) |
| |
|
| | |
| | all_shapes = list(builtin.values()) + list(custom) |
| | self._add_shapes(self.form.toolsContainer, all_shapes) |
| |
|
| | def on_shape_button_clicked(self, shape): |
| | self.shape = shape |
| | self.form.close() |
| |
|
| | def show(self) -> Optional[ToolBitShape]: |
| | self.form.exec() |
| | return self.shape |
| |
|