{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Interactive shape picker\n\nThis demo shows how to let the user select a certain number of shapes in a plot.\n\nThe shapes are then returned as list of shapes. This list can also be assigned\nto the ``geometricShapes`` property of any other plot to display them in another plot.\n\nThe ``plotItem.drawAndPickElements`` method is used for this demo. It accepts\nany kind of shape (``plotItem.Primitive`` ...) besides ``plotItem.PrimitiveMultiPointPick``.\n\nUse instead ``PrimitivePoint`` or use the similar method ``plotItem.pickPoints``\nif the user should select a arbitrary number of single points.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from itom import dataObject\nfrom itom import plot\nfrom itom import shape\nfrom itom import ui\nfrom itom import plotItem\nfrom typing import Tuple\n\nelementList = [\n (plotItem.PrimitivePoint, 5),\n (plotItem.PrimitiveCircle, 3),\n (plotItem.PrimitivePolygon, 2),\n (plotItem.PrimitiveLine, 1)\n ]\n\nfor shapeType, numShapes in elementList:\n \n img = dataObject.zeros([100, 150], \"float32\")\n \n for r in range(img.shape[0]):\n img[r, :] = (r % 20) * 0.02\n \n [i, h] = plot(img)\n \n try:\n polygons: Tuple[shape] = h.drawAndPickElements(shapeType, numShapes)\n except RuntimeError as ex:\n print(str(ex))\n ui.msgWarning(\"Abort\", \"The user interaction has been aborted\")\n break\n else:\n print(\"The following shapes have been selected:\\n--------------------\")\n for p in polygons:\n print(str(p))\n print(\"---------------------\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}