Howto make GtkRadiobutton text flicker (was: Re: I have a problem with GtkRadioButton)



yeajchao wrote:

However, the need for some applications to use fixed colours like
green, yellow and red to indicate things like error-free results,
warnings, error messages or critical choices / operations is
recognized. That's why you can rather easily change colours and
appearances of texts on screen. See the following URL for an
overview of how to change text appearances of markup-enabled widgets
even easier than tweaking themes:

    First,thank you very much for your advice
    As you say, I want to use the radio button as a alarm,
    Usually,alarm's color is red
    My application controls some peripheral instrument,
       when my application detected some one broken down
       the alarm will be flicker with red color

    I am a beginer of gtk, also beginer of program,so I have no other
    idea to    resolve the problem
    Will you be so kind as to give some advice ?

First: you really should forget about manually recolouring the knobs of
radiobuttons, checkboxes and other controls. Recolouring just texts is
sufficient for this purpose and can be accomplished almost easily.

To make text(s) in dialogs flicker there are about four steps to be
taken. I assume you have your standard GtkRadiobutton* (the one to be
recoloured) within reach. In this example I will call it "rb_flicker":

1. learn about Pango's simple markup to apply custom colours (and other
   styles) to labels. See:
   http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html

2. obtain the GtkLabel that is (usually) associated with a
   GtkRadiobutton. The simpliest way to get it is about this:
   label_flicker = gtk_bin_get_child (GTK_BIN (rb_flicker));
   See:
   http://developer.gnome.org/doc/API/2.0/gtk/GtkBin.html#gtk-bin-get-child

3. use gtk_label_set_markup() to change the appearance of the label
   once, something like this:
   gtk_label_set_markup (label_flicker, "<span foreground=\"red\">This is critical</span>");
   See:
   http://developer.gnome.org/doc/API/2.0/gtk/GtkLabel.html#gtk-label-set-markup

4. to actually achieve a flicker effect (periodically changing appearance)
   you manually have to change the markup text of the label periodically.
   There are no automatic means to achieve any sort of animation in GTK+.
   Use one of gtk_timeout_add() or g_timeout_add() to register a simple
   function which periodically switches between two (or more) states of
   the label, like
   1. "<span foreground=\"red\">This is critical</span>" and
   2. "This is critical".
   This switches between red and default colour of the text.
   Upon registration, this simple markup changer function should receive
   the GtkLabel of the GtkRadiobutton as its data, like this:
   gtk_timeout_add (500, func_flicker, label_flicker);
   See:
   http://developer.gnome.org/doc/API/2.0/gtk/gtk-General.html#gtk-timeout-add
   http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-timeout-add

Notes:
Step 2, as described here, assumes you are using a simple radiobutton,
that is, a GtkRadiobutton with exactly one GtkLabel attached to it. GTK+
also supports more complex radiobuttons which have containers and
multiple children, i.e. images, attached to them, instead of just a
simple GtkLabel. In that case locating the GtkLabel would require some
more efforts.

Step 4: it is up to you to take care to stop the periodically called
timeout function. For instance, when the dialog that contains the
flickering radiobutton gets destroyed, the flicker function MUST NOT
continue to try changing the appearance of the radiobutton's label any
more. Removal of your timeout fucntion does not happen automatically!

After all I'd like to repeat: you shouldn't play with the appearance of
GTK+ widgets in a custom, non-themable way unless absolutely required!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]