Page 1 of 2

Xdialog combobox: How to edit text in entry field?

Posted: Thu 19 Dec 2013, 11:37
by MochiMoppel
I can't figure out how to make text in the entry field of a combobox editable.

Code: Select all

#!/bin/sh
ANSWER=`Xdialog  --editable --stdout --combobox "The stuff here should be editable" 0 0 "appel" "lemon"`
pupmessage "$ANSWER"
According to the manual the --editable option should do the trick, but doesn't.
The Xdialog manual wrote:--editable

This option is for use with the combobox widget. Its effect is to allow the user to edit the entry field of the combo box (by default it is not allowed to do so: only one of the items into the combo box pull-down list may be choosed).
I'm using Xdialog 2.3.1 that came with Slacko 5.6. Any help appreciated.

P.S. Didn't know that I can quote a link. :lol:

Posted: Thu 19 Dec 2013, 14:09
by rcrsn51
This Xdialog widget has always been wonky. Here is a simple replacement built from gtkdialog. The syntax is

Code: Select all

comboboxwidget Title Item1 Item2 .....

Posted: Thu 19 Dec 2013, 14:40
by amigo
"ANSWER=`Xdialog --editable --stdout --combobox "The stuff here should be editable" 0 0 "appel" "lemon"` " works fine for me here -but you surely have a different version than I do. Oh wait, I have it for either gtk1 or gtk2 -the gtk2 version doesn't work. Someone here before did a bit of work on the gtk2 version -maybe they can help out here -or maybe one of their fixes broke that. I'll have a look, too.

Posted: Thu 19 Dec 2013, 15:17
by amigo
He He, found it:
"gtk_entry_set_editable is deprecated and should not be used in newly-written code. Use gtk_editable_set_editable() instead." I'll create a patch and put it up. Ok, here it is:

Code: Select all

--- ./src/interface.c.00	2013-12-19 16:59:13.000000000 +0000
+++ ./src/interface.c	2013-12-19 17:29:42.000000000 +0000
@@ -1246,8 +1246,12 @@
 	if (strlen(Xdialog.default_item) != 0)
 		gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), Xdialog.default_item);
 
+#ifdef USE_GTK2
+	gtk_editable_set_editable(GTK_ENTRY(Xdialog.widget1), Xdialog.editable);
+#else
 	gtk_entry_set_editable(GTK_ENTRY(Xdialog.widget1), Xdialog.editable);
-
+#endif
+	
 	if (Xdialog.buttons) {
 		button_ok = set_all_buttons(FALSE, TRUE);
 		gtk_signal_connect(GTK_OBJECT(button_ok), "clicked", GTK_SIGNAL_FUNC(inputbox_ok), NULL);
Thanks for finding this on a day when I really should be warming up my grinch mood... Edit: Oops, that doesn't seem to fix it after all. Now I *am* felling grinchy...

Posted: Fri 20 Dec 2013, 02:09
by MochiMoppel
@rcrsn51:
Thanks. I know that I have choices, but Xdialog is so refreshingly simply for some tasks that I hate to give up on it. Your code works nicely but I dare to make a small suggestion: It should be

Code: Select all

for P in "$@"; do
which would accommodate entries containing spaces (comboboxwidget Title "apple jam" "lemon juice")

@amigo:
I admit that I have no clue what you are doing but I watch with fascination and eager expectation :lol:

Posted: Fri 20 Dec 2013, 02:24
by rcrsn51
MochiMoppel wrote:

Code: Select all

for P in "$@"; do
Good idea. I have posted v1.1 above.

Posted: Fri 20 Dec 2013, 16:17
by amigo
MochiMoppel, what version of gtk2 are you using?

Posted: Sat 21 Dec 2013, 02:05
by MochiMoppel
Honestly, I don't know for sure. Is there command to find this out? The PPM tells me
gtk+-1.2.10 ALREADY INSTALLED
gtk+2-2.24.10 ALREADY INSTALLED

Posted: Sat 21 Dec 2013, 03:50
by sunburnt
Refreshingly simple... Yeah, you could put it that way.

I`m about to post my own GtkDialog Q, and it`s a simple item also.
Whenever I`m going to use it I know I`ll spend all my time trying to get it to work.
If I go any further ( inconsistent syntax, unsupported props. & events ) this`ll be a rant.
.

Posted: Sat 21 Dec 2013, 07:46
by amigo
MochiMoppel, gtk+2-2.24 is what I have also. I suspect that this might have still been working for 2.23 -but I'm not sure. As it is, it requires a re-write of a section of Xdialog sources to create an editable combo-box. I see that thunor was having a time with this in gtkdialog and pointing out how many times the function had been renamed or used differnt syntax -pretty close to a dozen times!

Posted: Sat 21 Dec 2013, 17:03
by sunburnt
Time to fork it out ( or start over...) and make a completely incompatible "what-ever-it`s-called".?

Both the user end and the back end are messed up. Start with a clean slate and fix it all.

Posted: Sat 21 Dec 2013, 17:21
by rcrsn51
sunburnt wrote:Time to fork it out ( or start over...) and make a completely incompatible "what-ever-it`s-called".? Both the user end and the back end are messed up. Start with a clean slate and fix it all.
Are you talking about Xdialog or gtkdialog?

Other than the issue with combobox, I have no problems with Xdialog.

Posted: Sat 21 Dec 2013, 19:05
by sunburnt
Xdialog pretty much is what it is, it can`t be changed without forking it.

GtkDialog in my opinion is poorly conceived for a number of reasons.
As I`ve said before: I just pray for a good replacement for it.

Posted: Tue 24 Dec 2013, 19:26
by matiasbatero
sunburnt wrote:Xdialog pretty much is what it is, it can`t be changed without forking it.

GtkDialog in my opinion is poorly conceived for a number of reasons.
As I`ve said before: I just pray for a good replacement for it.
For now, GtkDialog is the most powerfull solution for GUI shell scripting.
It have a lot of limitations, of course. And requires some tricks to get some results. Also, widgets have function limitations. But your XML based system is very good.

At this point, in think that shell is very easy to learn and so powerfull, but if you want to get a more sophisticated GUI .. the solution is trying with another language.

Maybe, a design a box of powerfull bash functions, that can draw gtk code in another scripting language that support natively gtk. For example: Perl. Or, a compiled language like Vala, that contain internally bash code, and executes it by "system calls" could be the solution.

If not, there is no way.. and gtkdialog will need steroids

PD: sorry for my english

Posted: Wed 25 Dec 2013, 18:54
by sunburnt
I know what you`re saying, I`ve been using GtkDialog on and off for 6 years now.

GtkServer seems good, but I recall having trouble with it also.

Barry made a good choice with it, there`s not much else to replace it really ( sadly ).

As to xml being good...
The only 3 tags I see that need closing tags are the <hbox>, <vbox>, and <notebook>.
So all the rest of them are wasted effort.! Hard to read, understand, and prone to errors.

I made a wrapper for it years ago, but as usual I get disgusted with the results and quit.
.

Posted: Thu 26 Dec 2013, 13:08
by MochiMoppel
I get the feeling that this thread gets more and more derailed into a discussion about gtkdialog issues... :cry:
rcrsn51 wrote:Other than the issue with combobox, I have no problems with Xdialog.
I also have no serious problems. Xdialog is amazingly stable for such an old tool that was never meant to be used with gtk2.

I've tested now all widgets. Apart from combobox I found only 2 with problems:
yesno: --default-no option works only in combination with --check option; L18L reported a YesNo Bug, which I can't confirm for Slacko.
treeview: Doesn't work at all. Error message: Gtk-CRITICAL (recursed) **: IA__gtk_tree_store_append: assertion `VALID_ITER (parent, tree_store)' failed

Anything else?

Posted: Thu 26 Dec 2013, 15:59
by jamesbond

Code: Select all

jamesbond 2013
fix editable combobox problem under gtk2

Index: src/interface.c
==================================================================
--- src/interface.c
+++ src/interface.c
@@ -1220,25 +1220,45 @@
 	open_window();
 
 	set_backtitle(TRUE);
 	set_label(optarg, TRUE);
 
-	combo = gtk_combo_new();
+#ifdef USE_GTK2
+	combo = gtk_combo_box_entry_new_text(); 
+	Xdialog.widget1 = GTK_ENTRY (GTK_BIN (combo)->child);
+#else
+	combo = gtk_combo_new(); 
 	Xdialog.widget1 = GTK_COMBO(combo)->entry;
+#endif
 	Xdialog.widget2 = Xdialog.widget3 = NULL;
 	gtk_box_pack_start(Xdialog.vbox, combo, TRUE, TRUE, 0);
 	gtk_widget_grab_focus(Xdialog.widget1);
 	gtk_widget_show(combo);
+#ifndef USE_GTK2
 	gtk_signal_connect(GTK_OBJECT(Xdialog.widget1), "key_press_event",
 			   GTK_SIGNAL_FUNC(input_keypress), NULL);
+#endif
 
 	/* Set the popdown strings */
+#ifdef USE_GTK2	
+	for (i = 0; i < list_size; i++)
+		gtk_combo_box_append_text(GTK_COMBO_BOX(combo), options[i]);
+#else
 	for (i = 0; i < list_size; i++)
 		glist = g_list_append(glist, options[i]);
 	gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
+#endif
+
 	if (strlen(Xdialog.default_item) != 0)
+#ifdef USE_GTK2
+	{
+		gtk_combo_box_prepend_text(GTK_COMBO_BOX(combo), Xdialog.default_item);
+		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+	}
+#else
 		gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), Xdialog.default_item);
+#endif
 
 	gtk_entry_set_editable(GTK_ENTRY(Xdialog.widget1), Xdialog.editable);
 
 	if (Xdialog.buttons) {
 		button_ok = set_all_buttons(FALSE, TRUE);
This is confirmed to work.

Anyway, I started a repo for Xdialog here: http://chiselapp.com/user/jamesbond/rep ... alog/index. I have applied most of amigo's patches and some of mine (including this one).

I don't have any problems on default-no and treeview.

Posted: Thu 26 Dec 2013, 17:31
by amigo
Oh, thank you for that. I had already found that it was gonna need gtk_combo_box_entry_new_text() and gtk_combo_box_append_text but dreaded trying to get that going. You've answered our wish her.

Thanks very much for reporting back -I especially appreciate any fixes which apply to stuff I maintain on amigolinux.org. You mention other patches -do you have anything there I am not using?

I'll attach an archive of the patches I use(not including the one you just posted).

Posted: Fri 27 Dec 2013, 05:29
by jamesbond
No worries, it's just giving back to the community.
amigo wrote:Thanks very much for reporting back -I especially appreciate any fixes which apply to stuff I maintain on amigolinux.org. You mention other patches -do you have anything there I am not using?
I used:
1. 00-Xdialog-extra-button (from your patchset)
2. 01-Xdialog-gkt2-fixes-dougal (from your patchset)
3. 02-Xdialog-combobox-default-item (from your patchset)
4. default-no patch (based on yours, but "fixed" so that it works with NLS)
5. The editable-combobox patch above.
Oh and I use all the new icons from your patches too.

You can see the details and the patches if you visit that fossil page and go to timeline section.

Posted: Fri 27 Dec 2013, 06:52
by amigo
I don't see how to view individual commits there, can you post a copy of your fixed default-no patch?