当前位置: 首页>>代码示例>>Python>>正文


Python Builder.load_file方法代码示例

本文整理汇总了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)) 
开发者ID:mahart-studio,项目名称:kivystudio,代码行数:27,代码来源:__init__.py

示例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) 
开发者ID:kpiorno,项目名称:kivy3dgui,代码行数:9,代码来源:node.py

示例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) 
开发者ID:mahart-studio,项目名称:kivystudio,代码行数:38,代码来源:__init__.py

示例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)) 
开发者ID:mahart-studio,项目名称:kivystudio,代码行数:8,代码来源:__init__.py

示例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) 
开发者ID:elParaguayo,项目名称:RPi-InfoScreen-Kivy,代码行数:37,代码来源:infoscreen.py

示例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) 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:28,代码来源:lang.py

示例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") 
开发者ID:atuldo,项目名称:real-time-plot-microphone-kivy,代码行数:4,代码来源:main.py


注:本文中的kivy.lang.Builder.load_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。