← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~tomasgroth/openlp/vlc-pyinst-win-fix into lp:openlp

 

Tomas Groth has proposed merging lp:~tomasgroth/openlp/vlc-pyinst-win-fix into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/vlc-pyinst-win-fix/+merge/281366

Only import vlc in one place. Make it work with PyInstaller.
Added bit-install-hint for VLC
Pep8 fixes


-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/vlc-pyinst-win-fix into lp:openlp.
=== modified file 'openlp/core/ui/media/playertab.py'
--- openlp/core/ui/media/playertab.py	2015-11-07 00:49:40 +0000
+++ openlp/core/ui/media/playertab.py	2015-12-26 20:15:34 +0000
@@ -22,6 +22,7 @@
 """
 The :mod:`~openlp.core.ui.media.playertab` module holds the configuration tab for the media stuff.
 """
+import platform
 from PyQt5 import QtCore, QtWidgets
 
 from openlp.core.common import Registry, Settings, UiStrings, translate
@@ -250,4 +251,9 @@
             if player.available:
                 checkbox.setText(player.display_name)
             else:
-                checkbox.setText(translate('OpenLP.PlayerTab', '%s (unavailable)') % player.display_name)
+                checkbox_text = translate('OpenLP.PlayerTab', '%s (unavailable)') % player.display_name
+                if player.name == 'vlc':
+                    checkbox_text += ' ' + translate('OpenLP.PlayerTab',
+                                                     'NOTE: To use VLC you must install the %s version',
+                                                     'Will insert "32bit" or "64bit"') % platform.architecture()[0]
+                checkbox.setText(checkbox_text)

=== modified file 'openlp/core/ui/media/vlcplayer.py'
--- openlp/core/ui/media/vlcplayer.py	2015-11-07 00:49:40 +0000
+++ openlp/core/ui/media/vlcplayer.py	2015-12-26 20:15:34 +0000
@@ -28,7 +28,7 @@
 import os
 import threading
 import sys
-
+import ctypes
 from PyQt5 import QtWidgets
 
 from openlp.core.common import Settings, is_win, is_macosx, is_linux
@@ -65,14 +65,24 @@
     if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
         # If VLC has already been imported, no need to do all the stuff below again
         return sys.modules['openlp.core.ui.media.vendor.vlc']
-
     is_vlc_available = False
     try:
         if is_macosx():
             # Newer versions of VLC on OS X need this. See https://forum.videolan.org/viewtopic.php?t=124521
             os.environ['VLC_PLUGIN_PATH'] = '/Applications/VLC.app/Contents/MacOS/plugins'
+        # On Windows when frozen in PyInstaller, we need to blank SetDllDirectoryW to allow loading of the VLC dll.
+        # This is due to limitations (by desgin) in PyInstaller. SetDllDirectoryW original value is restored once
+        # VLC has been imported.
+        if is_win():
+            buffer_size = 1024
+            dll_directory = ctypes.create_unicode_buffer(buffer_size)
+            new_buffer_size = ctypes.windll.kernel32.GetDllDirectoryW(buffer_size, dll_directory)
+            dll_directory = ''.join(dll_directory[:new_buffer_size]).replace('\0', '')
+            log.debug('Original DllDirectory: %s' % dll_directory)
+            ctypes.windll.kernel32.SetDllDirectoryW(None)
         from openlp.core.ui.media.vendor import vlc
-
+        if is_win():
+            ctypes.windll.kernel32.SetDllDirectoryW(dll_directory)
         is_vlc_available = bool(vlc.get_default_instance())
     except (ImportError, NameError, NotImplementedError):
         pass

=== modified file 'openlp/plugins/media/forms/mediaclipselectorform.py'
--- openlp/plugins/media/forms/mediaclipselectorform.py	2015-11-07 00:49:40 +0000
+++ openlp/plugins/media/forms/mediaclipselectorform.py	2015-12-26 20:15:34 +0000
@@ -31,6 +31,7 @@
 from openlp.core.common import translate, is_win, is_linux, is_macosx, RegistryProperties
 from openlp.plugins.media.forms.mediaclipselectordialog import Ui_MediaClipSelector
 from openlp.core.lib.ui import critical_error_message_box
+from openlp.core.ui.media.vlcplayer import get_vlc
 
 if is_win():
     from win32com.client import Dispatch
@@ -38,17 +39,6 @@
 if is_linux():
     import dbus
 
-try:
-    from openlp.core.ui.media.vendor import vlc
-except (ImportError, NameError, NotImplementedError):
-    pass
-except OSError as e:
-    if is_win():
-        if not isinstance(e, WindowsError) and e.winerror != 126:
-            raise
-    else:
-        raise
-
 log = logging.getLogger(__name__)
 
 
@@ -126,6 +116,7 @@
         """
         Setup VLC instance and mediaplayer
         """
+        vlc = get_vlc()
         self.vlc_instance = vlc.Instance()
         # creating an empty vlc media player
         self.vlc_media_player = self.vlc_instance.media_player_new()
@@ -160,6 +151,7 @@
         :param path: Path to the device to be tested.
         :return: True if it was an audio CD else False.
         """
+        vlc = get_vlc()
         # Detect by trying to play it as a CD
         self.vlc_media = self.vlc_instance.media_new_location('cdda://' + path)
         self.vlc_media_player.set_media(self.vlc_media)
@@ -193,6 +185,7 @@
         :param clicked: Given from signal, not used.
         """
         log.debug('on_load_disc_button_clicked')
+        vlc = get_vlc()
         self.disable_all()
         self.application.set_busy_cursor()
         path = self.media_path_combobox.currentText()
@@ -281,6 +274,7 @@
 
         :param clicked: Given from signal, not used.
         """
+        vlc = get_vlc()
         if self.vlc_media_player.get_state() == vlc.State.Playing:
             self.vlc_media_player.pause()
             self.play_button.setIcon(self.play_icon)
@@ -381,6 +375,7 @@
         :param index: The index of the newly chosen title track.
         """
         log.debug('in on_titles_combo_box_changed, index: %d', index)
+        vlc = get_vlc()
         if not self.vlc_media_player:
             log.error('vlc_media_player was None')
             return
@@ -619,6 +614,7 @@
         :param media_state: VLC media state to wait for.
         :return: True if state was reached within 15 seconds, False if not or error occurred.
         """
+        vlc = get_vlc()
         start = datetime.now()
         while media_state != self.vlc_media_player.get_state():
             if self.vlc_media_player.get_state() == vlc.State.Error:

=== modified file 'openlp/plugins/songs/lib/songselect.py'
--- openlp/plugins/songs/lib/songselect.py	2015-12-23 18:20:22 +0000
+++ openlp/plugins/songs/lib/songselect.py	2015-12-26 20:15:34 +0000
@@ -220,4 +220,3 @@
             db_song.add_author(author)
         self.db_manager.save_object(db_song)
         return db_song
-

=== modified file 'scripts/translation_utils.py'
--- scripts/translation_utils.py	2015-12-23 21:51:00 +0000
+++ scripts/translation_utils.py	2015-12-26 20:15:34 +0000
@@ -427,4 +427,3 @@
     else:
         if not main():
             sys.exit(1)
-

=== modified file 'tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py'
--- tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py	2015-11-07 00:49:40 +0000
+++ tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py	2015-12-26 20:15:34 +0000
@@ -51,7 +51,7 @@
         self.main_window = QtWidgets.QMainWindow()
         Registry().register('main_window', self.main_window)
         # Mock VLC so we don't actually use it
-        self.vlc_patcher = patch('openlp.plugins.media.forms.mediaclipselectorform.vlc')
+        self.vlc_patcher = patch('openlp.plugins.media.forms.mediaclipselectorform.get_vlc')
         self.vlc_patcher.start()
         Registry().register('application', self.app)
         # Mock the media item


Follow ups