Need GUI pop-up to edit a (unicode ?) string

R

Rikishi42

I'm in need for a graphical pop-up that will display a (unicode ?) string in
a field, allow the user to change it and return the modified string.

Maybe also keep the original one displayed above it.


Something like this:
+-------------------------------------------------+
| Please confirm or edit the following string |
| |
| Original_example_string |
| |
| +-------------------------------------------+ |
| | Original_about_to_be_changed | |
| +-------------------------------------------+ |
| |
| OK |
| |
+-------------------------------------------------+


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.

From what I can see the solution lays with PyQT, but the docs I find are
courses that aim to teach the whole GUI tool. I only need a little pop-up to
alow a user to edit part of a filename, for instance.


I'm using Python 2.6.x on various Linux platforms (mainly openSUSE and Mint)
and on Windows. Windows support is not important, in this case.
 
C

Corey Richardson

I'm in need for a graphical pop-up that will display a (unicode ?) string in
a field, allow the user to change it and return the modified string.

Maybe also keep the original one displayed above it.


Something like this:
+-------------------------------------------------+
| Please confirm or edit the following string |
| |
| Original_example_string |
| |
| +-------------------------------------------+ |
| | Original_about_to_be_changed | |
| +-------------------------------------------+ |
| |
| OK |
| |
+-------------------------------------------------+


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.

courses that aim to teach the whole GUI tool. I only need a little pop-up to
alow a user to edit part of a filename, for instance.


I'm using Python 2.6.x on various Linux platforms (mainly openSUSE and Mint)
and on Windows. Windows support is not important, in this case.

If that is all you need, I suggest Tkinter. Nice and easy, comes built
into Python. Looks like you need two labels, an entry, and a button.
When I was learning Tkinter I used http://effbot.org/tkinterbook/.

Hope it helped,
~Corey
 
G

geremy condra

I'm in need for a graphical pop-up that will display a (unicode ?) string in
a field, allow the user to change it and return the modified string.

Maybe also keep the original one displayed above it.


Something like this:
+-------------------------------------------------+
|   Please confirm or edit the following string   |
|                                                 |
|     Original_example_string                     |
|                                                 |
|  +-------------------------------------------+  |
|  |  Original_about_to_be_changed             |  |
|  +-------------------------------------------+  |
|                                                 |
|                     OK                          |
|                                                 |
+-------------------------------------------------+


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.

courses that aim to teach the whole GUI tool. I only need a little pop-up to
alow a user to edit part of a filename, for instance.


I'm using Python 2.6.x on various Linux platforms (mainly openSUSE and Mint)
and on Windows. Windows support is not important, in this case.

If windows doesn't matter to you, just use Zenity. Here's a python
function wrapping zenity that does what you want:

import commands

def confirm_or_edit(s):
zenity = 'zenity'
mode = '--entry'
text = "--text='Please confirm or edit the following string:'"
title = "--title='confirm or edit'"
entry = "--entry-text='%s'" % s
cmd = ' '.join([zenity, mode, text, title, entry])
status, output = commands.getstatusoutput(cmd)
if status: raise Exception("Couldn't run zenity")
return output

There's also a full-blown API for zenity, but this should do what you want.

Geremy Condra
 
R

Rikishi42

If that is all you need, I suggest Tkinter. Nice and easy, comes built
into Python. Looks like you need two labels, an entry, and a button.
When I was learning Tkinter I used http://effbot.org/tkinterbook/.

I had to add Tkinter, which was not isntalled on my machine.

But it looks easy enough, I'll definitively look into it.


Thanks !
 
R

Rikishi42

If windows doesn't matter to you, just use Zenity. Here's a python
function wrapping zenity that does what you want:

import commands

def confirm_or_edit(s):
zenity = 'zenity'
mode = '--entry'
text = "--text='Please confirm or edit the following string:'"
title = "--title='confirm or edit'"
entry = "--entry-text='%s'" % s
cmd = ' '.join([zenity, mode, text, title, entry])
status, output = commands.getstatusoutput(cmd)
if status: raise Exception("Couldn't run zenity")
return output

There's also a full-blown API for zenity, but this should do what you want.

Very, very nice. Thanks !

I'm amazed at how many GUI's are available.


No wonder I couldn't find "the" interface, there are too many. :)
 
R

rantingrick

I'm in need for a graphical pop-up that will display a (unicode ?) string in
a field, allow the user to change it and return the modified string.

Maybe also keep the original one displayed above it.

Something like this:
+-------------------------------------------------+
|   Please confirm or edit the following string   |
|                                                 |
|     Original_example_string                     |
|                                                 |
|  +-------------------------------------------+  |
|  |  Original_about_to_be_changed             |  |
|  +-------------------------------------------+  |
|                                                 |
|                     OK                          |
|                                                 |
+-------------------------------------------------+

If you download wxPython and build it with unicdode support (i did not
for my version!) you can use a simple textctrl and a statictext to
display this.

For an example of how to do this download the wxPython demo and in the
tree menu under the "miscellaneous" node pick the "Unicode" example.
You will be able to see both the source code and run a demo of this
example strait from the demo GUI! If you need help turning the demo
code into something usable for your script then post back here and i
will help you create whatever you want.
 
B

Bryan

I'm in need for a graphical pop-up that will display a (unicode ?) string in
a field, allow the user to change it and return the modified string.

Maybe also keep the original one displayed above it.

Something like this:
+-------------------------------------------------+
|   Please confirm or edit the following string   |
|                                                 |
|     Original_example_string                     |
|                                                 |
|  +-------------------------------------------+  |
|  |  Original_about_to_be_changed             |  |
|  +-------------------------------------------+  |
|                                                 |
|                     OK                          |
|                                                 |
+-------------------------------------------------+

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.

From what I can see the solution lays with PyQT, but the docs I find are
courses that aim to teach the whole GUI tool. I only need a little pop-up to
alow a user to edit part of a filename, for instance.

I'm using Python 2.6.x on various Linux platforms (mainly openSUSE and Mint)
and on Windows. Windows support is not important, in this case.

tkinter is likely the easiest solution. Here's a quick hack, assuming
you want a program with a single window, rather than dialog you can
pop up. This has no cancel button since you didn't specify you wanted
one. It just pops up a window, and when you press ok, <return> or
dismiss via the window manager, the edited value will be printed to
stdout. It's not a perfect solution but it gives you a feel for how
easy it is to do with tkinter.

import Tkinter as tk

class App(tk.Tk):
def __init__(self, s):
tk.Tk.__init__(self)
self.wm_title("Edit the string")

# the main layout is composed of four areas:
# 1) the label / instructions
# 2) the original value
# 3) the edit field
# 4) a row of buttons
label = tk.Label(self, text="Please confirm or edit the
following string:")
oframe = tk.LabelFrame(text="Original:")
eframe = tk.LabelFrame(text="Edited:")
buttons = tk.Frame(self)

orig = tk.Entry(self, width=40)
edit = tk.Entry(self, width=40)
edit.insert(0, s)
orig.insert(0, s)
orig.config(state="disabled")
ok = tk.Button(self, text="Ok", command=self.ok,
default="active")

# this does all the layout
label.pack(side="top", fill="both", expand=True)
oframe.pack(side="top", fill="both", expand=True, padx=4)
eframe.pack(side="top", fill="both", expand=True, padx=4,
pady=(4,0))
orig.pack(in_=oframe, side="top", fill="x", padx=4, pady=4)
edit.pack(in_=eframe, side="top", fill="x", padx=4, pady=4)
buttons.pack(side="bottom", fill="x", pady=4)
ok.pack(in_=buttons, expand=True)

edit.select_range(0, "end")
edit.bind("<Return>", lambda event: self.ok)
self.wm_protocol("WM_DELETE_WINDOW", self.ok)
edit.focus()

# keep a reference so self.ok can access it
self.edit = edit

def ok(self):
value = self.edit.get()
print value
self.destroy()

if __name__ == "__main__":
import sys
try:
s = sys.argv[1]
except:
s = "Hello, world"
app = App(s)
app.mainloop()
 
R

rantingrick

tkinter is likely the easiest solution. Here's a quick hack,

[...snip code...]

Well this is nice Bryan however it should be much easier than this.
Basically your code is creating most of the functionality that should
be wrapped up in a Dialog class. Tkinter has the tkSimpleDialog from
which one can inherit and build custom dialogs like the one you have
here however it has a major flaw! Fredrick choose not give the class a
show method and instead just threw all the code that should be in a
"show" method into the __init__ method. This is not a good idea. And
i'll explain why...

What Fredrick was trying to do was to make noob programmers life
easier. And he accomplished this in a specific way! However by NOT
creating a show method he has at the same time handicapped these same
people! The proper way to use a dialog class is...

* Subclass a built-in in Dialog class and insert some widgets.
class MyDialog(tkSimpleDialog.Dialog): blah

* Create and instance of your custom dialog.
dlg = MyDialog(blah)

* Configure any widget values (if needed!)
dlg.origText['text'] = unicodestring

* and show the dialog
dlg.show(blah)

This design pattern promotes reuse-ability and encapsulation. However
with Fredricks design you cannot configure the contained widgets after
creating the instance because the dialog has entered a local event
loop brought on by "self.wait_window(self)" which is in the DAMN
INITIAL METHOD! This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself! What a jerk! Which is quite
disgusting considering that Tkinter, and TclTk are completely open
source!

And i don't want to hear any arguments about invoking the __init__
method because if you read the source you will see why doing that is
completely ridiculous because of Fredericks design. This is another
example of how few people actually use Tkinter. If many people where
using the module obviously bad code such as this would not exist for
14 years! Someone would have complained.

If Frederic wants some pointers for how to create a proper dialog he
should contact me, or we should have a discussion here. The sad thing
is that this dialog has not been fixed since 1997. And you people
wonder why i hate Tkinter!
 
T

Terry Reedy

This design pattern promotes reuse-ability and encapsulation. However
with Fredricks design you cannot configure the contained widgets after
creating the instance because the dialog has entered a local event
loop brought on by "self.wait_window(self)" which is in the DAMN
INITIAL METHOD!

I only see "self.wait_window(self)" in the Dialog base class and not in
SimpleDialog, which is what I though you were talking about. It is the
last line of Dialog.__init__. It appears that the intention is that all
configuration be done in the body and button_box methods which are
called earlier.
> This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself!

As far as I know, anything contributed to the stdlib has been licensed
by the author to be redistributed under the Python license and can be
patched by the developers. (This is one reason for people to not
contribute their code to the stdlib.)
 
R

rantingrick

I only see "self.wait_window(self)" in the Dialog base class and not in
SimpleDialog, which is what I though you were talking about. It is the
last line of Dialog.__init__.

Yes. In the module "tkSimpleDialog" the class "Dialog" is what i am
referring to. Sorry for the confusion.
It appears that the intention is that all
configuration be done in the body and button_box methods which are
called earlier.

Yes exactly. And this works well most of the time. However there are
many times where you may want to create a dialog with say a Label. And
you do not want to hard code the string displayed on the label.
However you cannot change the string once you initialize the dialog
because it enters a "modal wait loop". So what i am proposing is that
we change tkSimpleDialog to be like any other modal dialogs out there.
We move the modal code into a show method and use the dialog like i
suggested. I can send you a patch if you would be interested. My patch
does break backward compatibility. However we can make it compatible
somehow. Or an alternative approach would be to create a new dialog
module and then depreciate tkSimpleDialog. Let me know on or off list
if you are interested.
As far as I know, anything contributed to the stdlib has been licensed
by the author to be redistributed under the Python license and can be
patched by the developers. (This is one reason for people to not
contribute their code to the stdlib.)

I don't understand what that means. Are you suggesting that
contributing code is bad?
 
T

Terry Reedy

Yes. In the module "tkSimpleDialog"

In 3.x, the module is now tk.simpledialog -- all lower case. The purpose
of all lowercase module names is to avoid confusion with upper case
class names.
the class "Dialog" is what i am
referring to. Sorry for the confusion.

and there is also a SimpleDialog class.
Yes exactly. And this works well most of the time. However there are
many times where you may want to create a dialog with say a Label. And
you do not want to hard code the string displayed on the label.
However you cannot change the string once you initialize the dialog
because it enters a "modal wait loop". So what i am proposing is that
we change tkSimpleDialog to be like any other modal dialogs out there.

SimpleDialog has a go method. Dialog does not, but I see no reason (yet)
why it could not.
We move the modal code into a show method and use the dialog like i
suggested. I can send you a patch if you would be interested.

I saw that first and was puzzled what you were asking. Clearer now.
My patch
does break backward compatibility. However we can make it compatible
somehow. Or an alternative approach would be to create a new dialog
module and then depreciate tkSimpleDialog. Let me know on or off list
if you are interested.


I don't understand what that means. Are you suggesting that
contributing code is bad?

If you write code and want to keep absolute control over it -- the api,
the doc, the coding style, and the test methods -- then yes it can be
bad, especially for people who are not active core developers.
Contributing can also be a great -- if the module already meets with
approval or if one is flexible and wants the critical review and likely
improvement and increased usage. It depends on one's goal in writing the
code.
 
R

rantingrick

In 3.x, the module is now tk.simpledialog -- all lower case. The purpose
of all lowercase module names is to avoid confusion with upper case
class names.

Yes Terry, i found the new module and documented the bugs in a new
thread. I am not sure if the bugs are still present in the current RC
(Note: i have 3.1.1 installed) however i would bet they are. As soon
as i can find the current source in svn i'll update the "bug thread".
However i cannot find it. If you can give a link that would be great!
 
S

Stephen Hansen

This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself! What a jerk! Which is quite
disgusting considering that Tkinter, and TclTk are completely open
source!


Uh. ... LOL.

Copyright doesn't mean what you think it means.

Tkinter is copyrighted. Python is copyrighted. Tcl/TK is copyrgithed.

In fact: everything that is "open source" is copyrighted. By
definition[* see footnote].

Open source is simply copyrighted material that has been released under
a *license* that allows you to copy it, too: sometimes with some
significant catches (i.e., GPL), sometimes with basically no strings at
all except not to sue (i.e., MIT).

So.

Its a major flaw? Well! Go fix it, you have every right to. Python's
source is released under a rather liberal license, allowing you to do
just about anything you want with it. Including fix it and even-- gasp--
submit those fixes to the bug-tracker for inclusion.


--

Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

* Some software has no copyright, such as SQLITE: it has been released
into the public domain. But that is exceedingly rare, and can be a bit
complicated as public domain and its meaning varies from jurisdiction to
jurisdiction. Whereas copyright is pretty standard across the board and
subject to a whole lot of international treaties. I'm really not sure
you can legitimately call public domain software open source: its free
to use, modify, and do anything you want with (provided you're in a
jurisdiction which recognizes public domain), but it has its own
particular legal ... issues. Then again, IANAL.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)

iQEcBAEBAgAGBQJNQPkgAAoJEKcbwptVWx/l2EoIALbYtmfWsV55bsVShkIgAXJU
wxmwrmOgZpQyB1df51zWluCQAxSi95TucGu6SMozcASrOK/IXshdd51cDxOxnbpi
FTephdc6VK5GTSCBVwofuArObQjBhMiCTdYml3hJkSjMtd8LCQZFeQTAhNcv4fAM
te1sUDj7QHX66uu1trhFvUYlzdeTArCYLtA2WI25Q6DTEjsjLmGUOlmPPIVCpEo2
MLDkxQbkRnuO/vmcdos9Yv1xj0IRH+e/f8yyGxgB4ZGE9N0YNQIflm4lRn8rKR9z
EWNnLjwzSssJvmYsZdqwP0D8effT6IAK0xYfwWOWlMwffvrY/IIvU7s4H4CAc6M=
=w/Kg
-----END PGP SIGNATURE-----
 
G

Grant Edwards

This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself! What a jerk! Which is quite
disgusting considering that Tkinter, and TclTk are completely open
source!

Uh. ... LOL.

Copyright doesn't mean what you think it means.

Tkinter is copyrighted. Python is copyrighted. Tcl/TK is copyrgithed.

In fact: everything that is "open source" is copyrighted. By
definition[* see footnote].

One (domestic US) exception would be open-source software written by
an employee of the US federal government. Works produced by the US
Government are not copyrighted under US domestic copyright law. Such
works are copyrighted under international law (which is probably what
the Python maintainers care about).
 
S

Stephen Hansen

This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself! What a jerk! Which is quite
disgusting considering that Tkinter, and TclTk are completely open
source!

Uh. ... LOL.

Copyright doesn't mean what you think it means.

Tkinter is copyrighted. Python is copyrighted. Tcl/TK is copyrgithed.

In fact: everything that is "open source" is copyrighted. By
definition[* see footnote].

One (domestic US) exception would be open-source software written by
an employee of the US federal government. Works produced by the US
Government are not copyrighted under US domestic copyright law. Such
works are copyrighted under international law (which is probably what
the Python maintainers care about).

I've actually wondered a bit about that: but the only open source
software that I'm aware of that's been government-adjacent has ended up
being written/owned by some University or joint venture funded by a
government agency -- it didn't fall into the public domain category of
content created directly by the federal government.

Are you aware of any code out there that is? Just curious. I'm not
arguing that the exception doesn't exist or anything.

--

Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)

iQEcBAEBAgAGBQJNQbcSAAoJEKcbwptVWx/l9zkH/jZrIcnJz7qsjYW02PqhVQCh
2zCdQh8TDeKEJgtCW+ptbDDFxhdv1clfnPmBVqO6RNnHemycdGxLpLqCFwFQk1oL
VlbwbrBJARcyDqbcTW235JL4+y0Je3ie4yRz7iX4g1MDMddD/GDt8oQR2bXW/oJ+
xzT1cQyQuuHczyaLqCsJp4b9La4yMRuch0w4FVmjLGNnVYwRVcv9NrbuZV2kgNLT
+HxDrTFH5WhbYGJ9cDUAAzwTJl2lYrbBnana66J3kJWo4UGHv8jM3T162ab6wXS4
GM29zbS3qKeyQaWSmB51iw6apt2kP18XlBmB5YHfK6fFJTPhL6uERYYX67LP+0Q=
=6ey0
-----END PGP SIGNATURE-----
 
G

Grant Edwards

In fact: everything that is "open source" is copyrighted. By
definition[* see footnote].

One (domestic US) exception would be open-source software written by
an employee of the US federal government. Works produced by the US
Government are not copyrighted under US domestic copyright law. Such
works are copyrighted under international law (which is probably what
the Python maintainers care about).

I've actually wondered a bit about that: but the only open source
software that I'm aware of that's been government-adjacent has ended
up being written/owned by some University or joint venture funded by
a government agency -- it didn't fall into the public domain category
of content created directly by the federal government.

That seems to be the usual case.
Are you aware of any code out there that is? Just curious. I'm not
arguing that the exception doesn't exist or anything.

No, I can't point to anything significant or recent. I have vague
memories of stuff from a long time ago (back when open-source software
travelled hand-to-hand on DECUS tapes) written by people at NOAA or
USGS that was copyright-free.
 
R

Robert Kern

On 1/25/11 3:02 PM, rantingrick wrote:
This is a major flaw in the design and i would be
happy to fix the flaw. However our "friend" Fredrick decided to
copyright the module to himself! What a jerk! Which is quite
disgusting considering that Tkinter, and TclTk are completely open
source!

Uh. ... LOL.

Copyright doesn't mean what you think it means.

Tkinter is copyrighted. Python is copyrighted. Tcl/TK is copyrgithed.

In fact: everything that is "open source" is copyrighted. By
definition[* see footnote].

One (domestic US) exception would be open-source software written by
an employee of the US federal government. Works produced by the US
Government are not copyrighted under US domestic copyright law. Such
works are copyrighted under international law (which is probably what
the Python maintainers care about).

I've actually wondered a bit about that: but the only open source
software that I'm aware of that's been government-adjacent has ended up
being written/owned by some University or joint venture funded by a
government agency -- it didn't fall into the public domain category of
content created directly by the federal government.

Are you aware of any code out there that is? Just curious. I'm not
arguing that the exception doesn't exist or anything.

A lot of stuff from NIST is legitimately public domain. E.g.

http://fingerprint.nist.gov/NFIS/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top