Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Update to gtk-rs 0.18 #59

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -13,7 +13,7 @@ edition = "2021"

[dependencies]
enigo = "^0.0.14"
gtk = "0.17"
gtk = "0.18"

[[test]]
harness = false
Expand Down
42 changes: 26 additions & 16 deletions src/functions.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn click<W: Clone + IsA<Object> + IsA<Widget> + WidgetExt + IsA<W>>(widget:
observer_new!(tool_button, connect_clicked, |_|)
} else {
observer_new!(widget, connect_button_release_event, |_, _| {
Inhibit(false)
Propagation::Stop
})
};
let allocation = widget.allocation();
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn click<W: Clone + IsA<Object> + IsA<Widget> + WidgetExt + IsA<W>>(widget:
pub fn double_click<W: Clone + IsA<Object> + IsA<Widget> + 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);
Expand Down Expand Up @@ -243,7 +243,9 @@ pub fn mouse_release<W: IsA<Object> + IsA<Widget> + WidgetExt>(widget: &W) {
/// ```
pub fn enter_key<W: Clone + IsA<Object> + IsA<Widget> + 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));
Expand Down Expand Up @@ -286,8 +288,9 @@ pub fn enter_keys<W: Clone + IsA<Object> + IsA<Widget> + 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();
}
Expand Down Expand Up @@ -382,15 +385,16 @@ pub fn find_widget_by_name<W: Clone + IsA<Object> + IsA<Widget>>(
/// #[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");
/// let but = Button::new();
///
/// but.connect_focus(|_, _| {
/// println!("focused!");
/// Inhibit(false)
/// Propagation::Stop
/// });
/// gtk_test::focus(&but);
/// # }
Expand Down Expand Up @@ -426,22 +430,25 @@ pub fn focus<W: Clone + IsA<Object> + IsA<Widget> + 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);
/// # }
/// ```
// FIXME: don't wait the observer for modifier keys like shift?
pub fn key_press<W: Clone + IsA<Object> + IsA<Widget> + 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));
Expand All @@ -467,21 +474,24 @@ pub fn key_press<W: Clone + IsA<Object> + IsA<Widget> + 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<W: Clone + IsA<Object> + IsA<Widget> + 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));
Expand All @@ -507,7 +517,7 @@ pub fn key_release<W: Clone + IsA<Object> + IsA<Widget> + 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();
}
Expand Down
5 changes: 3 additions & 2 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
}
Expand Down
Loading