如何访问GTK / Gnome上的主题字体和颜色 [英] How to access the theming Fonts and Colors on GTK/Gnome

查看:284
本文介绍了如何访问GTK / Gnome上的主题字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何获得文本的默认主题颜色,
选定的文本和背景以及这是用户默认的
字体?我发现GNOME在GNOME外观中为此定义了5种特殊的系统字体和默认大小
配置对话框,
,但我还没有在GTK文档中找到一个单词,如何
访问它们(和GTK邮件列表是一个笑话:-()。

Windows和Cocoa都给我几十个系统值。

我找到了GtkStyle类,但这似乎不是我需要的。

解决方案

对于默认颜色,使用如下所示:

  GdkColor color; 
/ *在主题中查找默认文本颜色,如果未定义,则使用默认的
* /
GtkStyle * style = gtk_rc_get_style (my_widget);
if(!gtk_style_lookup_color(style,text_color ,& color))
gdk_color_parse(black,& color);

定义了 gtk_style_lookup_color()。它们的确切位置有点不清楚,但这些是您可以在GNOME对话框中定义的:


  • fg_color

  • bg_c​​olor

  • base_color

  • text_color

  • selected_bg_color

  • selected_fg_color

  • tooltip_bg_color

  • tooltip_fg_color



至于字体和其他系统设置,您需要使用GConf库来获取这些默认值。 GTK对它们一无所知,因为它们是GNOME桌面的一部分,而不是GTK。例如,默认字体可以在 / desktop / gnome / interface / font_name 键处找到。如果您安装了GConf配置编辑器,则可以浏览这些键以查看哪些键可用;它们都在 / desktop / gnome 下。



PS。你问过什么GTK邮件列表?我读过的一篇似乎不是一个笑话......


Lets say i want to write a special text editor widget.

How can i get the default themed colors for texts, selected text and background and which are the users default fonts?

I see that GNOME does define 5 special system fonts and default sizes for this purpose in the GNOME Appearance Configuration dialog, but i haven't found a single word in the GTK documentation how to access them (and the GTK mailing list is a joke:-( ).

Windows and Cocoa both give me dozens of system values.

I found the GtkStyle class but this doesn't seem to be what i need.

解决方案

For the default colors, use something like this:

GdkColor color;
/* Look up the default text color in the theme, use a default 
if it's not defined */
GtkStyle *style = gtk_rc_get_style(my_widget);
if(!gtk_style_lookup_color(style, "text_color", &color))
    gdk_color_parse("black", &color);

There are several names defined for gtk_style_lookup_color(). It's a bit unclear where exactly they are defined, but these are the ones you can define in the GNOME dialog:

  • fg_color
  • bg_color
  • base_color
  • text_color
  • selected_bg_color
  • selected_fg_color
  • tooltip_bg_color
  • tooltip_fg_color

As for the fonts and other system settings, you need to use the GConf library to get these defaults. GTK knows nothing about them, because they're part of the GNOME desktop, not GTK. The default font can be found at the key /desktop/gnome/interface/font_name, for example. If you install the GConf configuration editor, you can browse these keys to see which ones are available; they're all under /desktop/gnome.

PS. What GTK mailing list did you ask on? The one I read doesn't seem to be a joke...

这篇关于如何访问GTK / Gnome上的主题字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆