Example #1
0
 def start_presentation(self):
     """
     Starts a presentation from the beginning.
     """
     log.debug('start_presentation')
     # SlideShowWindow measures its size/position by points, not pixels
     # https://technet.microsoft.com/en-us/library/dn528846.aspx
     try:
         dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88)
     except win32ui.error:
         try:
             dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps(
                 88)
         except win32ui.error:
             dpi = 96
     size = ScreenList().current.display_geometry
     ppt_window = None
     try:
         # Disable the presentation console
         self.presentation.SlideShowSettings.ShowPresenterView = 0
         # Start the presentation
         ppt_window = self.presentation.SlideShowSettings.Run()
     except (AttributeError, pywintypes.com_error):
         log.exception('Caught exception while in start_presentation')
         trace_error_handler(log)
         self.show_error_msg()
     if ppt_window and not Registry().get('settings').value(
             'presentations/powerpoint control window'):
         try:
             ppt_window.Top = size.y() * 72 / dpi
             ppt_window.Height = size.height() * 72 / dpi
             ppt_window.Left = size.x() * 72 / dpi
             ppt_window.Width = size.width() * 72 / dpi
         except AttributeError:
             log.exception('AttributeError while in start_presentation')
     # Find the presentation window and save the handle for later
     self.presentation_hwnd = None
     if ppt_window:
         log.debug('main display size:  y={y:d}, height={height:d}, '
                   'x={x:d}, width={width:d}'.format(
                       y=size.y(),
                       height=size.height(),
                       x=size.x(),
                       width=size.width()))
         try:
             win32gui.EnumWindows(self._window_enum_callback, size)
         except pywintypes.error:
             # When _window_enum_callback returns False to stop the enumeration (looping over open windows)
             # it causes an exception that is ignored here
             pass
     # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup
     if len(ScreenList()) > 1:
         Registry().get('main_window').activateWindow()
Example #2
0
    def load_presentation(self):
        """
        Called when a presentation is added to the SlideController. It generates images from the PDF.

        :return: True is loading succeeded, otherwise False.
        """
        log.debug('load_presentation pdf')
        temp_dir_path = self.get_temp_folder()
        # Check if the images has already been created, and if yes load them
        if (temp_dir_path / 'mainslide001.png').is_file():
            created_files = sorted(temp_dir_path.glob('*'))
            for image_path in created_files:
                if image_path.is_file():
                    self.image_files.append(image_path)
            self.num_pages = len(self.image_files)
            return True
        size = ScreenList().current.display_geometry
        # Generate images from PDF that will fit the frame.
        runlog = ''
        try:
            if not temp_dir_path.is_dir():
                temp_dir_path.mkdir(parents=True)
            # The %03d in the file name is handled by each binary
            if self.controller.mudrawbin:
                log.debug('loading presentation using mudraw')
                runlog = check_output([
                    str(self.controller.mudrawbin), '-w',
                    str(size.width()), '-h',
                    str(size.height()), '-o',
                    str(temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            elif self.controller.mutoolbin:
                log.debug('loading presentation using mutool')
                runlog = check_output([
                    str(self.controller.mutoolbin), 'draw', '-w',
                    str(size.width()), '-h',
                    str(size.height()), '-o',
                    str(temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            elif self.controller.gsbin:
                log.debug('loading presentation using gs')
                resolution = self.gs_get_resolution(size)
                runlog = check_output([
                    str(self.controller.gsbin), '-dSAFER', '-dNOPAUSE',
                    '-dBATCH', '-sDEVICE=png16m',
                    '-r{res}'.format(res=resolution), '-dTextAlphaBits=4',
                    '-dGraphicsAlphaBits=4', '-sOutputFile={output}'.format(
                        output=temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            elif PYMUPDF_AVAILABLE:
                log.debug('loading presentation using PyMuPDF')
                pdf = fitz.open(str(self.file_path))
                for i, page in enumerate(pdf, start=1):
                    src_size = page.bound().round()
                    # keep aspect ratio
                    scale = min(size.width() / src_size.width,
                                size.height() / src_size.height)
                    m = fitz.Matrix(scale, scale)
                    page.getPixmap(m, alpha=False).writeImage(
                        str(temp_dir_path / 'mainslide{:03d}.png'.format(i)))
                pdf.close()
            created_files = sorted(temp_dir_path.glob('*'))
            for image_path in created_files:
                if image_path.is_file():
                    self.image_files.append(image_path)
        except Exception:
            log.exception(runlog)
            return False
        self.num_pages = len(self.image_files)
        # Create thumbnails
        self.create_thumbnails()
        return True
Example #3
0
 def set_default_header(self):
     current_screen_geometry = ScreenList().current.display_geometry
     self.font_main_x = 10
     self.font_main_y = 0
     self.font_main_width = current_screen_geometry.width() - 20
     self.font_main_height = current_screen_geometry.height() * 9 / 10
Example #4
0
 def set_default_footer(self):
     current_screen_geometry = ScreenList().current.display_geometry
     self.font_footer_x = 10
     self.font_footer_y = current_screen_geometry.height() * 9 / 10
     self.font_footer_width = current_screen_geometry.width() - 20
     self.font_footer_height = current_screen_geometry.height() / 10
Example #5
0
    def load_presentation(self):
        """
        Called when a presentation is added to the SlideController. It generates images from the PDF.

        :return: True is loading succeeded, otherwise False.
        """
        log.debug('load_presentation pdf')
        temp_dir_path = self.get_temp_folder()
        # Check if the images has already been created, and if yes load them
        if (temp_dir_path / 'mainslide001.png').is_file():
            created_files = sorted(temp_dir_path.glob('*'))
            for image_path in created_files:
                if image_path.is_file():
                    self.image_files.append(image_path)
            self.num_pages = len(self.image_files)
            return True
        size = ScreenList().current['size']
        # Generate images from PDF that will fit the frame.
        runlog = ''
        try:
            if not temp_dir_path.is_dir():
                temp_dir_path.mkdir(parents=True)
            # The %03d in the file name is handled by each binary
            if self.controller.mudrawbin:
                log.debug('loading presentation using mudraw')
                runlog = check_output([
                    str(self.controller.mudrawbin), '-w',
                    str(size.width()), '-h',
                    str(size.height()), '-o',
                    str(temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            elif self.controller.mutoolbin:
                log.debug('loading presentation using mutool')
                runlog = check_output([
                    str(self.controller.mutoolbin), 'draw', '-w',
                    str(size.width()), '-h',
                    str(size.height()), '-o',
                    str(temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            elif self.controller.gsbin:
                log.debug('loading presentation using gs')
                resolution = self.gs_get_resolution(size)
                runlog = check_output([
                    str(self.controller.gsbin), '-dSAFER', '-dNOPAUSE',
                    '-dBATCH', '-sDEVICE=png16m',
                    '-r{res}'.format(res=resolution), '-dTextAlphaBits=4',
                    '-dGraphicsAlphaBits=4', '-sOutputFile={output}'.format(
                        output=temp_dir_path / 'mainslide%03d.png'),
                    str(self.file_path)
                ],
                                      startupinfo=self.startupinfo)
            created_files = sorted(temp_dir_path.glob('*'))
            for image_path in created_files:
                if image_path.is_file():
                    self.image_files.append(image_path)
        except Exception as e:
            log.exception(runlog)
            return False
        self.num_pages = len(self.image_files)
        # Create thumbnails
        self.create_thumbnails()
        return True