GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Apr 21, 2014 9:41 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Entering non ascii characters in pygtk entry box
PostPosted: Sun Mar 24, 2013 7:03 pm 
Offline
Familiar Face

Joined: Sun Mar 24, 2013 8:35 am
Posts: 6
The Entry-code example in http://zetcode.com/gui/pygtk/widgetsII/ does not react on entering non ascii characters such as ë in the entry box if I use direct keyboard input via Alt-0235.
It does work if I do it via ctrl-c ctrl-v from another application. How can I make it working as well for the direct keyboard input such as Alt-0235?
I'm using python 2.7.3, Windows7.


Top
 Profile  
 
 Post subject: Re: Entering non ascii characters in pygtk entry box
PostPosted: Mon Mar 25, 2013 8:07 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hi,

Do you know which version of GTK+ you are using? There are some changes with the GtkEntry widget with 2.18.

In this case Alt-0235 is not passed on as a key release. It is processed within Windows and the character generated is then inserted into the GtkEntry's buffer, without generating any key presses.

The example shown in the link is a little simple and does not take into account that text can be entered with out pressing any keys on the keyboard.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Entering non ascii characters in pygtk entry box
PostPosted: Mon Mar 25, 2013 3:16 pm 
Offline
Familiar Face

Joined: Sun Mar 24, 2013 8:35 am
Posts: 6
Errol,

gtk.gtk_version gives (2,24,10). If the problem is that Alt-0235 is currently not passed on as a key release, (how) can I change the code to have it passed on as a key release?


Top
 Profile  
 
 Post subject: Re: Entering non ascii characters in pygtk entry box
PostPosted: Tue Mar 26, 2013 11:46 am 
Offline
Familiar Face

Joined: Sun Mar 24, 2013 8:35 am
Posts: 6
I found the solution: Press and hold the Ctrl-Shift and type u, followed by the unicode of the character, using the numbers above the letter keys and not the numbers on the numerical key-pad. E.g. Ctrl-Shift u00eb gives the character ë.


Top
 Profile  
 
 Post subject: Re: Entering non ascii characters in pygtk entry box
PostPosted: Wed Mar 27, 2013 11:53 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hi, this is a modification of the original code. This should work with PyGtk 2.22 and above.
Code:
#!/usr/bin/python

# ZetCode PyGTK tutorial
#
# This example demonstrates the Entry widget changes for PyGtk 2.22+
#
# author: jan bodnar
# website: zetcode.com
# last edited: February 2009

import gtk

class PyApp(gtk.Window):

    def __init__(self):
        super(PyApp, self).__init__()
       
        self.set_title("Entry")
        self.set_size_request(250, 200)
        self.set_position(gtk.WIN_POS_CENTER)

        fixed = gtk.Fixed()

        self.label = gtk.Label("...")
        fixed.put(self.label, 60, 40)

        entry = gtk.Entry()
        abuffer = entry.get_buffer()
        fixed.put(entry, 60, 100)

        abuffer.connect("deleted-text", self.on_delete_text)
        abuffer.connect("inserted-text", self.on_insert_text)

        self.connect("destroy", gtk.main_quit)
        self.add(fixed)
        self.show_all()

    def on_insert_text(self, abuffer, position, chars, n_chars):
        self.label.set_text(abuffer.get_text())

    def on_delete_text(self, abuffer, position, n_chars):
        self.label.set_text(abuffer.get_text())

PyApp()
gtk.main()


This works by monitoring any changes to the GtkEntryBuffer so should work with any method of text entry/deletion. The original only worked by looking for keyboard button press releases. This is OK if your entry is via the keyboard (not all keyboard entry give a keyboard button event). So if you do some entry via the mouse then the original would not work.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group