Exemplo n.º 1
0
 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()
         for radio in sorted(keys):
             child = FModel(radio, fpl.urls_dict[radio][0]).parent(
                 parent).add_type(FTYPE_RADIO).add_is_file(True)
             self.append(child)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
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}
Exemplo n.º 4
0
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
                    }