Exemplo n.º 1
0
        def run_cmd(*args):
            '''Run the command
            '''
            # this is run inside a thread so take care, avoid gui ops
            try:
                _posix = True
                if sys.platform[0] == 'w':
                    _posix = False
                cmd = command
                if PY2 and isinstance(cmd, unicode):
                    cmd = command.encode(get_fs_encoding())
                if not self.shell:
                    cmd = shlex.split(cmd, posix=_posix)
                    for i in range(len(cmd)):
                        cmd[i] = cmd[i].replace('\x01', ' ')
                    map(lambda s: s.decode(get_fs_encoding()), cmd)
            except Exception as err:
                cmd = ''
                self.add_to_cache(''.join((str(err), ' <', command, ' >\n')))
            if len(cmd) > 0:
                prev_stdout = sys.stdout
                sys.stdout = self.stdout
                try:
                    # execute command
                    self.popen_obj = popen = subprocess.Popen(
                        cmd,
                        bufsize=0,
                        stdout=subprocess.PIPE,
                        stdin=subprocess.PIPE,
                        stderr=subprocess.STDOUT,
                        preexec_fn=None,
                        close_fds=False,
                        shell=self.shell,
                        cwd=self.cur_dir.encode(get_fs_encoding()),
                        universal_newlines=False,
                        startupinfo=None,
                        creationflags=0)
                    popen_stdout_r = popen.stdout.readline
                    popen_stdout_flush = popen.stdout.flush
                    txt = popen_stdout_r()
                    plat = platform()
                    while txt:
                        # skip flush on android
                        if plat[0] != 'a':
                            popen_stdout_flush()

                        if isinstance(txt, bytes):
                            txt = txt.decode(get_fs_encoding())
                        add_to_cache(txt)
                        txt = popen_stdout_r()
                except (OSError, ValueError) as err:
                    add_to_cache(''.join(
                            (str(err),
                             ' < ', command, ' >\n')))
                    self.command_status = 'closed'
                    self.dispatch('on_subprocess_done')
                sys.stdout = prev_stdout
            self.popen_obj = None
            Clock.schedule_once(remove_command_interaction_widgets, 0)
Exemplo n.º 2
0
        def run_cmd(*args):
            '''Run the command
            '''
            # this is run inside a thread so take care, avoid gui ops
            try:
                _posix = True
                if sys.platform[0] == 'w':
                    _posix = False
                cmd = command
                if PY2 and isinstance(cmd, unicode):
                    cmd = command.encode(get_fs_encoding())
                if not self.shell:
                    cmd = shlex.split(cmd, posix=_posix)
                    for i in range(len(cmd)):
                        cmd[i] = cmd[i].replace('\x01', ' ')
                    map(lambda s: s.decode(get_fs_encoding()), cmd)
            except Exception as err:
                cmd = ''
                self.add_to_cache(''.join((str(err), ' <', command, ' >\n')))
            if len(cmd) > 0:
                prev_stdout = sys.stdout
                sys.stdout = self.stdout
                try:
                    # execute command
                    self.popen_obj = popen = subprocess.Popen(
                        cmd,
                        bufsize=0,
                        stdout=subprocess.PIPE,
                        stdin=subprocess.PIPE,
                        stderr=subprocess.STDOUT,
                        preexec_fn=None,
                        close_fds=False,
                        shell=self.shell,
                        cwd=self.cur_dir.encode(get_fs_encoding()),
                        universal_newlines=False,
                        startupinfo=None,
                        creationflags=0)
                    popen_stdout_r = popen.stdout.readline
                    popen_stdout_flush = popen.stdout.flush
                    txt = popen_stdout_r()
                    plat = platform()
                    while txt:
                        # skip flush on android
                        if plat[0] != 'a':
                            popen_stdout_flush()

                        if isinstance(txt, bytes):
                            txt = txt.decode(get_fs_encoding())
                        add_to_cache(txt)
                        txt = popen_stdout_r()
                except (OSError, ValueError) as err:
                    add_to_cache(''.join((str(err), ' < ', command, ' >\n')))
                    self.command_status = 'closed'
                    self.dispatch('on_subprocess_done')
                sys.stdout = prev_stdout
            self.popen_obj = None
            Clock.schedule_once(remove_command_interaction_widgets, 0)
Exemplo n.º 3
0
    def run(self, *args, **kwargs):
        '''Run the project using Python
        '''
        if self.designer.popup:
            self.profiler.dispatch(
                'on_error', 'You must close all popups '
                'before building your project')
            return
        mod = kwargs.get('mod', '')
        data = kwargs.get('data', [])

        self._get_python()
        if not self.can_run:
            return

        py_main = os.path.join(self.profiler.project_path, 'main.py')
        if isinstance(py_main, bytes):
            py_main = py_main.decode(get_fs_encoding())

        if not os.path.isfile(py_main):
            self.profiler.dispatch('on_error', 'Cannot find main.py')
            return
        if sys.platform[0] == 'w':
            py_main = py_main.replace(' ', '\x01')
        else:
            py_main = py_main.replace(' ', '\\ ')
        cmd = ''
        if mod == '':
            cmd = '%s %s %s' % (self.python_path, py_main, self.args)
        elif mod == 'screen':
            cmd = '%s %s -m screen:%s %s' % (self.python_path, py_main, data,
                                             self.args)
        else:
            cmd = '%s %s -m %s %s' % (self.python_path, py_main, mod,
                                      self.args)

        status = self.run_command(cmd)

        # popen busy
        if status is False:
            confirm_dlg = ConfirmationDialog(
                message="There is another command running.\n"
                "Do you want to stop it to run your project?")
            self.designer.popup = Popup(title='Kivy Designer',
                                        content=confirm_dlg,
                                        size_hint=(None, None),
                                        size=('300pt', '150pt'),
                                        auto_dismiss=False)
            confirm_dlg.bind(on_ok=self._perform_kill_run,
                             on_cancel=self.designer.close_popup)
            self.designer.popup.open()
            return

        self.ui_creator.tab_pannel.switch_to(
            self.ui_creator.tab_pannel.tab_list[2])

        self.profiler.dispatch('on_message', 'Running main.py...')
        self.profiler.dispatch('on_run')
        self.ui_creator.kivy_console.bind(on_command_list_done=self.on_stop)
Exemplo n.º 4
0
 def prompt(self, *args):
     '''Returns the PS1 variable
     '''
     p = "[%s@%s %s]$ " % (self._username, self._hostname,
                           os.path.basename(self.cur_dir.encode('utf-8')))
     if isinstance(p, bytes):
         p = p.decode(get_fs_encoding())
     return p
Exemplo n.º 5
0
    def run(self, *args, **kwargs):
        '''Run the project using Python
        '''
        if self.designer.popup:
            self.profiler.dispatch('on_error', 'You must close all popups '
                                               'before building your project')
            return
        mod = kwargs.get('mod', '')
        data = kwargs.get('data', [])

        self._get_python()
        if not self.can_run:
            return

        py_main = os.path.join(self.profiler.project_path, 'main.py')
        if isinstance(py_main, bytes):
            py_main = py_main.decode(get_fs_encoding())

        if not os.path.isfile(py_main):
            self.profiler.dispatch('on_error', 'Cannot find main.py')
            return
        if sys.platform[0] == 'w':
            py_main = py_main.replace(' ', '\x01')
        else:
            py_main = py_main.replace(' ', '\\ ')
        cmd = ''
        if mod == '':
            cmd = '%s %s %s' % (self.python_path, py_main, self.args)
        elif mod == 'screen':
            cmd = '%s %s -m screen:%s %s' % (self.python_path, py_main,
                                             data, self.args)
        else:
            cmd = '%s %s -m %s %s' % (self.python_path, py_main,
                                      mod, self.args)

        status = self.run_command(cmd)

        # popen busy
        if status is False:
            confirm_dlg = ConfirmationDialog(
                message="There is another command running.\n"
                        "Do you want to stop it to run your project?")
            self.designer.popup = Popup(title='Kivy Designer',
                                        content=confirm_dlg,
                                        size_hint=(None, None),
                                        size=('300pt', '150pt'),
                                        auto_dismiss=False)
            confirm_dlg.bind(on_ok=self._perform_kill_run,
                             on_cancel=self.designer.close_popup)
            self.designer.popup.open()
            return

        self.ui_creator.tab_pannel.switch_to(
            self.ui_creator.tab_pannel.tab_list[2])

        self.profiler.dispatch('on_message', 'Running main.py...')
        self.profiler.dispatch('on_run')
        self.ui_creator.kivy_console.bind(on_command_list_done=self.on_stop)
Exemplo n.º 6
0
 def prompt(self, *args):
     '''Returns the PS1 variable
     '''
     p = "[%s@%s %s]$ " % (
         self._username, self._hostname,
         os.path.basename(self.cur_dir.encode('utf-8')))
     if isinstance(p, bytes):
         p = p.decode(get_fs_encoding())
     return p
Exemplo n.º 7
0
    def add_recent(self, list_files):
        '''To add buttons representing Recent Files.
        :param list_files: array of paths
        '''
        for p in list_files:
            if isinstance(p, bytes):
                p = p.decode(get_fs_encoding())
            recent_item = RecentItem(path=p)
            self.grid.add_widget(recent_item)
            recent_item.bind(on_press=self.btn_release)
            self.grid.height += recent_item.height

        self.grid.height = max(self.grid.height, self.height)
Exemplo n.º 8
0
    def add_recent(self, list_files):
        '''To add buttons representing Recent Files.
        :param list_files: array of paths
        '''
        for p in list_files:
            if isinstance(p, bytes):
                p = p.decode(get_fs_encoding())
            recent_item = RecentItem(path=p)
            self.grid.add_widget(recent_item)
            recent_item.bind(on_press=self.btn_release)
            self.grid.height += recent_item.height

        self.grid.height = max(self.grid.height, self.height)
Exemplo n.º 9
0
 def write(self, s):
     '''Write a command to the pipe
     '''
     if isinstance(s, bytes):
         s = s.decode(get_fs_encoding())
     Logger.debug('write called with command:' + s)
     if self.mode == 'stdout':
         self.obj.add_to_cache(s)
         self.flush()
     else:
         # process.stdout.write ...run command
         if self.mode == 'stdin':
             self.obj.txtinput_command_line.text = ''.join(
                 (self.obj.prompt(), s))
             self.obj.on_enter()
Exemplo n.º 10
0
 def write(self, s):
     '''Write a command to the pipe
     '''
     if isinstance(s, bytes):
         s = s.decode(get_fs_encoding())
     Logger.debug('write called with command:' + s)
     if self.mode == 'stdout':
         self.obj.add_to_cache(s)
         self.flush()
     else:
         # process.stdout.write ...run command
         if self.mode == 'stdin':
             self.obj.txtinput_command_line.text = ''.join((
                 self.obj.prompt(), s))
             self.obj.on_enter()
Exemplo n.º 11
0
    def load_files(self):
        '''To load the list of files from disk
        '''

        recent_file_path = os.path.join(get_config_dir(),
                                        RECENT_FILES_NAME)

        if not os.path.exists(recent_file_path):
            return

        f = open(recent_file_path, 'r')
        path = f.readline()

        while path != '':
            file_path = path.strip()
            if isinstance(file_path, bytes):
                file_path = file_path.decode(get_fs_encoding()).encode(
                    get_fs_encoding())
            if os.path.exists(file_path):
                self.list_projects.append(file_path)

            path = f.readline()

        f.close()
Exemplo n.º 12
0
    def add_path(self, path):
        '''To add file to RecentManager.
        :param path: path of project
        '''
        if isinstance(path, bytes):
            path = path.decode(get_fs_encoding()).encode(get_fs_encoding())

        _file_index = 0
        try:
            _file_index = self.list_projects.index(path)
        except:
            _file_index = -1

        if _file_index != -1:
            # If _file is already present in list_files, then move it to 0 index
            self.list_projects.remove(path)

        self.list_projects.insert(0, path)

        # Recent files should not be greater than max_recent_files
        while len(self.list_projects) > self.max_recent_files:
            self.list_projects.pop()

        self.store_files()
Exemplo n.º 13
0
    def __init__(self, file_list, **kwargs):
        super(RecentDialog, self).__init__(**kwargs)
        self.item_strings = []
        for item in file_list:
            if isinstance(item, bytes):
                item = item.decode(get_fs_encoding())
            self.item_strings.append(item)

        self.list_items = RecentItemButton

        self.adapter = ListAdapter(
                cls=self.list_items,
                data=self.item_strings,
                selection_mode='single',
                allow_empty_selection=False,
                args_converter=self._args_converter)

        self.listview.adapter = self.adapter
Exemplo n.º 14
0
    def build(self, *args):
        '''Compile all .py to .pyc
        '''
        self._get_python()
        if not self.can_run:
            return

        self.project_watcher.pause_watching()
        proj_path = self.profiler.project_path
        if isinstance(proj_path, bytes):
            proj_path = proj_path.decode(get_fs_encoding())

        self.run_command(
                    '%s -m compileall -l %s' % (self.python_path, proj_path))

        self.ui_creator.tab_pannel.switch_to(
            self.ui_creator.tab_pannel.tab_list[2])

        self.profiler.dispatch('on_message', 'Building project...')
        self.ui_creator.kivy_console.bind(on_command_list_done=self.on_build)
Exemplo n.º 15
0
    def build(self, *args):
        '''Compile all .py to .pyc
        '''
        self._get_python()
        if not self.can_run:
            return

        self.project_watcher.pause_watching()
        proj_path = self.profiler.project_path
        if isinstance(proj_path, bytes):
            proj_path = proj_path.decode(get_fs_encoding())

        self.run_command('%s -m compileall -l %s' %
                         (self.python_path, proj_path))

        self.ui_creator.tab_pannel.switch_to(
            self.ui_creator.tab_pannel.tab_list[2])

        self.profiler.dispatch('on_message', 'Building project...')
        self.ui_creator.kivy_console.bind(on_command_list_done=self.on_build)
Exemplo n.º 16
0
def main():
    data = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
    if isinstance(data, bytes):
        data = data.decode(get_fs_encoding())
    resource_add_path(data)
    DesignerApp().run()