Xdialog combobox: How to edit text in entry field?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Xdialog combobox: How to edit text in entry field?

#1 Post 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:

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#2 Post 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 .....
Attachments
comboboxwidget-1.1.pet
(696 Bytes) Downloaded 367 times
Last edited by rcrsn51 on Fri 20 Dec 2013, 02:23, edited 1 time in total.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#3 Post 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.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#4 Post 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...

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post 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:

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#6 Post by rcrsn51 »

MochiMoppel wrote:

Code: Select all

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

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post by amigo »

MochiMoppel, what version of gtk2 are you using?

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#8 Post 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

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#9 Post 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.
.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#10 Post 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!

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#11 Post 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.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#12 Post 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.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#13 Post 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.

User avatar
matiasbatero
Posts: 60
Joined: Fri 12 Oct 2012, 01:27
Location: Mar del Plata, Argentina

#14 Post 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

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#15 Post 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.
.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#16 Post 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?

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#17 Post 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.
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#18 Post 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).
Attachments
xdialog-gtk2-patches.tar.bz2
(13.53 KiB) Downloaded 185 times

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#19 Post 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.
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#20 Post by amigo »

I don't see how to view individual commits there, can you post a copy of your fixed default-no patch?

Post Reply