<commit_before># Copyright (C) 2009, <NAME>
# See the README file for details, or visit http://0install.net.

import gtk
from dialog import Template
from zeroinstall.gtkui import help_box
from zeroinstall.injector.model import network_levels
from zeroinstall.injector import trust, gpg
from freshness import freshness_levels, Freshness
from sets import Set

tips = gtk.Tooltips()

SHOW_CACHE = 0

network_names = {
	'off-line': _('Off-line'),
	'minimal': _('Minimal'),
	'full': _('Full'),
}

class Preferences:
	def __init__(self, policy):
		widgets = Template('preferences_box')

		self.window = widgets.get_widget('preferences_box')
		self.window.connect('destroy', lambda w: self.destroyed())

		network = widgets.get_widget('network_use')
		for level in network_levels:
			network.append_text(network_names.get(level, level.capitalize()))
		network.set_active(list(network_levels).index(policy.network_use))

		def set_network_use(combo):
			policy.network_use = network_levels[network.get_active()]
			policy.save_config()
			policy.solve_with_downloads()
		network.connect('changed', set_network_use)

		# Freshness
		times = [x.time for x in freshness_levels]
		if policy.freshness not in times:
			freshness_levels.append(Freshness(policy.freshness,
							  '%d seconds' % policy.freshness))
			times.append(policy.freshness)
		eb = gtk.EventBox()	# For the tooltip
		freshness = widgets.get_widget('freshness')
		for level in freshness_levels:
			freshness.append_text(str(level))
		freshness.set_active(times.index(policy.freshness))
		def set_freshness(combo):
			policy.freshness = freshness_levels[freshness.get_active()].time
			policy.save_config()
			policy.recalculate()
		freshness.connect('changed', set_freshness)

		stable_toggle = widgets.get_widget('help_test')
		stable_toggle.set_active(policy.help_with_testing)
		def toggle_stability(toggle):
			policy.help_with_testing = toggle.get_active()
			policy.save_config()
			policy.recalculate()
		stable_toggle.connect('toggled', toggle_stability)

		# Keys
		keys_view = widgets.get_widget('trusted_keys')
		KeyList(keys_view)

		# Responses
		self.window.set_default_response(gtk.RESPONSE_CLOSE)
		self.window.default_widget.grab_focus()

		def response(dialog, resp):
			if resp in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT):
				self.window.destroy()
			elif resp == gtk.RESPONSE_HELP:
				gui_help.display()
		self.window.connect('response', response)

		self.window.set_default_size(-1, gtk.gdk.screen_height() / 3)

	def destroyed(self):
		global preferences_box
		preferences_box = None

class KeyList:
	def __init__(self, tv):
		self.trusted_keys = gtk.TreeStore(str, object)
		tv.set_model(self.trusted_keys)
		tc = gtk.TreeViewColumn(_('Trusted keys'), gtk.CellRendererText(), text = 0)
		tv.append_column(tc)
		trust.trust_db.ensure_uptodate()

		def update_keys():
			# Remember which ones are open
			expanded_elements = set()
			def add_row(tv, path):
				if len(path) == 1:
					domain = self.trusted_keys[path][0]
					expanded_elements.add(domain)
			tv.map_expanded_rows(add_row)

			self.trusted_keys.clear()
			domains = {}

			keys = gpg.load_keys(trust.trust_db.keys.keys())

			for fingerprint in keys:
				for domain in trust.trust_db.keys[fingerprint]:
					if domain not in domains:
						domains[domain] = Set()
					domains[domain].add(keys[fingerprint])
			for domain in domains:
				iter = self.trusted_keys.append(None, [domain, None])
				for key in domains[domain]:
					self.trusted_keys.append(iter, [key.name, key])

			def may_expand(model, path, iter):
				if len(path) == 1:
					if model[iter][0] in expanded_elements:
						tv.expand_row(path, False)
			self.trusted_keys.foreach(may_expand)

		trust.trust_db.watchers.append(update_keys)
		tv.connect('destroy', lambda w: trust.trust_db.watchers.remove(update_keys))

		update_keys()

		def remove_key(fingerprint, domain):
			trust.trust_db.untrust_key(fingerprint, domain)
			trust.trust_db.notify()

		def trusted_keys_button_press(tv, bev):
			if bev.type == gtk.gdk.BUTTON_PRESS and bev.button == 3:
				pos = tv.get_path_at_pos(int(bev.x), int(bev.y))<commit_msg>Fix Python 2.6 deprecation warning<commit_after># Copyright (C) 2009, <NAME>
# See the README file for details, or visit http://0install.net.

import gtk
from dialog import Template
from zeroinstall.gtkui import help_box
from zeroinstall.injector.model import network_levels
from zeroinstall.injector import trust, gpg
from freshness import freshness_levels, Freshness

tips = gtk.Tooltips()

SHOW_CACHE = 0

network_names = {
	'off-line': _('Off-line'),
	'minimal': _('Minimal'),
	'full': _('Full'),
}

class Preferences:
	def __init__(self, policy):
		widgets = Template('preferences_box')

		self.window = widgets.get_widget('preferences_box')
		self.window.connect('destroy', lambda w: self.destroyed())

		network = widgets.get_widget('network_use')
		for level in network_levels:
			network.append_text(network_names.get(level, level.capitalize()))
		network.set_active(list(network_levels).index(policy.network_use))

		def set_network_use(combo):
			policy.network_use = network_levels[network.get_active()]
			policy.save_config()
			policy.solve_with_downloads()
		network.connect('changed', set_network_use)

		# Freshness
		times = [x.time for x in freshness_levels]
		if policy.freshness not in times:
			freshness_levels.append(Freshness(policy.freshness,
							  '%d seconds' % policy.freshness))
			times.append(policy.freshness)
		eb = gtk.EventBox()	# For the tooltip
		freshness = widgets.get_widget('freshness')
		for level in freshness_levels:
			freshness.append_text(str(level))
		freshness.set_active(times.index(policy.freshness))
		def set_freshness(combo):
			policy.freshness = freshness_levels[freshness.get_active()].time
			policy.save_config()
			policy.recalculate()
		freshness.connect('changed', set_freshness)

		stable_toggle = widgets.get_widget('help_test')
		stable_toggle.set_active(policy.help_with_testing)
		def toggle_stability(toggle):
			policy.help_with_testing = toggle.get_active()
			policy.save_config()
			policy.recalculate()
		stable_toggle.connect('toggled', toggle_stability)

		# Keys
		keys_view = widgets.get_widget('trusted_keys')
		KeyList(keys_view)

		# Responses
		self.window.set_default_response(gtk.RESPONSE_CLOSE)
		self.window.default_widget.grab_focus()

		def response(dialog, resp):
			if resp in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT):
				self.window.destroy()
			elif resp == gtk.RESPONSE_HELP:
				gui_help.display()
		self.window.connect('response', response)

		self.window.set_default_size(-1, gtk.gdk.screen_height() / 3)

	def destroyed(self):
		global preferences_box
		preferences_box = None

class KeyList:
	def __init__(self, tv):
		self.trusted_keys = gtk.TreeStore(str, object)
		tv.set_model(self.trusted_keys)
		tc = gtk.TreeViewColumn(_('Trusted keys'), gtk.CellRendererText(), text = 0)
		tv.append_column(tc)
		trust.trust_db.ensure_uptodate()

		def update_keys():
			# Remember which ones are open
			expanded_elements = set()
			def add_row(tv, path):
				if len(path) == 1:
					domain = self.trusted_keys[path][0]
					expanded_elements.add(domain)
			tv.map_expanded_rows(add_row)

			self.trusted_keys.clear()
			domains = {}

			keys = gpg.load_keys(trust.trust_db.keys.keys())

			for fingerprint in keys:
				for domain in trust.trust_db.keys[fingerprint]:
					if domain not in domains:
						domains[domain] = set()
					domains[domain].add(keys[fingerprint])
			for domain in domains:
				iter = self.trusted_keys.append(None, [domain, None])
				for key in domains[domain]:
					self.trusted_keys.append(iter, [key.name, key])

			def may_expand(model, path, iter):
				if len(path) == 1:
					if model[iter][0] in expanded_elements:
						tv.expand_row(path, False)
			self.trusted_keys.foreach(may_expand)

		trust.trust_db.watchers.append(update_keys)
		tv.connect('destroy', lambda w: trust.trust_db.watchers.remove(update_keys))

		update_keys()

		def remove_key(fingerprint, domain):
			trust.trust_db.untrust_key(fingerprint, domain)
			trust.trust_db.notify()

		def trusted_keys_button_press(tv, bev):
			if bev.type == gtk.gdk.BUTTON_PRESS and bev.button == 3:
				pos = tv.get_path_at_pos(int(bev.x), int(bev.y))
{'fraction_non_alphanumeric': 0.1196570876599855, 'fraction_numerical': 0.003622313450857281, 'mean_word_length': 4.728215767634855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5700558', 'n_tokens_mistral': 3327, 'n_tokens_neox': 2834, 'n_words': 543}