#!/usr/bin/env python

from gi.repository import Gtk, Gdk, GObject

CSS = """
GtkLabel.left {
    background: red;
}
GtkLabel.right {
    background: green;
}
.tweak-titlebar-left:dir(ltr),
.tweak-titlebar-right:dir(rtl) {
    border-top-right-radius: 0;
}

.tweak-titlebar-right:dir(ltr),
.tweak-titlebar-left:dir(rtl) {
    border-top-left-radius: 0;
}

"""

class Window(Gtk.Window):
    
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_size_request(400, 400)
        self.connect("destroy", lambda q: Gtk.main_quit())
        
        paned = Gtk.Paned()
        paned.props.position = 150
        label1 = Gtk.Label("Left")
        label1.get_style_context().add_class("left")
        paned.pack1(label1)
        label2 = Gtk.Label("Right")
        label2.get_style_context().add_class("right")
        paned.pack2(label2)
        self.add(paned)
        
        header = Gtk.Box()
        hb1 = Gtk.HeaderBar()
        hb1.get_style_context().add_class("titlebar")
        hb1.get_style_context().add_class("tweak-titlebar-left")
        hb2 = Gtk.HeaderBar()
        hb2.get_style_context().add_class("titlebar")
        hb2.get_style_context().add_class("tweak-titlebar-right")
        hb2.props.show_close_button = True
        t1 = Gtk.Label("left")
        t1.get_style_context().add_class("title")
        hb1.set_custom_title(t1)
        t2 = Gtk.Label("right")
        t2.get_style_context().add_class("title")
        hb2.set_custom_title(t2)
        sep = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
        header.pack_start(hb1, False, False, 0)
        header.pack_start(sep, False, False, 0)
        header.pack_start(hb2, True, True, 0)
        self.set_titlebar(header)
        
        paned.bind_property("position", hb1, "width-request", GObject.BindingFlags.SYNC_CREATE)
        
        self.show_all()

        provider = Gtk.CssProvider()
        Gtk.StyleContext.add_provider_for_screen(Gdk.Display.get_default().get_default_screen(),
            provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
        provider.load_from_data(CSS)

if __name__ == "__main__":
    Window()
    Gtk.main()
