Python gi.repository.Gtk 模块,StyleContext() 实例源码

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

项目: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()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_button_press(self,widget,event):
        # tool_dict = {"browser": step_func.func0,
        #              "alienarena": step_func.func1,
        #              "live": step_func.func2,
        #              "cs-network": step_func.func3
        #              }

        button_pressed = event.button
        a=widget.label

        if button_pressed ==1:
            self.stepgrid.maingrid.contentbox.set_new(a)
            if widget.get_state()==Gtk.StateType.NORMAL:
                #set clicked to selected
                for widgets in self.stepgrid.widgetlist.list:
                    if widgets.get_state()==Gtk.StateType.SELECTED:
                        widgets.set_state(Gtk.StateType.NORMAL)
                        Gtk.StyleContext.remove_class(widgets.get_style_context(), "highlighted")

                Gtk.StyleContext.add_class(widget.get_style_context(), "highlighted")
                widget.set_state(Gtk.StateType.SELECTED)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def tool_btn_toggled(self,button):
        tool_dict = {"browser": tool_func.func0,
                     "alienarena": tool_func.func1,
                     "live": tool_func.func2,
                     "cs-network": tool_func.func3
                     }
        if button.get_active():
            state = "on"
            Gtk.StyleContext.add_class(button.get_style_context(), "toggleasd")
            btn_func_exist = button.name in tool_dict
            if btn_func_exist:
                tool_dict[button.name](button.name)
        else:
            state = "off"
            Gtk.StyleContext.remove_class(button.get_style_context(), "toggleasd")

        # print(button.name, "has been turned", state)
项目: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))
项目: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)