GtkDialog - tips
@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.
Probably not but I'm using it in a gtkdialog script. Thanks I will have a look.MochiMoppel wrote:@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.
Xdialog example are available thanks to wognath
http://puppylinux.org/wikka/Xdialog_examples
____________________________________________
http://puppylinux.org/wikka/Xdialog_examples
____________________________________________
Is it possible to convert a glade file to gtkdialog?
I would like to be able to create a GUI in glade then place it inside a bash script. Below is a simple example.
This is the gtkdialog code inside a bash script called (test):
This is the Glade/xml code called (test.glade)
The bash script will run by clicking on it.
To run the glade file it has to be saved as libglade format then called like:
Your gtkdialog must be compiled to use glade as well.
In a terminal type:
you should see something like:
gtkdialog version 0.8.4 release (C) 2003-2007 Laszlo Pere, 2011-2012 Thunor
Built with support for: GTK+ 2, Glade, VTE.
It's easier to make complicated GUI in Glade but more difficult to make them run.
I have worked out how to compile the glade file in C++ but it requires a lot of code to run actions. I also like the idea of a single script that is not architecture dependant.
Any ideas?
I would like to be able to create a GUI in glade then place it inside a bash script. Below is a simple example.
This is the gtkdialog code inside a bash script called (test):
Code: Select all
#!/bin/sh
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog
MAIN_DIALOG='
<window title="GtkDialog">
<vbox>
<hbox>
<button width-request="200">
<label>Viewnior</label>
<action>viewnior &</action>
</button>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<!-- interface-requires gtk+ 2.24 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Glade</property>
<property name="default_width">200</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkButton" id="button1">
<property name="label" translatable="yes">Viewnior</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="border_width">4</property>
<signal name="clicked" handler="viewnior &" swapped="no"/>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
To run the glade file it has to be saved as libglade format then called like:
Code: Select all
gtkdialog --glade-xml=test.glade --program=window1
In a terminal type:
Code: Select all
gtkdialog --version
gtkdialog version 0.8.4 release (C) 2003-2007 Laszlo Pere, 2011-2012 Thunor
Built with support for: GTK+ 2, Glade, VTE.
It's easier to make complicated GUI in Glade but more difficult to make them run.
I have worked out how to compile the glade file in C++ but it requires a lot of code to run actions. I also like the idea of a single script that is not architecture dependant.
Any ideas?
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
And where exactly is the problem?smokey01 wrote:I would like to be able to create a GUI in glade then place it inside a bash script.
Code: Select all
#!/bin/bash
echo '<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<!-- interface-requires gtk+ 2.24 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Glade</property>
<property name="default_width">200</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkButton" id="button1">
<property name="label" translatable="yes">Viewnior</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="border_width">4</property>
<signal name="clicked" handler="viewnior &" swapped="no"/>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>' > /tmp/test.glade
gtkdialog -g /tmp/test.glade -p window1
rm /tmp/test.glade
Ah, never thought to do it that way however, the file displays as a glade file in Rox instead of a script. If I click on it, it loads into glade.MochiMoppel wrote:And where exactly is the problem?smokey01 wrote:I would like to be able to create a GUI in glade then place it inside a bash script.
Thanks