Example #1
0
def test_key_pressed():
    # " -> ""
    editor = CodeEdit()
    editor.modes.append(modes.AutoCompleteMode())
    editor.setPlainText('', '', 'utf-8')
    QTest.keyPress(editor, '"')
    assert editor.toPlainText() == '""'
    editor.clear()

    # if a " already exists, cursor should just move after " and a new " should
    # not be inserted
    editor.setPlainText('"', 'text/x-python', 'utf-8')
    TextHelper(editor).goto_line(0, 0)
    QTest.keyPress(editor, '"')
    assert editor.toPlainText() == '"'
    editor.clear()

    # if a ) already exists, cursor should just move after ) and a new ) should
    # not be inserted
    editor.setPlainText(')', 'text/x-python', 'utf-8')
    TextHelper(editor).goto_line(0, 0)
    QTest.keyPress(editor, ')')
    QTest.qWait(1000)
    assert editor.toPlainText() == ')'

    # ] should be inserted ")" -> "])"
    TextHelper(editor).goto_line(0, 0)
    QTest.keyPress(editor, ']')
    QTest.qWait(1000)
    assert editor.toPlainText() == '])'
Example #2
0
"""
Minimal example showing the use of the CaseConverterMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.modes import CaseConverterMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CaseConverterMode()))
    editor.show()
    editor.setPlainText(
        'Press Ctrl+Shift+U to convert selected text to upper  case\n'
        'and Ctrl+U to convert the text to lower case.', '', '')
    editor.selectAll()
    app.exec_()
    editor.close()
    del editor
    del app
Example #3
0
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # we must add the document analyser prior to adding the symbol browser
    # panel
    editor.panels.append(QuickDocPanel(), QuickDocPanel.Position.BOTTOM)
    editor.show()
    editor.setPlainText(
        '''# Press Alt+Q on a symbol to get its documentation
import os


class Foo:
    """
    A foo class
    """

    def spam(self, eggs):
        """ spams some eggs """
        return str(eggs).lower()

foo = Foo()
os.path.join(foo.spam())
''', '', '')
    app.exec_()
    editor.close()
    del editor
    del app
"""
Minimal example showing the use of the SearchAndReplacePanel.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.panels import SearchAndReplacePanel


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    editor.panels.append(SearchAndReplacePanel(),
                         SearchAndReplacePanel.Position.TOP)
    editor.setPlainText('Pres Ctrl+F to search text in the document', '', '')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
Example #5
0
        ('A warning message', CheckerMessages.WARNING, 100),
        ('An error message', CheckerMessages.ERROR, 200),
    ]


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    editor.setCenterOnScroll(False)
    # use a string instead of the function directly (otherwise we
    # get __main__.check instead of checker.check)
    # print(editor.modes.append(CheckerMode(check)))  # does not work if
                                                      # function is in main
                                                      # module
    print(editor.modes.append(CheckerMode('global_checker.check')))
    print(editor.panels.append(GlobalCheckerPanel(),
                               GlobalCheckerPanel.Position.RIGHT))

    # we could also use the pyqode.python.backend like this (uncomment the next
    # two lines if you have pyqode.python)
    # from pyqode.python.backend import run_pep8
    # print(editor.modes.append(CheckerMode(run_pep8)))
    editor.show()
    editor.setPlainText('AAA\n' * 500, '', '')
    app.exec_()
    editor.close()
    del editor
    del app
Example #6
0
Minimal example showing the use of the FrostedCheckerMode.

We use Frosted (a fork of pyFlakes) that provides an easier API for running
pyFlakes on strings (instead of files).
"""
import logging
from pyqode.core.panels import CheckerPanel

logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.python.backend import server
from pyqode.python.modes import PyFlakesChecker, PythonSH

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PyFlakesChecker()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.panels.append(CheckerPanel())
    editor.show()
    editor.setPlainText('print("foo\n', 'text/x-python', 'utf-8')
    app.exec_()
    editor.close()
    del editor
    del app
Example #7
0
"""
Minimal example showing the use of the OccurrencesHighlighterMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.modes import OccurrencesHighlighterMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(OccurrencesHighlighterMode()))
    editor.setPlainText(
        'mode\nmode\nmodes\npanel\nmode', '', '')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
Example #8
0
"""
Minimal example showing the use of the PEP8CheckerMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.panels import CheckerPanel
from pyqode.python.backend import server
from pyqode.python.modes import PEP8CheckerMode, PythonSH


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PEP8CheckerMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.panels.append(CheckerPanel())
    editor.show()
    editor.setPlainText('class Foo:\n\n\ndef __init__(self):\n\npass',
                        'text/x-python', 'utf-8')
    app.exec_()
    editor.close()
    del editor
    del app
Example #9
0
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # we must add the document analyser prior to adding the symbol browser
    # panel
    editor.panels.append(QuickDocPanel(), QuickDocPanel.Position.BOTTOM)
    editor.show()
    editor.setPlainText(
        '''# Press Alt+Q on a symbol to get its documentation
import os


class Foo:
    """
    A foo class
    """

    def spam(self, eggs):
        """ spams some eggs """
        return str(eggs).lower()

foo = Foo()
os.path.join(foo.spam())
''',
        "",
        "",
    )
    app.exec_()
    editor.close()
    del editor
    del app
Example #10
0
We use Frosted (a fork of pyFlakes) that provides an easier API for running
pyFlakes on strings (instead of files).
"""
import logging
from pyqode.core.panels import CheckerPanel

logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.python.backend import server
from pyqode.python.modes import PyFlakesChecker, PythonSH


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PyFlakesChecker()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.panels.append(CheckerPanel())
    editor.show()
    editor.setPlainText('print("foo\n', 'text/x-python', 'utf-8')
    app.exec_()
    editor.close()
    del editor
    del app
Example #11
0
"""
Minimal example showing the use of the CaseConverterMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.modes import CaseConverterMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CaseConverterMode()))
    editor.show()
    editor.setPlainText(
        'Press Ctrl+Shift+U to convert selected text to upper  case\n'
        'and Ctrl+U to convert the text to lower case.', '', '')
    editor.selectAll()
    app.exec_()
    editor.close()
    del editor
    del app
Example #12
0
"""
Minimal example showing the use of the SearchAndReplacePanel.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.panels import SearchAndReplacePanel

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    editor.panels.append(SearchAndReplacePanel(),
                         SearchAndReplacePanel.Position.TOP)
    editor.setPlainText('Pres Ctrl+F to search text in the document', '', '')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
Example #13
0
        ('An error message', CheckerMessages.ERROR, 200),
    ]


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    editor.setCenterOnScroll(False)
    # use a string instead of the function directly (otherwise we
    # get __main__.check instead of checker.check)
    # print(editor.modes.append(CheckerMode(check)))  # does not work if
    # function is in main
    # module
    print(editor.modes.append(CheckerMode('global_checker.check')))
    print(
        editor.panels.append(GlobalCheckerPanel(),
                             GlobalCheckerPanel.Position.RIGHT))

    # we could also use the pyqode.python.backend like this (uncomment the next
    # two lines if you have pyqode.python)
    # from pyqode.python.backend import run_pep8
    # print(editor.modes.append(CheckerMode(run_pep8)))
    editor.show()
    editor.setPlainText('AAA\n' * 500, '', '')
    app.exec_()
    editor.close()
    del editor
    del app
Example #14
0
"""
Minimal example showing the use of the PEP8CheckerMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.panels import CheckerPanel
from pyqode.python.backend import server
from pyqode.python.modes import PEP8CheckerMode, PythonSH

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PEP8CheckerMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.panels.append(CheckerPanel())
    editor.show()
    editor.setPlainText('class Foo:\n\n\ndef __init__(self):\n\npass',
                        'text/x-python', 'utf-8')
    app.exec_()
    editor.close()
    del editor
    del app
Example #15
0
"""
Minimal example showing the use of the OccurrencesHighlighterMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys
import os
os.environ['QT_API'] = 'pyside2'
# os.environ['QT_API'] = 'pyqt5'

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit
from pyqode.core.backend import server
from pyqode.core.modes import OccurrencesHighlighterMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(OccurrencesHighlighterMode()))
    editor.setPlainText(
        'mode\nmode\nmodes\npanel\nmode', '', '')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app