GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 01, 2014 3:42 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: GtkCombobox with glade3
PostPosted: Fri Aug 08, 2008 9:21 am 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
Hello, for my computer science training (I'm French sorry for my English), I need to create an simple interface to use a professional scanner (Approximately interface like Gnome-Scan). For that my partner an I use Glade3 for the interface and Sane api for the scanner.
But I have some problems so some questions :
Let see the interface I create with glade,

Image

So I have 7 Comboboxes on the left, first question :

When I click on "Numériser" I want have in a structure, all the choice (option for scan) there is in Combobox to send to my scan function.

Other question:

How can I send parameters to a function called by glade (I put the name of the function in SIGNAL but I don't know where put the parameters) ?

Last question:

How can I put a default choice (I want put the first one) in my Comboboxes when my interface appear ?

Thanks a lot.

Edit: I'm programming in C.


Last edited by Dewey on Fri Aug 08, 2008 1:56 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: GtkCombobox with glade3
PostPosted: Fri Aug 08, 2008 10:11 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello

Dewey wrote:
When I click on "Numériser" I want have in a structure with all the choice (option for scan) there is in Combobox to send to my scan function.

Usually, when I need to track the selection of the combo boxes, I create structure inside main function and then update it from combo callback. When I need all the options, selected inside combos, I simply take my structure and I'm done.

Example:
Code:
/* structure definition */
typedef struct
{
    char *combo1;
    char *combo2;
    char *combo3;
} SOptions;


int
main( int    argc,
      char **argv )
{
    GtkWidget *combo;
    SOptions   options;
   
    /* create widgets here */
   
    g_signal_connect( G_OBJECT( combo ), 'changed',
                      G_CALLBACK( cb_changed ),
                      (gpointer)options.combo1 );
   
    /* do other suff here */
    return( 0);
}

void
cb_changed ( GtkComboBox *combo,
             gpointer     option )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
   
    /* free any previous options */
    if( option ) {
        gfree( option );
    }
   
    /* call this if your combo box is created with model */
    gtk_combo_box_get_model( combo, model );
    gtk_combo_box_get_active_iter( combo, &iter );
    gtk_tree_model_get( model, &iter, 0, &option, -1 );
   
    /* call this if your combo box is created with text */
    option = gtk_combo_box_get_active_text( combo );
}


Dewey wrote:
How can I send parameters to a function called by glade (I put the name of the function in SIGNAL but I don't know where put the parameters) ?

Since I don't use Glade, I won't be much of a help here. Sorry.

Dewey wrote:
How can I put a default choice (I want put the first one) in my Comboboxes when my interface appear ?

I would simply call gtk_combo_box_set_active() function. And if you have connected combo box callback before this call, your options struct will also get updated.

Hope it helps you a bit.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 7:12 am 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
Thank you for the answer !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 12, 2008 12:20 pm 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
New question :
I put an image in a gtkwindow and I want to rotate it with 2 buttons (right and left rotate).
Is it possible ?
If yes, which way ?
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 12, 2008 4:18 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Check out gdk_pixbuf_rotate_simple() function.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 9:24 am 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
Micah Carrick wrote:
Check out gdk_pixbuf_rotate_simple() function.

I found that this morning before see your message, thank you Micah.
It works good, but now my problem is to replace the old image bye the new (the rotate image).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 12:57 pm 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
Before rotate:

Image

After 90° rotate:

Image

Is it normal ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 1:15 pm 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
up


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 5:02 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
it looks normal to me. what do you think isn't normal?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:13 am 
Offline
Familiar Face

Joined: Fri Aug 08, 2008 9:04 am
Posts: 8
dreblen wrote:
it looks normal to me. what do you think isn't normal?

In fact, when I rotate by 90°, the height of the image seems to be modify (more long).
But I find the solution/ the screen resolution -_-
THanks a lot fot this topic, bye


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 10:22 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
Micah Carrick wrote:
Check out gdk_pixbuf_rotate_simple() function.


can i have an example program for this


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 3:47 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
It's pretty straightforward, and you can find its documentation here:
http://library.gnome.org/devel/gdk-pixb ... ate-simple
but here's an example:
Code:
#include <gtk/gtk.h>

static const struct
{
   gchar *name;
   gchar *pattern;
} chooser_filters[] = {
   { "All Files (*)", "*" },
   { "PNG Files (*.png)", "*.png" },
   { "JPEG Files (*.jpg)", "*.jpg" },
   { "BMP Files (*.bmp)", "*.bmp" },
};

void file_set_cb(GtkFileChooserButton *but, GtkImage *im)
{
   gchar *filename;

   filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(but));

   gtk_image_set_from_file(im, filename);
}

void rot_left(GtkWidget *but, GtkImage *im)
{
   GdkPixbuf *pbuf;

   pbuf = gtk_image_get_pixbuf(im);
   if(pbuf == NULL)
      return;

   pbuf = gdk_pixbuf_rotate_simple(pbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);

   gtk_image_set_from_pixbuf(im, pbuf);
}

void rot_right(GtkWidget *but, GtkImage *im)
{
   GdkPixbuf *pbuf;

   pbuf = gtk_image_get_pixbuf(im);
   if(pbuf == NULL)
      return;

   pbuf = gdk_pixbuf_rotate_simple(pbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);

   gtk_image_set_from_pixbuf(im, pbuf);
}

int main(int argc, char **argv)
{
   GtkWidget *win;
   GtkWidget *vbox;
   GtkWidget *button;
   GtkWidget *swin;
   GtkWidget *image;
   GtkWidget *hbox;

   GtkFileFilter *fil;
   gint i;

   gtk_init(&argc, &argv);

   win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);

   vbox = gtk_vbox_new(FALSE, 5);
   gtk_container_add(GTK_CONTAINER(win), vbox);
   gtk_widget_show(vbox);

   button = gtk_file_chooser_button_new("Select File", GTK_FILE_CHOOSER_ACTION_OPEN);
   gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
   gtk_widget_show(button);
   for(i = 0; i < G_N_ELEMENTS(chooser_filters); i++)
   {
      fil = gtk_file_filter_new();
      gtk_file_filter_set_name(fil, chooser_filters[i].name);
      gtk_file_filter_add_pattern(fil, chooser_filters[i].pattern);
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(button), fil);
   }

   swin = gtk_scrolled_window_new(NULL, NULL);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
   gtk_widget_show(swin);

   image = gtk_image_new();
   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), image);
   gtk_widget_show(image);

   /* connect "file-set" of button now that we have image */
   g_signal_connect(G_OBJECT(button), "file-set", G_CALLBACK(file_set_cb), (gpointer)image);

   hbox = gtk_hbox_new(TRUE, 2);
   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
   gtk_widget_show(hbox);

   button = gtk_button_new_with_label("Rotate Left");
   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(rot_left), (gpointer)image);
   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
   gtk_widget_show(button);

   button = gtk_button_new_with_label("Rotate Right");
   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(rot_right), (gpointer)image);
   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
   gtk_widget_show(button);

   gtk_widget_show(win);

   gtk_main();

   return 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 3:51 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
thats great.
working fine.
can i add slide transition for the image and
can i give orientation to the window.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 4:06 am 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
I would politely suggest that you start your own thread if you have more questions,
seeing as how they aren't really relating to the OP anymore.

Anyways, regarding question 1:
you've already started a thread (which I've answered) on this subject
viewtopic.php?t=1640
question 2:
what do you mean by orientation? do you mean rotate the window?
if so, then I believe that the answer is no because that would be something handled by the window manager


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group