Modality with
Scripts
Modality is how windows behave after they are drawn. In general, if a
window is modal, it takes presence, and is usually on top of other windows, and waits for
the user to do something before the next step is taken. Error dialogs are always
modal. A non-modal window can be minimized and will allow other steps to be
taken. Most windows are non-modal. Tables and plots in HEC-DSSVue are not
modal.
The purpose of Oakville.py script is to generate a .png file. When you run it, you do not see the plot. This is assured by closing the plot after it has been saved as a .png file:
# Save the plot and close
plot.saveToPng("C:/temp/Oakville.png")
plot.close() # Do this if you only want the plot
# as a .png and not on screen
Since plots are non-modal, they will close in batch mode regardless if they explicit close or not. However, suppose you want the user to look at the plot instead of just creating a file from it? If you are running interactively, and you do not close the plot, it will stay opened, but in batch it will close when the script is done.
Some windows in HEC-DSSVue are modal by default and some (those that inherit from RmaJFrame) have the function stayOpen() that emulate modality. The stayOpen() function causes the window to wait and stay open until the window is closed. Because of how this function is preformed, stayOpen() cannot be used in an interactive script. It will cause the program to freeze. Plots will stay open automatically when in an interactive mode. An example use for Oakville.py is:
# Display the plot and wait for them to close
plot.stayOpen() # Do not use in an interactive script
An alternative to stayOpen(), which can be used regardless if the window has the stayOpen() capability or not, is to insert a JOptionPane in the script after the window is complete. This will display a dialog for the user to click OK before the script continues. This call is safe for both interactive and batch modes. However, the users has an extra dialog on the screen and must press OK before continuing. An example of JOPtionPane is:
from hec.script import *
from hec.heclib.dss import *
from javax.swing import *
plot = Plot.newPlot()
plot.setSize(600, 500)
…
plot.showPlot()
JOptionPane.showMessageDialog(table,"Press OK when done")
The modality of the primary windows in HEC-DSSVue is shown below.
Modality of the Primary Windows
|
Class |
Modal |
Comment |
|
ListSelection |
No |
Use stayOpen() |
|
Plot (G2dDialog) |
No |
Use stayOpen() |
|
Table (HecDataTable) |
No |
Use stayOpen() |
|
DataEntry |
Yes |
Nothing needed |
|
CompareFiles |
No |
Use stayOpen() |
|
ExcelFrame |
No |
Use stayOpen() |
|
GridInfoFrame |
No |
Use JOptionPane |
|
Math |
No |
Use stayOpen() |
|
Pie Charts |
No |
Use JOptionPane |
|
SelectRecords |
No |
Use stayOpen() |
|
UndeleteRecords |
No |
Use stayOpen() |