Skip to content

Commit b3fc246

Browse files
Bump version 0.2.6
1 parent 9644a86 commit b3fc246

File tree

7 files changed

+62
-61
lines changed

7 files changed

+62
-61
lines changed

doc/changelog.d/75.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: Rename built in shadowing variables

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "ansys-tools-visualization-interface"
7-
version = "0.2.5"
7+
version = "0.2.6"
88
description = "A Python visualization interface for PyAnsys libraries"
99
readme = "README.rst"
1010
requires-python = ">=3.9,<4"

src/ansys/tools/visualization_interface/backends/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class BaseBackend(ABC):
3030
"""Base class for plotting backends."""
3131

3232
@abstractmethod
33-
def plot(self, object: Any, **plotting_options):
33+
def plot(self, plottable_object: Any, **plotting_options):
3434
"""Plot the specified object."""
3535
raise NotImplementedError("plot method must be implemented")
3636

3737
@abstractmethod
38-
def plot_iter(self, object: Iterable):
38+
def plot_iter(self, plotting_list: Iterable):
3939
"""Plot the elements of an iterable."""
4040
raise NotImplementedError("plot_iter method must be implemented")
4141

src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ def disable_picking(self):
307307

308308
def show(
309309
self,
310-
object: Any = None,
310+
plottable_object: Any = None,
311311
screenshot: Optional[str] = None,
312312
view_2d: Dict = None,
313-
filter: str = None,
313+
name_filter: str = None,
314314
**plotting_options,
315315
) -> List[Any]:
316316
"""Plot and show any PyAnsys object.
@@ -320,13 +320,13 @@ def show(
320320
321321
Parameters
322322
----------
323-
object : Any, default: None
323+
plottable_object : Any, default: None
324324
Object or list of objects to plot.
325325
screenshot : str, default: None
326326
Path for saving a screenshot of the image that is being represented.
327327
view_2d : Dict, default: None
328328
Dictionary with the plane and the viewup vectors of the 2D plane.
329-
filter : str, default: None
329+
name_filter : str, default: None
330330
Regular expression with the desired name or names to include in the plotter.
331331
**plotting_options : dict, default: None
332332
Keyword arguments. For allowable keyword arguments, see the
@@ -338,7 +338,7 @@ def show(
338338
List with the picked bodies in the picked order.
339339
340340
"""
341-
self.plot(object, filter, **plotting_options)
341+
self.plot(plottable_object, name_filter, **plotting_options)
342342
if self._pl._object_to_actors_map:
343343
self._object_to_actors_map = self._pl._object_to_actors_map
344344
else:
@@ -363,14 +363,14 @@ def show(
363363
self.show_plotter(screenshot)
364364

365365
picked_objects_list = []
366-
if isinstance(object, list):
366+
if isinstance(plottable_object, list):
367367
# Keep them ordered based on picking
368368
for meshobject in self._picked_list:
369-
for elem in object:
369+
for elem in plottable_object:
370370
if hasattr(elem, "name") and elem.name == meshobject.name:
371371
picked_objects_list.append(elem)
372-
elif hasattr(object, "name") and object in self._picked_list:
373-
picked_objects_list = [object]
372+
elif hasattr(plottable_object, "name") and plottable_object in self._picked_list:
373+
picked_objects_list = [plottable_object]
374374

375375
return picked_objects_list
376376

@@ -395,14 +395,14 @@ def show_plotter(self, screenshot: Optional[str] = None) -> None:
395395
pv.OFF_SCREEN = self._pv_off_screen_original
396396

397397
@abstractmethod
398-
def plot_iter(self, object: Any, filter: str = None, **plotting_options):
398+
def plot_iter(self, plottable_object: Any, name_filter: str = None, **plotting_options):
399399
"""Plot one or more compatible objects to the plotter.
400400
401401
Parameters
402402
----------
403-
object : Any
403+
plottable_object : Any
404404
One or more objects to add.
405-
filter : str, default: None.
405+
name_filter : str, default: None.
406406
Regular expression with the desired name or names to include in the plotter.
407407
**plotting_options : dict, default: None
408408
Keyword arguments. For allowable keyword arguments, see the
@@ -412,14 +412,14 @@ def plot_iter(self, object: Any, filter: str = None, **plotting_options):
412412
pass
413413

414414
@abstractmethod
415-
def plot(self, object: Any, filter: str = None, **plotting_options):
415+
def plot(self, plottable_object: Any, name_filter: str = None, **plotting_options):
416416
"""Plot a single object to the plotter.
417417
418418
Parameters
419419
----------
420-
object : Any
420+
plottable_object : Any
421421
Object to add.
422-
filter : str
422+
name_filter : str
423423
Regular expression with the desired name or names to include in the plotter.
424424
**plotting_options : dict, default: None
425425
Keyword arguments. For allowable keyword arguments, see the
@@ -458,7 +458,7 @@ def __init__(
458458
def plot_iter(
459459
self,
460460
plotting_list: List[Any],
461-
filter: str = None,
461+
name_filter: str = None,
462462
**plotting_options,
463463
) -> None:
464464
"""Plot the elements of an iterable of any type of object to the scene.
@@ -470,33 +470,33 @@ def plot_iter(
470470
----------
471471
plotting_list : List[Any]
472472
List of objects to plot.
473-
filter : str, default: None
473+
name_filter : str, default: None
474474
Regular expression with the desired name or names to include in the plotter.
475475
**plotting_options : dict, default: None
476476
Keyword arguments. For allowable keyword arguments, see the
477477
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
478478
479479
"""
480-
for object in plotting_list:
481-
self.plot(object, filter, **plotting_options)
480+
for plottable_object in plotting_list:
481+
self.plot(plottable_object, name_filter, **plotting_options)
482482

483-
def plot(self, object: Any, filter: str = None, **plotting_options):
483+
def plot(self, plottable_object: Any, name_filter: str = None, **plotting_options):
484484
"""Plot a ``pyansys`` or ``PyVista`` object to the plotter.
485485
486486
Parameters
487487
----------
488-
object : Any
488+
plottable_object : Any
489489
Object to add.
490-
filter : str
490+
name_filter : str
491491
Regular expression with the desired name or names to include in the plotter.
492492
**plotting_options : dict, default: None
493493
Keyword arguments. For allowable keyword arguments, see the
494494
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
495495
496496
"""
497-
if hasattr(object, "__iter__"):
497+
if hasattr(plottable_object, "__iter__"):
498498
logger.debug("Plotting objects in list...")
499-
self.pv_interface.plot_iter(object, filter, **plotting_options)
499+
self.pv_interface.plot_iter(plottable_object, name_filter, **plotting_options)
500500
else:
501-
self.pv_interface.plot(object, filter, **plotting_options)
501+
self.pv_interface.plot(plottable_object, name_filter, **plotting_options)
502502

src/ansys/tools/visualization_interface/backends/pyvista/pyvista_interface.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,25 @@ def clip(
159159
"""
160160
return mesh.clip(normal=plane.normal, origin=plane.origin)
161161

162-
def plot_meshobject(self, object: MeshObjectPlot, **plotting_options):
162+
def plot_meshobject(self, custom_object: MeshObjectPlot, **plotting_options):
163163
"""Plot a generic ``MeshObjectPlot`` object to the scene.
164164
165165
Parameters
166166
----------
167-
object : MeshObjectPlot
167+
plottable_object : MeshObjectPlot
168168
Object to add to the scene.
169169
**plotting_options : dict, default: None
170170
Keyword arguments. For allowable keyword arguments, see the
171171
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
172172
173173
"""
174-
dataset = object.mesh
174+
dataset = custom_object.mesh
175175
if "clipping_plane" in plotting_options:
176176
dataset = self.clip(dataset, plotting_options["clipping_plane"])
177177
plotting_options.pop("clipping_plane", None)
178178
actor = self.scene.add_mesh(dataset, **plotting_options)
179-
object.actor = actor
180-
self._object_to_actors_map[actor] = object
179+
custom_object.actor = actor
180+
self._object_to_actors_map[actor] = custom_object
181181
return actor.name
182182

183183
def plot_edges(self, custom_object: MeshObjectPlot, **plotting_options) -> None:
@@ -217,8 +217,8 @@ def plot_edges(self, custom_object: MeshObjectPlot, **plotting_options) -> None:
217217

218218
def plot(
219219
self,
220-
object: Union[pv.PolyData, pv.MultiBlock, MeshObjectPlot],
221-
filter: str = None,
220+
plottable_object: Union[pv.PolyData, pv.MultiBlock, MeshObjectPlot],
221+
name_filter: str = None,
222222
**plotting_options,
223223
) -> None:
224224
"""Plot any type of object to the scene.
@@ -228,43 +228,43 @@ def plot(
228228
229229
Parameters
230230
----------
231-
object : Union[pv.PolyData, pv.MultiBlock, MeshObjectPlot]
231+
plottable_object : Union[pv.PolyData, pv.MultiBlock, MeshObjectPlot]
232232
Object to plot.
233-
filter : str, default: None
233+
name_filter : str, default: None
234234
Regular expression with the desired name or names to include in the plotter.
235235
**plotting_options : dict, default: None
236236
Keyword arguments. For allowable keyword arguments, see the
237237
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
238238
239239
"""
240-
if filter:
241-
if hasattr(object, "name") and not re.search(filter, object.name):
240+
if name_filter:
241+
if hasattr(plottable_object, "name") and not re.search(name_filter, plottable_object.name):
242242
return self._object_to_actors_map
243243

244244
# Check what kind of object we are dealing with
245-
if isinstance(object, pv.PolyData):
245+
if isinstance(plottable_object, pv.PolyData):
246246
if "clipping_plane" in plotting_options:
247-
mesh = self.clip(object, plotting_options["clipping_plane"])
247+
mesh = self.clip(plottable_object, plotting_options["clipping_plane"])
248248
plotting_options.pop("clipping_plane", None)
249249
self.scene.add_mesh(mesh, **plotting_options)
250250
else:
251-
self.scene.add_mesh(object, **plotting_options)
252-
elif isinstance(object, pv.MultiBlock):
251+
self.scene.add_mesh(plottable_object, **plotting_options)
252+
elif isinstance(plottable_object, pv.MultiBlock):
253253
if "clipping_plane" in plotting_options:
254-
mesh = self.clip(object, plotting_options["clipping_plane"])
254+
mesh = self.clip(plottable_object, plotting_options["clipping_plane"])
255255
plotting_options.pop("clipping_plane", None)
256256
self.scene.add_composite(mesh, **plotting_options)
257257
else:
258-
self.scene.add_composite(object, **plotting_options)
259-
elif isinstance(object, MeshObjectPlot):
260-
self.plot_meshobject(object, **plotting_options)
258+
self.scene.add_composite(plottable_object, **plotting_options)
259+
elif isinstance(plottable_object, MeshObjectPlot):
260+
self.plot_meshobject(plottable_object, **plotting_options)
261261
else:
262262
logger.warning("The object type is not supported. ")
263263

264264
def plot_iter(
265265
self,
266266
plotting_list: List[Any],
267-
filter: str = None,
267+
name_filter: str = None,
268268
**plotting_options,
269269
) -> None:
270270
"""Plot elements of an iterable of any type of objects to the scene.
@@ -276,15 +276,15 @@ def plot_iter(
276276
----------
277277
plotting_list : List[Any]
278278
List of objects to plot.
279-
filter : str, default: None
279+
name_filter : str, default: None
280280
Regular expression with the desired name or names to include in the plotter.
281281
**plotting_options : dict, default: None
282282
Keyword arguments. For allowable keyword arguments, see the
283283
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
284284
285285
"""
286-
for object in plotting_list:
287-
_ = self.plot(object, filter, **plotting_options)
286+
for plottable_object in plotting_list:
287+
_ = self.plot(plottable_object, name_filter, **plotting_options)
288288

289289
def show(
290290
self,

src/ansys/tools/visualization_interface/plotter.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,41 @@ def __init__(self, backend: BaseBackend = None) -> None:
4444
else:
4545
self._backend = backend
4646

47-
def plot(self, object: Any, **plotting_options):
47+
def plot(self, plottable_object: Any, **plotting_options):
4848
"""Plots an object using the specified backend.
4949
5050
Parameters
5151
----------
52-
object : Any
52+
plottable_object : Any
5353
Object to plot.
5454
plotting_options : dict
5555
Additional plotting options.
5656
"""
57-
self._backend.plot(object=object, **plotting_options)
57+
self._backend.plot(plottable_object=plottable_object, **plotting_options)
5858

5959
def show(
6060
self,
61-
object: Any = None,
61+
plottable_object: Any = None,
6262
screenshot: str = None,
63-
filter: bool = None,
63+
name_filter: bool = None,
6464
**plotting_options
6565
) -> None:
6666
"""Show the plotted objects.
6767
6868
Parameters
6969
----------
70-
object : Any, optional
70+
plottable_object : Any, optional
7171
Object to show, by default None.
7272
screenshot : str, optional
7373
Path to save a screenshot, by default None.
74-
filter : bool, optional
74+
name_filter : bool, optional
7575
Flag to filter the object, by default None.
7676
plotting_options : dict
7777
Additional plotting options the selected backend accepts.
7878
"""
7979
self._backend.show(
80-
object=object,
80+
plottable_object=plottable_object,
8181
screenshot=screenshot,
82-
filter=filter,
82+
name_filter=name_filter,
8383
**plotting_options
8484
)

tests/test_generic_plotter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_plotter_filter():
6868
custom_cube = MeshObjectPlot(CustomTestClass("cube"), cube)
6969

7070
pl = Plotter()
71-
pl.plot([custom_sphere, custom_cube], filter="cube")
71+
pl.plot([custom_sphere, custom_cube], name_filter="cube")
7272
pl.show()
7373

7474

0 commit comments

Comments
 (0)