2016-01-15 14:55:33 +01:00
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
# Contact: https://www.qt.io/licensing/
|
|
|
|
#
|
|
|
|
# This file is part of Qt Creator.
|
|
|
|
#
|
|
|
|
# Commercial License Usage
|
|
|
|
# Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
# accordance with the commercial license agreement provided with the
|
|
|
|
# Software or, alternatively, in accordance with the terms contained in
|
|
|
|
# a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
# and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
# information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
#
|
|
|
|
# GNU General Public License Usage
|
|
|
|
# Alternatively, this file may be used under the terms of the GNU
|
|
|
|
# General Public License version 3 as published by the Free Software
|
|
|
|
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
# included in the packaging of this file. Please review the following
|
|
|
|
# information to ensure the GNU General Public License requirements will
|
|
|
|
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
#
|
|
|
|
############################################################################
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2016-06-01 10:56:14 +02:00
|
|
|
import __builtin__
|
2013-04-08 14:05:17 +02:00
|
|
|
|
2011-11-29 16:00:18 +01:00
|
|
|
# for easier re-usage (because Python hasn't an enum type)
|
2013-04-05 16:58:06 +02:00
|
|
|
class Targets:
|
2018-08-02 19:55:52 +02:00
|
|
|
ALL_TARGETS = tuple(range(5))
|
2015-03-19 17:22:12 +01:00
|
|
|
|
2018-01-04 12:11:55 +01:00
|
|
|
(DESKTOP_4_8_7_DEFAULT,
|
2015-03-19 17:22:12 +01:00
|
|
|
EMBEDDED_LINUX,
|
2018-01-04 12:11:55 +01:00
|
|
|
DESKTOP_5_4_1_GCC,
|
2018-03-21 22:21:56 +01:00
|
|
|
DESKTOP_5_6_1_DEFAULT,
|
|
|
|
DESKTOP_5_10_1_DEFAULT) = ALL_TARGETS
|
2016-06-01 18:22:05 +02:00
|
|
|
|
2018-08-02 19:55:52 +02:00
|
|
|
__TARGET_NAME_DICT__ = dict(zip(ALL_TARGETS,
|
|
|
|
["Desktop 4.8.7 default",
|
|
|
|
"Embedded Linux",
|
|
|
|
"Desktop 5.4.1 GCC",
|
|
|
|
"Desktop 5.6.1 default",
|
|
|
|
"Desktop 5.10.1 default"]))
|
|
|
|
|
2017-03-02 17:47:20 +01:00
|
|
|
@staticmethod
|
|
|
|
def availableTargetClasses():
|
|
|
|
availableTargets = list(Targets.ALL_TARGETS)
|
|
|
|
if platform.system() in ('Windows', 'Microsoft'):
|
|
|
|
availableTargets.remove(Targets.EMBEDDED_LINUX)
|
|
|
|
elif platform.system() == 'Darwin':
|
2018-01-04 12:11:55 +01:00
|
|
|
availableTargets.remove(Targets.DESKTOP_5_4_1_GCC)
|
2017-03-02 17:47:20 +01:00
|
|
|
return availableTargets
|
|
|
|
|
2013-01-18 16:31:48 +01:00
|
|
|
@staticmethod
|
|
|
|
def desktopTargetClasses():
|
2017-03-02 17:47:20 +01:00
|
|
|
desktopTargets = Targets.availableTargetClasses()
|
|
|
|
if Targets.EMBEDDED_LINUX in desktopTargets:
|
|
|
|
desktopTargets.remove(Targets.EMBEDDED_LINUX)
|
2013-01-18 16:31:48 +01:00
|
|
|
return desktopTargets
|
|
|
|
|
2011-11-29 16:00:18 +01:00
|
|
|
@staticmethod
|
|
|
|
def getStringForTarget(target):
|
2018-08-02 19:55:52 +02:00
|
|
|
return Targets.__TARGET_NAME_DICT__[target]
|
2011-11-29 16:00:18 +01:00
|
|
|
|
2012-02-17 17:10:53 +01:00
|
|
|
@staticmethod
|
|
|
|
def getTargetsAsStrings(targets):
|
|
|
|
if not isinstance(targets, (tuple,list)):
|
|
|
|
test.fatal("Wrong usage... This function handles only tuples or lists.")
|
|
|
|
return None
|
2018-08-02 19:55:52 +02:00
|
|
|
return map(Targets.getStringForTarget, targets)
|
2012-02-17 17:10:53 +01:00
|
|
|
|
2018-08-02 11:26:43 +02:00
|
|
|
@staticmethod
|
|
|
|
def getIdForTargetName(targetName):
|
2018-08-02 19:55:52 +02:00
|
|
|
return {v:k for k, v in Targets.__TARGET_NAME_DICT__.items()}[targetName]
|
2018-08-02 11:26:43 +02:00
|
|
|
|
2014-07-28 16:01:11 +02:00
|
|
|
@staticmethod
|
|
|
|
def getDefaultKit():
|
2018-03-21 22:21:56 +01:00
|
|
|
return Targets.DESKTOP_5_6_1_DEFAULT
|
2014-07-28 16:01:11 +02:00
|
|
|
|
2011-11-29 16:00:18 +01:00
|
|
|
# this class holds some constants for easier usage inside the Projects view
|
|
|
|
class ProjectSettings:
|
|
|
|
BUILD = 1
|
|
|
|
RUN = 2
|
|
|
|
|
|
|
|
# this class defines some constants for the views of the creator's MainWindow
|
|
|
|
class ViewConstants:
|
2016-03-09 14:34:44 +01:00
|
|
|
WELCOME, EDIT, DESIGN, DEBUG, PROJECTS, HELP = range(6)
|
2013-09-25 16:45:17 +02:00
|
|
|
FIRST_AVAILABLE = 0
|
2011-11-29 16:00:18 +01:00
|
|
|
# always adjust the following to the highest value of the available ViewConstants when adding new
|
|
|
|
LAST_AVAILABLE = HELP
|
|
|
|
|
|
|
|
# this function returns a regex of the tooltip of the FancyTabBar elements
|
|
|
|
# this is needed because the keyboard shortcut is OS specific
|
|
|
|
# if the provided argument does not match any of the ViewConstants it returns None
|
|
|
|
@staticmethod
|
|
|
|
def getToolTipForViewTab(viewTab):
|
2014-10-30 15:57:44 +01:00
|
|
|
if viewTab == ViewConstants.WELCOME:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Welcome</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
elif viewTab == ViewConstants.EDIT:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Edit</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
elif viewTab == ViewConstants.DESIGN:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Design</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
elif viewTab == ViewConstants.DEBUG:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Debug</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
elif viewTab == ViewConstants.PROJECTS:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Projects</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
elif viewTab == ViewConstants.HELP:
|
2013-09-18 11:54:08 +02:00
|
|
|
toolTip = ur'Switch to <b>Help</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
|
2011-11-29 16:00:18 +01:00
|
|
|
else:
|
|
|
|
return None
|
2013-09-18 11:54:08 +02:00
|
|
|
return toolTip % (viewTab + 1)
|
2011-11-29 16:00:18 +01:00
|
|
|
|
2014-04-24 16:50:29 +02:00
|
|
|
class LibType:
|
|
|
|
SHARED = 0
|
|
|
|
STATIC = 1
|
|
|
|
QT_PLUGIN = 2
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getStringForLib(libType):
|
|
|
|
if libType == LibType.SHARED:
|
|
|
|
return "Shared Library"
|
|
|
|
if libType == LibType.STATIC:
|
|
|
|
return "Statically Linked Library"
|
|
|
|
if libType == LibType.QT_PLUGIN:
|
|
|
|
return "Qt Plugin"
|
|
|
|
return None
|
2015-06-23 14:39:27 +02:00
|
|
|
|
|
|
|
class Qt5Path:
|
|
|
|
DOCS = 0
|
|
|
|
EXAMPLES = 1
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getPaths(pathSpec):
|
2018-03-21 22:21:56 +01:00
|
|
|
qt5targets = [Targets.DESKTOP_5_6_1_DEFAULT, Targets.DESKTOP_5_10_1_DEFAULT]
|
2016-06-01 17:49:31 +02:00
|
|
|
if platform.system() != 'Darwin':
|
2018-01-04 12:11:55 +01:00
|
|
|
qt5targets.append(Targets.DESKTOP_5_4_1_GCC)
|
2015-06-23 14:39:27 +02:00
|
|
|
if pathSpec == Qt5Path.DOCS:
|
2016-06-01 17:49:31 +02:00
|
|
|
return map(lambda target: Qt5Path.docsPath(target), qt5targets)
|
2015-06-23 14:39:27 +02:00
|
|
|
elif pathSpec == Qt5Path.EXAMPLES:
|
2016-06-01 17:49:31 +02:00
|
|
|
return map(lambda target: Qt5Path.examplesPath(target), qt5targets)
|
2015-06-23 14:39:27 +02:00
|
|
|
else:
|
|
|
|
test.fatal("Unknown pathSpec given: %s" % str(pathSpec))
|
|
|
|
return []
|
2016-06-01 10:56:14 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def __preCheckAndExtractQtVersionStr__(target):
|
|
|
|
if target not in Targets.ALL_TARGETS:
|
2016-07-25 17:49:25 +02:00
|
|
|
raise Exception("Unexpected target '%s'" % str(target))
|
2016-06-01 10:56:14 +02:00
|
|
|
|
2018-01-04 12:11:55 +01:00
|
|
|
matcher = re.match("^Desktop (5\.\\d{1,2}\.\\d{1,2}).*$", Targets.getStringForTarget(target))
|
2016-06-01 10:56:14 +02:00
|
|
|
if matcher is None:
|
|
|
|
raise Exception("Currently this is supported for Desktop Qt5 only, got target '%s'"
|
|
|
|
% str(Targets.getStringForTarget(target)))
|
|
|
|
return matcher.group(1)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def __createPlatformQtPath__(qt5Minor):
|
|
|
|
if platform.system() in ('Microsoft', 'Windows'):
|
|
|
|
return "C:/Qt/Qt5.%d.1" % qt5Minor
|
|
|
|
else:
|
|
|
|
return os.path.expanduser("~/Qt5.%d.1" % qt5Minor)
|
|
|
|
|
|
|
|
@staticmethod
|
2018-01-04 12:11:55 +01:00
|
|
|
def toVersionTuple(versionString):
|
|
|
|
return tuple(map(__builtin__.int, versionString.split(".")))
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getQtMinorAndPatchVersion(target):
|
2016-06-01 10:56:14 +02:00
|
|
|
qtVersionStr = Qt5Path.__preCheckAndExtractQtVersionStr__(target)
|
2018-01-04 12:11:55 +01:00
|
|
|
versionTuple = Qt5Path.toVersionTuple(qtVersionStr)
|
|
|
|
return versionTuple[1], versionTuple[2]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def examplesPath(target):
|
|
|
|
qtMinorVersion, qtPatchVersion = Qt5Path.getQtMinorAndPatchVersion(target)
|
2018-03-21 22:21:56 +01:00
|
|
|
if qtMinorVersion < 10:
|
2016-06-01 10:56:14 +02:00
|
|
|
path = "Examples/Qt-5.%d" % qtMinorVersion
|
2018-03-21 22:21:56 +01:00
|
|
|
else:
|
|
|
|
path = "Examples/Qt-5.%d.%d" % (qtMinorVersion, qtPatchVersion)
|
2016-06-01 10:56:14 +02:00
|
|
|
|
|
|
|
return os.path.join(Qt5Path.__createPlatformQtPath__(qtMinorVersion), path)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def docsPath(target):
|
2018-01-04 12:11:55 +01:00
|
|
|
qtMinorVersion, qtPatchVersion = Qt5Path.getQtMinorAndPatchVersion(target)
|
2018-03-21 22:21:56 +01:00
|
|
|
if qtMinorVersion < 10:
|
2016-06-01 10:56:14 +02:00
|
|
|
path = "Docs/Qt-5.%d" % qtMinorVersion
|
2018-03-21 22:21:56 +01:00
|
|
|
else:
|
|
|
|
path = "Docs/Qt-5.%d.%d" % (qtMinorVersion, qtPatchVersion)
|
2016-06-01 10:56:14 +02:00
|
|
|
|
|
|
|
return os.path.join(Qt5Path.__createPlatformQtPath__(qtMinorVersion), path)
|
2017-09-01 15:23:34 +02:00
|
|
|
|
|
|
|
class TestSection:
|
|
|
|
def __init__(self, description):
|
|
|
|
self.description = description
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
test.startSection(self.description)
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
test.endSection()
|