text=defButtonText, command=self.restoreDefault, ).grid(row=3, column=0, columnspan=3) self.inputCont.restoreDefault() if __name__ == "__main__": import CoordSysWdg import TUI.Base.TestDispatcher testDispatcher = TUI.Base.TestDispatcher.TestDispatcher("tcc") tuiModel = testDispatcher.tuiModel root = tuiModel.tkRoot def printOptions(): print optFrame.getString() csysWdg = CoordSysWdg.CoordSysWdg(root) getButton = Tkinter.Button(root, command=printOptions, text="Print Options") optFrame = AxisWrapWdg(root, defButtonText = "", ) csysWdg.pack() getButton.pack() optFrame.pack() tuiModel.reactor.run()
def __init__(self, master=None, userModel=None, **kargs): RO.Wdg.InputContFrame.__init__(self, master, **kargs) gr = RO.Wdg.Gridder(self, sticky="w") # start out by not checking object position # set this true after all widgets are painted # and the formatting functions have had their test run self.checkObjPos = 0 self._azAltRefreshTimer = Timer() self.objNameWdg = RO.Wdg.StrEntry( self, helpText="Object name (optional)", helpURL=_HelpPrefix + "NameWdg", width=25, ) self.objName = gr.gridWdg( label="Name", dataWdg=self.objNameWdg, colSpan=3, ) lastCol = gr.getNextCol() - 2 self.columnconfigure(lastCol, weight=1) objPos1UnitsVar = Tkinter.StringVar() self.objPos1 = gr.gridWdg( label="", dataWdg=RO.Wdg.DMSEntry( self, minValue=0, maxValue=359.99999999, defValue=None, unitsVar=objPos1UnitsVar, isHours= 0, # this will vary so no initial value is actually needed helpText="Object position", helpURL=_HelpPrefix + "PosWdg", ), units=objPos1UnitsVar, ) objPos2UnitsVar = Tkinter.StringVar() self.objPos2 = gr.gridWdg( label="", dataWdg=RO.Wdg.DMSEntry( self, minValue=0, maxValue=90, defValue=None, unitsVar=objPos2UnitsVar, isHours=0, # always in degrees helpText="Object position", helpURL=_HelpPrefix + "PosWdg", ), units=objPos2UnitsVar, ) self.coordSysWdg = CoordSysWdg.CoordSysWdg( master=self, userModel=userModel, ) gr.gridWdg( label="CSys", dataWdg=self.coordSysWdg, colSpan=3, ) self.rotWdg = RotWdg.RotWdg( master=self, userModel=userModel, ) gr.gridWdg( label="Rot", dataWdg=self.rotWdg, colSpan=3, ) azAltFrame = Tkinter.Frame(self) self.azWdg = RO.Wdg.FloatLabel( master=azAltFrame, precision=2, width=6, helpText="azimuth for proposed object", helpURL=_HelpPrefix + "Azimuth", ) self.azWdg.pack(side="left") Tkinter.Label(azAltFrame, text="%s Alt" % (RO.StringUtil.DegStr, )).pack(side="left") self.altWdg = RO.Wdg.FloatLabel( master=azAltFrame, precision=2, width=6, helpText="altitude for proposed object", helpURL=_HelpPrefix + "Altitude", ) self.altWdg.pack(side="left") Tkinter.Label(azAltFrame, text=RO.StringUtil.DegStr).pack(side="left") gr.gridWdg( label="Az", dataWdg=azAltFrame, colSpan=3, ) self.airmassWdg = RO.Wdg.FloatLabel( master=self, precision=3, width=6, helpText="airmass for proposed object", helpURL=_HelpPrefix + "Airmass", ) gr.gridWdg( label="Airmass", dataWdg=self.airmassWdg, ) # create a set of input widget containers # this makes it easy to retrieve a command # and also to get and set all data using a value dictionary # note: the coordsys widget must be FIRST # because it has to be set (when restoring from a value dict) # before pos1 is set, to set the isHours flag correctly def formatObjPos(inputCont): wdgList = inputCont.getWdgList() # format data using the widgets valList = [] for wdg in wdgList: if wdg.getString() == '': raise ValueError, "must specify position" val = wdg.getNum() if wdg.getIsHours(): val = val * 15.0 valList.append(val) return 'track %.7f, %.7f' % tuple(valList) def formatAll(inputCont): # container order is coordsys, objpos, rotator, name (optional) strList = inputCont.getStringList() return strList[1] + ' ' + strList[0] + ''.join(strList[2:]) def vmsQuoteStr(astr): return RO.StringUtil.quoteStr(astr, '"') self.inputCont = RO.InputCont.ContList( conts=[ self.coordSysWdg.inputCont, RO.InputCont.WdgCont( name="ObjPos", wdgs=(self.objPos1.dataWdg, self.objPos2.dataWdg), formatFunc=formatObjPos, ), RO.InputCont.WdgCont( name="Name", wdgs=self.objNameWdg, formatFunc=RO.InputCont.VMSQualFmt(vmsQuoteStr), ), self.rotWdg.inputCont, ], formatFunc=formatAll, ) self.userModel = userModel or TUI.TCC.UserModel.getModel() self.userModel.coordSysName.addCallback(self._coordSysChanged) self.userModel.potentialTarget.addCallback(self.setAzAltAirmass) self.tccModel = TUI.TCC.TCCModel.getModel() self.tccModel.azLim.addCallback(self._azLimChanged) self.tccModel.altLim.addCallback(self._altLimChanged) # initialize display self.restoreDefault() self.objNameWdg.focus_set()