<commit_before># -*- coding: utf-8 -*-

import totem
import gobject
import gtk
import iplayer2
import threading

class IplayerPlugin (totem.Plugin):
	def __init__ (self):
		totem.Plugin.__init__ (self)
		self.debug = False
		self.totem = None
		self.programme_download_lock = threading.Lock ()

	def activate (self, totem_object):
		# Build the interface
		builder = self.load_interface ("iplayer.ui", True, totem_object.get_main_window (), self)
		container = builder.get_object ('iplayer_vbox')

		self.tv_tree_store = builder.get_object ('iplayer_programme_store')
		programme_list = builder.get_object ('iplayer_programme_list')
		programme_list.connect ('row-expanded', self._row_expanded_cb)
		programme_list.connect ('row-activated', self._row_activated_cb)

		self.totem = totem_object
		container.show_all ()

		self.tv = iplayer2.feed ('tv')

		# Add the interface to Totem's sidebar
		self.totem.add_sidebar_page ("iplayer", _("BBC iPlayer"), container)

		# Get the channel category listings
		self.populate_channel_list (self.tv, self.tv_tree_store)

	def deactivate (self, totem_object):
		totem_object.remove_sidebar_page ("iplayer")

	def populate_channel_list (self, feed, tree_store):
		if self.debug:
			print "Populating channel list…"

		# Add all the channels as top-level rows in the tree store
		channels = feed.channels ()
		for channel_id, title in channels.items ():
			parent_iter = tree_store.append (None, [title, channel_id, None])

		# Add the channels' categories in a thread, since they each require a network request
		parent_path = tree_store.get_path (parent_iter)
		thread = PopulateChannelsThread (self, parent_path, feed, tree_store)
		thread.start ()

	def _populate_channel_list_cb (self, tree_store, parent_path, values):
		# Callback from PopulateChannelsThread to add stuff to the tree store
		if values == None:
			self.totem.action_error (_('Error Listing Channel Categories'), _('There was an unknown error getting the list of television channels available on BBC iPlayer.'))
			return False

		parent_iter = tree_store.get_iter (parent_path)
		category_iter = tree_store.append (parent_iter, values)

		# Append a dummy child row so that the expander's visible; we can
		# then queue off the expander to load the programme listing for this category
		tree_store.append (category_iter, [_('Loading…'), None, None])

		return False

	def _row_expanded_cb (self, tree_view, row_iter, path):
		tree_model = tree_view.get_model ()

		if self.debug:
			print "_row_expanded_cb called."

		# We only care about the category level (level 1), and only when
		# it has the "Loading..." placeholder child row
		if get_iter_level (tree_model, row_iter) != 1 or tree_model.iter_n_children (row_iter) != 1:
			return

		# Populate it with programmes asynchronously
		self.populate_programme_list (self.tv, tree_model, row_iter)

	def _row_activated_cb (self, tree_view, path, view_column):
		tree_store = tree_view.get_model ()
		tree_iter = tree_store.get_iter (path)
		mrl = tree_store.get_value (tree_iter, 2)

		# Only allow programme rows to be activated, not channel or category rows
		if mrl == None:
			return

		# Add the programme to the playlist and play it
		self.totem.add_to_playlist_and_play (mrl, tree_store.get_value (tree_iter, 0), True)

	def populate_programme_list (self, feed, tree_store, category_iter):
		if self.debug:
			print "Populating programme list…"

		category_path = tree_store.get_path (category_iter)
		thread = PopulateProgrammesThread (self, feed, tree_store, category_path)
		thread.start ()

	def _populate_programme_list_cb (self, tree_store, category_path, values, remove_placeholder):
		# Callback from PopulateProgrammesThread to add stuff to the tree store
		if values == None:
			self.totem.action_error (_('Error getting programme feed'), _('There was an unknown error getting the list of programmes for this channel and category combination.'))
			return False

		category_iter = tree_store.get_iter (category_path)

		tree_store.append (category_iter, values)

		# Remove the placeholder row
		if remove_placeholder:
			tree_store.remove (tree_store.iter_children (category_iter))

		return False

def get_iter_level (tree_model, tree_iter):
	i = -1;
	while (tree_iter != None):
		tree_iter = tree_model.iter_parent (tree_iter)
		i += 1
	return i<commit_msg>Fix some strings in the BBC iPlayer plugin<commit_after># -*- coding: utf-8 -*-

import totem
import gobject
import gtk
import iplayer2
import threading

class IplayerPlugin (totem.Plugin):
	def __init__ (self):
		totem.Plugin.__init__ (self)
		self.debug = False
		self.totem = None
		self.programme_download_lock = threading.Lock ()

	def activate (self, totem_object):
		# Build the interface
		builder = self.load_interface ("iplayer.ui", True, totem_object.get_main_window (), self)
		container = builder.get_object ('iplayer_vbox')

		self.tv_tree_store = builder.get_object ('iplayer_programme_store')
		programme_list = builder.get_object ('iplayer_programme_list')
		programme_list.connect ('row-expanded', self._row_expanded_cb)
		programme_list.connect ('row-activated', self._row_activated_cb)

		self.totem = totem_object
		container.show_all ()

		self.tv = iplayer2.feed ('tv')

		# Add the interface to Totem's sidebar
		self.totem.add_sidebar_page ("iplayer", _("BBC iPlayer"), container)

		# Get the channel category listings
		self.populate_channel_list (self.tv, self.tv_tree_store)

	def deactivate (self, totem_object):
		totem_object.remove_sidebar_page ("iplayer")

	def populate_channel_list (self, feed, tree_store):
		if self.debug:
			print "Populating channel list…"

		# Add all the channels as top-level rows in the tree store
		channels = feed.channels ()
		for channel_id, title in channels.items ():
			parent_iter = tree_store.append (None, [title, channel_id, None])

		# Add the channels' categories in a thread, since they each require a network request
		parent_path = tree_store.get_path (parent_iter)
		thread = PopulateChannelsThread (self, parent_path, feed, tree_store)
		thread.start ()

	def _populate_channel_list_cb (self, tree_store, parent_path, values):
		# Callback from PopulateChannelsThread to add stuff to the tree store
		if values == None:
			self.totem.action_error (_('Error listing channel categories'), _('There was an unknown error getting the list of television channels available on BBC iPlayer.'))
			return False

		parent_iter = tree_store.get_iter (parent_path)
		category_iter = tree_store.append (parent_iter, values)

		# Append a dummy child row so that the expander's visible; we can
		# then queue off the expander to load the programme listing for this category
		tree_store.append (category_iter, [_('Loading…'), None, None])

		return False

	def _row_expanded_cb (self, tree_view, row_iter, path):
		tree_model = tree_view.get_model ()

		if self.debug:
			print "_row_expanded_cb called."

		# We only care about the category level (level 1), and only when
		# it has the "Loading..." placeholder child row
		if get_iter_level (tree_model, row_iter) != 1 or tree_model.iter_n_children (row_iter) != 1:
			return

		# Populate it with programmes asynchronously
		self.populate_programme_list (self.tv, tree_model, row_iter)

	def _row_activated_cb (self, tree_view, path, view_column):
		tree_store = tree_view.get_model ()
		tree_iter = tree_store.get_iter (path)
		mrl = tree_store.get_value (tree_iter, 2)

		# Only allow programme rows to be activated, not channel or category rows
		if mrl == None:
			return

		# Add the programme to the playlist and play it
		self.totem.add_to_playlist_and_play (mrl, tree_store.get_value (tree_iter, 0), True)

	def populate_programme_list (self, feed, tree_store, category_iter):
		if self.debug:
			print "Populating programme list…"

		category_path = tree_store.get_path (category_iter)
		thread = PopulateProgrammesThread (self, feed, tree_store, category_path)
		thread.start ()

	def _populate_programme_list_cb (self, tree_store, category_path, values, remove_placeholder):
		# Callback from PopulateProgrammesThread to add stuff to the tree store
		if values == None:
			self.totem.action_error (_('Error getting programme feed'), _('There was an error getting the list of programmes for this channel and category combination.'))
			return False

		category_iter = tree_store.get_iter (category_path)

		tree_store.append (category_iter, values)

		# Remove the placeholder row
		if remove_placeholder:
			tree_store.remove (tree_store.iter_children (category_iter))

		return False

def get_iter_level (tree_model, tree_iter):
	i = -1;
	while (tree_iter != None):
		tree_iter = tree_model.iter_parent (tree_iter)
		i += 1
	return i
{'fraction_non_alphanumeric': 0.08822515795519816, 'fraction_numerical': 0.0022975301550832855, 'mean_word_length': 4.769383697813121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '753327', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2709, 'n_words': 845}