don570
Posts: 24
Joined: Mon Oct 26, 2015 10:15 pm

gtkdialog 0.8.4 available

Sat Jan 30, 2016 7:21 pm

I made a debian package of gtkdialog 0.8.4 . I tested it and
it seems useful for Raspberry pi 2 users. It adds a graphical interface to
scripts and it's not to difficult to use, so schools should be interested.

gtkdialog4-0.8.4-armv7.deb
Available for download:
http://www.mydrive.ch
Guest user: porteus@don570
Password: porteus

There are sample scripts inside the package.
/usr/share/docs/gtkdialog/examples/
A web site is devoted to tips...
http://murga-linux.com/puppy/viewtopic.php?t=38608

While testing it I noticed a small bug with the window widget.
The shell is important . The bug disappeared if I used the
bash shell, so I recommend that scripts using gtkdialog start with

Code: Select all

#!/bin/bash
Enjoy!

don570
Posts: 24
Joined: Mon Oct 26, 2015 10:15 pm

Re: gtkdialog 0.8.4 available

Wed Feb 03, 2016 10:45 pm

For beginners in programming here is a tutorial in gtkdialog script writing.
Install the gtkdialog debian package first ;) .
Some useful tips for using the terminal...
memorize
ctrl-a will place cursor at beginning of line
ctrl-e will place cursor at end of line
ctrl-l will clear screen
Up and down arrow keys will enter previous commands.

To study how gtkdialog behaves with a text line fed to it, we will take advantage
of a special option of gtkdialog, -s.

In a terminal a program line is fed into gtkdialog with the echo command.
So type each line in a terminal and press <ENTER> to execute the line
or copy the lines into the terminal with a drag and click of the mouse.
Strong or weak quoting is possible. Here is an example with weak quoting.

Code: Select all

echo "<window><text><label>Hello World</label></text></window>" | gtkdialog -s

A window is formed with text inside. There are two widgets used, a window widget to form a window,
and a text widget to write the text inside the window.
Note that the display text is actually inside label tags. Here is the alternative
method with strong quoting.

Code: Select all

echo '<window><text><label>Hello World</label></text></window>' | gtkdialog -s
So either strong quoting or weak quoting can be used.
However they aren't quite equivalent.
The special characters are treated differently.

As an example type the following as one line and observe that a substitution has occurred.
$World is substituted with the contents of the variable World

Code: Select all

World=MESSAGE; echo "<window><text><label>Hello $World</label></text></window>" | gtkdialog -s
Strong quoting would have resulted in a literal translation i.e. there is no substitution. You should test this by
changing the line (weak quoting to strong quoting) and running it in a terminal.

Code: Select all

World=MESSAGE; echo '<window><text><label>Hello $World</label></text></window>' | gtkdialog -s
Notice that there is no substitution!!

Warning ! After running this command in your terminal window you must
now close your terminal and launch another terminal window,
since you have assigned the variable World to a value. If you don't
the results are not consistent.
__________________________________________________________________________

The backslash will provide protection of special characters so that a literal translation is made.
In this example Hello \$World will be shown in the window even though weak quoting is being used.

Code: Select all

echo "<window><text><label>Hello \$World</label></text></window>" | gtkdialog -s

_____________________________________________________________________________

Note that if the variable isn't assigned then $World is blank . To see this
be sure to launch a new terminal and type....

Code: Select all

 echo "<window><text><label>Hello $World</label></text></window>" | gtkdialog -s

_______________________________________________________________________

In situations where a variable needs substitution , weak quoting is preferred by some programmers.
However, there is a potential problem. Widgets can have attributes and these attributes must use
weak quoting. They will need protection. Here's an example...

Code: Select all

echo "<window  title=\"Window Title\"><text><label>"Hello World"</label></text></window>" | gtkdialog -s
Note the that the text in the label tag can have weak quotes as well. You mustn't protect those
quotes, unless you want those quotes to show in window.

Another benefit of using weak quoting when feeding gtkdialog is the automatic protection of the apostophe
in the display text of the text widget.

Code: Select all

echo "<window><text><label>Tom's book</label></text></window>" | gtkdialog -s 
However protection of the apostrophe is needed in the following example
because the display text is between weak quotes.

Code: Select all

echo "<window><text><label>"Tom\'s book"</label></text></window>" | gtkdialog -s  


Here is another example to show how strong quotes in the text widget label
can have unexpected consequences...

Code: Select all

echo "<window><text><label>'Toms book'</label></text></window>" | gtkdialog -s
________________________________________________________________________________

By putting the text to be fed to gtkdialog in strong quotes avoids the need for protection
of the attributes.

Note that no protection of the attribute is needed in this example...

Code: Select all

echo '<window  title="Window Title"><text><label>Hello World</label></text></window>' | gtkdialog -s


In the following the display text will be Hello $World since no substitution occurs
i.e. there is a literal translation.

Code: Select all

echo '<window><text><label>Hello $World</label></text></window>' | gtkdialog -s   

If you DO want substitution to occur then it is possible with the right quoting...

Code: Select all

World=MESSAGE;echo '<window><text><label>'"Hello $World"'</label></text></window>' | gtkdialog -s

_______________________________________________________________________

There are 5 predefined buttons possible, cancel , ok , help , yes and no
The cancel button is demonstrated ...

Code: Select all

echo "<window><button cancel></button></window>" | gtkdialog -s

Code: Select all

echo '<window><button cancel></button></window>' | gtkdialog -s
You can make your own button. The most common method is putting a label
on the button...

Code: Select all

echo '<window><button><label>Click Here</label></button></window>' | gtkdialog -s
__________________________________________________________________________

Warning !! When feeding with strong quotes, the hyphen causes problems
as shown by this example...

Code: Select all

echo '<window><text><label>"Tom's book"</label></text></window>' | gtkdialog -s
but there are solutions possible. Here are two possible solutions...

Code: Select all

echo '<window><text><label>'"Tom's book"'</label></text></window>' | gtkdialog -s

Code: Select all

echo '<window><text><label>"'"Tom's book"'"</label></text></window>' | gtkdialog -s
_____________________________________________________________________________________________


By using the -e option with the echo command, the new line command (\n) is possible.

Code: Select all

echo -e '<window  title="Window Title"><text><label>"Hello\n World"</label></text></window>' | gtkdialog -s
Note that the Hello World text needs to be in quotes.

_____________________________________________________________________

The text widget can have width or height requests. Try this example...

Code: Select all

echo '<window  title="Window Title"><text width-request="200"><label>"Hello World"</label></text></window>' | gtkdialog -s
________________________________________________________________

Note that label tags can be replaced with a label attribute if you wish...

Code: Select all

echo '<window  title="Window Title"><text width-request="200" label="Hello World"></text></window>' | gtkdialog -s
_______________________________________________________________________________________

Widgets naturally flow from the top of the window to the bottom of the window.
However in the hbox widget the flow is from the right side of the window
to the left side. Here's an example ...

Code: Select all

echo '<window><hbox><button help></button><button cancel></button></hbox></window>' | gtkdialog -s
Note that the cancel button is on the right side of the window and the help button is to the left.
Tip: Give the hbox widget a width-request="300" to see this effect better.
____________________________________________________________

You now have enough background information to write your first script.
You can now convert the terminal line into a gtkdialog script.
The bash shell should be used to ensure consistent results.

Create a blank text file. Copy the final script into the file and save.
Make sure the script is executable and run
it in the terminal.

Here's how to convert...

Let us convert a terminal line...

Code: Select all

echo '<window><button><label>Click Here</label></button></window>' | gtkdialog -s
The final result...

Code: Select all

#! /bin/bash

export APP='
<window>
    <button>
    <label>Click Here</label>
    </button>
</window>
'
gtkdialog --program=APP

Congratulations ! You are now a gtkdialog programmer.
______________________________________________________________
Last edited by don570 on Mon Feb 08, 2016 9:04 pm, edited 1 time in total.

don570
Posts: 24
Joined: Mon Oct 26, 2015 10:15 pm

Re: gtkdialog 0.8.4 available

Thu Feb 04, 2016 6:18 pm

Inside the label you can have multiple lines, however
this requires weak quoting inside the label tags.
Here is an example. Compare with the previous example.

Code: Select all

#!/bin/bash 

export APP=' 
<window> 
     <text> 
     <label>"Click 
Here"</label> 
     </text> 
</window>
' 
gtkdialog --program=APP

_____________________________________________________________________________

The text widget also supports multiple lines.
As with the previous example, weak quoting will preserve the line endings.

Code: Select all

#!/bin/bash 

export APP=' 
<window> 
      <text width-request="300"> 
      <label>"Click 
Here"</label> 
      </text> 
</window>
' 
gtkdialog --program=APP

don570
Posts: 24
Joined: Mon Oct 26, 2015 10:15 pm

Re: gtkdialog 0.8.4 available

Mon Feb 08, 2016 8:09 pm

Here is an interesting use of gtkdialog -s
suggested by step. It uses EOF condition to feed an entire script
to gtkdialog and it is executed i.e. a window is formed.
When the window is closed , the values of the various variables are sent
to the shell which is useful for further processing.

Code: Select all

#!/bin/bash 
VALUE="a very long default value with spaces" 
cat << EOF | gtkdialog -s 
<window title="enter some text"> 
<hbox width-request="300">
     <entry> 
     <default>$VALUE</default> 
     </entry> 
<button ok></button>
</hbox>
</window> 
EOF 
You can give the entry box a variable name
<variable>ENTRY1</variable> to test if
something is assigned when the window is closed.

Code: Select all

#!/bin/bash 
VALUE="a very long default value with spaces" 
cat << EOF | gtkdialog -s 
<window title="enter some text"> 
<hbox width-request="300">
     <entry> 
     <default>$VALUE</default> 
     <variable>ENTRY1</variable>
</entry> 
<button ok></button>
</hbox>
</window> 
EOF 

don570
Posts: 24
Joined: Mon Oct 26, 2015 10:15 pm

playmusic application

Sat Mar 05, 2016 9:44 pm

Here is a simple way to play a folder of audio files such as mp3 files.
You simply find the folder by clicking a browser icon.

I've compiled playmusic by THUNOR
Requires gtkdialog to be installed (see first post)
Make sure that you have already installed mpg321 or mpg123 so that there will be a mp3 player
_______________________________________________________

available at mydrive.ch

as
playmusic-arm7-0.1.8.deb



Left-clicking the track details toggles between album/artist and track.

Left-clicking the cover navigates to the next folder if one exists.
Right-clicking the cover navigates to the previous folder if one exists.
Middle-clicking the cover will open the cover full-size in another window.

_______________________________________________________

Return to “Other programming languages”