Exemplo n.º 1
0
    def __init__(self,
        master,
        textList = None,
        bitmapList = None,
        valueList = None,
        defValue = None,
        var = None,
        helpText = None,
        helpURL = None,
        callFunc=None,
        defIfBlank = True,
        abbrevOK = False,
        ignoreCase = False,
        autoIsCurrent = False,
        trackDefault = None,
        isCurrent = True,
        side = None,
    **kargs):
        self._defValue = None
        if trackDefault is None:
            trackDefault = bool(autoIsCurrent)
        self.trackDefault = trackDefault
        if textList is None and bitmapList is None:
            raise ValueError("Must specify textList or bitmapList")
        elif textList is None:
            if valueList is None:
                raise ValueError("Must specify textList or valueList")
            textList = [None]*len(bitmapList)
        else:
            # textList specified; use as default for valueList
            if valueList is None:
                valueList = textList
            
            if bitmapList is None:
                bitmapList = [None]*len(textList)
            else:
                if len(textList) != len(bitmapList):
                    raise ValueError("textList and bitmapList both specified but have different lengths")
        nButtons = len(textList)
        if len(valueList) != nButtons:
            raise ValueError("valueList must have one entry per radio button")

        self._valueList = valueList
        if var is None:
            var = Tkinter.StringVar()
        self._var = var
        self._defIfBlank = defIfBlank

        self._matchItem = RO.Alg.MatchList(
            valueList = valueList,
            abbrevOK = abbrevOK,
            ignoreCase = ignoreCase,
        )
        RO.AddCallback.TkVarMixin.__init__(self, self._var)

        helpTextList = RO.SeqUtil.oneOrNAsList(helpText, nButtons, "helpText list")
        helpURLList = RO.SeqUtil.oneOrNAsList(helpURL, nButtons, "helpURL list")
        self.wdgSet = []
        for ii in range(nButtons):
            wdg = Button.Radiobutton(
                master = master,
                variable = self._var,
                text = textList[ii],
                bitmap = bitmapList[ii],
                value = valueList[ii],
                helpText = helpTextList[ii],
                helpURL = helpURLList[ii],
            **kargs)
            self.wdgSet.append(wdg)

        # do after adding callback support
        # and before setting default (which triggers a callback)
        AutoIsCurrentMixin.__init__(self, autoIsCurrent)
        IsCurrentActiveMixin.__init__(self)

        self.setDefault(defValue, isCurrent = isCurrent)
        
        if side:
            for wdg in self.wdgSet:
                wdg.pack(side=side)

        # add callback function after setting default
        # to avoid having the callback called right away
        if callFunc:
            self.addCallback(callFunc, False)
Exemplo n.º 2
0
    def __init__(self,
        master,
        items,
        var=None,
        defValue=None,
        noneDisplay='',
        helpText=None,
        helpURL=None,
        callFunc=None,
        defMenu = None,
        label = None,
        abbrevOK = False,
        ignoreCase = False,
        autoIsCurrent = False,
        trackDefault = None,
        isCurrent = True,
        postCommand = None,
        severity = RO.Constants.sevNormal,
    **kargs):
        showDefault = not (var and defValue is None)
        if var is None:
            var = Tkinter.StringVar()
        self._tempValue = None
        self._items = []
        self.defValue = None
        self.noneDisplay = noneDisplay or ''
        self.ignoreCase = ignoreCase
        self._helpTextDict = {}
        self._fixedHelpText = None
        self.helpText = None
        self.defMenu = defMenu
        self._matchItem = RO.Alg.MatchList(abbrevOK = abbrevOK, ignoreCase = ignoreCase)
        if trackDefault is None:
            trackDefault = bool(autoIsCurrent)
        self.trackDefault = trackDefault
        
        # handle keyword arguments for the Menubutton
        # start with defaults, update with user-specified values, if any
        # then set text or textvariable
        wdgKArgs = {
            "borderwidth": 2,
            "indicatoron": True,
            "relief": "raised",
            "anchor": "c",
            "highlightthickness": 2,
        }
        wdgKArgs.update(kargs)
        for item in ("text", "textvariable"):
            wdgKArgs.pop(item, None)
        if label is not None:
            wdgKArgs["text"] = label
        else:
            wdgKArgs["textvariable"] = var
        self.label = label
        Menubutton.__init__(self, master = master, helpURL = helpURL, **wdgKArgs)
        self._menu = Tkinter.Menu(self, tearoff = False, postcommand = postCommand)
        self["menu"] = self._menu

        RO.AddCallback.TkVarMixin.__init__(self, var)

        # do after adding callback support, but before setting default (which triggers a callback)
        AutoIsCurrentMixin.__init__(self, autoIsCurrent)
        IsCurrentActiveMixin.__init__(self)
        SeverityActiveMixin.__init__(self, severity)

        self.setItems(items, helpText=helpText, checkCurrent = False, checkDefault = False)
        self.setDefault(defValue, isCurrent = isCurrent, doCheck = True, showDefault = showDefault)
        
        # add callback function after setting default
        # to avoid having the callback called right away
        if callFunc:
            self.addCallback(callFunc, callNow=False)