From 66ba76847fd64fde3b91c034444ad50a1d670a27 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sun, 17 Jun 2012 14:23:46 +0200 Subject: [PATCH] Fix in the new song. --- songbook-editor.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) 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): -- 2.1.4