本文整理汇总了Python中gi.repository.Gtk.StyleContext方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.StyleContext方法的具体用法?Python Gtk.StyleContext怎么用?Python Gtk.StyleContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.StyleContext方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [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: gtk_style_context_get_color
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def gtk_style_context_get_color(sc, color_name, default=None):
"""
Look up a color by it's name in the :py:class:`Gtk.StyleContext` specified
in *sc*, and return it as an :py:class:`Gdk.RGBA` instance if the color is
defined. If the color is not found, *default* will be returned.
:param sc: The style context to use.
:type sc: :py:class:`Gtk.StyleContext`
:param str color_name: The name of the color to lookup.
:param default: The default color to return if the specified color was not found.
:type default: str, :py:class:`Gdk.RGBA`
:return: The color as an RGBA instance.
:rtype: :py:class:`Gdk.RGBA`
"""
found, color_rgba = sc.lookup_color(color_name)
if found:
return color_rgba
if isinstance(default, str):
color_rgba = Gdk.RGBA()
color_rgba.parse(default)
return color_rgba
elif isinstance(default, Gdk.RGBA):
return default
return
示例3: load_color_from_css
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def load_color_from_css(self, style_context, class_name = None):
""" Add class class_name to the time label and return its color.
Args:
label_time (:class:`Gtk.Label`): the label where the talk time is displayed
style_context (:class:`~Gtk.StyleContext`): the CSS context managing the color of the label
class_name (`str` or `None`): The name of the class, if any
Returns:
:class:`~Gdk.RGBA`: The color of the label with class "class_name"
"""
if class_name:
style_context.add_class(class_name)
self.label_time.show()
color = style_context.get_color(Gtk.StateType.NORMAL)
if class_name:
style_context.remove_class(class_name)
return color
示例4: __setup_css
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [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")
示例5: apply_styling_to_screen
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [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
示例6: _setup_css
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def _setup_css(self):
"""Setup the CSS."""
resource = 'resource:////com/github/bilelmoussaoui/AudioCutter/style.css'
css_file = Gio.File.new_for_uri(resource)
cssProvider = Gtk.CssProvider()
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
cssProvider.load_from_file(css_file)
styleContext.add_provider_for_screen(screen, cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
Logger.debug("Loading css file {}".format(css_file))
示例7: on_startup
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def on_startup(self, *args):
"""
call after RB has completed its initialisation and selected the first
view
:param args:
:return:
"""
self.startup_completed = True
self.reset_categories_pos(self.shell.props.selected_page)
self.reset_toolbar(self.shell.props.selected_page)
# lets hide the ghastly floating bar in RB 3.4.3
cssdata = """
.floating-bar {
opacity: 0;
}
"""
cssprovider = Gtk.CssProvider.new()
cssprovider.load_from_data(cssdata.encode())
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(
self.shell.props.window.props.screen,
cssprovider,
Gtk.STYLE_PROVIDER_PRIORITY_USER,
)
self.reset_entryview(self.shell.props.selected_page)
if self.plugin.prefer_dark_theme:
settings = Gtk.Settings.get_default()
settings.set_property('gtk-application-prefer-dark-theme', True)
示例8: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def __init__(self, install=None, icon_only=False, tutorial=False):
ApplicationWindow.__init__(self, 'Apps', 755, 588)
self._install = install
self._tutorial = tutorial
self._icon_only = icon_only
self._last_page = 0
self.connect("show", self._app_loaded)
# Destructor
self.connect('delete-event', Gtk.main_quit)
self.set_icon_from_file("/usr/share/kano-desktop/icons/apps.png")
# Styling
screen = Gdk.Screen.get_default()
specific_css_provider = Gtk.CssProvider()
specific_css_provider.load_from_path(Media.media_dir() +
'css/style.css')
specific_style_context = Gtk.StyleContext()
specific_style_context.add_provider_for_screen(
screen,
specific_css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER
)
style = self.get_style_context()
style.add_class('main_window')
# Setup widgets
self.set_decorated(True)
self._top_bar = TopBar(_("Apps"), self._win_width, False)
self._top_bar.set_close_callback(Gtk.main_quit)
self.set_titlebar(self._top_bar)
self._contents = Contents(self)
self.set_main_widget(self._contents)
self.show_apps_view()
示例9: lock
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def lock(self, msg, unlock_secs=None):
"""Lock the screen. Unlock after unlock_secs if it's not None."""
screen = Gdk.Screen.get_default()
swidth = screen.get_width()
sheight = screen.get_height()
smin = min(swidth, sheight)
gtk_provider = Gtk.CssProvider()
gtk_context = Gtk.StyleContext()
gtk_context.add_provider_for_screen(
screen, gtk_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
gtk_provider.load_from_data(bytes("""
* {{ transition-property: color; transition-duration: 4s; }}
window, GtkWindow {{ background-color: black; }}
label, GtkLabel {{ font-size: {0:.0f}px; }}
label#black, GtkLabel#black {{ color: black; }}
label#white, GtkLabel#white {{ color: #e0e0e0; }}
""".format(swidth / 70).encode()))
backlock = Gtk.Window(type=Gtk.WindowType.POPUP)
self.backlock = backlock
backlock.resize(1, 1)
frontview = Gtk.Window()
self.frontview = frontview
frontview.resize(swidth, sheight)
box = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL, spacing=smin/12,
halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)
image = Gtk.Image(pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(
'lock.svg', smin/3, smin/3))
box.pack_start(image, False, False, 0)
self.label = Gtk.Label(label=msg, name="black")
box.pack_start(self.label, False, False, 0)
frontview.add(box)
backlock.show_all()
frontview.show_all()
frontview.set_keep_above(True)
frontview.fullscreen()
Gdk.beep()
Gdk.keyboard_grab(backlock.get_window(), False, 0)
# Transitions need an event to start
GLib.timeout_add(100, self.do_transition)
# While developing, to only lock the screen for e.g. 5 seconds, run:
# ./lock-screen "" 5
if unlock_secs is not None:
GLib.timeout_add(unlock_secs*1000, self.unlock)
示例10: set_style
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import StyleContext [as 别名]
def set_style(cls, css_str=None) -> None:
"""
Set the specified css style, or set default styles if no css string is specified.
:param css_str: A valid css format string.
"""
css_list = []
if css_str is None:
# Initialize formatting colors.
css_list.append("grid { background-image: image(%s); }" % cls._colors['gray80'])
css_list.append("#light_grid { background-image: image(%s); }" % cls._colors['gray20'])
css_list.append("#dark_grid { background-image: image(%s); }" % cls._colors['gray70'])
css_list.append("#dark_box { background-image: image(%s); }" % cls._colors['slate_dk'])
css_list.append("#med_box { background-image: image(%s); }" % cls._colors['slate_md'])
css_list.append("#light_box { background-image: image(%s); }" % cls._colors['slate_lt'])
css_list.append("#head_box { background-image: image(%s); }" % cls._colors['blue'])
css_list.append("#warn_box { background-image: image(%s); }" % cls._colors['red'])
css_list.append("#button_box { background-image: image(%s); }" % cls._colors['slate_dk'])
css_list.append("#message_box { background-image: image(%s); }" % cls._colors['gray50'])
css_list.append("#message_label { color: %s; }" % cls._colors['white_off'])
css_list.append("#warn_label { color: %s; }" % cls._colors['white_pp'])
css_list.append("#white_label { color: %s; }" % cls._colors['white_off'])
css_list.append("#black_label { color: %s; }" % cls._colors['gray95'])
css_list.append("#ppm_combo { background-image: image(%s); color: %s; }" %
(cls._colors['green'], cls._colors['black']))
css_list.append("button { background-image: image(%s); color: %s; }" %
(cls._colors['slate_lt'], cls._colors['black']))
css_list.append("entry { background-image: image(%s); color: %s; }" %
(cls._colors['green'], cls._colors['gray95']))
# Below format does not work.
css_list.append("entry:selected { background-image: image(%s); color: %s; }" %
(cls._colors['yellow'], cls._colors['white']))
else:
css_list.append(css_str)
LOGGER.info('css %s', css_list)
screen = Gdk.Screen.get_default()
for css_item in css_list:
provider = Gtk.CssProvider()
css = css_item.encode('utf-8')
provider.load_from_data(css)
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)