All pastes #540189 Raw Edit

Mine

public python v1 · immutable
·published 2007-06-05 14:43 UTC
rendered paste body
#! /usr/bin/env python# coding=utf-8import pygtkpygtk.require('2.0')import gtkfrom math import piwindow = gtk.Window()#window.set_border_width(10)hbox = gtk.HBox(False,0)stage = 1types = {"Areal":	{"Kvadrat": ("%s**2", ["Sidelængde"]),			"Rektangel": ("%s*%s", ["Højde", "Bredde"]),			"Cirkel": ("%s**2*pi", ["Radius"])},	"Rumfang":	{"Kasse": ("%s*%s*%s", ["Højde", "Bredde", "Dybde"])},	"Overfladeareal":	{"Kube": ("%s**2*6", ["Sidelængde"]),				"Kasse": ("%s*(%s*4+%s*2)", ["Højde", "Bredde", "Dybde"])}}def close(widget, data=None):	gtk.quit_main()def stageone():	global stage	box = gtk.VBox(False, 2)	for i in types:		button = gtk.Button(i)		button.connect("clicked", stagetwo, i)		box.pack_start(button,True,False,2)		button.show()	hbox.pack_start(box,True,True,2)	box.show()	separator = gtk.VSeparator()	hbox.pack_start(separator,True,True,2)	separator.show()	stage = 2def stagetwo(widget, kind):	global stage	if stage == 2:		stage = 3		box2 = gtk.VBox(False,2)		for i in types[kind]:			button2 = gtk.Button(i)			button2.connect("clicked", stagethree, i, kind)			box2.pack_start(button2,True,False,2)			button2.show()		hbox.pack_start(box2,True,True,2)		box2.show()	else:		passdef stagethree(widget, kind, old):	global stage	if stage == 3:		stage = 1		entries = []		box3 = gtk.VBox(False,2)		for i in types[old][kind][1]:			label = gtk.Label(i)			box3.pack_start(label,True,False,2)			i = gtk.Entry(0)			box3.pack_start(i,True,False,2)			label.show()			i.show()			entries.append(i)		bbox = gtk.HBox(False,2)				button = gtk.Button("Calculate")		button.connect("clicked", calc, entries, types[old][kind][0])		button.connect_object("clicked", gtk.Widget.destroy, window)		bbox.pack_start(button, True, False, 2)		button.show()		quit = gtk.Button("Quit")		quit.connect_object("clicked", gtk.Widget.destroy, window)		bbox.pack_start(quit, True, False, 2)		quit.show()		box3.pack_start(bbox, True, False, 2)		hbox.pack_start(box3,True,True,2)		box3.show()		bbox.show()	else:		passdef calc(widget, entries, form):	window2 = gtk.Window()	window2.set_border_width(15)	vbox = gtk.VBox(False,2)	ent = []	for l in entries:		c = l.get_text()		ent.append(c)	a = eval(form % tuple(ent))	ligning = gtk.Label(str(form % tuple(ent))+" =")	label = gtk.Label(str(a))	vbox.pack_start(ligning, True, False, 2)	vbox.pack_start(label, True, False, 2)	ligning.show()	label.show()	window2.add(vbox)	vbox.show()	window2.show()stageone()window.add(hbox)hbox.show()window.show_all()gtk.main()