Skip to content

Commit

Permalink
examples: update for 4.10 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
jf2048 committed Apr 28, 2023
1 parent c11345e commit 03c4dcd
Show file tree
Hide file tree
Showing 38 changed files with 97 additions and 134 deletions.
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ im-rc = { version = "15", optional = true }
[dependencies.gtk]
path = "../gtk4"
package = "gtk4"
features = ["v4_8"]
features = ["v4_10"]

# used by gif-paintable example
[dependencies.image]
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ fn build_ui(application: &gtk::Application) {

window.set_child(Some(&button));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/builder_pattern/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ fn build_ui(application: &Application) {

window.set_child(Some(&button));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/clipboard/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ fn build_ui(application: &gtk::Application) {
container.append(&texture_container);

window.set_child(Some(&container));
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/clock/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn build_ui(application: &Application) {

window.set_child(Some(&label));

window.show();
window.present();

// we are using a closure to capture the label (else we could also use a normal function)
let tick = move || {
Expand Down
2 changes: 1 addition & 1 deletion examples/column_view_datagrid/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ fn build_ui(application: &gtk::Application) {
scrolled_window.set_child(Some(&columnview));

window.set_child(Some(&scrolled_window));
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/composite_template/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> glib::ExitCode {

application.connect_activate(|app| {
let win = ExApplicationWindow::new(app);
win.show();
win.present();
});
application.run()
}
2 changes: 1 addition & 1 deletion examples/confetti_snapshot_animation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ fn build_ui(application: &gtk::Application) {
confetti.explode(params, duration);
});
confetti.add_controller(ev_ctrl);
window.show();
window.present();
}
15 changes: 6 additions & 9 deletions examples/css/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use gtk::prelude::*;

use gtk::gdk::Display;
use gtk::{
Application, ApplicationWindow, Box as Box_, Button, ComboBoxText, CssProvider, Entry,
Orientation, STYLE_PROVIDER_PRIORITY_APPLICATION,
Application, ApplicationWindow, Box as Box_, Button, CssProvider, DropDown, Entry, Orientation,
STYLE_PROVIDER_PRIORITY_APPLICATION,
};

fn main() -> glib::ExitCode {
Expand Down Expand Up @@ -42,19 +42,16 @@ fn build_ui(application: &Application) {
entry.add_css_class("entry1");
entry.set_text("Some text");

let combo = ComboBoxText::new();
combo.append_text("option 1");
combo.append_text("option 2");
combo.append_text("option 3");
combo.set_active(Some(0));
let model = gtk::StringList::new(&["option 1", "option 2", "option 3"]);
let drop_down = DropDown::new(Some(model), gtk::Expression::NONE);

vbox.append(&button);
vbox.append(&entry);
vbox.append(&combo);
vbox.append(&drop_down);
// Then we add the container inside our window.
window.set_child(Some(&vbox));

application.connect_activate(move |_| {
window.show();
window.present();
});
}
2 changes: 1 addition & 1 deletion examples/custom_application/ex_application/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl ApplicationImpl for ExApplication {
let label = gtk::Label::new(Some("Hello"));
label.add_css_class("title-2");
window.set_child(Some(&label));
window.show();
window.present();
}
}
impl GtkApplicationImpl for ExApplication {}
4 changes: 2 additions & 2 deletions examples/custom_buildable/custom_buildable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ impl CustomBuildable {
pub fn add_suffix<T: glib::IsA<gtk::Widget>>(&self, widget: &T) {
let imp = self.imp();
imp.suffixes.append(widget);
imp.suffixes.show();
imp.suffixes.set_visible(true);
}

pub fn add_prefix<T: glib::IsA<gtk::Widget>>(&self, widget: &T) {
let imp = self.imp();
imp.prefixes.append(widget);
imp.prefixes.show();
imp.prefixes.set_visible(true);
}
}
2 changes: 1 addition & 1 deletion examples/custom_buildable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ fn build_ui(application: &gtk::Application) {

let window: gtk::ApplicationWindow = builder.object("window").expect("Couldn't get window");
application.add_window(&window);
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/custom_editable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ fn build_ui(application: &gtk::Application) {

container.append(&horizontal_container);
window.set_child(Some(&container));
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/custom_layout_manager/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() -> glib::ExitCode {
}

window.set_child(Some(&widget));
window.show();
window.present();
});

application.run()
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_orientable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> glib::ExitCode {
bx.set_margin_end(18);

window.set_child(Some(&bx));
window.show();
window.present();
});

application.run()
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_paintable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ fn build_ui(application: &gtk::Application) {
picture.set_paintable(Some(&paintable));

window.set_child(Some(&picture));
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/custom_widget/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> glib::ExitCode {
button.set_margin_start(18);
button.set_margin_end(18);
window.set_child(Some(&button));
window.show();
window.present();
});

application.run()
Expand Down
21 changes: 8 additions & 13 deletions examples/dialog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,19 @@ fn build_ui(application: &gtk::Application) {
}

async fn dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
let question_dialog = gtk::MessageDialog::builder()
.transient_for(&*window)
let question_dialog = gtk::AlertDialog::builder()
.modal(true)
.buttons(gtk::ButtonsType::OkCancel)
.text("What is your answer?")
.buttons(["Cancel", "Ok"])
.message("What is your answer?")
.build();

let answer = question_dialog.run_future().await;
question_dialog.close();
let answer = question_dialog.choose_future(Some(&*window)).await;

let info_dialog = gtk::MessageDialog::builder()
.transient_for(&*window)
let info_dialog = gtk::AlertDialog::builder()
.modal(true)
.buttons(gtk::ButtonsType::Close)
.text("You answered")
.secondary_text(format!("Your answer: {answer:?}"))
.message("You answered")
.detail(format!("Your answer: {answer:?}"))
.build();

info_dialog.run_future().await;
info_dialog.close();
info_dialog.show(Some(&*window));
}
7 changes: 6 additions & 1 deletion examples/entry_completion/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// TODO - EntryCompletion is deprecated without replacement in GTK 4.10. This example should be
// updated to remove the deprecated code when a replacement lands.
// See: https://gitlab.gnome.org/GNOME/gtk/-/issues/5689
#![allow(deprecated)]

use gtk::glib;
use gtk::prelude::*;

Expand Down Expand Up @@ -73,7 +78,7 @@ fn build_ui(application: &Application) {
window.set_child(Some(&row));

// show everything
window.show();
window.present();
}

struct Data {
Expand Down
2 changes: 1 addition & 1 deletion examples/entry_undo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ fn build_ui(application: &gtk::Application) {

window.set_child(Some(&vbox));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/expressions/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn build_ui(app: &gtk::Application) {
.child(&scrolled_window)
.build();

window.show();
window.present();
}

fn data() -> gio::ListStore {
Expand Down
2 changes: 1 addition & 1 deletion examples/femtovg_area/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ fn build_ui(application: &gtk::Application) {
let widget = FemtoVGArea::default();
window.set_child(Some(&widget));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/flow_box/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn build_ui(app: &gtk::Application) {
.build();

window.set_child(Some(&scrolled_window));
window.show();
window.present();
}

fn create_color_button(color: &'static str) -> gtk::Button {
Expand Down
2 changes: 1 addition & 1 deletion examples/gif_paintable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> glib::ExitCode {

application.connect_activate(|app| {
let win = GifPaintableWindow::new(app);
win.show();
win.present();
});

application.run()
Expand Down
2 changes: 1 addition & 1 deletion examples/glium_gl_area/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ fn build_ui(application: &gtk::Application) {
let widget = GliumGLArea::new();
window.set_child(Some(&widget));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/grid_packing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ fn build_ui(application: &gtk::Application) {

grid.attach(&quit_button, 0, 1, 2, 1);

window.show();
window.present();
}
8 changes: 0 additions & 8 deletions examples/gtk_builder/gtk_builder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,4 @@
</object>
</child>
</object>
<object class="GtkMessageDialog" id="messagedialog">
<property name="transient-for">window</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="buttons">ok</property>
<property name="text" translatable="yes">Thank you for trying this example</property>
<property name="secondary-text" translatable="yes">You have pressed the button</property>
</object>
</interface>
23 changes: 11 additions & 12 deletions examples/gtk_builder/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Builder, Button, MessageDialog, ResponseType};
use gtk::{glib, Application, ApplicationWindow, Builder, Button};

fn main() -> glib::ExitCode {
let application = gtk::Application::new(
Expand All @@ -17,17 +17,16 @@ fn build_ui(application: &Application) {
let window: ApplicationWindow = builder.object("window").expect("Couldn't get window");
window.set_application(Some(application));
let bigbutton: Button = builder.object("button").expect("Couldn't get button");
let dialog: MessageDialog = builder
.object("messagedialog")
.expect("Couldn't get messagedialog");

dialog.connect_response(move |d: &MessageDialog, _: ResponseType| {
d.hide();
});
bigbutton.connect_clicked(glib::clone!(@weak window => move |_| {
gtk::AlertDialog::builder()
.modal(true)
.message("Thank you for trying this example")
.detail("You have pressed the button")
.buttons(["Ok"])
.build()
.show(Some(&window));
}));

bigbutton.connect_clicked(move |_| {
dialog.show();
});

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/list_box_model/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ fn build_ui(application: &gtk::Application) {
model.append(&RowData::new(&format!("Name {i}"), i * 10));
}

window.show();
window.present();
}
12 changes: 5 additions & 7 deletions examples/list_view_apps_launcher/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ fn build_ui(app: &gtk::Application) {
if let Err(err) = app_info.launch(&[], Some(&context)) {
let parent_window = list_view.root().and_downcast::<gtk::Window>().unwrap();

gtk::MessageDialog::builder()
.text(format!("Failed to start {}", app_info.name()))
.secondary_text(err.to_string())
.message_type(gtk::MessageType::Error)
gtk::AlertDialog::builder()
.message(format!("Failed to start {}", app_info.name()))
.detail(err.to_string())
.modal(true)
.transient_for(&parent_window)
.build()
.show();
.show(Some(&parent_window));
}
});

Expand All @@ -91,5 +89,5 @@ fn build_ui(app: &gtk::Application) {
.build();

window.set_child(Some(&scrolled_window));
window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/rotation_bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ fn build_ui(application: &gtk::Application) {

window.set_child(Some(&vbox));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/scale_bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> glib::ExitCode {
let window = gtk::ApplicationWindow::new(app);
let scale_bin = ScaleBin::new();
window.set_child(Some(&scale_bin));
window.show();
window.present();
});

application.run()
Expand Down
2 changes: 1 addition & 1 deletion examples/search_bar/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ fn build_ui(application: &gtk::Application) {
}
}));

window.show();
window.present();
}
2 changes: 1 addition & 1 deletion examples/squeezer_bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> glib::ExitCode {

window.set_titlebar(Some(&headerbar));
window.set_child(Some(&squeezer));
window.show();
window.present();
});

application.run()
Expand Down

0 comments on commit 03c4dcd

Please sign in to comment.