MCPcopy
hub / github.com/kivy/kivy / load_string

Method load_string

kivy/lang/builder.py:339–421  ·  view source on GitHub ↗

Insert a string into the Language Builder and return the root widget (if defined) of the kv string. :Parameters: `rulesonly`: bool, defaults to False If True, the Builder will raise an exception if you have a root widget inside the definit

(self, string, **kwargs)

Source from the content-addressed store, hash-verified

337 Factory.unregister_from_filename(filename)
338
339 def load_string(self, string, **kwargs):
340 '''Insert a string into the Language Builder and return the root widget
341 (if defined) of the kv string.
342
343 :Parameters:
344 `rulesonly`: bool, defaults to False
345 If True, the Builder will raise an exception if you have a root
346 widget inside the definition.
347 `filename`: str, defaults to None
348 If specified, the filename used to index the kv rules.
349
350 The filename parameter can be used to unload kv strings in the same way
351 as you unload kv files. This can be achieved using pseudo file names
352 e.g.::
353
354 Build.load_string("""
355 <MyRule>:
356 Label:
357 text="Hello"
358 """, filename="myrule.kv")
359
360 can be unloaded via::
361
362 Build.unload_file("myrule.kv")
363
364 ''&#x27;
365
366 kwargs.setdefault('rulesonly', False)
367 self._current_filename = fn = kwargs.get('filename', None)
368
369 # put a warning if a file is loaded multiple times
370 if fn in self.files:
371 Logger.warning(
372 'Lang: The file {} is loaded multiples times, '
373 'you might have unwanted behaviors.'.format(fn))
374
375 try:
376 # parse the string
377 parser = Parser(content=string, filename=fn)
378
379 # merge rules with our rules
380 self.rules.extend(parser.rules)
381 self._clear_matchcache()
382
383 # add the template found by the parser into ours
384 for name, cls, template in parser.templates:
385 self.templates[name] = (cls, template, fn)
386 Factory.register(name,
387 cls=partial(self.template, name),
388 is_template=True, warn=True)
389
390 # register all the dynamic classes
391 for name, baseclasses in parser.dynamic_classes.items():
392 Factory.register(name, baseclasses=baseclasses, filename=fn,
393 warn=True)
394
395 # create root object is exist
396 if kwargs['rulesonly'] and parser.root:

Callers 15

load_fileMethod · 0.95
inspector.pyFile · 0.80
startFunction · 0.80
console.pyFile · 0.80
rst.pyFile · 0.80
filechooser.pyFile · 0.80
__init__Method · 0.80
screenmanager.pyFile · 0.80
sandbox.pyFile · 0.80
actionbar.pyFile · 0.80
buildMethod · 0.80
cover.pyFile · 0.80

Calls 10

_clear_matchcacheMethod · 0.95
_apply_ruleMethod · 0.95
ParserClass · 0.90
setdefaultMethod · 0.80
formatMethod · 0.80
appendMethod · 0.80
getMethod · 0.45
registerMethod · 0.45
dispatchMethod · 0.45