def reset_shell(shell, base_ns):
    """ Resets shell and loads project settings for Python """
    projectPlugin = get_project_plugin()
    projectMap = projectPlugin.property('projectMap')
    if 'python' in projectMap:
        projectName = projectPlugin.property('projectName')
        projectMapPython = projectMap['python']
        # Check Python version
        version = projectMapPython.get('version', None)
        if not is_version_compatible(version):
            msg = i18n('\n\nCannot load this project: %1. Python Version incompatible', projectName)
            shell.write(msg)
            sys.stdout.flush()
            return

        shell.reset()
        shell.user_ns.update(base_ns)

        shell.write(i18n('\n\nLoad project: %1', projectName))
        extraPath = projectMapPython.get('extraPath', [])
        environs = projectMapPython.get('environs', {})
        # Add Extra path
        add_extra_path(extraPath)
        # Add environs
        add_environs(environs)
        # Special treatment
        if projectMapPython.get('projectType', '').lower() == 'django':
            insert_django_objects(shell)
        # Print details
        sys.stdout.flush()
Exemple #2
0
def createSignalAutocompleteDocument(view=None, *args, **kwargs):
    # https://launchpad.net/ubuntu/precise/+source/pykde4
    # https://launchpad.net/ubuntu/precise/+source/pykde4/4:4.7.97-0ubuntu1/+files/pykde4_4.7.97.orig.tar.bz2
    # http://doc.trolltech.com/4.6/qabstractitemmodel.html
    # http://gitorious.org/kate/kate/blobs/a17eb928f8133528a6194b7e788ab7a425ef5eea/ktexteditor/codecompletionmodel.cpp
    # http://code.google.com/p/lilykde/source/browse/trunk/frescobaldi/python/frescobaldi_app/mainapp.py#1391
    # http://api.kde.org/4.0-api/kdelibs-apidocs/kate/html/katecompletionmodel_8cpp_source.html
    # https://svn.reviewboard.kde.org/r/1640/diff/?expand=1
    view = view or kate.activeView()
    projectPlugin = get_project_plugin()
    if projectPlugin:
        projectPlugin.projectFileNameChanged.connect(projectFileNameChanged)
    global pyplete
    pyplete = PyPlete(PythonCodeCompletionModel.createItemAutoComplete, sys.path)
    cci = view.codeCompletionInterface()
    cci.registerCompletionModel(codecompletationmodel)
Exemple #3
0
def projectFileNameChanged(*args, **kwargs):
    projectPlugin = get_project_plugin()
    projectMap = projectPlugin.property("projectMap")
    if "python" in projectMap:
        projectMapPython = projectMap["python"]
        version = projectMapPython.get("version", None)
        # Check Python version
        if not is_version_compatible(version):
            return
        extraPath = projectMapPython.get("extraPath", [])
        environs = projectMapPython.get("environs", {})
        # Add Extra path
        add_extra_path(extraPath)
        # Add environs
        add_environs(environs)
        global pyplete
        pyplete = PyPlete(PythonCodeCompletionModel.createItemAutoComplete, sys.path)
def make_terminal_widget(parent=None, **base_ns):
    try:
        gui_completion = _GUI_COMPLETION_CONVERT[kate.configuration[_GUI_COMPLETION_TYPE_CFG]]
    except KeyError:
        gui_completion = 'droplist'
    if gui_completion:
        widget = RichIPythonWidget(parent=parent, gui_completion=gui_completion)
    else:
        widget = RichIPythonWidget(parent=parent)

    widget.banner += i18n('\nAvailable variables are everything from pylab, “%1”, and this console as “console”', '”, “'.join(base_ns.keys()))

    client, manager, shell = init_ipython()

    # https://github.com/ipython/ipython/blob/master/examples/inprocess/embedded_qtconsole.py
    if ipython_1:
        widget.kernel_client = client

        widget.exit_requested.connect(widget.kernel_client.stop_channels)
        widget.exit_requested.connect(manager.shutdown_kernel)
    else:
        widget.exit_requested.connect(manager.cleanup_connection_file)

    widget.kernel_manager = manager

    base_ns['console'] = widget
    shell.user_ns.update(base_ns)

    try:
        projectPlugin = get_project_plugin()
    except AttributeError:
        projectPlugin = None
    if projectPlugin:
        def project_changed(*args, **kwargs):
            reset_shell(shell, base_ns)
        projectPlugin.projectFileNameChanged.connect(project_changed)
        project_changed()

    sys.stdout.flush()
    return widget