Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Parsing


Actually, Kivy has the parser package that helps in the CSS parsing. Even though it is not a complete parsing, it helps to parse instructions related to a framework. The recipe will show some that you could find useful in your context.

How to do it…

The parser package has eight classes, so we will work in Python to review all of them. Let's follow the next steps:

  1. Import the parser package.

    from kivy.parser import *
    
  2. Parse a color from a string.

    parse_color('#090909')
    
  3. Parse a string to a string.

    parse_string("(a,1,2)")a
    
  4. Parse a string to a boolean value.

    parse_bool("0")
    
  5. Parse a string to a list of two integers.

    parse_int2("12 54")
    
  6. Parse a string to a list of four floats.

    parse_float4('54 87.13 35 0.9')
    
  7. Parse a file name.

    parse_filename('e7.py')
    

Finally, we have parse_int and parse_float, which are aliases of int and float, respectively.

How it works…

In the second step, we parse any of the common ways to define a color (that is, RGB(r, g, b), RGBA(r, g, b, a), aaa, rrggbb, #aaa or #rrggbb...