本文整理汇总了Python中scss.types.Number类的典型用法代码示例。如果您正苦于以下问题:Python Number类的具体用法?Python Number怎么用?Python Number使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Number类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sprite
def sprite(map, sprite, offset_x=None, offset_y=None, cache_buster=True):
"""
Returns the image and background position for use in a single shorthand
property
"""
map = map.render()
sprite_map = sprite_maps.get(map)
sprite_name = String.unquoted(sprite).value
sprite = sprite_map and sprite_map.get(sprite_name)
if not sprite_map:
log.error("No sprite map found: %s", map, extra={'stack': True})
elif not sprite:
log.error("No sprite found: %s in %s", sprite_name, sprite_map['*n*'], extra={'stack': True})
if sprite:
url = '%s%s' % (config.ASSETS_URL, sprite_map['*f*'])
if cache_buster:
url += '?_=%s' % sprite_map['*t*']
x = Number(offset_x or 0, 'px')
y = Number(offset_y or 0, 'px')
if not x.value or (x.value <= -1 or x.value >= 1) and not x.is_simple_unit('%'):
x -= Number(sprite[2], 'px')
if not y.value or (y.value <= -1 or y.value >= 1) and not y.is_simple_unit('%'):
y -= Number(sprite[3], 'px')
url = "url(%s)" % escape(url)
return List([String.unquoted(url), x, y])
return List([Number(0), Number(0)])
示例2: sprite_position
def sprite_position(map, sprite, offset_x=None, offset_y=None):
"""
Returns the position for the original image in the sprite.
This is suitable for use as a value to background-position.
"""
map = map.render()
sprite_map = sprite_maps.get(map)
sprite_name = String.unquoted(sprite).value
sprite = sprite_map and sprite_map.get(sprite_name)
if not sprite_map:
log.error("No sprite map found: %s", map, extra={'stack': True})
elif not sprite:
log.error("No sprite found: %s in %s", sprite_name, sprite_map['*n*'], extra={'stack': True})
if sprite:
x = None
if offset_x is not None and not isinstance(offset_x, Number):
x = offset_x
if not x or x.value not in ('left', 'right', 'center'):
if x:
offset_x = None
x = Number(offset_x or 0, 'px')
if not x.value or (x.value <= -1 or x.value >= 1) and not x.is_simple_unit('%'):
x -= Number(sprite[2], 'px')
y = None
if offset_y is not None and not isinstance(offset_y, Number):
y = offset_y
if not y or y.value not in ('top', 'bottom', 'center'):
if y:
offset_y = None
y = Number(offset_y or 0, 'px')
if not y.value or (y.value <= -1 or y.value >= 1) and not y.is_simple_unit('%'):
y -= Number(sprite[3], 'px')
return List([x, y])
return List([Number(0), Number(0)])
示例3: __grad_position
def __grad_position(index, default, radial, color_stops):
try:
stops = Number(color_stops[index][0])
if radial and not stops.is_simple_unit('px') and (index == 0 or index == -1 or index == len(color_stops) - 1):
log.warn("Webkit only supports pixels for the start and end stops for radial gradients. Got %s", stops)
except IndexError:
stops = Number(default)
return stops
示例4: sprite_map
def sprite_map(g, **kwargs):
"""
Generates a sprite map from the files matching the glob pattern.
Uses the keyword-style arguments passed in to control the placement.
$direction - Sprite map layout. Can be `vertical` (default), `horizontal`, `diagonal` or `smart`.
$position - For `horizontal` and `vertical` directions, the position of the sprite. (defaults to `0`)
$<sprite>-position - Position of a given sprite.
$padding, $spacing - Adds paddings to sprites (top, right, bottom, left). (defaults to `0, 0, 0, 0`)
$<sprite>-padding, $<sprite>-spacing - Padding for a given sprite.
$dst-color - Together with `$src-color`, forms a map of source colors to be converted to destiny colors (same index of `$src-color` changed to `$dst-color`).
$<sprite>-dst-color - Destiny colors for a given sprite. (defaults to `$dst-color`)
$src-color - Selects source colors to be converted to the corresponding destiny colors. (defaults to `black`)
$<sprite>-dst-color - Source colors for a given sprite. (defaults to `$src-color`)
$collapse - Collapses every image in the sprite map to a fixed size (`x` and `y`).
$collapse-x - Collapses a size for `x`.
$collapse-y - Collapses a size for `y`.
"""
if not Image:
raise Exception("Images manipulation require PIL")
now_time = time.time()
g = String(g, quotes=None).value
if g in sprite_maps:
sprite_maps[glob]['*'] = now_time
elif '..' not in g: # Protect against going to prohibited places...
if callable(config.STATIC_ROOT):
glob_path = g
rfiles = files = sorted(config.STATIC_ROOT(g))
else:
glob_path = os.path.join(config.STATIC_ROOT, g)
files = glob.glob(glob_path)
files = sorted((f, None) for f in files)
rfiles = [(rf[len(config.STATIC_ROOT):], s) for rf, s in files]
if not files:
log.error("Nothing found at '%s'", glob_path)
return String.unquoted('')
map_name = os.path.normpath(os.path.dirname(g)).replace('\\', '_').replace('/', '_')
key = [f for (f, s) in files] + [repr(kwargs), config.ASSETS_URL]
key = map_name + '-' + make_filename_hash(key)
asset_file = key + '.png'
ASSETS_ROOT = config.ASSETS_ROOT or os.path.join(config.STATIC_ROOT, 'assets')
asset_path = os.path.join(ASSETS_ROOT, asset_file)
cache_path = os.path.join(config.CACHE_ROOT or ASSETS_ROOT, asset_file + '.cache')
inline = Boolean(kwargs.get('inline', False))
sprite_map = None
asset = None
file_asset = None
inline_asset = None
if os.path.exists(asset_path) or inline:
try:
save_time, file_asset, inline_asset, sprite_map, sizes = pickle.load(open(cache_path))
if file_asset:
sprite_maps[file_asset.render()] = sprite_map
if inline_asset:
sprite_maps[inline_asset.render()] = sprite_map
if inline:
asset = inline_asset
else:
asset = file_asset
except:
pass
if sprite_map:
for file_, storage in files:
_time = getmtime(file_, storage)
if save_time < _time:
if _time > now_time:
log.warning("File '%s' has a date in the future (cache ignored)" % file_)
sprite_map = None # Invalidate cached sprite map
break
if sprite_map is None or asset is None:
cache_buster = Boolean(kwargs.get('cache_buster', True))
direction = String.unquoted(kwargs.get('direction', config.SPRTE_MAP_DIRECTION)).value
repeat = String.unquoted(kwargs.get('repeat', 'no-repeat')).value
collapse = kwargs.get('collapse', Number(0))
if isinstance(collapse, List):
collapse_x = int(Number(collapse[0]).value)
collapse_y = int(Number(collapse[-1]).value)
else:
collapse_x = collapse_y = int(Number(collapse).value)
if 'collapse_x' in kwargs:
collapse_x = int(Number(kwargs['collapse_x']).value)
if 'collapse_y' in kwargs:
collapse_y = int(Number(kwargs['collapse_y']).value)
position = Number(kwargs.get('position', 0))
if not position.is_simple_unit('%') and position.value > 1:
#.........这里部分代码省略.........
示例5: to_lower_case
def to_lower_case(string):
expect_type(string, String)
return String(string.value.lower(), quotes=string.quotes)
# ------------------------------------------------------------------------------
# Number functions
@ns.declare
def percentage(value):
expect_type(value, Number, unit=None)
return value * Number(100, unit='%')
ns.set_function('abs', 1, Number.wrap_python_function(abs))
ns.set_function('round', 1, Number.wrap_python_function(round))
ns.set_function('ceil', 1, Number.wrap_python_function(math.ceil))
ns.set_function('floor', 1, Number.wrap_python_function(math.floor))
# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
if separator is None:
separator = 'auto'
separator = String.unquoted(separator).value
if separator == 'comma':
return True
示例6: to_lower_case
@register('to-lower-case', 1)
def to_lower_case(string):
expect_type(string, String)
return String(string.value.lower(), quotes=string.quotes)
# ------------------------------------------------------------------------------
# Number functions
@register('percentage', 1)
def percentage(value):
expect_type(value, Number, unit=None)
return value * Number(100, unit='%')
CORE_LIBRARY.add(Number.wrap_python_function(abs), 'abs', 1)
CORE_LIBRARY.add(Number.wrap_python_function(round), 'round', 1)
CORE_LIBRARY.add(Number.wrap_python_function(math.ceil), 'ceil', 1)
CORE_LIBRARY.add(Number.wrap_python_function(math.floor), 'floor', 1)
# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
if separator is None:
separator = 'auto'
separator = String.unquoted(separator).value
if separator == 'comma':
return True
示例7: ValueError
raise ValueError("Expected unitless number, got %r" % (base,))
if base is None:
ret = math.log(number.value)
else:
ret = math.log(number.value, base.value)
return Number(ret)
@register('pow', 2)
def pow(number, exponent):
return number ** exponent
COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.sqrt), 'sqrt', 1)
COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.sin), 'sin', 1)
COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.cos), 'cos', 1)
COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.tan), 'tan', 1)
# ------------------------------------------------------------------------------
# Fonts
def _fonts_root():
return config.STATIC_ROOT if config.FONTS_ROOT is None else config.FONTS_ROOT
def _font_url(path, only_path=False, cache_buster=True, inline=False):
filepath = String.unquoted(path).value
file = None
示例8: ValueError
raise ValueError("Expected unitless number, got %r" % (base,))
if base is None:
ret = math.log(number.value)
else:
ret = math.log(number.value, base.value)
return Number(ret)
@ns.declare
def pow(number, exponent):
return number ** exponent
ns.set_function('sqrt', 1, Number.wrap_python_function(math.sqrt))
ns.set_function('sin', 1, Number.wrap_python_function(math.sin))
ns.set_function('cos', 1, Number.wrap_python_function(math.cos))
ns.set_function('tan', 1, Number.wrap_python_function(math.tan))
# ------------------------------------------------------------------------------
# Fonts
def _fonts_root():
return config.STATIC_ROOT if config.FONTS_ROOT is None else config.FONTS_ROOT
def _font_url(path, only_path=False, cache_buster=True, inline=False):
filepath = String.unquoted(path).value
file = None
示例9: expect_type
expect_type(string, String)
return String(string.value.lower(), quotes=string.quotes)
# ------------------------------------------------------------------------------
# Number functions
@ns.declare
def percentage(value):
expect_type(value, Number, unit=None)
return value * Number(100, unit="%")
ns.set_function("abs", 1, Number.wrap_python_function(abs))
ns.set_function("round", 1, Number.wrap_python_function(round))
ns.set_function("ceil", 1, Number.wrap_python_function(math.ceil))
ns.set_function("floor", 1, Number.wrap_python_function(math.floor))
# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
if separator is None:
separator = "auto"
separator = String.unquoted(separator).value
if separator == "comma":
示例10: String
return String(arg.value, quotes='"')
else:
return String(arg.render(), quotes='"')
# ------------------------------------------------------------------------------
# Number functions
@register("percentage", 1)
def percentage(value):
expect_type(value, Number, unit=None)
return value * Number(100, unit="%")
CORE_LIBRARY.add(Number.wrap_python_function(abs), "abs", 1)
CORE_LIBRARY.add(Number.wrap_python_function(round), "round", 1)
CORE_LIBRARY.add(Number.wrap_python_function(math.ceil), "ceil", 1)
CORE_LIBRARY.add(Number.wrap_python_function(math.floor), "floor", 1)
# ------------------------------------------------------------------------------
# List functions
def __parse_separator(separator, default_from=None):
if separator is None:
return None
separator = String.unquoted(separator).value
if separator == "comma":
return True