Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/35m_operations/TUI/Scripts/ScriptingTutorial/UserInput.html
Дата изменения: Sat Sep 6 02:16:02 2014
Дата индексирования: Sun Apr 10 07:19:13 2016
Кодировка:

Поисковые слова: comet
TUI:Scripts:Scripting Tutorial:User Input

User Input

This example shows how to add a few input widgets to a script and how to get data from them. This is a fairly artificial example in that one would normally just use the DIS Expose window for this purpose. However, it demonstrates a few useful techniques, including:

DISDarks v2 script

Be sure you have permission to use DIS before running this example!!!


import RO.Wdg
import Tkinter
import TUI.Inst.ExposeModel as ExposeModel
from TUI.Inst.ExposeStatusWdg import ExposeStatusWdg

class ScriptClass(object):
    """Take a series of DIS darks with user input.
    """
    def __init__(self, sr):
        """Display exposure status and a few user input widgets.
        """
        # if True, run in debug-only mode (which doesn't DO anything, it just pretends)
        sr.debug = False

        expStatusWdg = ExposeStatusWdg(
            master = sr.master,
            instName = "DIS",
        )
        expStatusWdg.grid(row=0, column=0, sticky="w")
        
        wdgFrame = Tkinter.Frame(sr.master)
     
        gr = RO.Wdg.Gridder(wdgFrame)
        
        self.expModel = ExposeModel.getModel("DIS")
    
        timeUnitsVar = Tkinter.StringVar()
        self.timeWdg = RO.Wdg.DMSEntry (
            master = wdgFrame,
            minValue = self.expModel.instInfo.minExpTime,
            maxValue = self.expModel.instInfo.maxExpTime,
            isRelative = True,
            isHours = True,
            unitsVar = timeUnitsVar,
            width = 10,
            helpText = "Exposure time",
        )
        gr.gridWdg("Time", self.timeWdg, timeUnitsVar)
        
        self.numExpWdg = RO.Wdg.IntEntry(
            master = wdgFrame,
            defValue = 1,
            minValue = 1,
            maxValue = 999,
            helpText = "Number of exposures in the sequence",
        )
        gr.gridWdg("#Exp", self.numExpWdg)
        
        wdgFrame.grid(row=1, column=0, sticky="w")
        
    def run(self, sr):
        """Take a series of DIS darks"""
        expType = "dark"
        expTime = self.timeWdg.getNum()
        numExp = self.numExpWdg.getNum()
    
        fileName = "dis_" + expType
        
        if expTime <= 0:
            raise sr.ScriptError("Specify exposure time")
    
        cmdStr = self.expModel.formatExpCmd(
            expType = expType,
            expTime = expTime,
            fileName = fileName,
            numExp = numExp,
        )
    
        yield sr.waitCmd(
            actor = "disExpose",
            cmdStr = cmdStr,
            abortCmdStr = "abort",
        )

Comments:

Advanced Topic

It is actually possible to create a gridder on sr.master and use it to lay out the status widget and the input widgets. I present the code without comment for folks who understand the Tk gridder and are willing to read the help for RO.Wdg.Gridder.

    gr = RO.Wdg.Gridder(sr.master)
    
    expStatusWdg = ExposeStatusWdg(
        master = sr.master,
        instName = "DIS",
    )
    gr.gridWdg(False, expStatusWdg, colSpan=4)
    sr.master.grid_columnconfigure(3, weight=1)
    ...
    gr.gridWdg("Time", timeWdg, timeUnitsVar)
    ...
    gr.gridWdg("#Exp", numExpWdg)