Example #1
0
    def __init__(self,
                 master,
                 defPath=None,
                 fileTypes=None,
                 maxChar=30,
                 callFunc=None,
                 severity=RO.Constants.sevNormal,
                 helpText=None,
                 helpURL=None,
                 **kargs):
        """Creates a new Button.
        
        Inputs:
        - defPath: initial path; silently ignored if invalid or nonexistent
        - fileTypes: sequence of (label, pattern) tuples;
            use * as a pattern to allow all files of that labelled type;
            omit altogether to allow all files
        - maxChar: maximum # of characters of file path to display
        - callFunc  callback function; the function receives one argument: self.
                    It is called whenever the value changes (manually or via
                    the associated variable being set).
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - helpText  text for hot help
        - helpURL   URL for longer help
        - all remaining keyword arguments are used to configure the Tkinter Button;
          command is supported, for the sake of conformity, but callFunc is preferred.
        """
        self.fileTypes = fileTypes
        self.maxChar = max(3, int(maxChar))
        self.helpText = helpText
        self.path = None
        self.defPath = None

        self.leftChar = 0
        self.rightChar = (self.maxChar - self.leftChar) - 1

        Tkinter.Button.__init__(self,
                                master=master,
                                command=self._doChoose,
                                **kargs)

        RO.AddCallback.BaseMixin.__init__(self)

        CtxMenu.CtxMenuMixin.__init__(
            self,
            helpURL=helpURL,
        )
        SeverityActiveMixin.__init__(self, severity)

        self._initPath(defPath)

        if callFunc:
            self.addCallback(callFunc, False)
Example #2
0
File: PathWdg.py Project: r-owen/RO
    def __init__(self,
        master,
        defPath = None,
        fileTypes = None,
        maxChar = 30,
        callFunc = None,
        severity = RO.Constants.sevNormal,
        helpText = None,
        helpURL = None,
    **kargs):
        """Creates a new Button.
        
        Inputs:
        - defPath: initial path; silently ignored if invalid or nonexistent
        - fileTypes: sequence of (label, pattern) tuples;
            use * as a pattern to allow all files of that labelled type;
            omit altogether to allow all files
        - maxChar: maximum # of characters of file path to display
        - callFunc  callback function; the function receives one argument: self.
                    It is called whenever the value changes (manually or via
                    the associated variable being set).
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - helpText  text for hot help
        - helpURL   URL for longer help
        - all remaining keyword arguments are used to configure the Tkinter Button;
          command is supported, for the sake of conformity, but callFunc is preferred.
        """
        self.fileTypes = fileTypes
        self.maxChar = max(3, int(maxChar))
        self.helpText = helpText
        self.path = None
        self.defPath = None
        
        self.leftChar = 0
        self.rightChar = (self.maxChar - self.leftChar) - 1

        Tkinter.Button.__init__(self,
            master = master,
            command = self._doChoose,
        **kargs)
        
        RO.AddCallback.BaseMixin.__init__(self)
        
        CtxMenu.CtxMenuMixin.__init__(self,
            helpURL = helpURL,
        )
        SeverityActiveMixin.__init__(self, severity)

        self._initPath(defPath)
        
        if callFunc:
            self.addCallback(callFunc, False)
Example #3
0
File: Button.py Project: r-owen/RO
    def __init__(self,
        master,
        helpText = None,
        helpURL = None,
        severity=RO.Constants.sevNormal,
    **kwArgs):
        """Creates a new Button.
        
        Inputs:
        - helpText  text for hot help
        - helpURL   URL for longer help
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - all remaining keyword arguments are used to configure the Tkinter Button
        """
        self.helpText = helpText

        Tkinter.Radiobutton.__init__(self, master = master, **kwArgs)
        CtxMenu.CtxMenuMixin.__init__(self, helpURL = helpURL)
        SeverityActiveMixin.__init__(self, severity)
Example #4
0
    def __init__(self,
                 master,
                 helpText=None,
                 helpURL=None,
                 severity=RO.Constants.sevNormal,
                 **kwArgs):
        """Creates a new Button.
        
        Inputs:
        - helpText  text for hot help
        - helpURL   URL for longer help
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - all remaining keyword arguments are used to configure the Tkinter Button
        """
        self.helpText = helpText

        Tkinter.Radiobutton.__init__(self, master=master, **kwArgs)
        CtxMenu.CtxMenuMixin.__init__(self, helpURL=helpURL)
        SeverityActiveMixin.__init__(self, severity)
Example #5
0
    def __init__(self,
                 master,
                 helpText=None,
                 helpURL=None,
                 callFunc=None,
                 command=None,
                 severity=RO.Constants.sevNormal,
                 **kwArgs):
        """Creates a new Button.
        
        Inputs:
        - helpText  text for hot help
        - helpURL   URL for longer help
        - callFunc  callback function; the function receives one argument: self.
                    It is called whenever the value changes (manually or via
                    the associated variable being set).
        - command   like callFunc, but the callback receives no arguments (standard Tk behavior)
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - all remaining keyword arguments are used to configure the Tkinter Button;
          command is supported, for the sake of conformity, but callFunc is preferred.
        """
        self.helpText = helpText

        if RO.TkUtil.getWindowingSystem() == RO.TkUtil.WSysAqua:
            # buttons with text are too cramped in 8.5.18; add some padding unless it's already been done
            if "text" in kwArgs or "textvariable" in kwArgs:
                kwArgs.setdefault("padx", 10)
                kwArgs.setdefault("pady", 3)

        Tkinter.Button.__init__(self, master=master, **kwArgs)

        RO.AddCallback.TkButtonMixin.__init__(
            self,
            callFunc=callFunc,
            callNow=False,
            command=command,
        )

        CtxMenu.CtxMenuMixin.__init__(self, helpURL=helpURL)
        SeverityActiveMixin.__init__(self, severity)
Example #6
0
File: Button.py Project: r-owen/RO
    def __init__(self,
        master,
        helpText = None,
        helpURL = None,
        callFunc = None,
        command = None,
        severity = RO.Constants.sevNormal,
    **kwArgs):
        """Creates a new Button.
        
        Inputs:
        - helpText  text for hot help
        - helpURL   URL for longer help
        - callFunc  callback function; the function receives one argument: self.
                    It is called whenever the value changes (manually or via
                    the associated variable being set).
        - command   like callFunc, but the callback receives no arguments (standard Tk behavior)
        - severity  initial severity; one of RO.Constants.sevNormal, sevWarning or sevError
        - all remaining keyword arguments are used to configure the Tkinter Button;
          command is supported, for the sake of conformity, but callFunc is preferred.
        """
        self.helpText = helpText

        if RO.TkUtil.getWindowingSystem() == RO.TkUtil.WSysAqua:
            # buttons with text are too cramped in 8.5.18; add some padding unless it's already been done
            if "text" in kwArgs or "textvariable" in kwArgs:
                kwArgs.setdefault("padx", 10)
                kwArgs.setdefault("pady", 3)

        Tkinter.Button.__init__(self, master = master, **kwArgs)
        
        RO.AddCallback.TkButtonMixin.__init__(self,
            callFunc = callFunc,
            callNow = False,
            command = command,
        )
        
        CtxMenu.CtxMenuMixin.__init__(self, helpURL = helpURL)
        SeverityActiveMixin.__init__(self, severity)
Example #7
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
Example #8
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
Example #9
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)