Pygobject (103) CSS Series--transition transition effect

Source: Internet
Author: User
Tags border color gtk

Example

Example


Code:

#!/usr/bin/env Python3 # Section 153 #-*-Mode:python; Py-indent-offset:4-*-# vim:tabstop=4 shiftwidth=4 expandtab # Copyright (C) 2013 Gian Mario Tagliaretti <gianmt@g Nome.org> # This library are free software; Can redistribute it and/or # modify it under the terms of the GNU Lesser General public # License as published by the Free Software Foundation;
Either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it'll be useful, # but without any WARRANTY;  Without even the implied warranty of # merchantability or FITNESS for A particular purpose.
The GNU # Lesser general public License for more details. # You are should have received a copy of the GNU Lesser General public # License along and this library; If not, write to the free Software # Foundation, INC, Wuyi Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA TITLE = "CSS accordion" DESCRIPTION = "" "A Simple accordion Demo written usingCSS transitions and multiple backgrounds. "" "Import gi gi.require_version (' Gtk ', ' 3.0 ') from gi.repository import GTK, Gio class Cssaccordionapp:def __ini T__ (self): window = Gtk.window () window.set_title (' CSS accordion ') window.set_default_size (600, 30 0) Window.set_border_width (window.connect) (' Destroy ', gtk.main_quit) Hbox = Gtk.box (homogeneou S=false, spacing=2, Orientation=gtk.orientation.horizontal) hbox.set_halign (Gtk.Align.CENTE R) hbox.set_valign (Gtk.Align.CENTER) Window.add (Hbox) for label in ("This", ' is ', ' A ', ' CSS ', ' Ac Cordion ', ':-) '): Hbox.add (Gtk.button (label=label)) bytes = Gio.resources_lookup_data ("/css/css_accor Dion.css ", 0) Provider = Gtk.cssprovider () provider.load_from_data (Bytes.get_data ()) Self.apply_c SS (window, provider) Window.show_all () def apply_css (self, widget, provider): GTK.Stylecontext.add_provider (Widget.get_style_context (), provider, gtk.style_provider_priority_application) if Isinstance (widget, Gtk.container): WIDG Et.forall (Self.apply_css, provider) def main (): Cssaccordionapp () Gtk.main () if __name__ = = ' __main__ ': IM Port OS base_path = Os.path.abspath (Os.path.dirname (__file__)) Resource_path = Os.path.join (Base_path, '..
 /data/demo.gresource ') resource = Gio.Resource.load (Resource_path) gio.resources_register (Resource) Main ()

Css_accordion.css

@import url ("Resource://css/css_reset.css");
    * {transition-property:color, background-color, Border-color, background-image, padding, border-width; transition-duration:500ms;
    /* Transition time 500ms*/Font-family:sans, Arial, Helvetica; font-size:20px; /* Set font and size//} window {/* set window background/background:linear-gradient (153deg, #151515, #151515 5px, Transparent 5p x) 0 0, Linear-gradient (333deg, #151515, #151515 5px, transparent 5px) 10px 5px, Linear-gradient (153deg, #222, #22 2 5px, transparent 5px) 0 5px, Linear-gradient (333deg, #222, #222 5px, transparent 5px) 10px 10px, linear-gradient (90deg, #1b1b1b, #1b1b1b 10px, Transparent 10px), Linear-gradient (#1d1d1d, #1d1d1d 25%, #1a1a1a 25%, #1a1a1a 50%, Tran
    Sparent 50%, Transparent 75%, #242424 75%, #242424);
    Background-color: #131313;
background-size:20px 20px; button {/* Set button Default Style * * Color:black/* Text color/background-color: #bbb/* background color/border-style:solid; /* Border Style, solid */border-width:2px 0 2px 2px; /* Border Width * * Border-color: #333; /* Border color */padding:12px 4px;

/* Text and button spacing/* * Set the first button to the upper left and lower left corner fillet size * * Button:first-child {border-radius:10px 0 0 10px;}
    /* Set the last button to the right and lower right corner fillet size * * Button:last-child {border-radius:0 10px 10px 0;
border-width:2px;
    * * Mouse hover increase the left and right space between the text and button, change the background color * * Button:hover {padding:12px 48px;
Background-color: #4870bc;

Button *:hover {color:white}
 /* Click on the button background color/button:hover:active, button:active {background-color: #993401;}

Css_reset.css
Clears all CSS properties

/* @import This colorsheet to get the default values for every property.
 * This is useful when writing special CSS tests which should not being * inluenced by themes-not even the default ones.
 * Keep in mind that the output would be very ugly and don't look like * anything GTK.
 * Also, when adding new style properties, please add them here.
  * * {color:inherit;
  Font-size:inherit;
  background-color:initial;
  Font-family:inherit;
  Font-style:inherit;
  Font-variant:inherit;
  Font-weight:inherit;
  Text-shadow:inherit;
  -gtk-icon-shadow:inherit;
  box-shadow:initial;
  margin-top:initial;
  margin-left:initial;
  margin-bottom:initial;
  margin-right:initial;
  padding-top:initial;
  padding-left:initial;
  padding-bottom:initial;
  padding-right:initial;
  border-top-style:initial;
  border-top-width:initial;
  border-left-style:initial;
  border-left-width:initial;
  border-bottom-style:initial;
  border-bottom-width:initial; Border-right-style:iniTial
  border-right-width:initial;
  border-top-left-radius:initial;
  border-top-right-radius:initial;
  border-bottom-right-radius:initial;
  border-bottom-left-radius:initial;
  outline-style:initial;
  outline-width:initial;
  outline-offset:initial;
  background-clip:initial;
  background-origin:initial;
  background-size:initial;
  background-position:initial;
  border-top-color:initial;
  border-right-color:initial;
  border-bottom-color:initial;
  border-left-color:initial;
  outline-color:initial;
  background-repeat:initial;
  background-image:initial;
  border-image-source:initial;
  border-image-repeat:initial;
  border-image-slice:initial;
  border-image-width:initial;
  transition-property:initial;
  transition-duration:initial;
  transition-timing-function:initial;
  transition-delay:initial;
  engine:initial;

  -gtk-key-bindings:initial;
  -gtkwidget-focus-line-width:0;
  -gtkwidget-focus-padding:0;
-gtknotebook-initial-gap:0;
 }

Code resolution:
Load resource file First

Base_path = Os.path.abspath (Os.path.dirname (__file__))
    Resource_path = Os.path.join (Base_path, '.. /data/demo.gresource ')
    resource = Gio.Resource.load (Resource_path)
    Gio.resources_register (Resource)

Create a 6 button

For label in ("This", ' is ', ' A ', ' CSS ', ' accordion ', ':-) '):
            hbox.add (Gtk.button (Label=label))

Find a Style file

bytes = Gio.resources_lookup_data ("/css/css_accordion.css", 0)

Creating Gtk.cssprovider, loading CSS style files

Provider = Gtk.cssprovider ()
Provider.load_from_data (Bytes.get_data ())

Apply a style to all parts where a Widget.forall () method is used, and if the widget is a container, continue to invoke the Apply_css method on the child part

def apply_css (self, widget, provider):
    Gtk.StyleContext.add_provider (
              widget.get_style_context (), provider ,                                                                 gtk.style_provider_priority_application)

    if Isinstance (widget, Gtk.container):
       Widget.forall ( SELF.APPLY_CSS, provider)





Code Download Address: http://download.csdn.net/detail/a87b01c14/9594728

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.