def __init__(self, meeting: Meeting, height: int):
        medium_font = pygame.font.Font("assets/FreeSansBold.ttf", 15)
        small_font = pygame.font.Font("assets/FreeSansBold.ttf", 10)
        summary = meeting.get_summary()
        location = meeting.get_location()

        if not summary:
            summary = "Okänt möte"
        if not location:
            location = "Okänd plats"

        self._text_heading = TextBox("Kommande möte:", small_font,
                                     (20, 20, 20))
        self._text_summary = TextBox(summary, medium_font, (20, 20, 20))
        self._text_location = TextBox(location, small_font, (20, 20, 20))
        self._text_duration = TextBox(
            meeting.get_start_time() + " - " + meeting.get_end_time(),
            medium_font, ACCENT)

        background = BorderedRect(
            pygame.rect.Rect(0, 0,
                             self.get_content_width() + 10, height))
        self.image = background.image
        self.rect = background.rect
        self._render_text()
示例#2
0
    def __init__(self, count: KeyPressCounter, location: tuple):
        self.count = count
        big_font = pygame.font.Font("assets/FreeSansBold.ttf", 50)
        small_font = pygame.font.Font("assets/FreeSansBold.ttf", 18)

        self.text_header = TextBox("Antal tryckningar:", small_font,
                                   (44, 44, 44))
        self.text_count = TextBox("{}".format(count.get_count()), big_font,
                                  (20, 20, 20))

        self.ballout = Ballout(230, 96, location, (28, 10))
        self.image = Image('assets/button.png')
示例#3
0
    def __init__(self, meeting: Meeting):
        big_font = pygame.font.Font("assets/FreeSansBold.ttf", 20)
        medium_font = pygame.font.Font("assets/FreeSansBold.ttf", 15)
        small_font = pygame.font.Font("assets/FreeSansBold.ttf", 10)

        self._text_summary = TextBox(meeting.get_summary(), medium_font,
                                     (20, 20, 20))
        self._text_location = TextBox(meeting.get_location(), small_font,
                                      (20, 20, 20))
        self._text_duration = TextBox(meeting.get_start_time(), big_font,
                                      ACCENT)

        size = self.get_content_size()

        background = BorderedRect(pygame.rect.Rect(0, 0, size[0], size[1]))
        self.image = background.image
        self.rect = background.rect
        self._render_text()
 def __init__(self, title: str, meeting: Meeting):
     big_font = pygame.font.Font("assets/FreeSansBold.ttf", 20)
     small_font = pygame.font.Font("assets/FreeSansBold.ttf", 12)
     self._text_header = TextBox(title, big_font, DEFAULT_FGCOLOR)
     self._text_summary = TextBox("Laddar...", small_font, DEFAULT_FGCOLOR)
     self._text_location = TextBox("", small_font, DEFAULT_FGCOLOR)
     self._text_duration = TextBox("", small_font, DEFAULT_FGCOLOR)
     self._bgcolor = DEFAULT_BGCOLOR
     self._fgcolor = DEFAULT_FGCOLOR
     self.current_meeting = None
     self.set_meeting(meeting)
     self._set_image_prop()
示例#5
0
class ButtonCount:
    """
    Composes the texts to be displayed
    """
    def __init__(self, count: KeyPressCounter, location: tuple):
        self.count = count
        big_font = pygame.font.Font("assets/FreeSansBold.ttf", 50)
        small_font = pygame.font.Font("assets/FreeSansBold.ttf", 18)

        self.text_header = TextBox("Antal tryckningar:", small_font,
                                   (44, 44, 44))
        self.text_count = TextBox("{}".format(count.get_count()), big_font,
                                  (20, 20, 20))

        self.ballout = Ballout(230, 98, location, (28, 10))
        self.image = Image('assets/button.png')

    def render(self, surface):
        """render at the specified display position"""
        self.text_count.set_text("{}".format(self.count.get_count()))
        self.ballout.render(surface)
        pos = self.ballout.get_pos()

        # Render Image
        self.image.rect.left = pos[0] + 2
        self.image.rect.top = pos[1] + 2
        self.image.render(surface)

        # Render text header
        self.text_header.rect.left = pos[0] + self.image.rect.width + 10
        self.text_header.rect.top = pos[1]
        self.text_header.render(surface)

        # Render text count
        self.text_count.rect.left = (pos[0] + self.image.rect.width + round(
            (self.ballout.width - self.image.rect.width) / 2) - 20)
        self.text_count.rect.top = pos[1] + 20
        self.text_count.render(surface)
class MeetingText:
    """
    Composes the texts to be displayed
    """
    def __init__(self, title: str, meeting: Meeting):
        big_font = pygame.font.Font("assets/FreeSansBold.ttf", 20)
        small_font = pygame.font.Font("assets/FreeSansBold.ttf", 12)
        self._text_header = TextBox(title, big_font, DEFAULT_FGCOLOR)
        self._text_summary = TextBox("Laddar...", small_font, DEFAULT_FGCOLOR)
        self._text_location = TextBox("", small_font, DEFAULT_FGCOLOR)
        self._text_duration = TextBox("", small_font, DEFAULT_FGCOLOR)
        self._bgcolor = DEFAULT_BGCOLOR
        self._fgcolor = DEFAULT_FGCOLOR
        self.current_meeting = None
        self.set_meeting(meeting)
        self._set_image_prop()

    def set_meeting(self, meeting):
        """Reload the dynamic text parts"""
        if self.current_meeting != meeting:
            self.current_meeting = meeting
            if not meeting.is_available():
                self._bgcolor = BUSY_BGCOLOR
                self._fgcolor = BUSY_FGCOLOR
                self._text_summary.set_text(meeting.get_summary())
                self._text_location.set_text("Plats: {}".format(
                    meeting.get_location()))
                self._text_duration.set_text("Åter: {}".format(
                    meeting.get_end_time()))
            else:
                self._bgcolor = AVAILABLE_BGCOLOR
                self._fgcolor = AVAILABLE_FGCOLOR
                self._text_summary.set_text("Inget möte bokat")
                self._text_location.set_text("")
                self._text_duration.set_text("")
                self._bgcolor = AVAILABLE_BGCOLOR

            self._text_header.set_color(self._fgcolor)
            self._text_summary.set_color(self._fgcolor)
            self._text_location.set_color(self._fgcolor)
            self._text_duration.set_color(self._fgcolor)
            self._set_image_prop()

    def get_bgcolor(self):
        """Gets the current background color"""
        return self._bgcolor

    def _set_image_prop(self):
        """Create surface and rect roperties"""
        size = self.get_content_size()
        self.image = pygame.surface.Surface(size)
        self.image.fill(self._bgcolor)
        self.rect = pygame.rect.Rect(0, 0, size[0], size[1])
        self._render_text()

    def get_content_size(self):
        """Calculate the max width of the current text"""
        width = 100
        height = 0
        for text_provider in (self._text_header, self._text_summary,
                              self._text_location, self._text_duration):
            width = max(text_provider.rect.width, width)
            height += (text_provider.rect.height)
        return (width + 21, height + 7)  # Add some padding after the text

    def _render_text(self):
        render_sprite_at_pos(self.image, self._text_header, (5, 0))
        render_sprite_at_pos(self.image, self._text_summary, (5, 30))
        render_sprite_at_pos(self.image, self._text_location, (5, 50))
        render_sprite_at_pos(self.image, self._text_duration, (5, 70))

    def render(self, surface):
        """render at the specified display position"""
        surface.blit(self.image, self.rect)