Need GUI pop-up to edit a string

Hi,
I’m in need for a graphical pop-up that will display a string in a field,
allowing the user to change it, returning the changed string.
Maybe also keep the original name displayed above it.

Something lie this:

±------------------------------------------------+
| Please confirm or edit the following string |
| |
| Original_example_string |
| |
| ±------------------------------------------+ |
| | Original_about_to_be_changed | |
| ±------------------------------------------+ |
| |
| OK |
| |
±------------------------------------------------+

I’d like to call it from Python, but a Python system call to bash would do
just as fine for now.

I’ve never used any kind of graphical interface programing before, so I
don’t have a clue where to start.
This would, however, be the only GUI part in the app at this point.


When in doubt, use brute force.
– Ken Thompson

I am not sure just how you expect to pass the text in and out of the script but here is something you can do in a bash script

#!/bin/bash

#: Title       : textedit
#: Date Created: Sun Jan 16 16:37:09 CST 2011
#: Last Edit   : Sun Jan 16 16:37:09 CST 2011
#: Author      : J. McDaniel
#: Version     : 1.00
#: Description : 
#: Options     : 

OLDTEXT="$1"

EDITTEXT=$(zenity --title "Text Editor Window" --entry --text "Edit this Text and press Enter when Done:" --entry-text="$OLDTEXT") 

NEWTEXT=$EDITTEXT

export NEWTEXT

echo $NEWTEXT

exit 0
# End Of Script

You would start the bash file as:


textedit "This is a Test"

This causes a GUI Window to pop up with the text This is a Test to be displayed which you can edit. It is then passed out in the environment variable NEWTEXT, but not sure if this is what you want or not.

Thank You,

You can’t export environment variables “upwards”.

#! /bin/bash

title="What you're asking for"
text="Please confirm or edit the following string"
string="All you need is love"
newstring=$(zenity --entry --title="$title" --text="$text" --entry-text="$string")

echo $newstring

You need to have the package zenity installed (Gnome users do).

Or with kdialog (KDE users should have it installed):


#! /bin/bash
title="Edit string dialog"
text="Please confirm or edit the following string"
oldstring="PLEASE EDIT ME"
newstring=$(kdialog --title "$title" --inputbox "$text" "$oldstring")
echo $newstring

I normally install GNOME as a backup Desktop and to allow GNOME apps to work in KDE. You can open YaST / Software Management, search on zenity and install by its self if you like. As for exporting Variables, I seldom get them to go or down, but as I said, I was not sure how to get back the results of the edit. You could perhaps save the result as a file as in:

echo $NEWTEXT > filename.txt

It does pose a problem when you have the middle solution to know what you are trying to do.

Thank You,

Or you could just get the script to echo the new string and do something like this (presuming that the script filename is test.sh)


**andrew@andrew-desktop:~>** cat test.sh
#! /bin/bash
title="Edit string dialog"
text="Please edit the following string"
oldstring="PLEASE EDIT ME"
newstring=$(kdialog --title "$title" --inputbox "$text" "$oldstring")
echo $newstring
**andrew@andrew-desktop:~>** NEWTEXT=$(bash test.sh)
**andrew@andrew-desktop:~>** echo $NEWTEXT
I have edited this text

Very good ! Then a more universal version:

#! /bin/bash

title="What you're asking for"
text="Please confirm or edit the following string: "
oldstring="All you need is love"

flag=0
which zenity &> /dev/null && flag=$((flag | 1))
which kdialog &> /dev/null && flag=$((flag | 2))

case $flag in
0) read -p "$text" -e -i "$oldstring" newstring ;;
1) newstring=$(zenity --entry --title="$title" --text="$text" --entry-text="$oldstring") ;;
2|3) newstring=$(kdialog --title "$title" --inputbox "$text" "$oldstring") ;;
esac

echo $newstring ...

Of course, that can still be fine tuned.

Nice. Works well on KDE (just tested it and it opened KDialog successfully)

It would have used kdialog too under Gnome if both kdialog and zenity were found (in the order it checks for them). That’s why I said it could still be improved, like checking wich wm is currently used or defining the preferred popup program.

Der Rest ist Arbeit. (Not sure if you can say “Rest is work” ) lol!

On 2011-01-17, please try again wrote:
>
> ah7013;2279007 Wrote:
>> Nice. Works well on KDE (just tested it and it opened KDialog
>> successfully)
>
> It would have used kdialog too under Gnome if both kdialog and zenity
> were found (in the order it checks for them). That’s why I said it could
> still be improved, like checking wich wm is currently used or defining
> the preferred popup program.
>
> -Der Rest ist Arbeit-. (Not sure if you can say “Rest is work” ) lol!

Well, you could say, The rest is work. :slight_smile:

People, I thank you humbly for all the suggestions.
I think I have plenty to start with.

Of course, if someone had a Python PyQT solution, please keep posting…
It’s just that the string to be edited might one day be in Unicode, and we
all know what happens with anything but pure ASCCII when it’s being passed
as argument between scripts or between programming languages
(bash<–>Python, for instance). :slight_smile:

But anyway, thanks again.
I’ve now got a great base to start with and look into.


When in doubt, use brute force.
– Ken Thompson

I know. But “Rest is work” sounds funnier. So does “Work is rest”.
It reminds me of an old song by Henri Salvador, that said:
“Le travail c’est la santé. Rien faire c’est la conserver” :wink:

On 2011-01-17, please try again wrote:
>
> Rikishi42;2279123 Wrote:
>>
>> > -Der Rest ist Arbeit-. (Not sure if you can say “Rest is work” )
>> lol!
>>
>> Well, you could say, The rest is work. :slight_smile:
>>
>
> I know. But “Rest is work” sounds funnier. So does “Work is rest”.
> It reminds me of an old song by Henri Salvador, that said:
> “Le travail c’est la santé. Rien faire c’est la conserver” :wink:
>
> * http://www.youtube.com/watch?v=Q7IwInwZxp0 (1965)

Or as Coluche sang:
“Le boulot y’en a pas beaucoup. Faut le laisser a ceux qu’aiment ca.”

http://www.youtube.com/watch?v=nFc3ye5lzd0


When in doubt, use brute force.
– Ken Thompson

He also said “Ils bossent comme quatre … oui mais ils sont huit!” :slight_smile:

I wrote a couple functions to display different kind of dialog boxes. Take a look in that thread: dialog boxes in bash scripts

This is not a good idea. It means that more than one instance of the script running could suffer interference. It’s not good enough that the window of vulnerability between writing the file and reading it is small. Someday, somehow you will hit it.

This is not a good idea. It means that more than one instance of the script running could suffer interference. It’s not good enough that the window of vulnerability between writing the file and reading it is small. Someday, somehow you will hit it.
Consider that the method to retrieve said edited text was not prescribed by the OP. In the future perhaps no suggestions should be made then.

Thank You,

Inadequate solutions should always be flagged as such. There are workable ways to retrieve information from children scripts, shown in the posts succeeding yours.

On 2011-01-19, please try again wrote:
>
> Rikishi42;2279371 Wrote:
>>
>> Or as Coluche sang:
>> “Le boulot y’en a pas beaucoup. Faut le laisser a ceux qu’aiment ca.”
>>
>
> He also said “Ils bossent comme quatre … oui mais ils sont huit!” :slight_smile:
>
> I wrote a couple functions to display different kind of dialog boxes.
> Take a look in that thread: ‘dialog boxes in bash scripts’
> (http://tinyurl.com/5tfpdnz)

Very nice.
I’m also looking into PyQT solutions, partly because they would keep things
withina same routine and might allow me to support Unicode strings.

But getting help or suggestions (like yours) from the Python community on
that level is like asking S. Hawkins to add up a grocery bill for me. It
seems way to deemed too mundane a task for them even to react to, most
documented solutions are complete overkill and communication with them is a
challenge in itself.

Sigh… :slight_smile:

Oh well, at least it’s not contagious, eighter.


When in doubt, use brute force.
– Ken Thompson