def show_version(): print("[Pyslvs " + version_number + "]", "Python Version: {0:d}.{1:d}.{2:d}".format(*version_info[:3])) try: try: from PyQt5.QtCore import qVersion except: from PyQt4.QtCore import qVersion print("Qt Version: {0}".format(qVersion().strip())) except: print("No Qt.") try: try: from PyQt5.QtCore import PYQT_VERSION_STR as pyqtVersion except: from PyQt4.QtCore import PYQT_VERSION_STR as pyqtVersion print("PyQt Version:", pyqtVersion.strip()) except: print("No PyQt.") try: from sip import SIP_VERSION_STR as sipVersion print("Sip Version:", sipVersion.strip()) except: print("No Sip.") try: try: from PyQt5.Qsci import QSCINTILLA_VERSION_STR as qsciVersion except: from PyQt4.Qsci import QSCINTILLA_VERSION_STR as qsciVersion print("QScintilla Version:", qsciVersion.strip()) except: print("No QScintilla.") print("-------")
def compat_getFrameDimensions(frame, cbname): if PYQT_VERSION_STR.startswith('4'): girth, ok = frame.evaluateJavaScript('document.getElementById("%s").offsetWidth;' % cbname).toInt() height, ok = frame.evaluateJavaScript('document.getElementById("%s").offsetHeight;' % cbname).toInt() else: girth = int(frame.evaluateJavaScript('document.getElementById("%s").offsetWidth;' % cbname)) height = frame.evaluateJavaScript('document.getElementById("%s").offsetHeight;' % cbname) return girth, height
def compat_isNone(state): if PYQT_VERSION_STR.startswith('4'): return state.isNull() # WTF! (QByteArray == None) is True! if state is None: return True return not len(state)
def initialize(self) -> None: super().initialize() self._mesh_file_handler = MeshFileHandler(self) #type: MeshFileHandler self._workspace_file_handler = WorkspaceFileHandler(self) #type: WorkspaceFileHandler # For some reason, with Qt 5.9 and up, the default "windows" style seems like Windows 95. We have to set the # style to "fusion" so it looks less ugly. pyqt_version_parts = [int(n) for n in PYQT_VERSION_STR.split(".")] if len(pyqt_version_parts) < 2: # Make sure there are at less 2 parts in the version pyqt_version_parts += [0 for _ in range(2 - len(pyqt_version_parts))] if pyqt_version_parts[0] == 5 and pyqt_version_parts[1] > 8: self.setStyle("fusion") # For some reason, with Qt 5.9 and up, the default "windows" style seems like Windows 95. We have to set the # style to "fusion" so it looks less ugly. pyqt_version_parts = [int(n) for n in PYQT_VERSION_STR.split(".")] if len(pyqt_version_parts) < 2: # Make sure there are at less 2 parts in the version pyqt_version_parts += [0 for _ in range(2 - len(pyqt_version_parts))] if pyqt_version_parts[0] == 5 and pyqt_version_parts[1] > 8: self.setStyle("fusion") self.setAttribute(Qt.AA_UseDesktopOpenGL) major_version, minor_version, profile = OpenGLContext.detectBestOpenGLVersion() if major_version is None and minor_version is None and profile is None: Logger.log("e", "Startup failed because OpenGL version probing has failed: tried to create a 2.0 and 4.1 context. Exiting") QMessageBox.critical(None, "Failed to probe OpenGL", "Could not probe OpenGL. This program requires OpenGL 2.0 or higher. Please check your video card drivers.") sys.exit(1) else: opengl_version_str = OpenGLContext.versionAsText(major_version, minor_version, profile) Logger.log("d", "Detected most suitable OpenGL context version: %s", opengl_version_str) OpenGLContext.setDefaultFormat(major_version, minor_version, profile = profile) self._qml_import_paths.append(os.path.join(os.path.dirname(sys.executable), "qml")) self._qml_import_paths.append(os.path.join(self.getInstallPrefix(), "Resources", "qml")) Logger.log("i", "Initializing job queue ...") self._job_queue = JobQueue() self._job_queue.jobFinished.connect(self._onJobFinished) Logger.log("i", "Initializing version upgrade manager ...") self._version_upgrade_manager = VersionUpgradeManager(self)
def compat_strList(dwcls): if PYQT_VERSION_STR.startswith('4'): return dwcls.toStringList() return dwcls
def compat_toByteArray(strobj): if PYQT_VERSION_STR.startswith('4'): return strobj.toByteArray() return strobj
def compat_toStr(qstate): if PYQT_VERSION_STR.startswith('4'): return str(qstate.toString()) return str(qstate)
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA print('Qtvcp python plugin found:',__file__) # HAL only widgets from qtvcp.plugins.simplewidgets_plugin import * from qtvcp.plugins.led_plugin import LEDPlugin from qtvcp.plugins.hal_label_plugin import HALLabelPlugin from qtvcp.plugins.detach_tabs_plugin import DetachTabWidgetPlugin from qtvcp.plugins.round_progress_bar_plugin import RoundProgressBarPlugin from PyQt5.QtCore import PYQT_VERSION_STR try: v = PYQT_VERSION_STR.split('.') if int(v[1]) > 10: from qtvcp.plugins.joypad_plugin import * except: print('PyQt version {} to old for JoyPad widget'.format(PYQT_VERSION_STR)) # plain widgets from qtvcp.plugins.nurbs_editor_plugin import NurbsEditorPlugin # Linuxcnc widgets from qtvcp.plugins.container_plugin import StateEnableGridLayoutPlugin from qtvcp.plugins.container_plugin import JointEnableWidgetPlugin from qtvcp.plugins.graphics_plugin import GCodeGraphicsPlugin from qtvcp.plugins.widgets_plugin import * from qtvcp.plugins.state_led_plugin import StateLEDPlugin from qtvcp.plugins.status_label_plugin import StatusLabelPlugin
try: sip.setapi('QString', 2) sip.setapi('QVariant', 2) except AttributeError: # PyQt < v4.6. The actual check is done by requirements.check_qt() # call from spyder.py pass try: from PyQt4.QtCore import PYQT_VERSION_STR as __version__ # analysis:ignore except ImportError: # Switching to PySide API = os.environ['QT_API'] = 'pyside' API_NAME = 'PySide' else: is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7')) is_pyqt46 = __version__.startswith('4.6') import sip try: API_NAME += (" (API v%d)" % sip.getapi('QString')) except AttributeError: pass if API == 'pyside': try: from PySide import __version__ # analysis:ignore except ImportError: raise ImportError("Spyder requires PySide or PyQt to be installed") else: is_old_pyqt = is_pyqt46 = False
sip.setapi('QDateTime', 2) sip.setapi('QTextStream', 2) sip.setapi('QTime', 2) sip.setapi('QUrl', 2) except (AttributeError, ValueError): # PyQt < v4.6 pass from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore from PyQt4.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore PYSIDE_VERSION = None PYQT5 = False PYQT4 = True except ImportError: API = os.environ['QT_API'] = 'pyside' else: is_old_pyqt = PYQT_VERSION.startswith(('4.4', '4.5', '4.6', '4.7')) is_pyqt46 = PYQT_VERSION.startswith('4.6') if API in PYSIDE_API: try: from PySide import __version__ as PYSIDE_VERSION # analysis:ignore from PySide.QtCore import __version__ as QT_VERSION # analysis:ignore PYQT_VERSION = None PYQT5 = PYSIDE2 = False PYSIDE = True except ImportError: raise PythonQtError('No Qt bindings could be found') # If a correct API name is passed to QT_API and it could not be found, # switches to another and informs through the warning if API != initial_api and binding_specified:
# Qt内嵌谷歌引擎BUG太多,实在是不好用->改用开源谷歌引擎 目前部分替换 from PyQt5.QtCore import PYQT_VERSION_STR, QCoreApplication, Qt, QProcess # 判断版本号 if int(PYQT_VERSION_STR.replace('.', '')) >= 560: from PyQt5.QtWebEngineWidgets import * # 处理闪屏、黑屏问题 必须放在 Application 实例化前 QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL) else: from PyQt5.QtWebKit import * from PyQt5.QtWebKitWidgets import * import multiprocessing, requests, platform, ctypes from multiprocessing import Process, Queue from importlib import import_module from utils.envir import * # 主界面 def main_ui(ui, app): if gol.get_value('ui_show', 0) == 0: ui.showMaximized() elif gol.get_value('ui_show', 0) == 1: ui.showFullScreen() else: ui.show() app.exec_() # def equip_ui(ui, app): ui.show()
the correct python and PyQt versions. In case this fails, error messages are written to stderr and we exit with returncode ERR_CODE. Module Attributes: PYQT_VERSION: The currently installed PyQt version as tuple if any. PYQT_REQUIRED_VERSION: The minimum PyQt version required. PYTHON_REQUIRED_VERSION: The minimum python version required. ERR_CODE: Returncode used with sys.exit. """ import sys try: from PyQt5.QtCore import PYQT_VERSION_STR PYQT_VERSION = tuple(map(int, PYQT_VERSION_STR.split("."))) except ImportError: # pragma: no cover # PyQt is there in tests, using None is tested # We check explicitly for None before using the tuple version PYQT_VERSION = None # type: ignore PYTHON_REQUIRED_VERSION = (3, 6) PYQT_REQUIRED_VERSION = (5, 9, 2) ERR_CODE = 2 def check_python_version(): """Ensure the python version is new enough.""" if sys.version_info < PYTHON_REQUIRED_VERSION: _exit_version("python", PYTHON_REQUIRED_VERSION, sys.version_info[:3])
##but WITHOUT ANY WARRANTY; without even the implied warranty of ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##GNU Affero General Public License for more details. ## ##You should have received a copy of the GNU Affero General Public License ##along with this program; if not, write to the Free Software ##Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from sys import version_info import platform import argparse import requests try: from PyQt5.QtCore import qVersion, PYQT_VERSION_STR Qt_Version = qVersion().strip() PyQt_Version = PYQT_VERSION_STR.strip() except ImportError: Qt_Version = "No Qt" PyQt_Version = "No PyQt" VERSION = (18, 2, 0, 'release') INFO = ( "Pyslvs {}.{}.{}({})".format(*VERSION), "OS Type: {} {} [{}]".format(platform.system(), platform.release(), platform.machine()), "Python Version: {v.major}.{v.minor}.{v.micro}({v.releaselevel})".format( v=version_info), "Python Compiler: {}".format( platform.python_compiler()), "Qt Version: {}".format(Qt_Version), "PyQt Version: {}".format(PyQt_Version))
sip.setapi("QTextStream", 2) sip.setapi("QTime", 2) sip.setapi("QUrl", 2) except AttributeError: # PyQt < v4.6 pass from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore from PyQt4.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore PYSIDE_VERSION = None PYQT5 = False PYQT4 = True except ImportError: API = os.environ["QT_API"] = "pyside" else: is_old_pyqt = PYQT_VERSION.startswith(("4.4", "4.5", "4.6", "4.7")) is_pyqt46 = PYQT_VERSION.startswith("4.6") if API in PYSIDE_API: try: from PySide import __version__ as PYSIDE_VERSION # analysis:ignore from PySide.QtCore import __version__ as QT_VERSION # analysis:ignore PYQT_VERSION = None PYQT5 = PYSIDE2 = False PYSIDE = True except ImportError: raise PythonQtError("No Qt bindings could be found") # If a correct API name is passed to QT_API and it could not be found, # switches to another and informs through the warning
sip.setapi('QDateTime', 2) sip.setapi('QTextStream', 2) sip.setapi('QTime', 2) sip.setapi('QUrl', 2) except (AttributeError, ValueError): # PyQt < v4.6 pass from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore from PyQt4.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore PYSIDE_VERSION = None PYQT5 = False PYQT4 = True except ImportError: API = os.environ['QT_API'] = 'pyside' else: is_old_pyqt = PYQT_VERSION.startswith(('4.4', '4.5', '4.6', '4.7')) is_pyqt46 = PYQT_VERSION.startswith('4.6') if API in PYSIDE_API: try: from PySide import __version__ as PYSIDE_VERSION # analysis:ignore from PySide.QtCore import __version__ as QT_VERSION # analysis:ignore PYQT_VERSION = None PYQT5 = PYSIDE2 = False PYSIDE = True except ImportError: raise PythonQtError('No Qt bindings could be found') # If a correct API name is passed to QT_API and it could not be found, # switches to another and informs through the warning if API != initial_api:
QDoubleValidator, QFocusEvent, QFont, QKeyEvent, QKeySequence, QIcon, QImage, QImageWriter, QIntValidator, QLinearGradient, QMouseEvent, QMovie, QPainter, QPainterPath, QPalette, QPen, QPixmap, QPolygon, QRegExpValidator, QTextCursor, QValidator) from PyQt5.uic import loadUi QStringList = list getQApp = QCoreApplication.instance qApp = QCoreApplication.instance qt_imported = True qt_variant = "PyQt5" qt_version_no = list(map(int, QT_VERSION_STR.split("."))) _ver = PYQT_VERSION_STR.split(".") ver = _ver + ["0"] * (3 - len(_ver)) pyqt_version_no = list(map(int, ver))[:3] except ImportError: pass try: from PyQt5.QtWebKit import QWebPage except ImportError: pass # # PyQt4 # if (qt_variant == "PyQt4") or (qt_variant is None and not qt_imported): #
from UM.Mesh.ReadMeshJob import ReadMeshJob import UM.Qt.Bindings.Theme from UM.PluginRegistry import PluginRegistry MYPY = False if MYPY: from PyQt5.QtCore import QObject # Raised when we try to use an unsupported version of a dependency. class UnsupportedVersionError(Exception): pass # Check PyQt version, we only support 5.4 or higher. major, minor = PYQT_VERSION_STR.split(".")[0:2] if int(major) < 5 or int(minor) < 4: raise UnsupportedVersionError( "This application requires at least PyQt 5.4.0") ## Application subclass that provides a Qt application object. @signalemitter class QtApplication(QApplication, Application): pluginsLoaded = Signal() applicationRunning = Signal() def __init__(self, tray_icon_name=None, **kwargs): plugin_path = "" if sys.platform == "win32": if hasattr(sys, "frozen"):
sip.setapi('QDateTime', 2) sip.setapi('QTextStream', 2) sip.setapi('QTime', 2) sip.setapi('QUrl', 2) except AttributeError: # PyQt < v4.6. The actual check is done by requirements.check_qt() # call from spyder.py pass from PyQt4.QtCore import PYQT_VERSION_STR as __version__ # analysis:ignore except ImportError: # Switching to PySide API = os.environ['QT_API'] = 'pyside' API_NAME = 'PySide' else: is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7')) is_pyqt46 = __version__.startswith('4.6') import sip try: API_NAME += (" (API v%d)" % sip.getapi('QString')) except AttributeError: pass if API == 'pyside': try: from PySide import __version__ # analysis:ignore except ImportError: raise ImportError("Spyder requires PySide or PyQt to be installed") else: is_old_pyqt = is_pyqt46 = False
from UM.Qt.Bindings.Bindings import Bindings from UM.Signal import Signal, signalemitter from UM.Resources import Resources from UM.Logger import Logger from UM.Preferences import Preferences from UM.i18n import i18nCatalog import UM.Settings.InstanceContainer #For version upgrade to know the version number. import UM.Settings.ContainerStack #For version upgrade to know the version number. import UM.Preferences #For version upgrade to know the version number. # Raised when we try to use an unsupported version of a dependency. class UnsupportedVersionError(Exception): pass # Check PyQt version, we only support 5.4 or higher. major, minor = PYQT_VERSION_STR.split(".")[0:2] if int(major) < 5 or int(minor) < 4: raise UnsupportedVersionError("This application requires at least PyQt 5.4.0") ## Application subclass that provides a Qt application object. @signalemitter class QtApplication(QApplication, Application): def __init__(self, **kwargs): plugin_path = "" if sys.platform == "win32": if hasattr(sys, "frozen"): plugin_path = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "PyQt5", "plugins") Logger.log("i", "Adding QT5 plugin path: %s" % (plugin_path)) QCoreApplication.addLibraryPath(plugin_path) else: import site
QPen, QPixmap, QPolygon, QRegExpValidator, QValidator ) from PyQt5.uic import loadUi QStringList = list getQApp = QCoreApplication.instance qApp = QCoreApplication.instance qt_imported = True qt_variant = "PyQt5" qt_version_no = list(map(int, QT_VERSION_STR.split("."))) _ver = PYQT_VERSION_STR.split(".") ver = _ver + ["0"] * (3 - len(_ver)) pyqt_version_no = list(map(int, ver))[:3] except ImportError: pass try: from PyQt5.QtWebKit import QWebPage except ImportError: pass # # PyQt4 # if (qt_variant == "PyQt4") or (qt_variant is None and not qt_imported): #