Example
Using CSS to implement Pygobject (84) Gdkpixbuf.pixbuf Example example
Code:
#!/usr/bin/env Python3 # Created by Xiaosanyu in 16/7/18 # section 157 # author:xiaosanyu # website:yuxiaosan.tk # HTTP://BLOG.CSDN.NET/A87B01C14 # CREATED:16/7/18 TITLE = "animated backgrounds" DESCRIPTION = "" "This demo is
Done in honour of the Pixbufs demo further down.
It is doing exclusively with CSS as the background of the window. "" "Import gi gi.require_version (' Gtk ', ' 3.0 ') from gi.repository import Gtk, GdK, Gio, GLib, Pango import OS class CSS
Pixbufwindow (Gtk.window): def __init__ (self): gtk.window.__init__ (Self, title= "animated backgrounds")
Self.set_default_size (paned) = gtk.vpaned () self.add (paned) Text = Gtk.textbuffer () Text.create_tag (tag_name= "Warning", Underline=pango.underline.single) Text.create_tag (tag_name= "error", Underl Ine=pango.underline.error) Provider = Gtk.cssprovider () container = Gtk.scrolledwindow () paned.a DD (container) child = GtK.textview.new_with_buffer (text) container.add (child) Text.connect ("changed", Self.css_text_changed, Provi Der) bytes = Gio.resources_lookup_data ("/css/css_pixbufs.css", 0) Text.set_text (Bytes.get_data (). Decode (' Utf-8 ')) provider.connect ("Parsing-error", Self.show_parsing_error, Child.get_buffer ()) Self.apply_css (s Elf, provider) def css_text_changed (self, buffer, provider): start = Buffer.get_start_iter () end = BU Ffer.get_end_iter () buffer.remove_all_tags (start, end) Text = Buffer.get_text (start, End, False). Encode (' Utf-8 ') # Ignore CSS errors as they are shown by highlighting Try:provider.load_from_data (Tex
T) except Glib.gerror as E:print (e) if E.domain!= ' Gtk-css-provider-error-quark ': Raise e Gtk.StyleContext.reset_widgets (Gdk.Screen.get_default ()) def show_parsing_error (self, provi Der, section, error, BUFFER): start = Buffer.get_iter_at_line_index (Section.get_start_line (),
Section.get_start_position ()) end = Buffer.get_iter_at_line_index (Section.get_end_line (),
Section.get_end_position ()) if Error.code = = Gtk.CssProviderError.DEPRECATED:
tag_name = "warning" else:tag_name = "error" Buffer.apply_tag_by_name (tag_name, start, end)
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) def main (Demoapp=none): W in = Csspixbufwindow () win.connect ("Delete-event", Gtk.main_quit) Win.show_all () Gtk.main () If __name__ = " __main__ ": 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) # Fixme:method Register () should be without t
He underscore # Fixme:see https://bugzilla.gnome.org/show_bug.cgi?id=684319 Resource._register () main ()
Css_pixbufs.css
/* You can edit the "* appearance of this window." * Is careful, if you are screw it up and nothing might is visible * anymore. :) * * * CSS resets all properties to their defaults values * and overrides all user settings and the theme in
Use */@import URL ("Resource://css/css_reset.css");
@import url ("Resource://css/css_view.css"); @keyframes Move-the-image {0% {background-position:50.00% 75%, 67.68% 67.68%, 75% 50%, 67.68% 32.32%, 50% 2 5%, 32.32% 32.32%, 25% 50%, 32.32% 67.68%, 0% 0%; } 3.125% {background-position:55.19% 76.11%, 72.14% 64.79%, 76.11% 44.81%, 64.79% 27.86%, 44.81% 23.89%, 27.86% 35.21%, 23.89% 55.19%, 35.21% 72.14%, 0% 0%; } 6.25% {background-position:60.79% 76.04%, 76.04% 60.79%, 76.04% 39.21%, 60.79% 23.96%, 39.21% 23.96%, 23.96% 39.21%, 2 3.96% 60.79%, 39.21% 76.04%, 0% 0%; } 9.375% {background-position:66.46% 74.64%, 79.06% 55.78%, 74.64% 33.54%, 55.78% 20.94%, 33.54% 25.36%, 20.94% 44.22%, 25.36% 66.46%, 44.22% 79.06%, 0% 0%; } 12.5% {background-position:71.84% 71.84%, 80.89% 50%, 71.84% 28.16%, 50% 19.11%, 28.16% 28.16%, 19.11% 50%, 2 8.16% 71.84%, 50% 80.89%, 0% 0%; } 15.625% {background-position:76.55% 67.74%, 81.32% 43.77%, 67.74% 23.45%, 43.77% 18.68%, 23.45% 32.26%, 18.68% 56.23%, 32.26% 76.55%, 56.23% 81.32%, 0% 0%; } 18.75% {background-position:80.21% 62.51%, 80.21% 37.49%, 62.51% 19.79%, 37.49% 19.79%, 19.79% 37.49%, 19.79% 62.51%, 37.49% 80.21%, 62.51% 80.21%, 0% 0%; } 21.875% {background-position:82.54% 56.47%, 77.58% 31.57%, 56.47% 17.46%, 31.57% 22.42%, 17.46% 43.53%, 22.42% 68.43%, 43.53% 82.54%, 68.43% 77.58%, 0% 0%; } 25% {background-position:83.33% 50%, 73.57% 26.43%, 50% 16.67%, 26.43% 26.43%, 16.67% 50%, 26.43% 73.57%, 50. 0% 83.33%, 73.57% 73.57%, 0% 0%; } 28.125% {background-position:82.54% 43.53%, 68.43% 22.42%, 43.53% 17.46%, 22.42% 31.57%, 17.46% 56.47%, 31.57% 77.58%, 56.47% 82.54%, 77.58% 68.43%, 0% 0%; } 31.25% {Background-position:80.21% 37.49%, 62.51% 19.79%, 37.49% 19.79%, 19.79% 37.49%, 19.79% 62.51%, 37.49% 80.21%, 62.51% 80.21%, 80.21% 62.51%, 0% 0%; } 34.375% {background-position:76.55% 32.26%, 56.23% 18.68%, 32.26% 23.45%, 18.68% 43.77%, 23.45% 67.74%, 43.77% 81.32%, 67.74% 76.55%, 81.32% 56.23%, 0% 0%; } 37.5% {background-position:71.84% 28.16%, 50% 19.11%, 28.16% 28.16%, 19.11% 50%, 28.16% 71.84%, 50% 80.89%, 7 1.84% 71.84%, 80.89% 50%, 0% 0%; } 40.625% {background-position:66.46% 25.36%, 44.22% 20.94%, 25.36% 33.54%, 20.94% 55.78%, 33.54% 74.64%, 55.78% 79.06%, 74.64% 66.46%, 79.06% 44.22%, 0% 0%; } 43.75% {background-position:60.79% 23.96%, 39.21% 23.96%, 23.96% 39.21%, 23.96% 60.79%, 39.21% 76.04%, 60.79% 76.04%, 76.04% 60.79%, 76.04% 39.21%, 0% 0%; } 46.875% {background-position:55.19% 23.89%, 35.21% 27.86%, 23.89% 44.81%, 27.86% 64.79%, 44.81% 76.11%, 64.79% 72.14%, 76.11% 55.19%, 72.14% 35.21%, 0% 0%; } 50% {background-position:50.00% 25%, 32.32% 32.32%,25% 50%, 32.32% 67.68%, 50% 75%, 67.68% 67.68%, 75% 50%, 67.68% 32.32%, 0% 0%; } 53.125% {background-position:45.44% 27.07%, 30.57% 37.01%, 27.07% 54.56%, 37.01% 69.43%, 54.56% 72.93%, 69.43% 62.99%, 72.93% 45.44%, 62.99% 30.57%, 0% 0%; } 56.25% {background-position:41.65% 29.85%, 29.85% 41.65%, 29.85% 58.35%, 41.65% 70.15%, 58.35% 70.15%, 70.15% 58.35%, 70.15% 41.65%, 58.35% 29.85%, 0% 0%; } 59.375% {background-position:38.68% 33.06%, 30.02% 46.03%, 33.06% 61.32%, 46.03% 69.98%, 61.32% 66.94%, 69.98% 53.97%, 66.94% 38.68%, 53.97% 30.02%, 0% 0%; } 62.5% {background-position:36.49% 36.49%, 30.89% 50%, 36.49% 63.51%, 50% 69.11%, 63.51% 63.51%, 69.11% 50%, 6 3.51% 36.49%, 50% 30.89%, 0% 0%; } 65.625% {background-position:34.97% 39.96%, 32.28% 53.53%, 39.96% 65.03%, 53.53% 67.72%, 65.03% 60.04%, 67.72% 46.47%, 60.04% 34.97%, 46.47% 32.28%, 0% 0%; } 68.75% {background-position:34.02% 43.38%, 34.02% 56.62%, 43.38% 65.98%, 56.62% 65.98%, 65.98% 56.62%, 65.98% 43.38%, 56.62% 34.02%, 43.38% 34.02%, 0% 0%; } 71.