做了个工具条,每次点arrow出来的菜单都没图标,郁闷;查来查去,看源码,看css,最后知道GtkAction缺省就是对应GtkImageMenuItem,再一试,跟toolbar无关,换menu也不显示图,查css设置看各种主题也没找到不显示图的规则;去切换主题的高级设置一看,靠,原来这里指定了不显示菜单图标。

/usr/share/themes/Adwaita#

http://superuser.com/questions/656595/how-do-i-install-themes-for-gnome3-in-debian-7

http://worldofgnome.org/making-gtk3-themes-part-4-porting-gtk2-themes/

对gtkApplication的功用一致不甚了解,

http://blog.m8t.in/2013/03/moving-from-unique-to-gtkapplication.html

GTK+ 3 在紧锣密鼓的开发之中,虽然说 3.0 版本相对于 GTK+ 2 在编程方面的改变并不大,不过仍然有些改变是和 GTK+ 使用者密切相关的,比如新加入的 GtkApplication 类。

大家知道开始学习 GTK+ 的一个难点就是莫名其妙的 gtk_init()、gtk_main(),以及 quit、destroy 等信号的区别之类的,简单来说,一个 Hello World 程序的构建过程很让人困惑,感觉就像记住了一个模板,每次都要写一次。

GTK+ 3 为了解决这个问题,抽象出了 GtkApplication 这个类,那么一切都变得容易理解起来:gtk_init() 就是 GtkApplication 的构造函数,现在只需要调用 gtk_application_new() 就可以,gtk_main() 现在变成了 gtk_application_run(),意义很明显,而程序的退出也只需要连接 GtkApplication 类的 quit 信号即可。

GtkApplication 默认自带一个 GtkWindow,可以通过 gtk_application_get_window() 获得,因此一个新的 Hello World 看起来可能是这样:

#include <gtk/gtk.h>
int main (int argc, char **argv)
{
GtkApplication *app;
GtkWindow *window;app = gtk_application_new ("org.gtk.Example", &argc, &argv);
window = gtk_application_get_window (app);
gtk_container_add (GTK_CONTAINER (window), gtk_label_new ("Hello world"));
gtk_widget_show_all (GTK_WIDGET (window));
gtk_application_run (app);
return 0;
}

怎么样,是不是简单明了得多?

http://www.kissuki.com/blog/2009/01/06/linux-i18n/

对于国际化程序的编写,终端程序和图形界面程序是不同的,但是后期的翻译步骤是一致的。

终端程序只有gettext函数,可以通过预编译(#define)来简化,而glib中的gi18n.h提供了 _() 宏,比较方便。把所有文本放在 _() 中间即可。

下面编写两个示例来说明。

终端程序:

#include <stdio.h>
#include <libintl.h>
#include <locale.h>
#define _(STRING) gettext(STRING)
int main () {
setlocale (LC_ALL, "");
bindtextdomain ("test", "./locale/");
textdomain ("test");
printf (_("This is English.\n"));
return 0;
}

GTK+程序:

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <stdio.h> #define GETTEXT_PACKAGE "ubuntu-tweak"
#define LOCALEDIR "./locale" int main(int argc,char **argv)
{
GtkWidget *window;
gtk_init (&argc, &argv);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), _("help"));
g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}

二、生成po文件

$ xgettext -k_ -o lang.po ./*.c

三、编辑po文件

将头部的CHARSET改为“UTF–8”,在msgstr后加入翻译。

四、生成mo文件

$ msgfmt -o test.mo lang.po

注意test是你程序中的GETTEXT_PACKAGE名字。

五、移动mo文件

先建立 locale/zh_CN/LC_MASSAGES/ 这个文件夹,然后把mo文件移动过去,注意locale是你程序中的LOCALEDIR。

六、运行程序

呵呵,看看效果吧,在不同的locale下(可修改$LANG),运行的程序效果不同哦~

源码下载

http://www.gtkforums.com/viewtopic.php?t=3137

多个window

http://ptomato.name/advanced-gtk-techniques/html/index.html

http://ptomato.name/advanced-gtk-techniques/html/custom-container.html

GtkImageMenuItem的更多相关文章

随机推荐

  1. android网络编程之HttpUrlConnection的讲解--POST请求

    1.服务器后台使用Servlet开发,这里不再介绍. 2.网络开发不要忘记在配置文件中添加访问网络的权限 <uses-permission android:name="android. ...

  2. philosophy

    Even though the UNIX system introduces a number of innovative programs and techniques, no single pro ...

  3. Mac 下格式化U盘

    diskutil list 查看U盘盘符: lapommedeMacBook-Pro:~ lapomme$ diskutil list /dev/disk0 (internal, physical): ...

  4. shell之路【第四篇】输入输出重定向

    输出重定向 命令输出重定向的语法为: command > file 或 command >> file 这样,输出到显示器的内容就可以被重定向到文件.果不希望文件内容被覆盖,可以使用 ...

  5. wl18xx wifi编译出现没有编译wlcore_sdio的情况

    打开config.mk ........................................................................................ ...

  6. innerHTML,innerText,outerHTML,outerText,value浅析

    首先是一个例子: <div id= "aa">0<br/>0<span>11</span>22</div><inp ...

  7. T-shirts Distribution

    T-shirts Distribution time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. Java中的五种单例模式实现方法

    [代码] Java中的五种单例模式实现方法   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 2 ...

  9. php cookies自动登录

    <?php header('Content-type: text/html; charset=utf-8'); error_reporting(0); //自动登陆 if($_COOKIE[&q ...

  10. php薪资

    2千的php程序员就是可以用cms,做一个小企业的门户网站. 3千的php程序员,可以自己写代码开发php软件,但是这样程序员写的代码非常混乱,通常只能写数千行代码的小软件,并且痛苦的完工. 4K的p ...