#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk
flos = [
"dividuum",
"syb",
"fiji",
"flowhase",
"florolf",
"piratenflo"
]
class WirSindDieFlo:
flobutts = []
def format_roman(self, case, counter):
ones = ['i', 'x', 'c', 'm']
fives = ['v', 'l', 'd']
label, index = '', 0
# This will die of IndexError when counter is too big
while counter > 0:
counter, x = divmod(counter, 10)
if x == 9:
label = ones[index] + ones[index+1] + label
elif x == 4:
label = ones[index] + fives[index] + label
else:
if x >= 5:
s = fives[index]
x = x-5
else:
s = ''
s = s + ones[index]*x
label = s + label
index = index + 1
if case == 'I':
return label.upper()
return label
def floberechnungscallback(self, widget, data=None):
i = 0
flozaehlung = 0
for flobutt in self.flobutts:
if flobutt.get_active():
flozaehlung += pow(2, i)
i += 1
diaflog = gtk.Dialog("Wir sind die Flo!",
None,
gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
flolabel = gtk.Label("Wir sind die FLO"
+ self.format_roman("I", flozaehlung)
+ ".")
flolabel.show()
diaflog.vbox.pack_start(flolabel)
diaflog.show()
diaflog.run()
diaflog.destroy()
def delete_event(self, widget, data=None):
gtk.main_quit()
return False
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Wir sind die Flo?")
self.window.set_border_width(20)
self.window.connect("delete_event", self.delete_event)
vbox = gtk.VBox(True, 2)
self.window.add(vbox)
for flo in flos:
cbut = gtk.CheckButton(flo)
vbox.pack_start(cbut)
cbut.show()
self.flobutts.append(cbut)
but = gtk.Button("Wir sind die Flo?")
but.connect("clicked", self.floberechnungscallback,)
vbox.pack_start(but)
but.show()
vbox.show()
self.window.show()
def main():
gtk.main()
return 0
if __name__ == "__main__":
WirSindDieFlo()
main()
Bewertung
- Zeilenzahl (100-x) relativ Referenzimplementierung: 100-100 = 0
- Bonus (10) kein Overflo: 10
- Bonus (100) Foto/Icon-Auswahl der Flos : 0
- Bonus (100) Feature Rückberechnung (aus römischer Notierung): 0
- Faktor Anzahl Programmiersprachen: *1 = 10