Page 40 of 76

Posted: Wed 31 Jul 2013, 09:47
by ASRI éducation
box579 wrote:Hi ASRI education,
to prevent users from editing your items use <comboboxtext> instead of <combobox>. See below, for specs read this:
http://code.google.com/p/gtkdialog/wiki/comboboxtext

Code: Select all

<vbox>
<text><label>Live Support</label></text>
<comboboxtext width-request=""$COMBOBOX_WIDTH"" tooltip-text=" Select the live support ">
<variable>CheckLiveSupport</variable>
$LIVE_SUPPORT_ITEMS
</comboboxtext>
</vbox>
BR, box579.
This is exactly what I needed.
A big thank you!
:wink:

Posted: Wed 31 Jul 2013, 11:09
by ASRI éducation
@ zigbert
May be, it could be interesting to add this info in the first message.
Cordialement,
ASRI éducation wrote:Hello !
I'm trying to create a GUI (GTK) and I need help.
I use the combobox option and I do not want the user could edit the items offered (so that he can choose only in the list of items proposed by the script).
Currently, my combobox like this:

Code: Select all

<vbox>
<text><label>Live Support</label></text>
<combobox width-request=""$COMBOBOX_WIDTH"" tooltip-text=" Select the live support ">
<variable>CheckLiveSupport</variable>
$LIVE_SUPPORT_ITEMS
</combobox>
</vbox>
My question: is it possible to prevent the publishing of the items proposed by the combobox?

Cordialement,
box579 wrote:Hi ASRI education,
to prevent users from editing your items use <comboboxtext> instead of <combobox>. See below, for specs read this:
http://code.google.com/p/gtkdialog/wiki/comboboxtext

Code: Select all

<vbox>
<text><label>Live Support</label></text>
<comboboxtext width-request=""$COMBOBOX_WIDTH"" tooltip-text=" Select the live support ">
<variable>CheckLiveSupport</variable>
$LIVE_SUPPORT_ITEMS
</comboboxtext>
</vbox>
BR, box579.
ASRI éducation wrote:This is exactly what I needed.
:wink:

Nested expanders

Posted: Tue 13 Aug 2013, 18:39
by SFR
Does anyone did it before?
Nested expanders - can be used for 'tree-view' of folders.
Hack on a hack pushed by another hack, but works beautifully!

Ok, so who's gonna write a routine that recursively parses directory tree and dynamically builds a GUI?
Not me - no way! :lol:

Code: Select all

#!/bin/bash

# Pure Mess v1.0 ;)
# Nested expanders example by SFR'2013
# Tricky as hell (chaos with vbox/hbox and alignment), but works like a charm!
# Requires Gtkdialog >= 0.8.1

file_select () {
  xmessage --center "'$@' has been selected..."
}
export -f file_select

export MAIN='
<window title="Recursive expander">
  <vbox spacing="0">
    <expander label="directory 1" space-fill="false" space-expand="false">
      <vbox spacing="0">
        <hbox>
          <text space-fill="false" space-expand="false"><label>" "</label></text>
          <vbox spacing="0">
            <expander label="directory 2" space-fill="false" space-expand="false">
              <vbox spacing="0">
                <hbox>
                  <text space-fill="false" space-expand="false"><label>" "</label></text>
                  <vbox spacing="0">
                    <expander label="dir3" space-fill="false" space-expand="false">
                      <vbox spacing="0">
                        <hbox>
                          <text space-fill="false" space-expand="false"><label>" "</label></text>
                          <button relief="2" space-fill="false" space-expand="false">
                            <label>bla bla 1</label>
                            <action>file_select bla bla 1</action>
                          </button>
                          <text space-fill="true" space-expand="true"><label>" "</label></text>
                        </hbox>
                        <hbox>
                          <text space-fill="false" space-expand="false"><label>" "</label></text>
                          <button relief="2" space-fill="false" space-expand="false">
                            <label>bla bla 2</label>
                            <action>file_select bla bla 2</action>
                          </button>
                          <text space-fill="true" space-expand="true"><label>" "</label></text>
                        </hbox>
                      </vbox>
                    </expander>
                  </vbox>
                  <text space-fill="true" space-expand="true"><label>" "</label></text>
                </hbox>
                <hbox>
                  <text space-fill="false" space-expand="false"><label>" "</label></text>
                  <button relief="2" space-fill="false" space-expand="false">
                    <label>somefile1 in dir2</label>
                    <action>file_select somefile1</action>
                  </button>
                  <text space-fill="true" space-expand="true"><label>" "</label></text>
                </hbox>
                <hbox>
                  <text space-fill="false" space-expand="false"><label>" "</label></text>
                  <button relief="2" space-fill="false" space-expand="false">
                    <label>somefile2 in dir2</label>
                    <action>file_select somefile2</action>
                  </button>
                  <text space-fill="true" space-expand="true"><label>" "</label></text>
                </hbox>
                <hbox>
                  <text space-fill="false" space-expand="false"><label>" "</label></text>
                  <button relief="2" space-fill="false" space-expand="false">
                    <label>and one more file in dir2</label>
                    <action>file_select one more file</action>
                  </button>
                  <text space-fill="true" space-expand="true"><label>" "</label></text>
                </hbox>
              </vbox>
            </expander>
            <hbox>
              <button relief="2" space-fill="false" space-expand="false">
                <label>File in directory 1</label>
                <action>file_select file from first dir</action>
              </button>
              <text space-fill="true" space-expand="true"><label>" "</label></text>
            </hbox>
          </vbox>
          <text space-fill="true" space-expand="true"><label>" "</label></text>
        </hbox>
      </vbox>
    </expander>
  </vbox>
</window>
'

gtkdialog -cp MAIN
Greetings!

Posted: Wed 14 Aug 2013, 07:03
by zigbert
Nested expanders - can be used for 'tree-view' of folders.
Really nice :D

Posted: Wed 14 Aug 2013, 07:53
by smokey01
Is it possible to have variables in gtkdialog that include dots? EG: firstname.surname="Billy Bloggs"

Can this be saved to a config file and be reloaded after changes have been made.

Without the dots it works fine but the variables I need to use, have dots in the name.

TIA

Posted: Wed 14 Aug 2013, 12:40
by SFR
Hi Smokey

I'm not sure if I understand what exactly you want to achieve (maybe a short example?), but since Bash won't accept a variable with a dot:

Code: Select all

# some.var=5
bash: some.var=5: command not found
# 
then probably Gtkdialog too.
I assume you have those "variables" stored in some file, haven't you?
So you could (before using) replace the dot with e.g. _underline , like this:

Code: Select all

# eval $(echo 'some.var="Smith, John A."' | sed '0,/\./s/\./_/')
# echo $some_var
Smith, John A.
# 
and, after change has been made, but before saving to a file, replace it back:

Code: Select all

# some_var="Brown, James E."
# echo "$(echo some_var | sed '0,/\_/s/\_/./')="$some_var"" > storefile
# cat storefile 
some.var="Brown, James E."
#
But this method isn't too pretty. :wink:
Anyway, hope it'll help you somehow.
________________
zigbert wrote:
Nested expanders - can be used for 'tree-view' of folders.
Really nice :D
Thanks! :)

I just wrote crude and simple equivalent of 'tree' in Bash, but I think I'll pass on trying to write dynamic GUI builder.
Besides, I'm afraid that Gtk(dialog) can have serious problems in handling such amount of widgets (thousands of expanders + buttons :roll: ).
But perhaps it would work nice with some small, local structures..?

Anyway, here's the 'tree' code, maybe someone find it useful:

Code: Select all

#!/bin/bash

# Simple equivalent of 'tree' in Bash by SFR'2013

parse_dirs () {
  CWD="$1"
  cd "$CWD"

  local DIRS=( $(find  -maxdepth 1 -mindepth 1 -type d | sort | grep -v "$CWD$" | cut -f2 -d'/') )
  local FILES=( $(find -maxdepth 1 -mindepth 1 ! -type d | sort | cut -f2 -d'/') )
  
  if [ ${#DIRS[@]} -ne 0 ]; then
    while read LINE; do
      echo -e "${INDENT}${BLUECOL}$LINE${OFFCOL}"
      INDENT="${INDENT} "
      parse_dirs "$LINE"
    done <<< `echo ${DIRS[@]}`
  fi
  
  if [ ${#FILES[@]} -ne 0 ]; then
    while read LINE; do
      echo "${INDENT}$LINE"
    done <<< `echo ${FILES[@]}`
  fi
  
  unset DIRS FILES
  INDENT=$(echo "${INDENT%?}")
  cd ..
}

CWD="$1"
[ ! "$CWD" ] && CWD="`pwd`"
[ ! -d "$CWD" ] && echo "Directory doesn't exist!" && exit 1

BLUECOL="\e[0;34m"
OFFCOL="\e[00m"

OLD_IFS=$IFS; IFS=' '
echo -e "${BLUECOL}$(basename "$CWD")${OFFCOL}"
INDENT=" "
parse_dirs "$CWD"
IFS=$OLD_IFS
exit
Greetings!

Posted: Thu 15 Aug 2013, 05:31
by smokey01
SFR,

I sent you a PM.

Posted: Thu 15 Aug 2013, 06:06
by technosaurus
SFR wrote:I just wrote crude and simple equivalent of 'tree' in Bash, but I think I'll pass on trying to write dynamic GUI builder.
I threw a recursive one together a couple years ago (also terminal only, I think it is in the bashbox thread)

... btw you can handle more widgets in older versions of gtkdialog (I think this is unneeded in newer versions) if you pipe the xml | gtkdialog -s instead of using an env variable for it

Posted: Thu 15 Aug 2013, 12:45
by koulaxizis
I have just started playing with gtkdialog and i have a (rather stupid) question:

How can i set action for the chosen entry into a combobox, after pressing OK?

The script is a simple shutdown timer with 3 options for now: one hour, two hours and three hours

It was easy to make it with buttons but i can't understand how to do it with combobox! :/

This is my first effort, so stop mocking me! :lol:

Any help?

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

export DIALOG='
<window title="Go to sleep" window_position="1">
<vbox>
<frame Shutdown computer in...>
<hbox>
<combobox>
<variable>COMBOBOX</variable>
<item>one hour</item>
<item>two hours</item>
<item>three hours</item>
</combobox>
</hbox>
</frame>
<hbox>
<button>
<label>Sleep</label>
<action>exec $COMBOBOX</action>
</button> 
<button cancel></button>
</hbox>
</vbox>
</window>
'

$GTKDIALOG --program=DIALOG


Posted: Thu 15 Aug 2013, 13:52
by SFR
technosaurus wrote:
SFR wrote:I just wrote crude and simple equivalent of 'tree' in Bash, but I think I'll pass on trying to write dynamic GUI builder.
I threw a recursive one together a couple years ago (also terminal only, I think it is in the bashbox thread)

... btw you can handle more widgets in older versions of gtkdialog (I think this is unneeded in newer versions) if you pipe the xml | gtkdialog -s instead of using an env variable for it
Hey Techno

Yeah, I found it in your bashbox:

Code: Select all

tree() { #show a cli visualization of directories and files
for x in `ls $1`; do [ -d $1/$x ] &&  echo "$2\`-{"$x && tree $1/$x "$2   " || echo "$2\`-<"$x; done
}
And now I'm embarrassed that it can be done with just a single line (vs. mine ~40!). :oops:

As for Gtkdialog, in such cases I use external files, but anyway with such amount of data it could take about 10-20 sec before GUI will appear. :roll:
___________________
koulaxizis wrote:How can i set action for the chosen entry into a combobox, after pressing OK?
Hi Koulaxizis

One of possibilities:

Code: Select all

<button>
  <label>Sleep</label>
  <action>xmessage --center "Computer will shut down in ${COMBOBOX}." &</action>
  <action>exit:EXIT</action>
</button>
then, instead of 'xmessage' stuff you can put a call to your function that will compare $COMBOBOX and set timer properly.

HTH
Greetings!

Posted: Thu 15 Aug 2013, 14:31
by koulaxizis
SFR wrote: Hi Koulaxizis

One of possibilities:

Code: Select all

<button>
  <label>Sleep</label>
  <action>xmessage --center "Computer will shut down in ${COMBOBOX}." &</action>
  <action>exit:EXIT</action>
</button>
then, instead of 'xmessage' stuff you can put a call to your function that will compare $COMBOBOX and set timer properly.

HTH
Greetings!
Thanks! Seems like i have a lot of reading to do and a long road to go if i want to create something useful! :)

Posted: Thu 15 Aug 2013, 14:43
by koulaxizis
Well, i have settled to this:

Code: Select all

GTKDIALOG=gtkdialog

export DIALOG='
<window title="Go to sleep" window_position="1">
<vbox>
<frame Shutdown computer in...>
<hbox>
 <entry>
<default>...seconds</default>
<variable>ENTRY</variable>
</entry>
</hbox>
</frame>
<text>
<label>30 minutes = 1800 seconds</label>
</text>
<text>
<label>60 minutes = 3600 seconds</label>
</text>
<text>
<label>90 minutes = 5400 seconds</label>
</text>
<hseparator></hseparator>
<hbox>
<button>
<label>Sleep</label>
<action>sleep "$ENTRY" && wmpoweroff &</action>
<action>exit:EXIT</action>
</button> 
<button cancel></button>
</hbox>
</vbox>
</window>
'

$GTKDIALOG --program=DIALOG
How can i improve it? What should i do to make it more handy?

Posted: Fri 16 Aug 2013, 05:51
by box579
Hi all,

I'm still in question whether there's any chance to have a list/table/tree with checkboxes in first column. Like I asked on the previous page of this thread:
is there any option to have checkboxes within a gtkdialog tree/list/table? I would like to select multiple items.

Input is optained from a textfile:
monitor1|true|option1
monitor2|false|option2
monitor3|true|option3
Output is written to a textfile.
A simple yes/no would be enough. :-)
If yes, maybe a slight hint how would be perfect.

Thanks & regards,
Box579.

Posted: Fri 16 Aug 2013, 10:11
by SFR
box579 wrote:any chance to have a list/table/tree with checkboxes in first column
AFAIK it's not possible, but if you want to select multiple rows, why not use:
<tree selection-mode="3">
tree_selection_mode

Greetings!

Posted: Fri 16 Aug 2013, 16:19
by Nathan F
@koulaxizis - check out the comboboxtext and comboboxentry widgets, which are more powerful than the stock combobox.

For comboboxtext, the default signal is "changed", which is emitted when you choose another selection in the combobox. So you can easily do some useful things with it. The following example lists the contents of all the hidden directories in your home folder in the tree widget.

Code: Select all

<vbox>
<comboboxtext tooltip-text="List contents of your dotdirs">
<variable>COMB1</variable>
<input>find $HOME -maxdepth 1 -mindepth 1 -type d -name '.*'</input>
<default>$HOME/.config</default>
<action>refresh:TREE1</action>
</comboboxtext>
<tree>
<label>Contents</label>
<variable>TREE1</variable>
<input>ls \$COMB1</input>
</tree>
<button ok></button>
</vbox>
Hope that's helpful in the future even though you settled on a different approach.

Posted: Fri 16 Aug 2013, 17:07
by koulaxizis
Nathan F wrote:@koulaxizis - check out the comboboxtext and comboboxentry widgets, which are more powerful than the stock combobox.

For comboboxtext, the default signal is "changed", which is emitted when you choose another selection in the combobox. So you can easily do some useful things with it. The following example lists the contents of all the hidden directories in your home folder in the tree widget.

Code: Select all

<vbox>
<comboboxtext tooltip-text="List contents of your dotdirs">
<variable>COMB1</variable>
<input>find $HOME -maxdepth 1 -mindepth 1 -type d -name '.*'</input>
<default>$HOME/.config</default>
<action>refresh:TREE1</action>
</comboboxtext>
<tree>
<label>Contents</label>
<variable>TREE1</variable>
<input>ls \$COMB1</input>
</tree>
<button ok></button>
</vbox>
Hope that's helpful in the future even though you settled on a different approach.
Thank you very much! I'll try this too to see how it goes!

Posted: Sun 18 Aug 2013, 05:54
by Nathan F
Quick question. Is it still possible to do right click actions on the tree widget? Adding 'signal="button-press-event"' seems to execute the actions on both right and left click, which is not what I remember the case being before.

Posted: Sun 18 Aug 2013, 06:55
by Nathan F
And another one. Trying to set accel-keys for an app. So far as I can tell, the menu and menuitem widgets are the only ones that accept accel keys.

What I would like to do is set an accel key for an action without actually showing the menuitem. However, so far my experimentation has not worked. It seems if the widget set 'visible="false"' then the accel-key no longer works. I also tried putting a menubar inside a notebook tab with the 'show-tabs="false"' setting, and once again no luck.

At the moment what does work is a menu with a blank label. It doesn't show on the menubar, but it can still be opened by clicking it's location, and the accel-key works. But this is not exactly what I want.

Posted: Sun 18 Aug 2013, 06:57
by zigbert
Nathan
gtkdialog sends the status of $PTR_BTN. - 1=left, 2=middle, 3=right

Code: Select all

[ $PTR_BTN != 3 ] && exit

Posted: Sun 18 Aug 2013, 07:15
by Nathan F
Thanks. Works like a champ.