(self)
Update configuration for the whole application
Update configuration for the whole application
Update configuration for the whole application
def reconfigure(self):
        """Update configuration for the whole application"""

        if self.style_providers != []:
            for style_provider in self.style_providers:
                Gtk.StyleContext.remove_provider_for_screen(
                    Gdk.Screen.get_default(),
                    style_provider)
        self.style_providers = []

        # Force the window background to be transparent for newer versions of
        # GTK3. We then have to fix all the widget backgrounds because the
        # widgets theming may not render it's own background.
        css = """
            .terminator-terminal-window {
                background-color: alpha(@theme_bg_color,0); }

            .terminator-terminal-window .notebook.header,
            .terminator-terminal-window notebook header {
                background-color: @theme_bg_color; }

            .terminator-terminal-window .pane-separator {
                background-color: @theme_bg_color; }

            .terminator-terminal-window .terminator-terminal-searchbar {
                background-color: @theme_bg_color; }
            """

        # Fix several themes that put a borders, corners, or backgrounds around
        # viewports, making the titlebar look bad.
        css += """
            .terminator-terminal-window GtkViewport,
            .terminator-terminal-window viewport {
                border-width: 0px;
                border-radius: 0px;
                background-color: transparent; }
            """

        # Add per profile snippets for setting the background of the HBox
        template = """
            .terminator-profile-%s {
                background-color: alpha(%s, %s); }
            """
        profiles = self.config.base.profiles
        for profile in list(profiles.keys()):
            if profiles[profile]['use_theme_colors']:
                # Create a dummy window/vte and realise it so it has correct
                # values to read from
                tmp_win = Gtk.Window()
                tmp_vte = Vte.Terminal()
                tmp_win.add(tmp_vte)
                tmp_win.realize()
                bgcolor = tmp_vte.get_style_context().get_background_color(Gtk.StateType.NORMAL)
                bgcolor = "#{0:02x}{1:02x}{2:02x}".format(int(bgcolor.red  * 255),
                                                          int(bgcolor.green * 255),
                                                          int(bgcolor.blue * 255))
                tmp_win.remove(tmp_vte)
                del(tmp_vte)
                del(tmp_win)
            else:
                bgcolor = Gdk.RGBA()
                bgcolor = profiles[profile]['background_color']
            if profiles[profile]['background_type'] == 'image':
                backgound_image = profiles[profile]['background_image']
            if profiles[profile]['background_type'] == 'transparent' or profiles[profile]['background_type'] == 'image':
                bgalpha = profiles[profile]['background_darkness']
            else:
                bgalpha = "1"

            munged_profile = "".join([c if c.isalnum() else "-" for c in profile])
            css += template % (munged_profile, bgcolor, bgalpha)

        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(css.encode('utf-8'))
        self.style_providers.append(style_provider)

        # Attempt to load some theme specific stylistic tweaks for appearances
        usr_theme_dir = os.path.expanduser('~/.local/share/themes')
        (head, _tail) = os.path.split(borg.__file__)
        app_theme_dir = os.path.join(head, 'themes')

        theme_name = self.gtk_settings.get_property('gtk-theme-name')

        theme_part_list = ['terminator.css']
        if self.config['extra_styling']:    # checkbox_style - needs adding to prefs
            theme_part_list.append('terminator_styling.css')
        for theme_part_file in theme_part_list:
            for theme_dir in [usr_theme_dir, app_theme_dir]:
                path_to_theme_specific_css = os.path.join(theme_dir,
                                                          theme_name,
                                                          'gtk-3.0/apps',
                                                          theme_part_file)
                if os.path.isfile(path_to_theme_specific_css):
                    style_provider = Gtk.CssProvider()
                    style_provider.connect('parsing-error', self.on_css_parsing_error)
                    try:
                        style_provider.load_from_path(path_to_theme_specific_css)
                    except GError:
                        # Hmmm. Should we try to provide GTK version specific files here on failure?
                        gtk_version_string = '.'.join([str(Gtk.get_major_version()),
                                                       str(Gtk.get_minor_version()),
                                                       str(Gtk.get_micro_version())])
                        err('Error(s) loading css from %s into Gtk %s' % (path_to_theme_specific_css,
                                                                          gtk_version_string))
                    self.style_providers.append(style_provider)
                    break

        # Size the GtkPaned splitter handle size.
        css = ""
        if self.config['handle_size'] in range(0, 21):
            css += """
                .terminator-terminal-window separator {
                    min-height: %spx;
                    min-width: %spx; 
                }
                """ % (self.config['handle_size'],self.config['handle_size'])
        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(css.encode('utf-8'))
        self.style_providers.append(style_provider)

        # Apply the providers, incrementing priority so they don't cancel out
        # each other
        for idx in range(0, len(self.style_providers)):
            Gtk.StyleContext.add_provider_for_screen(
                Gdk.Screen.get_default(),
                self.style_providers[idx],
                Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION+idx)

        # Cause all the terminals to reconfigure
        for terminal in self.terminals:
            terminal.reconfigure()

        # Reparse our keybindings
        self.keybindings.configure(self.config['keybindings'])

        # Update tab position if appropriate
        maker = Factory()
        for window in self.windows:
            child = window.get_child()
            if maker.isinstance(child, 'Notebook'):
                child.configure()
def reconfigure ( self ) : if self . style_providers != [ ] : for style_provider in self . style_providers : Gtk . StyleContext . remove_provider_for_screen ( Gdk . Screen . get_default ( ) , style_provider ) self . style_providers = [ ] # Force the window background to be transparent for newer versions of # GTK3. We then have to fix all the widget backgrounds because the # widgets theming may not render it's own background. css = """
            .terminator-terminal-window {
                background-color: alpha(@theme_bg_color,0); }

            .terminator-terminal-window .notebook.header,
            .terminator-terminal-window notebook header {
                background-color: @theme_bg_color; }

            .terminator-terminal-window .pane-separator {
                background-color: @theme_bg_color; }

            .terminator-terminal-window .terminator-terminal-searchbar {
                background-color: @theme_bg_color; }
            """ # Fix several themes that put a borders, corners, or backgrounds around # viewports, making the titlebar look bad. css += """
            .terminator-terminal-window GtkViewport,
            .terminator-terminal-window viewport {
                border-width: 0px;
                border-radius: 0px;
                background-color: transparent; }
            """ # Add per profile snippets for setting the background of the HBox template = """
            .terminator-profile-%s {
                background-color: alpha(%s, %s); }
            """ profiles = self . config . base . profiles for profile in list ( profiles . keys ( ) ) : if profiles [ profile ] [ 'use_theme_colors' ] : # Create a dummy window/vte and realise it so it has correct # values to read from tmp_win = Gtk . Window ( ) tmp_vte = Vte . Terminal ( ) tmp_win . add ( tmp_vte ) tmp_win . realize ( ) bgcolor = tmp_vte . get_style_context ( ) . get_background_color ( Gtk . StateType . NORMAL ) bgcolor = "#{0:02x}{1:02x}{2:02x}" . format ( int ( bgcolor . red * 255 ) , int ( bgcolor . green * 255 ) , int ( bgcolor . blue * 255 ) ) tmp_win . remove ( tmp_vte ) del ( tmp_vte ) del ( tmp_win ) else : bgcolor = Gdk . RGBA ( ) bgcolor = profiles [ profile ] [ 'background_color' ] if profiles [ profile ] [ 'background_type' ] == 'image' : backgound_image = profiles [ profile ] [ 'background_image' ] if profiles [ profile ] [ 'background_type' ] == 'transparent' or profiles [ profile ] [ 'background_type' ] == 'image' : bgalpha = profiles [ profile ] [ 'background_darkness' ] else : bgalpha = "1" munged_profile = "" . join ( [ c if c . isalnum ( ) else "-" for c in profile ] ) css += template % ( munged_profile , bgcolor , bgalpha ) style_provider = Gtk . CssProvider ( ) style_provider . load_from_data ( css . encode ( 'utf-8' ) ) self . style_providers . append ( style_provider ) # Attempt to load some theme specific stylistic tweaks for appearances usr_theme_dir = os . path . expanduser ( '~/.local/share/themes' ) ( head , _tail ) = os . path . split ( borg . __file__ ) app_theme_dir = os . path . join ( head , 'themes' ) theme_name = self . gtk_settings . get_property ( 'gtk-theme-name' ) theme_part_list = [ 'terminator.css' ] if self . config [ 'extra_styling' ] : # checkbox_style - needs adding to prefs theme_part_list . append ( 'terminator_styling.css' ) for theme_part_file in theme_part_list : for theme_dir in [ usr_theme_dir , app_theme_dir ] : path_to_theme_specific_css = os . path . join ( theme_dir , theme_name , 'gtk-3.0/apps' , theme_part_file ) if os . path . isfile ( path_to_theme_specific_css ) : style_provider = Gtk . CssProvider ( ) style_provider . connect ( 'parsing-error' , self . on_css_parsing_error ) try : style_provider . load_from_path ( path_to_theme_specific_css ) except GError : # Hmmm. Should we try to provide GTK version specific files here on failure? gtk_version_string = '.' . join ( [ str ( Gtk . get_major_version ( ) ) , str ( Gtk . get_minor_version ( ) ) , str ( Gtk . get_micro_version ( ) ) ] ) err ( 'Error(s) loading css from %s into Gtk %s' % ( path_to_theme_specific_css , gtk_version_string ) ) self . style_providers . append ( style_provider ) break # Size the GtkPaned splitter handle size. css = "" if self . config [ 'handle_size' ] in range ( 0 , 21 ) : css += """
                .terminator-terminal-window separator {
                    min-height: %spx;
                    min-width: %spx; 
                }
                """ % ( self . config [ 'handle_size' ] , self . config [ 'handle_size' ] ) style_provider = Gtk . CssProvider ( ) style_provider . load_from_data ( css . encode ( 'utf-8' ) ) self . style_providers . append ( style_provider ) # Apply the providers, incrementing priority so they don't cancel out # each other for idx in range ( 0 , len ( self . style_providers ) ) : Gtk . StyleContext . add_provider_for_screen ( Gdk . Screen . get_default ( ) , self . style_providers [ idx ] , Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION + idx ) # Cause all the terminals to reconfigure for terminal in self . terminals : terminal . reconfigure ( ) # Reparse our keybindings self . keybindings . configure ( self . config [ 'keybindings' ] ) # Update tab position if appropriate maker = Factory ( ) for window in self . windows : child = window . get_child ( ) if maker . isinstance ( child , 'Notebook' ) : child . configure ( )