Associated script
Prev Glade2script Reference Manual Next



Associated script


The associated script may be translated into several languages. It must create a FIFO, keep listening for this file (in order to load variables in the environment or call functions) and return commands on the stdout ( echo, print depending on the language).

In this FIFO file, two different types of data can be written:
# variable load
GET@WidgetName_action=”resultat”

# function call
WidgetName Argument


Example using Bash

#! /bin/bash

FIFO creation

fonction()
{ # widget function
echo "SET@_label.set_text('Hello world !')"
}

retrieval loop

exit 


# FIFO creation
PID=$$
FIFO=/tmp/FIFO${PID}
mkfifo $FIFO
# retrieval loop
while read ligne; do
  if [[ "$ligne" =~ GET@ ]]; then
    eval ${ligne#*@}
    echo "DEBUG => in boucle bash :" ${ligne#*@}
  else
    echo "DEBUG=> in bash NOT GET" $ligne
    $ligne
  fi
done < <(while true; do
read entree < /tmp/FIFO
[[ "$entree" == "QuitNow" ]] && break
echo $entree
done)
# retrieval loop  suggested by Totor on the french Ubuntu forum
exec 4<>/tmp/FIFO
while read -u 4 ligne
  do
    if [[ "$ligne" == "QuitNow" ]]; then
      break
    elif [[ "$ligne" =~ GET@ ]]; then
      eval ${ligne#*@}
      echo "DEBUG => in boucle bash :" ${ligne#*@}
    else
      echo "DEBUG=> in bash NOT GET" $ligne
      $ligne
    fi
  done
exec 4>&- 4<&-



Example using Python

 The --import option must be used.
  One may also get rid of the go_*.py script and replace it by the last condition.

#! /usr/bin/env python
# -*- coding:Utf­8 ­-*-

   
class Action(threading.Thread):
    '''
    This class must keep this very name
    '''
    def __init__(self, g2s):
        '''
        g2s = instance of glade2script
        '''
        threading.Thread.__init__(self)
        # Call the from_import method to communicate with glade2script
        self.to_glade = g2s.from_import
       
    def run(self):
        ''' This function shall not be removed'''
        pass
    
    def quit_now(self):
        ''' This function shall not be removed'''
        pass
           
    def btn_traduire(self, arg=None):
        self.to_glade('''SET@_label.set_text('Hello world !')''')


if __name__ == '__main__':
    path_file = os.path.abspath(__file__)
    path_folder = os.path.dirname(path_file)
    os.chdir(path_folder)
    os.system('./glade2script.py -g ./Test.glade -d --import="%s"' % path_file)

In order to directly get the return, on may add the True argument. Otherwise the same behavior as for bash will be observed. A function would be called and/or a variable loaded into the environment.
 liste = self.to_glade('MULTI@@GET@@get_text()@@_entry_name, _entry_os', True)
In order to get the callback from HIZO commands. Be careful though, this solution might cause problems with the GTK queue!
 text = self.g2s.TEXTHIZOTAG('TEXT@@HIZOTAG@@_textview_saisie', True)


Prev Glade2script Reference Manual Next