Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <gtk/gtk.h>
- #define MAXTEST 100000000
- typedef struct WidgetBank
- {
- GtkWidget *window;
- GtkWidget *fixedspace;
- GtkWidget *button;
- GtkWidget *PrimeToFind;
- GtkWidget *readoutCount;
- GtkWidget *readoutPrime;
- GtkEntryBuffer *PrimeToFindBuffer;
- } Widgets;
- int isitprime(unsigned long int index);
- static void destroy (GtkWidget *window, gpointer data)
- {
- gtk_main_quit ();
- }
- //callback function that starts prime finder and updates labels in main window
- static void FindNthPrime (GtkWidget *button, gpointer data)
- {
- Widgets *widgets = data;
- char *PrimeToFind = gtk_entry_buffer_get_text(widgets->PrimeToFindBuffer);
- //gtk_label_set_text((GtkLabel *)widgets->readoutCount, PrimeToFind);
- //g_print("%s\n", PrimeToFind);
- }
- int main (int argc, char *argv[])
- {
- //GtkWidget *window, *fixedspace, *button, *readoutCount, *readoutPrime;
- gtk_init (&argc, &argv);
- Widgets PE7_Widgets;
- //Set up widget pointers
- PE7_Widgets.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- PE7_Widgets.fixedspace = gtk_fixed_new();
- PE7_Widgets.button = gtk_button_new_with_label("Start");
- PE7_Widgets.readoutCount = gtk_label_new("Primes Found: 0");
- PE7_Widgets.readoutPrime = gtk_label_new("Current Prime: 0");
- PE7_Widgets.PrimeToFindBuffer = gtk_entry_buffer_new(NULL, -1);
- PE7_Widgets.PrimeToFind = gtk_entry_new_with_buffer(PE7_Widgets.PrimeToFindBuffer);
- //pack and set up locations
- gtk_container_add(GTK_CONTAINER (PE7_Widgets.window), PE7_Widgets.fixedspace);
- gtk_fixed_put((GtkFixed *)PE7_Widgets.fixedspace, PE7_Widgets.button, 0, 0);
- gtk_fixed_put((GtkFixed *)PE7_Widgets.fixedspace, PE7_Widgets.readoutCount, 0, 30);
- gtk_fixed_put((GtkFixed *)PE7_Widgets.fixedspace, PE7_Widgets.readoutPrime, 0, 50);
- gtk_fixed_put((GtkFixed *)PE7_Widgets.fixedspace, PE7_Widgets.PrimeToFind, 45, 0);
- //connect signals for closing main window and the button
- g_signal_connect (G_OBJECT (PE7_Widgets.window), "destroy", G_CALLBACK (destroy), NULL);
- g_signal_connect (G_OBJECT (PE7_Widgets.button), "clicked", G_CALLBACK (FindNthPrime), &PE7_Widgets);
- //display and wait
- gtk_widget_show_all(PE7_Widgets.window);
- gtk_main ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement