| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- MODULE builder ;
- (*
- m2-GTK4 example - building a window from a .ui file with GtkBuilder.
- Loads examples/builder.ui (object ids: window, button, status), wires
- the button's "clicked" signal to update the status label, and shows
- the window.
- Build: make examples
- Run: ./build/examples/builder (from the repository root)
- *)
- FROM Gio IMPORT g_application_run;
- FROM GtkApplication IMPORT gtk_application_new;
- FROM GtkBuilder IMPORT GtkBuilder, gtk_builder_new, gtk_builder_add_from_file,
- gtk_builder_get_object;
- FROM GtkWindow IMPORT gtk_window_set_application, gtk_window_present;
- FROM GtkLabel IMPORT gtk_label_set_text;
- FROM GError IMPORT GError;
- FROM GtkClosures IMPORT Connect2;
- FROM GtkUtils IMPORT ErrorMessage, ClearError;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.Builder";
- VAR
- builder: ADDRESS;
- PROCEDURE OnClicked (button: ADDRESS; user: ADDRESS);
- BEGIN
- gtk_label_set_text(user, "Button clicked!")
- END OnClicked;
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, button, status: ADDRESS;
- err: GError;
- buf: ARRAY [0..255] OF CHAR;
- BEGIN
- builder := gtk_builder_new();
- err := NIL;
- IF gtk_builder_add_from_file(builder, "examples/builder.ui", err) = 0 THEN
- ErrorMessage(err, buf);
- printf("failed to load examples/builder.ui: %s\n", buf);
- printf("(run this example from the repository root)\n");
- ClearError(err);
- HALT(1)
- END;
- window := gtk_builder_get_object(builder, "window");
- button := gtk_builder_get_object(builder, "button");
- status := gtk_builder_get_object(builder, "status");
- Connect2(button, "clicked", OnClicked, status);
- gtk_window_set_application(window, application);
- gtk_window_present(window)
- END OnActivate;
- VAR
- app: ADDRESS;
- BEGIN
- app := gtk_application_new(AppId, 0);
- IF app = NIL THEN
- printf("gtk_application_new failed\n");
- HALT(1)
- END;
- Connect2(app, "activate", OnActivate, NIL);
- g_application_run(app, 0, NIL)
- END builder.
|