示例#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
示例#2
0
文件: Checkbutton.py 项目: r-owen/RO
    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
示例#3
0
    def __init__ (self,
        master,
        wdgList,
        labelText=None,
        takefocus=True,  # should the checkboxes take focus?
    **kargs):
        """
        Inputs:
        - wdgList   a list of data about the widgets to show or hide;
            each data is a list of 2-4 elements containing:
            - text for checkbox control
            - the widget itself
            - help text (optional)
            - help URL (optional)
        - labelText text for a label above the set of checkbuttons
        - takefocus should the checkbuttons take focus?
        - **kargs   keyword arguments for Tkinter.Frame
        
        All widgets in wdgList must have a common master, which the user is responsible for displaying
        (i.e. packing or gridding). This widget displays checkbuttons which will automatically
        show or hide (by gridding or ungridding) the widgets within their master frame.
        """
        Tkinter.Frame.__init__(self, master, **kargs)
        CtxMenuMixin.__init__(self)
        self._btnDict = {}
        
        if labelText is not None:
            Tkinter.Label(self, text=labelText).pack(side="top", anchor="nw")

        wdgMaster = wdgList[0][1].master
        emptyFrame = Tkinter.Frame(wdgMaster)
        emptyFrame.grid(row=0, column=0)
        
        for ind in range(len(wdgList)):
            wdgData = wdgList[ind]
            wdgName = wdgData[0]
            wdg = wdgData[1]

            try:
                helpText = wdgData[2]
            except IndexError:
                helpText = "show/hide %s panel" % wdgName
                
            try:
                helpURL = wdgData[3]
            except IndexError:
                helpURL = None
                
            wdg.grid(row=0, column=ind, sticky="n")
            wdg.grid_remove()

            # create the checkbutton to control hiding of the widget
            btn = _WdgButton(
                master = self,
                wdg = wdg,
                wdgName = wdgName,
                helpText = helpText,
                helpURL = helpURL,
                takefocus = takefocus,
            )
            btn.pack(side="top", anchor="nw")
            
            self._btnDict[wdgName] = btn