From 6a8e11093bd6ece4f07ddb2ac5710a5d080c0d73 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Thu, 9 Apr 2009 11:32:50 +0200 Subject: [PATCH] =?UTF-8?q?Completata=20(anche=20se=20ancora=20difettosa)?= =?UTF-8?q?=20l'esportazione=20di=20una=20singola=20canzone=20in=20LaTeX,?= =?UTF-8?q?=20ma=20manca=20ancora=20la=20lista=20e=20la=20possibilit=C3=A0?= =?UTF-8?q?=20di=20salvare?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- latex_manager.py | 36 ++++++++++++++++++++++++++++++++++++ songbook-editor.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 latex_manager.py diff --git a/latex_manager.py b/latex_manager.py new file mode 100644 index 0000000..080cc7b --- /dev/null +++ b/latex_manager.py @@ -0,0 +1,36 @@ +import re + +class latex_manager(): + def __init__(self): + ## TODO: Verify Latex Installation + print "LaTeX loaded" + + def create_song(self, song): + # Ci aspettiamo di ottenere un oggetto song + title = song.title + tone = song.tone + mauthor = song.mauthor + tauthor = song.tauthor + year = song.year + body = song.body + + latex_song = unicode() + latex_song += "\\begin{song}{" + title + "}{" + tone + "}\n{" + mauthor + "}\n{" + tauthor + "}\n{" + year + "}" + "{}\n\n\\index{" + title + "}\n\n" + + for item in body: + if(item.is_chorus()): + latex_song += "\n\\begin{SBChorus}\n" + latex_song += re.sub("\n", "\n\n", item.content()) + latex_song += "\n\\end{SBChorus}\n" + else: + latex_song += "\n\\begin{SBVerse}" + latex_song += re.sub("\n" , "\n\n", item.content()) + latex_song += "\n\\end{SBVerse}\n" + + latex_song += "\n\\end{song}\n\n" + + latex_song = re.sub("\[", "\\Ch{", latex_song) + latex_song = re.sub("\]", "}{}", latex_song) + + return latex_song + diff --git a/songbook-editor.py b/songbook-editor.py index 46ef363..2dfa7c0 100755 --- a/songbook-editor.py +++ b/songbook-editor.py @@ -3,20 +3,59 @@ from PyQt4 import QtGui, QtCore from interface import * from song import * +from latex_manager import * +import re class interface(QtGui.QMainWindow): - def __init__(self, parent=None): + def __init__(self, lm, parent=None): super(interface, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) + # Connections self.connect(self.ui.actionEsci_2, QtCore.SIGNAL("activated()"), self.exit_called) + self.connect(self.ui.btn_create_latex_song, QtCore.SIGNAL("clicked()"), self.create_latex_song) + # Functions to manage events def exit_called(self): print "TODO: Save data on exit" + def get_active_song(self): + newtitle = str(self.ui.le_title.text()) + newmauthor = str(self.ui.le_mauthor.text()) + newtauthor = str(self.ui.le_tauthor.text()) + newyear = str(self.ui.le_year.text()) + newtone = str(self.ui.le_tone.text()) + newsong = song(newtitle, [], newmauthor, newtauthor, newtone, newyear) + + newbody = unicode(self.ui.te_body.toPlainText()) + print newbody + newbody = newbody.split("\n\n") + for paragraph in newbody: + if(len(paragraph) < 3): + break + if( (paragraph[0] == 'R') & (paragraph[1] == ':') ): + newsong.add_chorus(paragraph.split("R:")[1]) + else: + newsong.add_verse(paragraph) + + return newsong + + def create_latex_song(self): + song = self.get_active_song() + filetowrite = lm.create_song(song) + filename = QtGui.QFileDialog.getSaveFileName(self, "Salva file latex", "/home/leonardo", "LaTeX Source File (*.tex)") + handle = open(filename, 'w') + handle.write(filetowrite.encode("utf-8")) + handle.close() + + + + + if __name__ == "__main__": app = QtGui.QApplication(None) - widget = interface() + lm = latex_manager() + widget = interface(lm) widget.show() app.exec_() -- 2.1.4