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
|
|
|
|
2011-11-09 16:40:35 +01:00
|
|
|
# this function switches the MainWindow of creator to the specified view
|
|
|
|
|
def switchViewTo(view):
|
2012-03-27 15:26:38 +02:00
|
|
|
# make sure that no tooltip is shown, so move the mouse away and wait until all disappear
|
|
|
|
|
mouseMove(waitForObject(':Qt Creator_Core::Internal::MainWindow'), -20, -20)
|
2012-03-26 17:21:30 +02:00
|
|
|
waitFor("not QToolTip.isVisible()", 15000)
|
2013-09-25 16:45:17 +02:00
|
|
|
if view < ViewConstants.FIRST_AVAILABLE or view > ViewConstants.LAST_AVAILABLE:
|
2011-11-09 16:40:35 +01:00
|
|
|
return
|
2019-02-04 13:54:54 +01:00
|
|
|
mouseClick(waitForObject("{name='ModeSelector' type='Core::Internal::FancyTabBar' visible='1' "
|
2012-03-26 17:21:30 +02:00
|
|
|
"window=':Qt Creator_Core::Internal::MainWindow'}"), 20, 20 + 52 * view, 0, Qt.LeftButton)
|
2011-11-09 16:40:35 +01:00
|
|
|
|
2018-08-02 11:26:43 +02:00
|
|
|
def __kitIsActivated__(kit):
|
2020-02-11 12:03:19 +01:00
|
|
|
return not ("<h3>Click to activate</h3>" in str(kit.toolTip)
|
|
|
|
|
or "<h3>Kit is unsuited for project</h3>" in str(kit.toolTip))
|
2011-11-09 16:40:35 +01:00
|
|
|
|
2018-08-02 11:26:43 +02:00
|
|
|
# returns a list of the IDs (see class Targets) of all kits
|
|
|
|
|
# which are currently configured for the active project
|
|
|
|
|
# Creator must be in projects mode when calling
|
|
|
|
|
def iterateConfiguredKits():
|
|
|
|
|
treeView = waitForObject(":Projects.ProjectNavigationTreeView")
|
2016-08-05 12:27:28 +02:00
|
|
|
bAndRIndex = getQModelIndexStr("text='Build & Run'", ":Projects.ProjectNavigationTreeView")
|
2018-08-02 11:26:43 +02:00
|
|
|
kitIndices = dumpIndices(treeView.model(), waitForObject(bAndRIndex))
|
|
|
|
|
configuredKitNames = map(lambda t: str(t.data(0)),
|
|
|
|
|
filter(__kitIsActivated__, kitIndices))
|
|
|
|
|
return map(Targets.getIdForTargetName, configuredKitNames)
|
|
|
|
|
|
2016-08-05 12:27:28 +02:00
|
|
|
|
2018-08-02 11:26:43 +02:00
|
|
|
# This function switches to the build or the run settings (inside the Projects view).
|
|
|
|
|
# If you haven't already switched to the Projects view this will raise a LookupError.
|
|
|
|
|
# It will return a boolean value indicating whether the selected Kit was changed by the function.
|
|
|
|
|
# Note that a 'False' return does not indicate any error.
|
|
|
|
|
# param wantedKit specifies the ID of the kit (see class Targets)
|
|
|
|
|
# for which to switch into the specified settings
|
|
|
|
|
# param projectSettings specifies where to switch to (must be one of
|
|
|
|
|
# ProjectSettings.BUILD or ProjectSettings.RUN)
|
|
|
|
|
def switchToBuildOrRunSettingsFor(wantedKit, projectSettings):
|
|
|
|
|
treeView = waitForObject(":Projects.ProjectNavigationTreeView")
|
|
|
|
|
bAndRIndex = getQModelIndexStr("text='Build & Run'", ":Projects.ProjectNavigationTreeView")
|
|
|
|
|
wantedKitName = Targets.getStringForTarget(wantedKit)
|
|
|
|
|
wantedKitIndexString = getQModelIndexStr("text='%s'" % wantedKitName, bAndRIndex)
|
|
|
|
|
if not test.verify(__kitIsActivated__(findObject(wantedKitIndexString)),
|
|
|
|
|
"Verifying target '%s' is enabled." % wantedKitName):
|
|
|
|
|
raise Exception("Kit '%s' is not activated in the project." % wantedKitName)
|
|
|
|
|
index = waitForObject(wantedKitIndexString)
|
|
|
|
|
projectAlreadySelected = index.font.bold
|
|
|
|
|
if projectAlreadySelected:
|
|
|
|
|
test.log("Kit '%s' is already selected." % wantedKitName)
|
|
|
|
|
else:
|
|
|
|
|
test.log("Selecting kit '%s'..." % wantedKitName)
|
|
|
|
|
treeView.scrollTo(index)
|
|
|
|
|
mouseClick(index)
|
2016-08-05 12:27:28 +02:00
|
|
|
|
|
|
|
|
if projectSettings == ProjectSettings.BUILD:
|
2018-08-02 11:26:43 +02:00
|
|
|
settingsIndex = getQModelIndexStr("text='Build'", wantedKitIndexString)
|
2016-08-05 12:27:28 +02:00
|
|
|
elif projectSettings == ProjectSettings.RUN:
|
2018-08-02 11:26:43 +02:00
|
|
|
settingsIndex = getQModelIndexStr("text='Run'", wantedKitIndexString)
|
2011-11-09 16:40:35 +01:00
|
|
|
else:
|
2018-08-02 11:26:43 +02:00
|
|
|
raise Exception("Unexpected projectSettings parameter (%s), needs to be BUILD or RUN."
|
|
|
|
|
% str(projectSettings))
|
2016-08-05 12:27:28 +02:00
|
|
|
mouseClick(waitForObject(settingsIndex))
|
2018-08-02 11:26:43 +02:00
|
|
|
return not projectAlreadySelected
|
2011-11-09 16:40:35 +01:00
|
|
|
|
2011-12-08 11:52:38 +01:00
|
|
|
# this function switches "Run in terminal" on or off in a project's run settings
|
2018-08-02 11:26:43 +02:00
|
|
|
# param wantedKit specifies the ID of the kit to edit (see class Targets)
|
2011-12-08 11:52:38 +01:00
|
|
|
# param runInTerminal specifies if "Run in terminal should be turned on (True) or off (False)
|
2018-08-02 11:26:43 +02:00
|
|
|
def setRunInTerminal(wantedKit, runInTerminal=True):
|
2011-12-08 11:52:38 +01:00
|
|
|
switchViewTo(ViewConstants.PROJECTS)
|
2018-08-02 11:26:43 +02:00
|
|
|
switchToBuildOrRunSettingsFor(wantedKit, ProjectSettings.RUN)
|
2012-07-27 10:00:03 +02:00
|
|
|
ensureChecked("{window=':Qt Creator_Core::Internal::MainWindow' text='Run in terminal'\
|
2011-12-08 11:52:38 +01:00
|
|
|
type='QCheckBox' unnamed='1' visible='1'}", runInTerminal)
|
|
|
|
|
switchViewTo(ViewConstants.EDIT)
|
2012-07-24 11:42:14 +02:00
|
|
|
|
2012-08-10 12:21:49 +02:00
|
|
|
def __getTargetFromToolTip__(toolTip):
|
2021-10-29 14:38:35 +02:00
|
|
|
if toolTip == None or not isString(toolTip):
|
|
|
|
|
test.warning("Parameter toolTip must be of type str and can't be None!")
|
2012-08-10 12:21:49 +02:00
|
|
|
return None
|
2012-11-19 17:10:31 +01:00
|
|
|
pattern = re.compile(".*<b>Kit:</b>(.*)<b>Deploy.*")
|
2012-08-10 12:21:49 +02:00
|
|
|
target = pattern.match(toolTip)
|
|
|
|
|
if target == None:
|
|
|
|
|
test.fatal("UI seems to have changed - expected ToolTip does not match.",
|
|
|
|
|
"ToolTip: '%s'" % toolTip)
|
|
|
|
|
return None
|
|
|
|
|
return target.group(1).split("<br/>")[0].strip()
|
|
|
|
|
|
2013-05-02 15:21:05 +02:00
|
|
|
def getExecutableAndTargetFromToolTip(toolTip):
|
|
|
|
|
target = __getTargetFromToolTip__(toolTip)
|
2021-10-29 14:38:35 +02:00
|
|
|
if toolTip == None or not isString(toolTip):
|
2013-05-02 15:21:05 +02:00
|
|
|
return None, target
|
|
|
|
|
pattern = re.compile('.*<b>Run:</b>(.*)</.*')
|
|
|
|
|
exe = pattern.match(toolTip)
|
|
|
|
|
if exe == None:
|
|
|
|
|
test.fatal("UI seems to have changed - expected ToolTip does not match.",
|
|
|
|
|
"ToolTip: '%s'" % toolTip)
|
|
|
|
|
return None, target
|
|
|
|
|
return exe.group(1).strip(), target
|
|
|
|
|
|
2013-08-23 10:01:59 +02:00
|
|
|
def invokeContextMenuOnProject(projectName, menuItem):
|
|
|
|
|
try:
|
|
|
|
|
projItem = waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", projectName, 3000)
|
|
|
|
|
except:
|
|
|
|
|
try:
|
|
|
|
|
projItem = waitForObjectItem(":Qt Creator_Utils::NavigationTreeView",
|
|
|
|
|
addBranchWildcardToRoot(projectName), 1000)
|
|
|
|
|
except:
|
|
|
|
|
test.fatal("Failed to find root node of the project '%s'." % projectName)
|
|
|
|
|
return
|
|
|
|
|
openItemContextMenu(waitForObject(":Qt Creator_Utils::NavigationTreeView"),
|
|
|
|
|
str(projItem.text).replace("_", "\\_").replace(".", "\\."), 5, 5, 0)
|
2019-12-03 09:36:32 +01:00
|
|
|
activateItem(waitForObjectItem("{name='Project.Menu.Project' type='QMenu' visible='1'}", menuItem))
|
2013-08-23 10:01:59 +02:00
|
|
|
return projItem
|
2016-10-17 15:16:05 +02:00
|
|
|
|
|
|
|
|
def addAndActivateKit(kit):
|
|
|
|
|
bAndRIndex = getQModelIndexStr("text='Build & Run'", ":Projects.ProjectNavigationTreeView")
|
|
|
|
|
kitString = Targets.getStringForTarget(kit)
|
2020-02-18 11:31:25 +01:00
|
|
|
clickToActivate = "<html><body><h3>%s</h3><p><h3>Click to activate</h3>" % kitString
|
2016-10-17 15:16:05 +02:00
|
|
|
switchViewTo(ViewConstants.PROJECTS)
|
|
|
|
|
try:
|
2018-08-02 13:45:34 +02:00
|
|
|
waitForObject(":Projects.ProjectNavigationTreeView")
|
2016-10-17 15:16:05 +02:00
|
|
|
wanted = getQModelIndexStr("text='%s'" % kitString, bAndRIndex)
|
|
|
|
|
index = findObject(wanted)
|
|
|
|
|
if str(index.toolTip).startswith(clickToActivate):
|
|
|
|
|
mouseClick(index)
|
|
|
|
|
test.verify(waitFor("not str(index.toolTip).startswith(clickToActivate)", 1500),
|
|
|
|
|
"Kit added for this project")
|
|
|
|
|
else:
|
|
|
|
|
test.warning("Kit is already added for this project.")
|
|
|
|
|
mouseClick(index)
|
|
|
|
|
test.verify(waitFor("index.font.bold == True", 1500),
|
|
|
|
|
"Verifying whether kit is current active")
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
finally:
|
|
|
|
|
switchViewTo(ViewConstants.EDIT)
|
|
|
|
|
return True
|