Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

gtk

If it's not on-topic, it's in here.

gtk

Postby nadir » Sun Feb 17, 2013 11:38 am

While fooling a bit with codeblocks, which i don't like much, i figured i could check gui-apps, for the lulz.
It didn't take long and i exited codeblocks and was doing gtk-coding for an hour or two.

I only found this how-to:
http://developer.gnome.org/gtk-tutorial/2.22/
which is way too fast, for my taste.
If i find a better how-to i might do this for a while.

I fool around a lot, these days. gdb too. valgrind. and, like said, codeblocks
By that i run into problems. Say "gcc easy-gtk.c" didn't work. I searched the WisdomWarningsWorkarounds, and found that i have to use "gcc easy-gtk $(pkg-config gtk+-2.0 --cflags) $(pkg-config gtk+-2.0 --libs)" to make it find <gtk/gtk.h>, which, for unknown reasons, is in /usr/include/gtk-2.0.

If my math is right, i still miss 9500 hours to be a badass coder ... :-) (but for the same time the grim reaper has announced a whistle-stop. Oh my! )
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1159
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: gtk

Postby nadir » Wed Feb 27, 2013 11:53 pm

Today i made a step in the rigtht direction:
I used a vertical_box and packed horizontal boxes inside of it.
Also was able to create a separator and a button "quit" which closes the window.

That won't make the wizards scream, but i am ok with it.
All that padding and filling is beyond me (and probably ever will be).
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>


static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
   gtk_main_quit();
   return FALSE;
}


int main(int argc, char *argv[])
{
   GtkWidget *window;
   GtkWidget *vbox;
   GtkWidget *hbox;
   GtkWidget *button;
   GtkWidget *separator;

   gtk_init(&argc, &argv);

   /*----------------------------------------*/
   /* window */
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    
   g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL);
   gtk_widget_show(window);


   /*----------------------------------------*/
   /* vertical box */
   vbox = gtk_vbox_new(FALSE, 0);
   gtk_widget_show(vbox);


   /*----------------------------------------*/
   /* first horizontal box */
   hbox = gtk_hbox_new(FALSE, 0);
   gtk_widget_show(hbox);
   button = gtk_button_new_with_label("mount");
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
   gtk_widget_show(button);
   
   button = gtk_button_new_with_label("fdisk");
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
   gtk_widget_show(button);


   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

   /*----------------------------------------*/
   /* separator */
   separator = gtk_hseparator_new();
   gtk_widget_set_size_request(separator, 400, 5);
   gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 5);
   gtk_widget_show(separator);    
   
   /*----------------------------------------*/
   /* second horizontal box */
   hbox = gtk_hbox_new(TRUE, 50);
   gtk_widget_show(hbox);
   button = gtk_button_new_with_label("cat");
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
   gtk_widget_show(button);

   button = gtk_button_new_with_label("less");
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
   gtk_widget_show(button);

   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
   
      
   /*----------------------------------------*/
   /* separator */
   separator = gtk_hseparator_new();
   gtk_widget_set_size_request(separator, 400, 5);
   gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 5);
   gtk_widget_show(separator);
   
   /*----------------------------------------*/
   /* quit box */
   hbox = gtk_hbox_new(FALSE, 0);
   gtk_widget_show(hbox);
   button = gtk_button_new_with_label("quit");
   g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_main_quit), window);
   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 50);    
   gtk_widget_show(button);

   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

   /*----------------------------------------*/
   /* adding vbox to container window */
   gtk_container_add(GTK_CONTAINER(window), vbox);



   /*----------------------------------------*/
   gtk_main();


   /*----------------------------------------*/
   return EXIT_SUCCESS;
}

* in C is a lot. Here it is a pointer (not multiplicate and not dereferencing).
& is the address of a variable. If a function expects a pointer, and you got a variable, say int i = 42, you can use &i to give the function what it asks for. You could also do: int *j; j = &i; and then offer j to the function. Confusing? Yes.
Both can be ignored to understand what is getting done.

Ups: Just in case,
to compile it you will need "libgtk2.0-dev" and
gcc name_of.c $(pkg-config gtk+-2.0 --cflags) $(pkg-config gtk+-2.0 --libs)
Then click on "quit" and foo, it closes. A miracle.
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1159
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: gtk

Postby nadir » Thu Feb 28, 2013 12:43 am

Not sure why i posted the above.
Perhaps because packing horizontal boxes in vertical boxes
was quite hard to understand.
But the window doesn't do anything.
Thinking about it i can think of two things:
a) if i click on "mount" or "fdisk" i can see the output of said
commands (seeing it on the command line after clicking is not hard,
i mean inside the window or in a new window).
b) being able to enter text inside a window (similar but much easier than an
editor or a notekeeper).
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1159
Joined: Wed Mar 09, 2011 4:18 am
Location: here


Return to General Nonsense

Who is online

Users browsing this forum: No registered users and 0 guests

suspicion-preferred