Exemplo n.º 1
0
 def setupOptParameters(self):
     params = []
     if hasattr(self.options, 'optParameters'):
         params.extend(self.options.optParameters)
     d = {}
     soFar = {}
     for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
         full = 'opt_' + meth
         func = getattr(self.options, full)
         if usage.flagFunction(func) or soFar.has_key(func):
             continue
         soFar[func] = 1
         existing = d.setdefault(func, meth)
         if existing != meth:
             if len(existing) < len(meth):
                 d[func] = meth
     for (func, name) in d.items():
         params.append((name, None, None, func.__doc__))
     if len(params):
         self.paramFrame = Tkinter.Frame(self)
         self.paramLines = []
         for (flag, _, default, desc) in params:
             try:
                 default = self.options[flag]
             except KeyError:
                 pass
             self.makeField(flag, default, desc)
         self.paramFrame.grid(row=1, column=2)
Exemplo n.º 2
0
    def setupOptParameters(self):
        params = []
        if hasattr(self.options, 'optParameters'):
            params.extend(self.options.optParameters)

        d = {}
        soFar = {}
        for meth in reflect.prefixedMethodNames(self.options.__class__,
                                                'opt_'):
            full = 'opt_' + meth
            func = getattr(self.options, full)

            if usage.flagFunction(func) or soFar.has_key(func):
                continue

            soFar[func] = 1

            existing = d.setdefault(func, meth)
            if existing != meth:
                if len(existing) < len(meth):
                    d[func] = meth
        for (func, name) in d.items():
            params.append((name, None, None, func.__doc__))

        if len(params):
            self.paramFrame = Tkinter.Frame(self)
            self.paramLines = []
            for (flag, _, default, desc) in params:
                try:
                    default = self.options[flag]
                except KeyError:
                    pass
                self.makeField(flag, default, desc)
            self.paramFrame.grid(row=1, column=2)
Exemplo n.º 3
0
 def setupOptFlags(self):
     self.optFlags = []
     flags = []
     if hasattr(self.options, 'optFlags'):
         flags.extend(self.options.optFlags)
     d = {}
     soFar = {}
     for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
         full = 'opt_' + meth
         func = getattr(self.options, full)
         if not usage.flagFunction(func) or meth in ('help', 'version'):
             continue
         if soFar.has_key(func):
             continue
         soFar[func] = 1
         existing = d.setdefault(func, meth)
         if existing != meth:
             if len(existing) < len(meth):
                 d[func] = meth
         for (func, name) in d.items():
             flags.append((name, None, func.__doc__))
         if len(flags):
             self.optFrame = f = Tkinter.Frame(self)
             for (flag, _, desc) in flags:
                 b = Tkinter.BooleanVar()
                 c = Tkinter.Checkbutton(f, text=desc, variable=b, wraplen=200)
                 c.pack(anchor=Tkinter.W)
                 self.optFlags.append((flag, b))
             f.grid(row=1, column=1)
Exemplo n.º 4
0
    def setupOptFlags(self):
        self.optFlags = []
        flags = []
        if hasattr(self.options, 'optFlags'):
            flags.extend(self.options.optFlags)

        d = {}
        soFar = {}
        for meth in reflect.prefixedMethodNames(self.options.__class__,
                                                'opt_'):
            full = 'opt_' + meth
            func = getattr(self.options, full)

            if not usage.flagFunction(func) or meth in ('help', 'version'):
                continue

            if soFar.has_key(func):
                continue
            soFar[func] = 1

            existing = d.setdefault(func, meth)
            if existing != meth:
                if len(existing) < len(meth):
                    d[func] = meth

            for (func, name) in d.items():
                flags.append((name, None, func.__doc__))

            if len(flags):
                self.optFrame = f = Tkinter.Frame(self)
                for (flag, _, desc) in flags:
                    b = Tkinter.BooleanVar()
                    c = Tkinter.Checkbutton(f,
                                            text=desc,
                                            variable=b,
                                            wraplen=200)
                    c.pack(anchor=Tkinter.W)
                    self.optFlags.append((flag, b))
                f.grid(row=1, column=1)
Exemplo n.º 5
0
        def _absorbHandlers(self):
            twistd_handlers = {}
            reflect.addMethodNamesToDict(self.__class__, twistd_handlers, "opt_")

            # NOTE(termie): Much of the following is derived/copied from
            #               twisted.python.usage with the express purpose of
            #               providing compatibility
            for name in twistd_handlers.keys():
                method = getattr(self, 'opt_'+name)

                takesArg = not usage.flagFunction(method, name)
                doc = getattr(method, '__doc__', None)
                if not doc:
                    doc = 'undocumented'

                if not takesArg:
                    if name not in FLAGS:
                        flags.DEFINE_boolean(name, None, doc)
                    self._flagHandlers[name] = method
                else:
                    if name not in FLAGS:
                        flags.DEFINE_string(name, None, doc)
                    self._paramHandlers[name] = method
Exemplo n.º 6
0
 def test_noArg(self):
     """
     L{usage.flagFunction} returns C{True} if the method checked allows
     exactly no argument.
     """
     self.assertIs(True, usage.flagFunction(self.SomeClass().noArg))
Exemplo n.º 7
0
 def test_hasArg(self):
     """
     L{usage.flagFunction} returns C{False} if the method checked allows
     exactly one argument.
     """
     self.assertIs(False, usage.flagFunction(self.SomeClass().oneArg))
Exemplo n.º 8
0
 def test_noArg(self):
     """
     L{usage.flagFunction} returns C{True} if the method checked allows
     exactly no argument.
     """
     self.assertIs(True, usage.flagFunction(self.SomeClass().noArg))
Exemplo n.º 9
0
 def test_hasArg(self):
     """
     L{usage.flagFunction} returns C{False} if the method checked allows
     exactly one argument.
     """
     self.assertIs(False, usage.flagFunction(self.SomeClass().oneArg))