On 1 March 2011 08:20, Miroslav Rajcic <raj...@sokrates.hr> wrote: > I am trying to make the "Pause" button flash (or show any similar behaviour > similar to that) when the pause state is active. > So far I tried many things, but none of these seem to work: > - changing the button background color > - changing the button stock icon
Alternating between two different stock items is quite easy when you know how, but I had to ask here for help. If you have two images, --8<--- img1 = gtk_image_new_from_stock( GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_SMALL_TOOLBAR); img2 = gtk_image_new_from_stock( GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_SMALL_TOOLBAR); /* convert img1 and img2 from floating references which are deleted when no longer in use, to a normal reference. this prevents either of the images being deleted when we swap the play/stop button images. unref'd after gtk_main. */ g_object_ref_sink(img1); g_object_ref_sink(img2); --8<--- then in your idle callback simply use gtk_button_set_image, alternating between the two images every time the function is called (ie you could use a static gboolean to track which button to show each time). then once gtk_main returns: --8<--- gtk_main(); /* free the play & stop images */ g_object_unref(img1); g_object_unref(img2); --8<--- http://github.com/jwm-art-net/BoxySeq/blob/master/boxyseq_gui/gui_main.c > - changing the button relief style > > Relevant code is following: > > //start timer to alternate the button state > nBlinkButtonTimerID = g_timeout_add (900, flash_pause_button_timer, NULL); > > gboolean flash_pause_button_timer(gpointer data) > { > static bool bFlipFlop = false; > bFlipFlop = !bFlipFlop; > > //get pointers to the relevant buttons > GtkToolbar *toolbar2 = (GtkToolbar *)lookup_widget(window1, "toolbar2"); > GtkWidget *tool_pause = (GtkWidget *)gtk_toolbar_get_nth_item(toolbar2, 2); > GList *children1 = gtk_container_get_children(GTK_CONTAINER(tool_pause)); > GtkButton *button = (GtkButton *)g_list_nth_data (children1, 0); > g_list_free(children1); > GtkWidget *tool_stop = (GtkWidget *)gtk_toolbar_get_nth_item(toolbar2, 1); > > //create two alternating colors (standard bkg and black bkg) > GtkStyle* style = gtk_rc_get_style(tool_stop); > GdkColor rgbStart = style->bg[GTK_STATE_NORMAL]; > GdkColor rgbEnd = { 0, 0, 0, 0 }; > > //modify color > gtk_widget_modify_bg (GTK_WIDGET(button), GTK_STATE_NORMAL, (bFlipFlop)? > &rgbEnd : &rgbStart); > gtk_widget_modify_bg (GTK_WIDGET(button), GTK_STATE_ACTIVE, (bFlipFlop)? > &rgbEnd : &rgbStart); > gtk_widget_modify_base (GTK_WIDGET(button), GTK_STATE_NORMAL, (bFlipFlop)? > &rgbEnd : &rgbStart); > gtk_widget_modify_base (GTK_WIDGET(button), GTK_STATE_ACTIVE, (bFlipFlop)? > &rgbEnd : &rgbStart); > gtk_widget_queue_draw (GTK_WIDGET(button)); > #if GTK_CHECK_VERSION(2,18,0) > gdk_window_process_updates (gtk_widget_get_window(GTK_WIDGET(button)), > TRUE); > #else > gdk_window_process_updates (GTK_WIDGET(button)->window, TRUE); > #endif > > /* > GtkWidget *w1 = > gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(tool_pause)); > gtk_widget_modify_bg (w1, GTK_STATE_NORMAL, (bFlipFlop)? &rgbEnd : > &rgbStart); > gtk_widget_modify_bg (w1, GTK_STATE_ACTIVE, (bFlipFlop)? &rgbEnd : > &rgbStart); > gtk_widget_modify_base (w1, GTK_STATE_NORMAL, (bFlipFlop)? &rgbEnd : > &rgbStart); > gtk_widget_modify_base (w1, GTK_STATE_ACTIVE, (bFlipFlop)? &rgbEnd : > &rgbStart); > */ > > //modify relief style > gtk_button_set_relief(button, (bFlipFlop)? > GTK_RELIEF_NORMAL:GTK_RELIEF_NONE); > > //modify stock icon > gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(tool_pause), (bFlipFlop)? > GTK_STOCK_MEDIA_PAUSE : GTK_STOCK_MEDIA_RECORD); > > gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM(tool_pause)); > > return TRUE; > } > > Why doesn't any of these work ? Any tips ? > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > -- _ : http://jwm-art.net/ -audio/image/text/code/ _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list