📄 calculator.ksh.fifo
字号:
#!/bin/ksh## Demonstration on how to use Glade and the GTK-server with KSH.## Tested with GTK-server 2.2.9 on Zenwalk 5.2 and Korn93.# October 23, 2008 (c) Peter van Eerten - GPL license.## Proving unlimited input for FIFO.##----------------------------------------------------------- Setup embedded GTK# Pipe filename must be unique for your applicationPIPE="/tmp/gtk.bash.\$$"# Find GTK-server configfile firstif [[ -f gtk-server.cfg ]]; then CFG=gtk-server.cfgelif [[ -f /etc/gtk-server.cfg ]]; then CFG=/etc/gtk-server.cfgelif [[ -f /usr/local/etc/gtk-server.cfg ]]; then CFG=/usr/local/etc/gtk-server.cfgelse echo "No GTK-server configfile found! Please install GTK-server..." exit 1fi# Now create global functionnames from GTK APIif [[ ! -f $HOME/.gtk4bash || $CFG -nt $HOME/.gtk4bash ]]; then echo "#!/bin/bash" > $HOME/.gtk4bash echo "gtk-server -fifo=$PIPE &" >> $HOME/.gtk4bash echo "while [ ! -p $PIPE ]; do continue; done" >> $HOME/.gtk4bash while read LINE do if [[ $LINE = FUNCTION_NAME* ]]; then LINE=${LINE#*= } printf "\nfunction ${LINE%%,*}\n" >> $HOME/.gtk4bash printf "{\necho ${LINE%%,*} \$@ > $PIPE" >> $HOME/.gtk4bash printf "\nread GTK < $PIPE\n}\n" >> $HOME/.gtk4bash fi done < $CFGfi# Declare global variablestypeset GTK NULL="NULL"unset CFG PIPE LINE# Include the generated file to use embedded GTK functions. ${HOME}/.gtk4bash#---------------------------------------------------------- Global inits# GTK-server must go after an error in the scripttrap 'echo "gtk_server_exit" > $PIPE' ERR# Assignment functionfunction define { $2 $3 $4 $5 $6 $7 $8 $9; eval $1="\"$GTK\""; }#---------------------------------------------------------- GUI realization# Set GUI definitionGUI="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE glade-interface SYSTEM \"glade-2.0.dtd\"><!--Generated with glade3 3.4.0 on Fri Jan 11 20:13:32 2008 --><glade-interface> <widget class=\"GtkWindow\" id=\"window\"> <property name=\"width_request\">250</property> <property name=\"height_request\">225</property> <property name=\"visible\">True</property> <property name=\"title\" translatable=\"yes\">KSH Calculator FIFO</property> <property name=\"resizable\">False</property> <property name=\"window_position\">GTK_WIN_POS_CENTER</property> <property name=\"default_width\">264</property> <property name=\"default_height\">248</property> <property name=\"icon_name\">calc</property> <child> <widget class=\"GtkTable\" id=\"table1\"> <property name=\"visible\">True</property> <property name=\"n_rows\">5</property> <property name=\"n_columns\">5</property> <property name=\"homogeneous\">True</property> <child> <widget class=\"GtkButton\" id=\"buttonMemadd\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">M+</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">3</property> <property name=\"right_attach\">4</property> <property name=\"top_attach\">4</property> <property name=\"bottom_attach\">5</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkEntry\" id=\"entry\"> <property name=\"visible\">True</property> <property name=\"sensitive\">False</property> <property name=\"editable\">False</property> <property name=\"xalign\">1</property> </widget> <packing> <property name=\"right_attach\">5</property> <property name=\"x_padding\">4</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button1\"> <property name=\"width_request\">0</property> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">1</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"top_attach\">1</property> <property name=\"bottom_attach\">2</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button3\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">3</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">2</property> <property name=\"right_attach\">3</property> <property name=\"top_attach\">1</property> <property name=\"bottom_attach\">2</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"buttonC\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">C</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">3</property> <property name=\"right_attach\">4</property> <property name=\"top_attach\">1</property> <property name=\"bottom_attach\">2</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"buttonCE\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">CE</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">4</property> <property name=\"right_attach\">5</property> <property name=\"top_attach\">1</property> <property name=\"bottom_attach\">2</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button4\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">4</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"top_attach\">2</property> <property name=\"bottom_attach\">3</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button5\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">5</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">1</property> <property name=\"right_attach\">2</property> <property name=\"top_attach\">2</property> <property name=\"bottom_attach\">3</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button6\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">6</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">2</property> <property name=\"right_attach\">3</property> <property name=\"top_attach\">2</property> <property name=\"bottom_attach\">3</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"buttonAdd\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">+</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">3</property> <property name=\"right_attach\">4</property> <property name=\"top_attach\">2</property> <property name=\"bottom_attach\">3</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"buttonMinus\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">-</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">4</property> <property name=\"right_attach\">5</property> <property name=\"top_attach\">2</property> <property name=\"bottom_attach\">3</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button7\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">7</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"top_attach\">3</property> <property name=\"bottom_attach\">4</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button8\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">8</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">1</property> <property name=\"right_attach\">2</property> <property name=\"top_attach\">3</property> <property name=\"bottom_attach\">4</property> <property name=\"x_padding\">5</property> <property name=\"y_padding\">8</property> </packing> </child> <child> <widget class=\"GtkButton\" id=\"button9\"> <property name=\"visible\">True</property> <property name=\"label\" translatable=\"yes\">9</property> <property name=\"response_id\">0</property> </widget> <packing> <property name=\"left_attach\">2</property> <property name=\"right_attach\">3</property> <property name=\"top_attach\">3</property> <property name=\"bottom_attach\">4</property> <property name=\"x_padding\">4</property> <property name=\"y_padding\">8</property> </packing>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -