From 9e822f69f11c41aba027eb3c73b511a7e4d1a8ed Mon Sep 17 00:00:00 2001 From: Ethan Randall Date: Thu, 11 Jun 2015 12:58:36 -0400 Subject: [PATCH 1/3] mac patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit patches Intel HD Graphics 5000 (OS X 10.10.3) issue where OpenGL version 2.4 is parsed as 1.0 makes win32api only import if platform is win32 (other platforms don’t have it and won’t use it) --- src/mcedit2/util/directories.py | 9 +++++++-- src/mcedit2/util/qglcontext.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mcedit2/util/directories.py b/src/mcedit2/util/directories.py index e5bfa783..2392c118 100644 --- a/src/mcedit2/util/directories.py +++ b/src/mcedit2/util/directories.py @@ -1,7 +1,12 @@ import os import sys -import win32api - +try: + assert sys.platform == "win32" + # If sys.platform is "win32", win32api is needed and expected + import win32api +except AssertionError as _ae: + # If sys.platform is not "win32", do not try to import win32api + win32api = None def getUserFilesDirectory(): if sys.platform == "win32": diff --git a/src/mcedit2/util/qglcontext.py b/src/mcedit2/util/qglcontext.py index bd7f50ca..13cabaee 100644 --- a/src/mcedit2/util/qglcontext.py +++ b/src/mcedit2/util/qglcontext.py @@ -5,6 +5,7 @@ from OpenGL import GL from PySide import QtOpenGL, QtGui import logging +from sys import platform log = logging.getLogger(__name__) @@ -37,6 +38,16 @@ def validateQGLContext(context): actualFormat = context.format() """:type : QtOpenGL.QGLFormat""" + def getmajor(): + return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[0]) + + def getminor(): + return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[2]) + + if platform == 'darwin': + actualFormat.majorVersion = getmajor + actualFormat.minorVersion = getminor + detailedText = "Obtained a GL context with this format:\n" detailedText += "Valid: %s\n" % (context.isValid(),) detailedText += "Version: %s.%s\n" % (actualFormat.majorVersion(), actualFormat.minorVersion()) From ddb22ea8727ec553d70e6a3edd85c2139083e14a Mon Sep 17 00:00:00 2001 From: Ethan Randall Date: Sat, 3 Oct 2020 15:32:10 +0000 Subject: [PATCH 2/3] Fixed building on MacOS 10.10 Yosemite --- requirements.txt | 4 ++-- steal_qt.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 steal_qt.py diff --git a/requirements.txt b/requirements.txt index 82e951a8..1cd1fe7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -r requirements-mceditlib.txt pyzmq==15.0.0 # v15.4.0 fails to freeze with PyInstaller - see pyinstaller/issues/2147 -pyside>=1.2.0 ; sys.platform != 'darwin' # install this via homebrew, not visible to pip +pyside>=1.2.0 ; sys.platform != 'darwin' # install this via homebrew or macports, not visible to pip pyopengl ipython -qtconsole +qtconsole==4.1.1 # later versions may require higher versions of pyzmq pygments pastebin raven diff --git a/steal_qt.py b/steal_qt.py new file mode 100644 index 00000000..900340fe --- /dev/null +++ b/steal_qt.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# The following file is for fixing the build environment on Mac OS 10.10 Yosemite. It may work +# Steal PySide stuff from MacPorts install locations since HomeBrew dropped support for Yosemite! +# Before running this script, install the following ports using MacPorts: (sudo port install FOO) +# py27-pyside-tools +# py27-pyside +from __future__ import print_function + +__author__ = 'ethan' + +import collections +import os +import shutil +import subprocess + +PathSub_T = collections.namedtuple('PathSub_T', ['old_root', 'new_root']) + +VENV_DIR = os.path.abspath(os.getenv('VIRTUAL_ENV', None)) +assert os.path.isdir(VENV_DIR) # Ensure the virtual env is functional + + +def steal_port(port_name, path_subs): + print("Stealing {}".format(port_name)) + port_contents = [p.strip() for p in subprocess.check_output(['port', '-q', 'contents', port_name]).splitlines()] + for port_content_path in port_contents: + for path_sub in path_subs: # type: PathSub_T + if port_content_path.startswith(path_sub.old_root): + new_content_path = port_content_path.replace(path_sub.old_root, path_sub.new_root, 1) + + if os.path.exists(new_content_path): + print(" --> Skipping re-copying {} -> {}".format(port_content_path, new_content_path)) + else: + if not os.path.isdir(os.path.dirname(new_content_path)): + os.makedirs(os.path.dirname(new_content_path)) + print(" --> Copying {} -> {}".format(port_content_path, new_content_path)) + shutil.copy(port_content_path, new_content_path) + break + else: + print(" --> No steal rule for {}".format(port_content_path)) + print(" --> Done stealing {}".format(port_name)) + + +def main(): + steal_port('py27-pyside-tools', + [PathSub_T('/opt/local/Library/Frameworks/Python.framework/Versions/2.7', VENV_DIR), + PathSub_T('/opt/local/bin', os.path.join(VENV_DIR, 'bin'))] + ) + + steal_port('py27-pyside', + [PathSub_T('/opt/local/Library/Frameworks/Python.framework/Versions/2.7', VENV_DIR), + PathSub_T('/opt/local/include', os.path.join(VENV_DIR, 'include')), + PathSub_T('/opt/local/lib/', os.path.join(VENV_DIR, 'lib')), + PathSub_T('/opt/local/share', os.path.join(VENV_DIR, 'share')) + ] + ) + + +if __name__ == '__main__': + main() From 2813d0646e9d1b6e2decd552d9175bd8ed87bfa7 Mon Sep 17 00:00:00 2001 From: Ethan Randall Date: Sat, 3 Oct 2020 15:37:30 +0000 Subject: [PATCH 3/3] Revert "Merge branch 'master' of https://github.com/iJunkie22/mcedit2" This reverts commit 480bf7198c0e2b5cb5bf8eb88fa84b34b7ba8361, reversing changes made to ddb22ea8727ec553d70e6a3edd85c2139083e14a. --- src/mcedit2/util/directories.py | 46 ------------------------- src/mcedit2/util/qglcontext.py | 59 +++++++++++++++------------------ 2 files changed, 26 insertions(+), 79 deletions(-) delete mode 100644 src/mcedit2/util/directories.py diff --git a/src/mcedit2/util/directories.py b/src/mcedit2/util/directories.py deleted file mode 100644 index 2392c118..00000000 --- a/src/mcedit2/util/directories.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import sys -try: - assert sys.platform == "win32" - # If sys.platform is "win32", win32api is needed and expected - import win32api -except AssertionError as _ae: - # If sys.platform is not "win32", do not try to import win32api - win32api = None - -def getUserFilesDirectory(): - if sys.platform == "win32": - # On Windows, sys.executable is codepage-encoded. - # It cannot represent all possible filenames, so get the exe filename - # using this wide-character API, which returns a `unicode` - exe = win32api.GetModuleFileNameW(None) - else: - # On OS X, the FS encoding is always UTF-8 - # OS X filenames are defined to be UTF-8 encoded. - # On Linux, the FS encoding is given by the current locale - # Linux filenames are defined to be bytestrings. - exe = sys.executable.decode(sys.getfilesystemencoding()) - - assert os.path.exists(exe), "%r does not exist" % exe - if hasattr(sys, 'frozen'): - folder = os.path.dirname(exe) - else: - if exe.endswith("python") or exe.endswith("python.exe"): - script = sys.argv[0] - # assert the source checkout is not in a non-representable path... - assert os.path.exists(script), "Source checkout path cannot be represented with 'mbcs' encoding. Put the source checkout somewhere else." - folder = os.path.dirname(os.path.dirname(os.path.dirname(script))) # from src/mcedit, ../../ - else: - folder = os.path.dirname(exe) - - dataDir = os.path.join(folder, "MCEdit User Data") - - if not os.path.exists(dataDir): - os.makedirs(dataDir) - return dataDir - -def getUserSchematicsDirectory(): - return os.path.join(getUserFilesDirectory(), "schematics") - -def getUserPluginsDirectory(): - return os.path.join(getUserFilesDirectory(), "plugins") diff --git a/src/mcedit2/util/qglcontext.py b/src/mcedit2/util/qglcontext.py index 13cabaee..7604fff5 100644 --- a/src/mcedit2/util/qglcontext.py +++ b/src/mcedit2/util/qglcontext.py @@ -5,48 +5,37 @@ from OpenGL import GL from PySide import QtOpenGL, QtGui import logging -from sys import platform +import re log = logging.getLogger(__name__) +_lastAcquiredContextInfo = None + +def getContextInfo(): + return _lastAcquiredContextInfo + def setDefaultFormat(): oglFormat = QtOpenGL.QGLFormat() oglFormat.setVersion(1, 3) oglFormat.setDirectRendering(True) QtOpenGL.QGLFormat.setDefaultFormat(oglFormat) -def validateQGLContext(context): +def validateWidgetQGLContext(widget): + context = widget.context() context.makeCurrent() - versionFlags = QtOpenGL.QGLFormat.openGLVersionFlags() - log.info("OpenGL Version Info:") - for flag in ( - QtOpenGL.QGLFormat.OpenGL_Version_1_1, - QtOpenGL.QGLFormat.OpenGL_Version_1_2, - QtOpenGL.QGLFormat.OpenGL_Version_1_3, - QtOpenGL.QGLFormat.OpenGL_Version_1_4, - QtOpenGL.QGLFormat.OpenGL_Version_1_5, - QtOpenGL.QGLFormat.OpenGL_Version_2_0, - QtOpenGL.QGLFormat.OpenGL_Version_3_0, - QtOpenGL.QGLFormat.OpenGL_Version_3_1, - QtOpenGL.QGLFormat.OpenGL_Version_3_2, - QtOpenGL.QGLFormat.OpenGL_Version_3_3, - QtOpenGL.QGLFormat.OpenGL_Version_4_0, - ): - if flag & versionFlags: - log.info(str(flag)) actualFormat = context.format() """:type : QtOpenGL.QGLFormat""" - def getmajor(): - return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[0]) - - def getminor(): - return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[2]) - - if platform == 'darwin': - actualFormat.majorVersion = getmajor - actualFormat.minorVersion = getminor + # Qt 4.8.6 on OS X always returns (1, 0) for the QGLFormat's major and minor versions. + # (QTBUG-40415) + # Check GL_VERSION instead. + + version = GL.glGetString(GL.GL_VERSION) + match = re.match(r'^(\d+)\.(\d+)', version) + major, minor = match.groups() + major = int(major) + minor = int(minor) detailedText = "Obtained a GL context with this format:\n" detailedText += "Valid: %s\n" % (context.isValid(),) @@ -54,17 +43,21 @@ def getminor(): detailedText += "Hardware Accelerated: %s\n" % (actualFormat.directRendering(), ) detailedText += "Depth buffer: %s, %s\n" % (actualFormat.depth(), actualFormat.depthBufferSize()) detailedText += "Double buffer: %s\n" % (actualFormat.doubleBuffer(), ) + detailedText += "Rendering profile: %s\n" % (actualFormat.profile(), ) detailedText += "\n" detailedText += "Driver info:\n" - detailedText += "GL_VERSION: %s\n" % GL.glGetString(GL.GL_VERSION) - detailedText += "GL_VENDOR: %s\n" % GL.glGetString(GL.GL_VENDOR) - detailedText += "GL_RENDERER: %s\n" % GL.glGetString(GL.GL_RENDERER) + detailedText += "GL_VERSION: %s (%s, %s)\n" % (version, major, minor) + detailedText += "GL_VENDOR: %r\n" % GL.glGetString(GL.GL_VENDOR) + detailedText += "GL_RENDERER: %r\n" % GL.glGetString(GL.GL_RENDERER) log.info("%s", detailedText) - + global _lastAcquiredContextInfo + _lastAcquiredContextInfo = detailedText + versionFlags = QtOpenGL.QGLFormat.openGLVersionFlags() + if (not context.isValid() or not actualFormat.directRendering() or not versionFlags & QtOpenGL.QGLFormat.OpenGL_Version_1_3 - or (actualFormat.majorVersion(), actualFormat.minorVersion()) < (1, 3)): + or (major, minor) < (1, 3)): msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(QtGui.qApp.tr("OpenGL Error")) msgBox.setStandardButtons(QtGui.QMessageBox.Close)