diff --git a/Cargo.toml b/Cargo.toml index 7a1586b..6f0ce8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gtk-test" -version = "0.17.0" +version = "0.18.0" authors = ["The Gtk-rs Project Developers"] license = "MIT" description = "Crate to test GTK UIs" @@ -13,7 +13,7 @@ edition = "2021" [dependencies] enigo = "^0.0.14" -gtk = "0.17" +gtk = "0.18" [[test]] harness = false diff --git a/src/functions.rs b/src/functions.rs index 74bac12..68caea6 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -1,9 +1,9 @@ use enigo::{self, Enigo, KeyboardControllable, MouseButton, MouseControllable}; use gtk::gdk::keys::constants as key; use gtk::gdk::keys::Key; -use gtk::glib::{Cast, Continue, IsA, Object, StaticType}; +use gtk::glib::{Cast, ControlFlow, IsA, Object, Propagation, StaticType}; use gtk::prelude::{BinExt, ButtonExt, ContainerExt, EditableExt, ToolButtonExt, WidgetExt}; -use gtk::{Bin, Button, Container, Entry, Inhibit, ToolButton, Widget, Window}; +use gtk::{Bin, Button, Container, Entry, ToolButton, Widget, Window}; use crate::observer_new; @@ -44,7 +44,7 @@ pub fn click + IsA + WidgetExt + IsA>(widget: observer_new!(tool_button, connect_clicked, |_|) } else { observer_new!(widget, connect_button_release_event, |_, _| { - Inhibit(false) + Propagation::Stop }) }; let allocation = widget.allocation(); @@ -87,7 +87,7 @@ pub fn click + IsA + WidgetExt + IsA>(widget: pub fn double_click + IsA + WidgetExt>(widget: &W) { wait_for_draw(widget, || { let observer = observer_new!(widget, connect_button_release_event, |_, _| { - Inhibit(false) + Propagation::Stop }); let allocation = widget.allocation(); mouse_move(widget, allocation.width() / 2, allocation.height() / 2); @@ -243,7 +243,9 @@ pub fn mouse_release + IsA + WidgetExt>(widget: &W) { /// ``` pub fn enter_key + IsA + WidgetExt>(widget: &W, key: Key) { wait_for_draw(widget, || { - let observer = observer_new!(widget, connect_key_release_event, |_, _| { Inhibit(false) }); + let observer = observer_new!(widget, connect_key_release_event, |_, _| { + Propagation::Stop + }); focus(widget); let mut enigo = Enigo::new(); enigo.key_click(gdk_key_to_enigo_key(key)); @@ -286,8 +288,9 @@ pub fn enter_keys + IsA + WidgetExt>(widget: &W, focus(widget); let mut enigo = Enigo::new(); for char in text.chars() { - let observer = - observer_new!(widget, connect_key_release_event, |_, _| { Inhibit(false) }); + let observer = observer_new!(widget, connect_key_release_event, |_, _| { + Propagation::Stop + }); enigo.key_sequence(&char.to_string()); observer.wait(); } @@ -382,7 +385,8 @@ pub fn find_widget_by_name + IsA>( /// #[macro_use] /// extern crate gtk_test; /// -/// use gtk::{Button, Inhibit, prelude::WidgetExt}; +/// use gtk::{Button, prelude::WidgetExt}; +/// use gtk::glib::Propagation; /// /// # fn main() { /// gtk::init().expect("GTK init failed"); @@ -390,7 +394,7 @@ pub fn find_widget_by_name + IsA>( /// /// but.connect_focus(|_, _| { /// println!("focused!"); -/// Inhibit(false) +/// Propagation::Stop /// }); /// gtk_test::focus(&but); /// # } @@ -426,14 +430,15 @@ pub fn focus + IsA + WidgetExt>(widget: &W) { /// #[macro_use] /// extern crate gtk_test; /// -/// use gtk_test::gtk::{Entry, Inhibit, prelude::WidgetExt}; +/// use gtk_test::gtk::{Entry, prelude::WidgetExt}; +/// use gtk_test::gtk::glib::Propagation; /// /// # fn main() { /// gtk_test::gtk::init().expect("GTK init failed"); /// let entry = Entry::new(); /// entry.connect_key_press_event(|_, _| { /// println!("key pressed"); -/// Inhibit(false) +/// Propagation::Stop /// }); /// gtk_test::key_press(&entry, gtk_test::gdk::keys::constants::Agrave); /// # } @@ -441,7 +446,9 @@ pub fn focus + IsA + WidgetExt>(widget: &W) { // FIXME: don't wait the observer for modifier keys like shift? pub fn key_press + IsA + WidgetExt>(widget: &W, key: Key) { wait_for_draw(widget, || { - let observer = observer_new!(widget, connect_key_press_event, |_, _| { Inhibit(false) }); + let observer = observer_new!(widget, connect_key_press_event, |_, _| { + Propagation::Stop + }); focus(widget); let mut enigo = Enigo::new(); enigo.key_down(gdk_key_to_enigo_key(key)); @@ -467,21 +474,24 @@ pub fn key_press + IsA + WidgetExt>(widget: &W, k /// #[macro_use] /// extern crate gtk_test; /// -/// use gtk_test::gtk::{Entry, Inhibit, prelude::WidgetExt}; +/// use gtk_test::gtk::{Entry, prelude::WidgetExt}; +/// use gtk_test::gtk::glib::Propagation; /// /// # fn main() { /// gtk_test::gtk::init().expect("GTK init failed"); /// let entry = Entry::new(); /// entry.connect_key_release_event(|_, _| { /// println!("key released"); -/// Inhibit(false) +/// Propagation::Stop /// }); /// gtk_test::key_release(&entry, gtk_test::gdk::keys::constants::Agrave); /// # } /// ``` pub fn key_release + IsA + WidgetExt>(widget: &W, key: Key) { wait_for_draw(widget, || { - let observer = observer_new!(widget, connect_key_release_event, |_, _| { Inhibit(false) }); + let observer = observer_new!(widget, connect_key_release_event, |_, _| { + Propagation::Stop + }); focus(widget); let mut enigo = Enigo::new(); enigo.key_up(gdk_key_to_enigo_key(key)); @@ -507,7 +517,7 @@ pub fn key_release + IsA + WidgetExt>(widget: &W, pub fn wait(ms: u32) { gtk::glib::timeout_add(std::time::Duration::from_millis(ms as u64), || { gtk::main_quit(); - Continue(false) + ControlFlow::Break }); gtk::main(); } diff --git a/tests/basic.rs b/tests/basic.rs index 4173c08..eb84925 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -4,8 +4,9 @@ extern crate gtk_test; use gtk::{ prelude::ButtonExt, prelude::ContainerExt, prelude::GtkWindowExt, prelude::LabelExt, - prelude::WidgetExt, Button, Inhibit, Label, Orientation, Window, WindowType, + prelude::WidgetExt, Button, Label, Orientation, Window, WindowType, }; +use gtk::glib::Propagation; pub fn init_ui() -> (Window, Label, Button) { gtk::init().unwrap(); @@ -26,7 +27,7 @@ pub fn init_ui() -> (Window, Label, Button) { window.show_all(); window.connect_delete_event(|_, _| { gtk::main_quit(); - Inhibit(false) + Propagation::Stop }); (window, label, but) }