예제 #1
0
"""
Minimal example showing the use of the ZoomMode.
"""
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 ZoomMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(ZoomMode()))
    editor.appendPlainText(
        'Use Ctrl+Mouse wheel to zoom in/out\n'
        'Ctrl++ and Ctrl+- can also be used\n'
        'Ctrl+0 resets the editor zoom level to 0')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #2
0
"""
Minimal example showing the use of the CommentsMode.
"""
import logging
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 CommentsMode, PythonSH


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CommentsMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.show()
    editor.appendPlainText(
'''# press Ctrl+/ to comment/uncomment selected text or the current line
class Foo:
    def bar(self):
        pass''')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #3
0
    return [
        ('An information message', CheckerMessages.INFO, 0),
        ('A warning message', CheckerMessages.WARNING, 1),
        ('An error message', CheckerMessages.ERROR, 2),
    ]


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # 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('checker.check')))
    print(editor.panels.append(CheckerPanel()))

    # 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.appendPlainText('AAA\n' * 4)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #4
0
"""
Minimal example showing the use of the AutoIndentMode.
"""
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 IndenterMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(IndenterMode()))
    editor.show()
    editor.appendPlainText('    Press TAB then Shift+Tab')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #5
0
"""
Minimal example showing the use of the PyAutoCompleteMode.
"""
import logging

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 PyAutoCompleteMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PyAutoCompleteMode()))
    editor.appendPlainText('# Please press "("\n' 'class Foo:\n' '    def bar')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #6
0
"""
Minimal example showing the use of the ZoomMode.
"""
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 ZoomMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(ZoomMode()))
    editor.appendPlainText('Use Ctrl+Mouse wheel to zoom in/out\n'
                           'Ctrl++ and Ctrl+- can also be used\n'
                           'Ctrl+0 resets the editor zoom level to 0')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #7
0
"""
Minimal example showing the use of the AutoIndentMode.
"""
import logging
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.core.modes import SymbolMatcherMode
from pyqode.python.modes import PyAutoIndentMode, PythonSH

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # PyAutoIndent needs the matcher mode and a syntax highlighter to work
    # properly
    editor.modes.append(PythonSH(editor.document()))
    editor.modes.append(SymbolMatcherMode())
    print(editor.modes.append(PyAutoIndentMode()))
    editor.show()
    editor.appendPlainText('class Foo:')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #8
0
"""
Minimal example showing the use of the CommentsMode.
"""
import logging

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 CommentsMode, PythonSH

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CommentsMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.show()
    editor.appendPlainText(
        '''# press Ctrl+/ to comment/uncomment selected text or the current line
class Foo:
    def bar(self):
        pass''')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #9
0
"""
Minimal example showing the use of the PyAutoCompleteMode.
"""
import logging
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 PyAutoCompleteMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(PyAutoCompleteMode()))
    editor.appendPlainText(
        '# Please press "("\n'
        'class Foo:\n'
        '    def bar')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
This example will show you that the caret line color is automatically set
by the syntax highlighter mode.

See how the color is different from the color obtained in
``caret_line_highligter.py``
"""
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 CaretLineHighlighterMode
from pyqode.core.modes import PygmentsSyntaxHighlighter


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CaretLineHighlighterMode()))
    print(editor.modes.append(PygmentsSyntaxHighlighter(editor.document())))
    editor.show()
    editor.appendPlainText('\n' * 10)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #11
0
"""
Minimal example showing the use of the AutoIndentMode.
"""
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 AutoIndentMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(AutoIndentMode()))
    editor.show()
    editor.appendPlainText(
        '    Please press "RETURN"; the cursor should align with this line')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #12
0
import logging
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 GoToAssignmentsMode, PythonSH


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(GoToAssignmentsMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.show()
    editor.appendPlainText(
'''press_me = 10


def spam():
    # press Ctrl+Left click on ``press_me`` to go to its definition
    print(press_me)
''')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #13
0
"""
Minimal example showing the use of the AutoCompleteMode.
"""
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 AutoCompleteMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(AutoCompleteMode()))
    editor.appendPlainText(
        'Press one of these keys to test auto completion: ", \', (, {, [\n')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #14
0
"""
Minimal example showing the use of the SymbolMatcherMode.
"""
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 SymbolMatcherMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(SymbolMatcherMode()))
    editor.appendPlainText('(----(j\njj)\n)')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #15
0
"""
Minimal example showing the use of the CalltipsMode.
"""
import logging
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 CalltipsMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CalltipsMode()))
    editor.show()
    editor.appendPlainText(
        'import os\nos.path.join')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #16
0
    """
    return [
        ('An information message', CheckerMessages.INFO, 0),
        ('A warning message', CheckerMessages.WARNING, 1),
        ('An error message', CheckerMessages.ERROR, 2),
    ]


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # 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('checker.check')))

    # 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.appendPlainText('AAA\n' * 4)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #17
0
"""
Minimal example showing the use of the SmartBackSpaceMode.
"""
import logging

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

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit, TextHelper
from pyqode.core.backend import server
from pyqode.core.modes import SmartBackSpaceMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(SmartBackSpaceMode()))
    editor.show()
    editor.appendPlainText(
        '    Please press "BACKSPACE"; the 4 whitespaces should be deleted '
        'with a single key press')
    TextHelper(editor).goto_line(0, 4)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #18
0
"""
import logging

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 GoToAssignmentsMode, PythonSH

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(GoToAssignmentsMode()))
    editor.modes.append(PythonSH(editor.document()))  # looks better
    editor.show()
    editor.appendPlainText('''press_me = 10


def spam():
    # press Ctrl+Left click on ``press_me`` to go to its definition
    print(press_me)
''')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #19
0
"""
Minimal example showing the use of the SmartBackSpaceMode.
"""
import logging
logging.basicConfig(level=logging.DEBUG)
import sys

from pyqode.qt import QtWidgets
from pyqode.core.api import CodeEdit, TextHelper
from pyqode.core.backend import server
from pyqode.core.modes import SmartBackSpaceMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(SmartBackSpaceMode()))
    editor.show()
    editor.appendPlainText(
        '    Please press "BACKSPACE"; the 4 whitespaces should be deleted '
        'with a single key press')
    TextHelper(editor).goto_line(0, 4)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #20
0
Minimal example showing the use of the AutoIndentMode.
"""
import logging
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.core.modes import SymbolMatcherMode
from pyqode.python.modes import PyAutoIndentMode, PythonSH


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    # PyAutoIndent needs the matcher mode and a syntax highlighter to work
    # properly
    editor.modes.append(PythonSH(editor.document()))
    editor.modes.append(SymbolMatcherMode())
    print(editor.modes.append(PyAutoIndentMode()))
    editor.show()
    editor.appendPlainText(
        'class Foo:')
    app.exec_()
    editor.close()
    del editor
    del app
예제 #21
0
"""
Minimal example showing the use of the AutoCompleteMode.
"""
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 AutoCompleteMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(AutoCompleteMode()))
    editor.appendPlainText(
        'Press one of these keys to test auto completion: ", \', (, {, [\n')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app
예제 #22
0
"""
Minimal example showing the use of the AutoIndentMode.
"""
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 IndenterMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(IndenterMode()))
    editor.show()
    editor.appendPlainText(
        '    Press TAB then Shift+Tab')
    app.exec_()
    editor.close()
    del editor
    del app
"""
Minimal example showing the use of the CaretLineHighlighterMode.

This example editor does not have a SyntaxHighlighterMode, the caret line color
is simply derived from the background color (darker for white background,
lighter for dark background)
"""
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 CaretLineHighlighterMode

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(CaretLineHighlighterMode()))
    editor.show()
    editor.appendPlainText('\n' * 10)
    app.exec_()
    editor.close()
    del editor
    del app
예제 #24
0
"""
Minimal example showing the use of the SymbolMatcherMode.
"""
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 SymbolMatcherMode


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    editor = CodeEdit()
    editor.backend.start(server.__file__)
    editor.resize(800, 600)
    print(editor.modes.append(SymbolMatcherMode()))
    editor.appendPlainText(
        '(----(j\njj)\n)')
    editor.show()
    app.exec_()
    editor.close()
    del editor
    del app