Page 46 of 76

Posted: Tue 10 Dec 2013, 15:14
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.

Posted: Tue 10 Dec 2013, 15:25
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.

Posted: Wed 11 Dec 2013, 01:20
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.

Posted: Wed 11 Dec 2013, 11:45
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?

Posted: Wed 11 Dec 2013, 22:49
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.
.

Posted: Thu 12 Dec 2013, 13:47
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! :)

Posted: Thu 12 Dec 2013, 14:22
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
  }

Posted: Thu 12 Dec 2013, 20:11
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

Posted: Sat 14 Dec 2013, 16:04
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"

Posted: Sat 14 Dec 2013, 19:07
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.

Posted: Sat 14 Dec 2013, 22:42
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

Posted: Sat 14 Dec 2013, 23:41
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.

Change background and foreground entry colors

Posted: Sun 15 Dec 2013, 13:28
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.

GtkDialog Select Option from List (combobox?)

Posted: Mon 27 Jan 2014, 03:47
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?

Posted: Mon 27 Jan 2014, 21:22
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
# 

Posted: Mon 27 Jan 2014, 22:22
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!

Posted: Tue 28 Jan 2014, 02:26
by can8v
@SFR
Thanks so much for this.

Gtkdialog -get notebook tabnumber

Posted: Sat 22 Feb 2014, 14:33
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]

sorry last code should read

Posted: Sat 22 Feb 2014, 14:36
by Puma
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -cp MAIN); do
eval $STATEMENTS
done
IFS=$I

Posted: Sat 22 Feb 2014, 15:22
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!