本文整理汇总了Python中kivy.lang.Builder.load_file方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.load_file方法的具体用法?Python Builder.load_file怎么用?Python Builder.load_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.lang.Builder
的用法示例。
在下文中一共展示了Builder.load_file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_defualt_kv
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def load_defualt_kv(filename, file_content):
''' load the default kivy file
associated the the python file,
usaully lowercase of the app class
'''
app_cls_name = get_app_cls_name(file_content)
if app_cls_name is None:
return
kv_name = app_cls_name.lower()
if app_cls_name.endswith('App'):
kv_name = app_cls_name[:len(app_cls_name)-3].lower()
if app_cls_name:
file_dir = os.path.dirname(filename)
kv_filename = os.path.join(file_dir, kv_name+'.kv')
if os.path.exists(kv_filename):
try: # cacthing error with kivy files
Builder.unload_file(kv_filename)
root = Builder.load_file(kv_filename)
except:
trace = traceback.format_exc()
Logger.error("KivyStudio: You kivy file has a problem")
Logger.error("KivyStudio: {}".format(trace))
示例2: load_kv_file
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def load_kv_file(self, file_path):
for e in self.fbo_widget.children:
self.fbo_widget.remove_widget(e)
if os.path.isfile(file_path):
res = Builder.load_file(file_path)
self.add_widget(res)
示例3: start_emulation
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def start_emulation(filename, file_content, threaded=False):
root = None
has_error = False
if os.path.splitext(filename)[1] =='.kv': # load the kivy file directly
try: # cacthing error with kivy files
Builder.unload_file(filename)
root = Builder.load_file(filename)
except:
has_error = True
trace = traceback.format_exc()
Logger.error("Emulator: {}".format(trace))
elif os.path.splitext(filename)[1] =='.py':
load_defualt_kv(filename, file_content)
try: # cahching error with python files
root = load_py_file(filename, file_content)
except:
has_error = True
trace = traceback.format_exc()
Logger.error("Emulator: {}".format(trace))
else:
Logger.warning("KivyStudio: can't emulate file type {}".format(filename))
if not root and not has_error:
Logger.error('Emulator: No root widget found.')
elif not isinstance(root,Widget) and not has_error:
Logger.error("KivyStudio: root instance found = '{}' and is not a widget".format(root))
elif root:
if threaded:
emulation_done(root, filename)
else:
get_emulator_area().screen_display.screen.add_widget(root)
dirname=os.path.dirname(filename)
sys.path.pop()
resource_remove_path(dirname)
示例4: load_kv
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def load_kv(filepath, file):
''' load a kivy file from the current
directory of the file calling this func
where filepath is __file__ and file is a kv file'''
filepath = dirname(filepath)
Builder.load_file(join(filepath, file))
示例5: add_screen
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def add_screen(self, screenname):
# Get the info we need to import this screen
foundscreen = [p for p in getPlugins() if p["name"] == screenname]
# Check we've found a screen and it's not already running
if foundscreen and not screenname in self.availablescreens:
# Get the details for the screen
p = foundscreen[0]
# Import it
plugin = imp.load_module("screen", *p["info"])
# Get the reference to the screen class
screen = getattr(plugin, p["screen"])
# Add the KV file to the builder
Builder.load_file(p["kvpath"])
# Add the screen
self.scrmgr.add_widget(screen(name=p["name"],
master=self,
params=p["params"]))
# Add to our list of available screens
self.availablescreens.append(screenname)
# Activate screen
self.switch_to(screename)
elif screenname in self.availablescreens:
# This shouldn't happen but we need this to prevent duplicates
self.reload_screen(screenname)
示例6: load_file
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def load_file(self, filename, **kwargs):
'''Insert a file into the language builder and return the root widget
(if defined) of the kv file.
:parameters:
`rulesonly`: bool, defaults to False
If True, the Builder will raise an exception if you have a root
widget inside the definition.
'''
filename = resource_find(filename) or filename
if __debug__:
trace('Builder: load file %s' % filename)
with open(filename, 'r') as fd:
kwargs['filename'] = filename
data = fd.read()
# remove bom ?
if PY2:
if data.startswith((codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE)):
raise ValueError('Unsupported UTF16 for kv files.')
if data.startswith((codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE)):
raise ValueError('Unsupported UTF32 for kv files.')
if data.startswith(codecs.BOM_UTF8):
data = data[len(codecs.BOM_UTF8):]
return self.load_string(data, **kwargs)
示例7: build
# 需要导入模块: from kivy.lang import Builder [as 别名]
# 或者: from kivy.lang.Builder import load_file [as 别名]
def build(self):
return Builder.load_file("look.kv")