From ea3c529fdc87e0802b579abd6abe88fff0eb3eba Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sat, 11 Apr 2009 10:44:21 +0200 Subject: [PATCH 1/4] Modifiche da casa --- latex_manager.py | 7 ------ songbook-editor.mm | 30 ++------------------------ songbook-editor.py | 63 ------------------------------------------------------ 3 files changed, 2 insertions(+), 98 deletions(-) diff --git a/latex_manager.py b/latex_manager.py index 089adff..080cc7b 100644 --- a/latex_manager.py +++ b/latex_manager.py @@ -14,8 +14,6 @@ class latex_manager(): year = song.year body = song.body - # We really have to assume that latex_song is unicode, - # or the write() function will eat us! latex_song = unicode() latex_song += "\\begin{song}{" + title + "}{" + tone + "}\n{" + mauthor + "}\n{" + tauthor + "}\n{" + year + "}" + "{}\n\n\\index{" + title + "}\n\n" @@ -31,13 +29,8 @@ class latex_manager(): latex_song += "\n\\end{song}\n\n" - # Transform chords in LaTeX Chords latex_song = re.sub("\[", "\\Ch{", latex_song) - latex_song = re.sub("\](\w|\s)(\w|\s)(\w|\s)", self.quadra_to_chord_end, latex_song) latex_song = re.sub("\]", "}{}", latex_song) return latex_song - def quadra_to_chord_end(self,m): - st = "}{" + m.group(1) + m.group(2) + m.group(3) + "}" - return st diff --git a/songbook-editor.mm b/songbook-editor.mm index 762df77..fb1dc53 100644 --- a/songbook-editor.mm +++ b/songbook-editor.mm @@ -1,29 +1,3 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/songbook-editor.py b/songbook-editor.py index 49f301e..e69de29 100755 --- a/songbook-editor.py +++ b/songbook-editor.py @@ -1,63 +0,0 @@ -#!/usr/bin/env python - -from PyQt4 import QtGui, QtCore -from interface import * -from song import * -from latex_manager import * -import re - -class interface(QtGui.QMainWindow): - 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 = unicode(self.ui.le_title.text()) - newmauthor = unicode(self.ui.le_mauthor.text()) - newtauthor = unicode(self.ui.le_tauthor.text()) - newyear = unicode(self.ui.le_year.text()) - newtone = unicode(self.ui.le_tone.text()) - newsong = song(newtitle, [], newmauthor, newtauthor, newtone, newyear) - - newbody = unicode(self.ui.te_body.toPlainText()) - print newbody - newbody = re.split("\n\n+", newbody) - 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') - # Just remember that filetowrite is an "unicode" object, treat it - # as it just deserve - handle.write(filetowrite.encode("utf-8")) - handle.close() - - - - - -if __name__ == "__main__": - app = QtGui.QApplication(None) - lm = latex_manager() - widget = interface(lm) - widget.show() - app.exec_() -- 2.1.4 From 3e33e1f8622762101fd77f3ebe233ef0f106b03f Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sat, 11 Apr 2009 11:16:22 +0200 Subject: [PATCH 2/4] Revert "Convertita tutta la gestione in unicode per non avere problemi" This reverts commit 399e64e9f4e0488e36d0ca9ee69d8f69e7e62615. Conflicts: songbook-editor.py --- songbook-editor.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/songbook-editor.py b/songbook-editor.py index e69de29..17a7630 100755 --- a/songbook-editor.py +++ b/songbook-editor.py @@ -0,0 +1,64 @@ +<<<<<<< HEAD:songbook-editor.py +======= +#!/usr/bin/env python + +from PyQt4 import QtGui, QtCore +from interface import * +from song import * +from latex_manager import * +import re + +class interface(QtGui.QMainWindow): + 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 = re.split("\n\n+", newbody) + 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) + lm = latex_manager() + widget = interface(lm) + widget.show() + app.exec_() +>>>>>>> 399e64e... Convertita tutta la gestione in unicode per non avere problemi:songbook-editor.py -- 2.1.4 From cd0388f681aa41a3c55f1d4ebc6c36767adca429 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sat, 11 Apr 2009 11:39:04 +0200 Subject: [PATCH 3/4] Spero di aver sistemato... --- songbook-editor.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/songbook-editor.py b/songbook-editor.py index 17a7630..49f301e 100755 --- a/songbook-editor.py +++ b/songbook-editor.py @@ -1,5 +1,3 @@ -<<<<<<< HEAD:songbook-editor.py -======= #!/usr/bin/env python from PyQt4 import QtGui, QtCore @@ -23,11 +21,11 @@ class interface(QtGui.QMainWindow): 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()) + newtitle = unicode(self.ui.le_title.text()) + newmauthor = unicode(self.ui.le_mauthor.text()) + newtauthor = unicode(self.ui.le_tauthor.text()) + newyear = unicode(self.ui.le_year.text()) + newtone = unicode(self.ui.le_tone.text()) newsong = song(newtitle, [], newmauthor, newtauthor, newtone, newyear) newbody = unicode(self.ui.te_body.toPlainText()) @@ -48,6 +46,8 @@ class interface(QtGui.QMainWindow): filetowrite = lm.create_song(song) filename = QtGui.QFileDialog.getSaveFileName(self, "Salva file latex", "/home/leonardo", "LaTeX Source File (*.tex)") handle = open(filename, 'w') + # Just remember that filetowrite is an "unicode" object, treat it + # as it just deserve handle.write(filetowrite.encode("utf-8")) handle.close() @@ -61,4 +61,3 @@ if __name__ == "__main__": widget = interface(lm) widget.show() app.exec_() ->>>>>>> 399e64e... Convertita tutta la gestione in unicode per non avere problemi:songbook-editor.py -- 2.1.4 From 242777c038ea32ea62ceccca76cb60ae27b1f2ca Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sun, 12 Apr 2009 11:24:24 +0200 Subject: [PATCH 4/4] 4 words instead of 3 in the chord --- latex_manager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/latex_manager.py b/latex_manager.py index 080cc7b..5ccdc02 100644 --- a/latex_manager.py +++ b/latex_manager.py @@ -14,6 +14,8 @@ class latex_manager(): year = song.year body = song.body + # We really have to assume that latex_song is unicode, + # or the write() function will eat us! latex_song = unicode() latex_song += "\\begin{song}{" + title + "}{" + tone + "}\n{" + mauthor + "}\n{" + tauthor + "}\n{" + year + "}" + "{}\n\n\\index{" + title + "}\n\n" @@ -29,8 +31,13 @@ class latex_manager(): latex_song += "\n\\end{song}\n\n" + # Transform chords in LaTeX Chords latex_song = re.sub("\[", "\\Ch{", latex_song) + latex_song = re.sub("\](\w|\s)(\w|\s)(\w|\s)(\w|\s)", self.quadra_to_chord_end, latex_song) latex_song = re.sub("\]", "}{}", latex_song) return latex_song + def quadra_to_chord_end(self,m): + st = "}{" + m.group(1) + m.group(2) + m.group(3) + m.group(4) + "}" + return st -- 2.1.4