gtk的rc

来源:互联网 发布:淘宝评价图片怎么删除 编辑:程序博客网 时间:2024/04/28 09:59
gtk提供源文的机制,使我们可以动态的配置gtk在运行时候的很多方面

默认文件:
一个程序可以通过使用gtk_rc_parse()这个函数来指定配置文件的位置。另外rc文件也可以在gtk_init()执行中自动读取。一般文件的位置是sysconfdir/gtk-2.0/gtkrc 和 用户主目录中的.gtkrc-2.0(默认的位置是/usr/local/etc)他可通过在安装gtk的使用使用--prefix --sysconfidir来配置,我们注意到虽然文件是又2.0这个版本号的但是在使用的时候所有的2.x都可以使用这个文件

配置文件的路径和位置可以使用 gtk_rc_get_default_files() 函数得到,使用 modified with gtk_rc_add_default_file(), gtk_rc_set_default_files()函数修改。另外,GTK2_RC_FILES 环境变量的设置可以覆盖默认文件的设置

对于每一个rc文件来说,gtk都是根据本地LANG环境变量来读取额外的设置,例如如果LANG设置为ja_JP.uijs 在读入默认的~/.gtkrc后 gtk还将寻找 ~/.gtkrc.ja_JP 和 ~/.gtkrc.ja 文件并读取他们的设置

一个rc文件定义了一系列的样式,并把这些样式应用到特定的部件上去。这些样式在应是的应用是依靠widget,widget_class,call这样的声明完成的例如:
widget "mywindow.*.GtkEntry" style "my-entry-class"
应用"my-entry-class"样式到所有匹配"mywindow.*.GtkEntry"的部件上。这些部件是在gtkwindow叫做mywindow中的输入框gtkentry
 
这里的给出的模式和shell的标准的语法一样,?代表任意一个字符,*代表零个或者是多个字符。类的路径 类的继承 部件路径, gtk_widget_set_name()可以设置widget的名字在,类路径中出现

从gtk+2.10开始,widget_class可以包含<classname>这样的字串,可以匹配类和他的子类。例如:

widget_class "*<GtkMenuItem>.GtkLabel" style "my-style"

会匹配所有在menu item中包含的label
所以如果你又一个gtkentry叫"myentry" 包含在一个水平的box中,这个box又在一个叫做mywindow的部件中,这个部件的路径就是mywindow.GtkHBox.myentry 类的路径就是GtkWidndow.GtkHBox.GtkEntry

类的路径又一些不同,所有从这个类继承的类也要使用定义的样式 比如:
class "GtkButton" style "my-style"
不光是匹配gtkButton GtkToggleButton GtkCheckButton也将匹配一味这些类是从gtkButton继承的

另外模式也是有优先级的样式覆盖其他的样式依靠优先级,他们的顺序是从高到底:
rc
theme
application
gtkSpecifies a style or binding set for a particular branch of the inheritance hierarchy.
rc默认是从rc文件读出来,theme默认是从theme rc文件读,application是在一个程序建立的时候定义的,gtk是gtk+默认的样式

定制rc文件
为了加速你的程序使用以下的一些建议:

1.为专用的应用程序使用专业的rc文件
2.把同一个模式的匹配尽量放到一起
例如:
     style "Foo" { foo_content }
     class "X" style "Foo"
     style "Bar" { bar_content }
     class "X" style "Bar"
修改成为:
style "FooBar" { foo_content bar_content }
class "X" style "FooBar"


3.尽量的减少使用统配符
4.避免递归的匹配多使用全的路径名称,尽量少使用统配符
5.在可能的情况下只在头或者是结尾使用统配符
6.尽量使用?代替*这样可以降低查找的复杂度
7.*要尽量少的使用

顶级声明:

rc是一个文本的文件,其中使用"#"作为注释
又可能的定义如下:

binding name  { ... } Declares a binding set.


class pattern [ style | binding ][ : priority ] name    

Specifies a style or binding set for a particular branch of the inheritance hierarchy.

//
include filename    

Parses another file at this point. If filename is not an absolute filename, it is searched in the directories of the currently open RC files.
//
GTK+ also tries to load a locale-specific variant of the included file.
//
module_path path    

Sets a path (a list of directories separated by colons) that will be searched for theme engines referenced in RC files.
//
pixmap_path path    

Sets a path (a list of directories separated by colons) that will be searched for pixmaps referenced in RC files.
//
im_module_file pathname    

Sets the pathname for the IM modules file. Setting this from RC files is deprecated; you should use the environment variable GTK_IM_MODULE_FILE instead.
style name [ = parent ] { ... }    

Declares a style.
widget pattern [ style | binding ][ : priority ] name    

Specifies a style or binding set for a particular group of widgets by matching on the widget pathname.
widget_class pattern [ style | binding ][ : priority ] name    

Specifies a style or binding set for a particular group of widgets by matching on the class pathname.
setting = value    

Specifies a value for a setting. Note that settings in RC files are overwritten by system-wide settings (which are managed by an XSettings manager on X11).

rc样式

一个样式在rc文件中使用style声明,然后使用widget,widget_class class和部件绑定 ,所有的样式应用于特定的样式widget 将覆盖widget_class 和class的声明,在同一个级别下,最后的声明覆盖现前的声明。
在一个样式在声明中下面是可能的声明:
bg[state] = color    Sets the color used for the background of most widgets.

fg[state] = color   Sets the color used for the foreground of most widgets.

base[state] = color  Sets the color used for the background of widgets displaying editable text. This color is used for the
background of, among others, GtkText, GtkEntry, GtkList, and GtkCList.

text[state] = color  Sets the color used for foreground of widgets using base for the background color.

xthickness = number  Sets the xthickness, which is used for various horizontal padding values in GTK+.

ythickness = number Sets the ythickness, which is used for various vertical padding values in GTK+.

bg_pixmap[state] = pixmap Sets a background pixmap to be used in place of the bg color (or for GtkText, in place of the base color. The special value "<parent>" may be used to indicate that the widget should use the same background pixmap as its parent. The special value "<none>" may be used to indicate no background pixmap.

font = font Starting with GTK+ 2.0, the "font" and "fontset" declarations are ignored; use "font_name" declarations instead.

fontset = font Starting with GTK+ 2.0, the "font" and "fontset" declarations are ignored; use "font_name" declarations instead.

font_name = font Sets the font for a widget. font must be a Pango font name, e.g. "Sans Italic 10". For details about Pango font names, see pango_font_description_from_string().

stock["stock-id"] = { icon source specifications } Defines the icon for a stock item.

color["color-name"] = color specification Since 2.10, this element can be used to defines symbolic colors. See below for the syntax of color specifications.

engine "engine" { engine-specific settings } Defines the engine to be used when drawing with this style.

class::property = value Sets a style property for a widget class.

The colors and background pixmaps are specified as a function of the state of the widget. The states are:
NORMAL    

A color used for a widget in its normal state.
ACTIVE    

A variant of the NORMAL color used when the widget is in the GTK_STATE_ACTIVE state, and also for the trough of a ScrollBar, tabs of a NoteBook other than the current tab and similar areas. Frequently, this should be a darker variant of the NORMAL color.
PRELIGHT    

A color used for widgets in the GTK_STATE_PRELIGHT state. This state is the used for Buttons and MenuItems that have the mouse cursor over them, and for their children.
SELECTED    

A color used to highlight data selected by the user. for instance, the selected items in a list widget, and the selection in an editable widget.
INSENSITIVE    

A color used for the background of widgets that have been set insensitive with gtk_widget_set_sensitive().


颜色可以使用颜色的名称(GTK+ knows all names from the X color database /usr/lib/X11/rgb.txt),使用一种16进制的形式例如#rrrrggggbbbb, #rrrgggbbb, #rrggbb, or #rgb。r,g,b是16进制的整数(0-65535)或者是浮点数字0.0-1.0
从2.10开始颜色可以使用符号颜色 以@color-name 或者是用表达式合成颜色。
mix (factor, color1, color2)    

Computes a new color by mixing color1 and color2. The factor determines how close the new color is to color1. A factor of 1.0 gives pure color1, a factor of 0.0 gives pure color2.
shade (factor, color)    

Computes a lighter or darker variant of color. A factor of 1.0 leaves the color unchanged, smaller factors yield darker colors, larger factors yield lighter colors.
lighter (color)    

This is an abbreviation for shade (1.3, color).
darker (color)    

This is an abbreviation for shade (0.7, color).
例如:
 mix (0.5, "red", "blue")
 shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 }))
 lighter (@foreground)

在库中图标的定义是一个四元组(图标的名字,文字的方向,widget状态,和大小),当你自己定义这些属性的时候gtk不会修改他们,当你使用统配符的时候gtk自己决定匹配的状态
stock["my-stock-item"] =
{
  { "itemltr.png", LTR, *, * },
  { "itemrtl.png", RTL, *, * }
}
省略的写法
stock["my-stock-item"] =
{
  { "itemltr.png", LTR },
  { "itemrtl.png", RTL }
}



key bingdings:
key bindings 允许用户定义当按键按下以后特定的状态
binding name {
  bind key {
    signalname (param, ...)
    ...
  }
  ...
}

key可以包括:

<alt>
<ctl>
<control>
<meta>
<hyper>
<super>
<mod1>
<mod2>
<mod3>
<mod4>
<mod5>
<release>
<shft>
<shift>
<shft> is an alias for <shift>, <ctl> is an alias for <control>, and <alt> is an alias for <mod1>.




原创粉丝点击