GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#61 Post by 01micko »

zigbert wrote:Hello Mick
Nice tutorial!
I will include this in the main post, but thought it might fit better as a new chapter - The benefits of a config file.
- Both <entry> and <edit> widgets uses the <default> tag.
- How to activate a given item in a combobox.


Sigmund
Hi Sigmund,

Glad I could add something useful to this thread. It has some nice info. :D

Mick
Puppy Linux Blog - contact me for access

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#62 Post by technosaurus »

I was trying to get some more documentation on GTK Dialog and figured out a reason why there may not be much documentation thus far. It seems that it was an intermediated step / building block for these:

CUI http://linux.pte.hu/~pipas/CUI/index.html
GUI Completion http://linux.pte.hu/~pipas/GUIcompletion/index.html

So goes the development cycle on a project with a small or one man team. They do look pretty promising for a couple of my projects (Pcompile in particular) Has anyone here done anything with them yet?
Last edited by technosaurus on Mon 05 Oct 2009, 22:15, edited 1 time in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#63 Post by disciple »

I looked at them the other day, but I can't remember why I gave up on them. I think one had some unreasonable (gnome?) dependencies.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#64 Post by zigbert »

Make the gui scalable
>> Did you know that it is possible to make gtkdialog windows fully scalable? That means to be able to drag the window corner, and make the gui bigger.

As long as a <tree>, <table>, <list> or <edit> widget is enclosed ONLY by a <hbox> OR <vbox>, the widget will remain scalable both horizontally and vertically. Pfind, Pmusic and Pprocess uses various solutions of this.

>> Note about frames
If you enclose a <frame> with <hbox> or <vbox>, you set a fixed size of the frame. If you instead put the <hbox>/<vbox> definitions inside the <frame>, the frame will dynamically scale to fit gui.

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

#65 Post by sunburnt »

Hi zigbert; I need help with the "tree", I don`t see how the sub levels are controlled.

Code: Select all

#! /bin/bash
export MAIN_DIALOG='
<vbox>
  <tree>
    <input file>tmp.text</input>
    <label>Device</label>
    <item stock="gtk-harddisk">Hard Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-cdrom">CD_ROM Drive</item>
    <height>200</height>
    <width>300</width>
    <variable>TREE</variable>
  </tree>
</vbox>
'
gtkdialog2 --program=MAIN_DIALOG
This should give multi. levels but only gives a few, but what designates the sub levels?
The code above is gtk-2, so gtk-3 may be a better choice...

I`m trying to make a "WinExplorer" type file browser, left pane = dir. tree, right pane = file list.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#66 Post by zigbert »

sunburnt
I had no idea that sub-levels was supported. :shock:
I really hope you see the light and tell us how it all works. I also want this. :D
Have you seen any documentation at all about sub-levels?


Sigmund

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

#67 Post by sunburnt »

The GTK widget your using is probably a different one.
Here`s the tree from GTK 0.59.8, the floppy has 2 tree levels of depth.
But I see no method by which it`s done or to control it.
The xDialog controls are completely different of course...
Attachments
tree_multicolumn_gtk-0.59.8.gz
(503 Bytes) Downloaded 719 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#68 Post by zigbert »

Be careful with the use of subshells, and slow commands as sed, ps, expr, cat ... This is of course most important when building a loop.

This script takes 3.0 seconds on my system

Code: Select all

echo 'hello' > /tmp/tmp
for I in $(seq 1 1000); do
   B="`cat /tmp/tmp`"
done
while the next takes 0.9 seconds

Code: Select all

echo 'hello' > /tmp/tmp
IFS=$'\n' 
for I in $(seq 1 1000); do
   B=($(<"/tmp/tmp"))
done

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#69 Post by zigbert »

Rewritten:

The pairs of code shows how to do the same operation in 2 different ways. The speed differs a lot. First an example why avoid 'cat', then why never use 'expr' if speed matters. My system needed 4 seconds to calculate 1+1 thousand times with 'expr'. Using the builtin bash command it took 'no time'.

Code: Select all

# time for I in $(seq 1 1000); do B="`cat /tmp/tmp`"; done 
real    0m3.095s
# time `IFS=$'\n'; for I in $(seq 1 1000); do B=($(<"/tmp/tmp")); done`
real    0m0.927s


# time for I in $(seq 1 1000); do expr 1 + 1 > /dev/null; done
real    0m4.286s
# time for I in $(seq 1 1000); do A=$((1+1)); done
real    0m0.032s

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

#70 Post by sunburnt »

Thanks zigbert; I need to brush up on true bash replacements for the "odd" commands.
I added your examples to my code snips collection.
It will help for my removable drive auto mounter app. as it has a daemon loop.
The mount and unmount functions don`t matter so much as they only run occasionally.

I`ve looked for Bash replacements for sed, but don`t see the same functionality.
Same goes for: grep, tr, cut, paste, awk, comm, and the "if" statement.

### In looking at the tree control it seems that the sub levels are made
if the node is labeled the same as the one that came before it. Weird !!!
I modified it and the sub levels didn`t work properly, I think it`s just a bad control.
I need to find docs. for gtkDialog3, there must be a newer tree control...

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

#71 Post by sunburnt »

zigbert; A problem with usage of your substitue for the "cat" command:

Code: Select all

# PP='/proc/partitions'
# ($(<"$PP")) | wc -c
bash: major: command not found
0
It appears to try to execute the "catted" file`s contense; "major".
And then gives a wrong value for the byte count; "0".
This is in a daemon loop, so it`d be nice to figure it out...! Terry

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

#72 Post by sunburnt »

It appears the command only gives the first word in the file, as shown:

Code: Select all

# PP=($(<"/proc/partitions"))
# echo "$PP"
major

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

#73 Post by amigo »

This works:
PP=$(<"/proc/partitions")

PP=$(<"/proc/partitions") ; echo $PP
major minor #blocks name 22 0 78125000 hdc 22 1 1954480 hdc1 22 2 1955520 hdc2 22 3 10000368 hdc3 22 4 1 hdc4 22 5 19999696 hdc5 22 6 44214376 hdc6 3 0 1255968 hda 3 1 251968 hda1 3 2 1003968 hda2 3 64 78150744 hdb 3 65 1036161 hdb1 3 66 2056320 hdb2 3 67 7181055 hdb3 3 68 1 hdb4 3 69 10273536 hdb5 3 70 20555136 hdb6 3 71 37045858 hdb7

I've created a few pure-bash replacements for some tools -there's even a pure-bash wget!

I'll attach the tarball containing them here, since my site seems to be down at the moment.
This is what's included:
basename
cat
cut
dirname
grep
head
rev
sort
tail
tr
uniq
wc
wget
which

If you work out any new ones, let me know so they can be added to the collection.

Edit: You mentioned sed, that would be very diifficult to implement. However, the included 'tr' can do some of the same stuff. You can use it to do simple replacements like sed does. 'normal' tr only lets you replace single characters, but my version lets you replace however many you want, so it will do what sed does in that respect.
Attachments
BashTrix-0.2.tar.gz
pure-bash utility replacements
(13.19 KiB) Downloaded 770 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#74 Post by zigbert »

sunburnt
To keep format

Code: Select all

# IFS='\n' PP=$(<"/proc/partitions") ; echo $PP 
major mi or  #blocks   ame

   1     0      13824 ram0
   1     1      13824 ram1
   1     2      13824 ram2
   1     3      13824 ram3
   1     4      13824 ram4
   1     5      13824 ram5
   1     6      13824 ram6
   1     7      13824 ram7
   1     8      13824 ram8
   1     9      13824 ram9
   1    10      13824 ram10
   1    11      13824 ram11
   1    12      13824 ram12
   1    13      13824 ram13
   1    14      13824 ram14
   1    15      13824 ram15
   7     0      93400 loop0
   7     1    1572864 loop1
   7     4      15616 loop4
   7     5     101668 loop5
   8     0  156290904 sda
   8     1    9140953 sda1
   8     2          1 sda2
   8     3     104422 sda3
   8     4     514080 sda4
   8     5    4088511 sda5
   8     6  141950308 sda6
Just a note. It would be possible to manually build a <tree> with sublevels. If you can live with not having icons in the <tree>, you could add + and - in front of each directory.


Sigmund

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#75 Post by seaside »

zigbert wrote:sunburnt

Just a note. It would be possible to manually build a <tree> with sublevels. If you can live with not having icons in the <tree>, you could add + and - in front of each directory.


Sigmund
Zigbert,

Lot's of goodies here. Strange thing this Gtkdialog :D trade icons for + and - signs. :?:

How would the extra levels work in this context -

Code: Select all

<tree>
    <input file>tmp.text</input>
    <label>Device                        | Directory | File</label>
    <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.tex</item>
    <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.dvi</item>
    <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.ps</item>
    <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.pdf</item>
    <item stock="gtk-cdrom">CD_ROM Drive | /cdrom/   | </item>
    <height>200</height>
    <width>300</width>
    <variable>TREE</variable>
  </tree>
What will be discovered next :?:

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

#76 Post by sunburnt »

zigbert; I tried various ways of what you suggest and I had no luck.
Could you please give an example of what you`re proposing?

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#77 Post by zigbert »

sunburnt
An example will require to build a complete left-pane for the filebrowser. I am in lack of time, but if you have no rush, I will try to make it in a week or 2 ..............


Sigmund

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

#78 Post by sunburnt »

zigbert; I`m a little unsure of the extent of "build complete".
I don`t want you to spend lots of time on this, it`s not critical.
If it`s possible... Just post examples of tree sub branch control.

If you have to "play" with it for awhile to figure it out, take your time...

Icons would be nice of course, but gtkDialog is not very flexible.
I gather from the discussion that gtkDialog does support some
underlying properties of GTK, but I don`t know how to use them.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#79 Post by zigbert »

sunburnt
What I mean with 'build complete' is that the list must be completely built by bash each time user click on a directory.

This draft only gives a picture how it could be solved.
It is not tested or complete.

1. List directories in <table>.
<table><variable>DIR</variable><labels>"|directory structure"</label><input>cat /tmp/dirs</input>
I would use a command like:

Code: Select all

find "$DIR" -maxdepth 1 -mindepth 1 -type d -follow -printf "  %p|%f/\n" | sort > /tmp/dirs
The trick here is to list full path of directories in first column, and then hide the column with the given <label>.

2. Add a + in front of all directories that includes subdirectories. Others gets a -.
I suggest here to use sed, but since it is a very slow command, you should probably search for a faster solution.

Code: Select all

cut -c 3 /tmp/dirs > /tmp/dirs2 #get rid of spaces added by -printf command
while read I; do
	NAME=`basename "$I"`
	if [ -d "`ls -1 --group-directories-firs "$I" | head -n 1`" ]; then
		sed -i -e "s%|$NAME%|+ $NAME%g" /tmp/dirs
	else
		sed -i -e "s%|$NAME%|- $NAME%g" /tmp/dirs
	fi		 
done < /tmp/dirs2
3. User click on a + directory and the list must expand with the given sublevel

Code: Select all

BEFORE="`grep --before-context=1000 -w "$DIR" /tmp/dirs`"
AFTER="`grep --after-context=1000 -w "$DIR" /tmp/dirs`"
SUBLEVEL="`find "$DIR" -maxdepth 1 -mindepth 1 -type d -follow -printf "  %p|    %f/\n" | sort`"
echo -e "$BEFORE\n$DIR\n$SUBLEVEL\$AFTER" >  /tmp/dirs
4. Clear and Refresh <table>

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

#80 Post by sunburnt »

I found this in the docs.:
But the tree tag "Hover_expand=" doesn`t seem to create sub levels.

Code: Select all

#! /bin/bash
export MAIN_DIALOG='
<vbox>
  <frame Hover Mode>
    <tree hover_expand="true" hover_selection="true">
      <input file>tmp.text</input>
      <label>Device                        | Directory | File</label>
      <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.tex</item>
      <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.dvi</item>
      <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.ps</item>
      <item stock="gtk-floppy">Floppy Disk | /floppy/  | ak.pdf</item>
      <item stock="gtk-cdrom">CD_ROM Drive | /cdrom/   | </item>
      <height>100</height><width>400</width>
      <variable>TREE</variable>
    </tree>
  </frame>
  <hbox>
    <button cancel></button>
    <button ok></button>
  </hbox>
</vbox>
'
gtkdialog --program=MAIN_DIALOG
In fact in none of these examples have the sub triangles like the other example I posted.
For something SO VERY IMPORTANT, it`s hard to believe it`s not in the docs. (intentional).

Post Reply