Python gi.repository.Gtk 模块,STYLE_PROVIDER_PRIORITY_USER 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_USER

项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def do_activate(self):
        print("Activating...")
        if not self._window:
            current_dir = os.path.dirname(os.path.abspath(__file__))
            css_provider = Gtk.CssProvider()
            css_provider.load_from_path(pkg_resources.resource_filename('ez_gpg',
                                                                        'data/application.css'))

            screen = Gdk.Screen.get_default()
            style_context = Gtk.StyleContext()
            style_context.add_provider_for_screen(screen,
                                                  css_provider,
                                                  Gtk.STYLE_PROVIDER_PRIORITY_USER)

            self._window = MainWindow(self)
            self._window.show_all()

        self.add_window(self._window)

        self._window.present()
项目:Icon-Requests    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gnome.IconRequests",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("Icon Requests"))
        GLib.set_prgname("Icon Requests")


        Gtk.Settings.get_default().set_property(
            "gtk-application-prefer-dark-theme", settings.get_is_night_mode())

        self.menu = Gio.Menu()
        cssProviderFile = Gio.File.new_for_uri(
            'resource:///org/gnome/IconRequests/css/style.css')
        cssProvider = Gtk.CssProvider()
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        try:
            cssProvider.load_from_file(cssProviderFile)
            styleContext.add_provider_for_screen(screen, cssProvider,
                                                 Gtk.STYLE_PROVIDER_PRIORITY_USER)
            logging.debug("Loading css file ")
        except Exception as e:
            logging.error("Error message %s" % str(e))
项目:cozy    作者:geigi    | 项目源码 | 文件源码
def __init_css(self):
        """
        Initialize the main css files and providers.
        Add css classes to the default screen style context.
        """
        if Gtk.get_minor_version() > 18:
            log.debug("Fanciest design possible")
            cssProviderFile = Gio.File.new_for_uri(
                "resource:///de/geigi/cozy/application.css")
        else:
            log.debug("Using legacy css file")
            cssProviderFile = Gio.File.new_for_uri(
                "resource:///de/geigi/cozy/application_legacy.css")
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_file(cssProviderFile)

        # add the bordered css class to the default screen for the borders around album art
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(
            screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
        styleContext.add_class("bordered")
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gnome.Authenticator",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("Gnome Authenticator"))
        GLib.set_prgname("Gnome Authenticator")

        self.observable = ApplicaitonObservable()

        self.menu = Gio.Menu()
        self.db = Database()

        result = GK.unlock_sync("org.gnome.Authenticator", None)
        if result == GK.Result.CANCELLED:
            self.quit()

        Gtk.Settings.get_default().set_property(
            "gtk-application-prefer-dark-theme", settings.get_is_night_mode())

        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            cssFileName = "org.gnome.Authenticator-post3.20.css"
        else:
            cssFileName = "org.gnome.Authenticator-pre3.20.css"
        cssProviderFile = Gio.File.new_for_uri(
            'resource:///org/gnome/Authenticator/%s' % cssFileName)
        cssProvider = Gtk.CssProvider()
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        try:
            cssProvider.load_from_file(cssProviderFile)
            styleContext.add_provider_for_screen(screen, cssProvider,
                                                 Gtk.STYLE_PROVIDER_PRIORITY_USER)
            logging.debug("Loading css file ")
        except Exception as e:
            logging.error("Error message %s" % str(e))
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _apply_css(config):
        if OSDWindow.css_provider:
            Gtk.StyleContext.remove_provider_for_screen(
                Gdk.Screen.get_default(), OSDWindow.css_provider)

        colors = {}
        for x in config['osk_colors'] : colors["osk_%s" % (x,)] = config['osk_colors'][x]
        for x in config['osd_colors'] : colors[x] = config['osd_colors'][x]
        colors = OSDCssMagic(colors)
        try:
            css_file = os.path.join(get_share_path(), "osd_styles", config["osd_style"])
            css = file(css_file, "r").read()
            if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)):
                css += OSDWindow.CSS_3_20
            OSDWindow.css_provider = Gtk.CssProvider()
            OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8"))
            Gtk.StyleContext.add_provider_for_screen(
                    Gdk.Screen.get_default(),
                    OSDWindow.css_provider,
                    Gtk.STYLE_PROVIDER_PRIORITY_USER)
        except GLib.Error, e:
            log.error("Failed to apply css with user settings:")
            log.error(e)
            log.error("Retrying with default values")

            OSDWindow.css_provider = Gtk.CssProvider()
            css_file = os.path.join(get_share_path(), "osd_styles", "Classic.gtkstyle.css")
            css = file(css_file, "r").read()
            if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)):
                css += OSDWindow.CSS_3_20
            OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8"))
            Gtk.StyleContext.add_provider_for_screen(
                    Gdk.Screen.get_default(),
                    OSDWindow.css_provider,
                    Gtk.STYLE_PROVIDER_PRIORITY_USER)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def install_error_css():
        if Editor._error_css_provider is None:
            Editor._error_css_provider = Gtk.CssProvider()
            Editor._error_css_provider.load_from_data(str(Editor.ERROR_CSS))
            Gtk.StyleContext.add_provider_for_screen(
                    Gdk.Screen.get_default(),
                    Editor._error_css_provider,
                    Gtk.STYLE_PROVIDER_PRIORITY_USER)
项目:MTodo    作者:mortezaipo    | 项目源码 | 文件源码
def load_style(self):
        """Load CSS theme."""
        style = Gtk.CssProvider()
        style.load_from_path(self.__config.software_style_file)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(),
            style,
            Gtk.STYLE_PROVIDER_PRIORITY_USER
        )

        if self.__config.software_is_dark_style == "true":
            settings = Gtk.Settings.get_default()
            settings.set_property("gtk-application-prefer-dark-theme", True)
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def apply_css():

    # Tested on Gtk 3.18/3.20

    alpha = "popover, .popover { opacity: 0.95; }"

    theme = "#notebook header { background: url('"\
    + theme_file + "') no-repeat center; background-size: cover; }"

    css = """

    #notebook tab { padding: 5px 10px 5px 10px; }
    #frame_main border, #frame_find border, #frame_vte border, #frame_status border,
    #frame_permission border, #frame_cert border, #frame_cookies border { border-style: none; }
    #frame_main, #frame_find, #frame_vte, #frame_status, #frame_permission, #frame_cert, #frame_cookies,
    #frame_mime border, #frame_mime { padding: 5px; }
    #notebook header { background: none; }
    #entry border { border-style: solid; }
    #label_x509 { padding: 10px; }
    #frame_x509 border { border-width: 0px 0px 1px 0px; }

    """

    if trans_pop: css += alpha

    if os.path.exists(theme_file):
        if is_image_valid(theme_file): css += theme

    cssprovider = Gtk.CssProvider()
    cssprovider.load_from_data(bytes(css.encode()))
    screen = Gdk.Screen.get_default()
    stylecontext = Gtk.StyleContext()
    stylecontext.add_provider_for_screen(screen, cssprovider, Gtk.STYLE_PROVIDER_PRIORITY_USER)