My Word Search program works, but...SOLVED

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

My Word Search program works, but...SOLVED

#1 Post by oldyeller »

Hello Everyone,

I have made a word search program for Manna. it all works good except that I have to hit the OK button twice for the results show up in the window. I have done many different whys to code this. This is the best that I have come up with.

Any help to get the OK button to be clicked on once would be great.

Thanks

Code: Select all

#!/bin/sh



if [ "`which gtkdialog4`" ]; then
 GTKDIALOG=gtkdialog4
elif [ "`which gtkdialog3`" ]; then
 GTKDIALOG=gtkdialog3
else
 GTKDIALOG=gtkdialog
fi






export WORKDIR="/usr/local/Search"
export TMP="/usr/local/Search/tmp"

NAME=`cat $TMP/name`
 


#define special font for Reader and GUI frames
READER_FONTNAME=`cat $WORKDIR/font_name`
[ "$READER_FONTNAME" = "" ] && READER_FONTNAME="Sans" && echo "Sans" > $WORKDIR/font_name
READER_FONTSIZE=`cat $WORKDIR/font_size`
[ "$READER_FONTSIZE" = "" ] && READER_FONTSIZE="12" && echo "12" > $WORKDIR/font_size

echo "style \"specialsize\"
{
  font_name=\"$READER_FONTNAME $READER_FONTSIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"

style \"specialframe\"
{
  font_name=\"Sans bold 11\"
  fg[NORMAL]=\"grey40\"
}
widget \"*.GtkFrame.GtkLabel\" style \"specialframe\"
class \"*.GtkFrame.GtkLabel\" style \"specialframe\"" > "$WORKDIR/gtkrc_special"

export GTK2_RC_FILES="$WORKDIR/gtkrc_special:${HOME}/.gtkrc-2.0"

#define icon for current fontsize
if [ "$READER_FONTSIZE" = "12" ]; then
 FONTSIZE12_ICON='stock-id="gtk-apply"'
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "14" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON='stock-id="gtk-apply"'
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "16" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON='stock-id="gtk-apply"'
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "18" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON='stock-id="gtk-apply"'
fi



#Main dlg
export MAIN_DIALOG='
<window title="'$(gettext "$mytitle $version")'" icon-name="Com" resizable="true" window-position="1">
  <vbox>
   <hbox>
    <menubar>
     <menu stock-id="gtk-file" label="'$(gettext "_File")'">
      <menuitem stock-id="gtk-open" tooltip-text="'$(gettext " Open new document ")'">
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem stock-id="gtk-quit">
		<action>exit:Quit</action>
      </menuitem>
     </menu>

     <menu icon-name="font" label="F_onts" use-underline="true">
	  <menuitem icon-name="font" label="Dejavu Sans">
		<action>echo "Dejavu Sans" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Droid Sans">
		<action>echo "Droid Sans" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Droid Sans Mono">
		<action>echo "Droid Sans Mono" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Droid Serif">
		<action>echo " Droid Serif" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Gruppo">
		<action>echo "Gruppo" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Kelly Slab">
		<action>echo "Kelly Slab" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="MONO">
		<action>echo "Mono" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Nimbus Roman No9 L">
		<action>echo "Nimbus Roman No9 L" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	   <menuitem icon-name="font" label="Nimbus Sans L">
		<action>echo "Nimbus Sans L" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Play">
		<action>echo "Play" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>	 
	   <menuitem icon-name="font" label="Sans">
		<action>echo "Sans" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
	  </menuitem>
	  <menuitem icon-name="font" label="Serif">
		<action>echo "Serif" > '"$WORKDIR"'/font_name</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
		</menuitem>
     </menu>

     <menu icon-name="pc48" label="'$(gettext "_View")'" use-underline="true" tooltip-text="'$(gettext " Change font size ")'">
		<menuitem '$FONTSIZE12_ICON' label="12">
		<action>echo "12" > '$WORKDIR'/font_size</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE14_ICON' label="14">
		<action>echo "14" > '$WORKDIR'/font_size</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE16_ICON' label="16">
		<action>echo "16" > '$WORKDIR'/font_size</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE18_ICON' label="18">
		<action>echo "18" > '$WORKDIR'/font_size</action>
		<action>touch /tmp/mannastudies_flag</action>
		<action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
      </menuitem>
     </menu>
    </menubar>

      <text width-request="2"><label>""</label></text>
      <vseparator></vseparator>
      <text width-request="1"><label>""</label></text>
	  <text><label>"'$(gettext "Font:")'"</label></text>

     <entry>
      <variable>FONTNAME</variable>
       <input file>'"$WORKDIR"'/font_name</input>
     </entry>

    <menubar>
     <menu stock-id="gtk-help" label="'$(gettext "_Help")'" use-underline="true">
      <menuitem stock-id="gtk-about" label="'$(gettext "About")'">
		<action>/tmp/MannaStudies-help &</action>
      </menuitem>
     </menu>
    </menubar>	 
   </hbox>
  

    <hbox>
	 <text><label>"'$(gettext "Search:")'"</label></text>
     <entry has-focus="true" width-request="250" wrap-width="0">
      <variable>SEARCH</variable>
      <default>Type something here...</default>
     <input file>'"$TMP"'/name</input>
	<output file>'"$TMP"'/name</output>
	<action signal="activate">save:SEARCH</action>
		<action signal="activate">refresh:SEARCH</action>
		<action>refresh:RESULTS</action>
		</entry>
     <button>
     <label>OK</label>
      <action>grep -w '$NAME' *|sort -n > results</action>
      <action>'$WORKDIR'/search &</action>
		<action type="exit">quit_now</action>
		<action>refresh:RESULTS</action>
       </button>
   </hbox>

   <hbox space-expand="true" space-fill="true"> 
    <frame '$(gettext "Results")'>
    <vbox space-expand="true" space-fill="true">  
     <edit editable="false" justification="3" indent="" left-margin="12" right-margin="12" wrap-mode="2">
      <variable>RESULTS</variable>
       <height>500</height>
       <width>700</width>
       <input file>'"$WORKDIR"'/results</input>
     </edit>
    </vbox>
    </frame>
   </hbox>
 </vbox>
<action signal="hide">exit:Exit</action> 
</window>'

$GTKDIALOG -p MAIN_DIALOG > /dev/null 2>&1 </dev/null
unset MAIN_DIALOG
exit 0
Last edited by oldyeller on Thu 03 Jul 2014, 17:39, edited 1 time in total.

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#2 Post by oldyeller »

Hello Everyone,

I got this fixed. What I did was put this
code]
NAME=`cat $TMP/name
[grep -w '$NAME' *|sort -n > results`
geany results
[/code]

Into a func and it all works with just hitting the enter key once.

Post Reply