# to use the functionality in this file, import it into a .jy script using # # execfile('LibInterac.jy') # # at or near the top of the .jy script in question. # To-Do: # # - find a way to set the length of the label via some sort of call from the # main program. # # - turn the whole thing into a class, or somesuch...? # from javax.swing import JPanel, JButton, JDialog, JCheckBox, JLabel, SwingConstants, BorderFactory from java.awt import BorderLayout, GridLayout # set up interactivity. def contAction(evt): contAction.pause = False return contAction.pause def quitAction(evt): quitAction.stop = True return quitAction.stop def Interact_SetLabel(Str): Interact_Init.textLabel.setText(Str) return True def Interact_ContinueAfterInput(): contAction.pause = True Interact_Init.contBut.setEnabled(True) Interact_Init.quitBut.setEnabled(True) Interact_Init.textLabel.setText('Modify plot, if desired.') while (contAction.pause and Interact_Init.pauseCheckBox.selected and not quitAction.stop): sleep(100) # interrupt execution if requested. if quitAction.stop: # should put a confirmation pop-up here, so as to not accidentally quit... return False Interact_Init.contBut.setEnabled(False) Interact_Init.quitBut.setEnabled(False) Interact_Init.textLabel.setText('Processing...') return True def Interact_CleanUp(): Interact_Init.dia.dispose() # initialize the interactivity dialog. # winLen - number of characters of the message display box will hold. def Interact_Init(winLen): quitAction.stop = False Interact_Init.pauseCheckBox = JCheckBox('Pause for each event') Interact_Init.pauseCheckBox.selected = True Interact_Init.contBut = JButton('Continue', actionPerformed=contAction) Interact_Init.quitBut = JButton('Quit', actionPerformed=quitAction) # initialize the label with a blank string of length winLen, so the # panel/dialog size will be set appropriately. Using 'o' as it is a # reasonably average width character in the default proportional font. Interact_Init.textLabel = JLabel('o' * winLen, SwingConstants.CENTER) Interact_Init.textLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0), \ BorderFactory.createLineBorder(Color.black))) checkPanel = JPanel(BorderLayout()) checkPanel.add(Interact_Init.pauseCheckBox, BorderLayout.EAST) butPanel = JPanel(BorderLayout()) butPanel.add(Interact_Init.contBut, BorderLayout.WEST) butPanel.add(Interact_Init.quitBut, BorderLayout.EAST) panel = JPanel(GridLayout(3, 1, 10, 10)) panel.add(Interact_Init.textLabel) panel.add(checkPanel) panel.add(butPanel) panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)) Interact_Init.dia = JDialog() Interact_Init.dia.setContentPane(panel) Interact_Init.dia.pack() Interact_Init.dia.setVisible(True) # set state for when script is executing. Interact_Init.textLabel.setText('Processing...') Interact_Init.contBut.setEnabled(False) Interact_Init.quitBut.setEnabled(False)