TestCenter Reference
ScreenShot.py
Go to the documentation of this file.
2# Copyright 2009, MeVis Medical Solutions AG
3#
4# The user may use this file in accordance with the license agreement provided with
5# the Software or, alternatively, in accordance with the terms contained in a
6# written agreement between the user and MeVis Medical Solutions AG.
7#
8# For further information use the contact form at https://www.mevislab.de/contact
9#
10
11
13
14# -- system imports ----------------------------------------------------------------------------{{{-
15import os
16import sys
17import traceback
18import time
19# ----------------------------------------------------------------------------------------------}}}-
20
21# -- local imports -----------------------------------------------------------------------------{{{-
22import mevis
23
24from TestSupport.TestHelper import TestHelper
25from . import Base, Fields, Image, Logging
26# ----------------------------------------------------------------------------------------------}}}-
27
28# -- def createOffscreenScreenShot -------------------------------------------------------------{{{-
29
40def createOffscreenScreenShot (SONodeName, filename=None, transparencyType=None, size=None, backgroundColor=None):
41 context = TestHelper.getInstance().getHelperContext()
42 modOffRend = context.module('oSSOffscreenRender')
43 if not modOffRend.field('supported').value:
44 Logging.warning('Offscreen rendering is not supported on this hardware. Cannot create screenshot.')
45 return None
46
47 resultDirectory = Base.getResultDirectory()
48
49 # If no filename was given generate one.
50 if not filename:
51 i = 0
52 filename = os.path.join(resultDirectory, "Screenshot_%03d.png")
53 while os.path.isfile(filename % (i)):
54 i += 1
55 path = filename % (i)
56 else:
57 path = os.path.join(resultDirectory, filename)
58
59 if os.path.isfile(path):
60 Logging.error("File with name %s already exists!" % (path))
61 return None
62
63 changeSet = Fields.ChangeSet(context=context)
64 if transparencyType:
65 changeSet.setFieldValue("oSSOffscreenRender.transparencyType", transparencyType)
66 if size:
67 changeSet.setFieldValue("oSSOffscreenRender.size", size)
68 if backgroundColor:
69 changeSet.setFieldValue("oSSOffscreenRender.bgColor", backgroundColor)
70
71 modImgSave = context.module('oSSImgSave')
72
73 modOffRend.field("sceneGraph").connectFrom(Base.getTestCaseContext().field(SONodeName))
74 mevis.MLAB.processInventorQueue()
75 modOffRend.field("update").touch()
76 if not modOffRend.field('output0').isValid():
77 Logging.error('Creation of screenshot failed.')
78 return None
79
80 modImgSave.field("format").value = "PNG"
81 modImgSave.field('filename').value = path
82 modImgSave.field('save').touch()
83
84 return path
85# ----------------------------------------------------------------------------------------------}}}-
86
87# -- def createScreenShot ----------------------------------------------------------------------{{{-
88
89def createScreenShot (window, filename):
90 helperModule = TestHelper.getInstance().getHelperContext()
91
92 pathname = Base.getResultDirectory()
93
94 if not window:
95 Logging.error("ScreenShot failed (no window available)")
96 return
97
98 tabview = window.getTabViewControl()
99 if tabview == None:
100 return
101
102 window.raiseWindow()
103 window.updateFrame()
104
105 for i in range(10):
106 time.sleep(0.002)
107 mevis.MLAB.processEvents(True)
108
109 imgList = []
110 for i in range(0, tabview.countTabs()):
111 tabview.selectTabAtIndex(i)
112
113 mevis.MLAB.priv().repaintWidget(tabview.widget())
114
115 imgName = os.path.join(pathname, filename+"."+str(i)+".png")
116
117 if not window.createScreenshot(imgName):
118 Logging.warning("ScreenShot failed")
119 else:
120 imgList.append(imgName)
121 return imgList
122# ----------------------------------------------------------------------------------------------}}}-
123
124# -- def createScreenShot ----------------------------------------------------------------------{{{-
125
127 context = TestHelper.getInstance().getHelperContext()
128 return context.field('oSSOffscreenRender.supported').value
129
130# ----------------------------------------------------------------------------------------------}}}-
131
Class to handle field changes and make them revertable.
Definition ChangeSet.py:33
canCreateScreenshot()
Returns whether a screenshot can be created on this hardware.
createOffscreenScreenShot(SONodeName, filename=None, transparencyType=None, size=None, backgroundColor=None)
Create an screenshot of the given Inventor node that must be present in the given context.
Definition ScreenShot.py:40
createScreenShot(window, filename)
Create a screenshot of the given MeVisLab window.
Definition ScreenShot.py:89