Exemplo n.º 1
0
    def generate_card_results(self, tracks: List[Song],
                              cards: List[BingoTicket]):
        """generate PDF showing when each ticket wins"""
        doc = DG.Document(pagesize=PageSizes.A4,
                          title=f'{self.options.game_id} - {self.options.title}',
                          topMargin="0.25in",
                          bottomMargin="0.25in",
                          rightMargin="0.25in",
                          leftMargin="0.25in")

        doc.append(self.options.palette.logo_image("6.2in"))
        doc.append(DG.Spacer(width=0, height="0.05in"))

        doc.append(DG.Paragraph(
            f'Results For Game Number: <b>{self.options.game_id}</b>',
            self.TEXT_STYLES['results-heading']))
        doc.append(DG.Paragraph(
            self.options.title,
            self.TEXT_STYLES['results-title']))

        pstyle = self.TEXT_STYLES['results-cell']
        heading: DG.TableRow = [
            DG.Paragraph('<b>Ticket Number</b>', pstyle),
            DG.Paragraph('<b>Wins after track</b>', pstyle),
            DG.Paragraph('<b>Start Time</b>', pstyle),
        ]
        data: List[DG.TableRow] = []

        cards = copy.copy(cards)
        cards.sort(key=lambda card: card.ticket_number, reverse=False)
        for card in cards:
            win_point = self.get_when_ticket_wins(tracks, card)
            song = tracks[win_point - 1]
            data.append([
                DG.Paragraph(f'{card.ticket_number}', pstyle),
                DG.Paragraph(
                    f'Track {win_point} - {song.title} ({song.artist})',
                    pstyle),
                DG.Paragraph(Duration(song.start_time).format(), pstyle)
            ])

        col_widths: List[Dimension] = [
            Dimension("0.75in"), Dimension("5.5in"), Dimension("0.85in"),
        ]
        hstyle = pstyle.replace(
            name='results-table-heading',
            background=self.options.palette.title_bg)
        tstyle = TableStyle(name='results-table',
                            borderColour=Colour('black'),
                            borderWidth=1.0,
                            gridColour=Colour('black'),
                            gridWidth=0.5,
                            verticalAlignment=VerticalAlignment.CENTER,
                            headingStyle=hstyle)
        table = DG.Table(data, heading=heading, repeat_heading=True,
                         colWidths=col_widths, style=tstyle)
        doc.append(table)
        filename = str(self.options.ticket_results_output_name())
        self.doc_gen.render(filename, doc, Progress())
Exemplo n.º 2
0
 def clear(self):
     """remove all songs from Treeview"""
     children = self.tree.get_children()
     if children:
         self.tree.delete(*children)
     self._duration = Duration(0)
     self._num_songs = 0
     self._data = {}
Exemplo n.º 3
0
 def _update_footer(self):
     """
     Update the duration text at the bottom of the treeview.
     This function is called after any addition or removal of songs
     to/from the lists.
     """
     txt = self.FOOTER_TEMPLATE.format(num_songs=self._num_songs,
                                       duration=Duration(
                                           self._duration).format())
     self.footer.config(text=txt)
Exemplo n.º 4
0
 def run(self, songs: List[Song]) -> None:  # type: ignore
     """
     Play one or more songs
     This function runs in its own thread
     """
     mp3editor = MP3Factory.create_editor()
     for song in songs:
         afile = mp3editor.use(song)
         if self.options.mode == GameMode.CLIP:
             start = int(Duration.parse(self.options.clip_start))
             end = start + self.options.clip_duration * 1000
             afile = afile.clip(start, end)
         self.progress.text = f'{song.artist}: {song.title}'
         mp3editor.play(afile, self.progress)
         if self.progress.abort:
             return
Exemplo n.º 5
0
 def _update_footer(self):
     """
     Update the duration text at the bottom of the panel.
     This function is called after any addition or removal of songs
     to/from the lists.
     """
     if self._num_songs < 30:
         box_col = "#ff0000"
     elif self._num_songs < 45:
         box_col = "#fffa20"
     else:
         box_col = "#00c009"
     if self.options.mode == GameMode.CLIP:
         mode = "to clip"
     elif self.options.mode == GameMode.QUIZ:
         mode = "in quiz"
     else:
         mode = "in game"
     txt = self.FOOTER_TEMPLATE.format(mode=mode,
                                       num_songs=self._num_songs,
                                       duration=Duration(
                                           self._duration).format())
     self.footer.config(text=txt, fg=box_col)
Exemplo n.º 6
0
 def generate(self, songs: List[Song]) -> List[Path]:
     """
     Generate all clips for all selected Songs
     Returns list of filenames of new clips
     """
     total_songs = len(songs)
     clips: List[Path] = []
     start = int(Duration(self.options.clip_start))
     end = start + 1000 * self.options.clip_duration
     for index, song in enumerate(songs):
         self.progress.text = '{} ({:d}/{:d})'.format(
             Song.clean(song.title), index, total_songs)
         self.progress.pct = 100.0 * float(index) / float(total_songs)
         #pylint: disable=broad-except
         try:
             clips.append(self.generate_clip(song, start, end))
         except InvalidMP3Exception as err:
             traceback.print_exc()
             print(r'Error generating clip: {0} - {1}'.format(
                 Song.clean(song.title), str(err)))
     self.progress.pct = 100.0
     self.progress.text = 'Finished generating clips'
     return clips
Exemplo n.º 7
0
 def duration(self) -> Duration:
     """total duration of the file"""
     assert self.start is not None
     assert self.end is not None
     return Duration(int(self.end) - int(self.start))
Exemplo n.º 8
0
 def duration(self) -> Duration:
     """total duration of the file"""
     return Duration(sum([int(f.duration) for f in self._files]))
Exemplo n.º 9
0
    def generate_track_listing(self, tracks: List[Song]) -> None:
        """generate a PDF version of the track order in the game"""
        assert len(tracks) > 0
        doc = DG.Document(PageSizes.A4, topMargin="0.25in",
                          bottomMargin="0.25in",
                          leftMargin="0.35in", rightMargin="0.35in",
                          title=f'{self.options.game_id} - {self.options.title}')

        doc.append(self.options.palette.logo_image("6.2in"))
        doc.append(DG.Spacer(width=0, height="0.05in"))

        doc.append(DG.Paragraph(
            f'Track Listing For Game Number: <b>{self.options.game_id}</b>',
            self.TEXT_STYLES['track-heading']))

        doc.append(DG.Paragraph(
            self.options.title,
            self.TEXT_STYLES['track-title']))

        cell_style = self.TEXT_STYLES['track-cell']
        heading: DG.TableRow = [
            DG.Paragraph('<b>Order</b>', cell_style),
            DG.Paragraph('<b>Title</b>', cell_style),
            DG.Paragraph('<b>Artist</b>', cell_style),
            DG.Paragraph('<b>Start Time</b>', cell_style),
            DG.Paragraph('', cell_style),
        ]

        data: List[DG.TableRow] = []

        for index, song in enumerate(tracks, start=1):
            order = DG.Paragraph(f'<b>{index}</b>', cell_style)
            title = DG.Paragraph(song.title, cell_style)
            if self.should_include_artist(song):
                artist = DG.Paragraph(song.artist, cell_style)
            else:
                artist = DG.Paragraph('', cell_style)
            start = DG.Paragraph(Duration(song.start_time).format(), cell_style)
            end_box = DG.Paragraph('', cell_style)
            data.append([order, title, artist, start, end_box])

        col_widths = [Dimension("0.55in"),
                      Dimension("2.9in"),
                      Dimension("2.9in"),
                      Dimension("0.85in"),
                      Dimension("0.2in")]

        hstyle = cell_style.replace(
            name='track-table-heading',
            background=self.options.palette.title_bg)
        tstyle = TableStyle(
            name='track-table',
            borderColour=Colour('black'),
            borderWidth=1.0,
            gridColour=Colour('black'),
            gridWidth=0.5,
            verticalAlignment=VerticalAlignment.CENTER,
            headingStyle=hstyle)
        table = DG.Table(data, heading=heading, repeat_heading=True,
                         colWidths=col_widths, style=tstyle)
        doc.append(table)
        filename = str(self.options.track_listing_output_name())
        self.doc_gen.render(filename, doc, Progress())