3
3
// the LICENSE-APACHE file) or the MIT license (found in
4
4
// the LICENSE-MIT file), at your option.
5
5
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 ;
8
13
9
14
#[ derive( Clone ) ]
10
15
#[ pyclass( module = "accesskit" ) ]
@@ -59,6 +64,22 @@ impl Node {
59
64
pub fn clear_actions ( & mut self ) {
60
65
self . inner_mut ( ) . clear_actions ( )
61
66
}
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
+ }
62
83
}
63
84
64
85
pub type NodeId = u64 ;
@@ -151,7 +172,6 @@ impl From<accesskit::TextPosition> for TextPosition {
151
172
}
152
173
}
153
174
154
- #[ derive( Clone ) ]
155
175
#[ pyclass( get_all, set_all, module = "accesskit" ) ]
156
176
pub struct TextSelection {
157
177
pub anchor : Py < TextPosition > ,
@@ -178,15 +198,20 @@ impl From<&accesskit::TextSelection> for TextSelection {
178
198
impl From < TextSelection > for accesskit:: TextSelection {
179
199
fn from ( selection : TextSelection ) -> Self {
180
200
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 ,
183
203
} )
184
204
}
185
205
}
186
206
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
+ } )
190
215
}
191
216
}
192
217
@@ -293,14 +318,14 @@ macro_rules! vec_property_methods {
293
318
$( #[ pymethods]
294
319
impl Node {
295
320
#[ 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 ( ) )
299
324
}
300
- pub fn $setter( & mut self , values: & PyList ) {
325
+ pub fn $setter( & mut self , values: & Bound < ' _ , PyList > ) {
301
326
let values = values
302
327
. iter( )
303
- . map( PyAny :: extract:: <$py_item_type>)
328
+ . map( |item| item . extract:: <$py_item_type>( ) )
304
329
. filter_map( PyResult :: ok)
305
330
. map( <$accesskit_item_type>:: from)
306
331
. collect:: <Vec <$accesskit_item_type>>( ) ;
@@ -404,7 +429,6 @@ macro_rules! unique_enum_property_methods {
404
429
405
430
flag_methods ! {
406
431
( is_hidden, set_hidden, clear_hidden) ,
407
- ( is_linked, set_linked, clear_linked) ,
408
432
( is_multiselectable, set_multiselectable, clear_multiselectable) ,
409
433
( is_required, set_required, clear_required) ,
410
434
( is_visited, set_visited, clear_visited) ,
@@ -540,7 +564,7 @@ unique_enum_property_methods! {
540
564
property_methods ! {
541
565
( transform, option_getter, Option <crate :: Affine >, set_transform, simple_setter, crate :: Affine , clear_transform) ,
542
566
( 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)
544
568
}
545
569
546
570
vec_property_methods ! {
@@ -551,7 +575,6 @@ vec_property_methods! {
551
575
#[ pyclass( module = "accesskit" , get_all, set_all) ]
552
576
pub struct Tree {
553
577
pub root : NodeId ,
554
- pub app_name : Option < String > ,
555
578
pub toolkit_name : Option < String > ,
556
579
pub toolkit_version : Option < String > ,
557
580
}
@@ -562,7 +585,6 @@ impl Tree {
562
585
pub fn new ( root : NodeId ) -> Self {
563
586
Self {
564
587
root,
565
- app_name : None ,
566
588
toolkit_name : None ,
567
589
toolkit_version : None ,
568
590
}
@@ -573,14 +595,12 @@ impl From<Tree> for accesskit::Tree {
573
595
fn from ( tree : Tree ) -> Self {
574
596
Self {
575
597
root : tree. root . into ( ) ,
576
- app_name : tree. app_name ,
577
598
toolkit_name : tree. toolkit_name ,
578
599
toolkit_version : tree. toolkit_version ,
579
600
}
580
601
}
581
602
}
582
603
583
- #[ derive( Clone ) ]
584
604
#[ pyclass( module = "accesskit" , get_all, set_all) ]
585
605
pub struct TreeUpdate {
586
606
pub nodes : Py < PyList > ,
@@ -600,22 +620,21 @@ impl TreeUpdate {
600
620
}
601
621
}
602
622
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 {
605
625
Python :: with_gil ( |py| Self {
606
626
nodes : update
607
627
. nodes
608
- . as_ref ( py)
628
+ . bind ( py)
609
629
. iter ( )
610
- . map ( PyAny :: extract :: < ( NodeId , Node ) > )
630
+ . map ( |n| n . extract :: < ( NodeId , Node ) > ( ) )
611
631
. filter_map ( Result :: ok)
612
632
. map ( |( id, node) | ( id. into ( ) , node. into ( ) ) )
613
633
. 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 ( ) ;
616
636
accesskit:: Tree {
617
637
root : tree. root . into ( ) ,
618
- app_name : tree. app_name . clone ( ) ,
619
638
toolkit_name : tree. toolkit_name . clone ( ) ,
620
639
toolkit_version : tree. toolkit_version . clone ( ) ,
621
640
}
@@ -625,13 +644,14 @@ impl From<TreeUpdate> for accesskit::TreeUpdate {
625
644
}
626
645
}
627
646
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 ) ]
630
649
pub enum ActionDataKind {
631
650
CustomAction ,
632
651
Value ,
633
652
NumericValue ,
634
- ScrollTargetRect ,
653
+ ScrollUnit ,
654
+ ScrollHint ,
635
655
ScrollToPoint ,
636
656
SetScrollOffset ,
637
657
SetTextSelection ,
@@ -641,38 +661,48 @@ pub enum ActionDataKind {
641
661
pub struct ActionRequest {
642
662
pub action : accesskit:: Action ,
643
663
pub target : NodeId ,
644
- pub data : Option < ( ActionDataKind , Py < PyAny > ) > ,
664
+ pub data : Option < Py < PyTuple > > ,
645
665
}
646
666
647
667
impl From < accesskit:: ActionRequest > for ActionRequest {
648
668
fn from ( request : accesskit:: ActionRequest ) -> Self {
649
669
Python :: with_gil ( |py| Self {
650
670
action : request. action ,
651
671
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
+ ) ,
655
702
}
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 ( )
676
706
} ) ,
677
707
} )
678
708
}
@@ -690,9 +720,9 @@ impl accesskit::ActivationHandler for LocalPythonActivationHandler<'_> {
690
720
fn request_initial_tree ( & mut self ) -> Option < accesskit:: TreeUpdate > {
691
721
let result = self . handler . call0 ( self . py ) . unwrap ( ) ;
692
722
result
693
- . extract :: < Option < TreeUpdate > > ( self . py )
723
+ . extract :: < Option < PyRef < TreeUpdate > > > ( self . py )
694
724
. unwrap ( )
695
- . map ( Into :: into)
725
+ . map ( |tree| ( & * tree ) . into ( ) )
696
726
}
697
727
}
698
728
@@ -703,9 +733,9 @@ impl accesskit::ActivationHandler for PythonActivationHandler {
703
733
Python :: with_gil ( |py| {
704
734
let result = self . 0 . call0 ( py) . unwrap ( ) ;
705
735
result
706
- . extract :: < Option < TreeUpdate > > ( py)
736
+ . extract :: < Option < PyRef < TreeUpdate > > > ( py)
707
737
. unwrap ( )
708
- . map ( Into :: into)
738
+ . map ( |tree| ( & * tree ) . into ( ) )
709
739
} )
710
740
}
711
741
}
0 commit comments