Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

9.8 Statusbars

  Statusbars are simple widgets used to display a text message. They keep a stack of the messages pushed onto them, so that popping the current message will re-display the previous text message.

  In order to allow different parts of an application to use the same statusbar to display messages, the statusbar widget issues Context Identifiers which are used to identify different "users". The message on top of the stack is the one displayed, no matter what context it is in. Messages are stacked in last-in-first-out order, not context identifier order.

  A statusbar is created with a call to:


GtkWidget *gtk_statusbar_new( void );

  A new Context Identifier is requested using a call to the following function with a short textual description of the context:


guint gtk_statusbar_get_context_id( GtkStatusbar *statusbar,
const gchar*context_description );

  There are three functions that can operate on statusbars:


guint gtk_statusbar_push( GtkStatusbar *statusbar,
guint context_id,gchar*text );
void gtk_statusbar_pop( GtkStatusbar *statusbar)
guint context_id );
void gtk_statusbar_remove( GtkStatusbar *statusbar,
guint context_id,guint message_id ); 

  The first, gtk_statusbar_push, is used to add a new message to the statusbar. It returns a Message Identifier, which can be passed later to the function gtk_statusbar_remove to remove the message with the given Message and Context Identifiers from the statusbar's stack.

  The function gtk_statusbar_pop removes the message highest in the stack with the given Context Identifier.

  The following example creates a statusbar and two buttons, one for pushing items onto the statusbar, and one for popping the last item back off.


/* example-start statusbar statusbar.c */
#include <gtk/gtk.h>
#include <glib.h>
GtkWidget *status_bar;
void push_item( GtkWidget *widget,gpointer data )
{
static int count = 1;
char buff[20];
g_snprintf(buff, 20, "Item %d", count++);
gtk_statusbar_push( GTK_STATUSBAR(status_bar), GPOINTER_TO_INT(data), buff);
return;
}
void pop_item( GtkWidget *widget,gpointer data )
{
gtk_statusbar_pop( GTK_STATUSBAR(status_bar), GPOINTER_TO_INT(data) );
return;
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
gint context_id;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
gtk_window_set_title(GTK_WINDOW (window), "GTK Statusbar Example");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
status_bar = gtk_statusbar_new();
gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
gtk_widget_show (status_bar);
context_id = gtk_statusbar_get_context_id(
GTK_STATUSBAR(status_bar), "Statusbar example");
button = gtk_button_new_with_label("push item");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (push_item), GINT_TO_POINTER(context_id) );
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 2);
gtk_widget_show(button);
button = gtk_button_new_with_label("pop last item");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (pop_item), GINT_TO_POINTER(context_id) );
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 2);
gtk_widget_show(button);
/* always display the window as the last step so it all splashes on
 * the screen at once. */
gtk_widget_show(window);
gtk_main ();
return 0;
}
/* example-end */

9.9 Text Entries

  The Entry widget allows text to be typed and displayed in a single line text box. The text may be set with function calls that allow new text to replace, prepend or append the current contents of the Entry widget.

  There are two functions for creating Entry widgets:


GtkWidget *gtk_entry_new( void );
GtkWidget *gtk_entry_new_with_max_length( guint16 max );

  The first just creates a new Entry widget, whilst the second creates a new Entry and sets a limit on the length of the text within the Entry.

  There are several functions for altering the text which is currently within the Entry widget.

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页 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 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 下一页


上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
·Motorola微处理器bootloader分析与应用
·Fedora Core5 NFS服务器搭建过程介绍
·Linux系统:让内存不再泄漏的实用技巧
·新手看招 手把手教你安装VMware虚拟机
·“侵权事件” 红帽称微软企图干扰用户
·删除Linux后 如何找回Windows启动菜单
·菜鸟乐园 Linux中常见文件系统格式介绍
·Linux操作系统下IPTables配置方法详解
·实用技巧 Linux系统的经典使用技巧八则
·Linux系统文件优化及磁盘检查方法介绍
推荐文章
·Linux技巧:bz2文件如何解压缩
·用MRTG检测Linux网络性能
·红帽宣布开放JBoss中核心系统管理软
·如何设定与维持准确的电脑时钟
·Linux系统中找出并解决程序错误方法
·在Linux下成功运行最新的QQ和MSN
·如何重新规划分割区
·Webmin---Linux下的用户管理工具
精彩文章
·起步走 二十五步跟我搞定Linux系统
·几个JSP应用模板
·浅析:从xml生成Java类
·Linux下ip隧道研究(1)
·CORBA及MICO简介
·用Linux防火墙构建DMZ
·linux汉化大全(六)
·用Java Mail API查看邮件
·在Linux Shell程序中进行身份验证
·Linux指令大全(2)
·rootkit综述
·在linux7.1上安装jdk+tomcat+orac
·Linux御敌策略谈
·巧用KDE
·Linux 网管 123 --- 第8章. 备份及
·Socket建立连接的过程
·Linux命令Man解释:ftpaccess(5) :ft
·和luster一起学习系统调用(3)
·文件系统安全--EXT2文件系统的属性
·打造完美Linux系统:疑难杂症的解决
·Bean管理持续化实例
·Linux 每次启动时钟日期就多了 8 小
·基于Linux的Web服务器性能测试
·JDK开发工具包(三)
·Linux平台C++类库tinycxx使用说明
·和luster一起学习java编程(4)
Power by linux-cn.com 粤ICP备05006655号