GtkDialog - tips
I was wondering if there is a way in a tree widget with entires with multiple columns (see for example PPM), when you select an entry to pass the information of all the columns and not just the first one
In the PPM case the relevant code is and the input filterpkgs.results.post file is in the format:
<name>|<category>|<description>|<repository>
The <name> and <description> fields are showing in the widget but only <name> is passed in the $TREE1 variable.
Is there a way to pass both <name> and <description> (or ideally <name> and <repository> ?
Thanks
In the PPM case the relevant code is
Code: Select all
<hbox space-expand=\"true\" space-fill=\"true\">
<tree hover-selection="true" selection-mode="1" column-resizeable="true|false" space-expand="true" space-fill="true">
<label>'$(gettext 'Package')'|'$(gettext 'Description')'</label>
<variable>TREE1</variable>
<width>300</width>
<input file icon-column="1">/tmp/petget/filterpkgs.results.post</input>
<action signal="button-release-event">add_item</action>
<action signal="button-release-event">refresh:TREE_INSTALL</action>
<action signal="button-release-event">enable:BUTTON_INSTALL</action>
</tree>
</hbox>
<name>|<category>|<description>|<repository>
The <name> and <description> fields are showing in the widget but only <name> is passed in the $TREE1 variable.
Is there a way to pass both <name> and <description> (or ideally <name> and <repository> ?
Thanks
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==
I would add an extra column at the end, which packs together all the fields you want to export. They need to be separated by a character that isn't '|' and doesn't appear in the data. Backspace is usually a good choice.
So now your tree receives these data:
Now tell <tree> to hide the <packed> column. Use attribute column-visible="1|1|1|1|0". And you want to export the last column. Use attribute exported-column="5".
If <tree> is showing the icon column you might need to shift those numbers +/- 1, I don't recall the details. Experiment till you get the correct indexes.
Finally, the process that receives gtkdialog output is responsible for unpacking <packed> and extracting the fields you're interested in.
CAVEAT: The tree widget limits the total character count of each row to slightly over 510. I use 510.
So now your tree receives these data:
Code: Select all
<name>|<category>|<description>|<repository>|<packed>
where
<packed> = <name>bs<category>bs<description>bs<repository>
If <tree> is showing the icon column you might need to shift those numbers +/- 1, I don't recall the details. Experiment till you get the correct indexes.
Finally, the process that receives gtkdialog output is responsible for unpacking <packed> and extracting the fields you're interested in.
Code: Select all
bs=`printf '\b'`
echo "$TREE1" | cut -d "$bs" -f4 # will get <repository>
Last edited by step on Tue 17 Jan 2017, 14:05, edited 1 time in total.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
This won't work. I assume you mean something likestep wrote:Code: Select all
echo "$TREE1" | tr -s "$bs" -f4 # will get <repository>
Code: Select all
echo "$TREE1" | cut -d "$bs" -f4
Thank you both for the help.
I guess we cannot export 2 columns in $TREE1 (with something like exported-column="1|2"?). Would it be possible to export 2 variables out of the same tree widget? ie column 1 for TREE1 and Column 2 for TREE2
I guess we cannot export 2 columns in $TREE1 (with something like exported-column="1|2"?). Would it be possible to export 2 variables out of the same tree widget? ie column 1 for TREE1 and Column 2 for TREE2
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==
@mavrothal, AFAIK, a widget can have only one associated variable. So a single tree with TREE1 and TREE2 variables isn't possible.
@MochiMoppel, thanks for catching my typo! Fixed.
@MochiMoppel, thanks for catching my typo! Fixed.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]
selection of tree items
Perhaps this also might be useful.step wrote:@mavrothal, AFAIK, a widget can have only one associated variable. So a single tree with TREE1 and TREE2 variables isn't possible.
@MochiMoppel, thanks for catching my typo! Fixed.
Code: Select all
# get fields from a tree selection
# example file
echo 'name1 | cat1 | desc1 | repo1
name2 | cat2 | desc2 | repo2 ' >ppm.dat
# load variables, "items" for gui, "total" for all
while read line; do
total="$total
$line"
items="$items
<item>$line</item>"
done <ppm.dat
# Gui
GTKDIALOG=gtkdialog
export MAIN_DIALOG='
<window title="PPM_test" window_position="2" icon-name="gtk-dialog-warning">
<vbox>
<frame Left-click Selection>
<tree hover-expand="true" hover-selection="true">
<variable>SELECT</variable>
<width>460</width><height>260</height>
<label>Name | Cat | Desc |Repo</label>
'"$items"'
<action signal="button-press-event">exit:getitem</action>
</tree>
</frame>
<hbox homogeneous="true">
<button cancel></button>
</hbox>
</vbox>
</window>
'
eval "$($GTKDIALOG --program=MAIN_DIALOG)"
[ "$EXIT" = "Cancel" ] && exit
# getitem for repo and/or other items
IFSold="$IFS"
IFS='|'
# match selection in total
while read line;do
[[ ${line/$SELECT/} != ${line} ]] && aline=($line) && break
done <<<"$total"
NAME=${aline[0]}
CAT=${aline[1]}
DESC=${aline[2]}
REPO=${aline[3]}
echo "$REPO"
IFS="$IFSold"
Cheers,
s
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Good point. I don't know how you manage to get "slightly over" 510. For me the limit is exactly 510, and that includes the separators.step wrote:CAVEAT: The tree widget limits the total character count of each row to slightly over 510. I use 510.
This limitation alone can make it impossible to load data into the widget, let alone duplicate the data in an added <packed> column. Packing all data in an extra column is perfectly OK for short and few data. For large amounts of data, especially when their length is not known, we need a different approach.
Let's think big. The following demo puts names and descriptions of all packages into a tree widget, in total almost 6000 items. In Slacko this means retrieving data from these files:
- /root/.packages/Packages-puppy-2-official
/root/.packages/Packages-puppy-3-official
/root/.packages/Packages-puppy-4-official
/root/.packages/Packages-puppy-5-official
/root/.packages/Packages-puppy-common-official
/root/.packages/Packages-puppy-noarch-official
/root/.packages/Packages-puppy-quirky-official
/root/.packages/Packages-puppy-slacko14-official
/root/.packages/Packages-slackware-14.0-official
/root/.packages/Packages-slackware-14.0-patches
/root/.packages/Packages-slackware-14.0-salix
/root/.packages/Packages-slackware-14.0-slacky
The second trick is to define "helper widgets" in the dialog. Their sole purpose is to hold the variables which we can not export from the tree or which exist only in the data source, but not in the tree. In the demo this is achieved with the 4 entry widgets at the top. Normally they would be hidden, so would be the (exported) "Source" column of the tree.
Code: Select all
#!/bin/sh
TMPFILE=/tmp/treeinput
## Retrieve all Name and Description fields from all repositories, add path of and line number within Packages file, then write to file
awk -F"|" '{print $1"|"$10"|"FILENAME"#"FNR}' /root/.packages/Packages* > $TMPFILE
function print_field {
[ "$vTREE" ] || return # exit if vTREE empty (happens at startup when nothing selected yet)
FIELD=$1 # field number within record
RECORD=${vTREE##*#} # line number within source file
SOURCE=${vTREE%#*} # full path of source file
awk -F"|" 'FNR == '$RECORD' {print $'$FIELD'}' $SOURCE # fetch and print field content
## FNR is the line number within each source file
## print adds trailing newline (printf does not)
## This ensures that output of awk is never an empty string, even if the printed field is empty.
## Gtkdialog refresh function does nothing (=keeps previous value) if <input> results in an empty string. Bug?
## Feeding value to entry widget and not a text widget will make sure that trailing newline(s) are discarded
}; export -f print_field
echo -n '
<window>
<vbox>
<vbox visible="true">
<entry>
<input>print_field 1</input>
<variable>vNAME</variable>
</entry>
<entry>
<input>print_field 10</input>
<variable>vDESCRIPTION</variable>
</entry>
<entry>
<input>print_field 6</input>
<variable>vSIZE</variable>
</entry>
<entry>
<input>echo ${vTREE%#*}</input>
<variable>vSOURCE</variable>
</entry>
</vbox>
<tree column-visible="1|1|1" exported-column="2" auto-sort="true">
<variable>vTREE</variable>
<label>"Name|Description|Source"</label>
<input file>'$TMPFILE'</input>
<action signal="changed">refresh:vNAME</action>
<action signal="changed">refresh:vDESCRIPTION</action>
<action signal="changed">refresh:vSIZE</action>
<action signal="changed">refresh:vSOURCE</action>
</tree>
<button></button>
</vbox>
</window>
' | gtkdialog -G 600x400 -s
- Attachments
-
- returned_variables.png
- (106.05 KiB) Downloaded 601 times
For the "history", since I was trying to keep changes to a minimum and consistent with the rest of the ppm infrastucture I formulated a solution based on step's suggestion.
But I think is time for someone (not me) to really take up on re-writing PPM from scratch and implementing all these nice ideas both in UI an underneath.
But I think is time for someone (not me) to really take up on re-writing PPM from scratch and implementing all these nice ideas both in UI an underneath.
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==
.
comboboxtext widget
-menuitem refuses to follow cursor up if any xy is set in the theme for "menu" ?
Appears 1st item up, while 2nd+ look ok. Cursor down is ok.
Is able to click it, while spoils the look...
Tested with "default" theme with only this xy added, so it will apply for any theme.
Is that a "bug" or should I know something?
comboboxtext widget
-menuitem refuses to follow cursor up if any xy is set in the theme for "menu" ?
Appears 1st item up, while 2nd+ look ok. Cursor down is ok.
Is able to click it, while spoils the look...
Tested with "default" theme with only this xy added, so it will apply for any theme.
Is that a "bug" or should I know something?
Hi All, how to make an entry with only one character and automatically change everytime we write it? I have do something like this:
If I only use one entry (e1) and refresh e1, it also does not do.
My example output like this:
Code: Select all
#!/bin/sh
export a='
<hbox>
<entry max-length="1">
<variable>e1</variable>
<action>echo e1: $e1</action>
<action>grabfocus:e2</action>
</entry>
<entry>
<variable>e2</variable>
<action>echo e2: $e2</action>
<action>grabfocus:e1</action>
</entry>
</hbox>'
gtkdialog -p a
My example output like this:
Code: Select all
e1: d
e2: s
e1:
e1: d
e2:
e2: f
e1:
e1: g
e2:
e2: d
e1:
e1: s
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Not clear what you are trying to achieve. To stop output of empty variable you could do something like this:
If additionally you want to prevent e1 from changing focus to e2 while e1 is empty (= prevent empty entry boxes) you will have to add a condition to the grabfocus function.
Code: Select all
export a='
<hbox>
<entry max-length="1">
<variable>e1</variable>
<action>[[ $e1 ]] && echo e1: $e1</action>
<action>grabfocus:e2</action>
</entry>
<entry>
<variable>e2</variable>
<action>[[ $e2 ]] && echo e2: $e2</action>
<action>grabfocus:e1</action>
</entry>
</hbox>'
gtkdialog -p a
Actually, I want to make release event of winkey shortcut work for menu and win+"other key" for another shortcut in jwm. So I call my gtkdialog script when win key being pressed. Then if i do not click any alphabet, my menu show. If I press "E" in my keyboard, then rox filer show. Something like that.
But I realize that, if I use this methode, i can not use F1, arrow, alt, ctrl, and so in entry.
:'(
So I let joewing to add release event in shortcut alone.
But I realize that, if I use this methode, i can not use F1, arrow, alt, ctrl, and so in entry.
:'(
So I let joewing to add release event in shortcut alone.
How to move from entry to the button on left or right by arrow key (not tab key)?
Thank you
Code: Select all
#!/bin/sh
echo '
<hbox>
<button>
<label>left</label>
</button>
<entry has-focus="true">
</entry>
<button>
<label>right</label>
</button>
</hbox>'|gtkdialog -s
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Code: Select all
#!/bin/bash
echo '
<hbox>
<button>
<label>left</label>
<variable>BTN1</variable>
</button>
<entry has-focus="true">
<action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Left ] && echo true )">grabfocus:BTN1</action>
<action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Right ] && echo true )">grabfocus:BTN2</action>
</entry>
<button>
<label>right</label>
<variable>BTN2</variable>
</button>
</hbox>'|gtkdialog -s
Can anyone explain this weird behaviour in Fatdog64-710. Have a look at the code below. Turn it into a script and make it executable.
When this script is run it creates an svg image and displays it in your default image viewer.
Notice all of the #### at the top. Try deleting one or two and the script is displayed as an image rather than a script.
If you rename your script from script to script.sh then it remains a script. It seems like it's a mime type problem. What the ????
Code: Select all
#!/bin/sh
##################################################
##################################################
##################################################
##################################################
##################
svg_buttons () {
echo '<svg width="100%" height="100%" viewBox="0 0 60 20">
<defs>
<linearGradient id="button_surface" gradientUnits="objectBoundingBox"
x1="1" x2="1" y1="0" y2="1">
<stop stop-color="#D26F6F" offset="0"/>
<stop stop-color="#FF0000" offset="0.67"/>
</linearGradient>
<linearGradient id="virtual_light" gradientUnits="objectBoundingBox"
x1="0" x2="0" y1="0" y2="1">
<stop stop-color="#EEEEEE" offset="0" stop-opacity="0.8"/>
<stop stop-color="#EEEEEE" offset="0.4" stop-opacity="0"/>
</linearGradient>
</defs>
<!-- button content -->
<rect x="0" y="0" width="60" height="20" fill="url(#button_surface)" stroke="#570B0B"/>
<text x="17" y="15" fill="white"
font-family="Tahoma" font-size="14" font-weight="bold">
Kill
</text>
<!-- vitual lighting effect -->
<rect x="2" y="2" width="56" height="16" fill="url(#virtual_light)" stroke="#FFFFFF" stroke-opacity="0.4"/>
</svg>
'>/tmp/killk.svg
}
export -f svg_buttons
defaultimageviewer /tmp/killk.svg
Notice all of the #### at the top. Try deleting one or two and the script is displayed as an image rather than a script.
If you rename your script from script to script.sh then it remains a script. It seems like it's a mime type problem. What the ????
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
@smokey01. Not really a Gtkdialog issue. See here.
The long # string is there to prevent the file to be mistakenly recognized as a svg image.
The long # string is there to prevent the file to be mistakenly recognized as a svg image.