Пример #1
0
    def show_album_title(self, bean=None):
        if not bean:
            bean = self.bean
        if bean.UUID != self.bean.UUID:
            return
        """update info album and year"""
        info_line = bean.artist
        if bean.text in FCache().album_titles:
            info_line = FCache().album_titles[bean.text]
        else:
            album_name = self.controls.lastfm_service.get_album_name(
                bean.artist, bean.title)
            album_year = self.controls.lastfm_service.get_album_year(
                bean.artist, bean.title)
            if album_name:
                info_line = album_name
            if album_name and album_year:
                info_line = album_name + " (" + album_year + ")"

            if isinstance(info_line, str):
                FCache().album_titles[bean.text] = info_line
        if info_line and bean.UUID == self.bean.UUID:
            info_line = info_line.replace('&', '&')
            GLib.idle_add(self.album_label.set_markup, "<b>%s</b>" % info_line)
            GLib.idle_add(self.controls.coverlyrics.album_title.set_markup,
                          "<b>%s</b>" % info_line)
Пример #2
0
 def task():
     logging.debug("radio Lazy loading")
     if FCache().cache_radio_tree_beans:
         self.populate_all(FCache().cache_radio_tree_beans)
     else:
         self.update_radio_tree()
     self.is_radio_populated = True
Пример #3
0
 def on_toggle_singletab(widget, data=None):
     self.tree_controller.clear_tree()
     for path in FCache().music_paths[0]:
         self.tree_controller.append(
             FDModel(os.path.basename(path), path).add_is_file(False))
     self.temp_music_paths = FCache().music_paths[0][:]
     self.frame.show()
Пример #4
0
 def on_add_button_click(self):
     self._append_tab()
     self.controls.perspectives.get_perspective('fs').show_add_button()
     FCache().music_paths.insert(0, [])
     FCache().tab_names.insert(
         0, self.get_full_tab_name(self.get_current_tree().scroll))
     FCache().cache_music_tree_beans.insert(0, {})
Пример #5
0
    def add_folder(self, in_new_tab=False):
        chooser = Gtk.FileChooserDialog(title=_("Choose directory with music"),
                                        action=Gtk.FileChooserAction.SELECT_FOLDER,
                                        buttons=(Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        chooser.set_default_response(Gtk.ResponseType.OK)
        chooser.set_select_multiple(True)
        if FCache().last_music_path:
            chooser.set_current_folder(FCache().last_music_path)
        response = chooser.run()

        if response == Gtk.ResponseType.OK:
            paths = chooser.get_filenames()
            chooser.destroy()
            self.controls.main_window.present()

            def task():
                tabhelper = self.controls.perspectives.get_perspective('fs').get_tabhelper()
                path = paths[0]
                FCache().last_music_path = path[:path.rfind("/")]
                tree = self
                number_of_tab = tabhelper.page_num(tree.scroll)

                if in_new_tab:
                    tab_name = unicode(path[path.rfind("/") + 1:])
                    tabhelper._append_tab(tab_name)
                    tree = tabhelper.get_current_tree()
                    number_of_tab = tabhelper.get_current_page()
                    FCache().music_paths.insert(0, [])
                    FCache().tab_names.insert(0, tab_name)
                    FCache().cache_music_tree_beans.insert(0, {})

                elif tree.is_empty():
                    tab_name = unicode(path[path.rfind("/") + 1:])
                    vbox = Gtk.VBox()
                    label = Gtk.Label(tab_name + " ")
                    label.set_angle(90)
                    if FC().tab_close_element:
                        vbox.pack_start(tabhelper.button(tree.scroll), False, False)
                    vbox.pack_end(label, False, False)
                    event = self.controls.notetabs.to_eventbox(vbox, tree)
                    event = tabhelper.tab_menu_creator(event, tree.scroll)
                    event.connect("button-press-event", tabhelper.on_button_press)
                    tabhelper.set_tab_label(tree.scroll, event)
                    FCache().tab_names[number_of_tab] = tab_name
                    FCache().music_paths[number_of_tab] = []

                for path in paths:
                    if path in FCache().music_paths[number_of_tab]:
                        pass
                    else:
                        FCache().music_paths[number_of_tab].append(path)
                        #self.controls.preferences.on_load()
                        logging.info("New music paths" + str(FCache().music_paths[number_of_tab]))
                self.controls.update_music_tree(tree, number_of_tab)

            #self.controls.in_thread.run_with_progressbar(task, with_lock=False)
            self.controls.search_progress.background_spinner_wrapper(task)
        elif response == Gtk.ResponseType.CANCEL:
            logging.info('Closed, no files selected')
            chooser.destroy()
Пример #6
0
    def update_music_tree(self, tree=None, number_of_page=0):
        if not tree:
            tree = self.tree

        logging.info("Update music tree" +
                     str(FCache().music_paths[number_of_page]))
        tree.clear_tree()
        FCache().cache_music_tree_beans[number_of_page] = []

        all = []

        all = get_all_music_by_paths(FCache().music_paths[number_of_page],
                                     self)

        for bean in all:
            FCache().cache_music_tree_beans[number_of_page].append(bean)
        try:
            self.perspective.hide_add_button()
        except AttributeError:
            logging.warn("Object perspective not exists yet")

        if not all:
            tree.is_empty = True
            try:
                self.perspective.show_add_button()
            except AttributeError:
                logging.warn("Object perspective not exists yet")
            all.append(FModel(_("Music not found in folder(s):")))
            for path in FCache().music_paths[number_of_page]:
                all.append(FModel(path).add_is_file(True))
        else:
            tree.is_empty = False

        tree.append_all(all)
        tree.ext_width = tree.ext_column.get_width()
Пример #7
0
 def load_music_tree(self):
     self.perspective.hide_add_button()
     if not FCache().cache_music_tree_beans[0] and len(FCache().cache_music_tree_beans) == 1:
         
         self.perspective.show_add_button()
         
         self.tree.is_empty = True
         
         if FCache().tab_names[0]:
             self.tabhelper.label.set_label(FCache().tab_names[0] + " ")
     else:
         tabs = len(FCache().cache_music_tree_beans)
         self.tree.simple_append_all(FCache().cache_music_tree_beans[tabs - 1])
         self.tabhelper.label.set_label(FCache().tab_names[tabs - 1] + " ")
         for tab in xrange(tabs - 2, -1, -1):
             
             tree = NavigationTreeControl(self)
             tree.simple_append_all(FCache().cache_music_tree_beans[tab])
             self.tabhelper._append_tab(FCache().tab_names[tab], navig_tree=tree)
             if not FCache().cache_music_tree_beans[tab]: 
                 tree.is_empty = True
                 self.perspective.show_add_button()
         
         logging.info("Tree loaded from cache")
     
     if FC().update_tree_on_start:
         def cycle():
             for n in xrange(len(FCache().music_paths)):
                 tab_child = self.tabhelper.get_nth_page(n)
                 tree = tab_child.get_child()
                 self.update_music_tree(tree, n)
         gobject.idle_add(cycle)
Пример #8
0
 def save_tabs(self):
     number_music_tabs = self.get_n_pages()
     FCache().cache_pl_tab_contents = []
     FCache().tab_pl_names = []
     if number_music_tabs > 0:
         for tab_number in range(self.get_n_pages()):
             self.save_nth_tab(tab_number)
Пример #9
0
 def delete_files(self, a):
     row_refs, paths, get_iter_from_row_reference = a
     copy_paths = paths[:]
     if delete_files_from_disk(row_refs, paths, get_iter_from_row_reference):
         beans = FCache().cache_music_tree_beans[self.controls.tabhelper.get_current_page()]
         for bean in beans[:] :
             if bean.path in copy_paths:
                 beans.remove(bean)
Пример #10
0
 def on_delete_tab(self, child):
     n = self.page_num(child)
     if self.get_n_pages() == 1: return
     self.remove_page(n)
     if self.navig:
         del FCache().tab_names[n]
         del FCache().music_paths[n]
         del FCache().cache_music_tree_beans[n]
Пример #11
0
 def lazy_load(self):
     if not self.is_lazy_load:
         logging.debug("radio Lazy loading")
         self.populate_all(FCache().cache_radio_tree_beans)
         if not FCache().cache_radio_tree_beans:
             logging.debug("populdate from file system")
             self.update_radio_tree()
         self.is_lazy_load = True
Пример #12
0
 def delete_files(self, a):
     row_refs, paths, get_iter_from_row_reference = a
     copy_paths = paths[:]
     if delete_files_from_disk(row_refs, paths,
                               get_iter_from_row_reference):
         beans = FCache().cache_music_tree_beans[
             self.controls.tabhelper.get_current_page()]
         for bean in beans[:]:
             if bean.path in copy_paths:
                 beans.remove(bean)
Пример #13
0
 def save_nth_tab(self, tab_number):
     tab = self.get_nth_page(tab_number)
     pl_tree = tab.get_child()
     FCache().cache_pl_tab_contents.append(
         [list(row) for row in pl_tree.model])
     FCache().tab_pl_names.append(self.get_full_tab_name(tab))
     for i, column in enumerate(pl_tree.get_columns()):
         FC().columns[column.key][1] = i
         if column.get_width(
         ) > 1:  #to avoid recording of zero width in config
             FC().columns[column.key][2] = column.get_width()
Пример #14
0
 def reorder_callback(self, notebook, child, new_page_num):
     for list in [
             FCache().music_paths,
             FCache().tab_names,
             FCache().cache_music_tree_beans
     ]:
         reorderer_list(
             list,
             new_page_num,
             self.page_number,
         )
Пример #15
0
 def add_dir(self, *a):
     current_folder = FCache().last_music_path if FCache().last_music_path else None
     paths = directory_chooser_dialog(_("Choose directory with music"), current_folder)
     if not paths:
         return
     path = paths[0]
     FCache().last_music_path = path[:path.rfind("/")]          
     for path in paths:            
         if path not in self.temp_music_paths:
             self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
             self.temp_music_paths.append(path)
Пример #16
0
 def save_beans_from_tree(self):
     number_of_page = self.controls.notetabs.page_num(self.scroll)
     FCache().cache_music_tree_beans[number_of_page] = []
     for row in self.model:
         def task(row):
             for child_row in row.iterchildren():
                 bean = self.get_bean_from_row(child_row)
                 FCache().cache_music_tree_beans[number_of_page].append(bean)
                 if child_row.iterchildren():
                     task(child_row)
         bean = self.get_bean_from_row(row)
         FCache().cache_music_tree_beans[number_of_page].append(bean)
         if row.iterchildren():
             task(row)
Пример #17
0
 def task(row):
     for child_row in row.iterchildren():
         bean = self.get_bean_from_row(child_row)
         FCache().cache_music_tree_beans[number_of_page].append(
             bean)
         if child_row.iterchildren():
             task(child_row)
Пример #18
0
    def remove_dir(self, *a):
        selection = self.tree_controller.get_selection()
        fm, paths = selection.get_selected_rows()  #@UnusedVariable
        paths.reverse()
        for path in paths:
            del FCache().music_paths[0][path[0]]
            del FCache().cache_music_tree_beans[0][path[0]]

        self.tree_controller.delete_selected()
        remaining_beans = self.tree_controller.get_all_beans()
        if remaining_beans:
            self.temp_music_paths = [
                bean.path for bean in self.tree_controller.get_all_beans()
            ]
        else:
            self.temp_music_paths = []
Пример #19
0
    def get_dest_folder(self, to_f_model, to_filter_iter, to_filter_path):
        if to_filter_iter:
            path = to_f_model.get_value(to_filter_iter, self.path[0])
            if os.path.isdir(path):
                return path
            parent_iter = to_f_model.iter_parent(to_filter_iter)
        else:
            return FCache().music_paths[
                self.controls.tabhelper.get_current_page()][-1]
        if not parent_iter:
            logging.debug("no parent iter found")
            if to_filter_path[-1] > 0:
                previous_iter = to_f_model.get_iter((to_filter_path[-1] - 1, ))
                previous_path = to_f_model.get_value(previous_iter,
                                                     self.path[0])
                dest_folder = os.path.dirname(previous_path)
            else:
                logging.debug("item is top in tree")
                next_path = to_f_model.get_value(to_f_model.get_iter_root(),
                                                 self.path[0])
                dest_folder = os.path.dirname(next_path)
        else:
            dest_folder = to_f_model.get_value(parent_iter, self.path[0])

        return dest_folder
Пример #20
0
 def on_quit(self):
     number_music_tabs = self.get_n_pages() - 1
     FCache().cache_pl_tab_contents = []
     FCache().tab_pl_names = []
     if number_music_tabs > 0:
         for page in xrange(number_music_tabs, 0, -1):
             tab_content = self.get_nth_page(page)
             pl_tree = tab_content.get_child()
             FCache().cache_pl_tab_contents.append(
                 [list(row) for row in pl_tree.model])
             FCache().tab_pl_names.append(
                 self.get_text_label_from_tab(tab_content))
             for i, column in enumerate(pl_tree.get_columns()):
                 FC().columns[column.key][1] = i
                 if column.get_width(
                 ) > 1:  #to avoid recording of zero width in config
                     FC().columns[column.key][2] = column.get_width()
Пример #21
0
 def task():
     self.save_lock.acquire()
     try:
         self.save_tabs()
         FCache().save()
     finally:
         if self.save_lock.locked():
             self.save_lock.release()
Пример #22
0
 def on_load(self):
     self.tree_controller.clear_tree()
     for path in FCache().music_paths[0]:
         self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
         
     self.files_controller.clear_tree()
     for ext in FC().all_support_formats:
         self.files_controller.append(FDModel(ext))
         
     self.adjustment.set_value(FC().gap_secs)
     if FC().tabs_mode == "Single":
         self.singletab_button.set_active(True)
         self.controls.tabhelper.set_show_tabs(False)
         
     if FC().update_tree_on_start:
         self.update_on_start.set_active(True)
     
     self.temp_music_paths = FCache().music_paths[0][:] #create copy of list
Пример #23
0
 def show_album_title(self):
     bean = self.bean
     """update info album and year"""
     info_line = bean.artist
     if FCache().album_titles.has_key(bean.text):
         info_line = FCache().album_titles[bean.text]
     else:
         album_name = self.controls.lastfm_service.get_album_name(bean.artist, bean.title)
         album_year = self.controls.lastfm_service.get_album_year(bean.artist, bean.title)
         if album_name:
             info_line = album_name
         if album_name and album_year:
             info_line = album_name + "(" + album_year + ")"
         
         if isinstance(info_line, unicode) or isinstance(info_line, str) :
             FCache().album_titles[bean.text] = info_line
     info_line.replace('&', '&amp;')
     self.album_label.set_markup("<b>%s</b>" % info_line)
     self.controls.coverlyrics.album_title.set_markup("<b>%s</b>" % info_line)
Пример #24
0
 def task():
     self.save_lock.acquire()
     try:
         tab_number = self.get_current_page()
         tab = self.get_nth_page(tab_number)
         pl_tree = tab.get_child()
         FCache().cache_pl_tab_contents[tab_number] = [
             list(row) for row in pl_tree.model
         ]
         FCache().tab_pl_names[tab_number] = self.get_full_tab_name(tab)
         for i, column in enumerate(pl_tree.get_columns()):
             FC().columns[column.key][1] = i
             if column.get_width(
             ) > 1:  #to avoid recording of zero width in config
                 FC().columns[column.key][2] = column.get_width()
                 FCache().save()
     finally:
         if self.save_lock.locked():
             self.save_lock.release()
Пример #25
0
 def on_save(self):
     FCache().music_paths[0] = self.tree_controller.get_all_beans_text()
     FC().all_support_formats = self.files_controller.get_all_beans_text()
     FC().gap_secs = self.adjustment.get_value()
     if self.singletab_button.get_active():
         for i in xrange(len(FCache().music_paths) - 1, 0, -1):
             del FCache().music_paths[i]
             del FCache().cache_music_tree_beans[i]
             del FCache().tab_names[i]
             self.controls.tabhelper.remove_page(i)
         FC().tabs_mode = "Single"
         self.controls.tabhelper.set_show_tabs(False)
     else:
         FC().tabs_mode = "Multi"
         self.controls.tabhelper.set_show_tabs(True)
     if self.update_on_start.get_active():
         FC().update_tree_on_start = True
     else:
         FC().update_tree_on_start = False
Пример #26
0
    def on_load(self):
        if FC().tab_position == "no":
            self.set_tab_no()
        elif FC().tab_position == "left":
            self.set_tab_left()
        else:
            self.set_tab_top()

        for page in range(len(FCache().cache_pl_tab_contents) - 1, -1, -1):
            if not FCache().cache_pl_tab_contents[page]:
                self._append_tab(FCache().tab_pl_names[page])
                continue
            self._append_tab(FCache().tab_pl_names[page])

            for row in FCache().cache_pl_tab_contents[page]:
                self.get_current_tree().model.append(
                    None, FTreeModel.normalize_row(row))

        self.set_current_page(FC().pl_selected_tab)
        self.loaded = True
Пример #27
0
 def show_album_title(self):
     bean = self.bean
     """update info album and year"""
     info_line = bean.artist
     if FCache().album_titles.has_key(bean.text):
         info_line = FCache().album_titles[bean.text]
     else:
         album_name = self.controls.lastfm_service.get_album_name(bean.artist, bean.title)
         album_year = self.controls.lastfm_service.get_album_year(bean.artist, bean.title)
         if album_name:
             info_line = album_name
         if album_name and album_year:
             info_line = album_name + "(" + album_year + ")"
         
         if isinstance(info_line, unicode) or isinstance(info_line, str) :
             FCache().album_titles[bean.text] = info_line
     if info_line:
         info_line = info_line.replace('&', '&amp;')
         self.album_label.set_markup("<b>%s</b>" % info_line)
         self.controls.coverlyrics.album_title.set_markup("<b>%s</b>" % info_line)
Пример #28
0
 def rename_files(self, a):
     row, index_path, index_text = a
     if rename_file_on_disk(row, index_path, index_text):
         old_bean = self.get_selected_bean()
         beans = FCache().cache_music_tree_beans[
             self.controls.tabhelper.get_current_page()]
         for bean in beans:
             if old_bean == bean:
                 bean.path = row[index_path]
                 bean.text = row[index_text]
                 break
Пример #29
0
    def load_music_tree(self):
        tabs = len(FCache().cache_music_tree_beans)
        tabhelper = self.perspectives.get_perspective('fs').get_tabhelper()
        for tab in xrange(tabs - 1, -1, -1):
            tabhelper._append_tab(FCache().tab_names[tab], rows=FCache().cache_music_tree_beans[tab])

            if not FCache().cache_music_tree_beans[tab]:
                self.perspectives.get_perspective('fs').show_add_button()
            else:
                self.perspectives.get_perspective('fs').hide_add_button()

            logging.info("Tree loaded from cache")

        if FC().update_tree_on_start:
            def cycle():
                for n in xrange(len(FCache().music_paths)):
                    tab_child = tabhelper.get_nth_page(n)
                    tree = tab_child.get_child()
                    self.update_music_tree(tree, n)
            GLib.idle_add(cycle)
Пример #30
0
 def add_dir(self, *a):
     chooser = gtk.FileChooserDialog(
         title=_("Choose directory with music"),
         action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
         buttons=(gtk.STOCK_OPEN, gtk.RESPONSE_OK))
     chooser.set_default_response(gtk.RESPONSE_OK)
     chooser.set_select_multiple(True)
     if FCache().last_music_path:
         chooser.set_current_folder(FCache().last_music_path)
     response = chooser.run()
     if response == gtk.RESPONSE_OK:
         paths = chooser.get_filenames()
         path = paths[0]
         FCache().last_music_path = path[:path.rfind("/")]
         for path in paths:
             if path not in self.tree_controller.get_all_beans_text():
                 self.tree_controller.append(FDModel(path))
         self.reload_dir()
     elif response == gtk.RESPONSE_CANCEL:
         logging.info('Closed, no files selected')
     chooser.destroy()
Пример #31
0
    def on_load(self):
        if FC().tab_position == "no":
            self.set_tab_no()
        elif FC().tab_position == "left":
            self.set_tab_left()
        else:
            self.set_tab_top()

        for page in range(len(FCache().cache_pl_tab_contents) - 1, -1, -1):
            if not FCache().cache_pl_tab_contents[page]:
                self._append_tab(FCache().tab_pl_names[page])
                continue
            self._append_tab(FCache().tab_pl_names[page])
            model_len = len(FTreeModel().__dict__)
            cache_len = len(FCache().cache_pl_tab_contents[page][0])

            for row in FCache().cache_pl_tab_contents[page]:
                if model_len > cache_len:
                    for i in range(abs(model_len - cache_len)):
                        row.append((None, None))
                elif model_len < cache_len:
                    for i in range(abs(model_len - cache_len)):
                        del row[-1]

                self.get_current_tree().model.append(None, row)

        self.set_current_page(FC().pl_selected_tab)
        self.loaded = True
Пример #32
0
            def task():
                path = paths[0]
                FCache().last_music_path = path[:path.rfind("/")]
                tree = self
                number_of_tab = self.controls.tabhelper.page_num(tree.scroll)

                if in_new_tab:
                    tree = NavigationTreeControl(self.controls)
                    tab_name = unicode(path[path.rfind("/") + 1:])
                    self.controls.tabhelper._append_tab(tab_name,
                                                        navig_tree=tree)
                    number_of_tab = self.controls.tabhelper.get_current_page()
                    FCache().music_paths.insert(0, [])
                    FCache().tab_names.insert(0, tab_name)
                    FCache().cache_music_tree_beans.insert(0, [])

                elif tree.is_empty:
                    tab_name = unicode(path[path.rfind("/") + 1:])
                    vbox = gtk.VBox()
                    label = gtk.Label(tab_name + " ")
                    label.set_angle(90)
                    if FC().tab_close_element:
                        vbox.pack_start(
                            self.controls.tabhelper.button(tree.scroll), False,
                            False)
                    vbox.pack_end(label, False, False)
                    event = self.controls.notetabs.to_eventbox(vbox, tree)
                    event = self.controls.tabhelper.tab_menu_creator(
                        event, tree.scroll)
                    event.connect("button-press-event",
                                  self.controls.tabhelper.on_button_press)
                    self.controls.tabhelper.set_tab_label(tree.scroll, event)
                    FCache().tab_names[number_of_tab] = tab_name
                    FCache().music_paths[number_of_tab] = []

                for path in paths:
                    if path in FCache().music_paths[number_of_tab]:
                        pass
                    else:
                        FCache().music_paths[number_of_tab].append(path)
                        #self.controls.preferences.on_load()
                        logging.info("New music paths" +
                                     str(FCache().music_paths[number_of_tab]))
                self.controls.update_music_tree(tree, number_of_tab)
                FC().save()
Пример #33
0
    def show_album_title(self, bean=None):
        if not bean:
            bean = self.bean
        if bean.UUID != self.bean.UUID:
            return

        """update info album and year"""
        info_line = bean.artist
        if bean.text in FCache().album_titles:
            info_line = FCache().album_titles[bean.text]
        else:
            album_name = self.controls.lastfm_service.get_album_name(bean.artist, bean.title)
            album_year = self.controls.lastfm_service.get_album_year(bean.artist, bean.title)
            if album_name:
                info_line = album_name
            if album_name and album_year:
                info_line = album_name + " (" + album_year + ")"

            if isinstance(info_line, unicode) or isinstance(info_line, str):
                FCache().album_titles[bean.text] = info_line
        if info_line and bean.UUID == self.bean.UUID:
            info_line = info_line.replace('&', '&amp;')
            GLib.idle_add(self.album_label.set_markup, "<b>%s</b>" % info_line)
            GLib.idle_add(self.controls.coverlyrics.album_title.set_markup, "<b>%s</b>" % info_line)
Пример #34
0
    def show_disc_cover(self, bean=None):
        if not bean:
            bean = self.bean
        if bean.UUID != self.bean.UUID:
            return
        dict = FCache().covers

        """update image"""
        if not bean.image:
            if not os.path.isdir(COVERS_DIR):
                os.mkdir(COVERS_DIR)
            list_images = os.listdir(COVERS_DIR)
            """remove extra keys"""
            for key in dict.keys():
                if (key + ".jpg") not in list_images:
                    del dict[key]
            """remove extra files"""
            for file in list_images:
                if os.path.splitext(file)[0] not in dict.keys() and os.path.isfile(os.path.join(COVERS_DIR, file)):
                    os.remove(os.path.join(COVERS_DIR, file))

            for list, key in zip(dict.values(), dict.keys()):
                if bean.text in list:
                    bean.image = os.path.join(COVERS_DIR, key + ".jpg")
                    break

            if not bean.image:
                """get image url"""
                bean.image = self.controls.lastfm_service.get_album_image_url(bean.artist, bean.title)

        if not bean.image:
            logging.warning(
                """""Can't get cover image. Check the correctness of the artist's name and track title""" ""
            )

        """make .jpg image and store it in cache"""
        if bean.image and bean.image.startswith("http://"):
            url_basename = os.path.splitext(os.path.basename(bean.image))[0]
            if dict.has_key(url_basename):
                dict[url_basename].append(bean.text)
            else:
                dict[url_basename] = [bean.text]
                self.image.get_pixbuf().save(os.path.join(COVERS_DIR, url_basename + ".jpg"), "jpeg", {"quality": "90"})

        if bean.UUID == self.bean.UUID:
            self.image.update_info_from(bean)
            self.controls.trayicon.update_info_from(bean)
            self.controls.coverlyrics.set_cover()
Пример #35
0
 def on_toggle_singletab(widget, data=None):
     self.tree_controller.clear_tree()
     for path in FCache().music_paths[0]:
         self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
     self.temp_music_paths = FCache().music_paths[0][:]
     self.frame.show()
Пример #36
0
class MusicLibraryConfig(ConfigPlugin, FControl):
    name = CONFIG_MUSIC_LIBRARY
    enable = True

    def __init__(self, controls):
        FControl.__init__(self, controls)

        box = Gtk.VBox(False, 0)
        box.hide()
        box.pack_start(self.tabs_mode(), False, True, 0)
        box.pack_start(self.dirs(), False, True, 0)
        box.pack_start(self.formats(), False, True, 0)

        self.widget = box
        uhbox = Gtk.HBox()
        ulabel = Gtk.Label(_("Update library on start (more slow) "))
        self.update_on_start = Gtk.CheckButton()

        uhbox.pack_start(ulabel, False, True, 0)
        uhbox.pack_start(self.update_on_start, False, False, 0)
        box.pack_start(uhbox, False, True, 0)
        box.pack_start(self.gap(), False, True, 0)

    def dirs(self):
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()
        self.frame = FrameDecorator(_("Music dirs"), frame_box, 0.5, 0.5, border_width=0)
        self.frame.show()
        self.frame.set_no_show_all(True)

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame

    def reload_dir(self, *a):
        FCache().music_paths[0] = self.temp_music_paths[:] #create copy of list
        self.controls.update_music_tree()

    def on_load(self):
        self.tree_controller.clear_tree()
        for path in FCache().music_paths[0]:
            self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))

        self.files_controller.clear_tree()
        for ext in FC().all_support_formats:
            self.files_controller.append(FDModel(ext))

        self.adjustment.set_value(FC().gap_secs)

        if FC().tabs_mode == "Single":
            self.singletab_button.set_active(True)
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(False)

        if FC().update_tree_on_start:
            self.update_on_start.set_active(True)

        self.temp_music_paths = FCache().music_paths[0][:] #create copy of list

    def on_save(self):
        FC().all_support_formats = self.files_controller.get_all_beans_text()
        FC().gap_secs = self.adjustment.get_value()

        if self.singletab_button.get_active():
            '''for i in xrange(len(FCache().music_paths) - 1, 0, -1):
                del FCache().music_paths[i]
                del FCache().cache_music_tree_beans[i]
                del FCache().tab_names[i]
                self.controls.tabhelper.remove_page(i)'''
            FC().tabs_mode = "Single"
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(False)
            if self.temp_music_paths != FCache().music_paths[0]:
                self.reload_dir()

        else:
            FC().tabs_mode = "Multi"
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(True)
        if self.update_on_start.get_active():
            FC().update_tree_on_start = True
        else:
            FC().update_tree_on_start = False

    def add_dir(self, *a):
        current_folder = FCache().last_music_path if FCache().last_music_path else None
        paths = directory_chooser_dialog(_("Choose directory with music"), current_folder)
        if not paths:
            return
        path = paths[0]
        FCache().last_music_path = path[:path.rfind("/")]
        for path in paths:
            if path not in self.temp_music_paths:
                self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
                self.temp_music_paths.append(path)

    def remove_dir(self, *a):
        selection = self.tree_controller.get_selection()
        fm, paths = selection.get_selected_rows()#@UnusedVariable
        paths.reverse()
        for path in paths:
            del FCache().music_paths[0][path[0]]
            del FCache().cache_music_tree_beans[0][path[0]]

        self.tree_controller.delete_selected()
        remaining_beans = self.tree_controller.get_all_beans()
        if remaining_beans:
            self.temp_music_paths = [bean.path for bean in self.tree_controller.get_all_beans()]
        else:
            self.temp_music_paths = []

    def formats(self):
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        frame = FrameDecorator(_("File Types"), frame_box, 0.5, 0.5, border_width=0)
        frame.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        return frame

    def on_add_file(self, *a):
        val = show_entry_dialog(_("Please add audio extension"), _("Extension should be like '.mp3'"))
        if val and val.find(".") >= 0 and len(val) <= 5 and val not in self.files_controller.get_all_beans_text():
            self.files_controller.append(FDModel(val))
        else:
            logging.info("Can't add your value" + val)

    def gap(self):
        label = Gtk.Label(_("Gap between tracks"))

        self.adjustment = Gtk.Adjustment(value=0, lower=0, upper=5, step_incr=0.5)

        gap_len = Gtk.SpinButton(adjustment=self.adjustment, climb_rate=0.0, digits=1)
        gap_len.show()

        hbox = Gtk.HBox(False, 10)
        hbox.pack_start(gap_len, False, False, 0)
        hbox.pack_start(label, False, False, 0)
        hbox.show_all()

        return hbox

    def tabs_mode(self):
        hbox = Gtk.HBox()
        self.multitabs_button = Gtk.RadioButton.new_with_label(None, _("Multi tab mode"))
        def on_toggle_multitab(widget, data=None):
            self.frame.hide()
        self.multitabs_button.connect("toggled", on_toggle_multitab)
        hbox.pack_start(self.multitabs_button, True, False, 0)

        self.singletab_button = Gtk.RadioButton.new_with_label_from_widget(self.multitabs_button, _("Single tab mode"))
        def on_toggle_singletab(widget, data=None):
            self.tree_controller.clear_tree()
            for path in FCache().music_paths[0]:
                self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
            self.temp_music_paths = FCache().music_paths[0][:]
            self.frame.show()
        self.singletab_button.connect("toggled", on_toggle_singletab)
        hbox.pack_end(self.singletab_button, True, False, 0)
        return hbox