GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#901 Post by Moose On The Loose »

sunburnt wrote:Thanks Moose; Looking at it...
Puppy has no: /tmp/gtkrc_fft
Look more closely. My script wrote that file.
/tmp/gtkrc_fft is what I added to make red and mono type
And: /root/.gtkrc-2.0 is an empty file.
It must be you didn't set a theme or something mine looks like this.

Code: Select all

# -- THEME AUTO-WRITTEN DO NOT EDIT
include "/usr/share/themes/Stardust/gtk-2.0/gtkrc"

style "user-font" {
	font_name = "Sans 12"
}

include "/root/.gtkrc.mine"

# -- THEME AUTO-WRITTEN DO NOT EDIT
You may have to use find to find the one that is used on your version of puppy. I am on puppy 5.2.8.006 right now.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#902 Post by Moose On The Loose »

koulaxizis wrote:Is it possible in a combobox when selecting an <item> to have a different action than reading the exact word written inside? For example: when selecting <item>hello</item>, the script will actually read/use <item>hello</item>. But i want to select <item>Greek</item> and use on the final output "el", not "Greek". I want to do that so i can change the ugly language shortcut code (eg "el) with the whole word (Greek) but on the final output it must be used the shortcut (el) for the command to work properly... I hope you understood what i mean, my English are not too good... :/
A method I've used is to use string operations in bash to change the string from what is returned into what I want it to be.

Code: Select all

STRING="${STRING/Greek/el}"
It means you need to do one line per country but that is not too bad because you sort of need to do that anyway when you make the list of countries and codes.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#903 Post by sunburnt »

Yeah, Ive never set a theme on this Puppy. Not too concerned with that usually.

Changing the objects is beyond themes, I need new widgets and window decorations.

User avatar
koulaxizis
Posts: 452
Joined: Sun 17 Jul 2011, 18:43
Location: Greece
Contact:

#904 Post by koulaxizis »

Moose On The Loose wrote:A method I've used is to use string operations in bash to change the string from what is returned into what I want it to be.

Code: Select all

STRING="${STRING/Greek/el}"
It means you need to do one line per country but that is not too bad because you sort of need to do that anyway when you make the list of countries and codes.
Can you show me a piece of the updated code to understand it? How should it look with the "string" parameter?
[b]Christos Koulaxizis[/b]
[i]Woof woof from Greece![/i]

[color=darkred][url=https://sourceforge.net/projects/puppystuff/][ Puppy Stuff Repository ][/url][/color]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#905 Post by sunburnt »

Hi koulaxizis; Bash does built-in string manipulation.

Code: Select all

STRING=12345abcde

echo ${STRING/a*/6789} ### This outputs: 123456789

echo $STRING:0:4} ### This outputs: 12345

echo $STRING: -4} ### This outputs: bcde

echo $STRING##*3} ### This outputs: 45abcde

P=/1/2/3/F.ext

echo $P##*/} ### This outputs: F.ext

echo $P#*/} ### This outputs: 1/2/3/F.ext

echo $P##*.} ### This outputs: ext

echo $P%/*} ### This outputs: /1/2/3

echo $P%.*} ### This outputs: /1/2/3/F
# Is starting at the first character.
% Is starting at the last character.

### Ask if you have any more Qs... Always glad to help a friend.! Terry B.
.

User avatar
koulaxizis
Posts: 452
Joined: Sun 17 Jul 2011, 18:43
Location: Greece
Contact:

#906 Post by koulaxizis »

sunburnt wrote:Ask if you have any more Qs... Always glad to help a friend.! Terry B.
.
I'll try it and i'll return with questions if i don't manage to do it. Thanks brother! :)
[b]Christos Koulaxizis[/b]
[i]Woof woof from Greece![/i]

[color=darkred][url=https://sourceforge.net/projects/puppystuff/][ Puppy Stuff Repository ][/url][/color]

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#907 Post by Moose On The Loose »

sunburnt wrote:Yeah, Ive never set a theme on this Puppy. Not too concerned with that usually.

Changing the objects is beyond themes, I need new widgets and window decorations.
My answer was narrow to the determination of what the fonts are.

A trick that I have used to make something beyond what gtkdialog did easily was to make an item that is a button and use that to pop up another dialog right on top of where the button is.

gtkdialog like many programs will take the geometry on the command line. The code that was the basis of doing it is below. It is not the best code in the world but it gets it done

Code: Select all


#########################################################################
#  Use a slight bit of trickery to make the sub-dialogs come up on top
#  the main one in a relative position
#  Syntax:
#    RelToMain XOFFSET YOFFSET
#    RelToMain XOFFSET YOFFSET WIDTH HEIGHT
#
#  Output: "--geometry +123+456"  ready for command line
#  Output: "--geometry 543x654+123+456"  ready for command line
#########################################################################
DISPLAY_HEIGHT=`xdpyinfo | grep "dimensions:" | sed -r "s/ +/x/g"`
DISPLAY_WIDTH=`echo "$DISPLAY_HEIGHT" | cut -dx -f3`
DISPLAY_HEIGHT=`echo "$DISPLAY_HEIGHT" | cut -dx -f4`


function RelToMain () {
  local MAINWIN
  local MAINX
  local MAINY

  local HEIGHT
  local WIDTH
  
  # xdpyinfo contains the info about which window is in focus.  In our
  # case, that will be the window on which the user hit a button that
  # got us here
  # xwininfo tells us about the window in question once we know which one
  # to refer to
  MAINWIN=`xdpyinfo | grep "focus:" | sed "s/window/,/" | cut -d, -f2 `
  MAINWIN=`xwininfo -id $MAINWIN | grep "Absolute upper-left"`
  MAINX=`echo "$MAINWIN" | grep "X:" | cut -d: -f2`
  MAINY=`echo "$MAINWIN" | grep "Y:" | cut -d: -f2`
  
  # Add in the caller's offsets
  MAINX=$(( $MAINX + $1 ))
  MAINY=$(( $MAINY + $2 ))
  
  if [[ "$3" != "" ]] ; then
    WIDTH="$3"
  else
    WIDTH="200"
    fi
    
  if [[ "$4" != "" ]] ; then
    HEIGHT="$4"
  else 
    HEIGHT="200"
    fi
    
  if (( $MAINX + $WIDTH + 30 > $DISPLAY_WIDTH )) ; then
    MAINX=$(( $DISPLAY_WIDTH - $WIDTH - 30 ))
    if (( $MAINX < 5 )) ; then
      MAINX=5
      fi  
    fi

  # echo "--- $MAINY   $HEIGHT  $DISPLAY_HEIGHT">&2
  
  if (( $MAINY + $HEIGHT + 60 > $DISPLAY_HEIGHT )) ; then
    MAINY=$(( $DISPLAY_HEIGHT - $HEIGHT - 60 ))
    if (( $MAINY < 5 )) ; then
      MAINY = 5
      fi
    fi
      
    
  
  if [[ "$4" != "" ]] ; then
    echo "--geometry ${3}x${4}+$MAINX+$MAINY"
  else
    echo "--geometry +$MAINX+$MAINY"
    fi
  }

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#908 Post by sunburnt »

That`s very useful Moose, thank you, I keep code snip files for each type of "language".

Q: Have you ever tried my text-size utility? http://www.murga-linux.com/puppy/viewtopic.php?t=90592

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#909 Post by Moose On The Loose »

sunburnt wrote:That`s very useful Moose, thank you, I keep code snip files for each type of "language".

Q: Have you ever tried my text-size utility? http://www.murga-linux.com/puppy/viewtopic.php?t=90592
As with many things, that is on the list of "not yet"

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#910 Post by Argolance »

Bonsoir,
This is what can be read on the first page of this topic:
>> Show progress in entry - or simply change the color of the entry background
<entry progress-fraction="0.5">
"simply" :shock: change the color of the entry background?
:?
... Could someone tell a bit more about the way to change the background color of an entry?
Thank you!

Cordialement.

User avatar
Bert
Posts: 1103
Joined: Fri 30 Jun 2006, 20:09

#911 Post by Bert »

Hi Argolance,

Just change the progress-fraction="0.5" to "1" and the whole entry will be coloured:

Image

And text will be white.
Hope I understood your question correctly.

Bye
[url=http://pupsearch.weebly.com/][img]http://pupsearch.weebly.com/uploads/7/4/6/4/7464374/125791.gif[/img][/url]
[url=https://startpage.com/do/search?q=host%3Awww.murga-linux.com%2F][img]http://i.imgur.com/XJ9Tqc7.png[/img][/url]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#912 Post by Argolance »

Hello Bert,
Thank you for replying.
This background color depends on the gtk theme configuration and is not necessarily "colored"... In my case, it is actually... white! :wink:
Hope I understood your question correctly.
I myself misunderstood the effect of this entry option, thinking it was really the entry background color that could be changed so.
As a matter of fact, my question has rather something to do with the "Define unique gtk-theme" section of this topic.

Cordialement.
Last edited by Argolance on Sun 15 Dec 2013, 13:30, edited 1 time in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Change background and foreground entry colors

#913 Post by Argolance »

Bonjour,
Thinking it could be useful, here is the way to customize background and foreground entry colors that I founded following the example given above, in the "Define unique gtk-theme" section of this topic. :D

Code: Select all

#!/bin/bash
echo 'style "entry_test"
{
  font_name="Sans 30"
  base[NORMAL]="#FF00E1"
  bg[SELECTED]="#FFCE00"
  text[SELECTED]="#62EEFF"
  text[NORMAL]="#04FD00"
  text[ACTIVE]="#FFCE00"
}
widget "*colored_entry" style "entry_test"
class "GtkText*" style "entry_test"' > /tmp/gtkrc_entry_test

export GTK2_RC_FILES=/tmp/gtkrc_entry_test:/root/.gtkrc-2.0

export test_app="
<vbox>
   <entry name=\"colored_entry\"><default>TEST</default></entry>
</vbox>"
gtkdialog4 --program=test_app
Cordialement.
Attachments
colored_entry.jpg
selected text/active window - unselected text/active window - selected text/inactive window...
(20.3 KiB) Downloaded 649 times

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

GtkDialog Select Option from List (combobox?)

#914 Post by can8v »

I have been searching for some examples on how to do this for over an hour and I think I must not be using relevant search queries or something, so I thought I would just ask here.
I am writing my first bash script of any significance and I need a gui dialog to ask the user to make a selection from a few different options and return the selected value back to the script in the form of a variable. Ideally I would feed an array with the possible options to the function that creates the dialog and after the user makes selection get the variable back.
I won't know how many options will be in the variable prior to running the script. The script will get the data for the array from a database and it will likely have from 1 to 7 elements. Even if it only has one element I still need to user to make the choice, as this will be a chance for the user to confirm that they want to proceed.
Sorry if this has been answered before, I just can't seem to find it.
This is what I have tried:

Code: Select all

for i in ${LINES[@]}
do
   PRODUCTS=$PRODUCTS"<item>$i</item>"
done
export MAIN_DIALOG=' 
<combobox tag_attr="value">
        <variable>PRODUCT</variable>
        <sensitive>state</sensitive>
        <action signal="type">activity</action>
		$PRODUCTS
</combobox>'
gtkdialog --program MAIN_DIALOG
echo $PRODUCT
And this is the error I am getting:

Code: Select all

** (gtkdialog:21366): ERROR **: gtkdialog: Error in line 7, near token 'string': syntax error

/root/my-applications/bin/unmountMTP.sh: line 25: 21366 Trace/breakpoint trap   gtkdialog --program MAIN_DIALOG
First of all am I even using the correct GtkDialog widget and second, if I am, what am I doing wrong?

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#915 Post by can8v »

Ok I made some progress. I am using an appropriate GtkDialog widget.
If I use this

Code: Select all

DEVICE_FILE="/root/my-applications/bin/activeMTPdevices.txt"
old_IFS=$IFS
IFS=$'\n'
LINES=($(cat $DEVICE_FILE)) # array
IFS=$old_IFS
for i in ${LINES[@]}
do
   PRODUCTS="$PRODUCTS""<item>""$i""</item>"$'\n'
done
DEVICE_DIALOG_LIST="'<combobox tag_attr=\"value\">
	<variable>PRODUCT</variable>
	<sensitive>state</sensitive>
	<action signal=\"type\">activity</action>
		$PRODUCTS</combobox>'"
#echo "$DEVICE_DIALOG_LIST"
export MAIN_DIALOG='<combobox tag_attr="value">
	<variable>PRODUCT</variable>
	<sensitive>state</sensitive>
	<action signal="type">activity</action>
		<item>Nexus_7</item>
<item>Galaxy_S4</item>
<item>Nexus_10</item>
<item>Nexus_4</item>
<item>Nexus_5</item>
<item>Galaxy_S2</item>
<item>Galaxy_S3</item>
</combobox>
gtkdialog --program MAIN_DIALOG'
I get a combo box widget with all of the various items. My problem is that I don't know the items at the time of writing the script, I need to have the script build that list of items. When I try the following I get and error, which I will copy below.

Code: Select all

DEVICE_FILE="/root/my-applications/bin/activeMTPdevices.txt"
old_IFS=$IFS
IFS=$'\n'
LINES=($(cat $DEVICE_FILE)) # array
IFS=$old_IFS
for i in ${LINES[@]}
do
   PRODUCTS="$PRODUCTS""<item>""$i""</item>"$'\n'
done
DEVICE_DIALOG_LIST="'<combobox tag_attr=\"value\">
	<variable>PRODUCT</variable>
	<sensitive>state</sensitive>
	<action signal=\"type\">activity</action>
		$PRODUCTS</combobox>'"
export "$DEVICE_DIALOG_LIST"
gtkdialog --program DEVICE_DIALOG_LIST
Here is the error I am getting

Code: Select all

# unmountMTP.sh
/root/my-applications/bin/unmountMTP.sh: line 24: export: `'<combobox tag_attr="value">
	<variable>PRODUCT</variable>
	<sensitive>state</sensitive>
	<action signal="type">activity</action>
		<item>Nexus_7</item>
<item>Galaxy_S4</item>
<item>Nexus_10</item>
<item>Nexus_4</item>
<item>Nexus_5</item>
<item>Galaxy_S2</item>
<item>Galaxy_S3</item>
</combobox>'': not a valid identifier

** (gtkdialog:2624): ERROR **: Gtkdialog: Could not find the dialog description in the environment variable 'DEVICE_DIALOG_LIST'.
/root/my-applications/bin/unmountMTP.sh: line 25:  2624 Trace/breakpoint trap   gtkdialog --program DEVICE_DIALOG_LIST
# 

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

#916 Post by SFR »

Can8v, <combobox> is rather deprecated - how about <comboboxentry> or <comboboxtext> instead, which have <input file> tag, what makes importing data much easier?

Here's a sample:

Code: Select all

DEVICE_FILE="/root/my-applications/bin/activeMTPdevices.txt" 

export DEVICE_DIALOG_LIST='
<window title="The list">
  <vbox>

    <comboboxtext active="0"> 
      <variable>RESULT</variable>
      <input file>'${DEVICE_FILE}'</input>
    </comboboxtext>

    <hbox>
      <button ok>
        <action>exit:PROCEED</action>
      </button>
      <button cancel>
        <action>exit:CANCEL</action>
      </button>
    </hbox>
  
  </vbox>
</window>'


# In order to access returned variables, we have to evaluate them first
eval `gtkdialog --program DEVICE_DIALOG_LIST`


# EXIT states "PROCEED" and "CANCEL" are defined above, but "abort" is internal
if [ "$EXIT" = "PROCEED" ]; then
  xmessage "$RESULT"	#show the result
elif [ "$EXIT" = "CANCEL" ]; then
  xmessage "Cancelled"
elif [ "$EXIT" = "abort" ]; then
  xmessage "Window closed via X"
fi
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]

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#917 Post by can8v »

@SFR
Thanks so much for this.

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

Gtkdialog -get notebook tabnumber

#918 Post by Puma »

could one explain why this code works

Code: Select all

export MAIN='
<notebook>
  <frame><text><label>first tab</label></text></frame>
  <frame><text><label>second tab</label></text></frame>
  <frame><text><label>third tab</label></text></frame>
 
  <variable>VAR</variable>
  <action signal="button-release-event">[ $VAR -eq 0 ] && xmessage "first tab"</action>
  <action signal="key-release-event">[ $VAR -eq 0 ] && xmessage "first tab"</action>
  <action signal="button-release-event">[ $VAR -eq 1 ] && xmessage "second tab"</action>
  <action signal="key-release-event">[ $VAR -eq 1 ] && xmessage "second tab"</action>
  <action signal="button-release-event">[ $VAR -eq 2 ] && xmessage "third tab"</action>
  <action signal="key-release-event">[ $VAR -eq 2 ] && xmessage "third tab"</action>
 
</notebook>'

gtkdialog -cp MAIN
and this not

Code: Select all

export MAIN="
<notebook>

  <frame><text><label>\"first tab\"</label></text></frame>
  <frame><text><label>\"second tab\"</label></text></frame>
  <frame><text><label>\"third tab\"</label></text></frame>
 
  <variable>nTabPage</variable> 
   
  <action signal=\"button-release-event\">[ $nTabPage -eq 0 ] && xmessage \"first tab\"</action>
  <action signal=\"button-release-event\">[ $nTabPage -eq 1 ]  && xmessage \"second tab\"</action>    

</notebook>"

gtkdialog -cp MAIN
also i tried

Code: Select all

I=$IFS; IFS=""
for STATEMENTS in  $(PumaGui.pmx -cp MAIN); do
  eval $STATEMENTS
done
IFS=$I 
the only different is the double qoute sign.

thanks in advance

[/quote]

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

sorry last code should read

#919 Post by Puma »

I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -cp MAIN); do
eval $STATEMENTS
done
IFS=$I

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

#920 Post by SFR »

Puma wrote:the only different is the double qoute sign.
When you're using double quotes instead of single ones, the variables between <action>...</action> tags get evaluated instead of being exported literally as strings, so in result (since nTabPage var is null at this stage) MAIN contains:
<action signal="button-release-event">[ -eq 0 ] && xmessage "first tab"</action>
That's why I prefer s. quotes - much less hassle with escaping, etc.
Anyway, this will work:

Code: Select all

[ "'$nTabPage'" -eq 0 ]
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]

Post Reply