1- """Client for accessing the NI Python Panel Service."""
2-
31from __future__ import annotations
42
53import logging
3129_logger = logging .getLogger (__name__ )
3230
3331
34- class PanelClient :
35- """Client for accessing the NI Python Panel Service."""
36-
32+ class _PanelClient :
3733 def __init__ (
3834 self ,
3935 * ,
@@ -43,15 +39,6 @@ def __init__(
4339 grpc_channel_pool : GrpcChannelPool | None = None ,
4440 grpc_channel : grpc .Channel | None = None ,
4541 ) -> None :
46- """Initialize the panel client.
47-
48- Args:
49- provided_interface: The interface provided by the service.
50- service_class: The class of the service.
51- discovery_client: An optional discovery client.
52- grpc_channel: An optional panel gRPC channel.
53- grpc_channel_pool: An optional gRPC channel pool.
54- """
5542 self ._initialization_lock = threading .Lock ()
5643 self ._provided_interface = provided_interface
5744 self ._service_class = service_class
@@ -61,51 +48,17 @@ def __init__(
6148 self ._stub : PythonPanelServiceStub | None = None
6249
6350 def start_panel (self , panel_id : str , panel_script_path : str , python_path : str ) -> str :
64- """Start the panel.
65-
66- Args:
67- panel_id: The ID of the panel to start.
68- panel_script_path: The path of the panel script file.
69- python_path: The path to the Python executable.
70-
71- Returns:
72- The URL of the panel.
73-
74- Raises:
75- grpc.RpcError: With status code:
76- - INVALID_ARGUMENT: If the panel script filename doesn't end in .py, or
77- if the panel identifier contains invalid characters (only alphanumeric
78- characters and underscores are allowed).
79- - NOT_FOUND: If the panel script file or Python executable file was not found.
80- """
8151 start_panel_request = StartPanelRequest (
8252 panel_id = panel_id , panel_script_path = panel_script_path , python_path = python_path
8353 )
8454 response = self ._invoke_with_retry (self ._get_stub ().StartPanel , start_panel_request )
8555 return response .panel_url
8656
8757 def stop_panel (self , panel_id : str , reset : bool ) -> None :
88- """Stop the panel.
89-
90- Args:
91- panel_id: The ID of the panel to stop.
92- reset: Whether to reset all storage associated with panel.
93-
94- Raises:
95- grpc.RpcError: With status code:
96- - INVALID_ARGUMENT: If the panel identifier contains invalid characters
97- (only alphanumeric characters and underscores are allowed).
98- """
9958 stop_panel_request = StopPanelRequest (panel_id = panel_id , reset = reset )
10059 self ._invoke_with_retry (self ._get_stub ().StopPanel , stop_panel_request )
10160
10261 def enumerate_panels (self ) -> dict [str , tuple [str , list [str ]]]:
103- """Enumerate all available panels.
104-
105- Returns:
106- A dictionary mapping panel IDs to a tuple containing the url of the panel (if it is
107- running) and a list of value IDs associated with the panel.
108- """
10962 enumerate_panels_request = EnumeratePanelsRequest ()
11063 response = self ._invoke_with_retry (
11164 self ._get_stub ().EnumeratePanels , enumerate_panels_request
@@ -115,60 +68,18 @@ def enumerate_panels(self) -> dict[str, tuple[str, list[str]]]:
11568 }
11669
11770 def set_value (self , panel_id : str , value_id : str , value : object , notify : bool ) -> None :
118- """Set the value for the control with value_id.
119-
120- Args:
121- panel_id: The ID of the panel.
122- value_id: The ID of the control.
123- value: The value to set.
124- notify: Whether to notify other clients of the new value.
125-
126- Raises:
127- grpc.RpcError: With status code:
128- - INVALID_ARGUMENT: If the panel identifier or value identifier contains
129- invalid characters (only alphanumeric characters and underscores are allowed).
130- """
13171 new_any = to_any (value )
13272 set_value_request = SetValueRequest (
13373 panel_id = panel_id , value_id = value_id , value = new_any , notify = notify
13474 )
13575 self ._invoke_with_retry (self ._get_stub ().SetValue , set_value_request )
13676
13777 def get_value (self , panel_id : str , value_id : str ) -> object :
138- """Get the value for the control with value_id.
139-
140- Args:
141- panel_id: The ID of the panel.
142- value_id: The ID of the control.
143-
144- Returns:
145- The value.
146-
147- Raises:
148- grpc.RpcError: With status code:
149- - INVALID_ARGUMENT: If the panel identifier or value identifier contains
150- invalid characters (only alphanumeric characters and underscores are allowed).
151- - NOT_FOUND: If the value with the specified identifier was not found.
152- """
15378 get_value_request = GetValueRequest (panel_id = panel_id , value_id = value_id )
15479 response = self ._invoke_with_retry (self ._get_stub ().GetValue , get_value_request )
15580 return from_any (response .value )
15681
15782 def try_get_value (self , panel_id : str , value_id : str ) -> object | None :
158- """Try to get the value for the control with value_id.
159-
160- Args:
161- panel_id: The ID of the panel.
162- value_id: The ID of the control.
163-
164- Returns:
165- The value if found, otherwise None.
166-
167- Raises:
168- grpc.RpcError: With status code:
169- - INVALID_ARGUMENT: If the panel identifier or value identifier contains
170- invalid characters (only alphanumeric characters and underscores are allowed).
171- """
17283 try_get_value_request = TryGetValueRequest (panel_id = panel_id , value_id = value_id )
17384 response = self ._invoke_with_retry (self ._get_stub ().TryGetValue , try_get_value_request )
17485 if response .HasField ("value" ):
0 commit comments