def load_presentation(self): """ Called when a presentation is added to the SlideController. Opens the PowerPoint file using the process created earlier. """ log.debug('load_presentation') try: if not self.controller.process: self.controller.start_process() self.controller.process.Presentations.Open( os.path.normpath(self.file_path), False, False, False) self.presentation = self.controller.process.Presentations( self.controller.process.Presentations.Count) self.create_thumbnails() self.create_titles_and_notes() # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow() return True except (AttributeError, pywintypes.com_error) as e: log.exception( 'Exception caught while loading Powerpoint presentation') log.exception(e) trace_error_handler(log) return False
def unblank_screen(self): """ Unblanks (restores) the presentation. """ log.debug('unblank_screen') try: self.presentation.SlideShowWindow.Activate() self.presentation.SlideShowWindow.View.State = 1 # Unblanking is broken in PowerPoint 2010 (14.0), need to redisplay if 15.0 > float(self.presentation.Application.Version) >= 14.0: self.presentation.SlideShowWindow.View.GotoSlide( self.index_map[self.blank_slide], False) if self.blank_click: self.presentation.SlideShowWindow.View.GotoClick( self.blank_click) except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in unblank_screen') log.exception(e) trace_error_handler(log) self.show_error_msg() # Stop powerpoint from flashing in the taskbar if self.presentation_hwnd: win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def load_presentation(self): """ Called when a presentation is added to the SlideController. It builds the environment, starts communcations with the background OpenOffice task started earlier. If OpenOffice is not present is is started. Once the environment is available the presentation is loaded and started. """ log.debug('Load Presentation OpenOffice') if is_win(): desktop = self.controller.get_com_desktop() if desktop is None: self.controller.start_process() desktop = self.controller.get_com_desktop() url = 'file:///' + self.file_path.replace('\\', '/').replace( ':', '|').replace(' ', '%20') else: desktop = self.controller.get_uno_desktop() url = uno.systemPathToFileUrl(self.file_path) if desktop is None: return False self.desktop = desktop properties = [] properties.append(self.create_property('Hidden', True)) properties = tuple(properties) try: self.document = desktop.loadComponentFromURL( url, '_blank', 0, properties) except: log.warning('Failed to load presentation %s' % url) return False self.presentation = self.document.getPresentation() self.presentation.Display = ScreenList().current['number'] + 1 self.control = None self.create_thumbnails() self.create_titles_and_notes() return True
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['size'] ppt_window = None try: ppt_window = self.presentation.SlideShowSettings.Run() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in start_presentation') log.exception(e) trace_error_handler(log) self.show_error_msg() if ppt_window and not 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 as e: log.exception('AttributeError while in start_presentation') log.exception(e) # 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())) win32gui.EnumWindows(self._window_enum_callback, size) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def __init__(self, parent): """ Initialise the general settings tab """ self.screens = ScreenList() self.icon_path = ':/icon/openlp-logo-16x16.png' general_translated = translate('OpenLP.GeneralTab', 'General') super(GeneralTab, self).__init__(parent, 'Core', general_translated)
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') # Check if the images has already been created, and if yes load them if os.path.isfile( os.path.join(self.get_temp_folder(), 'mainslide001.png')): created_files = sorted(os.listdir(self.get_temp_folder())) for fn in created_files: if os.path.isfile(os.path.join(self.get_temp_folder(), fn)): self.image_files.append( os.path.join(self.get_temp_folder(), fn)) 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 os.path.isdir(self.get_temp_folder()): os.makedirs(self.get_temp_folder()) if self.controller.mudrawbin: runlog = check_output([ self.controller.mudrawbin, '-w', str(size.width()), '-h', str(size.height()), '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path ], startupinfo=self.startupinfo) elif self.controller.gsbin: resolution = self.gs_get_resolution(size) runlog = check_output([ self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m', '-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4', '-sOutputFile=' + os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path ], startupinfo=self.startupinfo) created_files = sorted(os.listdir(self.get_temp_folder())) for fn in created_files: if os.path.isfile(os.path.join(self.get_temp_folder(), fn)): self.image_files.append( os.path.join(self.get_temp_folder(), fn)) except Exception as e: log.debug(e) log.debug(runlog) return False self.num_pages = len(self.image_files) # Create thumbnails self.create_thumbnails() return True
def __init__(self, parent): """ Initialise the general settings tab """ self.logo_file = ':/graphics/openlp-splash-screen.png' self.logo_background_color = '#ffffff' self.screens = ScreenList() self.icon_path = ':/icon/openlp-logo-16x16.png' general_translated = translate('OpenLP.GeneralTab', 'General') super(GeneralTab, self).__init__(parent, 'Core', general_translated)
def update_display(self): """ Screen has changed size so rebuild the cache to new size. """ log.debug('update_display') current_screen = ScreenList().current self.width = current_screen['size'].width() self.height = current_screen['size'].height() # Mark the images as dirty for a rebuild by setting the image and byte stream to None. for image in list(self._cache.values()): self._reset_image(image)
def set_default_header_footer(self): """ Set the header and footer size into the current primary screen. 10 px on each side is removed to allow for a border. """ current_screen = ScreenList().current self.font_main_y = 0 self.font_main_width = current_screen['size'].width() - 20 self.font_main_height = current_screen['size'].height() * 9 / 10 self.font_footer_width = current_screen['size'].width() - 20 self.font_footer_y = current_screen['size'].height() * 9 / 10 self.font_footer_height = current_screen['size'].height() / 10
def __init__(self): """ Constructor for the image manager. """ super(ImageManager, self).__init__() Registry().register('image_manager', self) current_screen = ScreenList().current self.width = current_screen['size'].width() self.height = current_screen['size'].height() self._cache = {} self.image_thread = ImageThread(self) self._conversion_queue = PriorityQueue() self.stop_manager = False Registry().register_function('images_regenerate', self.process_updates)
def __init__(self, parent=None, name=None, icon=None): """ Initialise the DockWidget """ log.debug('Initialise the %s widget' % name) super(OpenLPDockWidget, self).__init__(parent) if name: self.setObjectName(name) if icon: self.setWindowIcon(build_icon(icon)) # Sort out the minimum width. screens = ScreenList() main_window_docbars = screens.current['size'].width() // 5 if main_window_docbars > 300: self.setMinimumWidth(300) else: self.setMinimumWidth(main_window_docbars)
def close_presentation(self): """ Close presentation and clean up objects. This is triggered by a new object being added to SlideController or OpenLP being shut down. """ log.debug('ClosePresentation') if self.presentation: try: self.presentation.Close() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while closing powerpoint presentation') log.exception(e) trace_error_handler(log) self.presentation = None self.controller.remove_doc(self) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def __init__(self): """ Initialise the renderer. """ super(Renderer, self).__init__(None) # Need live behaviour if this is also working as a pseudo MainDisplay. self.screens = ScreenList() self.theme_level = ThemeLevel.Global self.global_theme_name = '' self.service_theme_name = '' self.item_theme_name = '' self.force_page = False self._theme_dimensions = {} self._calculate_default() self.web = QtWebKitWidgets.QWebView() self.web.setVisible(False) self.web_frame = self.web.page().mainFrame() Registry().register_function('theme_update_global', self.set_global_theme)
def __init__(self, parent): """ Constructor """ super(MainDisplay, self).__init__(parent) self.screens = ScreenList() self.rebuild_css = False self.hide_mode = None self.override = {} self.retranslateUi() self.media_object = None if self.is_live and PHONON_AVAILABLE: self.audio_player = AudioPlayer(self) else: self.audio_player = None self.first_time = True self.web_loaded = True self.setStyleSheet(OPAQUE_STYLESHEET) window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint if Settings().value('advanced/x11 bypass wm'): window_flags |= QtCore.Qt.X11BypassWindowManagerHint # TODO: The following combination of window_flags works correctly # on Mac OS X. For next OpenLP version we should test it on other # platforms. For OpenLP 2.0 keep it only for OS X to not cause any # regressions on other platforms. if is_macosx(): window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window # For primary screen ensure it stays above the OS X dock # and menu bar if self.screens.current['primary']: self.setWindowState(QtCore.Qt.WindowFullScreen) else: window_flags |= QtCore.Qt.WindowStaysOnTopHint self.setWindowFlags(window_flags) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.set_transparency(False) if self.is_live: Registry().register_function('live_display_hide', self.hide_display) Registry().register_function('live_display_show', self.show_display) Registry().register_function('update_display_css', self.css_changed)
def load_presentation(self): """ Called when a presentation is added to the SlideController. It builds the environment, starts communication with the background PptView task started earlier. """ log.debug('LoadPresentation') temp_folder = self.get_temp_folder() size = ScreenList().current['size'] rect = RECT(size.x(), size.y(), size.right(), size.bottom()) self.file_path = os.path.normpath(self.file_path) preview_path = os.path.join(temp_folder, 'slide') # Ensure that the paths are null terminated byte_file_path = self.file_path.encode('utf-16-le') + b'\0' preview_path = preview_path.encode('utf-16-le') + b'\0' if not os.path.isdir(temp_folder): os.makedirs(temp_folder) self.ppt_id = self.controller.process.OpenPPT(byte_file_path, None, rect, preview_path) if self.ppt_id >= 0: self.create_thumbnails() self.stop_presentation() return True else: return False
def start_presentation(self): """ Start the presentation from the beginning. """ log.debug('start presentation OpenOffice') if self.control is None or not self.control.isRunning(): window = self.document.getCurrentController().getFrame().getContainerWindow() window.setVisible(True) self.presentation.start() self.control = self.presentation.getController() # start() returns before the Component is ready. Try for 15 seconds. sleep_count = 1 while not self.control and sleep_count < 150: time.sleep(0.1) sleep_count += 1 self.control = self.presentation.getController() window.setVisible(False) else: self.control.activate() self.goto_slide(1) # Make sure impress doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def next_step(self): """ Triggers the next effect of slide on the running presentation. """ log.debug('next_step') try: self.presentation.SlideShowWindow.Activate() self.presentation.SlideShowWindow.View.Next() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in next_step') log.exception(e) trace_error_handler(log) self.show_error_msg() return if self.get_slide_number() > self.get_slide_count(): log.debug('past end, stepping back to previous') self.previous_step() # Stop powerpoint from flashing in the taskbar if self.presentation_hwnd: win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def __init__(self, parent): """ Constructor """ super(MainDisplay, self).__init__(parent) self.screens = ScreenList() self.rebuild_css = False self.hide_mode = None self.override = {} self.retranslateUi() self.media_object = None if self.is_live: self.audio_player = AudioPlayer(self) else: self.audio_player = None self.first_time = True self.web_loaded = True self.setStyleSheet(OPAQUE_STYLESHEET) window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint if Settings().value('advanced/x11 bypass wm'): window_flags |= QtCore.Qt.X11BypassWindowManagerHint # TODO: The following combination of window_flags works correctly # on Mac OS X. For next OpenLP version we should test it on other # platforms. For OpenLP 2.0 keep it only for OS X to not cause any # regressions on other platforms. if is_macosx(): window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window self.setWindowFlags(window_flags) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.set_transparency(False) if is_macosx(): if self.is_live: # Get a pointer to the underlying NSView try: nsview_pointer = self.winId().ascapsule() except: nsview_pointer = voidptr(self.winId()).ascapsule() # Set PyCapsule name so pyobjc will accept it pythonapi.PyCapsule_SetName.restype = c_void_p pythonapi.PyCapsule_SetName.argtypes = [py_object, c_char_p] pythonapi.PyCapsule_SetName(nsview_pointer, c_char_p(b"objc.__object__")) # Covert the NSView pointer into a pyobjc NSView object self.pyobjc_nsview = objc_object(cobject=nsview_pointer) # Set the window level so that the MainDisplay is above the menu bar and dock self.pyobjc_nsview.window().setLevel_(NSMainMenuWindowLevel + 2) # Set the collection behavior so the window is visible when Mission Control is activated self.pyobjc_nsview.window().setCollectionBehavior_( NSWindowCollectionBehaviorManaged) if self.screens.current['primary']: # Connect focusWindowChanged signal so we can change the window level when the display is not in # focus on the primary screen self.application.focusWindowChanged.connect( self.change_window_level) if self.is_live: Registry().register_function('live_display_hide', self.hide_display) Registry().register_function('live_display_show', self.show_display) Registry().register_function('update_display_css', self.css_changed) self.close_display = False