Skip to content

vedo.settings

settings

settings

Settings

Global settings for vedo. Access via the singleton vedo.settings.

Attributes can be set as properties or with dictionary syntax:

Examples:

from vedo import settings, Cube
settings.use_parallel_projection = True
settings["use_parallel_projection"] = True  # equivalent
Cube().color('g').show().close()

Call print(vedo.settings) to list all current values grouped by category.

Font parameters can be customised per font
settings.font_parameters["Normografo"] = dict(
    mono=False, fscale=0.75, hspacing=1, lspacing=0.2,
    dotsep="~×", islocal=True,
)
# mono    : if True, all letters occupy the same horizontal slot
# fscale  : overall scaling factor for the font size
# hspacing: horizontal stretching (letters and words)
# lspacing: horizontal spacing between letters (not words)
# dotsep  : characters interpreted as dot separator
# islocal : True = bundled in /fonts, False = downloaded from vedo.embl.es/fonts

To run a fonts demo: vedo --run fonts

Available fonts: http://vedo.embl.es/fonts

Source code in vedo/settings.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
class Settings:
    """
    Global settings for vedo. Access via the singleton ``vedo.settings``.

    Attributes can be set as properties or with dictionary syntax:

    Examples:
        ```python
        from vedo import settings, Cube
        settings.use_parallel_projection = True
        settings["use_parallel_projection"] = True  # equivalent
        Cube().color('g').show().close()
        ```

    Call ``print(vedo.settings)`` to list all current values grouped by category.

    Font parameters can be customised per font:
        ```python
        settings.font_parameters["Normografo"] = dict(
            mono=False, fscale=0.75, hspacing=1, lspacing=0.2,
            dotsep="~×", islocal=True,
        )
        # mono    : if True, all letters occupy the same horizontal slot
        # fscale  : overall scaling factor for the font size
        # hspacing: horizontal stretching (letters and words)
        # lspacing: horizontal spacing between letters (not words)
        # dotsep  : characters interpreted as dot separator
        # islocal : True = bundled in /fonts, False = downloaded from vedo.embl.es/fonts
        ```

    To run a fonts demo: ``vedo --run fonts``

    Available fonts: http://vedo.embl.es/fonts
    """

    # Restrict attributes so accidental typos raise AttributeError.
    __slots__ = [
        "default_font",
        "default_backend",
        "cache_directory",
        "palette",
        "remember_last_figure_format",
        "enable_print_color",
        "progressbar_delay",
        "enable_pipeline",
        "enable_default_mouse_callbacks",
        "enable_default_keyboard_callbacks",
        "screenshot_transparent_background",
        "screenshot_large_image",
        "force_single_precision_points",
        "enable_rendering_points_as_spheres",
        "immediate_rendering",
        "interpolate_scalars_before_mapping",
        "use_parallel_projection",
        "tiff_orientation_type",
        "point_smoothing",
        "line_smoothing",
        "polygon_smoothing",
        "light_follows_camera",
        "two_sided_lighting",
        "use_depth_peeling",
        "alpha_bit_planes",
        "multi_samples",
        "max_number_of_peels",
        "occlusion_ratio",
        "use_fxaa",
        "preserve_depth_buffer",
        "use_polygon_offset",
        "polygon_offset_factor",
        "polygon_offset_units",
        "renderer_frame_color",
        "renderer_frame_alpha",
        "renderer_frame_width",
        "renderer_frame_padding",
        "window_splitting_position",
        "background_gradient_orientation",
        "annotated_cube_color",
        "annotated_cube_text_color",
        "annotated_cube_text_scale",
        "annotated_cube_texts",
        "annotated_cube_text_rotations",
        "backend_autoclose",
        "k3d_menu_visibility",
        "k3d_plot_height",
        "k3d_antialias",
        "k3d_lighting",
        "k3d_camera_autofit",
        "k3d_grid_visible",
        "k3d_grid_autofit",
        "k3d_axes_color",
        "k3d_axes_helper",
        "k3d_point_shader",
        "k3d_line_shader",
        "font_parameters",
    ]

    # Groups used by __str__ to produce readable output.
    # Each entry is (section_title, [slot_names]).
    _SECTIONS = (
        ("General", [
            "default_font",
            "default_backend",
            "cache_directory",
            "palette",
            "remember_last_figure_format",
            "enable_print_color",
            "progressbar_delay",
        ]),
        ("Interaction", [
            "enable_pipeline",
            "enable_default_mouse_callbacks",
            "enable_default_keyboard_callbacks",
        ]),
        ("Screenshots", [
            "screenshot_transparent_background",
            "screenshot_large_image",
        ]),
        ("Rendering", [
            "force_single_precision_points",
            "enable_rendering_points_as_spheres",
            "immediate_rendering",
            "interpolate_scalars_before_mapping",
            "use_parallel_projection",
            "tiff_orientation_type",
        ]),
        ("Smoothing", [
            "point_smoothing",
            "line_smoothing",
            "polygon_smoothing",
        ]),
        ("Lighting", [
            "light_follows_camera",
            "two_sided_lighting",
        ]),
        ("Transparency / Anti-aliasing", [
            "use_depth_peeling",
            "alpha_bit_planes",
            "multi_samples",
            "max_number_of_peels",
            "occlusion_ratio",
            "use_fxaa",
            "preserve_depth_buffer",
        ]),
        ("Polygon offset", [
            "use_polygon_offset",
            "polygon_offset_factor",
            "polygon_offset_units",
        ]),
        ("Window / Multi-renderer", [
            "renderer_frame_color",
            "renderer_frame_alpha",
            "renderer_frame_width",
            "renderer_frame_padding",
            "window_splitting_position",
            "background_gradient_orientation",
        ]),
        ("Annotated cube", [
            "annotated_cube_color",
            "annotated_cube_text_color",
            "annotated_cube_text_scale",
            "annotated_cube_texts",
            "annotated_cube_text_rotations",
        ]),
        ("Backend", [
            "backend_autoclose",
        ]),
        ("K3D backend", [
            "k3d_menu_visibility",
            "k3d_plot_height",
            "k3d_antialias",
            "k3d_lighting",
            "k3d_camera_autofit",
            "k3d_grid_visible",
            "k3d_grid_autofit",
            "k3d_axes_color",
            "k3d_axes_helper",
            "k3d_point_shader",
            "k3d_line_shader",
        ]),
        ("Fonts", [
            "font_parameters",
        ]),
    )

    # Dry-run mode (for testing only):
    #   0 = normal execution
    #   1 = do not hold execution (no interactive loop)
    #   2 = do not hold execution and do not open any window
    # Stored as a class variable (not an instance slot) so that vtkclasses.py
    # can read Settings.dry_run_mode without instantiating Settings and without
    # triggering circular imports.
    dry_run_mode = 0

    ############################################################
    def __init__(self) -> None:

        self.default_backend = "vtk"
        try:
            # adapted from: https://stackoverflow.com/a/39662359/2912349
            shell = get_ipython().__class__.__name__  # type: ignore
            if shell == "ZMQInteractiveShell":
                self.default_backend = "2d"
        except NameError:
            pass

        self.default_font = "Normografo"
        self.palette = 0
        self.remember_last_figure_format = False
        self.enable_print_color = True
        self.progressbar_delay = 0.5

        self.enable_pipeline = True
        self.enable_default_mouse_callbacks = True
        self.enable_default_keyboard_callbacks = True

        if "VEDO_CACHE_DIR" in os.environ:
            self.cache_directory = os.environ["VEDO_CACHE_DIR"]
        else:
            self.cache_directory = ".cache"  # "/vedo" is appended automatically

        self.screenshot_transparent_background = False
        self.screenshot_large_image = False

        self.force_single_precision_points = True
        self.enable_rendering_points_as_spheres = True
        self.immediate_rendering = True
        self.interpolate_scalars_before_mapping = True
        self.use_parallel_projection = False
        self.tiff_orientation_type = 1

        self.point_smoothing = False
        self.line_smoothing = False
        self.polygon_smoothing = False

        self.light_follows_camera = False
        self.two_sided_lighting = True

        self.use_depth_peeling = False
        self.alpha_bit_planes = True
        self.multi_samples = 8
        self.max_number_of_peels = 4
        self.occlusion_ratio = 0.1
        self.use_fxaa = False
        self.preserve_depth_buffer = False

        self.use_polygon_offset = True
        self.polygon_offset_factor = 0.1
        self.polygon_offset_units = 0.1

        self.renderer_frame_color = None
        self.renderer_frame_alpha = 0.5
        self.renderer_frame_width = 0.5
        self.renderer_frame_padding = 0.0001
        self.window_splitting_position = None
        self.background_gradient_orientation = 0

        self.annotated_cube_color = (0.75, 0.75, 0.75)
        self.annotated_cube_text_color = None
        self.annotated_cube_text_scale = 0.2
        self.annotated_cube_texts = [
            "right",
            "left ",
            "front",
            "back ",
            " top ",
            "bottom",
        ]
        self.annotated_cube_text_rotations = [0, 0, 90]

        self.backend_autoclose = True

        self.k3d_menu_visibility = True
        self.k3d_plot_height = 512
        self.k3d_antialias = True
        self.k3d_lighting = 1.5
        self.k3d_camera_autofit = True
        self.k3d_grid_visible = None
        self.k3d_grid_autofit = True
        self.k3d_axes_color = "k4"
        self.k3d_axes_helper = 1.0
        self.k3d_point_shader = "mesh"
        self.k3d_line_shader = "thick"

        self.font_parameters = dict(
            Normografo=dict(
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~×",
                islocal=True,
            ),
            Bongas=dict(
                mono=False,
                fscale=0.875,
                hspacing=0.52,
                lspacing=0.25,
                dotsep="·",
                islocal=True,
            ),
            Calco=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=True,
            ),
            Comae=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=True,
            ),
            ComicMono=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="x",
                islocal=False,
            ),
            Edo=dict(
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~x ",
                islocal=False,
            ),
            FiraMonoMedium=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            FiraMonoBold=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Glasgo=dict(
                mono=True,
                fscale=0.75,
                lspacing=0.1,
                hspacing=1,
                dotsep="~×",
                islocal=True,
            ),
            Kanopus=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.15,
                hspacing=0.75,
                dotsep="~×",
                islocal=True,
            ),
            LogoType=dict(
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~×",
                islocal=False,
            ),
            Quikhand=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.6,
                lspacing=0.15,
                dotsep="~~×~",
                islocal=True,
            ),
            SmartCouric=dict(
                mono=True,
                fscale=0.8,
                hspacing=1.05,
                lspacing=0.1,
                dotsep="×",
                islocal=True,
            ),
            Spears=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.5,
                lspacing=0.2,
                dotsep="~×",
                islocal=False,
            ),
            Theemim=dict(
                mono=False,
                fscale=0.825,
                hspacing=0.52,
                lspacing=0.3,
                dotsep="~~×",
                islocal=True,
            ),
            VictorMono=dict(
                mono=True,
                fscale=0.725,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=True,
            ),
            Justino1=dict(
                mono=True,
                fscale=0.725,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Justino2=dict(
                mono=True,
                fscale=0.725,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Justino3=dict(
                mono=True,
                fscale=0.725,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Calibri=dict(
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~×",
                islocal=False,
            ),
            Capsmall=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.75,
                lspacing=0.15,
                dotsep="~×",
                islocal=False,
            ),
            Cartoons123=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.75,
                lspacing=0.15,
                dotsep="x",
                islocal=False,
            ),
            Darwin=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.75,
                lspacing=0.15,
                dotsep="x",
                islocal=False,
            ),
            Vega=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.75,
                lspacing=0.15,
                dotsep="×",
                islocal=False,
            ),
            Meson=dict(
                mono=False,
                fscale=0.8,
                hspacing=0.9,
                lspacing=0.225,
                dotsep="~×",
                islocal=False,
            ),
            Komika=dict(
                mono=False,
                fscale=0.7,
                hspacing=0.75,
                lspacing=0.225,
                dotsep="~×",
                islocal=False,
            ),
            Brachium=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="x",
                islocal=False,
            ),
            Dalim=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            Miro=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            Ubuntu=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            Mizar=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=0.75,
                dotsep="~×",
                islocal=False,
            ),
            LiberationSans=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            DejavuSansMono=dict(
                mono=True,
                fscale=0.725,
                hspacing=1,
                lspacing=0.1,
                dotsep="~×",
                islocal=False,
            ),
            SunflowerHighway=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            Swansea=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=1,
                dotsep="~×",
                islocal=False,
            ),
            Housekeeper=dict(  # supports chinese glyphs
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~×",
                islocal=False,
            ),
            Wananti=dict(  # supports chinese glyphs
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~x",
                islocal=False,
            ),
            AnimeAce=dict(
                mono=False,
                fscale=0.75,
                hspacing=1,
                lspacing=0.2,
                dotsep="~x",
                islocal=False,
            ),
            Antares=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Archistico=dict(
                mono=False,
                fscale=0.75,
                lspacing=0.2,
                hspacing=0.75,
                dotsep="~×",
                islocal=False,
            ),
            KazyCase=dict(
                mono=True,
                fscale=0.8,
                hspacing=1.2,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
            Roboto=dict(
                mono=True,
                fscale=0.8,
                hspacing=1,
                lspacing=0.1,
                dotsep="×",
                islocal=False,
            ),
        )

    ############################################################
    def __getitem__(self, key):
        """Make the class work like a dictionary too."""
        try:
            return getattr(self, key)
        except AttributeError:
            raise KeyError(key) from None

    def __setitem__(self, key, value):
        """Make the class work like a dictionary too."""
        setattr(self, key, value)

    def __contains__(self, key):
        """Support ``'key' in settings`` queries."""
        return key in self.__slots__ or key == "dry_run_mode"

    def __setattr__(self, key, value):
        # dry_run_mode is a class variable (not a slot) so that vtkclasses.py
        # can read Settings.dry_run_mode without needing an instance.
        # Redirect instance assignment to the class to keep the two in sync.
        if key == "dry_run_mode":
            type(self).dry_run_mode = value
            return
        super().__setattr__(key, value)

    def _body_lines(self) -> list:
        """Return plain-text lines for all settings, grouped by section."""
        lines = []
        for title, keys in self._SECTIONS:
            lines.append(f"\n# {title}")
            for key in keys:
                val = getattr(self, key)
                if key == "font_parameters":
                    lines.append(f"font_parameters  # {len(val)} fonts defined")
                else:
                    lines.append(f"{key} = {val!r}")
        lines.append("\n# Testing")
        lines.append(f"dry_run_mode = {type(self).dry_run_mode!r}")
        return lines

    def __str__(self) -> str:
        s = "\n".join(self._body_lines())
        try:
            from pygments import highlight
            from pygments.lexers import Python3Lexer
            from pygments.formatters import Terminal256Formatter
            s = highlight(s, Python3Lexer(), Terminal256Formatter(style="zenburn"))
        except (ModuleNotFoundError, ImportError):
            pass
        module = self.__class__.__module__
        name = self.__class__.__name__
        header = f"{module}.{name}".ljust(75)
        return f"\x1b[1m\x1b[7m{header}\x1b[0m\n" + s.strip()

    def __repr__(self) -> str:
        return self.__str__()

    def __rich__(self):
        from rich.panel import Panel
        from rich.syntax import Syntax

        body = "\n".join(self._body_lines()).strip()
        module = self.__class__.__module__
        name = self.__class__.__name__
        return Panel(
            Syntax(body, "python", theme="zenburn"),
            title=f"{module}.{name}",
            title_align="left",
            border_style="bold white",
        )

    ############################################################
    def keys(self) -> list:
        """Return all setting names."""
        return list(self.__slots__) + ["dry_run_mode"]

    def values(self) -> list:
        """Return all current setting values."""
        return [getattr(self, key) for key in self.__slots__] + [type(self).dry_run_mode]

    def items(self) -> list:
        """Return all (name, value) pairs."""
        return [(key, getattr(self, key)) for key in self.__slots__] + [("dry_run_mode", type(self).dry_run_mode)]

    def reset(self) -> None:
        """Reset all settings to their default values."""
        self.__init__()

    ############################################################
    def clear_cache(self) -> None:
        """Clear the vedo cache directory."""
        import shutil
        cachedir = self.cache_directory
        if not os.path.isabs(cachedir):
            cachedir = os.path.join(os.path.expanduser("~"), cachedir)
        cachedir = os.path.join(cachedir, "vedo")
        try:
            shutil.rmtree(cachedir)
            print(f"Cache directory '{cachedir}' cleared.")
        except FileNotFoundError:
            print(f"Cache directory '{cachedir}' not found.")

    ############################################################
    def set_vtk_verbosity(self, level: int) -> None:
        """
        Set the verbosity level of VTK messages on stderr.

        Args:
            level: 0 = errors only, 1 = warnings, 2 = info
        """
        from vedo.vtkclasses import vtk
        vtkLogger = vtk.vtkLogger
        levels = {
            0: vtkLogger.VERBOSITY_ERROR,
            1: vtkLogger.VERBOSITY_WARNING,
            2: vtkLogger.VERBOSITY_INFO,
        }
        if level not in levels:
            raise ValueError(f"Invalid VTK verbosity level {level!r}. Allowed values: 0, 1, 2.")
        vtkLogger.SetStderrVerbosity(levels[level])

clear_cache()

Clear the vedo cache directory.

Source code in vedo/settings.py
786
787
788
789
790
791
792
793
794
795
796
797
def clear_cache(self) -> None:
    """Clear the vedo cache directory."""
    import shutil
    cachedir = self.cache_directory
    if not os.path.isabs(cachedir):
        cachedir = os.path.join(os.path.expanduser("~"), cachedir)
    cachedir = os.path.join(cachedir, "vedo")
    try:
        shutil.rmtree(cachedir)
        print(f"Cache directory '{cachedir}' cleared.")
    except FileNotFoundError:
        print(f"Cache directory '{cachedir}' not found.")

items()

Return all (name, value) pairs.

Source code in vedo/settings.py
777
778
779
def items(self) -> list:
    """Return all (name, value) pairs."""
    return [(key, getattr(self, key)) for key in self.__slots__] + [("dry_run_mode", type(self).dry_run_mode)]

keys()

Return all setting names.

Source code in vedo/settings.py
769
770
771
def keys(self) -> list:
    """Return all setting names."""
    return list(self.__slots__) + ["dry_run_mode"]

reset()

Reset all settings to their default values.

Source code in vedo/settings.py
781
782
783
def reset(self) -> None:
    """Reset all settings to their default values."""
    self.__init__()

set_vtk_verbosity(level)

Set the verbosity level of VTK messages on stderr.

Parameters:

Name Type Description Default
level int

0 = errors only, 1 = warnings, 2 = info

required
Source code in vedo/settings.py
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
def set_vtk_verbosity(self, level: int) -> None:
    """
    Set the verbosity level of VTK messages on stderr.

    Args:
        level: 0 = errors only, 1 = warnings, 2 = info
    """
    from vedo.vtkclasses import vtk
    vtkLogger = vtk.vtkLogger
    levels = {
        0: vtkLogger.VERBOSITY_ERROR,
        1: vtkLogger.VERBOSITY_WARNING,
        2: vtkLogger.VERBOSITY_INFO,
    }
    if level not in levels:
        raise ValueError(f"Invalid VTK verbosity level {level!r}. Allowed values: 0, 1, 2.")
    vtkLogger.SetStderrVerbosity(levels[level])

values()

Return all current setting values.

Source code in vedo/settings.py
773
774
775
def values(self) -> list:
    """Return all current setting values."""
    return [getattr(self, key) for key in self.__slots__] + [type(self).dry_run_mode]

init_colab(enable_k3d=True)

Initialize a Google Colab environment for vedo.

Installs Xvfb and pyvirtualdisplay, starts a virtual display, and optionally installs and enables k3d.

Source code in vedo/settings.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def init_colab(enable_k3d=True) -> None:
    """
    Initialize a Google Colab environment for vedo.

    Installs Xvfb and pyvirtualdisplay, starts a virtual display,
    and optionally installs and enables k3d.
    """
    import vedo
    print("setting up colab environment (can take a minute) ...", end="")

    if subprocess.run(["which", "Xvfb"], capture_output=True).returncode != 0:
        os.system("apt-get install xvfb")

    os.system("pip install pyvirtualdisplay")

    from pyvirtualdisplay import Display  # type: ignore
    display = Display(visible=0)
    display.start()

    if enable_k3d:
        os.system("pip install k3d")

    from google.colab import output  # type: ignore
    output.enable_custom_widget_manager()

    if enable_k3d:
        import k3d
        try:
            print("installing k3d...", end="")
            os.system("jupyter nbextension install --py --user k3d")
            os.system("jupyter nbextension enable  --py --user k3d")
            k3d.switch_to_text_protocol()
            vedo.settings.default_backend = "k3d"
            vedo.settings.backend_autoclose = False
        except Exception:
            print("(FAILED) ... ", end="")

    print(" setup completed.")
    return display  # caller may need to keep the display alive

start_xvfb()

Start an Xvfb virtual framebuffer.

Xvfb performs all graphical operations in virtual memory without showing any screen output. Useful for headless rendering on Linux.

Source code in vedo/settings.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def start_xvfb() -> None:
    """
    Start an Xvfb virtual framebuffer.

    Xvfb performs all graphical operations in virtual memory without
    showing any screen output. Useful for headless rendering on Linux.
    """
    print("starting xvfb (can take a minute) ...", end="")
    if subprocess.run(["which", "Xvfb"], capture_output=True).returncode != 0:
        subprocess.run(["apt-get", "install", "-y", "xvfb"], check=False)
    os.environ["DISPLAY"] = ":99.0"
    subprocess.Popen(
        ["Xvfb", ":99", "-screen", "0", "1024x768x24"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    time.sleep(3)
    print(" xvfb started.")