Pygobject (108) CSS Series--Blending mode

Source: Internet
Author: User
Tags gtk

Example

Blending mode determines how these two pictures are blended together, showing the appearance of the
Use the "Background-blend-mode" property setting example in CSS



Code:

#!/usr/bin/env Python3 # Created by Xiaosanyu in 16/7/19 # section 158 # Author:xiaosanyu # website:yuxiaosan.tk # HTTP://BLOG.CSDN.NET/A87B01C14 # Created:16/7/19 TITLE = "Blendmodes" DESCRIPTION = "" "You can blend multiple
Backgrounds using the CSS blend modes available. "" "Import gi gi.require_version (" GTK "," 3.0 ") from Gi.repository import Gtk, GdK, GLib, Gio, GObject import OS blend_m Odes = [{"Name": "Color", "id": "Color"}, {"Name": "Color (Burn)", "id": "Color-burn"}, {"Name": "Color" (DODG E) ", id": "Color-dodge"}, {"name": "Darken", "id": "Darken"}, {"name": "Difference", "id": "Difference"}, {"N
    Ame ": Exclusion", "id": "Exclusion"}, {"Name": "Hard Light", "id": "hard-light"}, {"Name": "Hue", "id": "Hue"}, {"Name": "Lighten", "id": "Lighten"}, {"Name": "Luminosity", "id": "luminosity"}, {"Name": "Multiply", "id": "m
    Ultiply "}, {" name ":" Normal "," id ":" normal "}, {" Name ":" Overlay "," id ":" Overlay "},{' name ': ' Saturate ', ' id ': ' saturate '}, {' Name ': ' Screen ', ' id ': ' Screen '}, {' name ': ' Soft Light ', ' id ': ' Soft-lig HT '},] class Cssblendmodeswindow (): Def __init__ (self): Builder = Gtk.Builder.new_from_resource ("/css/blend Modes.glade ") window = builder.get_object (" window ") Window.connect (" Destroy ", Gtk.main_quit) # Se Tup the CSS provider for window Provider = Gtk.cssprovider () Gtk.StyleContext.add_provider_for_screen (GDK .
                                                 Screen.get_default (), provider,
        gtk.style_provider_priority_application) Self.setup_listbox (builder, PROVIDER) Window.show_all () Gtk.main () def update_css_for_blend_mode (self, provider, Blend_mode): bytes = Gio.resources_lookup_da
        Ta ("/css/css_blendmodes.css", 0) CSS = Bytes.get_data (). Decode (' Utf-8 ')% (Blend_mode, Blend_mode, Blend_mode) Try:pRovider.load_from_data (Css.encode (' Utf-8 ')) except Glib.gerror as E:print (e) if E.domain != ' Gtk-css-provider-error-quark ': Raise e def row_activated (self, ListBox, row, provider): b Lend_mode = Blend_modes[row.get_index () ["id"] Self.update_css_for_blend_mode (provider, blend_mode) def setup _listbox (self, builder, provider): ListBox = Gtk.listbox () builder.get_object ("Scrolledwindow"). Add (Listbo x) listbox.connect ("row-activated", self.row_activated, provider) # ADD a row for each blend mode Availa
            ble for mode in Blend_modes:label = Gtk.label (label=mode["name"]) label.set_xalign (0) row = Gtk.listboxrow () row.add (label) listbox.add (Row) # The A-selected R 
        OW is "normal" if mode["id"] = = "normal": Normal_row = row # Select the ' normal ' row Listbox.select_Row (Normal_row) normal_row.emit ("Activate") Normal_row.grab_focus () def main (): Cssblendmodeswindow () if __name__ = = "__main__": Base_path = Os.path.abspath (Os.path.dirname (__file__)) Resource_path = Os.path.joi N (Base_path, '..
 /data/demo.gresource ') resource = Gio.Resource.load (Resource_path) gio.resources_register (Resource) Main ()

Layout file Blendmodes.glade

<?xml version= "1.0" encoding= "UTF-8"?> <interface> <requires lib= "GTK +" version= "3.20"/> <object class= "Gtkwindow" id= "window" > <property name= "can_focus" >False</property> <property name= "Resi" Zable ">False</property> <property name=" title >css Blend modes</property> <property name= "
      Default_width ">400</property> <property name=" Default_height ">300</property> <child> <object class= "Gtkgrid" > <property name= "visible" >True</property> <property name=  "Can_focus" >False</property> <property name= "Border_width" >12</property> <property Name= "row_spacing" >12</property> <property name= "column_spacing" >12</property> <c
            hild> <object class= "Gtklabel" > <property name= "visible" >True</property> <property name= "Can_focus ">False</property> <property name=" label "translatable=" Yes ">blend mode:</property&
            Gt
            <property name= "Xalign" >0</property> <style> <class name= "Dim-label"/> </style> </object> <packing> <property name= "Left_attach" &
        gt;0</property> <property name= "Top_attach" >0</property> </packing> </child> <child> <object class= "Gtkscrolledwindow" id= "Scrolledwindow" > &L
            T;property name= "visible" >True</property> <property name= "Can_focus" >True</property> <property name= "Vexpand" >True</property> <property name= "Shadow_type" >in</propert y> <property name= "min_content_width" >150</property> </object> <pa Cking>
          <property name= "Left_attach" >0</property> <property name= "Top_attach" >1</property>
            </packing> </child> <child> <object class= "Gtkstackswitcher" > <property name= "visible" >True</property> <property name= "Can_focus" >false</prope rty> <property name= "halign" >center</property> <property name= "Hexpand" >true& lt;/property> <property name= "stack" >stack</property> </object> <p acking> <property name= "Left_attach" >1</property> <property name= "Top_attach" ;0</property> </packing> </child> <child> <object class= "GT Kstack "id=" stack "> <property name=" visible ">True</property> <property name=" can _focus ""; false</property> <property name= "Hexpand" >True</property> <property name= "Vex Pand ">True</property> <property name=" hhomogeneous ">False</property> <prop Erty name= "vhomogeneous" >False</property> <property name= "Transition_type" >crossfade</proper ty> <child> <object class= "Gtkgrid" > <property name= "visible" & Gt  true</property> <property name= "Can_focus" >False</property> <property
                Name= "HAlign" >center</property> <property name= "valign" >center</property> <property name= "Hexpand" >False</property> <property name= "Vexpand" >true</proper ty> <property name= "row_spacing" >12</property> <property name= "column_sp Acing ">12</property> <child> <object class= "Gtklabel" > <property
                    Name= "visible" >True</property> <property name= "Can_focus" >False</property>
                  <property name= "label" translatable= "Yes" >Duck</property> </object>
                    <packing> <property name= "Left_attach" >0</property>
                <property name= "Top_attach" >0</property> </packing> </child> <child> <object class= "Gtklabel" > <property name= "Vis
                    Ible ">True</property> <property name=" Can_focus ">False</property>
                  <property name= "label" translatable= "Yes" >Background</property> </object> <packing&gT <property name= "Left_attach" >1</property> <property name= "Top_attach" >0</property > </packing> </child> <child>
                    ; object class= "Gtkimage" > <property name= "visible" >True</property> <property name= "Can_focus" >False</property> <style> <class
                    Name= "Duck"/> </style> </object> <packing> <property name= "Left_attach" >0</property> <property name= "Top_attach"
                  >1</property> </packing> </child> <child>
   <object class= "Gtkimage" > <property name= "visible" >True</property>                 <property name= "Can_focus" >False</property> <style>
                  <class name= "Gradient"/> </style> </object> <packing> <property name= "Left_attach" >1</property> <prope
                Rty name= "Top_attach" >1</property> </packing> </child> <child> <object class= "Gtklabel" > <property name= "visible" >tru e</property> <property name= "Can_focus" >False</property> <pro
                  Perty name= "label" translatable= "yes" > blended picture</property> </object> <packing> <property name= "Left_attach" >0</property> <pro Perty name= "Top_attach" &Gt;2</property> <property name= "width" >2</property> &LT;/PACKING&G
                T </child> <child> <object class= "Gtkimage" > <pro
                    Perty name= "visible" >True</property> <property name= "Can_focus" >False</property>
                      <property name= "HAlign" >center</property> <style>
                  <class name= "blend0"/> </style> </object> <packing> <property name= "Left_attach" >0</property> <proper
                  Ty name= "Top_attach" >3</property> <property name= "width" >2</property>
            </packing> </child> </object> <packing>    <property name= "name" >page0</property> <property name= "title" translatable= "Yes" >duc ky</property> </packing> </child> <child> < Object class= "Gtkgrid" > <
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.