Exemplo n.º 1
0
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())
Exemplo n.º 2
0
 def __init__(self):
     self.storyTeller = StoryTeller("dragon_encounter.xml")
     self.player = Player()
     self.storyTeller.about_story()
     end_happened = False
     while not end_happened:
         dialog = self.storyTeller.ask_question()
         end_happened = dialog.end_happened
         number = self.player.answer(dialog)
         print("===========")
         print(dialog.question)
         if len(dialog.answers) > 0:
             print(dialog.answers[number-1])
         print("===========")
         if not end_happened:
             reward = self.storyTeller.get_answer(number)
             self.player.get_reward(reward)
     print(self.storyTeller.end())
Exemplo n.º 3
0
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()

 def setUp(self):
     self.setUpStoryFiles()
     self.story = StoryTeller()
     self.story.setAudioDir(TESTDIR)
     self.story.setPlayer(MockPlayer)
     self.story.loadStoryLines()
class test_storyteller(TestCase):
    
    def setUp(self):
        self.setUpStoryFiles()
        self.story = StoryTeller()
        self.story.setAudioDir(TESTDIR)
        self.story.setPlayer(MockPlayer)
        self.story.loadStoryLines()
        
    def setUpStoryFiles(self):
        for filename in AUDIOFILES:
            self.touch(filename)
        
    def touch(self, filename):
        if not os.path.exists(TESTDIR):
            os.makedirs(TESTDIR) 
        fullname = os.path.join(TESTDIR,filename)
        with open(fullname, 'a'):
            os.utime(fullname, None)   
            
    def tearDown(self): 
        if os.path.exists(TESTDIR):
            shutil.rmtree(TESTDIR)
        
    def test_can_list_stories(self):
        storylines = self.story.getStoryLines()
        self.assertIsInstance(storylines,dict)
        count = len(STORYLENGTHS)
        self.assertEqual(len(storylines), count)
        for i in STORYLENGTHS:
            self.assertEqual(len(storylines[i]), STORYLENGTHS[i])
        
    def test_can_set_the_story_player(self):
        self.story.setCurrentStoryline(1)
        self.story.play()
        
    def test_if_current_storyline_not_set_raise_exception(self):
        self.assertRaises(StoryTellerError, self.story.play)
            
    def test_can_cycle_through_multiple_stories(self):
        self.story.setCurrentStoryline(1)
        self.assertCorrectFile(0)
        self.assertCorrectFile(1)
        self.assertCorrectFile(0)        
        self.story.setCurrentStoryline(2)
        self.assertCorrectFile(2)
        self.assertCorrectFile(3)
        self.assertCorrectFile(4)
        self.assertCorrectFile(2)
        
    def test_can_do_playNext(self):
        self.story.playNext(1)
        self.assertCorrectFile(1)
        self.story.playNext(2)
        self.story.playNext(2)
        self.story.playNext(2)
        self.assertCorrectFile(2)
        
    def test_can_show_storylines(self):
        self.assertEqual(self.story.showStoryLines(), '\n'.join(AUDIOFILES))
           
    def assertCorrectFile(self, audiofileindex):
        self.assertEquals(self.story.getCurrentStory(),AUDIOFILES[audiofileindex])
        self.story.play()