This commit is contained in:
lakinduakash 2019-03-05 11:02:22 +05:30
parent 81f64ec78f
commit cf2f508491

View File

@ -7,40 +7,49 @@ print_hello (GtkWidget *widget,
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
static void print_hello2 (GtkWidget *widget,
gpointer data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), button_box);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_container_add (GTK_CONTAINER (button_box), button);
gtk_widget_show_all (window);
g_print ("Hello World 2\n");
}
int
main (int argc,
char **argv)
char *argv[])
{
GtkApplication *app;
int status;
GtkBuilder *builder;
GObject *window;
GObject *button;
GError *error = NULL;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
gtk_init (&argc, &argv);
return status;
/* Construct a GtkBuilder instance and load our UI description */
builder = gtk_builder_new ();
if (gtk_builder_add_from_file (builder, "glade/main.ui", &error) == 0)
{
g_printerr ("Error loading file: %s\n", error->message);
g_clear_error (&error);
return 1;
}
/* Connect signal handlers to the constructed widgets. */
window = gtk_builder_get_object (builder, "window");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
button = gtk_builder_get_object (builder, "button1");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
button = gtk_builder_get_object (builder, "button_new");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello2), NULL);
button = gtk_builder_get_object (builder, "quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_main ();
return 0;
}