Ejemplo n.º 1
0
 def test_increment(self):
     editor = ReTextEdit(self)
     editor.tab = self.DummyReTextTab()
     QTest.keyClicks(editor, '1. Hello')
     QTest.keyClick(editor, Qt.Key.Key_Return)
     QTest.keyClicks(editor, 'World')
     self.assertEqual(editor.document().toPlainText(), '1. Hello\n2. World')
Ejemplo n.º 2
0
    def __init__(self, parent, fileName, previewState=PreviewDisabled):
        QObject.__init__(self, parent)
        self.p = parent
        self.fileName = fileName
        self.editBox = ReTextEdit(self)
        self.previewBox = self.createPreviewBox(self.editBox)
        self.markup = self.getMarkup()
        self.previewState = previewState
        self.previewBlocked = False

        textDocument = self.editBox.document()
        self.highlighter = ReTextHighlighter(textDocument)
        if enchant_available and parent.actionEnableSC.isChecked():
            self.highlighter.dictionary = enchant.Dict(parent.sl or None)
            self.highlighter.rehighlight()
        self.highlighter.docType = self.markup.name

        self.editBox.textChanged.connect(self.updateLivePreviewBox)
        self.editBox.undoAvailable.connect(parent.actionUndo.setEnabled)
        self.editBox.redoAvailable.connect(parent.actionRedo.setEnabled)
        self.editBox.copyAvailable.connect(parent.actionCopy.setEnabled)

        textDocument.modificationChanged.connect(parent.modificationChanged)

        self.updateBoxesVisibility()
Ejemplo n.º 3
0
	def createTab(self, fileName):
		self.previewBlocked = False
		self.editBoxes.append(ReTextEdit(self))
		self.highlighters.append(ReTextHighlighter(self.editBoxes[-1].document()))
		if enchant_available and self.actionEnableSC.isChecked():
			self.highlighters[-1].dictionary = \
			enchant.Dict(self.sl) if self.sl else enchant.Dict()
			self.highlighters[-1].rehighlight()
		if self.useWebKit:
			self.previewBoxes.append(self.getWebView())
		else:
			self.previewBoxes.append(QTextBrowser())
			self.previewBoxes[-1].setOpenExternalLinks(True)
		self.previewBoxes[-1].setVisible(False)
		self.fileNames.append(fileName)
		markupClass = self.getMarkupClass(fileName)
		self.markups.append(self.getMarkup(fileName))
		self.highlighters[-1].docType = (markupClass.name if markupClass else '')
		liveMode = self.restorePreviewState and self.livePreviewEnabled
		self.apc.append(liveMode)
		self.alpc.append(liveMode)
		self.aptc.append(False)
		metrics = QFontMetrics(self.editBoxes[-1].font())
		self.editBoxes[-1].setTabStopWidth(self.tabWidth*metrics.width(' '))
		self.connect(self.editBoxes[-1], SIGNAL('textChanged()'), self.updateLivePreviewBox)
		self.connect(self.editBoxes[-1], SIGNAL('undoAvailable(bool)'), self.actionUndo,
			SLOT('setEnabled(bool)'))
		self.connect(self.editBoxes[-1], SIGNAL('redoAvailable(bool)'), self.actionRedo,
			SLOT('setEnabled(bool)'))
		self.connect(self.editBoxes[-1], SIGNAL('copyAvailable(bool)'), self.enableCopy)
		self.connect(self.editBoxes[-1].document(), SIGNAL('modificationChanged(bool)'),
			self.modificationChanged)
		return self.getSplitter(-1)
Ejemplo n.º 4
0
	def createTab(self, fileName):
		self.previewBlocked = False
		self.editBoxes.append(ReTextEdit(self))
		self.highlighters.append(ReTextHighlighter(self.editBoxes[-1].document()))
		if enchant_available and self.actionEnableSC.isChecked():
			self.highlighters[-1].dictionary = \
			enchant.Dict(self.sl) if self.sl else enchant.Dict()
			self.highlighters[-1].rehighlight()
		if globalSettings.useWebKit:
			self.previewBoxes.append(self.getWebView())
		else:
			self.previewBoxes.append(QTextBrowser())
			self.previewBoxes[-1].setOpenExternalLinks(True)
		self.previewBoxes[-1].setVisible(False)
		self.fileNames.append(fileName)
		markupClass = self.getMarkupClass(fileName)
		self.markups.append(self.getMarkup(fileName))
		self.highlighters[-1].docType = (markupClass.name if markupClass else '')
		liveMode = globalSettings.restorePreviewState and globalSettings.previewState
		self.actionPreviewChecked.append(liveMode)
		self.actionLivePreviewChecked.append(liveMode)
		metrics = QFontMetrics(self.editBoxes[-1].font())
		self.editBoxes[-1].setTabStopWidth(globalSettings.tabWidth * metrics.width(' '))
		self.editBoxes[-1].textChanged.connect(self.updateLivePreviewBox)
		self.editBoxes[-1].undoAvailable.connect(self.actionUndo.setEnabled)
		self.editBoxes[-1].redoAvailable.connect(self.actionRedo.setEnabled)
		self.editBoxes[-1].copyAvailable.connect(self.enableCopy)
		self.editBoxes[-1].document().modificationChanged.connect(self.modificationChanged)
		if globalSettings.useFakeVim:
			self.installFakeVimHandler(self.editBoxes[-1])
		return self.getSplitter(-1)
Ejemplo n.º 5
0
	def test_repeat(self):
		class TestSettings:
			orderedListMode = 'repeat'
			useFakeVim = False
		editor = ReTextEdit(self, settings=TestSettings())
		editor.tab = self.DummyReTextTab()
		QTest.keyClicks(editor, '1. Hello')
		QTest.keyClick(editor, Qt.Key.Key_Return)
		QTest.keyClicks(editor, 'World')
		self.assertEqual(editor.document().toPlainText(), '1. Hello\n1. World')
Ejemplo n.º 6
0
    def __init__(self,
                 parent,
                 fileName,
                 defaultMarkup,
                 previewState=PreviewDisabled):
        super(QSplitter, self).__init__(Qt.Horizontal, parent=parent)
        self.p = parent
        self._fileName = fileName
        self.editBox = ReTextEdit(self)
        self.previewBox = self.createPreviewBox(self.editBox)
        self.defaultMarkupClass = defaultMarkup
        self.activeMarkupClass = None
        self.markup = None
        self.converted = None
        self.previewState = previewState
        self.previewOutdated = False
        self.conversionPending = False

        self.converterProcess = converterprocess.ConverterProcess()
        self.converterProcess.conversionDone.connect(self.updatePreviewBox)

        textDocument = self.editBox.document()
        self.highlighter = ReTextHighlighter(textDocument)
        if enchant is not None and parent.actionEnableSC.isChecked():
            self.highlighter.dictionary = enchant.Dict(parent.sl or None)
            # Rehighlighting is tied to the change in markup class that
            # happens at the end of this function

        self.editBox.textChanged.connect(self.triggerPreviewUpdate)
        self.editBox.undoAvailable.connect(parent.actionUndo.setEnabled)
        self.editBox.redoAvailable.connect(parent.actionRedo.setEnabled)
        self.editBox.copyAvailable.connect(parent.actionCopy.setEnabled)

        # Give both boxes a minimum size so the minimumSizeHint will be
        # ignored when splitter.setSizes is called below
        for widget in self.editBox, self.previewBox:
            widget.setMinimumWidth(125)
            self.addWidget(widget)
        self.setSizes((50, 50))
        self.setChildrenCollapsible(False)

        textDocument.modificationChanged.connect(
            self.handleModificationChanged)

        self.updateActiveMarkupClass()
Ejemplo n.º 7
0
 def setUp(self):
     self.p = self
     self.editor = ReTextEdit(self)
     self.dummytab = self.DummyReTextTab()
     self.editor.tab = self.dummytab
Ejemplo n.º 8
0
	def setUp(self):
		self.p = self
		self.editor = ReTextEdit(self)
		self.document = QTextDocument()
		self.document.setPlainText('foo bar baz qux corge grault')
		self.cursor = QTextCursor(self.document)