hello all,
i am new to GTK actually, but am trying to develop a UI with GTK on linux.
I wanted to know, whether any widget is available in GTK which can allow me to enter the IP address in the format its normally entered, ex: 195. 156. 15. 46 (dotted decimal)
and that i should be allowed to enter only numbers.

Then use the insert-at-cursor signal of the GtkEntry to restrict it to only digits. Of course, like I said before, making a custom widget would probably be the best thing to do, but that is your choice.

You could integrate it even better by setting the background color of every widget as the same color & then placing a black one pixel border around the hbox in a custom widget.

This is actually a really good idea for an example. I am currently working on a book on GTK+ programming that will be coming out in a few months. Would you give me permission to use this idea for an example in the book in the custom widgets chapter?

Thanks Andrew for the above solutions. I could'nt get the idea about ur second solution about "change" signal. Can please put some light on the same.
When is your book releasing by the way?
Thnaks a lot once again,
Regards,
Shri.

Actually, I misspoke on that. What you could do is set the default text of the entry to " . . . ", where there are spaces. Then, connect the entry to key-press-event with the g_signal_connect() function.

Then, when a key is pressed, check if it is a digit. It it is a digit, replace the space with the number. If it is delete or backspace, take appropriate action. Ignore all other keys. Then, make sure you return TRUE from the callback function so GTK+ will take no further action. Otherwise, GTK+ would continue to carry out the key-press-event action.

Being that you are new to GTK+, I would recommend using the third solution, however. The second solution requires that you are familiar with a lot of things a beginner probably wouldn't know yet. But then again, it would be a good learning experience.

Hi Andrew,
i have done the boxes for entering the dotted decimal format (for IP address) numbers, as suggested by u.
but how do i get the entered numbers for checking whether they are vaild or not?
i tried this by using the API "gchar* gtk_entry_get_text (GtkEntry *entry) ", but since i have made the entry length as three the first time it returns me the single character which is entered, the 2nd time it returns me 2 characters, n the third time 3. how do i get each entry discretely, so that i can check for its validity?

Please suggest some method to receive each entered numbers discretely, so that i can check each one of it for its validity?
thanks in advance
regards,
Shri.

Then, in the callback function, check to see what the GDK key value of the key is. If it is one of the ten digit keys or one of the keypad digit keys, return FALSE. When you return false from a GDK event callback function, the GTK+ continues to handle the event. By returning TRUE if the key is not a number, GTK+ will take no further action.

Who is online

Users browsing this forum: Google [Bot] and 3 guests

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