コード例 #1
0
    def create_surface(self):
        """Creates a Surface depicting the Tweet."""
        # TODO: Needs refactoring (including the helper methods).
        header = []

        profile_pic = image_handler.get_image(self.profile_image_url)
        size = config2.config['profile_size']
        profile_pic = pygame.transform.scale(profile_pic, (size, size))
        header.append(profile_pic)

        Tweet.font.set_underline(True)
        name = Tweet.font.render('@' + self.screen_name, 1, BLACK)
        Tweet.font.set_underline(False)
        header.append(name)


        text = Tweet.create_body(self.lines)
        content = []
        content.append(make_header(header, WHITE, text.get_rect().width))
        content.append(text)

        content.extend([image_handler.get_image(img) for img in self.imgs])
        
        popularity_bar = self.create_popularity_surface()
        content.append(popularity_bar)
        
        content_surf = make_column(content, WHITE)
        content_surf = Tweet.create_bubble(content_surf)#surrounds the content in the bubble
        surfs = []
        surfs.append(content_surf) 

        tweet = make_column(surfs, BLACK)
        return content_surf
コード例 #2
0
ファイル: tweet.py プロジェクト: sdsc/sandbox-tweeteor
 def create_surface(self):
     """Creates a Surface depicting the Tweet."""
     # TODO: Needs refactoring (including the helper methods).
     surfs = []
     image = image_handler.get_image(self.profile_image_url)
     profile_pic = pygame.transform.scale(image, (70, 70))
     surfs.append(profile_pic)
     name = Tweet.font.render('@' + self.screen_name, 1, BLACK)
     surfs.append(name)
     text = Tweet.create_body(self.lines)
     content = [text]
     content.extend([image_handler.get_image(img) for img in self.imgs])
     popularity_bar = self.create_popularity_surface()
     content.append(popularity_bar)
     content_surf = make_column(content, WHITE)
     surfs.append(Tweet.create_bubble(content_surf))
     tweet = make_column(surfs, TWITTER_BLUE)
     return tweet
コード例 #3
0
    def create_body(lines):
        """
        Create a surface representing the body of a tweet
        (the actual words in the tweet). Takes a matrix of Words
        (each row is a line) as input.
        """
        MAX_LENGTH = config2.config['max_text_length']

        words = []
        for line in lines:
            for word in line:
                word.text = word.text.rstrip()
                words.append(word)

        while True:
            bigWord = None
            for word in words:
                if len(word.text) > MAX_LENGTH:
                    bigWord = word
                    break
            if bigWord == None:
                break
            index = words.index(bigWord)
            beginChunk = bigWord.text[:MAX_LENGTH]
            newWord = Word(beginChunk)
            newWord.color = bigWord.color
            bigWord.text = bigWord.text[MAX_LENGTH:]
            words = words[:index] + [newWord] + words[index:]




        surfs = []
        word_surfs = []
        line_len = 0
        for word in words:
            word_len = len(word.text)
            if word_len + line_len > MAX_LENGTH:
                line_surf  = make_row(word_surfs, WHITE)
                surfs.append(line_surf)
                word_surfs = []
                line_len   = 0
            try:
                line_len += len(word.text)
                word_surf = Tweet.font.render(word.text + '  ', 1, word.color)
                word_surfs.append(word_surf)
            except:
                logging.exception("Error when rendering Word")

        if len(word_surfs) != 0:
            line_surf = make_row(word_surfs, WHITE)
            surfs.append(line_surf)


        return make_column(surfs, WHITE)
コード例 #4
0
ファイル: tweet.py プロジェクト: sdsc/sandbox-tweeteor
 def create_body(lines):
     """
     Create a surface representing the body of a tweet
     (the actual words in the tweet). Takes a matrix of Words
     (each row is a line) as input.
     """
     surfs = []
     for line in lines:
         word_surfs = []
         for word in line:
             try:
                 surf = Tweet.font.render(word.text + '  ', 1, word.color)
                 word_surfs.append(surf)
             except:
                 logging.exception("Error when rendering Word")
         if len(word_surfs) == 0:
             continue
         line = make_row(word_surfs, WHITE)
         surfs.append(line)
     return make_column(surfs, WHITE)