コード例 #1
0
ファイル: playground.py プロジェクト: susmit/kivy-designer
 def _perform_load_widget(self, widget_name, update_kv_lang=True):
     '''Loads the widget if everything is ok
     :param widget_name name of the widget to display
     :param update_kv_lang if True, reloads the kv file. If False, keep the
         kv lang text
     '''
     self.root_name = widget_name
     self.root = None
     self.sandbox.clear_widgets()
     widgets = get_current_project().app_widgets
     try:
         target = widgets[widget_name]
         if update_kv_lang:
             # updates kv lang text with file
             kv_path = target.kv_path
             if kv_path:
                 self.kv_code_input.text = open(kv_path).read()
             else:
                 show_message(
                     'Could not found the associated .kv file with %s'
                     ' widget' % widget_name, 5, 'error')
                 self.kv_code_input.text = ''
         self.root_app_widget = target
         wdg = get_app_widget(target)
         if wdg is None:
             self.kv_code_input.have_error = True
         self.add_widget_to_parent(wdg, None, from_undo=True, from_kv=True)
         self.kv_code_input.path = target.kv_path
     except (KeyError, AttributeError):
         show_message('Failed to load %s widget' % widget_name, 5, 'error')
コード例 #2
0
    def _clean_old_kv(self, path):
        '''
        Removes widgets and rules already processed to this file
        :param path: file path - the same that in app_widgets
        '''
        for key in dict(self.app_widgets):
            wd = self.app_widgets[key]
            if path != wd.kv_path:
                continue
            wdg = get_app_widget(wd)
            if wdg is None:
                p = get_designer().ui_creator.playground
                if p.root_name == wd.name:
                    wdg = p._last_root
                if not wdg:
                    continue
            if wd.is_dynamic:
                del self.app_widgets[key]

            rules = Builder.match(wdg)

            # Cleaning widget rules
            for _rule in rules:
                for _tuple in Builder.rules[:]:
                    if _tuple[1] == _rule:
                        Builder.rules.remove(_tuple)
                        if wd.is_dynamic:
                            Factory.unregister(wd.name.split('@')[0])

            # Cleaning class rules
            for rule in Builder.rules[:]:
                if rule[1].name == '<' + wd.name + '>':
                    Builder.rules.remove(rule)
                    break
コード例 #3
0
ファイル: playground.py プロジェクト: kivy/kivy-designer
 def _perform_load_widget(self, widget_name, update_kv_lang=True):
     '''Loads the widget if everything is ok
     :param widget_name name of the widget to display
     :param update_kv_lang if True, reloads the kv file. If False, keep the
         kv lang text
     '''
     self.root_name = widget_name
     self.root = None
     self.sandbox.clear_widgets()
     widgets = get_current_project().app_widgets
     try:
         target = widgets[widget_name]
         if update_kv_lang:
             # updates kv lang text with file
             kv_path = target.kv_path
             if kv_path:
                 self.kv_code_input.text = open(kv_path,
                                                encoding='utf-8').read()
             else:
                 show_message(
                     'Could not found the associated .kv file with %s'
                     ' widget' % widget_name, 5, 'error'
                 )
                 self.kv_code_input.text = ''
         self.root_app_widget = target
         wdg = get_app_widget(target)
         if wdg is None:
             self.kv_code_input.have_error = True
         self.add_widget_to_parent(wdg, None, from_undo=True, from_kv=True)
         self.kv_code_input.path = target.kv_path
     except (KeyError, AttributeError):
         show_message(
             'Failed to load %s widget' % widget_name, 5, 'error')
コード例 #4
0
ファイル: playground.py プロジェクト: susmit/kivy-designer
 def get_widget(self, widget_name, **default_args):
     '''This function is used to get the instance of class of name,
        widgetname.
        :param widget_name: name of the widget to be instantiated
     '''
     widget = None
     for _widget in widgets_common:
         if _widget[0] == widget_name and _widget[1] == 'custom':
             app_widgets = get_current_project().app_widgets
             widget = get_app_widget(app_widgets[widget_name])
             break
     if not widget:
         try:
             widget = Factory.get(widget_name)(**default_args)
         except:
             pass
     return widget
コード例 #5
0
ファイル: playground.py プロジェクト: kivy/kivy-designer
 def get_widget(self, widget_name, **default_args):
     '''This function is used to get the instance of class of name,
        widgetname.
        :param widget_name: name of the widget to be instantiated
     '''
     widget = None
     for _widget in widgets_common:
         if _widget[0] == widget_name and _widget[1] == 'custom':
             app_widgets = get_current_project().app_widgets
             widget = get_app_widget(app_widgets[widget_name])
             break
     if not widget:
         try:
             widget = Factory.get(widget_name)(**default_args)
         except:
             pass
     return widget