Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
display_utils.py
35
36from typing import List, Optional
37
38from visp.core import Display
39
40VISP_DISPLAY_CLS_MAP = {
41 'x': None,
42 'opencv': None,
43 'gtk': None,
44 'win32': None,
45 'gdi': None,
46}
47
48try:
49 from visp.gui import DisplayX
50 VISP_DISPLAY_CLS_MAP['x'] = DisplayX
51except ImportError:
52 pass
53
54try:
55 from visp.gui import DisplayOpenCV
56 VISP_DISPLAY_CLS_MAP['opencv'] = DisplayOpenCV
57except ImportError:
58 pass
59
60try:
61 from visp.gui import DisplayGTK
62 VISP_DISPLAY_CLS_MAP['gtk'] = DisplayGTK
63except ImportError:
64 pass
65
66try:
67 from visp.gui import DisplayWin32
68 VISP_DISPLAY_CLS_MAP['win32'] = DisplayWin32
69except ImportError:
70 pass
71
72try:
73 from visp.gui import DisplayGDI
74 VISP_DISPLAY_CLS_MAP['gdi'] = DisplayGDI
75except ImportError:
76 pass
77
78VISP_DEFAULT_DISPLAY_PREFERENCE = ['x', 'opencv', 'gtk', 'win32', 'gdi']
79
80
81def get_display(preferences: Optional[List[str]] = None) -> Optional[Display]:
82 '''
83 Get a new ViSP display instance, dependending on what display driver is available.
84
85 :param preference: An optional list of preferred backends to use.
86 The backends are tested in the order they are specified, and the first match is instanciated.
87 If preference is None, a default list of display is used. This list contains all basic displays.
88 The specified values are case insensitive and may include. See VISP_DEFAULT_DISPLAY_PREFERENCE for the available options
89
90 :return: a new instance of a ViSP display if one of the requested backend has been found, None otherwise
91 '''
92
93 final_prefs: List[str] = preferences if preferences is not None else VISP_DEFAULT_DISPLAY_PREFERENCE
94 for preference in final_prefs:
95 pref_key = preference.lower()
96 display_opt = VISP_DISPLAY_CLS_MAP.get(pref_key)
97 if display_opt is not None:
98 return display_opt()
99 return None
Optional[Display] get_display(Optional[List[str]] preferences=None)