本文整理汇总了Python中gi.repository.Gtk.CssProvider方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.CssProvider方法的具体用法?Python Gtk.CssProvider怎么用?Python Gtk.CssProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.CssProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def __init__(self, title, description):
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path(common_css_dir + "/heading.css")
styleContext = Gtk.StyleContext()
styleContext.add_provider(cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.title = Gtk.Label(title)
self.title_style = self.title.get_style_context()
self.title_style.add_provider(cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.title_style.add_class('title')
self.container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.container.pack_start(self.title, False, False, 0)
if description != "":
self.description = Gtk.Label(description)
self.description.set_justify(Gtk.Justification.CENTER)
self.description.set_line_wrap(True)
self.description_style = self.description.get_style_context()
self.description_style.add_provider(cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.description_style.add_class('description')
self.container.pack_start(self.description, False, False, 0)
示例2: on_app_startup
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def on_app_startup(self, app):
# initiate custom css
# css stylesheet
stylesheet = os.path.join(cli.install_dir, "ui", "gtk.css")
# ...encode() is needed because CssProvider expects byte type input
with open(stylesheet, "r") as f:
css = f.read().encode()
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
示例3: load_style_css
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def load_style_css(self, css_file):
self.logger.debug('loading style from css file: ' + css_file)
css_file = Gio.File.new_for_path(css_file)
style_provider = Gtk.CssProvider()
style_provider.connect('parsing-error', self.signal_css_provider_parsing_error)
try:
style_provider.load_from_file(css_file)
except GLib.Error: # pylint: disable=catching-non-exception
self.logger.error('there was an error parsing the css file, it will not be applied as a style provider')
return None
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
return style_provider
示例4: override_menu_borders
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def override_menu_borders():
""" Loads custom CSS to create borders around popup menus """
style_provider = Gtk.CssProvider()
style_provider.load_from_data(b"""
.menu {
border-image: linear-gradient(to top,
alpha(@borders, 0.80),
alpha(@borders, 0.60) 33%,
alpha(@borders, 0.50) 66%,
alpha(@borders, 0.15)) 2 2 2 2/ 2px 2px 2px 2px;
}
.menubar .menu {
border-image: linear-gradient(to top,
alpha(@borders, 0.80),
alpha(@borders, 0.60) 33%,
alpha(@borders, 0.50) 66%,
transparent 99%) 2 2 2 2/ 2px 2px 2px 2px;
}
""")
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
示例5: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def __init__(self, context, on_skip, on_postpone, style_sheet_path):
self.context = context
self.count_labels = []
self.display = Display()
self.enable_postpone = False
self.enable_shortcut = False
self.is_pretified = False
self.keycode_shortcut_postpone = 65
self.keycode_shortcut_skip = 9
self.on_postpone = on_postpone
self.on_skip = on_skip
self.shortcut_disable_time = 2
self.strict_break = False
self.windows = []
# Initialize the theme
css_provider = Gtk.CssProvider()
css_provider.load_from_path(style_sheet_path)
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
示例6: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def __init__(self):
self.theme = {}
self.gradient = {}
self.border = {}
self.headerbar_border = Gtk.CssProvider()
self.headerbar_border.load_from_data((
"""
headerbar {
border: none;
border-radius: 0;
}
"""
).encode('ascii'))
self.wm_border = Gtk.CssProvider()
self.caret = Gtk.CssProvider()
self.reset_style = Gtk.CssProvider()
self.reset_style.load_from_data((
"""
* {
box-shadow:none;
border: none;
}
"""
).encode('ascii'))
示例7: reset_gradients
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def reset_gradients(self):
css_provider_gradient = self.css_providers.gradient.get("reset")
if not css_provider_gradient:
css_provider_gradient = \
self.css_providers.gradient["reset"] = \
Gtk.CssProvider()
css_provider_gradient.load_from_data((
"""
* {
background-image: none;
}
"""
).encode('ascii'))
for widget in [
self.gtk_preview.button,
self.gtk_preview.headerbar.button,
self.gtk_preview.entry,
self.gtk_preview.headerbar,
]:
Gtk.StyleContext.add_provider(
widget.get_style_context(),
css_provider_gradient,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
示例8: get_theme_css_provider
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def get_theme_css_provider(self, theme_plugin):
css_dir = theme_plugin.gtk_preview_dir
css_name = "theme{}.css".format(
'20' if Gtk.get_minor_version() >= 20 else ''
)
css_path = os.path.join(css_dir, css_name)
if not os.path.exists(css_path):
css_path = os.path.join(css_dir, "theme.css")
css_provider = self.css_providers.theme.get(css_path)
if css_provider:
return css_provider
css_provider = Gtk.CssProvider()
try:
css_provider.load_from_path(css_path)
except GLib.Error as exc: # pylint: disable=catching-non-exception
print(exc)
self.css_providers.theme[css_path] = css_provider
return css_provider
示例9: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def __init__(self, label_time):
self.label_time = label_time
style_context = self.label_time.get_style_context()
self.color_override = Gtk.CssProvider()
style_context.add_provider(self.color_override, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + 1)
self.label_color_default = self.load_color_from_css(style_context)
label_color_ett_reached = self.load_color_from_css(style_context, "ett-reached")
label_color_ett_info = self.load_color_from_css(style_context, "ett-info")
label_color_ett_warn = self.load_color_from_css(style_context, "ett-warn")
self.color_map = [
( 300, self.label_color_default),
( 0, label_color_ett_reached),
(-150, label_color_ett_info),
(-300, label_color_ett_warn)
]
示例10: main
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def main():
style_provider = Gtk.CssProvider()
with open(os.path.join(STYLEDIR, "style.css"), 'rb') as css:
css_data = css.read()
style_provider.load_from_data(css_data)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(), style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
TouchPad(test=True)
Gtk.main()
示例11: configure_transparency
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def configure_transparency(c):
c.set_visual(c.get_screen().get_rgba_visual())
c.override_background_color(gtk.StateFlags.ACTIVE, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.BACKDROP, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.DIR_LTR, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.DIR_RTL, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.FOCUSED, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.INCONSISTENT, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.INSENSITIVE, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.PRELIGHT, Gdk.RGBA(0, 0, 0, 0))
c.override_background_color(gtk.StateFlags.SELECTED, Gdk.RGBA(0, 0, 0, 0))
transparentWindowStyleProvider = gtk.CssProvider()
transparentWindowStyleProvider.load_from_data(b"""
GtkWindow {
background-color:rgba(0,0,0,0);
background-image:none;
}""")
c.get_style_context().add_provider(transparentWindowStyleProvider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
示例12: _new_css_provider
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def _new_css_provider(self):
css = '''
#zim-pageview text {
color: %s;
background-color: %s;
}
widget box box scrolledwindow{
border-style: none;
}
box {
background-color: %s;
}
''' % (self.preferences['textcolor'], self.preferences['basecolor'],self.preferences['basecolor'])
provider = Gtk.CssProvider()
provider.load_from_data(css.encode('UTF-8'))
return provider
示例13: __setup_css
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def __setup_css():
"""Setup the CSS and load it."""
uri = 'resource:///com/github/bilelmoussaoui/Authenticator/style.css'
provider_file = Gio.File.new_for_uri(uri)
provider = Gtk.CssProvider()
screen = Gdk.Screen.get_default()
context = Gtk.StyleContext()
provider.load_from_file(provider_file)
context.add_provider_for_screen(screen, provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
Logger.debug("Loading CSS")
示例14: apply_styling_to_screen
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def apply_styling_to_screen(css_file, priority="USER"):
css = Gtk.CssProvider()
if not os.path.exists(css_file):
sys.exit(css_file + ' CSS file missing!')
css.load_from_path(css_file)
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
if priority == "FALLBACK":
gtk_priority = Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK
elif priority == "THEME":
gtk_priority = Gtk.STYLE_PROVIDER_PRIORITY_THEME
elif priority == "SETTINGS":
gtk_priority = Gtk.STYLE_PROVIDER_PRIORITY_SETTINGS
elif priority == "APPLICATION":
gtk_priority = Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
elif priority == "USER":
gtk_priority = Gtk.STYLE_PROVIDER_PRIORITY_USER
styleContext.add_provider_for_screen(screen, css, gtk_priority)
# Apply the styling from a CSS file to a specific widget
示例15: apply_styling_to_widget
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import CssProvider [as 别名]
def apply_styling_to_widget(widget, path):
if not os.path.exists(path):
sys.exit('{} CSS file missing!'.format(path))
provider = Gtk.CssProvider()
provider.load_from_path(path)
styleContext = widget.get_style_context()
styleContext.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
# Apply the colour variable names to the widget (useful if you want to refer to kano_green)