33// the LICENSE-APACHE file) or the MIT license (found in
44// the LICENSE-MIT file), at your option.
55
6- use crate :: { Point , Rect } ;
7- use pyo3:: { prelude:: * , types:: PyList } ;
6+ use pyo3:: {
7+ prelude:: * ,
8+ types:: { PyList , PyTuple } ,
9+ IntoPyObjectExt ,
10+ } ;
11+
12+ use crate :: Point ;
813
914#[ derive( Clone ) ]
1015#[ pyclass( module = "accesskit" ) ]
@@ -59,6 +64,22 @@ impl Node {
5964 pub fn clear_actions ( & mut self ) {
6065 self . inner_mut ( ) . clear_actions ( )
6166 }
67+
68+ pub fn child_supports_action ( & self , action : accesskit:: Action ) -> bool {
69+ self . inner ( ) . child_supports_action ( action)
70+ }
71+
72+ pub fn add_child_action ( & mut self , action : accesskit:: Action ) {
73+ self . inner_mut ( ) . add_child_action ( action)
74+ }
75+
76+ pub fn remove_child_action ( & mut self , action : accesskit:: Action ) {
77+ self . inner_mut ( ) . remove_child_action ( action)
78+ }
79+
80+ pub fn clear_child_actions ( & mut self ) {
81+ self . inner_mut ( ) . clear_child_actions ( ) ;
82+ }
6283}
6384
6485pub type NodeId = u64 ;
@@ -151,7 +172,6 @@ impl From<accesskit::TextPosition> for TextPosition {
151172 }
152173}
153174
154- #[ derive( Clone ) ]
155175#[ pyclass( get_all, set_all, module = "accesskit" ) ]
156176pub struct TextSelection {
157177 pub anchor : Py < TextPosition > ,
@@ -178,15 +198,20 @@ impl From<&accesskit::TextSelection> for TextSelection {
178198impl From < TextSelection > for accesskit:: TextSelection {
179199 fn from ( selection : TextSelection ) -> Self {
180200 Python :: with_gil ( |py| accesskit:: TextSelection {
181- anchor : selection. anchor . as_ref ( py) . borrow ( ) . 0 ,
182- focus : selection. focus . as_ref ( py) . borrow ( ) . 0 ,
201+ anchor : selection. anchor . bind ( py) . borrow ( ) . 0 ,
202+ focus : selection. focus . bind ( py) . borrow ( ) . 0 ,
183203 } )
184204 }
185205}
186206
187- impl From < TextSelection > for Box < accesskit:: TextSelection > {
188- fn from ( selection : TextSelection ) -> Self {
189- Box :: new ( selection. into ( ) )
207+ impl From < & TextSelection > for Box < accesskit:: TextSelection > {
208+ fn from ( selection : & TextSelection ) -> Self {
209+ Python :: with_gil ( |py| {
210+ Box :: new ( accesskit:: TextSelection {
211+ anchor : selection. anchor . borrow ( py) . 0 ,
212+ focus : selection. focus . borrow ( py) . 0 ,
213+ } )
214+ } )
190215 }
191216}
192217
@@ -293,14 +318,14 @@ macro_rules! vec_property_methods {
293318 $( #[ pymethods]
294319 impl Node {
295320 #[ getter]
296- pub fn $getter( & self , py: Python ) -> Py <PyList > {
297- let values = self . inner( ) . $getter( ) . iter( ) . cloned( ) . map( <$py_item_type>:: from) . map ( |i| i . into_py ( py ) ) ;
298- PyList :: new( py, values) . into ( )
321+ pub fn $getter( & self , py: Python ) -> PyResult < Py <PyList > > {
322+ let values = self . inner( ) . $getter( ) . iter( ) . cloned( ) . map( <$py_item_type>:: from) ;
323+ Ok ( PyList :: new( py, values) ? . unbind ( ) )
299324 }
300- pub fn $setter( & mut self , values: & PyList ) {
325+ pub fn $setter( & mut self , values: & Bound < ' _ , PyList > ) {
301326 let values = values
302327 . iter( )
303- . map( PyAny :: extract:: <$py_item_type>)
328+ . map( |item| item . extract:: <$py_item_type>( ) )
304329 . filter_map( PyResult :: ok)
305330 . map( <$accesskit_item_type>:: from)
306331 . collect:: <Vec <$accesskit_item_type>>( ) ;
@@ -404,7 +429,6 @@ macro_rules! unique_enum_property_methods {
404429
405430flag_methods ! {
406431 ( is_hidden, set_hidden, clear_hidden) ,
407- ( is_linked, set_linked, clear_linked) ,
408432 ( is_multiselectable, set_multiselectable, clear_multiselectable) ,
409433 ( is_required, set_required, clear_required) ,
410434 ( is_visited, set_visited, clear_visited) ,
@@ -540,7 +564,7 @@ unique_enum_property_methods! {
540564property_methods ! {
541565 ( transform, option_getter, Option <crate :: Affine >, set_transform, simple_setter, crate :: Affine , clear_transform) ,
542566 ( bounds, option_getter, Option <crate :: Rect >, set_bounds, converting_setter, crate :: Rect , clear_bounds) ,
543- ( text_selection, option_getter, Option <TextSelection >, set_text_selection, simple_setter, TextSelection , clear_text_selection)
567+ ( text_selection, option_getter, Option <TextSelection >, set_text_selection, simple_setter, & TextSelection , clear_text_selection)
544568}
545569
546570vec_property_methods ! {
@@ -551,7 +575,6 @@ vec_property_methods! {
551575#[ pyclass( module = "accesskit" , get_all, set_all) ]
552576pub struct Tree {
553577 pub root : NodeId ,
554- pub app_name : Option < String > ,
555578 pub toolkit_name : Option < String > ,
556579 pub toolkit_version : Option < String > ,
557580}
@@ -562,7 +585,6 @@ impl Tree {
562585 pub fn new ( root : NodeId ) -> Self {
563586 Self {
564587 root,
565- app_name : None ,
566588 toolkit_name : None ,
567589 toolkit_version : None ,
568590 }
@@ -573,14 +595,12 @@ impl From<Tree> for accesskit::Tree {
573595 fn from ( tree : Tree ) -> Self {
574596 Self {
575597 root : tree. root . into ( ) ,
576- app_name : tree. app_name ,
577598 toolkit_name : tree. toolkit_name ,
578599 toolkit_version : tree. toolkit_version ,
579600 }
580601 }
581602}
582603
583- #[ derive( Clone ) ]
584604#[ pyclass( module = "accesskit" , get_all, set_all) ]
585605pub struct TreeUpdate {
586606 pub nodes : Py < PyList > ,
@@ -600,22 +620,21 @@ impl TreeUpdate {
600620 }
601621}
602622
603- impl From < TreeUpdate > for accesskit:: TreeUpdate {
604- fn from ( update : TreeUpdate ) -> Self {
623+ impl From < & TreeUpdate > for accesskit:: TreeUpdate {
624+ fn from ( update : & TreeUpdate ) -> Self {
605625 Python :: with_gil ( |py| Self {
606626 nodes : update
607627 . nodes
608- . as_ref ( py)
628+ . bind ( py)
609629 . iter ( )
610- . map ( PyAny :: extract :: < ( NodeId , Node ) > )
630+ . map ( |n| n . extract :: < ( NodeId , Node ) > ( ) )
611631 . filter_map ( Result :: ok)
612632 . map ( |( id, node) | ( id. into ( ) , node. into ( ) ) )
613633 . collect ( ) ,
614- tree : update. tree . map ( |tree| {
615- let tree = tree. as_ref ( py) . borrow ( ) ;
634+ tree : update. tree . as_ref ( ) . map ( |tree| {
635+ let tree = tree. bind ( py) . borrow ( ) ;
616636 accesskit:: Tree {
617637 root : tree. root . into ( ) ,
618- app_name : tree. app_name . clone ( ) ,
619638 toolkit_name : tree. toolkit_name . clone ( ) ,
620639 toolkit_version : tree. toolkit_version . clone ( ) ,
621640 }
@@ -625,13 +644,14 @@ impl From<TreeUpdate> for accesskit::TreeUpdate {
625644 }
626645}
627646
628- #[ derive( Clone ) ]
629- #[ pyclass( module = "accesskit" , rename_all = "SCREAMING_SNAKE_CASE" ) ]
647+ #[ derive( PartialEq ) ]
648+ #[ pyclass( module = "accesskit" , rename_all = "SCREAMING_SNAKE_CASE" , eq , eq_int ) ]
630649pub enum ActionDataKind {
631650 CustomAction ,
632651 Value ,
633652 NumericValue ,
634- ScrollTargetRect ,
653+ ScrollUnit ,
654+ ScrollHint ,
635655 ScrollToPoint ,
636656 SetScrollOffset ,
637657 SetTextSelection ,
@@ -641,38 +661,48 @@ pub enum ActionDataKind {
641661pub struct ActionRequest {
642662 pub action : accesskit:: Action ,
643663 pub target : NodeId ,
644- pub data : Option < ( ActionDataKind , Py < PyAny > ) > ,
664+ pub data : Option < Py < PyTuple > > ,
645665}
646666
647667impl From < accesskit:: ActionRequest > for ActionRequest {
648668 fn from ( request : accesskit:: ActionRequest ) -> Self {
649669 Python :: with_gil ( |py| Self {
650670 action : request. action ,
651671 target : request. target . into ( ) ,
652- data : request. data . map ( |data| match data {
653- accesskit:: ActionData :: CustomAction ( action) => {
654- ( ActionDataKind :: CustomAction , action. into_py ( py) )
672+ data : request. data . map ( |data| {
673+ match data {
674+ accesskit:: ActionData :: CustomAction ( action) => (
675+ ActionDataKind :: CustomAction ,
676+ action. into_py_any ( py) . unwrap ( ) ,
677+ ) ,
678+ accesskit:: ActionData :: Value ( value) => {
679+ ( ActionDataKind :: Value , value. into_py_any ( py) . unwrap ( ) )
680+ }
681+ accesskit:: ActionData :: NumericValue ( value) => {
682+ ( ActionDataKind :: NumericValue , value. into_py_any ( py) . unwrap ( ) )
683+ }
684+ accesskit:: ActionData :: ScrollUnit ( unit) => {
685+ ( ActionDataKind :: ScrollUnit , unit. into_py_any ( py) . unwrap ( ) )
686+ }
687+ accesskit:: ActionData :: ScrollHint ( hint) => {
688+ ( ActionDataKind :: ScrollHint , hint. into_py_any ( py) . unwrap ( ) )
689+ }
690+ accesskit:: ActionData :: ScrollToPoint ( point) => (
691+ ActionDataKind :: ScrollToPoint ,
692+ Point :: from ( point) . into_py_any ( py) . unwrap ( ) ,
693+ ) ,
694+ accesskit:: ActionData :: SetScrollOffset ( point) => (
695+ ActionDataKind :: SetScrollOffset ,
696+ Point :: from ( point) . into_py_any ( py) . unwrap ( ) ,
697+ ) ,
698+ accesskit:: ActionData :: SetTextSelection ( selection) => (
699+ ActionDataKind :: SetTextSelection ,
700+ TextSelection :: from ( & selection) . into_py_any ( py) . unwrap ( ) ,
701+ ) ,
655702 }
656- accesskit:: ActionData :: Value ( value) => ( ActionDataKind :: Value , value. into_py ( py) ) ,
657- accesskit:: ActionData :: NumericValue ( value) => {
658- ( ActionDataKind :: NumericValue , value. into_py ( py) )
659- }
660- accesskit:: ActionData :: ScrollTargetRect ( rect) => (
661- ActionDataKind :: ScrollTargetRect ,
662- Rect :: from ( rect) . into_py ( py) ,
663- ) ,
664- accesskit:: ActionData :: ScrollToPoint ( point) => (
665- ActionDataKind :: ScrollToPoint ,
666- Point :: from ( point) . into_py ( py) ,
667- ) ,
668- accesskit:: ActionData :: SetScrollOffset ( point) => (
669- ActionDataKind :: SetScrollOffset ,
670- Point :: from ( point) . into_py ( py) ,
671- ) ,
672- accesskit:: ActionData :: SetTextSelection ( selection) => (
673- ActionDataKind :: SetTextSelection ,
674- TextSelection :: from ( & selection) . into_py ( py) ,
675- ) ,
703+ . into_pyobject ( py)
704+ . unwrap ( )
705+ . unbind ( )
676706 } ) ,
677707 } )
678708 }
@@ -690,9 +720,9 @@ impl accesskit::ActivationHandler for LocalPythonActivationHandler<'_> {
690720 fn request_initial_tree ( & mut self ) -> Option < accesskit:: TreeUpdate > {
691721 let result = self . handler . call0 ( self . py ) . unwrap ( ) ;
692722 result
693- . extract :: < Option < TreeUpdate > > ( self . py )
723+ . extract :: < Option < PyRef < TreeUpdate > > > ( self . py )
694724 . unwrap ( )
695- . map ( Into :: into)
725+ . map ( |tree| ( & * tree ) . into ( ) )
696726 }
697727}
698728
@@ -703,9 +733,9 @@ impl accesskit::ActivationHandler for PythonActivationHandler {
703733 Python :: with_gil ( |py| {
704734 let result = self . 0 . call0 ( py) . unwrap ( ) ;
705735 result
706- . extract :: < Option < TreeUpdate > > ( py)
736+ . extract :: < Option < PyRef < TreeUpdate > > > ( py)
707737 . unwrap ( )
708- . map ( Into :: into)
738+ . map ( |tree| ( & * tree ) . into ( ) )
709739 } )
710740 }
711741}
0 commit comments