當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。