def __init__(self): pygame.init() pygame.font.init() self.question_height = 100 self.answer_height = 50 self.surface = pygame.display.set_mode((800, 600)) self.clock = pygame.time.Clock() self.mouse_handlers = [] self.objects = [] self.answer_objects = [] self.current_question = None self.current_question_i = -1 self.score = 0 self.state = GameState.game data=pd.read_csv("sample.csv") self.questions = [Question_Object(data["question"][0], (data["answer 1"][0], data["answer 2"][0], data["answer 3"][0], data["answer 4"][0]), data["correct_answer"][0]-1), Question_Object(data["question"][1], (data["answer 1"][1], data["answer 2"][1], data["answer 3"][1], data["answer 4"][1]), data["correct_answer"][1]-1), Question_Object(data["question"][2], (data["answer 1"][2], data["answer 2"][2], data["answer 3"][2], data["answer 4"][2]), data["correct_answer"][2]-1), Question_Object(data["question"][3], (data["answer 1"][3], data["answer 2"][3], data["answer 3"][3], data["answer 4"][3]), data["correct_answer"][3]-1), Question_Object(data["question"][4], (data["answer 1"][4], data["answer 2"][4], data["answer 3"][4], data["answer 4"][4]), data["correct_answer"][4]-1) ] self.score_text_block = TextBlock(500, 10, 250, 50, "Score: {0}/{1}".format(str(self.score), str(len(self.questions)))) self.objects.append(self.score_text_block) self.nextQuestion() self.game_over_text_block = TextBlock(250, 250, 300, 50, "Game over")
def test_text_block_format_pprint(): tb = TextBlock("Header 1") tb.lines.append("line 1 1") tb.lines.append("line 1 2") tb_1_1 = TextBlock("Header 1 1") tb_1_1.lines.append("line 1 1 1") tb_1_1.lines.append("line 1 1 2") tb.blocks.append(tb_1_1) tb_1_2 = TextBlock("Header 1 2") tb_1_2.lines.append("line 1 2 1") tb_1_2.lines.append("line 1 2 2") tb_1_2_1 = TextBlock("Header 1 2 1") tb_1_2_1.lines.append("line 1 2 1 1") tb_1_2_1.lines.append("line 1 2 1 2") tb_1_2.blocks.append(tb_1_2_1) tb.blocks.append(tb_1_2) tb_1_3 = TextBlock("Header 1 3") tb_1_3.lines.append("line 1 3 1") tb_1_3.lines.append("line 1 3 2") tb.blocks.append(tb_1_3) print(tb.format_pprint())
def should_return_the_number_of_columns(self): self.text_block.get_columns_number() | should | equal_to(3) text = "| name | phone |" text_block = TextBlock(text) text_block.get_columns_number() | should | equal_to(2) text = """ | name | phone | | None | """ (lambda: TextBlock(text) ) | should | throw(DifferentNumberOfColumnsError)
def should_not_initialize_with_a_text_empty_or_composed_by_white_spaces( self): text = '' (lambda: TextBlock(text)) | should | throw(WhiteSpacesError) text = ' \n' (lambda: TextBlock(text)) | should | throw(WhiteSpacesError) text = ' \t' (lambda: TextBlock(text)) | should | throw(WhiteSpacesError) text = ' |' (lambda: TextBlock(text)) | should_not | throw(WhiteSpacesError)
def it_should_return_a_list_with_the_tabulation_before_each_line(self): text = """ |name|age| |something|19| """ text_block = TextBlock(text) text_block.tabulation | should | equal_to([' ', ' ']) text_block.tabulation | should | have(2).items text = """|name|age| |someone|22|""" text_block = TextBlock(text) text_block.tabulation | should | equal_to(['', ' ']) text_block.tabulation | should | have(2).items
def it_should_accept_empty_string_between_pipes(self): text = """ || phone| |something | | """ text_block = TextBlock(text) text_block.lines_list[0] | should | include_all_of([' ', 'phone']) text_block.lines_list[1] | should | include_all_of(['something', ' '])
def setUp(self): self.text = """ | name | phone| company | |Hugo Maia Vieira| (22) 8512-7751 | UENF | |Rodrigo Manhães | (22) 9145-8722 |NSI| """ self.text_block = TextBlock(self.text)
def __init__(self): pygame.init() pygame.font.init() self.question_height = 100 self.answer_height = 50 self.surface = pygame.display.set_mode((800, 600)) self.clock = pygame.time.Clock() self.mouse_handlers = [] self.objects = [] self.answer_objects = [] self.current_question = None self.current_question_i = -1 self.score = 0 self.state = GameState.game self.questions = [ Question_Object('World War I began in which year?', ('1923', '1938', '1917', '1914'), 3), Question_Object( 'The Hundred Years War was fought between what two countries?', ('Italy and Carthage', 'England and Germany', 'France and England', 'Spain and France'), 2), Question_Object('Who fought in the war of 1812?', ('Andrew Jackson', 'Arthur Wellsley', 'Otto von Bismarck', 'Napoleon'), 0), Question_Object( 'American involvement in the Korean War took place in which decade?', ('1950s', '1960s', '1970s', '1980s'), 0), Question_Object( 'The Battle of Hastings in 1066 was fought in which country? ', ('France', 'Russia', 'England', 'Norway'), 3), Question_Object( 'The Magna Carta was published by the King of which country? ', ('France', 'Austria', 'Italy', 'England'), 3), Question_Object( 'The first successful printing press was developed by this man.', ('Johannes Gutenburg', 'Benjamin Franklin', 'Sir Isaac Newton', 'Martin Luther'), 0) ] self.score_text_block = TextBlock( 500, 10, 250, 50, "Score: {0}/{1}".format(str(self.score), str(len(self.questions)))) self.objects.append(self.score_text_block) self.nextQuestion() self.game_over_text_block = TextBlock(250, 250, 300, 50, "Game over")
def it_should_align_the_text_block(self): self.text_block.align() | should | equal_to( u""" | name | phone | company | | Hugo Maia Vieira | (22) 8512-7751 | UENF | | Rodrigo Manhães | (22) 9145-8722 | NSI |""") text = """| name | phone| company | |Hugo Maia Vieira| (22) 8512-7751 | UENF | |Rodrigo Manhães | (22) 9145-8722 |NSI|""" text_block = TextBlock(text) text_block.align() | should | equal_to( u"""| name | phone | company | | Hugo Maia Vieira | (22) 8512-7751 | UENF | | Rodrigo Manhães | (22) 9145-8722 | NSI |""")
def on_align_columns_activate(self, action): """Callback to align columns on menu click or accelerator.""" doc = self._window.get_active_document() bounds = doc.get_selection_bounds() if not doc or not bounds: return text = doc.get_text(*bounds) try: text_block = TextBlock(text) aligned_columns = text_block.align() doc.delete_interactive(*bounds, default_editable=True) doc.insert(bounds[0], aligned_columns) except WhiteSpacesError: return except DifferentNumberOfColumnsError: message = gtk.MessageDialog(None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, 'The selection has lines with different numbers of columns.') message.run() message.destroy()
def addTextBlock(self, x, y, w, h, text): self.objects.append(TextBlock(x, y, w, h, text))