How to get GtkDialog ListBox to read a file? [ Solved ]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

How to get GtkDialog ListBox to read a file? [ Solved ]

#1 Post by sunburnt »

It`s been awhile, and I can`t get the listbox to read a file.
I looked at zigbert`s tips forum, but it`s a mile long now.
I tried: <input file> , <input \"file\"> , <input>file:
<input>/path/file , <input>`cat /path/file` , <input>cat /path/file ,

The edit box and the entry won`t show anything either...
And I can`t remember how to refresh another control:<action>refresh:PKGS</action>

Scrap of code:

Code: Select all

APP=`basename $0 .gtk3`
CONF=/usr/local/etc/$APP/dnld.conf

export MAIN_DIALOG='
    <list>
      <variable>MAIN</variable>
      <input file>'"$1"'/main.list</input>
      <action>'"$APP pkgs $MAIN"'</action>
      <action>refresh:PKGS</action>
	  <width>150</width><height>300</height>
    </list>
    <list>
      <variable>PKGS</variable>
      <input file>'"$1"'/pkgs.list</input>
      <action>'"$APP info $PKGS"'</action>
      <action>refresh:INFO</action>
      <width>150</width><height>300</height>
    </list>
    <edit editable="false">
      <variable>INFO</variable>
      <input file>'"$1"'/pkg.info</input>
      <width>400</width><height>300</height>
    </edit>
The input files are there, but the list and edit boxes are empty.

Here`s the error:

Code: Select all

# ./deb-dnld.gtk3
### GTK

** (gtkdialog3:12099): WARNING **: gtkdialog: Warning: Could not stat '/pkg.info'..
sh: File:/usr/local/etc/deb-dnld/dnld.conf: No such file or directory
And here`s the dir. listing for the "non-existant" file:

Code: Select all

# ls -1 /usr/local/etc/deb-dnld/*
/usr/local/etc/deb-dnld/dist.conf
/usr/local/etc/deb-dnld/dnld.conf
/usr/local/etc/deb-dnld/srcbin.conf
Last edited by sunburnt on Fri 09 Sep 2011, 11:59, edited 1 time in total.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#2 Post by thunor »

Hi sunburnt

The list widget supports <input> but not <input file>.

The reason you got the error you did is because there is quite a lot of old code in Gtkdialog that wasn't written very thoroughly, so instead of telling you that <input file> isn't supported it goes ahead and lumps it in with <input> and attempts to execute it as a command -- I've seen this in several places.

I've written a simple example for you below. I've found that two consecutive refreshes results in a hang which is why the buttons are enabled and disabled. I don't know why this is -- I haven't looked at this widget yet -- but I do know that it's old and GTK+ deprecated it in GTK+ 2.0.

Code: Select all

#!/bin/sh

# This example requires at least gtkdialog-0.7.21

GTKDIALOG=gtkdialog

funcinputfileCreate() {
	echo "$RANDOM
$RANDOM
$RANDOM
$RANDOM
$RANDOM" > inputfile
}; export -f funcinputfileCreate

export MAIN_DIALOG='
<window title="List widget input from file" resizable="false">
	<vbox border-width="5" spacing="10">
		<list>
			<variable>lstMain</variable>
			<input>"funcinputfileCreate; cat inputfile"</input>
		</list>
		<hbox spacing="30">
			<button use-stock="true" label="gtk-clear">
				<variable>btnClear</variable>
				<action>clear:lstMain</action>
				<action>disable:btnClear</action>
				<action>enable:btnRefresh</action>
			</button>
			<button use-stock="true" label="gtk-refresh">
				<variable>btnRefresh</variable>
				<sensitive>false</sensitive>
				<action>refresh:lstMain</action>
				<action>disable:btnRefresh</action>
				<action>enable:btnClear</action>
			</button>
			<vseparator></vseparator>
			<button ok></button>
		</hbox>
	</vbox>
	<action signal="hide">exit:Exit</action>
</window>
'

$GTKDIALOG --program=MAIN_DIALOG
Regards,
Thunor

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#3 Post by 8-bit »

A word of caution here.
If you get the list created and were planning on trying to make an action button to act on the selection it will not work!
See the example in gtkdialog/examples/list/list_actions or /usr/share/doc/gtkdialog3/examples/07.02-list_actions

You can try using "<tree>" in place of "<list>". With it, the action command on a selection will work.

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

#4 Post by sunburnt »

Thanks thunor; I`ll give it a go here.

I suggested a number of times over the years to make a wrapper for gtkDialog.
Then the dev. interface code wouldn`t change every time the gtkDialog guys
decide to rearrange everyone`s universe. Just correct the wrapper...
And Barry wouldn`t have to rewrite Puppy`s GUIs over and over again!

I made a bash shell function library years ago that created gtkDialog files.
Write a simple script and create the GUI, or run the GUI directly with the script.

8-bit; Yeah, gtkDialog supports so few properties and methods, it`s almost unusable.

A click on the list box puts the selection in a file, the button reads the file.
Sad... But that`s the only way that it works most of the time.

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

#5 Post by sunburnt »

thunor; I stated in my original post that I tried: <input> , that`s how I remember it being done.
Needless to say, it still doesn`t work. I guess I`ll post the entire script.
I seem to recall that you need to: '"$VAR"' enclose " " with ' ', like '" "' .

Code: Select all

#!/bin/sh
APP=`basename $0 .gtk3`					# app. name
CONF=/usr/local/etc/$APP/dnld.conf			# dnld. path

export MAIN_DIALOG='
<vbox>
  <hbox>
    <list>
	<variable>MAIN</variable>
	<input>'"cat $1/main.list"'</input>
	<action>'"$APP pkgs $MAIN"'</action>
	<action>refresh:PKGS</action>
	<width>150</width><height>300</height>
    </list>
    <list>
	<variable>PKGS</variable>
	<input>'"cat $1/pkgs.list"'</input>
	<action>'"$APP info $PKGS"'</action>
	<action>clear:INFO</action>
	<action>refresh:INFO</action>
	<width>150</width><height>300</height>
    </list>
    <edit editable="false">
	<variable>INFO</variable>
	<input>'"cat $1/pkg.info"'</input>
	<width>400</width><height>300</height>
    </edit>
  </hbox>
  <hbox>
    <entry>
      <variable>DIR</variable>
      <input>'"cat $CONF"'</input>
    </entry>
    <button>
      <input file stock="gtk-open"></input>
      <variable>SEL_DIR</variable>
      <action type="fileselect">DIR</action>
    </button>
    <button ok></button>
    <button cancel></button>
  </hbox>
</vbox>
'
gtkdialog3 --program=MAIN_DIALOG
I still need to put in the window`s position save and position set code.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#6 Post by thunor »

sunburnt wrote:thunor; I stated in my original post that I tried: <input> , that`s how I remember it being done.
Yes you did, but the "Scrap of code" within your original post uses "<input file>" within the list widgets and I am explaining that it is unsupported.

I think that these modifications [to the script directly above me] are what you need:

Code: Select all

<input>cat '"$1"'/main.list</input>
<action>'"$APP"' pkgs $MAIN</action>

Code: Select all

<input>cat '"$1"'/pkgs.list</input>
<action>'"$APP"' info $PKGS</action>

Code: Select all

<input>cat '"$1"'/pkg.info</input>

Code: Select all

<input>cat '"$CONF"'</input>
Regards,
Thunor

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

#7 Post by sunburnt »

Thanks thunor; I changed it to just the variables being quoted.

I quoted the second set of variables you missed: $MAIN and $PKGS.

Code: Select all

 like this:
		<action>'"$APP"' pkgs '"$MAIN"'</action>
and this:
		<action>'"$APP"' pkgs '"$PKGS"'</action>
Now it doesn`t show at all, it just leaves a crashed process to kill.

As long as we`re at it, is the "clear:" command needed, or is "refresh:" enough?
<action>clear:PKGS</action>
<action>refresh:PKGS</action>
gtkDialog2 needed both to work.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#8 Post by 8-bit »

As I previously stated, trying to use "<action>do something</action>" to act on the list variable of the selection item will not work. It locks up the program and if you open "Htop", you will see a lot of processing power being used.

You can verify this with thunor finding the same thing.
That is why he stated an example, "list_actions" is broken.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#9 Post by thunor »

sunburnt wrote:I quoted the second set of variables you missed: $MAIN and $PKGS.

Code: Select all

 like this:
		<action>'"$APP"' pkgs '"$MAIN"'</action>
and this:
		<action>'"$APP"' pkgs '"$PKGS"'</action>
Now it doesn`t show at all, it just leaves a crashed process to kill.

As long as we`re at it, is the "clear:" command needed, or is "refresh:" enough?
<action>clear:PKGS</action>
<action>refresh:PKGS</action>
gtkDialog2 needed both to work.
From your application above, I understood MAIN and PKGS to be the list widget <variable> names and if that is the case then they shouldn't be quoted. If MAIN and PKGS are instead shell variables that you wish to insert the contents of into your XML at XML construction time then they should be quoted as you've done above; your choice depending on requirements :)

Today I wrote the list widget reference and created examples/list/list_advanced and I've fixed a nasty bug that was making the list widget hang. If you want to use the list widget then I recommend checking-out the latest revision from SVN.

Regards,
Thunor

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#10 Post by 8-bit »

Thunor,
Again, thank you for all your work on gtkdialog.
To get long standing bugs in gtkdialog fixed takes a lot off effort and it is appreciated!

I did not know of your recent update when I made the comment to sunburnt on the use of list.

I have updated my code accordingly.

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

#11 Post by sunburnt »

Your right again thunor; Looking at old scripts showed my error.

I`m getting the docs and going to svn. Let you know...

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

#12 Post by sunburnt »

Success finally! Out of frustration I reworked it completely.

I changed the listBox for a table.
And the title line kept it from working also.

# What`s the correct code for a title?

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#13 Post by 8-bit »

If you enclose it all in a window, you can put <window title="My Title" icon-name="gtk-file"> before the first <vbox> and </window> after the last </vbox>.

icon-name places an icon of your choice on the program header along with the title.

To add a name to a button, use <label>button name</label> after the first <button>.

You can also check out the various examples in /usr/share/doc/gtkdialog3/examples.

Hope that helps.

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

#14 Post by sunburnt »

Thanks 8-bit; It did the trick!

I needed the window title so it could get the window position at exit.
Now it starts up in the same place it shut down at.

Post Reply