aboutsummaryrefslogtreecommitdiffstats
path: root/PySide
diff options
context:
space:
mode:
authorRoman Lacko <backup.rlacko@gmail.com>2013-05-31 08:34:14 +0200
committerJohn Ehresman <jpe@wingware.com>2013-06-22 23:12:47 +0200
commitc707a7cadd08792d8f9dc23d83fc9a27ba7a7656 (patch)
treeb20fa0b58e63bd93fa89323fc62e5ee19e2d080d /PySide
parente35d8904491e9ded4e64c9156e5e9f2b777b399f (diff)
Tell Qt to look for qml imports in the PySide package
Change-Id: Ia7565955f8a3b58c8c57631e13bb56a2793b702a Reviewed-by: John Ehresman <jpe@wingware.com>
Diffstat (limited to 'PySide')
-rw-r--r--PySide/CMakeLists.txt5
-rw-r--r--PySide/__init__.py.in13
-rw-r--r--PySide/_utils.py.in91
3 files changed, 108 insertions, 1 deletions
diff --git a/PySide/CMakeLists.txt b/PySide/CMakeLists.txt
index d8371c0b3..fce5bb12b 100644
--- a/PySide/CMakeLists.txt
+++ b/PySide/CMakeLists.txt
@@ -9,6 +9,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in"
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
"${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_utils.py.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/_utils.py" @ONLY)
+
HAS_QT_MODULE(QT_QTCORE_FOUND QtCore)
HAS_QT_MODULE(QT_QTGUI_FOUND QtGui)
HAS_QT_MODULE(QT_QTNETWORK_FOUND QtNetwork)
@@ -33,6 +36,8 @@ HAS_QT_MODULE(QT_QTDECLARATIVE_FOUND QtDeclarative)
# install
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py"
DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}")
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/_utils.py
+ DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_templates.xml
DESTINATION share/PySide${pyside_SUFFIX}/typesystems)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyside_global.h
diff --git a/PySide/__init__.py.in b/PySide/__init__.py.in
index fb70ec0f1..183df2d30 100644
--- a/PySide/__init__.py.in
+++ b/PySide/__init__.py.in
@@ -6,8 +6,9 @@ __version_info__ = (@BINDING_API_MAJOR_VERSION@, @BINDING_API_MINOR_VERSION@,
def _setupQtDirectories():
import sys
import os
+ from . import _utils
- pysideDir = os.path.abspath(os.path.dirname(__file__))
+ pysideDir = _utils.get_pyside_dir()
# On Windows add the PySide\openssl folder (if it exists) to the
# PATH so the SSL DLLs can be found when Qt tries to dynamically
@@ -40,5 +41,15 @@ def _setupQtDirectories():
pluginsDir not in QtCore.QCoreApplication.libraryPaths():
QtCore.QCoreApplication.addLibraryPath(pluginsDir)
+ # Tell Qt to look for qml imports in the PySide package, if the
+ # imports folder exists there.
+ importsDir = os.path.join(pysideDir, 'imports')
+ if os.path.exists(importsDir):
+ if 'QML_IMPORT_PATH' in os.environ:
+ qml_import_path = os.environ['QML_IMPORT_PATH']
+ os.environ['QML_IMPORT_PATH'] = importsDir + os.pathsep + qml_import_path
+ else:
+ os.environ['QML_IMPORT_PATH'] = importsDir
+
_setupQtDirectories()
diff --git a/PySide/_utils.py.in b/PySide/_utils.py.in
new file mode 100644
index 000000000..fb2d25e2d
--- /dev/null
+++ b/PySide/_utils.py.in
@@ -0,0 +1,91 @@
+# This file is part of PySide: Python for Qt
+#
+# Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+#
+# Contact: PySide team <contact@pyside.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import sys
+import os
+
+
+if sys.platform == 'win32':
+ # On Windows get the PySide package path in case sensitive format.
+ # Even if the file system on Windows is case insensitive,
+ # some parts in Qt environment such as qml imports path,
+ # requires to be in case sensitive format.
+ import ctypes
+ from ctypes import POINTER, WinError, sizeof, byref, create_unicode_buffer
+ from ctypes.wintypes import MAX_PATH, LPCWSTR, LPWSTR, DWORD
+
+ GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
+ GetShortPathNameW.argtypes = [LPCWSTR, LPWSTR, DWORD]
+ GetShortPathNameW.restype = DWORD
+
+ GetLongPathNameW = ctypes.windll.kernel32.GetLongPathNameW
+ GetLongPathNameW.argtypes = [LPCWSTR, LPWSTR, DWORD]
+ GetLongPathNameW.restype = DWORD
+
+ PY_2 = sys.version_info[0] < 3
+
+ if PY_2:
+ def u(x):
+ return unicode(x)
+ else:
+ def u(x):
+ return x
+
+ def _get_win32_short_name(s):
+ """ Returns short name """
+ buf_size = MAX_PATH
+ for i in range(2):
+ buf = create_unicode_buffer(u('\0') * (buf_size + 1))
+ r = GetShortPathNameW(u(s), buf, buf_size)
+ if r == 0:
+ raise WinError()
+ if r < buf_size:
+ if PY_2:
+ return buf.value.encode(sys.getfilesystemencoding())
+ return buf.value
+ buf_size = r
+ raise WinError()
+
+ def _get_win32_long_name(s):
+ """ Returns long name """
+ buf_size = MAX_PATH
+ for i in range(2):
+ buf = create_unicode_buffer(u('\0') * (buf_size + 1))
+ r = GetLongPathNameW(u(s), buf, buf_size)
+ if r == 0:
+ raise WinError()
+ if r < buf_size:
+ if PY_2:
+ return buf.value.encode(sys.getfilesystemencoding())
+ return buf.value
+ buf_size = r
+ raise WinError()
+
+ def _get_win32_case_sensitive_name(s):
+ """ Returns long name in case sensitive format """
+ path = _get_win32_long_name(_get_win32_short_name(s))
+ return path
+
+ def get_pyside_dir():
+ return _get_win32_case_sensitive_name(os.path.abspath(os.path.dirname(__file__)))
+
+else:
+ def get_pyside_dir():
+ return os.path.abspath(os.path.dirname(__file__))