class TransitionTab(gtk.VBox):
	def __init__(self, window):
		gtk.VBox.__init__(self)
		self.hmm = None
		clear_button = gtk.Button('Reset')
		clear_button.set_size_request(80,25)
		clear_button.connect('clicked', self.on_reset_clicked)
		apply_button = gtk.Button('Apply')
		apply_button.set_size_request(80,20)
		apply_button.connect('clicked', self.on_apply_clicked, window)

		hbox = gtk.HBox();
		hbox.set_size_request(200, 40);
		hbox.pack_start(clear_button, fill=False, padding=4);
		hbox.pack_start(apply_button, fill=False, padding=4);

		self.viewport = gtk.Viewport()
		sw = gtk.ScrolledWindow()
		sw.add(self.viewport)
		sw.set_size_request(400, 400)
		sw.set_policy(hscrollbar_policy=gtk.POLICY_AUTOMATIC, vscrollbar_policy=gtk.POLICY_AUTOMATIC)

		self.pack_start(sw)
		self.pack_end(hbox, fill=False)

		self.table = None

	def on_reset_clicked(self, sender):
		if self.hmm:
			self.on_hmm_changed(sender=self, hmm=self.hmm)

	def on_apply_clicked(self, sender, window):
		if self.table:
			window.on_transition_values_updated(self.table)

	def on_hmm_changed(self, sender, hmm):
		self.hmm = hmm
		if self.table:
			self.table.destroy()
		self.table = ValueTable(rows=len(hmm.states),
		                        columns=len(hmm.states),
		                        cell_width=6,
		                        row_captions=hmm.states,
		                        col_captions=hmm.states,
		                        top_left_caption= "old/new state")
		for i in xrange(hmm.get_num_states()):
			for j in xrange(hmm.get_num_states()):
				self.table[i, j] = str(hmm.get_transition_prob(i, j))
		self.viewport.add(self.table)
		self.table.show_all()
	def on_hmm_changed(self, sender, hmm):
		self.hmm = hmm
		if self.table:
			self.table.destroy()
		self.table = ValueTable(rows=1,
		                        columns=len(hmm.states),
		                        cell_width=6,
		                        row_captions=['probability'],
		                        col_captions=hmm.states,
		                        top_left_caption= 'initial')
		for i in xrange(hmm.get_num_states()):
			self.table[0, i] = str(hmm.initial_p(i))
		self.viewport.add(self.table)
		self.table.show_all()
	def on_hmm_changed(self, sender, hmm):
		self.hmm = hmm
		if self.table:
			self.table.destroy()
		self.table = ValueTable(rows=len(hmm.states),
		                        columns=len(hmm.states),
		                        cell_width=6,
		                        row_captions=hmm.states,
		                        col_captions=hmm.states,
		                        top_left_caption= "old/new state")
		for i in xrange(hmm.get_num_states()):
			for j in xrange(hmm.get_num_states()):
				self.table[i, j] = str(hmm.get_transition_prob(i, j))
		self.viewport.add(self.table)
		self.table.show_all()