[英]get gtk theme css property from python Gtk3
I am having trouble in getting certain properties from the system Gtk3 theme css (gtk.css) to render contextual components in my python Gtk3 application. 我无法从系统Gtk3主题css(gtk.css)获取某些属性,以在我的python Gtk3应用程序中呈现上下文组件。
What I have from my system theme gtk.css are the following: 我的系统主题gtk.css的内容如下:
entry {
...
color: #5c616c;
border-color: #cfd6e6;
background-color: #ffffff; }
entry:focus {
background-clip: border-box;
color: #5c616c;
border-color: #5294e2;
background-color: #ffffff; }
entry:disabled {
color: rgba(92, 97, 108, 0.55);
border-color: rgba(207, 214, 230, 0.55);
background-color: rgba(255, 255, 255, 0.55); }
entry.warning {
color: white;
border-color: #F27835;
background-color: #f7ae86; }
entry.warning image {
color: white; }
...
What I would like to get from it are those contextual colors, eg background-color
from entry.warning
, etc. 我想从中获得的是那些上下文颜色,例如来自
entry.warning
background-color
等。
I have done some research and here is where I get stuck: 我做了一些研究,这里是我被卡住的地方:
css_provider = Gtk.CssProvider.get_default()
warning_color = css_provider.get_style(something to put here)
Many thanks for your help! 非常感谢您的帮助!
The correct way would be to modify a Gtk.Widget
's Gtk.StyleContext
so that the CSS rule applies to it, then use the Gtk.render_whatever()
functions to draw your contextual components. 正确的方法是修改
Gtk.Widget
的Gtk.StyleContext
以便CSS规则适用于它,然后使用Gtk.render_whatever()
函数绘制上下文组件。
For example to render a background with the same style as the warning
background on a Gtk.Entry
subclass: 例如,在
Gtk.Entry
子类上渲染与warning
背景具有相同样式的背景:
context = my_entry.get_style_context()
context.save()
context.add_class('warning')
Gtk.render_background(context, blah, blah, blah)
context.restore()
Note that it's not possible to get the background color directly from CSS. 请注意,无法直接从CSS获取背景颜色 。 A CSS background may be a color, or an image, or a gradient.
CSS背景可以是颜色,图像或渐变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.