118118 Use `pin.pin.use_strict()` to enable strict mode for getting pin widget value.
119119 An ``AssertionError`` will be raised when try to get value of pin widgets that are currently not in the page.
120120
121+ .. autofunction:: get_pin_values
121122.. autofunction:: pin_wait_change
122123.. autofunction:: pin_update
123124.. autofunction:: pin_on_change
137138_pin_name_chars = set (string .ascii_letters + string .digits + '_-' )
138139
139140__all__ = ['put_input' , 'put_textarea' , 'put_select' , 'put_checkbox' , 'put_radio' , 'put_slider' , 'put_actions' ,
140- 'put_file_upload' , 'pin' , 'pin_update' , 'pin_wait_change' , 'pin_on_change' ]
141+ 'put_file_upload' , 'pin' , 'pin_update' , 'pin_wait_change' , 'pin_on_change' , 'get_pin_values' ]
141142
142143
143144def _pin_output (single_input_return , scope , position ):
@@ -258,11 +259,32 @@ def get_client_val():
258259
259260
260261@chose_impl
261- def get_pin_value (name , strict ):
262- send_msg ('pin_value ' , spec = dict (name = name ))
262+ def _get_pin_value (name , strict ):
263+ send_msg ('pin_values ' , spec = dict (names = [ name ] ))
263264 data = yield get_client_val ()
264- assert not strict or data , 'pin widget "%s" doesn\' t exist.' % name
265- return (data or {}).get ('value' )
265+ if strict :
266+ assert name in data , 'pin widget "%s" doesn\' t exist.' % name
267+ return data .get (name )
268+
269+
270+ @chose_impl
271+ def _get_pin_values (names : list [str ]):
272+ send_msg ('pin_values' , spec = dict (names = names ))
273+ data = yield get_client_val ()
274+ return data
275+
276+
277+ def get_pin_values (names : list [str ]) -> dict [str , Any ]:
278+ """
279+ Get the value of multiple pin widgets.
280+ Compared to using the :data:`pin` object to get the value of the pin widget one by one,
281+ this function can get the value of multiple pin widgets at once and is more efficient
282+ when getting the value of multiple pin widgets.
283+
284+ :return: A dict, the key is the name of the pin widget, and the value is the value of the pin widget.
285+ If the pin widget does not exist, the dict will not contain the corresponding key.
286+ """
287+ return _get_pin_values (names )
266288
267289
268290class Pin_ :
@@ -283,7 +305,7 @@ def __getattr__(self, name: str):
283305
284306 def __getitem__ (self , name : str ):
285307 check_dom_name_value (name , 'pin `name`' )
286- return get_pin_value (name , self ._strict )
308+ return _get_pin_value (name , self ._strict )
287309
288310 def __setattr__ (self , name : str , value ):
289311 """
0 commit comments