Fix in the new song.

Leonardo Robol [2012-06-17 12:23]
Fix in the new song.
Filename
songbook-editor.py
diff --git a/songbook-editor.py b/songbook-editor.py
index a1db58b..444d680 100755
--- a/songbook-editor.py
+++ b/songbook-editor.py
@@ -88,9 +88,32 @@ class interface(QtGui.QMainWindow):

     # Get the song object of the active song
     def get_active_song(self):
-        for song in self.song_db:
-            if( song.title == unicode(self.ui.le_title.text()) ):
-                return song
+        for newsong in self.song_db:
+            if( newsong.title == unicode(self.ui.le_title.text()) ):
+                return newsong
+
+        # If no song is found means that we need to create a new one
+        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())
+        # Just debug
+        # 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 get_active_song_in_list(self):
         newsong = self.get_active_song()
@@ -107,7 +130,7 @@ class interface(QtGui.QMainWindow):
     def savesong(self):
         need_new_song = True
         song_to_save = self.get_active_song()
-        list_item = QtGui.QListWidgetItem(song_to_save.title)
+
         # Check if we have already saved this song or if it's a new entry
         for song in self.song_db:
             if(song.title == song_to_save.title):
ViewGit