def on_reload_kv(self, kv_lang_area, text, force):
     """Reloads widgets from kv lang input and update the
     visible widget.
     if force is True, all widgets must be reloaded before parsing the new kv
     :param force: if True, will parse the project again
     :param text: kv source
     :param kv_lang_area: instance of kivy lang area
     """
     proj = get_current_project()
     # copy of initial widgets
     widgets = dict(proj.app_widgets)
     try:
         if force:
             proj.parse()
         if self.root_name:
             kv_path = widgets[self.root_name].kv_path
         else:
             kv_path = self.kv_code_input.path
         proj.parse_kv(text, kv_path)
         # if was displaying one widget, but it was removed
         if self.root_name and self.root_name not in proj.app_widgets:
             self.load_widget_from_file(self.root_app_widget.kv_path)
             show_message("The %s is not available. Displaying another widget" % self.root_name, 5, "info")
         elif not self.root_name and not widgets and proj.app_widgets:
             # if was not displaying a widget because there was no widget
             # and now a widget is available
             first_wdg = proj.app_widgets[list(proj.app_widgets.keys())[-1]]
             self.load_widget(first_wdg.name, update_kv_lang=False)
         else:
             # displaying an usual widget
             self.load_widget(self.root_name, update_kv_lang=False)
     except KeyError:
         show_message("Failed to load %s widget" % self.root_name, 5, "error")
示例#2
0
 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
     '''
     if self._popup:
         self._popup.dismiss()
     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')
    def _file_node_clicked(self, instance, touch):
        '''This is emmited whenever any file node of Project Tree is
           clicked. This will open up a tab in DesignerTabbedPanel, for
           editing that py file.
        '''

        # Travel upwards and find the path of instance clicked
        path = instance.text
        parent = instance.parent_node
        while parent != self._root_node:
            _path = parent.text
            path = os.path.join(_path, path)
            parent = parent.parent_node

        full_path = os.path.join(self.project.path, path)
        if os.path.basename(full_path) == 'buildozer.spec':
            self.tab_pannel.show_buildozer_spec_editor(self.project)
        else:
            ext = path[path.rfind('.'):]
            if ext not in SUPPORTED_EXT:
                show_message('This extension is not yet supported', 5, 'error')
                return
            if ext == '.kv':
                self.ui_creator.playground.load_widget_from_file(full_path)
                self.tab_pannel.switch_to(self.tab_pannel.tab_list[-1])
            else:
                self.tab_pannel.open_file(full_path, path)
示例#4
0
    def _file_node_clicked(self, instance, touch):
        '''This is emmited whenever any file node of Project Tree is
           clicked. This will open up a tab in DesignerTabbedPanel, for
           editing that py file.
        '''

        # Travel upwards and find the path of instance clicked
        path = instance.text
        parent = instance.parent_node
        while parent != self._root_node:
            _path = parent.text
            path = os.path.join(_path, path)
            parent = parent.parent_node

        full_path = os.path.join(self.project.path, path)
        if os.path.basename(full_path) == 'buildozer.spec':
            self.tab_pannel.show_buildozer_spec_editor(self.project)
        else:
            ext = path[path.rfind('.'):]
            if ext not in SUPPORTED_EXT:
                show_message('This extension is not yet supported', 5, 'error')
                return
            if ext == '.kv':
                self.ui_creator.playground.load_widget_from_file(full_path)
                self.tab_pannel.switch_to(self.tab_pannel.tab_list[-1])
            else:
                self.tab_pannel.open_file(full_path, path)
示例#5
0
    def runcode(self, _code):
        """Execute a code object.

        When an exception occurs, self.showtraceback() is called to
        display a traceback. All exceptions are caught except
        SystemExit, which is reraised.

        A note about KeyboardInterrupt: this exception may occur
        elsewhere in this code, and may not always be caught. The
        caller should be prepared to deal with it.

        """
        org_stdout = sys.stdout
        sys.stdout = PseudoFile(self)
        try:
            exec(_code, self.locals)
        except SystemExit:
            show_message(
                'It\'s not possible to exit from Kivy Designer Python console',
                5, 'error'
            )
        except:
            self.showtraceback()

        sys.stdout = org_stdout
 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
     """
     if self._popup:
         self._popup.dismiss()
     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")
示例#7
0
    def _add_event(self, *args):
        '''This function will create a new event given by 'txt' to the widget.
        '''
        # Find the class definition
        py_code_input = None
        txt = self.txt
        rel_path = self.rel_path
        for tab_item in self.designer_tabbed_panel.tab_list:
            if not hasattr(tab_item, 'rel_path'):
                continue
            if tab_item.rel_path == rel_path:
                if hasattr(tab_item.content, 'code_input'):
                    py_code_input = tab_item.content.code_input
                    break

        if py_code_input is None:
            show_message('Failed to create a custom event', 5, 'error')
            return
        pos = -1
        for searchiter in re.finditer(r'class\s+%s\(.+\):' %
                                      type(self.widget).__name__,
                                      py_code_input.text):
            pos = searchiter.end()

        if pos != -1:
            col, row = py_code_input.get_cursor_from_index(pos)
            row += 1
            lines = py_code_input.text.splitlines()
            found_events = False
            events_row = row
            for i in range(row, len(lines)):
                if re.match(r'\s+__events__\s*=\s*\(.+\)', lines[i]):
                    found_events = True
                    events_row = i
                    break

                elif re.match('class\s+[\w\d\_]+\(.+\):', lines[i]):
                    break

                elif re.match('def\s+[\w\d\_]+\(.+\):', lines[i]):
                    break

            if found_events:
                events_col = lines[events_row].rfind(')') - 1
                py_code_input.cursor = events_col, events_row
                py_code_input.insert_text(', "%s" ' % txt.text)

                py_code_input.cursor = 0, events_row + 1
                py_code_input.insert_text(
                    '\n    def %s(self, *args):\n        pass\n' % txt.text
                )
            else:
                py_code_input.text = py_code_input.text[:pos] + \
                    '\n\n    __events__=("%s",)\n\n'\
                    '    def %s(self, *args):\n        pass\n' % \
                    (txt.text, txt.text) +\
                    py_code_input.text[pos:]
            show_message('New event created!', 5, 'info')
示例#8
0
 def _perform_do_add(self, instance, selected_files, *args):
     '''Add the selected files to git index
     '''
     try:
         self.repo.index.add(selected_files)
         show_message('%d file(s) added to Git index' %
                      len(selected_files), 5, 'info')
         get_designer().close_popup()
     except GitCommandError as e:
         show_alert('Git Add', 'Failed to add files to Git!\n' + str(e))
示例#9
0
 def do_init(self, *args):
     '''Git init
     '''
     try:
         self.repo = Repo.init(self.path, mkdir=False)
         self.repo.index.commit('Init commit')
         self.is_repo = True
         self._update_menu()
         show_message('Git repo initialized', 5, 'info')
     except:
         show_alert('Git Init', 'Failted to initialize repo!')
示例#10
0
 def _perform_do_commit(self, input, *args):
     '''Perform the git commit with data from InputDialog
     '''
     message = input.get_user_input()
     if self.repo.is_dirty():
         try:
             self.repo.git.commit('-am', message)
             show_message('Commit: ' + message, 5, 'info')
         except GitCommandError as e:
             show_alert('Git Commit', 'Failed to commit!\n' + str(e))
     else:
         show_alert('Git Commit', 'There is nothing to commit')
     self._popup.dismiss()
示例#11
0
 def _perform_do_commit(self, input, *args):
     '''Perform the git commit with data from InputDialog
     '''
     message = input.get_user_input()
     if self.repo.is_dirty():
         try:
             self.repo.git.commit('-am', message)
             show_message('Commit: ' + message, 5, 'info')
         except GitCommandError as e:
             show_alert('Git Commit', 'Failed to commit!\n' + str(e))
     else:
         show_alert('Git Commit', 'There is nothing to commit')
     self._popup.dismiss()
 def show_errors(self, *args):
     '''Pop errors got in the last operations and display it on
     Error Console
     '''
     errors = list(self._errors)
     show_error_console('')
     if len(errors):
         show_message(
             'Errors found while parsing the project. Check Error Console',
             5, 'error')
     for er in range(0, len(errors)):
         show_error_console('\n\nError: %d\n' % (er + 1), append=True)
         show_error_console(errors[er], append=True)
         self._errors.remove(errors[er])
示例#13
0
 def show_errors(self, *args):
     '''Pop errors got in the last operations and display it on
     Error Console
     '''
     errors = list(self._errors)
     show_error_console('')
     if len(errors):
         show_message(
             'Errors found while parsing the project. Check Error Console',
             5, 'error'
         )
     for er in range(0, len(errors)):
         show_error_console('\n\nError: %d\n' % (er + 1), append=True)
         show_error_console(errors[er], append=True)
         self._errors.remove(errors[er])
示例#14
0
        def pull(*args):
            '''Do a pull in a separated thread
            '''
            try:
                remote_repo.pull(progress=progress)

                def set_progress_done(*args):
                    progress.label.text = 'Completed!'

                Clock.schedule_once(set_progress_done, 1)
                progress.stop()
                show_message('Git remote pull completed!', 5)
            except GitCommandError as e:
                progress.label.text = 'Failed to pull!\n' + str(e)
            get_designer().close_popup()
示例#15
0
        def push(*args):
            '''Do a push in a separated thread
            '''
            try:
                remote_repo.push(self.repo.active_branch.name,
                                 progress=progress)

                def set_progress_done(*args):
                    progress.label.text = 'Completed!'

                Clock.schedule_once(set_progress_done, 1)
                progress.stop()
                show_message('Git remote push completed!', 5)
            except GitCommandError as e:
                progress.label.text = 'Failed to push!\n' + str(e)
            self._popup.dismiss()
示例#16
0
 def load_widget_from_file(self, kv_path):
     '''Loads first widget from a file
     :param kv_path: absolute kv path
     '''
     self.sandbox.clear_widgets()
     proj = get_current_project()
     widgets = proj.app_widgets
     if not os.path.exists(kv_path):
         show_message(kv_path + ' not exists', 5, 'error')
         return
     self.kv_code_input.text = open(kv_path, 'r').read()
     self.kv_code_input.path = kv_path
     for key in widgets:
         wd = widgets[key]
         if wd.kv_path == kv_path:
             self.load_widget(wd.name, update_kv_lang=False)
             return
     # if not found a widget in the path, open the first one
     if len(widgets):
         first_wdg = widgets[list(widgets.keys())[-1]]
         self.load_widget(first_wdg.name, update_kv_lang=False)
         return
     show_message('No widget was found', 5, 'error')
示例#17
0
 def load_widget_from_file(self, kv_path):
     """Loads first widget from a file
     :param kv_path: absolute kv path
     """
     self.sandbox.clear_widgets()
     proj = get_current_project()
     widgets = proj.app_widgets
     if not os.path.exists(kv_path):
         show_message(kv_path + " not exists", 5, "error")
         return
     self.kv_code_input.text = open(kv_path, "r").read()
     self.kv_code_input.path = kv_path
     for key in widgets:
         wd = widgets[key]
         if wd.kv_path == kv_path:
             self.load_widget(wd.name, update_kv_lang=False)
             return
     # if not found a widget in the path, open the first one
     if len(widgets):
         first_wdg = widgets[list(widgets.keys())[-1]]
         self.load_widget(first_wdg.name, update_kv_lang=False)
         return
     show_message("No widget was found", 5, "error")
示例#18
0
 def on_reload_kv(self, kv_lang_area, text, force):
     '''Reloads widgets from kv lang input and update the
     visible widget.
     if force is True, all widgets must be reloaded before parsing the new kv
     :param force: if True, will parse the project again
     :param text: kv source
     :param kv_lang_area: instance of kivy lang area
     '''
     proj = get_current_project()
     # copy of initial widgets
     widgets = dict(proj.app_widgets)
     try:
         if force:
             proj.parse()
         if self.root_name:
             kv_path = widgets[self.root_name].kv_path
         else:
             kv_path = self.kv_code_input.path
         proj.parse_kv(text, kv_path)
         # if was displaying one widget, but it was removed
         if self.root_name and self.root_name not in proj.app_widgets:
             self.load_widget_from_file(self.root_app_widget.kv_path)
             show_message(
                 'The %s is not available. Displaying another widget' %
                 self.root_name, 5, 'info')
         elif not self.root_name and not widgets and proj.app_widgets:
             # if was not displaying a widget because there was no widget
             # and now a widget is available
             first_wdg = proj.app_widgets[list(proj.app_widgets.keys())[-1]]
             self.load_widget(first_wdg.name, update_kv_lang=False)
         else:
             # displaying an usual widget
             self.load_widget(self.root_name, update_kv_lang=False)
     except KeyError:
         show_message('Failed to load %s widget' % self.root_name, 5,
                      'error')
示例#19
0
 def no_widget(self, *args):
     '''Remove any reamining sandbox content and shows an message
     '''
     self.root = None
     show_message('No widget found!', 5, 'error')
     self.sandbox.clear_widgets()
示例#20
0
 def no_widget(self, *args):
     '''Remove any reamining sandbox content and shows an message
     '''
     self.root = None
     show_message('No widget found!', 5, 'error')
     self.sandbox.clear_widgets()
示例#21
0
 def no_widget(self, *args):
     """Remove any reamining sandbox content and shows an message
     """
     self.root = None
     show_message("No widget found!", 5, "error")
     self.sandbox.clear_widgets()