Exemple #1
0
    def __init__(self,
        master,
        var = None,
        defValue = None,
        helpText = None,
        helpURL = None,
        callFunc = None,
        defIfDisabled = False,
        showValue = False,
        autoIsCurrent = False,
        trackDefault = None,
        isCurrent = True,
        severity = RO.Constants.sevNormal,
    **kargs):
        self._defBool = False # just create the field for now
        if var is None:
            var = Tkinter.StringVar()
        elif defValue is None:
            defValue = var.get()
        self._var = var
        self._defIfDisabled = bool(defIfDisabled)
        if trackDefault is None:
            trackDefault = bool(autoIsCurrent)
        self._trackDefault = trackDefault
        self.helpText = helpText

        # if a command is supplied in kargs, remove it now and set it later
        # so it is not called during init
        cmd = kargs.pop("command", None)
        if "variable" in kargs:
            raise ValueError("Specify var instead of variable")
        if showValue:
            if "text" in kargs:
                raise ValueError("Do not specify text if showValue True")
            if "textvariable" in kargs:
                raise ValueError("Do not specify textvariable if showValue True (specify var instead)")
            kargs.setdefault("indicatoron", False)
            kargs["textvariable"] = self._var
        
        Tkinter.Checkbutton.__init__(self,
            master = master,
            variable = self._var,
        )
        self.configure(kargs) # call overridden configure to fix width, if necessary

        RO.AddCallback.TkVarMixin.__init__(self, self._var)
        
        CtxMenuMixin.__init__(self,
            helpURL = helpURL,
        )

        AutoIsCurrentMixin.__init__(self, autoIsCurrent)
        IsCurrentCheckbuttonMixin.__init__(self)
        SeverityActiveMixin.__init__(self, severity)

        self._defBool = self.asBool(defValue)
        self._isCurrent = isCurrent
        if self._defBool:
            self.select()
        else:
            self.deselect()
        
        # add the callbacks last, so the autoIsCurrent callback
        # is called first and to avoid calling them while setting default
        self.addCallback(callFunc, False)
        if cmd:
            self["command"] = cmd
Exemple #2
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)
Exemple #3
0
    def __init__(self,
                 master,
                 var=None,
                 defValue=None,
                 helpText=None,
                 helpURL=None,
                 callFunc=None,
                 defIfDisabled=False,
                 showValue=False,
                 autoIsCurrent=False,
                 trackDefault=None,
                 isCurrent=True,
                 severity=RO.Constants.sevNormal,
                 **kargs):
        self._defBool = False  # just create the field for now
        if var is None:
            var = Tkinter.StringVar()
        elif defValue is None:
            defValue = var.get()
        self._var = var
        self._defIfDisabled = bool(defIfDisabled)
        if trackDefault is None:
            trackDefault = bool(autoIsCurrent)
        self._trackDefault = trackDefault
        self.helpText = helpText

        # if a command is supplied in kargs, remove it now and set it later
        # so it is not called during init
        cmd = kargs.pop("command", None)
        if "variable" in kargs:
            raise ValueError("Specify var instead of variable")
        if showValue:
            if "text" in kargs:
                raise ValueError("Do not specify text if showValue True")
            if "textvariable" in kargs:
                raise ValueError(
                    "Do not specify textvariable if showValue True (specify var instead)"
                )
            kargs.setdefault("indicatoron", False)
            kargs["textvariable"] = self._var

        Tkinter.Checkbutton.__init__(
            self,
            master=master,
            variable=self._var,
        )
        self.configure(
            kargs)  # call overridden configure to fix width, if necessary

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

        CtxMenuMixin.__init__(
            self,
            helpURL=helpURL,
        )

        AutoIsCurrentMixin.__init__(self, autoIsCurrent)
        IsCurrentCheckbuttonMixin.__init__(self)
        SeverityActiveMixin.__init__(self, severity)

        self._defBool = self.asBool(defValue)
        self._isCurrent = isCurrent
        if self._defBool:
            self.select()
        else:
            self.deselect()

        # add the callbacks last, so the autoIsCurrent callback
        # is called first and to avoid calling them while setting default
        self.addCallback(callFunc, False)
        if cmd:
            self["command"] = cmd
Exemple #4
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)