issueing a warning

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

issueing a warning

Post by hproe »

Hi -

In a scripts that saves image I append a colour bar, identfied by the Id 'thisColourBar' like:

Code: Select all

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")

I would like to issue a warning to set this Id before the saving starts. I tired to do this with:

Code: Select all

JOptionPane.showMessageDialog(JFrame(),"Colour bar?","beware",JOptionPane.QUESTION_MESSAGE)

However, this message blocks any manual interaction until an 'OK' is given and the saving is starting, i.e. too late for a corrective measure if the Id has not been given beforehand. Any idea how this could be handled?

thanks, HP
User avatar
bobc
Posts: 988
Joined: Mon Nov 15, 2010 5:57 pm

Re: issueing a warning

Post by bobc »

Hi HP -

I'm testing this using your svImageSeq function from your script saving an image sequence does not work correctly forum post. Thus far, I'm seeing the same results that you are. Before digging into this too far, can you clarify something for me?

Are you looking to pop up a warning that would allow the user to set the display ID mid-script and then continue on?

Or are you trying to give a user a way to exit out of the script before going to the writeImageAtIndex portion if they forgot to enter display ID?

Thanks -
Bob Carp
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: issueing a warning

Post by Jon »

Hi HP,

My attempt at adding this to your svImageSeq function:

https://gist.github.com/jon4than/216bc360b2536131578a

Here's a convenient view that highlights what I added (plus two apparent spacing differences that don't really matter):

https://gist.github.com/jon4than/216bc3 ... /revisions

That said, I'd recommend throwing an exception rather than showing the dialog. It allows you to write code to "catch" if/when svImageSeq fails, and the JOptionPane may not work as expected if you are running your script in the background.

Here's an example that uses exceptions:

https://gist.github.com/jon4than/890995ffc5af453c237f

And here are the highlighted additions:

https://gist.github.com/jon4than/890995 ... /revisions

Yet another thing to try...if you have a reference to the layer (like "imLayer = imDisplay.getLayer(1)"), you could set the layer's ID to "thisColourBar" yourself. The only concern is dealing with the situation when someone has specified their own layer ID prior to running the script. I had to implement something very similar to this for McV's captureImage (and its "islformatters")--I'd be happy to describe it if you think it might help.
User avatar
bobc
Posts: 988
Joined: Mon Nov 15, 2010 5:57 pm

Re: issueing a warning

Post by bobc »

Hi HP -

Here's another alternative method I came up with. This pops up a dialog box asking if the layer ID has been set. If 'Yes' is chosen, the script runs. If 'No' is chosen, the script terminates and tells the user to specify a layer ID before running the script again.

Code: Select all

 # If switch=3, ask user if layer ID has been set.  If yes, continue.  If no, terminate script.
 if switch == 3:
  idSet = JOptionPane.showConfirmDialog(None,"Did you define the layer ID?","Layer ID Defined",JOptionPane.YES_NO_OPTION)
  if idSet == 0:
    print 'Script will continue.'
  else:
    sys.exit('Script terminating.  Set layer ID and run script again.')

I added this to the beginning of the svImageSeq function. I didn't change anything else in the script, so this assumes that the layer ID (if set) is set to 'thisColourBar'.

- Bob
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

Re: issueing a warning

Post by hproe »

Good people -

Many thanks for the suggestions. I have implemented Jonathan's 2nd proposal, i.e. I raise an exception.

cheers, HP
Post Reply