2 GTKdialog questions (answered)

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
matiasbatero
Posts: 60
Joined: Fri 12 Oct 2012, 01:27
Location: Mar del Plata, Argentina

2 GTKdialog questions (answered)

#1 Post by matiasbatero »

Hi Everybody.
I have 2 questions about GTKDIALOG.

FIRST: I'm developing an ambitious CD/DVD burning software in bash with gtkdialog. I have interesting progress at this moment, but i need to know 2 things:

1) I have a TREE widget with items loaded by a function like this:

Code: Select all

<tree space-fill="false" space-expand="false" headers-clickable="true">
	<label>Browser|Size</label>
	<input stock-column="index">'"cat $TEMP/list_dir.gtk"'</input>								
	<variable>TREE</variable>
	<height>500</height>
	<action>'"next_dir"'</action>
	<action>refresh:TREE</action>
</tree>	
list_dir.gtk its a file like:
gtk-directory|Foldername|Folder|459KB|/home/downloads

But i have problems with files/folders with names containing | (the pipe symbol), because gtkdialog separate data item in columns in a wrong place.
¿It's posible to escape | symbol? ¿Ideas?
If not posible, its a limitation for my program.

2) ¿Can i start the GUI with hide widgets, avoiding use toogle buttons/radiobuttons/checkboxes?

Thanks so much for your help
PD: Sorry for my english, i speak spanish
Last edited by matiasbatero on Fri 30 Nov 2012, 18:22, edited 2 times in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: 1 GTKdialog question

#2 Post by L18L »

matiasbatero wrote:... problems with files/folders with names containing | (the pipe symbol), ...
Hope this helps, a test on console wrote:#
# ls bla*
bla|bla
#
# cat bla|bla
bash: bla: command not found
cat: bla: Datei oder Verzeichnis nicht gefunden
#
# cat "bla|bla"
Hola matiasbatero #
#
nicht gefunden is not found
I am sure you will get help for the other question, too.

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

Re: 1 GTKdialog question

#3 Post by matiasbatero »

L18L wrote:
matiasbatero wrote:... problems with files/folders with names containing | (the pipe symbol), ...
Hope this helps, a test on console wrote:#
# ls bla*
bla|bla
#
# cat bla|bla
bash: bla: command not found
cat: bla: Datei oder Verzeichnis nicht gefunden
#
# cat "bla|bla"
Hola matiasbatero #
#
nicht gefunden is not found
I am sure you will get help for the other question, too.
Thanks for you answer!

Mmm, i not understand that very much.

Internally, the software have a function that: Explore a directory, then makes a list (files and folders) and exported to a "formated text file" to be readable for the input of the tree widget.

For example, if apply cat to that file:

Code: Select all

cat "list_dir.gtk"

gtk-file|gnu.jpg|32KB|/home/user/images
gtk-file|linux.gif|12KB|/home/user/images
Then the file have 3 "|" (delimiters) for each line, and the tree widget shows a 4 columns.

1º column = Icon = (display icon)
2º column = Name file = gnu.jpg
3º column = Size file = 32KB
4º column = Path of file = /home/user/images

And it's right! this is the correct form to show the data in the widget.
Because (| symbol) is the delimiter between the data of each column.

The problem is when a filename have a "|" inside, for example:

Code: Select all

pupp|ylinu|x.jpg
Then, the new cat "list_dir.gtk" is:

Code: Select all

gtk-file|pupp|ylinu|x.jpg|32KB|/home/user/images
Here, you found 5 "|" (delimiters). And the final result is:

1º column = Icon = (display icon)
2º column = Name file = pupp
3º column = Size file = ylinu
4º column = Path of file = x.jpg

And it's wrong.
This problem is about | symbol in the input data for the tree widget, not for the internally function.

The question is: ¿it's posible escape the "| symbol" in the list_dir.gtk for solve this conflict?[/code]

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#4 Post by don570 »

I don't have any experience with trees but I have had some experience
printing special characters on the screen with gtkdialog.

A trick I've used is to make a variable with the special character
for example a tick symbol.

SPECIAL_CHARACTER="'"


Then I can place the special character into commands with
$SPECIAL_CHARACTER


It only works in unusual situations.

______________________________

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

Re: 2 GTKdialog questions

#5 Post by SFR »

matiasbatero wrote:2) ¿Can i start the GUI with hide widgets, avoiding use toogle buttons/radiobuttons/checkboxes?
If I understand correctly you want to have ability to hide/show some of widgets on demand?
Later Gtkdialog versions have <expander> widget:
https://code.google.com/p/gtkdialog/wiki/expander
http://gtkdialog.googlecode.com/svn/tru ... r/expander
But you need Gtkdialog >= 0.8.1 (or better >=0.8.2) in order to use this.

As for | as a delimiter, me personally never found a way to display it in <tree> nor <table> (but I don't claim there is no way to do so)...but on the other hand is | really so commonly used in dir/filenames..? :wink:

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#6 Post by zigbert »

To hide a widget at startup, add the attribute visible="false".
ie. <button visible="false">
you can later toggle it with the function show:BUTTON_NAME


Sigmund

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

Re: 2 GTKdialog questions

#7 Post by matiasbatero »

SFR wrote:
matiasbatero wrote:2) ¿Can i start the GUI with hide widgets, avoiding use toogle buttons/radiobuttons/checkboxes?
If I understand correctly you want to have ability to hide/show some of widgets on demand?
Later Gtkdialog versions have <expander> widget:
https://code.google.com/p/gtkdialog/wiki/expander
http://gtkdialog.googlecode.com/svn/tru ... r/expander
But you need Gtkdialog >= 0.8.1 (or better >=0.8.2) in order to use this.

As for | as a delimiter, me personally never found a way to display it in <tree> nor <table> (but I don't claim there is no way to do so)...but on the other hand is | really so commonly used in dir/filenames..? :wink:

Greetings!
Thanks for you answer!
Yes, it's not commonly!! In a few weeks, i thought how to solve this.. and i had 3 ideas, 2 are difficult to implement, and the 3º was consider that the probabilities of find a file/folder with | symbol are less than 1% haha, so, this problem will be reported with an advertence dialog, and it will be a little limitation for my software.

regards!

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

#8 Post by matiasbatero »

zigbert wrote:To hide a widget at startup, add the attribute visible="false".
ie. <button visible="false">
you can later toggle it with the function show:BUTTON_NAME


Sigmund
Thanks for the answer Sigmund.
That was my first attempt to start the gui with hide widgets, but when applied that attribute on a Button, and loaded the gui, the widget appears like "deactivated" and not hidden. I'm using gtkdialog v:0.8.2.

Regards!!
PD: Again, for all users: Sorry for my english.

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

#9 Post by zigbert »

matiasbatero wrote:
zigbert wrote:To hide a widget at startup, add the attribute visible="false".
ie. <button visible="false">
you can later toggle it with the function show:BUTTON_NAME


Sigmund
Thanks for the answer Sigmund.
That was my first attempt to start the gui with hide widgets, but when applied that attribute on a Button, and loaded the gui, the widget appears like "deactivated" and not hidden. I'm using gtkdialog v:0.8.2.

Regards!!
PD: Again, for all users: Sorry for my english.
Please post an example script (short as possible). It is much easier for us to help you that way.


Sigmund

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

#10 Post by matiasbatero »

zigbert wrote:
matiasbatero wrote:
zigbert wrote:To hide a widget at startup, add the attribute visible="false".
ie. <button visible="false">
you can later toggle it with the function show:BUTTON_NAME


Sigmund
Thanks for the answer Sigmund.
That was my first attempt to start the gui with hide widgets, but when applied that attribute on a Button, and loaded the gui, the widget appears like "deactivated" and not hidden. I'm using gtkdialog v:0.8.2.

Regards!!
PD: Again, for all users: Sorry for my english.
Please post an example script (short as possible). It is much easier for us to help you that way.


Sigmund
Sigmund, i revised the code, and i saw that i put the incorrect attribute. You are right, the "visible tag" works perfectly.
What a bad luck!! I didn't realize about it!! When i saw that it doesn't work for me, i did a lot of experiments to emulate the effect using functions. haha, what a waste of time.

Thanks!

PD: For the first question.. you know how to show the "|" symbol, on tree items? Or is not possible?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#11 Post by SFR »

matiasbatero wrote:PD: For the first question.. you know how to show the "|" symbol, on tree items? Or is not possible?
I found a kind of workaround for this.
Actually I used quite similar trick to display one or two problematic characters in my UniMap and forgot about this...

But two conditions must be fulfilled:
1. You must have access to each column's data separately, before displaying (to not replace the "needed" | by accident).
2. Unicode support must be present (this may be another limitation).

Everything is based on a lie:
| looks practically the same as ∣ ...isn't it?
But the second one is not Vertical Line, but Divides.

It's enough to replace all | occurrences with ∣ in a given string, concatenate all columns and display it in <tree>.
Then if user will press such a record, appropriate function can replace all ∣ with | back again, to avoid problems with accessing such a file/folder.

But again we have to consider that probability of ∣ (Divides) in dir/filenames is small enough...well, nothing's perfect. :wink:
Maybe someone else will figure out a better way...

Here's working example:

Code: Select all

#!/bin/bash

TEMPFILE=/tmp/temp_file_$$
SUBSTITUTE="`echo -e '\x00\xe2\x88\xa3'`"	# Divides (U+2223)

COLUMN1="A st|ring wi|th a few | in|side."
COLUMN2="Something else"


# Convert all "Vertical Line" symbols in COLUMN1 to "Divides" symbols
COLUMN1="${COLUMN1//|/$SUBSTITUTE}"

# Concatenate columns
echo "$COLUMN1""|""$COLUMN2" > $TEMPFILE


export MAIN='
<window width-request="400">
    <tree>
      <label>First column|Second column</label>
      <input>cat "'$TEMPFILE'"</input>
    </tree>
</window>
'

gtkdialog -p MAIN
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#12 Post by matiasbatero »

SFR wrote:
matiasbatero wrote:PD: For the first question.. you know how to show the "|" symbol, on tree items? Or is not possible?
I found a kind of workaround for this.
Actually I used quite similar trick to display one or two problematic characters in my UniMap and forgot about this...

But two conditions must be fulfilled:
1. You must have access to each column's data separately, before displaying (to not replace the "needed" | by accident).
2. Unicode support must be present (this may be another limitation).

Everything is based on a lie:
| looks practically the same as ∣ ...isn't it?
But the second one is not Vertical Line, but Divides.

It's enough to replace all | occurrences with ∣ in a given string, concatenate all columns and display it in <tree>.
Then if user will press such a record, appropriate function can replace all ∣ with | back again, to avoid problems with accessing such a file/folder.

But again we have to consider that probability of ∣ (Divides) in dir/filenames is small enough...well, nothing's perfect. :wink:
Maybe someone else will figure out a better way...

Here's working example:

Code: Select all

#!/bin/bash

TEMPFILE=/tmp/temp_file_$$
SUBSTITUTE="`echo -e '\x00\xe2\x88\xa3'`"	# Divides (U+2223)

COLUMN1="A st|ring wi|th a few | in|side."
COLUMN2="Something else"


# Convert all "Vertical Line" symbols in COLUMN1 to "Divides" symbols
COLUMN1="${COLUMN1//|/$SUBSTITUTE}"

# Concatenate columns
echo "$COLUMN1""|""$COLUMN2" > $TEMPFILE


export MAIN='
<window width-request="400">
    <tree>
      <label>First column|Second column</label>
      <input>cat "'$TEMPFILE'"</input>
    </tree>
</window>
'

gtkdialog -p MAIN
Greetings!
Hi SFR!!
I think that it's a very good solution!!! Really good!!
Yes, it's a ficticius-character! Excellent! I will do some experiments.
The first condition "access to each column's data separately" it is the base of my program.
All tree widget lists were built concatenating data columns.

For files, i will put a replacement function before the concatenation and after clicking the item tree.
The folders works different in the software, but, the double replacement for files, gives a permanent correct path.
Because, in the software, i always have a .txt with the correct path.
But, the last part it's floating. Ex: /home/user/documents/image.jpg
only "image.jpg" it's changed with the new value for each navigation. So, the double replacement for files "should be compatible" for folders too.

The topic it's solved. That example, shows that work perfectly. The rest is build the appropiate functions.

Thanks you very much for you answer!! Very usefull.

Post Reply