コード例 #1
0
	def correct(self,last_char,next_char,cursor):
		ch_list = [u'\n',u' ',u'\u00A0',self.language.quotes[1],'!','?']
		if last_char in'!?' and (next_char not in ch_list):
			COTextCursorFunctions.insertText(cursor,u' ')
			return True

		return False
コード例 #2
0
	def correct(self,last_char,next_char,cursor):
		ch_list = [u'\n',u' ',u'\u00A0',self.language.quotes[1],u'.']+[str(i) for i in range(10)]
		if last_char in '.,;:' and (next_char not in ch_list):
			COTextCursorFunctions.insertText(cursor,u' ')
			return True

		return False
コード例 #3
0
ファイル: TextEdit.py プロジェクト: grumpfou/AthenaWriter
	def SLOT_actionInsertImage(self):
		if self.parent()!=None:
			dft_opening_site = self.parent().get_default_opening_saving_site()
			local_dir = self.get_local_dir()
		else:
			dft_opening_site ='.'
			local_dir = False
		filepath = FMTextFileManagement.open_gui_filepath(
					dft_opening_site ,
					self,filter="Image Files (*.png *.jpg *.bmp *.gif)")

		if filepath:
			d,f = os.path.split(filepath)
			assert os.path.isabs(d)

			if local_dir and d!=os.path.abspath(local_dir):
				assert os.path.isabs(local_dir)
				r = QtWidgets.QMessageBox.question(self, "Local importation",
					"Do you want to import the file locally ?",
					QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No)
				if r== QtWidgets.QMessageBox.Yes:
					newfilepath = os.path.join(local_dir,f)
					newfilepath = FMTextFileManagement.exists(newfilepath)
					if not newfilepath:
						return False
					shutil.copyfile(filepath,newfilepath)
					tmp,newfilepath = os.path.split(newfilepath) #local path
			elif not local_dir:
				newfilepath = filepath
				r = QtWidgets.QMessageBox.question(self, "Local importation",
					"Since you did not saved the file, the absolute path "+\
					"will be displayed. For import the file localy, save "+\
					"first",
					QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.Cancel)
				if r== QtWidgets.QMessageBox.Cancel:
					return False
			else :
				tmp,newfilepath = os.path.split(filepath)	#local path

			# self.SLOT_setFormating(TSStyleImage.userPropertyId)
			self.blockSignals(True)

			cursor=self.textCursor()
			cursor.clearSelection()
			block_id = cursor.blockFormat().property(
												QtGui.QTextFormat.UserProperty)
			# # block_id = block_id.toPyObject()
			cursor.beginEditBlock()
			if block_id==TSStyleImage.userPropertyId :
				# if there is an image, we remove the previous one
				TSManager.inverseStyle(cursor,block_id)
			res,cursor1 = TSManager.inverseStyle(cursor,TSStyleImage.userPropertyId)
			COTextCursorFunctions.insertText(cursor1,newfilepath)
			cursor.endEditBlock()
			self.blockSignals(False)
			self.somethingChanged .emit()

			return filepath
		return False
コード例 #4
0
	def correct(self,last_char,next_char,cursor):
		if last_char==u'.' and next_char==u'.':

			if self.language.lastChar(cursor,n=2)==u'.':
				cursor.deleteChar()
				cursor.deletePreviousChar()
				cursor.deletePreviousChar()
				COTextCursorFunctions.insertText(cursor,u'\u2026')
				return True
		return False
コード例 #5
0
	def correct(self,last_char,next_char,cursor):
		if last_char in self.diff_quotes[0]:
			cursor.deletePreviousChar()
			COTextCursorFunctions.insertText(cursor,self.language.quotes[0])
			return True
		elif last_char in self.diff_quotes[1]:
			cursor.deletePreviousChar()
			COTextCursorFunctions.insertText(cursor,self.language.quotes[1])
			return True
		return False
コード例 #6
0
	def correct(self,last_char,next_char,cursor):
		if next_char==u'"':
			if last_char in [u' ',u'\n',u'\u00A0']:
				cursor.deleteChar()
				COTextCursorFunctions.insertText(cursor,self.language.quotes[0])
			else :
				cursor.deleteChar()
				COTextCursorFunctions.insertText(cursor,self.language.quotes[1])
			return True

		return False
コード例 #7
0
ファイル: TextEdit.py プロジェクト: grumpfou/AthenaWriter
	def SLOT_correctWord(self,word):
		"""
		Replaces the selected text with word.
		"""
		cursor = self.textCursor()
		cursor.beginEditBlock()

		cursor.removeSelectedText()
		COTextCursorFunctions.insertText(cursor,word)

		self.language.check_after_paste(cursor,len(word) )

		cursor.endEditBlock()
コード例 #8
0
    def insert_delimiters(self, delim_key, cursor):
        assert delim_key in self.delimiters
        if cursor.hasSelection():
            selectionStart = cursor.selectionStart()
            selectionEnd = cursor.selectionEnd()
            position = cursor.position()

            l1 = len(self.delimiters[delim_key][0])
            l2 = len(self.delimiters[delim_key][1])

            cursor.beginEditBlock()
            cursor.setPosition(selectionStart)
            COTextCursorFunctions.insertText(cursor,
                                             self.delimiters[delim_key][0])
            cursor.setPosition(selectionEnd + l1)
            COTextCursorFunctions.insertText(cursor,
                                             self.delimiters[delim_key][1])
            cursor.setPosition(selectionStart + l1,
                               QtGui.QTextCursor.MoveAnchor)
            cursor.setPosition(selectionEnd + l1, QtGui.QTextCursor.KeepAnchor)
            cursor.endEditBlock()
            # cursor.setPosition(position+l1,QtGui.QTextCursor.KeepAnchor)

        else:
            cursor.beginEditBlock()
            COTextCursorFunctions.insertText(cursor,
                                             self.delimiters[delim_key][0])
            COTextCursorFunctions.insertText(cursor,
                                             self.delimiters[delim_key][1])
            cursor.movePosition(QtGui.QTextCursor.Left,
                                QtGui.QTextCursor.MoveAnchor,
                                len(self.delimiters[delim_key][1]))
            cursor.endEditBlock()

        return cursor
コード例 #9
0
ファイル: TextEdit.py プロジェクト: grumpfou/AthenaWriter
	def insertFromMimeData(self,source ):
		"""A re-implementation of insertFromMimeData. We have to check the
		typography of what we have just paste.
		TODO : some summary window of all the corrections.
		"""
		self.blockSignals (True)
		cursor=self.textCursor()
		cursor.beginEditBlock()
		cursor_pos=cursor.position()
		if source.hasFormat("text/athena"):
			xml = source.data("text/athena")
			# 106 for the utf-8
			xml = QtCore.QTextCodec.codecForMib(106).toUnicode(xml)
			document = QtGui.QTextDocument()
			document.setPlainText(xml)
			TSManager.fromXml(document)
			cur = QtGui.QTextCursor(document)
			cur.select(QtGui.QTextCursor.Document)
			sel = cur.selection()
			cursor.insertFragment(cur.selection())
			size = len(sel.toPlainText())

		# if source.html()==self.lastCopy[0].html():
		# 	# if the pasted thing comes from the document itself
		# 	cursor.insertFragment(self.lastCopy[1])
		# 	size = len(self.lastCopy[1].toPlainText())
		else :
			text=source.text()
			text.replace("\t", " ")
			# for k,v in TEDictCharReplace.items():
			# 	text = text.replace(k,v)
			COTextCursorFunctions.insertText(cursor,text)
			size = len(text)

		cursor.setPosition(cursor_pos)
		if TEPreferences["DO_TYPOGRAPHY"]:
			self.language.check_after_paste(cursor,size)
		cursor.setPosition(cursor_pos)
		cursor.movePosition(
				QtGui.QTextCursor.Right,
				QtGui.QTextCursor.KeepAnchor,
				n = size)
		# self.setTextCursor(cursor)
		TSManager.recheckBlockStyle(cursor)
		TSManager.recheckCharStyle(cursor)
		cursor.endEditBlock()
		self.blockSignals (False)
コード例 #10
0
	def correct(self,last_char,next_char,cursor):
		if self.language.inside_quotes==None:
			if last_char==self.language.quotes[0] and next_char in all_spaces:
				cursor.deleteChar()
				return True
			elif last_char in all_spaces  and next_char==self.language.quotes[1]:
				cursor.deletePreviousChar()
				return True
		else:
			if last_char==self.language.quotes[0] and next_char!=self.language.inside_quotes:
				COTextCursorFunctions.insertText(cursor,self.language.inside_quotes)
				return True
			elif last_char!=self.language.inside_quotes  and next_char==self.language.quotes[1]:
				COTextCursorFunctions.insertText(cursor,self.language.inside_quotes)
				return True

		return False
コード例 #11
0
    def afterWordWritten(self, cursor):
        """Function which is called after a word has just been witten. It
		replaces some things that are specific to the language. It also correct
		the word if there has some auto-correction to make."""
        cur_tmp = QtGui.QTextCursor(cursor)
        cur_tmp.clearSelection()

        block_id = cur_tmp.blockFormat().property(
            QtGui.QTextFormat.UserProperty)
        # # block_id = block_id.toPyObject()
        if block_id != None and TSManager.dictStyle[block_id].protected:
            return False

        if cur_tmp.movePosition(QtGui.QTextCursor.Left,
                                QtGui.QTextCursor.MoveAnchor, 1):
            word, cur_tmp = self.getWordUnderCursor(cur_tmp)
            replace = False

            # We replace things due to the language : 'oe' as a elision for
            # instance
            word_replace = str(word)
            id = COWordTools.whatID(word_replace)
            word_replace = word_replace.lower()
            for rule in self.afterWordRules:
                word_replace = rule.correct(word_replace, cursor)
                if word_replace:
                    word = COWordTools.toID(word_replace, id)
                    replace = True

            # We replace things due to the language user settings.
            # Example: 'gvt' --> 'government'
            word_replace = self.dict_autocorrection.get(word, False)
            if word_replace:
                word = word_replace
                replace = True

            if replace:
                COTextCursorFunctions.insertText(cur_tmp, word)
            return replace
        return False
コード例 #12
0
	def correct(self,last_char,next_char,cursor):
		if next_char==u"'":
			cursor.deleteChar()
			COTextCursorFunctions.insertText(cursor,u'\u2019')
			return True
		return False