Skip to content

Commit 8431b99

Browse files
authored
feat!: Update pyo3 to 0.24 and AccessKit crates to their latest versions (#6)
1 parent 519c9b3 commit 8431b99

File tree

9 files changed

+340
-455
lines changed

9 files changed

+340
-455
lines changed

Cargo.lock

Lines changed: 199 additions & 358 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ doc = false
1818
extension-module = ["pyo3/extension-module"]
1919

2020
[dependencies]
21-
accesskit = { version = "0.17.1", features = ["pyo3"] }
22-
pyo3 = { version = "0.20", features = ["abi3-py38", "multiple-pymethods"] }
21+
accesskit = { version = "0.21.0", features = ["pyo3"] }
22+
pyo3 = { version = "0.24", features = ["abi3-py38", "multiple-pymethods"] }
2323

2424
[target.'cfg(target_os = "windows")'.dependencies]
25-
accesskit_windows = { version = "0.24.1" }
25+
accesskit_windows = { version = "0.29.0" }
2626

2727
[target.'cfg(target_os = "macos")'.dependencies]
28-
accesskit_macos = { version = "0.18.1" }
28+
accesskit_macos = { version = "0.22.0" }
2929

3030
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
31-
accesskit_unix = { version = "0.13.1" }
31+
accesskit_unix = { version = "0.17.0" }
3232

3333
[profile.release]
3434
lto = true

examples/pygame/hello_world.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def build_initial_tree(self):
9191
button_2 = build_button(BUTTON_2_ID, "Button 2")
9292
result = accesskit.TreeUpdate(self.focus)
9393
tree = accesskit.Tree(WINDOW_ID)
94-
tree.app_name = "Hello world"
9594
result.tree = tree
9695
result.nodes.append((WINDOW_ID, root))
9796
result.nodes.append((BUTTON_1_ID, button_1))

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ classifiers = [
3434
"Programming Language :: Python :: 3.12",
3535
"Topic :: Software Development :: User Interfaces"
3636
]
37+
dynamic = ["version"]
3738

3839
[project.urls]
3940
Homepage = "https://github.com/AccessKit/accesskit-python"

src/common.rs

Lines changed: 87 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
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

6485
pub 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")]
156176
pub struct TextSelection {
157177
pub anchor: Py<TextPosition>,
@@ -178,15 +198,20 @@ impl From<&accesskit::TextSelection> for TextSelection {
178198
impl 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

405430
flag_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! {
540564
property_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

546570
vec_property_methods! {
@@ -551,7 +575,6 @@ vec_property_methods! {
551575
#[pyclass(module = "accesskit", get_all, set_all)]
552576
pub 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)]
585605
pub 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)]
630649
pub 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 {
641661
pub 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

647667
impl 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

Comments
 (0)