Convertita tutta la gestione in unicode per non avere problemi
Leonardo Robol [2009-04-11 08:09]
Convertita tutta la gestione in unicode per non avere problemi
diff --git a/latex_manager.py b/latex_manager.py
index 8dc85d8..089adff 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"
diff --git a/songbook-editor.py b/songbook-editor.py
index 60450e8..49f301e 100755
--- a/songbook-editor.py
+++ b/songbook-editor.py
@@ -21,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())
@@ -46,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()