|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="statusbar.c" xml:lang="es">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Statusbar (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#buttons"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.c"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="button.c"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-22" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Monica Kochofar</name>
|
|
Packit |
1470ea |
<email its:translate="no">monicakochofar@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Enviar mensajes de menor importancia al usuario</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Daniel Mustieles</mal:name>
|
|
Packit |
1470ea |
<mal:email>daniel.mustieles@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011 - 2017</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Nicolás Satragno</mal:name>
|
|
Packit |
1470ea |
<mal:email>nsatragno@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012 - 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Jorge González</mal:name>
|
|
Packit |
1470ea |
<mal:email>jorgegonz@svn.gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Statusbar</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/statusbar3.png"/>
|
|
Packit |
1470ea |
Esta barra de estado se usa para demostrar cómo se apilan los mensajes en un orden «último dentro, primero fuera». Siempre se muestra el mensaje en la parte superior de la pila.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Callback function in which pushes an item onto the statusbar*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
push_item (GtkWidget *widget,
|
|
Packit |
1470ea |
gpointer data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *status_bar = data;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create a context id, which is used to uniquely identify
|
|
Packit |
1470ea |
*the source of a message*/
|
|
Packit |
1470ea |
guint context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (status_bar),
|
|
Packit |
1470ea |
"Statusbar example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Count is used to keep track of the amount of items
|
|
Packit |
1470ea |
the user is pushing/popping*/
|
|
Packit |
1470ea |
static int count = 1;
|
|
Packit |
1470ea |
char hold_output[20];
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*This is a safer form of the standard sprintf () function. The output is
|
|
Packit |
1470ea |
guaranteed in this case to not exceed 20 characters, and the result is stored
|
|
Packit |
1470ea |
into the 'hold_output' variable*/
|
|
Packit |
1470ea |
g_snprintf (hold_output, 20, "Item %d", count++);
|
|
Packit |
1470ea |
gtk_statusbar_push (GTK_STATUSBAR (status_bar),
|
|
Packit |
1470ea |
context_id,
|
|
Packit |
1470ea |
hold_output);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Callback function that is used to pop an item off the statusbar*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
pop_item (GtkWidget *widget,
|
|
Packit |
1470ea |
gpointer data )
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *status_bar = data;
|
|
Packit |
1470ea |
guint context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (status_bar),
|
|
Packit |
1470ea |
"Statusbar example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_statusbar_pop (GTK_STATUSBAR (status_bar), context_id);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *grid;
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *status_bar;
|
|
Packit |
1470ea |
GtkWidget *pop_button;
|
|
Packit |
1470ea |
GtkWidget *push_button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create a window with a title, border width, and a default size**/
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 220, 100);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "Statusbar Example");
|
|
Packit |
1470ea |
gtk_container_set_border_width (GTK_CONTAINER(window), 10);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create the status bar, which is held in the global variable*/
|
|
Packit |
1470ea |
status_bar = gtk_statusbar_new ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create the buttons with labels*/
|
|
Packit |
1470ea |
push_button = gtk_button_new_with_label ("push item");
|
|
Packit |
1470ea |
pop_button = gtk_button_new_with_label ("pop last item");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create the grid, and attach the buttons/statusbar accordingly*/
|
|
Packit |
1470ea |
grid = gtk_grid_new ();
|
|
Packit |
1470ea |
gtk_grid_attach (GTK_GRID (grid), push_button, 0,1,1,1);
|
|
Packit |
1470ea |
gtk_grid_attach (GTK_GRID (grid), pop_button, 0,2,1,1);
|
|
Packit |
1470ea |
gtk_grid_attach (GTK_GRID (grid), status_bar, 0,3,1,1);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Connecting the clicked signals to the corresponding callback functions*/
|
|
Packit |
1470ea |
g_signal_connect (GTK_BUTTON (push_button), "clicked",
|
|
Packit |
1470ea |
G_CALLBACK (push_item), status_bar);
|
|
Packit |
1470ea |
g_signal_connect (GTK_BUTTON (pop_button), "clicked",
|
|
Packit |
1470ea |
G_CALLBACK (pop_item), status_bar);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Attach the grid holding the child widgets onto the window, and show all*/
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), grid);
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
En este ejemplo se usa lo siguiente:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkStatusbar.html">GtkStatusBar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-snprintf">Funciones de cadenas útiles</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkGrid.html">GtkGrid</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|