示例#1
0
 def onRemoteResponse(self, response, request_info):
     """
     Gets called when the backend (django) sends a packet to us.
     Populates the song table with all songs in the database.
     """
     self.status.setText("response received")
     if request_info.method == 'getAllSongs' or request_info.method == 'addSong' or request_info.method == 'deleteSong':
         self.status.setText(self.status.getText() + " - song list received")
         self.songListBox.clear()
         for item in response:
             song_id, song_num, song_title = item
             if song_num:
                 song_title = "%i %s" % (song_num, song_title)
             self.songListBox.addItem(song_title)
             self.songListBox.setValue(self.songListBox.getItemCount()-1, song_id)
     
     elif request_info.method == 'getSong':
         self.status.setText(self.status.getText() + " - song received")
         song_obj = songs.Song(response)
         self.status.setText(self.status.getText() + "; id: %i; num-chords: %i" % (song_obj.id, len(song_obj.chords) ) )
         self.songHtml.setHTML(song_obj.getHtml())
         #self.textArea.setText(song_obj.text)
     
     else:
         # Unknown response received form the server
         self.status.setText(self.status.getText() + "none!")
示例#2
0
    def load(self):
        self.notes_to_press = []

        # [[note, elapsed_time], ...]
        self.notes_time = []

        self.elapsed_time = 0.0

        # total time allowed in the song.
        self.total_time = 30.

        self.font_size = 40
        self.font = pygame.font.Font(data.filepath("freesansbold.ttf"),
                                     self.font_size)
        self.font_color = (255, 255, 255, 255)
        self.font_color = (0, 0, 0, 255)

        # the song currently being played.
        self.current_song = songs.Song()

        # a dummy song.

        s = 2.0
        self.current_song.notes_time = [
            ["a", 0.0 + s],
            ["c", 2.0 + s],
            ["b", 4.0 + s],
            ["c", 7.0 + s],
        ]
示例#3
0
    def GET(self, path):
        if not path:
            song_list = []
            results = db.select("songs")
            for row in results:
                song_list.append( {"id":row.id, "number":row.number, "title":row.title} )
            # This list of songs will get converted to JSON and passed to the front-end (client):
            
            return json.dumps( song_list )
        
        try:
            song_num = int(path)
        except ValueError:
            return "ERROR: Song number must be an integer"
        
        # results = db.select("songs", where="id=%s" % song_id)
        results = db.select("songs", where="number=%s" % song_num)
        song_dict = None
        for row in results:
            song_dict = dict(row)
            break
        
        if row == None:
            return "SONG DOES NOT EXIST: %i" % song_id
        
        song_id = song_dict["id"]
        
        chords = []
        results = db.select("song_chord_link", where="song_id=%s" % song_id)
        for row in results:
            chords.append( dict(row) )
        
        song_dict["chords"] = chords
        
        # This song dict will get converted to JSON and passed to the front-end (client):

        song = songs.Song(song_dict)
        
        web.header('Content-Type','text/html; charset=utf-8', unique=True)           
        
        return song.getHtml()
示例#4
0
"""Factory Design Pattern"""
# https://realpython.com/factory-method-python/


import songs
import serializers
import yaml_serializer


if __name__ == "__main__":
    serializer = serializers.ObjectSerializer()

    song = songs.Song('1', "Cool Guys Don't Look At Explosions", 'The Lonely Island')
    print(serializer.serialize(song, 'JSON'))
    print(serializer.serialize(song, 'XML'))
    print(serializer.serialize(song, 'YAML'))
import songs
import serializers
import yaml_serializer

song = songs.Song("1", "Water of Love", "Dire Straits")
serializer = serializers.ObjectSerializer()

print(serializer.serialize(song, "JSON"))
print("")
print(serializer.serialize(song, "XML"))
print("")
print(serializer.serialize(song, "YAML"))
示例#6
0
import songs
import serializers
import yaml_serializer
song = songs.Song('1', 'Lavitate', 'Behemoth')
serializer = serializers.ObjectSerializer()

print(serializer.serialize(song, 'JSON'))
print(serializer.serialize(song, 'XML'))

# register new serializer
serializers.factory.register_format('YAML', yaml_serializer.YamlSerializer)
print(serializer.serialize(song, 'YAML'))
示例#7
0
import serializers
import songs
import yaml_serializer

song = songs.Song('1','Water of Love','Dire Straits')
serializer = serializers.ObjectSerializer()

print(serializer.serialize(song,'JSON'))

print(serializer.serialize(song,'XML'))

print(serializer.serialize(song,'YAML'))
示例#8
0
import serializers
import songs
import yaml_serializer

song = songs.Song('1', 'Sultans of Swing', 'Dire Straits')
serializer = serializers.ObjectSerializer()
print(serializer.serialize(song, 'JSON'))
print(serializer.serialize(song, 'XML'))
print(serializer.serialize(song, 'YAML'))
示例#9
0
def upload_song():
    print(request, request.files, request.form)
    song = songs.Song(request.form, request.files)
    song.add_song(current_user.email_id)
    return navbar()