From f5afad13ff21862746660e46483671aa701881fb Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sat, 20 Jun 2009 21:07:27 +0200 Subject: [PATCH] Aggiunto syntax highlighting :) --- libs/syntax_highlighter.py | 29 +++++++++++++++++++++++++++++ songbook-editor.py | 4 ++++ ui/interface.py | 6 +++--- ui/interface.ui | 4 ++-- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 libs/syntax_highlighter.py diff --git a/libs/syntax_highlighter.py b/libs/syntax_highlighter.py new file mode 100644 index 0000000..0f5bd7a --- /dev/null +++ b/libs/syntax_highlighter.py @@ -0,0 +1,29 @@ +from PyQt4 import QtGui + +class syntax_highlighter(QtGui.QSyntaxHighlighter): + def __init__(self, parent): + super(syntax_highlighter, self).__init__(parent) + + def highlightBlock(self, text): + if(len(text) >= 2): + if((text[0] == "R") & (text[1] == ":") ): + self.setFormat(0, 2,QtGui.QColor(0,0,255)) + intag = False + bold_font = QtGui.QTextCharFormat() + bold_font.setFontWeight(QtGui.QFont.Bold) + for i in range(0, len(text)): + if(text[i] == "["): + intag = True + self.setFormat(i, 1, QtGui.QColor(255,0,255)) + elif(intag): + self.setFormat(i, 1, QtGui.QColor(255,0,255)) + self.setFormat(i, 1, bold_font) + if(text[i] == "]"): + intag = False + self.setFormat(i, 1, QtGui.QColor(255,0,255)) + + + + + + diff --git a/songbook-editor.py b/songbook-editor.py index 3823559..8ee485b 100755 --- a/songbook-editor.py +++ b/songbook-editor.py @@ -9,6 +9,7 @@ os.chdir("".join(sys.argv[0].rsplit("songbook-editor.py",1))) from PyQt4 import QtGui, QtCore from interface import * from options import * +import syntax_highlighter from song import * from latex_manager import * @@ -56,6 +57,8 @@ class interface(QtGui.QMainWindow): self.connect(self.ui.actionEsporta_in_LaTeX, QtCore.SIGNAL("activated()"), self.export_songbook) self.connect(self.ui.actionOpzioni_LaTeX, QtCore.SIGNAL("activated()"), self.options) self.connect(self.ui.actionOrdina_Canzoni, QtCore.SIGNAL("activated()"), self.sort_list) + + self.sh = syntax_highlighter.syntax_highlighter(self.ui.te_body.document()) # Functions to manage events @@ -261,6 +264,7 @@ class interface(QtGui.QMainWindow): output += paragraph.content() output += "\n\n" self.ui.te_body.setDocument(QtGui.QTextDocument(output, self.ui.te_body)) + self.sh = syntax_highlighter.syntax_highlighter(self.ui.te_body.document()) def item_selected(self, item_text): diff --git a/ui/interface.py b/ui/interface.py index cdd2778..1bcf544 100644 --- a/ui/interface.py +++ b/ui/interface.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'interface.ui' # -# Created: Sat Jun 20 19:06:39 2009 +# Created: Sat Jun 20 19:36:32 2009 # by: PyQt4 UI code generator 4.4.4 # # WARNING! All changes made in this file will be lost! @@ -233,14 +233,14 @@ class Ui_MainWindow(object): QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "SongBook Editor 0.2", None, QtGui.QApplication.UnicodeUTF8)) + MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "SongBook Editor 0.3", None, QtGui.QApplication.UnicodeUTF8)) self.btn_delete_song.setText(QtGui.QApplication.translate("MainWindow", "Elimina Canzone", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("MainWindow", "Titolo", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Autore", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Copyright", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Anno", None, QtGui.QApplication.UnicodeUTF8)) self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Tonalità", None, QtGui.QApplication.UnicodeUTF8)) - self.btn_savesong.setText(QtGui.QApplication.translate("MainWindow", "Aggiungi al canzoniere", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_savesong.setText(QtGui.QApplication.translate("MainWindow", "Salva", None, QtGui.QApplication.UnicodeUTF8)) self.btn_new_song.setText(QtGui.QApplication.translate("MainWindow", "Nuova Canzone", None, QtGui.QApplication.UnicodeUTF8)) self.btn_create_pdf.setText(QtGui.QApplication.translate("MainWindow", "Esporta canzoniere in PDF", None, QtGui.QApplication.UnicodeUTF8)) self.label_6.setText(QtGui.QApplication.translate("MainWindow", "\n" diff --git a/ui/interface.ui b/ui/interface.ui index 57dd46b..1d9db98 100644 --- a/ui/interface.ui +++ b/ui/interface.ui @@ -11,7 +11,7 @@ - SongBook Editor 0.2 + SongBook Editor 0.3 @@ -208,7 +208,7 @@ - Aggiungi al canzoniere + Salva -- 2.1.4