Exemplo n.º 1
0
def main():
    ns = _parseCommandLine()
    _fixSysPath(ns.binary)

    import qutepart  # after correct sys.path has been set

    with open(ns.file) as file:
        text = unicode(file.read(), 'utf8')

    if ns.debug:
        logging.getLogger('qutepart').setLevel(logging.DEBUG)

    app = QApplication(sys.argv)

    window = QMainWindow()

    qpart = qutepart.Qutepart()
    window.setCentralWidget(qpart)

    firstLine = text.splitlines()[0] if text else None
    qpart.detectSyntax(sourceFilePath=ns.file, firstLine=firstLine)

    qpart.lineLengthEdge = 20

    qpart.drawIncorrectIndentation = True
    qpart.drawAnyWhitespace = False

    qpart.indentUseTabs = False

    qpart.text = text

    qpart.setWindowTitle(ns.file)

    menu = {
        'File': ('printAction', ),
        'Bookmarks':
        ('toggleBookmarkAction', 'nextBookmarkAction', 'prevBookmarkAction'),
        'Navigation': (
            'scrollUpAction',
            'scrollDownAction',
            'selectAndScrollUpAction',
            'selectAndScrollDownAction',
        ),
        'Indentation': ('increaseIndentAction', 'decreaseIndentAction',
                        'autoIndentLineAction', 'indentWithSpaceAction',
                        'unIndentWithSpaceAction'),
        'Lines': ('moveLineUpAction', 'moveLineDownAction', 'deleteLineAction',
                  'copyLineAction', 'pasteLineAction', 'cutLineAction',
                  'duplicateLineAction'),
        'Edit': ('invokeCompletionAction', 'undoAction', 'redoAction')
    }
    for k, v in menu.items():
        menuObject = window.menuBar().addMenu(k)
        for actionName in v:
            menuObject.addAction(getattr(qpart, actionName))

    qpart.userWarning.connect(
        lambda text: window.statusBar().showMessage(text, 3000))

    window.resize(800, 600)
    window.show()

    from PyQt4.QtCore import QTimer
    if ns.quit:
        QTimer.singleShot(0, app.quit)

    return app.exec_()
Exemplo n.º 2
0
def main():
    ns = _parseCommandLine()
    _fixSysPath(ns.binary)

    import qutepart  # after correct sys.path has been set

    with open(ns.file, encoding='utf-8') as file:
        text = file.read()

    if ns.debug:
        logging.getLogger('qutepart').setLevel(logging.DEBUG)

    app = QApplication(sys.argv)

    window = QMainWindow()

    widget = QWidget()
    layout = QVBoxLayout(widget)
    window.setCentralWidget(widget)

    vimModeIndication = QLabel()
    vimModeIndication.setAutoFillBackground(True)
    layout.addWidget(vimModeIndication)

    qpart = qutepart.Qutepart()

    font = qpart.font()
    font.setPointSize(12)
    qpart.setFont(font)

    qpart.vimModeEnabled = False

    layout.addWidget(qpart)

    def onVimModeChanged(color, text):
        if color is not None:
            palette = vimModeIndication.palette()
            palette.setColor(QPalette.Window, color)
            vimModeIndication.setPalette(palette)
            vimModeIndication.setText(text)

    qpart.vimModeIndicationChanged.connect(onVimModeChanged)
    onVimModeChanged(*qpart.vimModeIndication)

    firstLine = text.splitlines()[0] if text else None
    qpart.detectSyntax(sourceFilePath=ns.file, firstLine=firstLine)
    if ns.show_language:
        print("Language:", qpart.language())

    qpart.lineLengthEdge = 20

    qpart.drawIncorrectIndentation = True
    qpart.drawAnyWhitespace = False

    qpart.indentUseTabs = False

    qpart.text = text

    qpart.setWindowTitle(ns.file)

    menu = {
        'File': ('printAction', ),
        'Bookmarks':
        ('toggleBookmarkAction', 'nextBookmarkAction', 'prevBookmarkAction'),
        'Navigation': (
            'scrollUpAction',
            'scrollDownAction',
            'selectAndScrollUpAction',
            'selectAndScrollDownAction',
        ),
        'Indentation': ('increaseIndentAction', 'decreaseIndentAction',
                        'autoIndentLineAction', 'indentWithSpaceAction',
                        'unIndentWithSpaceAction'),
        'Lines': ('moveLineUpAction', 'moveLineDownAction', 'deleteLineAction',
                  'copyLineAction', 'pasteLineAction', 'cutLineAction',
                  'duplicateLineAction'),
        'Edit': ('invokeCompletionAction', 'undoAction', 'redoAction')
    }
    for k, v in menu.items():
        menuObject = window.menuBar().addMenu(k)
        for actionName in v:
            menuObject.addAction(getattr(qpart, actionName))

    qpart.userWarning.connect(
        lambda text: window.statusBar().showMessage(text, 3000))

    window.resize(800, 600)
    window.show()

    from PyQt5.QtCore import QTimer
    if ns.quit:
        QTimer.singleShot(0, app.quit)

    app.exec_()

    qpart.terminate()
Exemplo n.º 3
0
#!/usr/bin/env python3

import sys
import time

from PyQt5.QtCore import QTimer, Qt
from PyQt5.QtGui import QApplication
from PyQt5.QtTest import QTest

import qutepart

app = QApplication(sys.argv)

q = qutepart.Qutepart()
q.detectSyntax(sourceFilePath=sys.argv[1])
print('Language:', q.language())

q.showMaximized()

with open(sys.argv[1], encoding='utf-8') as file_:
    text = file_.read()

clickTimes = {}


def click(key):
    clockBefore = time.clock()

    if isinstance(key, str):
        QTest.keyClicks(q, key)
    else: