class gStorytellerWindow(): __doc__ = """ This class builds the GTK interface for gStoryTeller """ def __init__(self): # creating a storyteller obect self.storyteller = StoryTeller() self.story = self.storyteller.random_future() # Window (it's singular and it's not the OS) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("Storyteller") self.window.set_border_width(0) self.window.set_size_request(500, 200) self.window.set_position(gtk.WIN_POS_CENTER) # main box self.wrapper = gtk.VButtonBox() self.text = gtk.Label(self.story) # it breaks lines if text exceeds the widget's size self.text.set_line_wrap(True) self.wrapper.pack_start(self.text, expand=True, fill=True) # What about buttons? self.buttons = gtk.HBox() self.bclose = gtk.Button(stock = gtk.STOCK_CLOSE) self.buttons.pack_end(self.bclose, expand=False,fill=False) self.bnext = gtk.Button(stock = gtk.STOCK_MEDIA_NEXT) self.buttons.pack_end(self.bnext, expand=False, fill=False) self.wrapper.add(self.buttons) # adding widgets to window self.window.add(self.wrapper) # connecting signals self.window.connect("destroy", gtk.main_quit) self.bnext.connect("clicked", self.get_story) self.bclose.connect("clicked", gtk.main_quit) # showing every little thing ;D self.window.show_all() def run(self): gtk.main() def get_story(self, widget): self.text.set_label(self.storyteller.random_future())
from storyteller import StoryTeller # As everybody knows, Rafael is a great storyteller rafael = StoryTeller() # Hey Rafael, could you tell us a fable? print "%s\n" % rafael.random_fable() # How "cult" are you? Could you tell us a love tragedy? print "%s\n" % rafael.random_love_tragedy() # What about a Nostradamus-like story? print "%s\n" % rafael.random_future()