def __init__(self, controls): FControl.__init__(self, controls) gtk.HBox.__init__(self, False, 0) self.old_menu = MenuBarWidget(controls) self.pack_start(self.old_menu.widget, False, False) self.new_menu_button = ImageButton(gtk.STOCK_PREFERENCES) self.new_menu_button.connect("button-press-event", self.on_button_press) self.pack_start(self.new_menu_button, False, False) self.pack_start(controls.playback, False, False) self.pack_start(controls.os, False, False) self.pack_start(controls.volume, False, False) self.pack_start(gtk.SeparatorToolItem(), False, False) self.pack_start(controls.seek_bar, True, True) self.show_all() """menu init""" menu = Popup() decorator = MenuStyleDecorator() MenuBarWidget(self.controls, menu) menu.add_separator() menu.add_item(_("Preferences"), gtk.STOCK_PREFERENCES, self.controls.show_preferences) menu.add_separator() menu.add_item(_("Quit"), gtk.STOCK_QUIT, self.controls.quit) decorator.apply(menu) self.menu = menu
def on_button_press(self, w, e): active = self.get_selected_bean() if is_rigth_click(e): menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play, active) menu.add_item(_('Copy to Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) menu.show(e)
def __init__(self, controls): FControl.__init__(self, controls) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.old_menu = MenuBarWidget(controls) self.pack_start(self.old_menu.widget, False, False, 0) self.new_menu_button = ImageButton("preferences-system", tooltip_text=_("Settings")) self.new_menu_button.connect("button-press-event", self.on_button_press) self.pack_start(self.new_menu_button, False, False, 0) self.pack_start(controls.playback, False, False, 0) self.pack_start(controls.os, False, False, 0) self.pack_start(controls.volume, False, False, 0) self.pack_start(Gtk.SeparatorToolItem.new(), False, False, 0) self.pack_start(controls.record, False, False, 0) self.pack_start(controls.seek_bar, True, True, 0) """menu init""" menu = Popup() decorator = MenuStyleDecorator() MenuBarWidget(self.controls, menu) menu.add_separator() menu.add_item(_("Preferences"), "preferences-system", self.controls.show_preferences) menu.add_separator() menu.add_item(_("Quit"), "application-exit", self.controls.quit) decorator.apply(menu) self.menu = menu
def __init__(self, controls): FControl.__init__(self, controls) Gtk.HBox.__init__(self, False, 0) self.old_menu = MenuBarWidget(controls) self.pack_start(self.old_menu.widget, False, False, 0) self.new_menu_button = ImageButton("preferences-system", tooltip_text=_("Settings")) self.new_menu_button.connect("button-press-event", self.on_button_press) self.pack_start(self.new_menu_button, False, False, 0) self.pack_start(controls.playback, False, False, 0) self.pack_start(controls.os, False, False, 0) self.pack_start(controls.volume, False, False, 0) self.pack_start(Gtk.SeparatorToolItem.new(), False, False, 0) self.pack_start(controls.record, False, False, 0) self.pack_start(controls.seek_bar, True, True, 0) """menu init""" menu = Popup() decorator = MenuStyleDecorator() MenuBarWidget(self.controls, menu) menu.add_separator() menu.add_item(_("Preferences"), "preferences-system", self.controls.show_preferences) menu.add_separator() menu.add_item(_("Quit"), "application-exit", self.controls.quit) decorator.apply(menu) self.menu = menu
def __init__(self, controls): FControl.__init__(self, controls) Gtk.HBox.__init__(self, False, 0) self.old_menu = MenuBarWidget(controls) self.pack_start(self.old_menu.widget, False, False, 0) self.new_menu_button = ImageButton(Gtk.STOCK_PREFERENCES) self.new_menu_button.connect("button-press-event", self.on_button_press) self.pack_start(self.new_menu_button, False, False, 0) self.pack_start(controls.playback, False, False, 0) self.pack_start(controls.os, False, False, 0) self.pack_start(controls.volume, False, False, 0) self.pack_start(Gtk.SeparatorToolItem.new(), False, False, 0) self.pack_start(controls.record, False, False, 0) self.pack_start(controls.seek_bar, True, True, 0) """menu init""" menu = Popup() decorator = MenuStyleDecorator() MenuBarWidget(self.controls, menu) menu.add_separator() menu.add_item(_("Preferences"), Gtk.STOCK_PREFERENCES, self.controls.show_preferences) menu.add_separator() menu.add_item(_("Quit"), Gtk.STOCK_QUIT, self.controls.quit) decorator.apply(menu) self.menu = menu
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) menu = Popup() menu.add_item(_("Add playlist"), gtk.STOCK_ADD, self.create_playlist, None) bean = self.get_selected_bean() if bean: if bean.is_file: menu.add_item(_("Rename"), gtk.STOCK_EDIT, self.rename_selected, None) menu.add_item(_("Delete"), gtk.STOCK_DELETE, self.delete_selected, None) else: menu.add_item(_("Rename playlist"), gtk.STOCK_EDIT, self.rename_selected, None) menu.add_item(_("Delete playlist"), gtk.STOCK_DELETE, self.delete_selected, None) #menu.add_item(_("Save as"), gtk.STOCK_SAVE_AS, None, None) #menu.add_item(_("Open as"), gtk.STOCK_OPEN, None, None) menu.show(e)
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() active = self.get_selected_bean() if active: active.type = FTYPE_NOT_UPDATE_INFO_PANEL else: return None if is_left_click(e): if active.get_status(): if active.get_status() == DOWNLOAD_STATUS_ALL: self.controls.dm.filter(None, FTreeModel().status[0]) else: self.controls.dm.filter(active.get_status(), FTreeModel().status[0]) if is_double_left_click(e): self.controls.play(active) if is_rigth_click(e): right_click_optimization_for_trees(w, e) menu = Popup() menu.add_item('Play', gtk.STOCK_MEDIA_PLAY, self.controls.play, active) menu.add_item('Copy to Search Line', gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) menu.show(e)
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() active = self.get_selected_bean() if active: active.type = FTYPE_NOT_UPDATE_INFO_PANEL else: return None if is_left_click(e): if active.get_status(): if active.get_status() == DOWNLOAD_STATUS_ALL: self.controls.dm.filter(None, FTreeModel().status[0]) else: self.controls.dm.filter(active.get_status(), FTreeModel().status[0]) if is_double_left_click(e): self.controls.play(active) if is_rigth_click(e): right_click_optimization_for_trees(w, e) menu = Popup() menu.add_item('Play', Gtk.STOCK_MEDIA_PLAY, self.controls.play, active) menu.add_item('Copy to Search Line', Gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) menu.show(e)
class LastFmIntegrationControls(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("Lasm.fm Integration ") + FCBase().lfm_login, self.ellipsize_render, text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() self.services = {_("My recommendations"): self.controls.lastfm_service.get_recommended_artists, _("My loved tracks"): self.controls.lastfm_service.get_loved_tracks, _("My top tracks"): self.controls.lastfm_service.get_top_tracks, _("My recent tracks"): self.controls.lastfm_service.get_recent_tracks, _("My top artists"): self.controls.lastfm_service.get_top_artists, _("My events"): self.controls.lastfm_service.get_events, _("My friends"): self.controls.lastfm_service.get_friends, _("My neighbours"): self.controls.lastfm_service.get_neighbours } for name in self.services: parent = FModel(name) bean = FDModel(_("loading...")).parent(parent).add_is_file(True) self.append(parent) self.append(bean) def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) active = self.get_selected_bean() self.tree_menu.clear() self.tree_menu.add_item(_('Play'), "media-playback-start", self.controls.play, active) self.tree_menu.add_item(_('Copy to Search Line'), "edit-copy", self.controls.searchPanel.set_search_text, active.text) self.tree_menu.show(e) def on_bean_expanded(self, parent): logging.debug("expanded %s" % parent) def task(): old_iters = self.get_child_iters_by_parent(self.model, self.get_iter_from_bean(parent)) childs = self.services[parent.text](FCBase().lfm_login, str(int(FC().search_limit))) update_parent_for_beans(childs, parent) self.append_all(childs) GLib.idle_add(self.remove_iters, old_iters) self.controls.in_thread.run_with_spinner(task)
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) active = self.get_selected_bean() menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play, active) menu.add_item(_('Copy to Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) menu.show(e)
def on_button_press(self, w, e): logging.debug("on dm button release") if is_rigth_click(e): menu = Popup() try: if self.get_selected_bean(): menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) else: menu.add_item(_("Open in file manager"), None, open_in_filemanager, FC().online_save_to_folder) except Exception, e: logging.error(e) menu.show(e)
def on_button_press(self, w, e): logging.debug("on dm button press") if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) try: menu = Popup() if self.get_selected_bean(): menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) else: menu.add_item(_("Open in file manager"), None, open_in_filemanager, FC().online_save_to_folder) menu.show(e) except Exception, e: logging.error(e)
def on_button_press(self, w, e): active = self.get_selected_bean() if active and is_rigth_click(e): menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play, active) menu.add_item(_('Copy to Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) menu.show(e) if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) "run radio channel" self.controls.play_first_file_in_playlist()
def on_button_press(self, w, e): self.controls.notetabs.set_active_tree(self) if is_double_left_click(e): self.controls.play_selected_song() if is_rigth_click(e): menu = Popup() menu.add_item(_("Play"), gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) menu.add_item(_("Download"), gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) # menu.add_item('Save as', gtk.STOCK_SAVE_AS, self.controls.save_beans_to, self.get_all_selected_beans()) menu.add_separator() path = self.get_selected_bean().path menu.add_item(_("Edit tags"), gtk.STOCK_EDIT, edit_tags, path) text = self.get_selected_bean().text menu.add_item(_("Copy to Search Line"), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) menu.show(e)
def __init__(self, controls): FControl.__init__(self, controls) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.old_menu = MenuBarWidget(controls) self.pack_start(self.old_menu.widget, False, False, 0) menu_icon = "open-menu" if not icon_exists("open-menu"): menu_icon = "open-menu-symbolic" if not icon_exists("open-menu-symbolic"): menu_icon = "application-menu" self.new_menu_button = ImageButton(menu_icon, tooltip_text=_("Menu")) self.new_menu_button.connect("button-press-event", self.on_button_press) self.pack_start(self.new_menu_button, False, False, 0) self.pack_start(controls.playback, False, False, 0) self.pack_start(controls.os, False, False, 0) self.pack_start(controls.volume, False, False, 0) self.pack_start(Gtk.SeparatorToolItem.new(), False, False, 0) self.pack_start(controls.record, False, False, 0) self.pack_start(controls.seek_bar, True, True, 0) """menu init""" menu = Popup() decorator = MenuStyleDecorator() MenuBarWidget(self.controls, menu) menu.add_separator() pref_icon = "gtk-preferences" if icon_exists("gtk-preferences") else "preferences-system" menu.add_item(_("Preferences"), pref_icon, self.controls.show_preferences) menu.add_separator() menu.add_item(_("Quit"), "application-exit", self.controls.quit) decorator.apply(menu) self.menu = menu
def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.append_to_new_notebook(selected.text, [selected] + beans) "run radio channel" self.controls.play_first_file_in_playlist() if is_rigth_click(e): menu = Popup() menu.add_item(_("Add Station"), gtk.STOCK_ADD, self.on_add_station, None) menu.add_item(_("Delete Station"), gtk.STOCK_DELETE, self.on_delete_station, None) menu.add_item(_("Edit Radio"), gtk.STOCK_EDIT, self.on_edit_radio, None) menu.add_separator() menu.add_item(_("Reload radio folder"), gtk.STOCK_REFRESH, self.update_radio_tree, None) menu.show(e)
def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) "run radio channel" self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) menu = Popup() bean = self.get_selected_bean() if bean: if self.get_selected_bean().is_file: menu.add_item(_("Edit Station"), gtk.STOCK_EDIT, self.on_edit_radio, None) menu.add_item(_("Delete Station"), gtk.STOCK_DELETE, self.delete_selected, None) else: menu.add_item(_("Rename Group"), gtk.STOCK_EDIT, self.on_rename_group, None) menu.add_item(_("Delete Group"), gtk.STOCK_DELETE, self.delete_selected, None) menu.add_separator() menu.add_item(_("Reload radio folder"), gtk.STOCK_REFRESH, self.update_radio_tree, None) menu.show(e)
def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) "run radio channel" self.controls.play_first_file_in_playlist() if is_rigth_click(e): menu = Popup() menu.add_item(_("Add Station"), gtk.STOCK_ADD, self.on_add_station, None) menu.add_item(_("Delete Station"), gtk.STOCK_DELETE, self.on_delete_station, None) menu.add_item(_("Edit Radio"), gtk.STOCK_EDIT, self.on_edit_radio, None) menu.add_separator() menu.add_item(_("Reload radio folder"), gtk.STOCK_REFRESH, self.update_radio_tree, None) menu.show(e)
def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.append_to_new_notebook(selected.text, [selected] + beans) if is_rigth_click(e): menu = Popup() menu.add_item(_("Add playlist"), gtk.STOCK_ADD, self.create_playlist, None) menu.add_item(_("Rename playlist"), gtk.STOCK_EDIT, self.rename_playlist, None) menu.add_item(_("Delete playlist"), gtk.STOCK_DELETE, self.delete_playlist, None) #menu.add_item(_("Save as"), gtk.STOCK_SAVE_AS, None, None) #menu.add_item(_("Open as"), gtk.STOCK_OPEN, None, None) menu.show(e)
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_middle_click(e): """to avoid unselect all selected items""" self.stop_emission('button-press-event') if is_left_click(e): # on left click expand selected folders return if is_double_left_click(e): # on middle click play selected beans self.add_to_tab() return if is_rigth_click(e): right_click_optimization_for_trees(w, e) # on right click, show pop-up menu menu = Popup() menu.add_item(_("Append to playlist"), gtk.STOCK_ADD, lambda: self.add_to_tab(True), None) menu.add_item(_("Open in new playlist"), gtk.STOCK_MEDIA_PLAY, self.add_to_tab, None) menu.add_separator() menu.add_item(_("Add folder here"), gtk.STOCK_OPEN, self.add_folder, None) menu.add_separator() if FC().tabs_mode == "Multi": menu.add_item(_("Add folder in new tab"), gtk.STOCK_OPEN, lambda : self.add_folder(True), None) menu.add_item(_("Clear"), gtk.STOCK_CLEAR, lambda : self.controls.tabhelper.clear_tree(self.scroll), None) menu.add_item(_("Update"), gtk.STOCK_REFRESH, lambda: self.controls.tabhelper.on_update_music_tree(self.scroll), None) f_model, f_t_paths = self.get_selection().get_selected_rows() if f_t_paths: model = f_model.get_model() t_paths = [f_model.convert_child_path_to_path(f_t_path) for f_t_path in f_t_paths] row = model[t_paths[0]] paths = [model[t_path][self.path[0]] for t_path in t_paths] row_refs = [gtk.TreeRowReference(model, t_path) for t_path in t_paths] menu.add_separator() menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) menu.add_item(_("Create folder"), None, self.create_folder, (model, f_t_paths[0], row)) menu.add_item(_("Rename file (folder)"), None, self.rename_files, (row, self.path[0], self.text[0])) menu.add_item(_("Delete file(s) / folder(s)"), None, self.delete_files, (row_refs, paths, self.get_iter_from_row_reference)) menu.show(e)
class DownloadManagerTreeControl(CommonTreeControl): def __init__(self, navigation): self.navigation = navigation CommonTreeControl.__init__(self, None) self.set_reorderable(False) self.set_headers_visible(True) self.tree_menu = Popup() """column config""" column = Gtk.TreeViewColumn(_("Name"), self.ellipsize_render, text=self.text[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn(_("Progress"), Gtk.CellRendererProgress(), text=self.persent[0], value=self.persent[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn(_("Size"), self.ellipsize_render, text=self.size[0]) column.set_resizable(True) self.append_column(column) """status""" column = Gtk.TreeViewColumn(_("Status"), self.ellipsize_render, text=self.status[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn(_("Path"), self.ellipsize_render, text=self.save_to[0]) column.set_resizable(True) column.set_expand(True) self.append_column(column) self.set_type_plain() @idle_task def delete_all(self): self.clear() @idle_task def delete_all_selected(self): self.delete_selected() @idle_task def update_status_for_selected(self, status): beans = self.get_all_selected_beans() for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) @idle_task def update_status_for_all(self, status): beans = self.get_all_beans() for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) @idle_task def update_status_for_beans(self, beans, status): for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) def get_next_bean_to_dowload(self): all = self.get_all_beans() if not all: return None for bean in all: if bean.get_status() == DOWNLOAD_STATUS_ACTIVE: self.set_bean_column_value(bean, FTreeModel().status[0], DOWNLOAD_STATUS_LOCK) return bean @idle_task def update_bean_info(self, bean): self.update_bean(bean) self.navigation.update_statistics() #self.navigation.use_filter() def on_button_press(self, w, e): logging.debug("on dm button press") if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) try: self.tree_menu.clear() if self.get_selected_bean(): self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) else: self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, FC().online_save_to_folder) self.tree_menu.show(e) except Exception, e: logging.error(e)
class PlaylistTreeControl(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.header_pressed = False self.menu = Popup() self.tree_menu = Popup() self.full_name = "" self.label = Gtk.Label() self.set_headers_visible(True) self.set_headers_clickable(True) self.set_reorderable(True) """Column icon""" self.icon_col = Gtk.TreeViewColumn(None, Gtk.CellRendererPixbuf(), icon_name=self.play_icon[0]) self.icon_col.key = "*" self.icon_col.label = Gtk.Label("*") self._append_column(self.icon_col) """track number""" self.trkn_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.tracknumber[0]) self.trkn_col.key = "N" #self.trkn_col.set_clickable(True) self.trkn_col.label = Gtk.Label("№") self.trkn_col.item = Gtk.CheckMenuItem(_("Number")) self._append_column(self.trkn_col) """column composer""" self.comp_col = Gtk.TreeViewColumn(None, self.ellipsize_render, text=self.composer[0]) self.comp_col.key = "Composer" self.comp_col.label = Gtk.Label(_("Composer")) self.comp_col.item = Gtk.CheckMenuItem(_("Composer")) self._append_column(self.comp_col) """column artist title""" self.description_col = Gtk.TreeViewColumn(None, self.ellipsize_render, text=self.text[0], font=self.font[0]) self.description_col.key = "Track" self.description_col.label = Gtk.Label(_("Track")) self.description_col.item = Gtk.CheckMenuItem(_("Track")) self._append_column(self.description_col) """column artist""" self.artist_col = Gtk.TreeViewColumn(None, self.ellipsize_render, text=self.artist[0]) self.artist_col.key = "Artist" self.artist_col.label = Gtk.Label(_("Artist")) self.artist_col.item = Gtk.CheckMenuItem(_("Artist")) self._append_column(self.artist_col) """column title""" self.title_col = Gtk.TreeViewColumn(None, self.ellipsize_render, text=self.title[0]) self.title_col.key = "Title" self.title_col.label = Gtk.Label(_("Title")) self.title_col.item = Gtk.CheckMenuItem(_("Title")) self._append_column(self.title_col) """column year""" self.year_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.year[0]) self.year_col.key = "Year" self.year_col.set_sizing(Gtk.TREE_VIEW_COLUMN_AUTOSIZE) self.year_col.set_resizable(True) self.year_col.label = Gtk.Label(_("Year")) self.year_col.item = Gtk.CheckMenuItem(_("Year")) self._append_column(self.year_col) """column album""" self.album_col = Gtk.TreeViewColumn(None, self.ellipsize_render, text=self.album[0]) self.album_col.key = "Album" if self.album_col.key not in FC().columns: FC().columns[self.album_col.key] = [False, 7, 90] self.album_col.label = Gtk.Label(_("Album")) self.album_col.item = Gtk.CheckMenuItem(_("Album")) self._append_column(self.album_col) """column time""" self.time_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.time[0]) self.time_col.key = "Time" self.time_col.label = Gtk.Label(_("Time")) self.time_col.item = Gtk.CheckMenuItem(_("Time")) self._append_column(self.time_col) self.configure_send_drag() self.configure_recive_drag() self.set_playlist_plain() self.connect("button-release-event", self.on_button_press) self.on_load() self.connect("columns-changed", self.on_columns_changed) def set_playlist_tree(self): self.rebuild_as_tree() def set_playlist_plain(self): self.rebuild_as_plain() def on_key_release(self, w, e): if is_modificator(e): return elif is_key(e, KEY_RETURN): self.controls.play_selected_song() elif is_key(e, KEY_DELETE): self.delete_selected() elif is_key(e, 'Left'): self.controls.seek_down() elif is_key(e, 'Right'): self.controls.seek_up() def get_bean_under_pointer_icon(self): for row in self.model: if row[self.play_icon[0]]: bean = self.get_bean_from_row(row) return bean def common_single_random(self): logging.debug("Repeat state " + str(FC().repeat_state)) if FC().repeat_state == const.REPEAT_SINGLE: return self.get_current_bean_by_UUID() if FC().is_order_random: bean = self.get_random_bean() self.set_play_icon_to_bean(bean) return bean def next(self): bean = self.common_single_random() if bean: self.scroll_follow_play_icon() return bean bean = self.get_next_bean(FC().repeat_state == const.REPEAT_ALL) if not bean: self.controls.state_stop() return self.set_play_icon_to_bean(bean) self.scroll_follow_play_icon() logging.debug("Next bean " + str(bean) + bean.text) return bean def prev(self): if FC().repeat_state == const.REPEAT_SINGLE: return self.get_current_bean_by_UUID() bean = self.get_prev_bean(FC().repeat_state == const.REPEAT_ALL) if not bean: self.controls.state_stop() return self.set_play_icon_to_bean(bean) self.scroll_follow_play_icon() return bean @idle_task def scroll_follow_play_icon(self): paths = [(i,) for i, row in enumerate(self.model)] for row, path in zip(self.model, paths): if row[self.play_icon[0]]: start_path, end_path = self.get_visible_range() path = row.path if path >= end_path or path <= start_path: self.scroll_to_cell(path) def append(self, paths): for i, path in enumerate(paths): if os.path.isdir(path): listdir = filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x), [os.path.join(path, f) for f in os.listdir(path)]) for k, p in enumerate(listdir): paths.insert(i + k + 1, p) rows = self.file_paths_to_rows(paths) if not rows: return #rows = self.playlist_filter(rows) for row in rows: self.model.append(None, row) thread.start_new_thread(self.safe_fill_treerows, ()) def is_empty(self): return True if not self.model.get_iter_first() else False def on_button_press(self, w, e): if self.header_pressed: self.header_pressed = False return if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): self.controls.play_selected_song() if is_rigth_click(e): right_click_optimization_for_trees(w, e) beans = self.get_selected_beans() if beans: self.tree_menu.clear() self.tree_menu.add_item(_('Play'), "media-playback-start", self.controls.play_selected_song, None) self.tree_menu.add_item(_('Delete from playlist'), "edit-delete", self.delete_selected, None) paths = [] inet_paths = [] local_paths = [] for bean in beans: if bean.path in paths: continue paths.append(bean.path) if not bean.path or bean.path.startswith("http://"): inet_paths.append(bean.path) else: local_paths.append(bean.path) if local_paths: self.tree_menu.add_item(_('Copy To...'), "list-add", copy_to, local_paths) self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, local_paths[0]) if inet_paths: self.tree_menu.add_item(_('Download'), "list-add", self.controls.dm.append_tasks, self.get_all_selected_beans()) self.tree_menu.add_item(_('Download To...'), "list-add", self.controls.dm.append_tasks_with_dialog, self.get_all_selected_beans()) self.tree_menu.add_separator() if local_paths: self.tree_menu.add_item(_('Edit Tags'), "accessories-text-editor", edit_tags, (self.controls, local_paths)) self.tree_menu.add_item(_('Format Converter'), "applications-utilities", convert_files, local_paths) text = self.get_selected_bean().text self.tree_menu.add_item(_('Copy To Search Line'), "edit-copy", self.controls.searchPanel.set_search_text, text) self.tree_menu.add_separator() self.tree_menu.add_item(_('Copy №-Title-Time'), "edit-copy", self.copy_info_to_clipboard) self.tree_menu.add_item(_('Copy Artist-Title-Album'), "edit-copy", self.copy_info_to_clipboard, True) self.tree_menu.add_separator() self.tree_menu.add_item(_('Love This Track(s) by Last.fm'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) self.tree_menu.add_item(_('Add to My Audio (VK)'), None, self.controls.add_to_my_playlist, self.get_all_selected_beans()) self.tree_menu.add_item(_('Copy link'), None, self.controls.copy_link, self.get_all_selected_beans()) self.tree_menu.show(e) def on_click_header(self, w, e): self.header_pressed = True if is_rigth_click(e): if "menu" in w.__dict__: w.menu.show(e) else: self.menu.show(e) def on_toggled_num(self, *a): FC().numbering_by_order = not FC().numbering_by_order number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for page in xrange(number_music_tabs, -1, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() if FC().numbering_by_order: pl_tree.update_tracknumber() pl_tree.num_order.set_active(True) continue pl_tree.num_tags.set_active(True) for row in pl_tree.model: if row[pl_tree.is_file[0]]: audio = get_mutagen_audio(row[pl_tree.path[0]]) if audio and audio.has_key('tracknumber'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio['tracknumber'][0]).group() if audio and audio.has_key('trkn'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio["trkn"][0]).group() def on_toggle(self, w, e, column): FC().columns[column.key][0] = not FC().columns[column.key][0] number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for key in self.__dict__.keys(): if self.__dict__[key] is column: atr_name = key break for page in xrange(number_music_tabs, -1, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() ## TODO: check "local variable 'atr_name' might be referenced before assignment" pl_tree_column = pl_tree.__dict__[atr_name] if FC().columns[column.key][0]: pl_tree.move_column_after(pl_tree_column, pl_tree.icon_col) pl_tree_column.set_visible(True) if self is not pl_tree: pl_tree_column.item.set_active(True) else: pl_tree_column.set_visible(False) if self is not pl_tree: pl_tree_column.item.set_active(False) def _append_column(self, column): column.set_widget(column.label) column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) column.set_min_width(20) column.set_resizable(True) if column.key is '*': column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) column.set_fixed_width(32) column.set_min_width(32) if FC().columns[column.key][2] > 0: column.set_fixed_width(FC().columns[column.key][2]) self.append_column(column) column.button = column.label.get_parent().get_parent().get_parent() column.button.connect("button-press-event", self.on_click_header) ''' if column.key == 'N': self.trkn_col.button.menu = Popup() group = [] self.num_order = Gtk.RadioMenuItem.new_with_label(group, _("Numbering by order")) self.num_order.connect("button-press-event", self.on_toggled_num) group.append(self.num_order) self.num_tags = Gtk.RadioMenuItem.new_with_label(group, _("Numbering by tags")) self.num_tags.connect("button-press-event", self.on_toggled_num) group.append(self.num_tags) self.trkn_col.button.menu.append(self.num_order) self.trkn_col.button.menu.append(self.num_tags) if FC().numbering_by_order: self.num_order.set_active(True) else: self.num_tags.set_active(True) ''' def on_columns_changed(self, *a): global FLAG if FLAG: return FLAG = True number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for i, column in enumerate(self.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() for page in xrange(number_music_tabs, 0, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() col_list = pl_tree.get_columns() col_list.sort(self.to_order_columns, reverse=True) for column in col_list: pl_tree.move_column_after(column, None) FLAG = False def to_order_columns(self, x, y): return cmp(FC().columns[x.key][1], FC().columns[y.key][1]) def on_load(self): col_list = self.get_columns() col_list.sort(self.to_order_columns, reverse=True) visible_columns = [] for column in col_list: column.label.show() column.set_widget(column.label) column.set_clickable(True) if column.key != "*": column.set_reorderable(True) if FC().columns[column.key][0]: self.move_column_after(column, None) if "item" in column.__dict__: column.item.connect("button-press-event", self.on_toggle, column) self.menu.append(column.item) column.item.set_active(True) visible_columns.append(column) else: if "item" in column.__dict__: column.item.connect("button-press-event", self.on_toggle, column) self.menu.append(column.item) column.item.set_active(False) column.set_visible(False) '''if FC().columns["Track"][2] < 0: self.description_col.set_fixed_width(self.get_allocation().width - (FC().columns["Time"][2]+70))''' def change_rows_by_path(self, file_paths): for treerow in self.model: if treerow[self.is_file[0]] and treerow[self.path[0]] in file_paths: bean = self.get_bean_from_row(treerow) bean = update_id3(bean) row_ref = Gtk.TreeRowReference.new(self.model, treerow.path) self.fill_row(row_ref, bean) GLib.idle_add(self.controls.notetabs.save_current_tab, priority=GLib.PRIORITY_LOW) def file_paths_to_rows(self, paths): result = [] for path in paths: bean = get_bean_from_file(path) beans = update_id3_for_m3u([bean]) beans = update_id3_for_pls(beans) if beans and (len(beans) > 1 or is_playlist(bean.path)): bean = bean.add_text(_('Playlist: ') + bean.text).add_font("bold").add_is_file(False) bean.path = '' beans.insert(0, bean) for bean in beans: result.append(self.get_row_from_bean(bean)) return result def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp): logging.debug('Playlist on_drag_data_received') model = self.get_model().get_model() drop_info = self.get_dest_row_at_pos(x, y) if drop_info: path, position = drop_info iter = model.get_iter(path) files = sorted([file for file in get_files_from_gtk_selection_data(selection) if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats], key=lambda x: x[self.text[0]]) if files: '''dnd from the outside of the player''' if self.is_empty(): if len(files) == 1 and os.path.isdir(files[0]): tabname = os.path.basename(files[0]) else: tabname = os.path.split(os.path.dirname(files[0]))[1] self.controls.notetabs.rename_tab(self.scroll, tabname) for i, file in enumerate(files): if os.path.isdir(file): sorted_dirs = [] sorted_files = [] for f in sorted(os.listdir(file), key=lambda x: x): f = os.path.join(file, f) if os.path.isdir(f): sorted_dirs.append(f) elif get_file_extension(f) in FC().all_support_formats: sorted_files.append(f) listdir = sorted_dirs + sorted_files ''' listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x), [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x) ''' for k, path in enumerate(listdir): files.insert(i + k + 1, path) rows = self.file_paths_to_rows(files) if not rows: return rows = self.playlist_filter(rows) for row in rows: if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.insert_before(None, iter, row) else: model.insert_after(None, iter, row) iter = model.iter_next(iter) else: model.append(None, row) else: '''dnd inside the player''' # ff - from_filter ff_tree = Gtk.drag_get_source_widget(context) ff_model, ff_paths = ff_tree.get_selection().get_selected_rows() treerows = [ff_model[ff_path] for ff_path in ff_paths] if self is ff_tree: '''internal dnd''' ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths] for ff_row_ref in ff_row_refs: ff_iter = self.get_iter_from_row_reference(ff_row_ref) f_iter = ff_model.convert_iter_to_child_iter(ff_iter) if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.move_before(f_iter, iter) else: model.move_after(f_iter, iter) iter = model.iter_next(iter) else: model.move_before(f_iter, None) return else: '''dnd from other tree''' if self.is_empty(): path = treerows[0][self.path[0]] if path: if len(treerows) == 1 and os.path.isdir(path): tabname = os.path.basename(path) else: tabname = os.path.split(os.path.dirname(path))[1] self.controls.notetabs.rename_tab(self.scroll, tabname) else: pass for i, treerow in enumerate(treerows): for k, ch_row in enumerate(treerow.iterchildren()): treerows.insert(i + k + 1, ch_row) #treerows = self.playlist_filter(treerows) for i, treerow in enumerate(treerows): if is_playlist(treerow[self.path[0]]): rows = self.file_paths_to_rows([treerow[self.path[0]]]) if rows: rows.reverse() map(lambda row: treerows.insert(i + 1, row), rows) continue row = [col for col in treerow] if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.insert_before(None, iter, row) else: model.insert_after(None, iter, row) iter = model.iter_next(iter) else: model.append(None, row) thread.start_new_thread(self.safe_fill_treerows, ()) context.finish(True, False, timestamp) self.stop_emission('drag-data-received') return True
def on_button_press(self, w, e): if is_middle_click(e): self.add_to_tab(True) return if is_left_click(e): # on left click expand selected folders return if is_double_left_click(e): # on middle click play selected beans self.add_to_tab() return if is_rigth_click(e): # on right click, show pop-up menu menu = Popup() menu.add_item(_("Add to current tab"), gtk.STOCK_ADD, lambda: self.add_to_tab(True), None) menu.add_item(_("Add to new tab"), gtk.STOCK_MEDIA_PLAY, self.add_to_tab, None) menu.add_separator() menu.add_item(_("Add folder"), gtk.STOCK_OPEN, self.add_folder, None) menu.add_separator() if FC().tabs_mode == "Multi": menu.add_item(_("Add folder in new tab"), gtk.STOCK_OPEN, lambda : self.add_folder(True), None) menu.add_item(_("Clear Music Tree"), gtk.STOCK_CLEAR, lambda : self.controls.tabhelper.clear_tree(self.scroll), None) menu.add_item(_("Update Music Tree"), gtk.STOCK_REFRESH, lambda: self.controls.tabhelper.on_update_music_tree(self.scroll), None) menu.show(e)
def on_button_press(self, w, e): self.controls.notetabs.set_active_tree(self) if is_double_left_click(e): self.controls.play_selected_song() if is_rigth_click(e): menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) menu.add_item(_('Download'), gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) #menu.add_item('Save as', gtk.STOCK_SAVE_AS, self.controls.save_beans_to, self.get_all_selected_beans()) menu.add_separator() paths = [bean.path for bean in self.get_selected_beans()] menu.add_item(_('Edit tags'), gtk.STOCK_EDIT, edit_tags, paths) text = self.get_selected_bean().text menu.add_item(_('Copy to Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) menu.add_separator() menu.add_item(_('Copy №-Title-Time'), gtk.STOCK_COPY, self.copy_info_to_clipboard) menu.add_item(_('Copy Artist-Title-Album'), gtk.STOCK_COPY, self.copy_info_to_clipboard, True) menu.add_separator() menu.add_item(_('Love this track(s)'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) menu.show(e)
def on_mouse_click(self, w, event): menu = Popup() menu.add_item(_("Play"), gtk.STOCK_MEDIA_PLAY, self.set_action_text, "--play") menu.add_item(_("Pause"), gtk.STOCK_MEDIA_PAUSE, self.set_action_text, "--pause") menu.add_item(_("Stop"), gtk.STOCK_MEDIA_STOP, self.set_action_text, "--stop") menu.add_item(_("Next song"), gtk.STOCK_MEDIA_NEXT, self.set_action_text, "--next") menu.add_item(_("Previous song"), gtk.STOCK_MEDIA_PREVIOUS, self.set_action_text, "--prev") menu.add_item(_("Volume up"), gtk.STOCK_GO_UP, self.set_action_text, "--volume-up") menu.add_item(_("Volume down"), gtk.STOCK_GO_DOWN, self.set_action_text, "--volume-down") menu.add_item(_("Show-Hide"), gtk.STOCK_FULLSCREEN, self.set_action_text, "--show-hide") menu.add_item(_("Play-Pause"), gtk.STOCK_MEDIA_RECORD, self.set_action_text, "--play-pause") menu.show(event)
class LastFmIntegrationControls(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("Lasm.fm Integration ") + FCBase().lfm_login, Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() self.services = { _("My recommendations"): self.controls.lastfm_service.get_recommended_artists, _("My loved tracks"): self.controls.lastfm_service.get_loved_tracks, _("My top tracks"): self.controls.lastfm_service.get_top_tracks, _("My recent tracks"): self.controls.lastfm_service.get_recent_tracks, _("My top artists"): self.controls.lastfm_service.get_top_artists, #_("My friends"):self.controls.lastfm_service.get_friends, # #_("My neighbours"):self.controls.lastfm_service.get_neighbours } for name in self.services: parent = FModel(name) bean = FDModel(_("loading...")).parent(parent).add_is_file(True) self.append(parent) self.append(bean) def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) active = self.get_selected_bean() self.tree_menu.clear() self.tree_menu.add_item(_('Play'), Gtk.STOCK_MEDIA_PLAY, self.controls.play, active) self.tree_menu.add_item(_('Copy to Search Line'), Gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, active.text) self.tree_menu.show(e) def on_bean_expanded(self, parent): logging.debug("expanded %s" % parent) def task(): old_iters = self.get_child_iters_by_parent( self.model, self.get_iter_from_bean(parent)) childs = self.services[parent.text](FCBase().lfm_login, str(int(FC().search_limit))) update_parent_for_beans(childs, parent) self.append_all(childs) GLib.idle_add(self.remove_iters, old_iters) self.controls.in_thread.run_with_spinner(task)
class VirtualTreeControl(CommonTreeControl, LoadSave): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("Storage"), Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() def on_key_release(self, w, e): if is_key(e, KEY_DELETE): self.delete_selected() def on_drag_drop_finish(self): FCache().cache_virtual_tree_beans = self.get_all_beans() FC().save() def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) self.tree_menu.clear() self.tree_menu.add_item(_("Add playlist"), Gtk.STOCK_ADD, self.create_playlist, None) bean = self.get_selected_bean() if bean: if bean.is_file: self.tree_menu.add_item(_("Rename"), Gtk.STOCK_EDIT, self.rename_selected, None) self.tree_menu.add_item(_("Delete"), Gtk.STOCK_DELETE, self.delete_selected, None) else: self.tree_menu.add_item(_("Rename playlist"), Gtk.STOCK_EDIT, self.rename_selected, None) self.tree_menu.add_item(_("Delete playlist"), Gtk.STOCK_DELETE, self.delete_selected, None) #menu.add_item(_("Save as"), Gtk.STOCK_SAVE_AS, None, None) #menu.add_item(_("Open as"), Gtk.STOCK_OPEN, None, None) self.tree_menu.show(e) def create_playlist(self): name = one_line_dialog(_("Create new playlist"), self.controls.main_window, message_text1=_("Enter playlist name")) if not name: return bean = self.get_selected_bean() folder_bean = FModel(name) if bean: if bean.is_file: folder_bean.add_parent(bean.parent_level) else: folder_bean.add_parent(bean.level) self.append(folder_bean) def rename_selected(self): bean = self.get_selected_bean() name = one_line_dialog(_("Rename Dialog"), self.controls.main_window, entry_text=bean.text, message_text1=_("Enter new name")) if not name: return rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name def on_load(self): self.scroll.hide() self.restore_rows(FCache().cache_virtual_tree_beans) self.restore_expand(FC().virtual_expand_paths) self.restore_selection(FC().virtual_selected_paths) def set_expand_path(new_value): FC().virtual_expand_paths = new_value def set_selected_path(new_value): FC().virtual_selected_paths = new_value self.expand_updated(set_expand_path) self.selection_changed(set_selected_path) def on_quit(self): self.save_rows_from_tree(FCache().cache_virtual_tree_beans) def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp): logging.debug('Storage on_drag_data_received') model = self.get_model().get_model() drop_info = self.get_dest_row_at_pos(x, y) # ff - from_filter ff_tree = Gtk.drag_get_source_widget(context) ff_model, ff_paths = ff_tree.get_selection().get_selected_rows() treerows = [ff_model[ff_path] for ff_path in ff_paths] if drop_info: path, position = drop_info iter = model.get_iter(path) if position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER: self.model[path][self.font[0]] = 'bold' if self == ff_tree: ff_row_refs = [ Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths ] def add_childs(treerow, new_iter): for ch_row in treerow.iterchildren(): niter = model.append(new_iter, [col for col in ch_row]) add_childs(ch_row, niter) for treerow, ref in zip(treerows, ff_row_refs): row = [col for col in treerow] if drop_info: if position == Gtk.TREE_VIEW_DROP_BEFORE: new_iter = model.insert_before(None, iter, row) elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER): new_iter = model.append(iter, row) else: new_iter = model.insert_after(None, iter, row) iter = model.iter_next(iter) else: new_iter = model.append(None, row) treerow = model[ref.get_path()] # reinitialize add_childs(treerow, new_iter) self.remove_replaced(ff_model, ff_row_refs) else: for treerow in treerows: row = [col for col in treerow] if drop_info: if position == Gtk.TREE_VIEW_DROP_BEFORE: new_iter = model.insert_before(None, iter, row) elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER): new_iter = model.append(iter, row) else: new_iter = model.insert_after(None, iter, row) iter = model.iter_next(iter) else: new_iter = model.append(None, row) if len(treerows) == 1 and treerow[self.font[0]] == 'bold': while treerow.next and treerow.next[ self.font[0]] != 'bold': treerow = treerow.next treerows.append(treerow) drop_info = True iter = new_iter position = Gtk.TREE_VIEW_DROP_INTO_OR_AFTER self.stop_emission('drag-data-received')
def on_button_press(self, w, e): if is_rigth_click(e): menu = Popup() menu.add_item('Restore Defaults', "view-refresh", None) menu.show(e)
def on_button_release(self, w, e): if is_rigth_click_release(e): """to select item under cursor""" try: path, col, cellx, celly = self.get_path_at_pos( int(e.x), int(e.y)) #@UnusedVariable self.get_selection().select_path(path) except TypeError: pass #menu.add_item('Save as', gtk.STOCK_SAVE_AS, self.controls.save_beans_to, self.get_all_selected_beans()) beans = self.get_selected_beans() if beans: menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) menu.add_item(_('Download'), gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) menu.add_item(_('Download To...'), gtk.STOCK_ADD, self.controls.dm.append_tasks_with_dialog, self.get_all_selected_beans()) menu.add_separator() paths = [bean.path for bean in beans] if paths[0]: menu.add_item(_('Edit Tags'), gtk.STOCK_EDIT, edit_tags, (self.controls, paths)) menu.add_item(_('Format Converter'), gtk.STOCK_CONVERT, convert_files, paths) text = self.get_selected_bean().text menu.add_item(_('Copy To Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) menu.add_separator() menu.add_item(_('Copy №-Title-Time'), gtk.STOCK_COPY, self.copy_info_to_clipboard) menu.add_item(_('Copy Artist-Title-Album'), gtk.STOCK_COPY, self.copy_info_to_clipboard, True) menu.add_separator() menu.add_item(_('Love This Track(s)'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) menu.add_separator() if paths[0]: menu.add_item(_("Open In File Manager"), None, open_in_filemanager, paths[0]) menu.show(e)
def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): self.controls.play_selected_song() if is_rigth_click(e): right_click_optimization_for_trees(w, e) beans = self.get_selected_beans() if beans: menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) menu.add_item(_('Delete from playlist'), gtk.STOCK_DELETE, self.delete_selected, None) paths = [] inet_paths = [] local_paths = [] for bean in beans: if bean.path in paths: continue paths.append(bean.path) if not bean.path or bean.path.startswith("http://"): inet_paths.append(bean.path) else: local_paths.append(bean.path) if local_paths: menu.add_item(_('Copy To...'), gtk.STOCK_ADD, copy_to, local_paths) menu.add_item(_("Open in file manager"), None, open_in_filemanager, local_paths[0]) if inet_paths: menu.add_item(_('Download'), gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) menu.add_item(_('Download To...'), gtk.STOCK_ADD, self.controls.dm.append_tasks_with_dialog, self.get_all_selected_beans()) menu.add_separator() if paths[0]: menu.add_item(_('Edit Tags'), gtk.STOCK_EDIT, edit_tags, (self.controls, paths)) menu.add_item(_('Format Converter'), gtk.STOCK_CONVERT, convert_files, paths) text = self.get_selected_bean().text menu.add_item(_('Copy To Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) menu.add_separator() menu.add_item(_('Copy №-Title-Time'), gtk.STOCK_COPY, self.copy_info_to_clipboard) menu.add_item(_('Copy Artist-Title-Album'), gtk.STOCK_COPY, self.copy_info_to_clipboard, True) menu.add_separator() menu.add_item(_('Love This Track(s) by Last.fm'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) menu.add_separator() if paths[0]: menu.add_item(_("Open In File Manager"), None, open_in_filemanager, paths[0]) menu.show(e)
def create_menu(self): menu = Popup() menu.add_item(_("Play-Pause"), Gtk.STOCK_MEDIA_PAUSE, self.set_action_text, "play_pause") menu.add_item(_("Stop"), Gtk.STOCK_MEDIA_STOP, self.set_action_text, "state_stop") menu.add_item(_("Next song"), Gtk.STOCK_MEDIA_NEXT, self.set_action_text, "next") menu.add_item(_("Previous song"), Gtk.STOCK_MEDIA_PREVIOUS, self.set_action_text, "prev") menu.add_item(_("Volume up"), Gtk.STOCK_GO_UP, self.set_action_text, "volume_up") menu.add_item(_("Volume down"), Gtk.STOCK_GO_DOWN, self.set_action_text, "volume_down") menu.add_item(_("Show-Hide"), Gtk.STOCK_FULLSCREEN, self.set_action_text, "show_hide") menu.add_item(_('Download'), Gtk.STOCK_ADD, self.set_action_text, "download") return menu
class PlaylistTreeControl(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.header_pressed = False self.menu = Popup() self.tree_menu = Popup() self.full_name = "" self.label = Gtk.Label() self.set_headers_visible(True) self.set_headers_clickable(True) self.set_reorderable(True) """Column icon""" self.icon_col = Gtk.TreeViewColumn(None, Gtk.CellRendererPixbuf(), icon_name=self.play_icon[0]) self.icon_col.key = "*" self.icon_col.set_sizing(Gtk.TreeViewColumnSizing.FIXED) self.icon_col.set_fixed_width(32) self.icon_col.set_min_width(32) self.icon_col.label = Gtk.Label("*") self._append_column(self.icon_col) """track number""" self.trkn_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.tracknumber[0]) self.trkn_col.key = "N" self.trkn_col.set_clickable(True) self.trkn_col.label = Gtk.Label("№") self.trkn_col.label.show() self.trkn_col.item = Gtk.CheckMenuItem(_("Number")) self.trkn_col.set_widget(self.trkn_col.label) self._append_column(self.trkn_col) """column composer""" self.comp_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.composer[0]) self.comp_col.key = "Composer" self.comp_col.set_resizable(True) self.comp_col.label = Gtk.Label(_("Composer")) self.comp_col.item = Gtk.CheckMenuItem(_("Composer")) self._append_column(self.comp_col) """column artist title""" self.description_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) self.description_col.key = "Track" self.description_col.set_resizable(True) self.description_col.label = Gtk.Label(_("Track")) self.description_col.item = Gtk.CheckMenuItem(_("Track")) self._append_column(self.description_col) """column artist""" self.artist_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.artist[0]) self.artist_col.key = "Artist" self.artist_col.set_sizing(Gtk.TREE_VIEW_COLUMN_AUTOSIZE) self.artist_col.set_resizable(True) self.artist_col.label = Gtk.Label(_("Artist")) self.artist_col.item = Gtk.CheckMenuItem(_("Artist")) self._append_column(self.artist_col) """column title""" self.title_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.title[0]) self.title_col.key = "Title" self.title_col.set_sizing(Gtk.TREE_VIEW_COLUMN_AUTOSIZE) self.title_col.set_resizable(True) self.title_col.label = Gtk.Label(_("Title")) self.title_col.item = Gtk.CheckMenuItem(_("Title")) self._append_column(self.title_col) """column album""" self.album_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.album[0]) self.album_col.key = "Album" if self.album_col.key not in FC().columns: FC().columns[self.album_col.key] = [False, 7, 90] self.album_col.set_sizing(Gtk.TREE_VIEW_COLUMN_AUTOSIZE) self.album_col.set_resizable(True) self.album_col.label = Gtk.Label(_("Album")) self.album_col.item = Gtk.CheckMenuItem(_("Album")) self._append_column(self.album_col) """column time""" self.time_col = Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=self.time[0]) self.time_col.key = "Time" self.time_col.label = Gtk.Label(_("Time")) self.time_col.item = Gtk.CheckMenuItem(_("Time")) self._append_column(self.time_col) self.configure_send_drag() self.configure_recive_drag() self.set_playlist_plain() self.connect("button-release-event", self.on_button_press) self.on_load() self.connect("columns-changed", self.on_columns_changed) def set_playlist_tree(self): self.rebuild_as_tree() def set_playlist_plain(self): self.rebuild_as_plain() def on_key_release(self, w, e): if is_modificator(e): return elif is_key(e, KEY_RETURN): self.controls.play_selected_song() elif is_key(e, KEY_DELETE): self.delete_selected() elif is_key(e, 'Left'): self.controls.seek_down() elif is_key(e, 'Right'): self.controls.seek_up() def get_bean_under_pointer_icon(self): for row in self.model: if row[self.play_icon[0]]: bean = self.get_bean_from_row(row) return bean def common_single_random(self): logging.debug("Repeat state " + str(FC().repeat_state)) if FC().repeat_state == const.REPEAT_SINGLE: return self.get_current_bean_by_UUID() if FC().is_order_random: bean = self.get_random_bean() self.set_play_icon_to_bean(bean) return bean def next(self): bean = self.common_single_random() if bean: self.scroll_follow_play_icon() return bean bean = self.get_next_bean(FC().repeat_state == const.REPEAT_ALL) if not bean: self.controls.state_stop() return self.set_play_icon_to_bean(bean) self.scroll_follow_play_icon() logging.debug("Next bean " + str(bean) + bean.text) return bean def prev(self): if FC().repeat_state == const.REPEAT_SINGLE: return self.get_current_bean_by_UUID() bean = self.get_prev_bean(FC().repeat_state == const.REPEAT_ALL) if not bean: self.controls.state_stop() return self.set_play_icon_to_bean(bean) self.scroll_follow_play_icon() return bean @idle_task def scroll_follow_play_icon(self): paths = [(i,) for i, row in enumerate(self.model)] for row, path in zip(self.model, paths): if row[self.play_icon[0]]: start_path, end_path = self.get_visible_range() path = row.path if path >= end_path or path <= start_path: self.scroll_to_cell(path) def append(self, paths): for i, path in enumerate(paths): if os.path.isdir(path): listdir = filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x), [os.path.join(path, f) for f in os.listdir(path)]) for k, p in enumerate(listdir): paths.insert(i + k + 1, p) rows = self.file_paths_to_rows(paths) if not rows: return #rows = self.playlist_filter(rows) for row in rows: self.model.append(None, row) thread.start_new_thread(self.safe_fill_treerows, ()) def is_empty(self): return True if not self.model.get_iter_first() else False def on_button_press(self, w, e): if self.header_pressed: self.header_pressed = False return if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): self.controls.play_selected_song() if is_rigth_click(e): right_click_optimization_for_trees(w, e) beans = self.get_selected_beans() if beans: self.tree_menu.clear() self.tree_menu.add_item(_('Play'), Gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) self.tree_menu.add_item(_('Delete from playlist'), Gtk.STOCK_DELETE, self.delete_selected, None) paths = [] inet_paths = [] local_paths = [] for bean in beans: if bean.path in paths: continue paths.append(bean.path) if not bean.path or bean.path.startswith("http://"): inet_paths.append(bean.path) else: local_paths.append(bean.path) if local_paths: self.tree_menu.add_item(_('Copy To...'), Gtk.STOCK_ADD, copy_to, local_paths) self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, local_paths[0]) if inet_paths: self.tree_menu.add_item(_('Download'), Gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) self.tree_menu.add_item(_('Download To...'), Gtk.STOCK_ADD, self.controls.dm.append_tasks_with_dialog, self.get_all_selected_beans()) self.tree_menu.add_separator() if local_paths: self.tree_menu.add_item(_('Edit Tags'), Gtk.STOCK_EDIT, edit_tags, (self.controls, local_paths)) self.tree_menu.add_item(_('Format Converter'), Gtk.STOCK_CONVERT, convert_files, local_paths) text = self.get_selected_bean().text self.tree_menu.add_item(_('Copy To Search Line'), Gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) self.tree_menu.add_separator() self.tree_menu.add_item(_('Copy №-Title-Time'), Gtk.STOCK_COPY, self.copy_info_to_clipboard) self.tree_menu.add_item(_('Copy Artist-Title-Album'), Gtk.STOCK_COPY, self.copy_info_to_clipboard, True) self.tree_menu.add_separator() self.tree_menu.add_item(_('Love This Track(s) by Last.fm'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) self.tree_menu.add_item(_('Add to My Audio (VK)'), None, self.controls.add_to_my_playlist, self.get_all_selected_beans()) self.tree_menu.add_item(_('Copy link'), None, self.controls.copy_link, self.get_all_selected_beans()) self.tree_menu.show(e) def on_click_header(self, w, e): self.header_pressed = True if is_rigth_click(e): if "menu" in w.__dict__: w.menu.show(e) else: self.menu.show(e) def on_toggled_num(self, *a): FC().numbering_by_order = not FC().numbering_by_order number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for page in xrange(number_music_tabs, -1, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() if FC().numbering_by_order: pl_tree.update_tracknumber() pl_tree.num_order.set_active(True) continue pl_tree.num_tags.set_active(True) for row in pl_tree.model: if row[pl_tree.is_file[0]]: audio = get_mutagen_audio(row[pl_tree.path[0]]) if audio and audio.has_key('tracknumber'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio['tracknumber'][0]).group() if audio and audio.has_key('trkn'): row[pl_tree.tracknumber[0]] = re.search('\d*', audio["trkn"][0]).group() def on_toggle(self, w, e, column): FC().columns[column.key][0] = not FC().columns[column.key][0] number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for key in self.__dict__.keys(): if self.__dict__[key] is column: atr_name = key break for page in xrange(number_music_tabs, -1, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() ## TODO: check "local variable 'atr_name' might be referenced before assignment" pl_tree_column = pl_tree.__dict__[atr_name] if FC().columns[column.key][0]: pl_tree.move_column_after(pl_tree_column, pl_tree.icon_col) pl_tree_column.set_visible(True) if self is not pl_tree: pl_tree_column.item.set_active(True) else: pl_tree_column.set_visible(False) if self is not pl_tree: pl_tree_column.item.set_active(False) def _append_column(self, column): column.set_widget(column.label) column.set_sizing(Gtk.TREE_VIEW_COLUMN_FIXED) if column.key in ['*', 'N', 'Time']: column.set_sizing(Gtk.TREE_VIEW_COLUMN_AUTOSIZE) else: column.set_sizing(Gtk.TREE_VIEW_COLUMN_FIXED) if FC().columns[column.key][2] > 0: column.set_fixed_width(FC().columns[column.key][2]) self.append_column(column) column.button = column.label.get_parent().get_parent().get_parent() column.button.connect("button-press-event", self.on_click_header) ''' if column.key == 'N': self.trkn_col.button.menu = Popup() group = [] self.num_order = Gtk.RadioMenuItem.new_with_label(group, _("Numbering by order")) self.num_order.connect("button-press-event", self.on_toggled_num) group.append(self.num_order) self.num_tags = Gtk.RadioMenuItem.new_with_label(group, _("Numbering by tags")) self.num_tags.connect("button-press-event", self.on_toggled_num) group.append(self.num_tags) self.trkn_col.button.menu.append(self.num_order) self.trkn_col.button.menu.append(self.num_tags) if FC().numbering_by_order: self.num_order.set_active(True) else: self.num_tags.set_active(True) ''' def on_columns_changed(self, *a): global FLAG if FLAG: return FLAG = True number_music_tabs = self.controls.notetabs.get_n_pages() - 1 for i, column in enumerate(self.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() for page in xrange(number_music_tabs, 0, -1): tab_content = self.controls.notetabs.get_nth_page(page) pl_tree = tab_content.get_child() col_list = pl_tree.get_columns() col_list.sort(self.to_order_columns, reverse=True) for column in col_list: pl_tree.move_column_after(column, None) FLAG = False def to_order_columns(self, x, y): return cmp(FC().columns[x.key][1], FC().columns[y.key][1]) def on_load(self): col_list = self.get_columns() col_list.sort(self.to_order_columns, reverse=True) visible_columns = [] for column in col_list: column.label.show() column.set_widget(column.label) column.set_clickable(True) if column.key != "*": column.set_reorderable(True) if FC().columns[column.key][0]: self.move_column_after(column, None) if "item" in column.__dict__: column.item.connect("button-press-event", self.on_toggle, column) self.menu.append(column.item) column.item.set_active(True) visible_columns.append(column) else: if "item" in column.__dict__: column.item.connect("button-press-event", self.on_toggle, column) self.menu.append(column.item) column.item.set_active(False) column.set_visible(False) '''if FC().columns["Track"][2] < 0: self.description_col.set_fixed_width(self.get_allocation().width - (FC().columns["Time"][2]+70))''' def change_rows_by_path(self, file_paths): for treerow in self.model: if treerow[self.is_file[0]] and treerow[self.path[0]] in file_paths: bean = self.get_bean_from_row(treerow) bean = update_id3(bean) row_ref = Gtk.TreeRowReference.new(self.model, treerow.path) self.fill_row(row_ref, bean) GLib.idle_add(self.controls.notetabs.save_current_tab, priority=GLib.PRIORITY_LOW) def file_paths_to_rows(self, paths): result = [] for path in paths: bean = get_bean_from_file(path) beans = update_id3_for_m3u([bean]) beans = update_id3_for_pls(beans) if beans and (len(beans) > 1 or is_playlist(bean.path)): bean = bean.add_text(_('Playlist: ') + bean.text).add_font("bold").add_is_file(False) bean.path = '' beans.insert(0, bean) for bean in beans: result.append(self.get_row_from_bean(bean)) return result def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp): logging.debug('Playlist on_drag_data_received') model = self.get_model().get_model() drop_info = self.get_dest_row_at_pos(x, y) if drop_info: path, position = drop_info iter = model.get_iter(path) files = sorted([file for file in get_files_from_gtk_selection_data(selection) if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats], key=lambda x: x[self.text[0]]) if files: '''dnd from the outside of the player''' if self.is_empty(): if len(files) == 1 and os.path.isdir(files[0]): tabname = os.path.basename(files[0]) else: tabname = os.path.split(os.path.dirname(files[0]))[1] self.controls.notetabs.rename_tab(self.scroll, tabname) for i, file in enumerate(files): if os.path.isdir(file): sorted_dirs = [] sorted_files = [] for f in sorted(os.listdir(file), key=lambda x: x): f = os.path.join(file, f) if os.path.isdir(f): sorted_dirs.append(f) elif get_file_extension(f) in FC().all_support_formats: sorted_files.append(f) listdir = sorted_dirs + sorted_files ''' listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x), [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x) ''' for k, path in enumerate(listdir): files.insert(i + k + 1, path) rows = self.file_paths_to_rows(files) if not rows: return rows = self.playlist_filter(rows) for row in rows: if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.insert_before(None, iter, row) else: model.insert_after(None, iter, row) iter = model.iter_next(iter) else: model.append(None, row) else: '''dnd inside the player''' # ff - from_filter ff_tree = Gtk.drag_get_source_widget(context) ff_model, ff_paths = ff_tree.get_selection().get_selected_rows() treerows = [ff_model[ff_path] for ff_path in ff_paths] if self is ff_tree: '''internal dnd''' ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths] for ff_row_ref in ff_row_refs: ff_iter = self.get_iter_from_row_reference(ff_row_ref) f_iter = ff_model.convert_iter_to_child_iter(ff_iter) if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.move_before(f_iter, iter) else: model.move_after(f_iter, iter) iter = model.iter_next(iter) else: model.move_before(f_iter, None) return else: '''dnd from other tree''' if self.is_empty(): path = treerows[0][self.path[0]] if path: if len(treerows) == 1 and os.path.isdir(path): tabname = os.path.basename(path) else: tabname = os.path.split(os.path.dirname(path))[1] self.controls.notetabs.rename_tab(self.scroll, tabname) else: pass for i, treerow in enumerate(treerows): for k, ch_row in enumerate(treerow.iterchildren()): treerows.insert(i + k + 1, ch_row) #treerows = self.playlist_filter(treerows) for i, treerow in enumerate(treerows): if is_playlist(treerow[self.path[0]]): rows = self.file_paths_to_rows([treerow[self.path[0]]]) if rows: rows.reverse() map(lambda row: treerows.insert(i + 1, row), rows) continue row = [col for col in treerow] if drop_info: if (position == Gtk.TREE_VIEW_DROP_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE): model.insert_before(None, iter, row) else: model.insert_after(None, iter, row) iter = model.iter_next(iter) else: model.append(None, row) thread.start_new_thread(self.safe_fill_treerows, ()) context.finish(True, False, timestamp) self.stop_emission('drag-data-received') return True
class NavigationTreeControl(CommonTreeControl, LoadSave): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.controls = controls self.full_name = "" self.label = Gtk.Label.new(None) self.tree_menu = Popup() self.set_headers_visible(True) self.set_headers_clickable(True) """column config""" self.column = Gtk.TreeViewColumn("File", self.ellipsize_render, text=self.text[0], font=self.font[0]) self._append_column(self.column, _("File")) def func(column, cell, model, iter, ext=False): try: data = model.get_value(iter, self.text[0]) except TypeError: data = None pass if not model.get_value(iter, self.path[0]): cell.set_property('text', '') return if os.path.isfile(model.get_value(iter, self.path[0])): if data: if ext: cell.set_property('text', os.path.splitext(data)[1][1:]) else: cell.set_property('text', os.path.splitext(data)[0]) else: if ext: cell.set_property('text', '') self.name_column = Gtk.TreeViewColumn("Name", self.ellipsize_render, text=self.text[0], font=self.font[0]) self.name_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) for rend in self.name_column.get_cells(): self.name_column.set_cell_data_func(rend, func, False) self._append_column(self.name_column, _("Name")) self.ext_column = Gtk.TreeViewColumn("Ext", Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) for rend in self.ext_column.get_cells(): self.ext_column.set_cell_data_func(rend, func, True) self._append_column(self.ext_column, _("Ext")) self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() self.connect("button-release-event", self.on_button_release) self.connect("drag-data-get", self.on_drag_data_get) '''to force the ext_column to take the minimum size''' self.name_column.set_fixed_width(2000) def task(*a): self.on_click_header(None, None, on_start=True) GLib.idle_add(task) self.scroll.get_vscrollbar().connect('show', task) self.scroll.get_vscrollbar().connect('hide', task) def on_button_release(self, w, e): if is_middle_click_release(e): # on left click add selected items to current tab """to select item under cursor""" try: path, col, cellx, celly = self.get_path_at_pos(int(e.x), int(e.y)) # @UnusedVariable self.get_selection().select_path(path) except TypeError: pass self.add_to_tab(True) return def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_middle_click(e): """to avoid unselect all selected items""" self.stop_emission('button-press-event') if is_left_click(e): # on left click expand selected folders return if is_double_left_click(e): # on middle click play selected beans self.add_to_tab() return if is_rigth_click(e): right_click_optimization_for_trees(w, e) tabhelper = self.controls.perspectives.get_perspective('fs').get_tabhelper() # on right click, show pop-up menu self.tree_menu.clear() self.tree_menu.add_item(_("Append to playlist"), "list-add", lambda: self.add_to_tab(True), None) self.tree_menu.add_item(_("Open in new playlist"), "list-add", self.add_to_tab, None) self.tree_menu.add_separator() self.tree_menu.add_item(_("Add folder here"), "folder-open", self.add_folder, None) self.tree_menu.add_separator() if FC().tabs_mode == "Multi": self.tree_menu.add_item(_("Add folder in new tab"), "folder-open", lambda: self.add_folder(True), None) self.tree_menu.add_item(_("Clear"), "edit-clear", lambda: tabhelper.clear_tree(self.scroll), None) self.tree_menu.add_item(_("Update"), "view-refresh", lambda: tabhelper.on_update_music_tree(self.scroll), None) f_model, f_t_paths = self.get_selection().get_selected_rows() if f_t_paths: model = f_model.get_model() t_paths = [f_model.convert_child_path_to_path(f_t_path) for f_t_path in f_t_paths] row = model[t_paths[0]] paths = [model[t_path][self.path[0]] for t_path in t_paths] row_refs = [Gtk.TreeRowReference.new(model, t_path) for t_path in t_paths] self.tree_menu.add_separator() self.tree_menu.add_item(_("Open in file manager"), "system-file-manager", open_in_filemanager, self.get_selected_bean().path) self.tree_menu.add_item(_("Create folder"), "folder-new", self.create_folder, (model, f_t_paths[0], row)) self.tree_menu.add_item(_("Rename file (folder)"), "edit-find-replace", self.rename_files, (row, self.path[0], self.text[0])) self.tree_menu.add_item(_("Delete file(s) / folder(s)"), "edit-delete", self.delete_files, (row_refs, paths, self.get_iter_from_row_reference)) self.tree_menu.show(e) def _append_column(self, column, title): column.label = Gtk.Label.new(title) column.label.show() column.set_widget(column.label) column.set_clickable(True) self.append_column(column) column.button = column.label.get_parent().get_parent().get_parent() column.button.connect("button-press-event", self.on_click_header) def rename_files(self, a): row, index_path, index_text = a if rename_file_on_disk(row, index_path, index_text): self.save_tree() def delete_files(self, a): row_refs, paths, get_iter_from_row_reference = a if delete_files_from_disk(row_refs, paths, get_iter_from_row_reference): self.delete_selected() self.save_tree() def create_folder(self, a): model, tree_path, row = a # @UnusedVariable file_path = row[self.path[0]] new_folder_path = create_folder_dialog(file_path) bean = FModel(os.path.basename(new_folder_path), new_folder_path).add_is_file(False) if os.path.isfile(file_path): bean.add_parent(row[self.parent_level[0]]) elif os.path.isdir(file_path): bean.add_parent(row[self.level[0]]) else: logging.error("So path doesn't exist") self.tree_append(bean) self.save_tree() def add_to_tab(self, current=False): paths = self.get_selected_bean_paths() to_tree = self.controls.notetabs.get_current_tree() try: to_model = to_tree.get_model().get_model() except AttributeError: current = False to_model = None from_model = self.get_model() def task(to_tree, to_model): treerows = [from_model[path] for path in paths] for i, treerow in enumerate(treerows): for k, ch_row in enumerate(treerow.iterchildren()): treerows.insert(i+k+1, ch_row) #treerows = self.playlist_filter(treerows) if not current: name = treerows[0][0] if isinstance(name, str): name = unicode(name, "utf-8") self.controls.notetabs._append_tab(name) to_tree = self.controls.notetabs.get_current_tree() # because to_tree has changed to_model = to_tree.get_model().get_model() for i, treerow in enumerate(treerows): if is_m3u(treerow[self.path[0]]): rows = to_tree.file_paths_to_rows([treerow[self.path[0]]]) if rows: rows.reverse() map(lambda row: treerows.insert(i + 1, row), rows) continue to_model.append(None, [col for col in treerow]) t = threading.Thread(target=to_tree.safe_fill_treerows) t.start() t.join() if not current: '''gobject because rebuild_as_plain use it too''' self.controls.play_first_file_in_playlist() self.controls.notetabs.on_save_tabs() task(to_tree, to_model) #self.controls.search_progress.background_spinner_wrapper(task, to_tree, to_model) def add_folder(self, in_new_tab=False): chooser = Gtk.FileChooserDialog(title=_("Choose directory with music"), action=Gtk.FileChooserAction.SELECT_FOLDER, buttons=(_("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) tab_name = path[path.rfind("/") + 1:] if isinstance(tab_name, str): tab_name = unicode(tab_name, "utf-8") if in_new_tab: 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(): vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) label = Gtk.Label.new(tab_name + " ") label.set_angle(90) if FC().tab_close_element: vbox.pack_start(tabhelper.button(tree.scroll), False, False, 0) vbox.pack_end(label, False, False, 0) 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_spinner(task, with_lock=False) self.controls.search_progress.background_spinner_wrapper(task) else: logging.info('Closed, no files selected') chooser.destroy() def normalize_columns_width(self): if not hasattr(self, 'ext_width') or not self.ext_width: self.ext_width = self.ext_column.get_width() increase = 0 vscrollbar = self.scroll.get_vscrollbar() if not vscrollbar.get_property('visible'): increase += 3 self.name_column.set_fixed_width(self.get_allocation().width - self.ext_width - increase) def on_click_header(self, w, e, on_start=False): def task(tree): if FC().show_full_filename: tree.column.set_visible(True) tree.name_column.set_visible(False) tree.ext_column.set_visible(False) else: tree.column.set_visible(False) tree.name_column.set_visible(True) tree.ext_column.set_visible(True) if not on_start: FC().show_full_filename = not FC().show_full_filename tabhelper = self.controls.perspectives.get_perspective('fs').get_tabhelper() for page in xrange(tabhelper.get_n_pages()): tab_content = tabhelper.get_nth_page(page) tree = tab_content.get_child() task(tree) else: task(self) self.normalize_columns_width() def on_load(self): #self.controls.load_music_tree() self.restore_expand(FC().nav_expand_paths) self.restore_selection(FC().nav_selected_paths) def set_expand_path(new_value): FC().nav_expand_paths = new_value def set_selected_path(new_value): FC().nav_selected_paths = new_value self.expand_updated(set_expand_path) self.selection_changed(set_selected_path) def on_save(self): pass def on_drag_data_get(self, source_tree, drag_context, selection, info, time): treeselection = source_tree.get_selection() ff_model, ff_paths = treeselection.get_selected_rows() iters = [ff_model.get_iter(ff_path) for ff_path in ff_paths] all_file_paths = '' for iter in iters: all_iters = self.get_list_of_iters_with_children(ff_model, iter) file_paths = ','.join([ff_model.get_value(iter, self.path[0]) for iter in all_iters]) all_file_paths += file_paths selection.set(selection.get_target(), 0, all_file_paths) self.stop_emission('drag-data-get') def save_tree(self): page_num = self.controls.perspectives.get_perspective('fs').get_tabhelper().page_num(self.scroll) self.save_rows_from_tree(FCache().cache_music_tree_beans[page_num])
class VKIntegrationControls(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("VK Integration "), self.ellipsize_render, text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() self.lazy = False self.cache = [] def lazy_load(self): if not self.lazy: self.controls.in_thread.run_with_spinner(self._lazy_load) def _lazy_load(self): def get_users_by_uuid(uuidd): for user in self.controls.vk_service.get_result( 'getProfiles', 'uids=' + uuidd): def task(user): logging.debug(user) name = user['first_name'] + " " + user['last_name'] parent = FModel(name) parent.user_id = user['uid'] bean = FDModel( _("loading...")).parent(parent).add_is_file(True) self.append(parent) self.append(bean) GLib.idle_add(task, user) if not FC().user_id and not self.controls.vk_service.auth(): return get_users_by_uuid(FC().user_id) uids = self.controls.vk_service.get_result('friends.get', 'uid=' + FC().user_id) if uids: get_users_by_uuid(",".join(["%s" % i for i in uids])) self.lazy = True def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) active = self.get_selected_bean() if active: self.tree_menu.clear() if isinstance(active, FModel) and active.path: self.tree_menu.add_item(_('Play'), "media-playback-start", self.controls.play, active) self.tree_menu.add_item( _('Copy to Search Line'), "edit-copy", self.controls.searchPanel.set_search_text, active.text) self.tree_menu.show(e) if is_double_left_click(e): selected = self.get_selected_bean() if not selected: return def task(): if (selected.user_id not in self.cache) and (not selected.is_file): beans = self.get_user_tracks_as_beans(selected.user_id) else: beans = self.get_all_child_beans_by_selected() self.controls.notetabs.append_tab(selected.text, [selected] + beans, optimization=True) self.controls.play_first_file_in_playlist() self.controls.in_thread.run_with_spinner(task) def on_row_expanded(self, widget, iter, path): self.on_bean_expanded(iter) def get_user_tracks_as_beans(self, user_id): beans = [] result = self.controls.vk_service.get_result('audio.get', "uid=" + user_id) if not result: beans = [FDModel(_("No results found")).add_is_file(True)] else: for line in result: bean = FModel(line['artist'] + ' - ' + line['title']) bean.aritst = line['artist'] bean.title = line['title'] bean.time = convert_seconds_to_text(line['duration']) bean.path = line['url'] bean.aid = line['aid'] bean.oid = line['owner_id'] bean.is_file = True bean.vk_audio_id = "%s_%s" % (line['owner_id'], line['aid']) beans.append(bean) return beans def on_bean_expanded(self, parent_iter): logging.debug("expanded %s" % parent_iter) p_iter = self.get_model().convert_iter_to_child_iter(parent_iter) parent = self.get_bean_from_iter(p_iter) if parent.user_id in self.cache: return None self.cache.append(parent.user_id) old_iters = self.get_child_iters_by_parent(self.model, p_iter) def task(): beans = self.get_user_tracks_as_beans(parent.user_id) def safe(): for bean in beans: bean.parent(parent) row = self.get_row_from_bean(bean) self.model.append(p_iter, row) for rem in old_iters: self.model.remove(rem) GLib.idle_add(safe) self.controls.in_thread.run_with_spinner(task)
class VKIntegrationControls(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("VK Integration "), self.ellipsize_render, text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() self.lazy = False self.cache = [] def lazy_load(self): if not self.lazy: self.controls.in_thread.run_with_spinner(self._lazy_load) def _lazy_load(self): def get_users_by_uuid(uuidd): for user in self.controls.vk_service.get_result('getProfiles', 'uids=' + uuidd): def task(user): logging.debug(user) name = user['first_name'] + " " + user['last_name'] parent = FModel(name) parent.user_id = user['uid'] bean = FDModel(_("loading...")).parent(parent).add_is_file(True) self.append(parent) self.append(bean) GLib.idle_add(task, user) if not FC().user_id and not self.controls.vk_service.auth(): return get_users_by_uuid(FC().user_id) uids = self.controls.vk_service.get_result('friends.get', 'uid=' + FC().user_id) if uids: get_users_by_uuid(",".join(["%s" % i for i in uids])) self.lazy = True def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) active = self.get_selected_bean() if active: self.tree_menu.clear() if isinstance(active, FModel) and active.path: self.tree_menu.add_item(_('Play'), "media-playback-start", self.controls.play, active) self.tree_menu.add_item(_('Copy to Search Line'), "edit-copy", self.controls.searchPanel.set_search_text, active.text) self.tree_menu.show(e) if is_double_left_click(e): selected = self.get_selected_bean() if not selected: return def task(): if (selected.user_id not in self.cache) and (not selected.is_file): beans = self.get_user_tracks_as_beans(selected.user_id) else: beans = self.get_all_child_beans_by_selected() self.controls.notetabs.append_tab(selected.text, [selected] + beans, optimization=True) self.controls.play_first_file_in_playlist() self.controls.in_thread.run_with_spinner(task) def on_row_expanded(self, widget, iter, path): self.on_bean_expanded(iter) def get_user_tracks_as_beans(self, user_id): beans = [] result = self.controls.vk_service.get_result('audio.get', "uid=" + user_id) if not result: beans = [FDModel(_("No results found")).add_is_file(True)] else: for line in result: bean = FModel(line['artist'] + ' - ' + line['title']) bean.aritst = line['artist'] bean.title = line['title'] bean.time = convert_seconds_to_text(line['duration']) bean.path = line['url'] bean.aid = line['aid'] bean.oid = line['owner_id'] bean.is_file = True bean.vk_audio_id = "%s_%s" % (line['owner_id'], line['aid']) beans.append(bean) return beans def on_bean_expanded(self, parent_iter): logging.debug("expanded %s" % parent_iter) p_iter = self.get_model().convert_iter_to_child_iter(parent_iter) parent = self.get_bean_from_iter(p_iter) if parent.user_id in self.cache: return None self.cache.append(parent.user_id) old_iters = self.get_child_iters_by_parent(self.model, p_iter) def task(): beans = self.get_user_tracks_as_beans(parent.user_id) def safe(): for bean in beans: bean.parent(parent) row = self.get_row_from_bean(bean) self.model.append(p_iter, row) for rem in old_iters: self.model.remove(rem) GLib.idle_add(safe) self.controls.in_thread.run_with_spinner(task)
def create_menu(self): menu = Popup() menu.add_item(_("Play-Pause"), "media-playback-pause", self.set_action_text, "play_pause") menu.add_item(_("Stop"), "media-playback-stop", self.set_action_text, "state_stop") menu.add_item(_("Next song"), "go-next", self.set_action_text, "next") menu.add_item(_("Previous song"), "go-previous", self.set_action_text, "prev") menu.add_item(_("Volume up"), "go-up", self.set_action_text, "volume_up") menu.add_item(_("Volume down"), "go-down", self.set_action_text, "volume_down") menu.add_item(_("Show-Hide"), "view-fullscreen", self.set_action_text, "show_hide") menu.add_item(_('Download'), "list-add", self.set_action_text, "download") return menu
class RadioTreeControl(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.set_reorderable(False) self.switcher_label = _("My channels") self.tree_menu = Popup() """column config""" column = Gtk.TreeViewColumn(_("Radio Stations"), Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() @idle_task def on_load(self): if FCache().cache_radio_tree_beans: self.restore_rows(FCache().cache_radio_tree_beans) else: self.update_radio_tree() def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) "run radio channel" self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) self.tree_menu.clear() bean = self.get_selected_bean() if bean: if self.get_selected_bean().is_file: self.tree_menu.add_item(_("Edit Station"), Gtk.STOCK_EDIT, self.on_edit_radio, None) self.tree_menu.add_item(_("Delete Station"), Gtk.STOCK_DELETE, self.delete_selected, None) else: self.tree_menu.add_item(_("Rename Group"), Gtk.STOCK_EDIT, self.on_rename_group, None) self.tree_menu.add_item(_("Delete Group"), Gtk.STOCK_DELETE, self.delete_selected, None) self.tree_menu.add_separator() self.tree_menu.add_item(_("Reload radio folder"), Gtk.STOCK_REFRESH, self.update_radio_tree, None) self.tree_menu.show(e) def on_edit_radio(self): bean = self.get_selected_bean() name, url = two_line_dialog(_("Edit Radio"), parent = self.controls.main_window, message_text1 = _("Enter new name and URL"), message_text2 = None, entry_text1=bean.text, entry_text2 = bean.path) if not name or not url: return bean.add_text(name) bean.add_path(url) rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name rows[0][self.path[0]] = url def on_rename_group(self): bean = self.get_selected_bean() name = one_line_dialog(_("Rename Group"), self.controls.main_window, entry_text=bean.text, message_text1=_("Enter new group name")) if not name: return rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name def on_add_station(self): name, url = two_line_dialog(_("Add New Radio Station"), parent = self.controls.main_window, message_text1 = _("Enter station name and URL"), message_text2 = None, entry_text1 = None, entry_text2 = "http://") if not name or not url: return bean = self.get_selected_bean() new_bean = FModel(name, url).add_type(FTYPE_RADIO).add_is_file(True) if bean: if bean.is_file: new_bean.add_parent(bean.parent_level) else: new_bean.add_parent(bean.level) self.append(new_bean) def on_save(self): pass #def update_radio_tree(self): # self.controls.in_thread.run_with_progressbar(self._update_radio_tree) @idle_task def update_radio_tree(self): logging.info("in update radio") self.clear_tree() self.radio_folder = RadioFolder() files = self.radio_folder.get_radio_FPLs() for fpl in files: parent = FModel(fpl.name).add_is_file(False) self.append(parent) keys = fpl.urls_dict.keys() keys.sort() for radio in keys: child = FModel(radio, fpl.urls_dict[radio][0]).parent(parent).add_type(FTYPE_RADIO).add_is_file(True) self.append(child) def auto_add_user_station(self): if os.path.isfile(CACHE_RADIO_FILE) and os.path.getsize(CACHE_RADIO_FILE) > 0: with open(CACHE_RADIO_FILE, 'r') as f: list = f.readlines() parent_level_for_depth = {} previous = {"bean": None, "depth": 0, "name": '', "url": ''} for line in list: depth = self.simbol_counter(line, '-') try: name = line[depth : line.index('#')] except ValueError, e: logging.warning('\'#\' ' + str(e) + ' in line \"' + line + '\"') continue url = line[line.index('#') + 1 : -1] bean = FModel(name) if url: bean.add_is_file(True).add_path(url).add_type(FTYPE_RADIO) if previous["depth"] < depth: bean.add_parent(previous["bean"].level) elif previous["depth"] > depth: bean.add_parent(parent_level_for_depth[depth]) else: if previous["bean"]: bean.add_parent(previous["bean"].parent_level) self.append(bean) parent_level_for_depth[depth] = bean.parent_level previous = {"bean": bean, "depth": depth, "name": name, "url": url}
class DownloadManagerTreeControl(CommonTreeControl): def __init__(self, navigation): self.navigation = navigation CommonTreeControl.__init__(self, None) self.set_reorderable(False) self.set_headers_visible(True) self.tree_menu = Popup() """column config""" column = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=self.text[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn("Progress", Gtk.CellRendererProgress(), text=self.persent[0], value=self.persent[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn("Size", Gtk.CellRendererText(), text=self.size[0]) column.set_resizable(True) self.append_column(column) """status""" column = Gtk.TreeViewColumn("Status", Gtk.CellRendererText(), text=self.status[0]) column.set_resizable(True) self.append_column(column) """column config""" column = Gtk.TreeViewColumn("Path", Gtk.CellRendererText(), text=self.save_to[0]) column.set_resizable(True) column.set_expand(True) self.append_column(column) self.set_type_plain() @idle_task def delete_all(self): self.clear() @idle_task def delete_all_selected(self): self.delete_selected() @idle_task def update_status_for_selected(self, status): beans = self.get_all_selected_beans() for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) @idle_task def update_status_for_all(self, status): beans = self.get_all_beans() for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) @idle_task def update_status_for_beans(self, beans, status): for bean in beans: self.set_bean_column_value(bean, FTreeModel().status[0], status) def get_next_bean_to_dowload(self): all = self.get_all_beans() if not all: return None for bean in all: if bean.get_status() == DOWNLOAD_STATUS_ACTIVE: self.set_bean_column_value(bean, FTreeModel().status[0], DOWNLOAD_STATUS_LOCK) return bean @idle_task def update_bean_info(self, bean): self.update_bean(bean) self.navigation.update_statistics() #self.navigation.use_filter() def on_button_press(self, w, e): logging.debug("on dm button press") if is_empty_click(w, e): w.get_selection().unselect_all() if is_rigth_click(e): right_click_optimization_for_trees(w, e) try: self.tree_menu.clear() if self.get_selected_bean(): self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) else: self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, FC().online_save_to_folder) self.tree_menu.show(e) except Exception, e: logging.error(e)
class NavigationTreeControl(CommonTreeControl, LoadSave): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.controls = controls self.full_name = "" self.label = Gtk.Label() self.tree_menu = Popup() self.set_headers_visible(True) self.set_headers_clickable(True) """column config""" self.column = Gtk.TreeViewColumn("File", Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) self._append_column(self.column, _("File")) def func(column, cell, model, iter, ext=False): try: data = model.get_value(iter, self.text[0]) except TypeError: data = None pass if not model.get_value(iter, self.path[0]): cell.set_property('text', '') return if os.path.isfile(model.get_value(iter, self.path[0])): if data: if ext: cell.set_property('text', os.path.splitext(data)[1][1:]) else: cell.set_property('text', os.path.splitext(data)[0]) else: if ext: cell.set_property('text', '') self.name_column = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) self.name_column.set_sizing(Gtk.TREE_VIEW_COLUMN_FIXED) for rend in self.name_column.get_cells(): self.name_column.set_cell_data_func(rend, func, False) self._append_column(self.name_column, _("Name")) self.ext_column = Gtk.TreeViewColumn("Ext", Gtk.CellRendererText(), text=self.text[0], font=self.font[0]) for rend in self.ext_column.get_cells(): self.ext_column.set_cell_data_func(rend, func, True) self._append_column(self.ext_column, _("Ext")) self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() #self.is_empty = False self.connect("button-release-event", self.on_button_release) self.connect("drag-data-get", self.on_drag_data_get) '''to force the ext_column to take the minimum size''' self.name_column.set_fixed_width(2000) def task(*a): self.on_click_header(None, None, on_start=True) GLib.idle_add(task) self.scroll.get_vscrollbar().connect('show', task) self.scroll.get_vscrollbar().connect('hide', task) def on_button_release(self, w, e): if is_middle_click_release(e): # on left click add selected items to current tab """to select item under cursor""" try: path, col, cellx, celly = self.get_path_at_pos(int(e.x), int(e.y)) # @UnusedVariable self.get_selection().select_path(path) except TypeError: pass self.add_to_tab(True) return def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_middle_click(e): """to avoid unselect all selected items""" self.stop_emission('button-press-event') if is_left_click(e): # on left click expand selected folders return if is_double_left_click(e): # on middle click play selected beans self.add_to_tab() return if is_rigth_click(e): right_click_optimization_for_trees(w, e) tabhelper = self.controls.perspectives.get_perspective('fs').get_tabhelper() # on right click, show pop-up menu self.tree_menu.clear() self.tree_menu.add_item(_("Append to playlist"), Gtk.STOCK_ADD, lambda: self.add_to_tab(True), None) self.tree_menu.add_item(_("Open in new playlist"), Gtk.STOCK_MEDIA_PLAY, self.add_to_tab, None) self.tree_menu.add_separator() self.tree_menu.add_item(_("Add folder here"), Gtk.STOCK_OPEN, self.add_folder, None) self.tree_menu.add_separator() if FC().tabs_mode == "Multi": self.tree_menu.add_item(_("Add folder in new tab"), Gtk.STOCK_OPEN, lambda: self.add_folder(True), None) self.tree_menu.add_item(_("Clear"), Gtk.STOCK_CLEAR, lambda: tabhelper.clear_tree(self.scroll), None) self.tree_menu.add_item(_("Update"), Gtk.STOCK_REFRESH, lambda: tabhelper.on_update_music_tree(self.scroll), None) f_model, f_t_paths = self.get_selection().get_selected_rows() if f_t_paths: model = f_model.get_model() t_paths = [f_model.convert_child_path_to_path(f_t_path) for f_t_path in f_t_paths] row = model[t_paths[0]] paths = [model[t_path][self.path[0]] for t_path in t_paths] row_refs = [Gtk.TreeRowReference.new(model, t_path) for t_path in t_paths] self.tree_menu.add_separator() self.tree_menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) self.tree_menu.add_item(_("Create folder"), None, self.create_folder, (model, f_t_paths[0], row)) self.tree_menu.add_item(_("Rename file (folder)"), None, self.rename_files, (row, self.path[0], self.text[0])) self.tree_menu.add_item(_("Delete file(s) / folder(s)"), None, self.delete_files, (row_refs, paths, self.get_iter_from_row_reference)) self.tree_menu.show(e) def _append_column(self, column, title): column.label = Gtk.Label(title) column.label.show() column.set_widget(column.label) column.set_clickable(True) self.append_column(column) column.button = column.label.get_parent().get_parent().get_parent() column.button.connect("button-press-event", self.on_click_header) def rename_files(self, a): row, index_path, index_text = a if rename_file_on_disk(row, index_path, index_text): self.save_tree() def delete_files(self, a): row_refs, paths, get_iter_from_row_reference = a if delete_files_from_disk(row_refs, paths, get_iter_from_row_reference): self.delete_selected() self.save_tree() def create_folder(self, a): model, tree_path, row = a # @UnusedVariable file_path = row[self.path[0]] new_folder_path = create_folder_dialog(file_path) bean = FModel(os.path.basename(new_folder_path), new_folder_path).add_is_file(False) if os.path.isfile(file_path): bean.add_parent(row[self.parent_level[0]]) elif os.path.isdir(file_path): bean.add_parent(row[self.level[0]]) else: logging.error("So path doesn't exist") self.tree_append(bean) self.save_tree() def add_to_tab(self, current=False): paths = self.get_selected_bean_paths() to_tree = self.controls.notetabs.get_current_tree() try: to_model = to_tree.get_model().get_model() except AttributeError: current = False to_model = None from_model = self.get_model() def task(to_tree, to_model): treerows = [from_model[path] for path in paths] for i, treerow in enumerate(treerows): for k, ch_row in enumerate(treerow.iterchildren()): treerows.insert(i+k+1, ch_row) #treerows = self.playlist_filter(treerows) if not current: name = treerows[0][0] self.controls.notetabs._append_tab(name) to_tree = self.controls.notetabs.get_current_tree() # because to_tree has changed to_model = to_tree.get_model().get_model() for i, treerow in enumerate(treerows): if is_m3u(treerow[self.path[0]]): rows = self.file_paths_to_rows([treerow[self.path[0]]]) if rows: rows.reverse() map(lambda row: treerows.insert(i + 1, row), rows) continue to_model.append(None, [col for col in treerow]) t = threading.Thread(target=to_tree.safe_fill_treerows) t.start() t.join() if not current: '''gobject because rebuild_as_plain use it too''' self.controls.play_first_file_in_playlist() self.controls.notetabs.on_save_tabs() task(to_tree, to_model) #self.controls.search_progress.background_spinner_wrapper(task, to_tree, to_model) 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() def normalize_columns_width(self): if not hasattr(self, 'ext_width') or not self.ext_width: self.ext_width = self.ext_column.get_width() increase = 0 vscrollbar = self.scroll.get_vscrollbar() if not vscrollbar.get_property('visible'): increase += 3 self.name_column.set_fixed_width(self.get_allocation().width - self.ext_width - increase) def on_click_header(self, w, e, on_start=False): def task(tree): if FC().show_full_filename: tree.column.set_visible(True) tree.name_column.set_visible(False) tree.ext_column.set_visible(False) else: tree.column.set_visible(False) tree.name_column.set_visible(True) tree.ext_column.set_visible(True) if not on_start: FC().show_full_filename = not FC().show_full_filename tabhelper = self.controls.perspectives.get_perspective('fs').get_tabhelper() for page in xrange(tabhelper.get_n_pages()): tab_content = tabhelper.get_nth_page(page) tree = tab_content.get_child() task(tree) else: task(self) self.normalize_columns_width() def on_load(self): #self.controls.load_music_tree() self.restore_expand(FC().nav_expand_paths) self.restore_selection(FC().nav_selected_paths) def set_expand_path(new_value): FC().nav_expand_paths = new_value def set_selected_path(new_value): FC().nav_selected_paths = new_value self.expand_updated(set_expand_path) self.selection_changed(set_selected_path) def on_save(self): pass def on_drag_data_get(self, source_tree, drag_context, selection, info, time): treeselection = source_tree.get_selection() ff_model, ff_paths = treeselection.get_selected_rows() iters = [ff_model.get_iter(ff_path) for ff_path in ff_paths] all_file_paths = '' for iter in iters: all_iters = self.get_list_of_iters_with_children(ff_model, iter) file_paths = ','.join([ff_model.get_value(iter, self.path[0]) for iter in all_iters]) all_file_paths += file_paths selection.set(selection.get_target(), 0, all_file_paths) self.stop_emission('drag-data-get') def save_tree(self): page_num = self.controls.perspectives.get_perspective('fs').get_tabhelper().page_num(self.scroll) self.save_rows_from_tree(FCache().cache_music_tree_beans[page_num])
class VirtualTreeControl(CommonTreeControl, LoadSave): def __init__(self, controls): CommonTreeControl.__init__(self, controls) """column config""" column = Gtk.TreeViewColumn(_("Storage"), self.ellipsize_render, text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.tree_menu = Popup() self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() def on_key_release(self, w, e): if is_key(e, KEY_DELETE): self.delete_selected() def on_drag_drop_finish(self): FCache().cache_virtual_tree_beans = self.get_all_beans() FC().save() def on_button_press(self, w, e): if is_empty_click(w, e): w.get_selection().unselect_all() if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) self.tree_menu.clear() self.tree_menu.add_item(_("Add playlist"), Gtk.STOCK_ADD, self.create_playlist, None) bean = self.get_selected_bean() if bean: if bean.is_file: self.tree_menu.add_item(_("Rename"), Gtk.STOCK_EDIT, self.rename_selected, None) self.tree_menu.add_item(_("Delete"), Gtk.STOCK_DELETE, self.delete_selected, None) else: self.tree_menu.add_item(_("Rename playlist"), Gtk.STOCK_EDIT, self.rename_selected, None) self.tree_menu.add_item(_("Delete playlist"), Gtk.STOCK_DELETE, self.delete_selected, None) #menu.add_item(_("Save as"), Gtk.STOCK_SAVE_AS, None, None) #menu.add_item(_("Open as"), Gtk.STOCK_OPEN, None, None) self.tree_menu.show(e) def create_playlist(self): name = one_line_dialog(_("Create new playlist"), self.controls.main_window, message_text1=_("Enter playlist name")) if not name: return bean = self.get_selected_bean() folder_bean = FModel(name) if bean: if bean.is_file: folder_bean.add_parent(bean.parent_level) else: folder_bean.add_parent(bean.level) self.append(folder_bean) def rename_selected(self): bean = self.get_selected_bean() name = one_line_dialog(_("Rename Dialog"), self.controls.main_window, entry_text=bean.text, message_text1=_("Enter new name")) if not name: return rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name def on_load(self): self.scroll.hide() self.restore_rows(FCache().cache_virtual_tree_beans) self.restore_expand(FC().virtual_expand_paths) self.restore_selection(FC().virtual_selected_paths) def set_expand_path(new_value): FC().virtual_expand_paths = new_value def set_selected_path(new_value): FC().virtual_selected_paths = new_value self.expand_updated(set_expand_path) self.selection_changed(set_selected_path) def on_quit(self): self.save_rows_from_tree(FCache().cache_virtual_tree_beans) def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp): logging.debug('Storage on_drag_data_received') model = self.get_model().get_model() drop_info = self.get_dest_row_at_pos(x, y) # ff - from_filter ff_tree = Gtk.drag_get_source_widget(context) ff_model, ff_paths = ff_tree.get_selection().get_selected_rows() treerows = [ff_model[ff_path] for ff_path in ff_paths] if drop_info: path, position = drop_info iter = model.get_iter(path) if position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER: self.model[path][self.font[0]] = 'bold' if self == ff_tree: ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths] def add_childs(treerow, new_iter): for ch_row in treerow.iterchildren(): niter = model.append(new_iter, [col for col in ch_row]) add_childs(ch_row, niter) for treerow, ref in zip(treerows, ff_row_refs): row = [col for col in treerow] if drop_info: if position == Gtk.TREE_VIEW_DROP_BEFORE: new_iter = model.insert_before(None, iter, row) elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER): new_iter = model.append(iter, row) else: new_iter = model.insert_after(None, iter, row) iter = model.iter_next(iter) else: new_iter = model.append(None, row) treerow = model[ref.get_path()] # reinitialize add_childs(treerow, new_iter) self.remove_replaced(ff_model, ff_row_refs) else: for treerow in treerows: row = [col for col in treerow] if drop_info: if position == Gtk.TREE_VIEW_DROP_BEFORE: new_iter = model.insert_before(None, iter, row) elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER): new_iter = model.append(iter, row) else: new_iter = model.insert_after(None, iter, row) iter = model.iter_next(iter) else: new_iter = model.append(None, row) if len(treerows) == 1 and treerow[self.font[0]] == 'bold': while treerow.next and treerow.next[self.font[0]] != 'bold': treerow = treerow.next treerows.append(treerow) drop_info = True iter = new_iter position = Gtk.TREE_VIEW_DROP_INTO_OR_AFTER self.stop_emission('drag-data-received')
def on_button_release(self, w, e): if is_rigth_click_release(e): """to select item under cursor""" try: path, col, cellx, celly = self.get_path_at_pos(int(e.x), int(e.y)) #@UnusedVariable self.get_selection().select_path(path) except TypeError: pass #menu.add_item('Save as', gtk.STOCK_SAVE_AS, self.controls.save_beans_to, self.get_all_selected_beans()) beans = self.get_selected_beans() if beans: menu = Popup() menu.add_item(_('Play'), gtk.STOCK_MEDIA_PLAY, self.controls.play_selected_song, None) menu.add_item(_('Delete from playlist'), gtk.STOCK_DELETE, self.delete_selected, None) paths = [] inet_paths = [] local_paths = [] for bean in beans: if bean.path in paths: continue paths.append(bean.path) if not bean.path or bean.path.startswith("http://"): inet_paths.append(bean.path) else: local_paths.append(bean.path) if local_paths: menu.add_item(_('Copy To...'), gtk.STOCK_ADD, copy_to, local_paths) menu.add_item(_("Open in file manager"), None, open_in_filemanager, local_paths[0]) if inet_paths: menu.add_item(_('Download'), gtk.STOCK_ADD, self.controls.dm.append_tasks, self.get_all_selected_beans()) menu.add_item(_('Download To...'), gtk.STOCK_ADD, self.controls.dm.append_tasks_with_dialog, self.get_all_selected_beans()) menu.add_separator() if paths[0]: menu.add_item(_('Edit Tags'), gtk.STOCK_EDIT, edit_tags, (self.controls, paths)) menu.add_item(_('Format Converter'), gtk.STOCK_CONVERT, convert_files, paths) text = self.get_selected_bean().text menu.add_item(_('Copy To Search Line'), gtk.STOCK_COPY, self.controls.searchPanel.set_search_text, text) menu.add_separator() menu.add_item(_('Copy №-Title-Time'), gtk.STOCK_COPY, self.copy_info_to_clipboard) menu.add_item(_('Copy Artist-Title-Album'), gtk.STOCK_COPY, self.copy_info_to_clipboard, True) menu.add_separator() menu.add_item(_('Love This Track(s)'), None, self.controls.love_this_tracks, self.get_all_selected_beans()) menu.add_separator() if paths[0]: menu.add_item(_("Open In File Manager"), None, open_in_filemanager, paths[0]) menu.show(e)
def on_button_press(self, w, e): if is_rigth_click(e): menu = Popup() menu.add_item('Restore Defaults', gtk.STOCK_REFRESH, None) menu.show(e)
def on_button_press(self, w, e): if is_middle_click(e): """to avoid unselect all selected items""" self.stop_emission('button-press-event') if is_left_click(e): # on left click expand selected folders return if is_double_left_click(e): # on middle click play selected beans self.add_to_tab() return if is_rigth_click(e): # on right click, show pop-up menu menu = Popup() menu.add_item(_("Append to playlist"), gtk.STOCK_ADD, lambda: self.add_to_tab(True), None) menu.add_item(_("Open in new playlist"), gtk.STOCK_MEDIA_PLAY, self.add_to_tab, None) menu.add_separator() menu.add_item(_("Add folder here"), gtk.STOCK_OPEN, self.add_folder, None) menu.add_separator() if FC().tabs_mode == "Multi": menu.add_item(_("Add folder in new tab"), gtk.STOCK_OPEN, lambda: self.add_folder(True), None) menu.add_item( _("Clear"), gtk.STOCK_CLEAR, lambda: self.controls.tabhelper.clear_tree(self.scroll), None) menu.add_item( _("Update"), gtk.STOCK_REFRESH, lambda: self.controls.tabhelper .on_update_music_tree(self.scroll), None) f_model, f_t_paths = self.get_selection().get_selected_rows() if f_t_paths: model = f_model.get_model() t_paths = [ f_model.convert_child_path_to_path(f_t_path) for f_t_path in f_t_paths ] row = model[t_paths[0]] paths = [model[t_path][self.path[0]] for t_path in t_paths] row_refs = [ gtk.TreeRowReference(model, t_path) for t_path in t_paths ] menu.add_separator() menu.add_item(_("Open in file manager"), None, open_in_filemanager, self.get_selected_bean().path) menu.add_item(_("Create folder"), None, self.create_folder, (model, f_t_paths[0], row)) menu.add_item(_("Rename file (folder)"), None, self.rename_files, (row, self.path[0], self.text[0])) menu.add_item( _("Delete file(s) / folder(s)"), None, self.delete_files, (row_refs, paths, self.get_iter_from_row_reference)) menu.show(e)
class RadioTreeControl(CommonTreeControl): def __init__(self, controls): CommonTreeControl.__init__(self, controls) self.set_reorderable(False) self.switcher_label = _("My channels") self.tree_menu = Popup() """column config""" column = Gtk.TreeViewColumn(_("Radio Stations"), self.ellipsize_render, text=self.text[0], font=self.font[0]) column.set_resizable(True) self.set_headers_visible(True) self.append_column(column) self.configure_send_drag() self.configure_recive_drag() self.set_type_tree() @idle_task def on_load(self): if FCache().cache_radio_tree_beans: self.restore_rows(FCache().cache_radio_tree_beans) else: self.update_radio_tree() def on_button_press(self, w, e): if is_double_left_click(e): selected = self.get_selected_bean() beans = self.get_all_child_beans_by_selected() self.controls.notetabs._append_tab(selected.text, [selected] + beans, optimization=True) "run radio channel" self.controls.play_first_file_in_playlist() if is_rigth_click(e): right_click_optimization_for_trees(w, e) self.tree_menu.clear() bean = self.get_selected_bean() if bean: if self.get_selected_bean().is_file: self.tree_menu.add_item(_("Edit Station"), "accessories-text-editor", self.on_edit_radio, None) self.tree_menu.add_item(_("Delete Station"), "edit-delete", self.delete_selected, None) else: self.tree_menu.add_item(_("Rename Group"), "accessories-text-editor", self.on_rename_group, None) self.tree_menu.add_item(_("Delete Group"), "edit-delete", self.delete_selected, None) self.tree_menu.add_separator() self.tree_menu.add_item(_("Reload radio folder"), "view-refresh", self.update_radio_tree, None) self.tree_menu.show(e) def on_edit_radio(self): bean = self.get_selected_bean() name, url = two_line_dialog(_("Edit Radio"), parent=self.controls.main_window, message_text1=_("Enter new name and URL"), message_text2=None, entry_text1=bean.text, entry_text2=bean.path) if not name or not url: return bean.add_text(name) bean.add_path(url) rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name rows[0][self.path[0]] = url def on_rename_group(self): bean = self.get_selected_bean() name = one_line_dialog(_("Rename Group"), self.controls.main_window, entry_text=bean.text, message_text1=_("Enter new group name")) if not name: return rows = self.find_rows_by_element(self.UUID, bean.UUID) if rows: rows[0][self.text[0]] = name def on_add_station(self): name, url = two_line_dialog( _("Add New Radio Station"), parent=self.controls.main_window, message_text1=_("Enter station name and URL"), message_text2=None, entry_text1=None, entry_text2="http://") if not name or not url: return bean = self.get_selected_bean() new_bean = FModel(name, url).add_type(FTYPE_RADIO).add_is_file(True) if bean: if bean.is_file: new_bean.add_parent(bean.parent_level) else: new_bean.add_parent(bean.level) self.append(new_bean) def on_save(self): pass #def update_radio_tree(self): # self.controls.in_thread.run_with_spinner(self._update_radio_tree) @idle_task def update_radio_tree(self): logging.info("in update radio") self.clear_tree() self.radio_folder = RadioFolder() files = self.radio_folder.get_radio_FPLs() for fpl in files: parent = FModel(fpl.name).add_is_file(False) self.append(parent) keys = fpl.urls_dict.keys() keys.sort() for radio in keys: child = FModel(radio, fpl.urls_dict[radio][0]).parent( parent).add_type(FTYPE_RADIO).add_is_file(True) self.append(child) def auto_add_user_station(self): if os.path.isfile( CACHE_RADIO_FILE) and os.path.getsize(CACHE_RADIO_FILE) > 0: with open(CACHE_RADIO_FILE, 'r') as f: list = f.readlines() parent_level_for_depth = {} previous = {"bean": None, "depth": 0, "name": '', "url": ''} for line in list: depth = self.simbol_counter(line, '-') try: name = line[depth:line.index('#')] except ValueError, e: logging.warning('\'#\' ' + str(e) + ' in line \"' + line + '\"') continue url = line[line.index('#') + 1:-1] bean = FModel(name) if url: bean.add_is_file(True).add_path(url).add_type( FTYPE_RADIO) if previous["depth"] < depth: bean.add_parent(previous["bean"].level) elif previous["depth"] > depth: bean.add_parent(parent_level_for_depth[depth]) else: if previous["bean"]: bean.add_parent(previous["bean"].parent_level) self.append(bean) parent_level_for_depth[depth] = bean.parent_level previous = { "bean": bean, "depth": depth, "name": name, "url": url }