[gtkada] Detecting key_press_event when using a label

Paul Cass cassp41 at yahoo.com.au
Sat Jun 12 08:04:11 CEST 2010


Hi,
    I'm developing, for my own amusement, a Sudoku game in GTKADA.  The Sudoku game area consists of  81 cells in a 9 * 9 grid.  Each cell usually contains a number (1 to 9) or blank, or it could contains candidate numbers as hints.  The most obvious display widget for the cell seems to be the GTK.Label.GTK_Label type.  Labels are not a normal editing widget and are intended for display purposes although you can make it selectable for cut and paste purposes. 

My problem is trying to make the label widget, or a container containing the label, respond to the key_press_event.  I understand the 'normal' way of doing this is to add the label to an Event_Box and write a suitable callback handler for the event_box.  The only way I can get the callback handler to detect the key_press_event is to enable the 'selectable' property of the label.  This has an undesirable side effect of displaying a selection point 'cursor' in the label.  I would prefer to avoid this visual effect.

The key_press_event callback handler validates that the key press is a number between 1 and 9 and then updates the label widget text.  At a later stage I will add validation against the game solution as well.  But I need to get the visual aspects sorted first.

I can detect a number of events including the button_press_event but something appears to be handling the key_press_event before it reaches my handler and discarding the event.  I've tried many permutations of labels inside of boxes, frames, viewports, etc without any success.  Currently I'm replacing the labels with buttons which will respond to the key_press_event but cause some visual problems.  My preference is to use labels.

So, is there some way of telling the underlying system that I want my handler to deal with key_press_events?  

I'm writing this in Windows 7 (64 bit), and the current GPL GNAT and GTKADA (2.14.0 I think).

TIA

Paul


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/gtkada/attachments/20100611/647c539d/attachment.htm 


More information about the gtkada mailing list