Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16522 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2011-12-01 22:02 -0600 |
| Last post | 2011-12-02 07:01 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
Passing along cmd.Cmd completion to contained class Tim Chase <python.list@tim.thechases.com> - 2011-12-01 22:02 -0600
Re: Passing along cmd.Cmd completion to contained class Miki Tebeka <miki.tebeka@gmail.com> - 2011-12-02 07:01 -0800
Re: Passing along cmd.Cmd completion to contained class Miki Tebeka <miki.tebeka@gmail.com> - 2011-12-02 07:01 -0800
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2011-12-01 22:02 -0600 |
| Subject | Passing along cmd.Cmd completion to contained class |
| Message-ID | <mailman.3214.1322798548.27778.python-list@python.org> |
I have sub-classes of cmd.Cmd in an arrangement somewhat like
class Config(cmd.Cmd):
def do_foo(self, line): print "Fooing %r" % line
def complete_foo(self, text, line, begidx, endidx):
...
class MyTUI(cmd.Cmd):
def __init__(self, configger=Config, *args, **kwargs):
cmd.Cmd.__init__(self, *args, **kwargs)
self.config = configger()
def complete_config(self, text, line, begidx, endidx):
magic_here(self.config, text, line, begidx, endidx)
I've been sparring with getting MyTUI.complete_config() to reach
into self.config for completions so I can type things like
(cmd) config <tab>
(cmd) config foo <tab>
and have it suggest from Config as if I had done something like
def do_config(self, line)
self.config.cmdloop()
and then asked for completions. That would mean that the first
one would act like Config.completenames() and the second one
would act like Config.complete_foo(...)
Is there a best way to get this pass-along behavior?
Thanks,
-tkc
[toc] | [next] | [standalone]
| From | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| Date | 2011-12-02 07:01 -0800 |
| Message-ID | <1593725.176.1322838100582.JavaMail.geo-discussion-forums@yqmd7> |
| In reply to | #16522 |
This is not tested, but maybe it'll work :)
def complete(self, text, state):
if text.startswith('config):
return self.config.complete(text, state)
return Cmd.complete(self, text, state)
[toc] | [prev] | [next] | [standalone]
| From | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| Date | 2011-12-02 07:01 -0800 |
| Message-ID | <mailman.3222.1322838104.27778.python-list@python.org> |
| In reply to | #16522 |
This is not tested, but maybe it'll work :)
def complete(self, text, state):
if text.startswith('config):
return self.config.complete(text, state)
return Cmd.complete(self, text, state)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web