Phil Thompson a écrit :
On Mon, 15 Jun 2009 19:02:58 +0200, projetmbc <[email protected]>
wrote:
Hello,
I'm always trying to make my own lexer but I don't have enough
informtaion to start easily.
I have to implement some methods but what have I to do with the method
description.
What part of...
http://www.riverbankcomputing.com/static/Docs/QScintilla2/classQsciLexer.html#dd9c20adb43bc38d1a0ca3083ac3e6fa
...is causing you a problem?
Phil
Indeed I've typed the code given with this message. I have the folowing
Error :
" QsciLexerCustom.description() is abstract and must be overridden. "
What's wrong ?
Christophe.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# PRESENTATION : ce script montre comment utiliser les focntionnalités de base
du composant QSci (Scintilla).
# AUTEUR : BAL Christophe
# MAIL : [email protected]
# SITE : http://christophe_bal.club.fr/index.php
# DATE DE CREATION : 28/08/2008
#
# TEST(S) EFFECTUE(S) : programme testé sous Windows XP avec succès.
# On importe les bibliothèques que nous allons utiliser.
import sys
from PyQt4 import QtCore, QtGui, Qsci
from window_LecteurCodePython_HTML import Ui_window_LecteurCodePython_HTML
class myLexer(Qsci.QsciLexerCustom):
def setStyling(self, lenght, style_bits = 0):
print '(lenght, style_bits)'
print (lenght, style_bits)
def startStyling(self, pos, style_bits = 0):
print '(pos, style_bits)'
print (pos, style_bits)
def styleText(self, start, end):
print '(start, end)'
print (start, end)
class window_LecteurCodePython_HTML(QtGui.QMainWindow,
Ui_window_LecteurCodePython_HTML):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_window_LecteurCodePython_HTML.__init__(self)
self.setupUi(self)
self.extensionsPython = ['py','pyw']
self.extensionsHTML = ['htm','html']
font = QtGui.QFont()
font = QtGui.QFont()
font.setFamily("Arial")
font.setFixedPitch(True)
font.setPointSize(10)
fm = QtGui.QFontMetrics(font)
self.textScintilla_Principal.setFont(font)
self.textScintilla_Principal.setMarginsFont(font)
self.textScintilla_Principal.setMarginLineNumbers(1,True)
self.textScintilla_Principal.setMarginWidth(1, fm.width( "00000" ) + 5)
self.textScintilla_Principal.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)
self.textScintilla_Principal.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle)
self.textScintilla_Principal.setWrapMode(Qsci.QsciScintilla.WrapMode(Qsci.QsciScintillaBase.SC_WRAP_WORD))
self.textScintilla_Principal.setWrapVisualFlags(Qsci.QsciScintilla.WrapVisualFlag(Qsci.QsciScintilla.WrapFlagByBorder),
Qsci.QsciScintilla.WrapVisualFlag(Qsci.QsciScintilla.WrapFlagNone), 0)
self.connect(self.actionOuvrir,
QtCore.SIGNAL("triggered()"),self.ouvrirFichier)
self.textScintilla_Principal.setLexer(myLexer)
f=open('test.txt')
textFichier= f.read()
self.textScintilla_Principal.setText(textFichier)
def ouvrirFichier(self) :
self.cheminFichier = QtGui.QFileDialog.getOpenFileName(self,
self.tr("Choisir le fichier"),QtCore.QDir.currentPath(),"");
if self.cheminFichier <> '':
self.textScintilla_Principal.setMarginLineNumbers(1,True)
nomFichier = str(QtCore.QFileInfo(self.cheminFichier).fileName())
separer = nomFichier.split('.')
if len(separer) == 1 :
print 'Fichier sans extension'
else:
extension = separer[len(separer) - 1]
if extension in self.extensionsPython:
self.textScintilla_Principal.setLexer(Qsci.QsciLexerPython())
elif extension in self.extensionsHTML:
self.textScintilla_Principal.setLexer(Qsci.QsciLexerHTML())
else:
print 'Seule la coloration des fichiers HTML et Python sont
gérés par cette application Test.'
self.textScintilla_Principal.setLexer(Qsci.QsciLexerCPP())
f=open(self.cheminFichier)
textFichier= f.read()
self.textScintilla_Principal.setText(textFichier)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
LecteurCodePython = window_LecteurCodePython_HTML()
LecteurCodePython.show()
sys.exit(app.exec_())
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt