469,271 Members | 1,740 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

User input with a default value that can be modified

Hello the list :-)

I do a little program that permit the user to manage list of sentences.
This program runs into a linux shell.
The user can add, modify and delete the sentences.

What I want to do is :

When the user want to modify one sentence, I would like to do this :

Modify your sentence : The_sentence_appear_here_followed_by_a_cursor

And the user can go back with the cursor, like in the bash shell,
delete, modify, and when pressing enter, the new value (or the same if
not modified) is put in my variable.

Of course, the first think I did as a newbie was :

new_sentence = raw_input("Modify your sentence : "old_sentence)

But OF COURSE, stupid am I, the user cannot put the cursor back into
the old sentence !

I think about playing with some sophisticated keyboard exercise where
I could program a new input command with a value already appearing as
answer, but I am pretty sure that it exists already.

What do you think about it ?

Actually, it is quite difficult to find anything on it, because the
keywords are not very obvious (input, default answer, ...)

Thank you for your help.

Etienne
--
(\__/)
(='.'=) Ceci est un petit lapin. Copiez/collez-le dans
(")_(") votre signature pour l'aider dominer le monde
May 28 '07 #1
2 2087
On May 28, 11:52 am, "Etienne Hilson" <etienne.hil...@gmail.com>
wrote:
Hello the list :-)

I do a little program that permit the user to manage list of sentences.
This program runs into a linux shell.
The user can add, modify and delete the sentences.

What I want to do is :

When the user want to modify one sentence, I would like to do this :

Modify your sentence : The_sentence_appear_here_followed_by_a_cursor

And the user can go back with the cursor, like in the bash shell,
delete, modify, and when pressing enter, the new value (or the same if
not modified) is put in my variable.

Of course, the first think I did as a newbie was :

new_sentence = raw_input("Modify your sentence : "old_sentence)

But OF COURSE, stupid am I, the user cannot put the cursor back into
the old sentence !

I think about playing with some sophisticated keyboard exercise where
I could program a new input command with a value already appearing as
answer, but I am pretty sure that it exists already.

What do you think about it ?

Actually, it is quite difficult to find anything on it, because the
keywords are not very obvious (input, default answer, ...)

Thank you for your help.

Etienne
--
(\__/)
(='.'=) Ceci est un petit lapin. Copiez/collez-le dans
(")_(") votre signature pour l'aider dominer le monde
Check into the readline module. This is what I came up with. A
second thread injects the text into the open readline instance.
Hopefully the experts will show the _right_ way to do it.

import readline, threading
import time

class write(threading.Thread):
def __init__ (self, s):
threading.Thread.__init__(self)
self.s = s

def run(self):
time.sleep(.01)
readline.insert_text(self.s)
readline.redisplay()

write("Edit this sentence").start()
s = raw_input("prompt:")

print s

~Sean

May 28 '07 #2
On May 28, 11:52 am, "Etienne Hilson" <etienne.hil...@gmail.com>
wrote:
Hello the list :-)

I do a little program that permit the user to manage list of sentences.
This program runs into a linux shell.
The user can add, modify and delete the sentences.

What I want to do is :

When the user want to modify one sentence, I would like to do this :

Modify your sentence : The_sentence_appear_here_followed_by_a_cursor

And the user can go back with the cursor, like in the bash shell,
delete, modify, and when pressing enter, the new value (or the same if
not modified) is put in my variable.

Of course, the first think I did as a newbie was :

new_sentence = raw_input("Modify your sentence : "old_sentence)

But OF COURSE, stupid am I, the user cannot put the cursor back into
the old sentence !

I think about playing with some sophisticated keyboard exercise where
I could program a new input command with a value already appearing as
answer, but I am pretty sure that it exists already.

What do you think about it ?

Actually, it is quite difficult to find anything on it, because the
keywords are not very obvious (input, default answer, ...)

Thank you for your help.

Etienne
--
(\__/)
(='.'=) Ceci est un petit lapin. Copiez/collez-le dans
(")_(") votre signature pour l'aider dominer le monde
Check into the readline module. This is what I came up with. A
second thread injects the text into the open readline instance.
Hopefully the experts will show the _right_ way to do it.

import readline, threading
import time

class write(threading.Thread):
def __init__ (self, s):
threading.Thread.__init__(self)
self.s = s

def run(self):
time.sleep(.01)
readline.insert_text(self.s)
readline.redisplay()

write("Edit this sentence").start()
s = raw_input("prompt:")

print s

~Sean

May 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by N?ant Humain | last post: by
4 posts views Thread by Amjad | last post: by
11 posts views Thread by John J. Hughes II | last post: by
14 posts views Thread by n3o | last post: by
12 posts views Thread by Daniel Klein | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.