GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GtkCombobox with glade3

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Fri Aug 08, 2008 9:21 am    Post subject: GtkCombobox with glade3 Reply with quote

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,



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
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 374
Location: Slovenia

PostPosted: Fri Aug 08, 2008 10:11 am    Post subject: Re: GtkCombobox with glade3 Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* 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
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Mon Aug 11, 2008 7:12 am    Post subject: Reply with quote

Thank you for the answer !
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Tue Aug 12, 2008 12:20 pm    Post subject: Reply with quote

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
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 514
Location: Portland, OR USA

PostPosted: Tue Aug 12, 2008 4:18 pm    Post subject: Reply with quote

Check out gdk_pixbuf_rotate_simple() function.
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Wed Aug 13, 2008 9:24 am    Post subject: Reply with quote

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).
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Wed Aug 13, 2008 12:57 pm    Post subject: Reply with quote

Before rotate:



After 90° rotate:



Is it normal ?
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Tue Aug 19, 2008 1:15 pm    Post subject: Reply with quote

up
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 638
Location: Falun, WI USA

PostPosted: Tue Aug 19, 2008 5:02 pm    Post subject: Reply with quote

it looks normal to me. what do you think isn't normal?
Back to top
Dewey
Familiar Face


Joined: 08 Aug 2008
Posts: 8

PostPosted: Thu Aug 21, 2008 8:13 am    Post subject: Reply with quote

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
Back to top
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 201
Location: INDIA

PostPosted: Thu Aug 21, 2008 10:22 am    Post subject: Reply with quote

Micah Carrick wrote:
Check out gdk_pixbuf_rotate_simple() function.


can i have an example program for this
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 638
Location: Falun, WI USA

PostPosted: Thu Aug 21, 2008 3:47 pm    Post subject: Reply with quote

It's pretty straightforward, and you can find its documentation here:
http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-scaling.html#gdk-pixbuf-rotate-simple
but here's an example:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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;
}
Back to top
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 201
Location: INDIA

PostPosted: Fri Aug 22, 2008 3:51 am    Post subject: Reply with quote

thats great.
working fine.
can i add slide transition for the image and
can i give orientation to the window.
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 638
Location: Falun, WI USA

PostPosted: Fri Aug 22, 2008 4:06 am    Post subject: Reply with quote

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
http://gtkforums.com/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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP