Manmax
Manmax

Reputation: 301

How to change color only one tab GtkNotebook

I'm working on Ubuntu 14 with GTK version 3.10.8. I wouldn't like to upgrade to Ubuntu 16 now…….

Nevertheless, I have a question of understanding with CSS and GtkNoteBook

My test

Is it possible to change color of tab for one tab only, like

GtkNotebook tab:nth-child(3) {} or
GtkNotebook tab:nth-child(4){} or
GtkNotebook tab:nth-child(5) etc …..

I Found it's ok or not for

/* first ok / / last ok */

/* odd ok */

/* even ok */

/* 1 ok */

/* 2n+1 ok */

/* 3n+4 non ok */

/* 2 non ok */

/* one non ok */

/* one non ok */

#!/usr/bin/python
# -*- coding: ISO-8859-1 -*-
# notebook_20.py
from gi.repository import Gtk, Gdk

def _destroy_cb(widget, data=None):
    Gtk.main_quit()

window = Gtk.Window()
window.connect("destroy", _destroy_cb)

screen = Gdk.Screen.get_default()

css_provider = Gtk.CssProvider()

css = """
        /* Theme any label within a notebook */
        GtkNotebook tab GtkLabel {background-color: green;color: cyan;}
        GtkNotebook > GtkLabel {background-color: pink;color: cyan;}


        GtkNotebook {              /*------  OR use " GtkNotebook#notebook OR GtkNotebook.mynotebook  */ 
        -GtkWidget-focus-line-width: 0;    /* Remove focus line (dotted line) around text on all tabs */
        -GtkNotebook-tab-overlap: 0; 
        padding: 10px 20px 10px 20px;
        border-radius: 15px; 
        border-width: 4px;               
        }   


        GtkLabel.first_label {        /* another way to select tab label */
        color: green;                 /* overides last font color selection  */
        font: Serif italic 10;        /* overides last font & font size selection */
        }

        /* first ok */
        /* last ok  */
        /* odd ok  */
        /* even ok  */
        /* 1 ok  */
        /* 2n+1 ok  */
        /* 3n+4 non ok  */
        /* 2 non ok  */
        /* one non ok  */
        /* one non ok  */

        GtkNotebook tab:nth-child(3n+4) {  /* modification 1er onglet tab "FirstTab */
        background-color: pink;             /* tab background color */
        color: green;                         /* tab font color */
        font: Sans 12;                      /* tab font & font size */
        }
        """
css_provider.load_from_data(css)


context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider,
                                Gtk.STYLE_PROVIDER_PRIORITY_USER)

box = Gtk.VBox()
window.add(box)

notebook = Gtk.Notebook()
box.pack_start(notebook, False, False, 0)

for i in range(10):
    bufferf = "Prepend Frame %d" % (i+1)
    bufferl = "Page %d" % (i+1)

    frame = Gtk.Frame()
    frame.set_border_width(10)
    frame.set_size_request(100, 75)
    label = Gtk.Label(bufferf)
    frame.add(label)
    label.show()

    label2 = Gtk.Label(bufferl)
    notebook.append_page(frame, label2)
    frame.show()

window.show_all()
Gtk.main()

Could you help me perhap must I change gtk version (now I have version 3.10.8 ) Thank you by advance

Upvotes: 1

Views: 1230

Answers (2)

Manmax
Manmax

Reputation: 301

ok thank you very much for your help. My understanding is : - GtkNotebook tab:nth-child(3) {} is "implemented" in CSS3 specification, but - not implemented in Gtk 3 at version 3.10.8.

In fact I changed my approch. first I would like manage a notebook. second when I changing date in tab child I would like indicate status modified if data no changed status is no modified After one or two night!!!, I found my need is to manage only two state.

my solution like is :

if status == 'modified';
    label.set_name ('modified)
else
    label.set_name ('no_modified)
.......

GtkNotebook > #no_modified {background-color: green;}
GtkNotebook > #modified {background-color: red;}

or something like that. I'm testing this next day. Thank you very much so one

Upvotes: 1

John F
John F

Reputation: 186

You could add a special CSS ID within the CSS string:

    #page2 {
        background-color: #0f0;
    }

Then set_name for "page 2" with page2. For example within in the for loop that creates the individual pages:

for i in range(10):
    ...
    label2 = Gtk.Label(bufferl)
    if i == 2:
        label2.set_name('page2')
    notebook.append_page(frame, label2)
    frame.show()

Upvotes: 0

Related Questions