December 12, 2007

Belajar gtkdialog menggunakan xml dan shell script [bagian 2]

Setelah saya membahas gtkdialog pada bagian1 mungkin anda sudah mempelajari lebih jauh, jadi kali ini saya akan langsung membuat sebuah program untuk ping dan traceroute. Kita akan mencoba membuat dan menggunakan fungsi-fungsi dari sebuah shell script.Untuk yang pertama buat file untuk konfigurasi GUI-nya.

# touch netutils

Edit dan tambahkan baris berikut.

#! /bin/bash

export MAIN_DIALOG=’

<window title=”Network Utilities” icon-name=”network-config”>

<vbox>

<menubar>

<menu>

<menuitem stock=”gtk-quit”>

<action>rm -rf /tmp/log*</action>

<action type=”exit”>=quit</action>

</menuitem>

<label>File</label>

</menu>

<menu>

<menuitem stock=”gtk-dialog-info”>

<action type=”launch”>ABOUT_DIALOG</action>

</menuitem>

<label>Help</label>

</menu>

</menubar>

<hbox>

<vbox>

-*

<frame Log Ping>

<table>

<variable>LOGSPING</variable>

<input>logping</input>

<height>150</height><width>350</width>

</table>

</frame>

<hbox>

<text>

<label>Network Address</label>

</text>

<entry>

<input>desip</input>

<variable>DESIP</variable>

</entry>

<button>

<input file stock=”gtk-refresh”></input>

<label>”clear”</label>

<action type=”clear”>DESIP</action>

<action type=”clear”>LOGSPING</action>

</button>

<button>

<input file stock=”gtk-refresh”></input>

<label>Ping</label>

<action>pingdab</action>

<action type=”refresh”>LOGSPING</action>

</button>

</hbox>

<vbox>

<frame Log Traceroute>

<table>

<variable>LOGSTRACE></variable>

<input>logtrace></input>

<height>150</height><width>350</width>

</table>

</frame>

<hbox>

<text>

<label>Network Address</label>

</text>

<entry>

<input>desiptrace</input>

<variable>DESIPTRACE</variable>

</entry>

<button>

<input file stock=”gtk-refresh”></input>

<label>”clear”</label>

<action type=”clear”>DESIPTRACE</action>

<action type=”clear”>LOGSTRACE</action>

</button>

<button>

<input file stock=”gtk-refresh”></input>

<label>Trace</label>

<action>tracedab</action>

<action type=”refresh”>LOGSTRACE</action>

</button>

</hbox>

</vbox>

</vbox>

</hbox>

<hbox>

<button>

<input file stock=”gtk-close”></input>

<label>Quit</label>

<action>rm -rf /tmp/log*</action>

<action type=”closewindow”>MAIN_DIALOG<action>

</button>

</hbox>

</vbox>

</window>

export ABOUT_DIALOG=’

<window title=”About” icon-name=”network-config”>

<vbox>

<frame Network Utilities>

<text wrap=”true” width-chars=”55″>

<label>”Network Utilities untuk Tuximan GNU/Linux.

Copyright@ 2007 Tuximan Project.
Author : Aji Kisworo Mukti

Netutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option)any later version.”

</label>

</text>

</frame>

<hbox>

<button>

<input file stock=”gtk-close”></input>

<label>Close</label>

<action type=”closewindow”>ABOUT_DIALOG</action>

</button>

</hbox>

</vbox>

</window>

gtkdialog -i netutils-functions –program=MAIN_DIALOG

Kemudian buat lagi file fungsi.

# touch netutils-function

Edit dan tambahkan baris berikut.

#!/bin/bash

desip(){
echo “127.0.0.1″
}

logping(){
cat /tmp/logping
}

pingdab(){
ping $DESIP -w 5 >/tmp/logping
}

logtrace(){
cat /tmp/logtrace
}

desiptrace(){
echo “127.0.0.1″
}

tracedab(){
traceroute -w 5 $DESIPTRACE >/tmp/logtrace
}

Saya kali ini memberi kesempatan anda untuk mempelajarinya dahulu. :P . mungkin ini akan saya bahas besok lain waktu.

Leave a Reply