示例#1
0
 def save_library(self):
     try:
         if self.current_library_filename:
             ml.save_library(self.library, self.current_library_filename)
         else:
             self.save_library_as()
     except Exception as e:
         print(traceback.print_exc())
         messagebox.showerror('Create Library Error', e)
示例#2
0
 def save_library_as(self):
     try:
         library_filename = filedialog.asksaveasfilename(initialdir=os.getcwd(),
                                                         title='Save music library',
                                                         filetypes=(('json', '*.json'),),
                                                         defaultextension='.json')
         if library_filename:
             ml.save_library(self.library, library_filename)
             self.current_library_filename = library_filename
     except Exception as e:
         print(traceback.print_exc())
         messagebox.showerror('Create Library Error', e)
示例#3
0
    def write_song_list_to_file_json(self):
        if not self.library:
            return

        try:
            song_list_file_name = filedialog.asksaveasfilename(initialdir=os.getcwd(),
                                                            title='Library Song List',
                                                            filetypes=(('Text File', '*.txt'),),
                                                            defaultextension='.txt')
            if song_list_file_name:
                ml.write_song_list_json(self.library, song_list_file_name)
        except Exception as e:
            print(traceback.print_exc())
            messagebox.showerror('Write song list error.', e)
示例#4
0
 def refresh_weight_labels(self):
     relative_frequencies = ml.calculate_relative_frequency(self.library, SONGS_IN_PLAYLIST)
     for priority, weight_label in enumerate(list(zip(*self.weight_modifier_widgets))[1]):
         num_songs_in_priority = ml.get_number_of_songs_for_priority(self.library, priority)
         priority_playlist_frequency = float(num_songs_in_priority / relative_frequencies[priority]) \
                                         if relative_frequencies[priority] != '--' else 0.0
         if relative_frequencies[priority] == '--':
             weight_label_text = f'Priority: {priority}'
         else:
             weight_label_format = 'Priority: {}, {} Songs in priority. Each song will' +\
                                 ' appear in 1 out of every {:.2f} playlists ({:.2f} out of {} for a single playlist)'
             weight_label_text = weight_label_format.format(priority,
                                                     num_songs_in_priority,
                                                     float(relative_frequencies[priority]),
                                                     priority_playlist_frequency,
                                                     SONGS_IN_PLAYLIST)
         weight_label.configure(text=weight_label_text)
示例#5
0
    def create_library_from_directory(self):
        try:
            library_directory = filedialog.askdirectory()

            if library_directory:
                self.library = ml.create_library(library_directory)
                self.current_library_filename = None
                self.current_category = None
                self.refresh_category_om()
                self.refresh_song_lb(None)
                self.load_weights()
        except Exception as e:
            print(traceback.print_exc())
            messagebox.showerror('Create Library Error', e)
示例#6
0
    def load_library(self, library_filename: typing.Optional[str] = None):
        try:
            if not library_filename:
                library_filename = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select Music Library",
                                                              filetypes=(("json", "*.json"),))

            if library_filename:
                self.library = ml.load_library(library_filename)
                self.current_library_filename = library_filename
                self.current_category = None
                self.refresh_category_om()
                self.refresh_song_lb(None)
                self.load_weights()
        except Exception as e:
            print(traceback.print_exc())
            messagebox.showerror('Open Library Error', e)
示例#7
0
    def update_library_keep_repeats(self):
        if not self.library:
            return

        try:
            library_directory = filedialog.askdirectory()

            if library_directory:
                self.library = ml.get_updated_library_keep_repeats(self.library, library_directory)
                self.current_category = None
                self.refresh_category_om()
                self.refresh_song_lb(None)
                self.load_weights()
        except Exception as e:
            print(traceback.print_exc())
            messagebox.showerror('Create Library Error', e)
示例#8
0
 def library(self, path):
     MusicLibrary.load(path)
 def library(self, path):
     MusicLibrary.load(path)
 def selectedSongs(self):
     return MusicLibrary.displayCount()
 def sameGenre(self):
     MusicLibrary.findArtist(MusicLibrary.looking.genre)
 def sameAlbum(self):
     MusicLibrary.findAlbum(MusicLibrary.looking.album)
示例#13
0
 def sameArtist(self):
     MusicLibrary.findArtist(MusicLibrary.looking.artist)
示例#14
0
 def reset_repeat_data(self):
     if self.library:
         ml.reset_repeat_data(self.library)
示例#15
0
 def select(self, i):
     MusicLibrary.select(MusicLibrary.library[i-1])
示例#16
0
 def sameAlbum(self):
     MusicLibrary.findAlbum(MusicLibrary.looking.album)
示例#17
0
 def reset_repeat_data_special(self):
     if self.library:
         ml.reset_repeats_special(self.library)
示例#18
0
 def sameGenre(self):
     MusicLibrary.findArtist(MusicLibrary.looking.genre)
示例#19
0
 def query(self):
     return MusicLibrary.displayContents()
 def sameArtist(self):
     MusicLibrary.findArtist(MusicLibrary.looking.artist)
 def query(self):
     return MusicLibrary.displayContents()
 def sameYear(self):
     MusicLibrary.findArtist(MusicLibrary.looking.year)
示例#23
0
 def sameYear(self):
     MusicLibrary.findArtist(MusicLibrary.looking.year)
 def showAll(self):
     MusicLibrary.findAll()
示例#25
0
 def selectedSongs(self):
     return MusicLibrary.displayCount()
 def select(self, i):
     MusicLibrary.select(MusicLibrary.library[i - 1])
示例#27
0
 def showAll(self):
     MusicLibrary.findAll()