<commit_before>from model import *
import gtk

import help_box
from dialog import Dialog
from policy import policy
from impl_list import ImplementationList
import writer

_dialogs = {}	# Interface -> Properties

def enumerate(items):
	x = 0
	for i in items:
		yield x, i
		x += 1

class Properties(Dialog):
	interface = None
	use_list = None

	def __init__(self, interface):
		Dialog.__init__(self)
		self.interface = interface
		self.set_title('Interface ' + interface.get_name())
		self.set_default_size(gtk.gdk.screen_width() / 2,
				      gtk.gdk.screen_height() / 3)

		vbox = gtk.VBox(False, 4)
		vbox.set_border_width(4)
		self.vbox.pack_start(vbox, True, True, 0)

		self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
		self.add_button(gtk.STOCK_REFRESH, 1)
		self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
		self.set_default_response(gtk.RESPONSE_CANCEL)

		label = gtk.Label('%s: %s' % (interface.get_name(),
						interface.summary))
		vbox.pack_start(label, False, True, 0)

		vbox.pack_start(gtk.Label('(%s)' % interface.uri),
					False, True, 0)

		def response(dialog, resp):
			if resp == gtk.RESPONSE_CANCEL:
				self.destroy()
			elif resp == 1:
				import reader
				reader.update_from_network(interface)
				policy.recalculate()
			elif resp == gtk.RESPONSE_HELP:
				properties_help.display()
		self.connect('response', response)

		frame = gtk.Frame()
		frame.set_shadow_type(gtk.SHADOW_IN)
		vbox.pack_start(frame, False, True, 0)
		if interface.uptodate:
			description = gtk.Label(interface.description or "-")
		else:
			description = gtk.Label("Information about this interface has not "
						"yet been downloaded.")
		description.set_line_wrap(True)
		frame.add(description)

		self.use_list = ImplementationList(interface)
		vbox.pack_start(self.use_list, True, True, 0)
		self.use_list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)

		hbox = gtk.HBox(False, 2)
		vbox.pack_start(hbox, False, True, 0)

		stability = gtk.combo_box_new_text()
		stability.append_text('Use default setting')
		stability.set_active(0)
		for i, x in enumerate((stable, testing, developer)):
			stability.append_text(str(x).capitalize())
			if x is interface.stability_policy:
				stability.set_active(i + 1)
		hbox.pack_start(gtk.Label('Preferred stability:'), False, True, 0)
		hbox.pack_start(stability, False, True, 0)
		def set_stability_policy(combo):<commit_msg>Better description layout.<commit_after>from model import *
import gtk

import help_box
from dialog import Dialog
from policy import policy
from impl_list import ImplementationList
import writer

_dialogs = {}	# Interface -> Properties

def enumerate(items):
	x = 0
	for i in items:
		yield x, i
		x += 1

class Properties(Dialog):
	interface = None
	use_list = None

	def __init__(self, interface):
		Dialog.__init__(self)
		self.interface = interface
		self.set_title('Interface ' + interface.get_name())
		self.set_default_size(gtk.gdk.screen_width() / 2,
				      gtk.gdk.screen_height() / 3)

		vbox = gtk.VBox(False, 4)
		vbox.set_border_width(4)
		self.vbox.pack_start(vbox, True, True, 0)

		self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
		self.add_button(gtk.STOCK_REFRESH, 1)
		self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
		self.set_default_response(gtk.RESPONSE_CANCEL)

		def response(dialog, resp):
			if resp == gtk.RESPONSE_CANCEL:
				self.destroy()
			elif resp == 1:
				import reader
				reader.update_from_network(interface)
				policy.recalculate()
			elif resp == gtk.RESPONSE_HELP:
				properties_help.display()
		self.connect('response', response)

		swin = gtk.ScrolledWindow(None, None)
		swin.set_shadow_type(gtk.SHADOW_IN)
		swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
		vbox.pack_start(swin, False, True, 0)
		description = gtk.TextView()
		description.set_left_margin(4)
		description.set_right_margin(4)
		description.set_wrap_mode(gtk.WRAP_WORD)
		description.set_editable(False)
		description.set_cursor_visible(False)
		swin.add(description)

		buffer = description.get_buffer()
		heading_style = buffer.create_tag(underline = True, scale = 1.2)
		iter = buffer.get_start_iter()
		buffer.insert_with_tags(iter,
			'%s (%s)' % (interface.get_name(), interface.summary), heading_style)

		buffer.insert(iter, '\nFull name: %s\n\n' % interface.uri)

		buffer.insert_with_tags(iter, 'Description\n', heading_style)

		description.set_size_request(-1, 100)

		if interface.uptodate:
			buffer.insert(iter, interface.description or "-")
		else:
			buffer.insert(iter, "Information about this interface has not "
						"yet been downloaded.")

		self.use_list = ImplementationList(interface)
		vbox.pack_start(self.use_list, True, True, 0)
		self.use_list.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)

		hbox = gtk.HBox(False, 2)
		vbox.pack_start(hbox, False, True, 0)

		stability = gtk.combo_box_new_text()
		stability.append_text('Use default setting')
		stability.set_active(0)
		for i, x in enumerate((stable, testing, developer)):
			stability.append_text(str(x).capitalize())
			if x is interface.stability_policy:
				stability.set_active(i + 1)
		hbox.pack_start(gtk.Label('Preferred stability:'), False, True, 0)
		hbox.pack_start(stability, False, True, 0)
		def set_stability_policy(combo):
{'fraction_non_alphanumeric': 0.11810574362875619, 'fraction_numerical': 0.008368200836820083, 'mean_word_length': 4.5946808510638295, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4758208', 'n_tokens_mistral': 2169, 'n_tokens_neox': 1887, 'n_words': 371}