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

GTK入门导引

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

  您可以看到, 这是很强很有弹性的系统. 用您最佳的想像力来看有多少好处.

  19.2 GTK的rc档案格式

  GTK的rc档格式如以下的范例. 这个testgtkrc档从GTK distribution而来, 但我加了点料及注解进去. 您也可以加一点解释来让使用者做微调.

  有好几个指令来改变该物件的属性.

  fg - 前景颜色.

  bg - 背景颜色.

  bg_pixmap - 背景图片pixmap.

  font - 字型.

  除此, 一个物件可以有好几种状态. 您可以设定不同的颜色, 图案及字形. 这些状态是:

  NORMAL - 物件一般的状态, 没有滑鼠滑过, 没有被按下.

  PRELIGHT - 滑鼠滑过该物件.

  ACTIVE - 当该物件被压下或按下, 该视窗会生效.

  INSENSITIVE - 当该物件被设为失效.

  SELECTED - 当物件被选择.

  当我们使用"fg"及"bg"来设定该物件的颜色时, 其格式为:


fg[<STATE>] = { Red, Green, Blue }

  这里STATE是我们以上所说的其中之一(PRELIGHT, ACTIVE etc), 而Red, Green及Blue为0到1.0, { 1.0, 1.0, 1.0 }为白色. 它们必须要为浮点数, "1"不行, 必须是"1.0", 否则会全部变成0. "0"可以. 不是以此格式者均为"0".

  bg_pixmap跟以上都很近似, 除了变成档名以外.

  pixmap_path是以":"做为分隔的一串路径. 这些路径会用来搜寻您所指定的pixmap.

  font指令很简单:


font = "<font name>"

  比较难的是找出想要的font名称. 用xfontsel或类似的工具来找会有点帮助.

  "widget_class"设定物件的类别. 这些类别在物件概论中的类别组织图有列出来.

  "widget"指令指定一个已经定好的形态给一个物件. 替代所有该物件的属性. 这些物件则在程式中以gtk_widget_set_name()注册过了. 这允许您指定各别物件的属性, 而不是设定全部同一类的. 我要求您要做好文件, 这样使用者可以自行修改.

  当"parent"用来当成一个属性时, 该物件会继承其父所有财产.

  当您定义一个形态时, 可以指定以前已经定义过的形态给新的.


style "main_button" = "button"
{
font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
bg[PRELIGHT] = { 0.75, 0, 0 }
}

  这个例子用"button"的形态, 产生一个"main_button"形态, 并且只改变font及背景颜色.

  当然了并非所有属性都对所有物件生效. 因为该物件不见得拥有该属性.

  19.3 rc档的范例


# pixmap_path "<dir 1>:<dir 2>:<dir 3>:..."
#
pixmap_path "/usr/include/X11R6/pixmaps:/home/imain/pixmaps"
#
# style <name> [= <name>]
# {
#<option>
# }
#
# widget <widget_set> style <style_name>
# widget_class <widget_class_set> style <style_name>
# Here is a list of all the possible states.Note that some do not apply to
# certain widgets.
#
# NORMAL - The normal state of a widget, without the mouse over top of
# it, and not being pressed etc.
#
# PRELIGHT - When the mouse is over top of the widget, colors defined
# using this state will be in effect.
#
# ACTIVE - When the widget is pressed or clicked it will be active, and
# the attributes assigned by this tag will be in effect.
#
# INSENSITIVE - When a widget is set insensitive, and cannot be
# activated, it will take these attributes.
#
# SELECTED - When an object is selected, it takes these attributes.
#
# Given these states, we can set the attributes of the widgets in each of
# these states using the following directives.
#
# fg - Sets the foreground color of a widget.
# fg - Sets the background color of a widget.
# bg_pixmap - Sets the background of a widget to a tiled pixmap.
# font - Sets the font to be used with the given widget.
#
# This sets a style called "button".The name is not really important, as
# it is assigned to the actual widgets at the bottom of the file.
style "window"
{
#This sets the padding around the window to the pixmap specified.
#bg_pixmap[<STATE>] = "<pixmap filename>"
bg_pixmap[NORMAL] = "warning.xpm"
}
style "scale"
{
#Sets the foreground color (font color) to red when in the "NORMAL"
#state.
fg[NORMAL] = { 1.0, 0, 0 }
#Sets the background pixmap of this widget to that of it's parent.
bg_pixmap[NORMAL] = "<parent>"
}
style "button"
{
# This shows all the possible states for a button.The only one that
# doesn't apply is the SELECTED state.
fg[PRELIGHT] = { 0, 1.0, 1.0 }
bg[PRELIGHT] = { 0, 0, 1.0 }
bg[ACTIVE] = { 1.0, 0, 0 }
fg[ACTIVE] = { 0, 1.0, 0 }
bg[NORMAL] = { 1.0, 1.0, 0 }
fg[NORMAL] = { .99, 0, .99 }
bg[INSENSITIVE] = { 1.0, 1.0, 1.0 }
fg[INSENSITIVE] = { 1.0, 0, 1.0 }
}
# In this example, we inherit the attributes of the "button" style and then
# override the font and background color when prelit to create a new
# "main_button" style.
style "main_button" = "button"
{
font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
bg[PRELIGHT] = { 0.75, 0, 0 }
}
style "toggle_button" = "button"
{
fg[NORMAL] = { 1.0, 0, 0 }
fg[ACTIVE] = { 1.0, 0, 0 }
# This sets the background pixmap of the toggle_button to that of it's
# parent widget (as defined in the application).
bg_pixmap[NORMAL] = "<parent>"
}
style "text"
{
bg_pixmap[NORMAL] = "marble.xpm"
fg[NORMAL] = { 1.0, 1.0, 1.0 }
}
style "ruler"
{
font = "-adobe-helvetica-medium-r-normal--*-80-*-*-*-*-*-*"
}
# pixmap_path "~/.pixmaps"
# These set the widget types to use the styles defined above.
# The widget types are listed in the class hierarchy, but could probably be
# just listed in this document for the users reference.
widget_class "GtkWindow" style "window"
widget_class "GtkDialog" style "window"
widget_class "GtkFileSelection" style "window"
widget_class "*Gtk*Scale" style "scale"
widget_class "*GtkCheckButton*" style "toggle_button"
widget_class "*GtkRadioButton*" style "toggle_button"
widget_class "*GtkButton*" style "button"
widget_class "*Ruler" style "ruler"
widget_class "*GtkText" style "text"
# This sets all the buttons that are children of the "main window" to
# the main_buton style.These must be documented to be taken advantage of.
widget "main window.*GtkButton*" style "main_button"


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



上一篇:GTK+/Gnome应用开发   下一篇:GTK v1.2 Tutorial(英文)

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章