如何在单击按钮事件中执行其他任务时关闭 main window?
How to close main window while doing other tasks in a clicked button event?
我正在尝试重新创建 this Python project in Rust。 Python版本使用PyQt5,Ruby版本使用GTK。使用 Rust 或 Ruby 时,我不知道如何在用户按下 "Tweet" 时正确执行 "Tweeting" 代码。
用户按下的按钮称为"send",按下时调用此代码:
send.connect_clicked(move |_| {
let sent: Option<String> = TextBuffer::get_text(
&TextView::get_buffer(&text).unwrap(),
&TextBuffer::get_start_iter(&TextView::get_buffer(&text).unwrap()),
&TextBuffer::get_end_iter(&TextView::get_buffer(&text).unwrap()), false);
let actual = sent.unwrap();
println!("Text: {}", actual);
let toot = Command::new("t").output()
.expect("Nope");
println!("{}", String::from_utf8_lossy(&toot.stdout));
Notification::new().summary("Sent")
.body(&actual).show().unwrap();
gtk::main_quit();
});
只要用户按下它,window 就会冻结,直到代码完成 运行,然后主程序 window 退出。
如何正确关闭 window 并执行此代码?它可能非常简单,但我几乎没有适当地研究过功能。编写 Python 脚本的坏习惯。
为了正确关闭主 window 并执行其他任务,我使用了 glib 中的 idle_add
。
thread::spawn(move || {
glib::idle_add(move || {
toot(tweet);
gtk::main_quit();
Continue(false)
});
});
我正在尝试重新创建 this Python project in Rust。 Python版本使用PyQt5,Ruby版本使用GTK。使用 Rust 或 Ruby 时,我不知道如何在用户按下 "Tweet" 时正确执行 "Tweeting" 代码。
用户按下的按钮称为"send",按下时调用此代码:
send.connect_clicked(move |_| {
let sent: Option<String> = TextBuffer::get_text(
&TextView::get_buffer(&text).unwrap(),
&TextBuffer::get_start_iter(&TextView::get_buffer(&text).unwrap()),
&TextBuffer::get_end_iter(&TextView::get_buffer(&text).unwrap()), false);
let actual = sent.unwrap();
println!("Text: {}", actual);
let toot = Command::new("t").output()
.expect("Nope");
println!("{}", String::from_utf8_lossy(&toot.stdout));
Notification::new().summary("Sent")
.body(&actual).show().unwrap();
gtk::main_quit();
});
只要用户按下它,window 就会冻结,直到代码完成 运行,然后主程序 window 退出。
如何正确关闭 window 并执行此代码?它可能非常简单,但我几乎没有适当地研究过功能。编写 Python 脚本的坏习惯。
为了正确关闭主 window 并执行其他任务,我使用了 glib 中的 idle_add
。
thread::spawn(move || {
glib::idle_add(move || {
toot(tweet);
gtk::main_quit();
Continue(false)
});
});