def on_button_refresh_clicked(self, button):
        # button can be None

        # Refresh episode cache

        preset = None
        combo = self.tool_bar_box.preset_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            preset = model[tree_iter][self.PresetComboModelColumn.PRESET]
            prog_type = model[tree_iter][self.PresetComboModelColumn.PROG_TYPE]

        channels = None
        combo = self.tool_bar_box.channel_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            channels = model[tree_iter][KEY_INDEX]
            (channels,
             exclude_channels) = _separate_excluded_channels(channels)

        future = self.tool_bar_box.future_check_button.get_active()

        self.main_window.display_busy_mouse_cursor(True)
        get_iplayer.refresh(preset=preset,
                            prog_type=prog_type,
                            channels=channels,
                            exclude_channels=exclude_channels,
                            future=future)
        self.main_window.display_busy_mouse_cursor(False)

        # Refresh episode list

        self.on_button_find_clicked(None)
    def on_button_refresh_clicked(self, button):
        # button can be None
        
        # Refresh episode cache

        preset = None
        combo = self.tool_bar_box.preset_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            preset = model[tree_iter][self.PresetComboModelColumn.PRESET]
            prog_type = model[tree_iter][self.PresetComboModelColumn.PROG_TYPE]

        channels = None
        combo = self.tool_bar_box.channel_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            channels = model[tree_iter][KEY_INDEX]
            (channels, exclude_channels) = _separate_excluded_channels(channels)

        future = self.tool_bar_box.future_check_button.get_active()

        self.main_window.display_busy_mouse_cursor(True)
        get_iplayer.refresh(preset=preset, prog_type=prog_type, channels=channels, exclude_channels=exclude_channels, future=future)
        self.main_window.display_busy_mouse_cursor(False)
        
        # Refresh episode list

        self.on_button_find_clicked(None)
def list_channels(compact=True):
    # Avoid refresh messages in the print statements below
    get_iplayer.refresh()
    print()

    channels = get_iplayer.channels("", get_iplayer.Preset.RADIO, get_iplayer.ProgType.RADIO, compact=compact)
    print("[radio]")
    print("channels =", channels)
    print()

    channels = get_iplayer.channels("", get_iplayer.Preset.TV, get_iplayer.ProgType.TV, compact=compact)
    print("[tv]")
    print("channels =", channels)
def list_categories():
    #NOTE end="" suppresses newline: print("...", end="")

    # Avoid refresh messages in the print statements below
    get_iplayer.refresh()
    print()

    categories = get_iplayer.categories("", get_iplayer.Preset.RADIO, get_iplayer.ProgType.RADIO)
    print("categories =", categories)
    print()

    categories = get_iplayer.categories("", get_iplayer.Preset.TV, get_iplayer.ProgType.TV)
    print("[tv]")
    print("categories =", categories)
    def on_button_find_clicked(self, button):
        # button can be None
        search_text = self.tool_bar_box.search_entry.get_text()
        search_all = self.tool_bar_box.search_all_check_button.get_active()
        disable_presets = string.str2bool(settings.get_config().get(
            config.NOSECTION, "disable-presets"))

        preset = None
        prog_type = None
        combo = self.tool_bar_box.preset_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            if disable_presets:
                preset = None
            else:
                preset = model[tree_iter][self.PresetComboModelColumn.PRESET]
            prog_type = model[tree_iter][self.PresetComboModelColumn.PROG_TYPE]

        categories = None
        exclude_categories = None
        combo = self.tool_bar_box.category_combo
        if not search_all or combo.get_active() > 0:
            # A specific set of categories has been selected
            tree_iter = combo.get_active_iter()
            if tree_iter is not None:
                model = combo.get_model()
                #WORKAROUND see also get_iplayer.py (at least in Python 2.7)
                #    On some systems, when model[tree_iter][KEY_INDEX] == None, the following exception is raised:
                #    AttributeError: 'NoneType' object has no attribute 'decode'
                #    In the debugger, model[tree_iter][KEY_INDEX] is displayed as a unicode string.
                categories = model[tree_iter][KEY_INDEX]
                (categories, exclude_categories
                 ) = _separate_excluded_categories(categories)

        channels = None
        exclude_channels = None
        combo = self.tool_bar_box.channel_combo
        if not search_all or combo.get_active() > 0:
            # A specific set of channels has been selected
            tree_iter = combo.get_active_iter()
            if tree_iter is not None:
                model = combo.get_model()
                channels = model[tree_iter][KEY_INDEX]
                #ALTERNATIVE
                #channels = model.get_value(tree_iter, KEY_INDEX)
                (channels,
                 exclude_channels) = _separate_excluded_channels(channels)

        since = 0
        combo = self.tool_bar_box.since_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            since = model[tree_iter][KEY_INDEX]

        future = self.tool_bar_box.future_check_button.get_active()

        self.main_window.display_busy_mouse_cursor(True)
        if self._check_first_time_find(prog_type):
            get_iplayer.refresh(preset=preset,
                                prog_type=prog_type,
                                channels=channels,
                                exclude_channels=exclude_channels,
                                future=future)
        output_lines = get_iplayer.search(
            search_text,
            preset=preset,
            prog_type=prog_type,
            channels=channels,
            exclude_channels=exclude_channels,
            categories=categories,
            exclude_categories=exclude_categories,
            since=since,
            future=future)
        self.main_window.display_busy_mouse_cursor(False)

        self.on_progress_bar_update(None)

        self.main_tree_view.set_store(output_lines)
        # Scroll to top
        adjustment = self.main_window.main_tree_view_scrollbars.get_vadjustment(
        )
        adjustment.set_value(0.0)
        adjustment.value_changed()
        #adjustment = self.main_window.main_tree_view_scrollbars.set_vadjustment(adjustment)

        #if disable_presets:
        #    prog_type = None
        self.main_window.set_window_title(prog_type=prog_type)

        # Invalidate downloaded PID list
        self.downloaded_pid_list = []

        # Disable filters when there are cached search results available
        self._set_filters_sensitive(prog_type)
    def on_button_find_clicked(self, button):
        # button can be None
        search_text = self.tool_bar_box.search_entry.get_text()
        search_all = self.tool_bar_box.search_all_check_button.get_active()
        disable_presets = string.str2bool(settings.get_config().get(config.NOSECTION, "disable-presets"))
        
        preset = None
        prog_type = None
        combo = self.tool_bar_box.preset_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            if disable_presets:
                preset = None
            else:
                preset = model[tree_iter][self.PresetComboModelColumn.PRESET]
            prog_type = model[tree_iter][self.PresetComboModelColumn.PROG_TYPE]

        categories = None
        exclude_categories = None
        combo = self.tool_bar_box.category_combo
        if not search_all or combo.get_active() > 0:
            # A specific set of categories has been selected
            tree_iter = combo.get_active_iter()
            if tree_iter is not None:
                model = combo.get_model()
                #WORKAROUND see also get_iplayer.py (at least in Python 2.7)
                #    On some systems, when model[tree_iter][KEY_INDEX] == None, the following exception is raised:
                #    AttributeError: 'NoneType' object has no attribute 'decode'
                #    In the debugger, model[tree_iter][KEY_INDEX] is displayed as a unicode string.
                categories = model[tree_iter][KEY_INDEX]
                (categories, exclude_categories) = _separate_excluded_categories(categories)
                
        channels = None
        exclude_channels = None
        combo = self.tool_bar_box.channel_combo
        if not search_all or combo.get_active() > 0:
            # A specific set of channels has been selected
            tree_iter = combo.get_active_iter()
            if tree_iter is not None:
                model = combo.get_model()
                channels = model[tree_iter][KEY_INDEX]
                #ALTERNATIVE
                #channels = model.get_value(tree_iter, KEY_INDEX)
                (channels, exclude_channels) = _separate_excluded_channels(channels)

        since = 0
        combo = self.tool_bar_box.since_combo
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = combo.get_model()
            since = model[tree_iter][KEY_INDEX]

        future = self.tool_bar_box.future_check_button.get_active()

        self.main_window.display_busy_mouse_cursor(True)
        if self._check_first_time_find(prog_type):
            get_iplayer.refresh(preset=preset, prog_type=prog_type, channels=channels, exclude_channels=exclude_channels, future=future)
        output_lines = get_iplayer.search(search_text, preset=preset, prog_type=prog_type,
                                          channels=channels, exclude_channels=exclude_channels,
                                          categories=categories, exclude_categories=exclude_categories,
                                          since=since, future=future)
        self.main_window.display_busy_mouse_cursor(False)

        self.on_progress_bar_update(None)

        self.main_tree_view.set_store(output_lines)
        # Scroll to top
        adjustment = self.main_window.main_tree_view_scrollbars.get_vadjustment()
        adjustment.set_value(0.0)
        adjustment.value_changed()
        #adjustment = self.main_window.main_tree_view_scrollbars.set_vadjustment(adjustment)

        #if disable_presets:
        #    prog_type = None
        self.main_window.set_window_title(prog_type=prog_type)

        # Invalidate downloaded PID list
        self.downloaded_pid_list = []
        
        # Disable filters when there are cached search results available
        self._set_filters_sensitive(prog_type)