-
-
Save jon4than/216bc360b2536131578a to your computer and use it in GitHub Desktop.
JOptionPane Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def svImageSeq(switch,imRelPath,fnPostfix,imPrefix,tickNumber,frWidth,frHeight,viewPoint): | |
""" HansPeter Roesli | |
2013-04-12 | |
Captures an image sequence from the active display in png format, | |
using filename template, | |
with given frame width/height and viewpoint, | |
options for label at the bottom and colour bar at the top | |
of the images (colour bar to be shown has to be marked | |
with id=thisColourBar. | |
Arguments: | |
switch=0: keep layer label | |
switch=1: delete layer label | |
switch=2: delete layer label, | |
add text label below image | |
switch=3: delete layer label, | |
add text label below image, | |
add colour bar above image | |
(set Id in proeprties of image display to | |
'thisColourBar') | |
imRelPath: path to output files relative to home directory | |
fnPostfix: text string to follow standard date/time | |
string in fileName | |
imPrefix: text string to precede date/time string | |
tickNumber: number of ticks in colour bar | |
frWidth: width of "full-screen" frame | |
frHeight: height of "full-screen" frame (for switch=2/3 | |
adds 20 / 36 lines for banners at bottom / top) | |
viewPoint: must exist in the list at | |
Projection>Viewpoints | |
Returns: | |
nothing | |
Sample call: | |
svImageSeq(2,"/Desktop/test/","_MedLow-ME","m9 AIRM - ",7,520,320,"CH") | |
creates: | |
files: <YYYYmmDDhhMM>_m9-AIRM_MedLow-ME.png | |
directory: <home>/Desktop/test/ | |
layer label: disabled | |
image label: m9 IR10.8 - <YYYY-mm-DD hh:MMUTC> | |
colour bar: 7 tick marks | |
image frame: 520x320 pixel | |
viewPoint: CH | |
""" | |
# search for thisColourBar prior to doing any work | |
if switch == 3 and not islInterpreter.findDisplayControl('thisColourBar'): | |
from javax.swing.JOptionPane import showMessageDialog, QUESTION_MESSAGE | |
showMessageDialog(None, "Colour bar?", "beware", QUESTION_MESSAGE) | |
return | |
import time | |
# pick up number of tick marks | |
# special syntax requirement! | |
tickNumbers = str(tickNumber) | |
# define heights of matte for label and colour bar | |
lHeight = 20 # I like these | |
cHeight = 36 # ... values | |
lHeights = str(lHeight)# special syntax requirement! | |
cHeights = str(cHeight)# special syntax requirement! | |
# derive absolute save path | |
homeDir = os.path.expanduser('~') # OS-independent root of save path | |
imPath = homeDir + imRelPath | |
# if path does not exist, create it | |
if not os.path.exists(imPath): | |
os.makedirs(imPath) | |
print "image(s) saved in: ", imPath | |
# get display controls | |
imDisplay = activeDisplay() | |
imLayer = imDisplay.getLayer(1) | |
imLayerVM = imLayer.getViewManager() | |
# set width of "full-screen" frame, adapt height to presence of image label and | |
# colour bar(s) | |
imLayerVM.setFullScreenWidth(int(frWidth)) | |
if switch < 2: | |
imLayerVM.setFullScreenHeight(int(frHeight)) | |
if switch == 2: # compensate for matte height (keep multiple-8) | |
imLayerVM.setFullScreenHeight(int(frHeight-lHeight)) | |
if switch == 3: # compensate for matte height (keep multiple-8) | |
imLayerVM.setFullScreenHeight(int(frHeight-(lHeight+cHeight))) | |
# for not better identified reason a print command is needed here | |
print '' | |
# go "full-screen" | |
imLayerVM.setFullScreen() # go "full-screen" | |
# make sure display label is off/on | |
imControls=imDisplay.getControls() | |
print type(imControls) | |
print type(imControls[1]) | |
if switch > 0: | |
imControls[1].setShowInDisplayList(0) # off | |
else: | |
imControls[1].setShowInDisplayList(1) # on | |
imLayerVM.setFullScreen() # go "full-screen" | |
if switch > 0: | |
imLayer.setLayerLabel(visible=False) | |
else: | |
imLayer.setLayerLabel(visible=True) | |
# set viewpoint to an item in list of saved viewpoints at Projection>Viewpoints | |
imDisplay.setViewpoint(viewPoint) | |
# get parameters of image sequence | |
imAnim=imDisplay.getAnimation() | |
imTimes=imAnim.getTimes() | |
imSteps=imAnim.getNumSteps() | |
# start saving from beginning of sequence | |
imAnim.setCurrent(0) | |
# time.sleep(5) # let things settle | |
pause() | |
imControls[1].notifyViewManagersOfChange() | |
# go through sequence and save frames | |
for image in range(imSteps): | |
idx = imAnim.getCurrent() | |
strTime = str(imTimes[image]) # compose date-time string for filename | |
HH, mm, SS = imTimes[image].timeString().split(":") | |
yyyy, MM, dd = imTimes[image].dateString().split("-") | |
dString = yyyy + MM + dd + HH + mm | |
fileName = imPath + dString + fnPostfix + ".png" # final filename | |
print idx, ' ', fileName | |
imLabel = imPrefix + strTime # compose image label | |
if switch < 2: # plain image with(out) layer label | |
writeImageAtIndex(fileName, idx) | |
if switch == 2: # add image label (bottom) | |
writeImageAtIndex(fileName, idx, \ | |
"matte background=white bottom="+lHeights+";\ | |
overlay text="+imLabel+" anchor=LM place=LM,0,-5 color=black fontsize=12 fontface=Tahoma bold") | |
if switch == 3: # add image label (bottom) and colour bar (top) | |
writeImageAtIndex(fileName, idx, \ | |
"matte background=white top="+cHeights+";\ | |
colorbar display=thisColourBar width=560 height=12 anchor=UM place=UM,0,2 showlines=true tickmarks="+tickNumbers+" showunit=true fontsize=12 Fontface=Tahoma bold;\ | |
matte background=white bottom="+lHeights+";\ | |
overlay text="+imLabel+" anchor=LM place=LM,0,-5 color=black fontsize=12 fontface=Tahoma bold") | |
# time.sleep(2) | |
imAnim.takeStep() # step on | |
pause() | |
imControls[1].notifyViewManagersOfChange() | |
# reset to original display (in case saving has to be repeated) | |
imLayerVM.resetFullScreen() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment