gtkdialog - choose one of n [SOLVED]

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
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

gtkdialog - choose one of n [SOLVED]

#1 Post by GatorDog »

.
[See post 7 & 8 for a solution]

I read through the gtkdialog tips thread and was able to get started.
I want to be able to select one of the three entry fields by clicking
the radiobutton next to the field. The first two fields are not editable.
The third field is editable. I've tried several ways to set the defalult status
of the radiobuttons, but they are all selected. This is what I have so far.

rod

Code: Select all

#! /bin/bash

Original_Name="Original"
Alternate_Name="Alternate"

export One_Of='
<window title="Pick One OF">
<frame>
 <hbox>
    <text>
      <label>Original Name:   </label>
    </text>

  <entry editable="false">
    <default>'"$Original_Name"'</default>
    <variable>selected_name</variable>
  </entry>

  <radiobutton label="">
    <variable>radio_button_1</variable>
    <default>"true"</default>
  </radiobutton>
 </hbox>



 <hbox>
    <text>
      <label>Alternate Name:</label>
    </text>

  <entry editable="false">
    <default>'"$Alternate_Name"'</default>
    <variable>selected_name</variable>
  </entry>

  <radiobutton label="">
    <variable>radio_button_2</variable>
    <default>"false"</default>
  </radiobutton>
 </hbox>



 <hbox>
    <text>
      <label>Enter A Name:   </label>
    </text>

  <entry>
    <default>Enter New Name</default>
    <variable>selected_name</variable>
  </entry>

  <radiobutton label="">
    <variable>radio_button_3</variable>
    <default>"false"</default>
  </radiobutton>
 </hbox>


 <hbox>
  <button ok></button>
  <button cancel></button>
 </hbox>
</frame>
</window>
'

I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog3 --program=One_Of); do
   eval $STATEMENTS
done
IFS=$I

echo $selected_name
Last edited by GatorDog on Sat 18 Jun 2011, 16:15, edited 1 time in total.

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#2 Post by Dougal »

What if you use

Code: Select all

<default>0</default>
? I remember having a bit of trouble with that. Also try without the quotes...
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#3 Post by sc0ttman »

they need to be nested inside the same hbox, vbox, frame or whatever (I think)
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

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

#4 Post by zigbert »

Radiobuttons (which belongs together) has to be defined inside the same <hbox> or <vbox>. Your approach is wrong and should be reconstructed to

Code: Select all

<hbox>
 <vbox>
  <entry>...</entry>
  <entry>...</entry>
  <entry>...</entry>
 </vbox>
 <vbox>
  <radiobutton>...</radiobutton>
  <radiobutton>...</radiobutton>
  <radiobutton>...</radiobutton>
 </vbox>
</hbox>
You might want to define the height of the radiobuttons to get them as tall as the entries. <radiobutton height-request="22">. 22 is a guess.

If no <default> is set, the first radiobutton is true. Else set one of the radiobuttons to <default>true</default>. The other has to be set <default>false</default>


Sigmund

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

gtkdialog - choose one of n

#5 Post by GatorDog »

Thank you Dougal, sc0ttman, and zigbert. This got me a lot closer.
Changed code to:

Code: Select all

#! /bin/bash

Original_Name="Original"
Alternate_Name="Alternate"

export One_Of='
<window title="Pick One OF">
<frame>
<hbox>
  <vbox>
    <hbox>
    <text>
      <label>Original Name:   </label>
    </text>

    <entry editable="false">
      <default>'"$Original_Name"'</default>
      <variable>selected_name</variable>
    </entry>
    </hbox>
    
    <hbox>
    <text>
      <label>Alternate Name:</label>
    </text>

    <entry editable="false">
      <default>'"$Alternate_Name"'</default>
      <variable>selected_name</variable>
    </entry>
    </hbox>
    
    <hbox>
    <text>
      <label>Enter A Name:   </label>
    </text>

    <entry>
      <default>Enter New Name</default>
      <variable>selected_name</variable>
    </entry>
    </hbox>

  </vbox>

  <vbox>
    <radiobutton height-request="25" label="">
      <variable>radio_button_1</variable>
      <default>"true"</default>
    </radiobutton>

    <radiobutton height-request="25" label="">
      <variable>radio_button_2</variable>
      <default>false</default>
    </radiobutton>

    <radiobutton height-request="25" label="">
      <variable>radio_button_3</variable>
      <default>false</default>
    </radiobutton>

  </vbox>
</hbox>

<hbox>
  <button ok></button>
  <button cancel></button>
</hbox>

</frame>
</window>
'

I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog3 --program=One_Of); do
   eval $STATEMENTS
done
IFS=$I

echo $selected_name
The radiobuttons work correctly. Now, how are the buttons connected to
the entry and output as a variable?

Also there is now about a dozen leading characters prefixing each line.

rod

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

#6 Post by seaside »

GatorDog,

You might consider just making a combobox with the three categories followed by a text entry box.

The combobox variable and the text entry box variable would then be linked.

Cheers,
s

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#7 Post by akash_rawal »

Is the following is the thing what you wanted?

Code: Select all

#!/bin/sh

Original_Name="Original"
Alternate_Name="Alternate"

export One_Of='
<window title="Pick One OF">
<frame>
<hbox>
  <vbox>
    <hbox>
    <text>
      <label>Original Name:   </label>
    </text>

    <entry editable="false">
      <default>'"$Original_Name"'</default>
      <variable>selected_name_1</variable>
    </entry>
    </hbox>
   
    <hbox>
    <text>
      <label>Alternate Name:</label>
    </text>

    <entry editable="false">
      <default>'"$Alternate_Name"'</default>
      <variable>selected_name_2</variable>
    </entry>
    </hbox>
   
    <hbox>
    <text>
      <label>Enter A Name:   </label>
    </text>

    <entry>
      <default>Enter New Name</default>
      <variable>selected_name_3</variable>
    </entry>
    </hbox>

  </vbox>

  <vbox>
    <radiobutton height-request="25" label="">
      <variable>radio_button_1</variable>
      <default>"true"</default>
    </radiobutton>

    <radiobutton height-request="25" label="">
      <variable>radio_button_2</variable>
      <default>false</default>
    </radiobutton>

    <radiobutton height-request="25" label="">
      <variable>radio_button_3</variable>
      <default>false</default>
    </radiobutton>

  </vbox>
</hbox>

<hbox>
  <button ok></button>
  <button cancel></button>
</hbox>

</frame>
</window>
'

I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog3 --program=One_Of); do
   eval $STATEMENTS
done
IFS=$I

test "$radio_button_1" = "true" && echo "$selected_name_1"
test "$radio_button_2" = "true" && echo "$selected_name_2"
test "$radio_button_3" = "true" && echo "$selected_name_3"

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#8 Post by GatorDog »

Code: Select all

test "$radio_button_1" = "true" && echo "$selected_name_1"
test "$radio_button_2" = "true" && echo "$selected_name_2"
test "$radio_button_3" = "true" && echo "$selected_name_3" 
Thank you akash_rawal. This works fine. I had thought there might
be some XML'ish way to connect the button and entry field. Or an "action"
to set the variable. But working it with bash is straight forward.


For those learning bash as well as gtkdialog, this may help you a little more
in isolating and using the variable.

Code: Select all

if [ "$EXIT" == "OK" ]; then
   test "$radio_button_1" = "true" && selected_name="$selected_name_1"
   test "$radio_button_2" = "true" && selected_name="$selected_name_2"
   test "$radio_button_3" = "true" && selected_name="$selected_name_3" 
else
   echo "Name select aborted"
   # do cleanup if necessary
   exit
fi

echo $selected_name
rod

Post Reply