How do I put a comboboxentry in the right click menu?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

How do I put a comboboxentry in the right click menu?SOLVED

#1 Post by oldyeller »

Hello Everyone,

I have a question can the comboboxentry be put into the menubar? If so how, I have tried and it does not work.

Any ideas?

Code: Select all

<comboboxentry has-focus="true" wrap-width="2">
    <variable>ITEM</variable>
     <input>ls '"$NOTES_DIR"'</input>
     <action>ln -f "/root/my-documents/Manna/$ITEM" '"$WORKDIR"'/note</action>
      <action>refresh:EDITOR</action>
   </comboboxentry>
I tried doing this

Code: Select all

<menubar>
<menuitem>
<comboboxentry has-focus="true" wrap-width="2">
    <variable>ITEM</variable>
     <input>ls '"$NOTES_DIR"'</input>
     <action>ln -f "/root/my-documents/Manna/$ITEM" '"$WORKDIR"'/note</action>
      <action>refresh:EDITOR</action>
   </comboboxentry>
</menuitem>
</menubar>
I also tried with the menu tag still nothing.

Thanks for any help
Last edited by oldyeller on Mon 24 Jun 2013, 15:32, edited 2 times in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

GTK+ supports all kinds of stuff like combos in menus.

But I don`t think a combo can be directly on the menu bar.

GtkDialog does not support lots of what GTK+ can do.
It`s complicated to try to enable all combinations of controls.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#3 Post by zigbert »

I have used a combo in menus - but only for right-click menus

Image

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

#4 Post by oldyeller »

@ sunburnt Thanks for the info.

@zigbert How would I go about doing one in right click menu for the editor?


Thanks

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#5 Post by zigbert »

What is 'the editor' ?

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

#6 Post by oldyeller »

The editor is Manna-Editor

Code: Select all

#!/bin/bash
#130617 i18n started 


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

WORKDIR="/usr/local/mannaeditor"
NOTES_DIR="/root/my-documents/Manna"

export TEXTDOMAIN=Editor
export OUTPUT_CHARSET=UTF-8 


#define special Sans-12 font for Editor
READER_FONTSIZE=`cat $WORKDIR/font_size`
[ "$READER_FONTSIZE" = "" ] && READER_FONTSIZE="12" && echo "12" > $WORKDIR/font_size

echo "style \"specialsize\"
{
  font_name=\"Sans $READER_FONTSIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"

export GTK2_RC_FILES="$WORKDIR/gtkrc_size:${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


add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'`   # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}
export -f add_note

#About dlg...
echo '#!/bin/sh' > /tmp/Editor-help
echo 'export EDITORHELP_DIALOG="
<window title=\"About\" icon-name=\"Com\" resizable=\"false\">
 <vbox>
 <notebook labels=\"About|License|Translations\">
 <vbox>
  <text height-request=\"2\"><label>\" \"</label></text>
  <pixmap><input file>/usr/local/Manna/icons/Com.png</input></pixmap>
  <text height-request=\"2\"><label>\" \"</label></text>
  <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor 2.2</span></b>\"</label></text>
  <text><label>\"    This is a basic text Editor for making notes or Teachings 
    and can be exported to Abiword. The user interface 
    supports the display of text in multiple font sizes for 
    general viewing comfort.
   \"</label></text>

  <text><label>\"Copyright © 2013 GPL
  \"</label></text>
</vbox>
 <vbox>
 <text height-request=\"8\"><label>\" \"</label></text>
 <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor</span></b>\"</label></text>
  <text use-markup=\"true\"><label>\"Is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
   <text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b><span color='"'red'"'>WITHOUT ANY WARRANTY</span></b>. See the GNU General Public License homepage for more details.\"</label></text>
    <hbox>
     <button>
      <label>\"http://www.gnu.org/licenses/\"</label>
      <action>defaultbrowser http:\/\/www.gnu.org\/licenses\/</action>
     </button>
    </hbox>
    </vbox>
   <vbox>
   <text height-request=\"8\"><label>\" \"</label></text>
   <text><label>\" German \"</label></text>
   <text><label>\" Spanish \"</label></text>
   </vbox>
  </notebook>
   <hbox homogeneous=\"true\">
     <button height-request=\"35\" width-request=\"100\">
      <label>\"Close\"</label>
	  <input file stock=\"gtk-close\"></input>
	  <action type=\"exit\">quit_now</action>
     </button>
   </hbox>
 </vbox>
</window>"
gtkdialog --center --program=EDITORHELP_DIALOG' >> /tmp/Editor-help
chmod 777 /tmp/Editor-help

export ADD_FILE='
  <window title="'$( gettext "Add Note")'" modal="true" icon-name="gtk-add" resizable="false">
    <vbox>
      <frame "'$(gettext "Note name:")'">
        <entry>
          <variable>NOTENAME</variable>
        </entry>
        <hbox>
          <button ok>
            <action>add_note</action>
            <action>clear:ITEM</action>
            <action>refresh:ITEM</action>
            <action type="closewindow">NOTENAME</action>
          </button>
          <button cancel>
            <action type="closewindow">NOTENAME</action>
          </button>
        </hbox>
      </frame>
    </vbox>
  </window>
'

export DEL_FILE='
  <window title="'$(gettext "Del Note")'" modal="true" icon-name="gtk-remove" resizable="false">
    <vbox>
      <text><label>"'$(gettext "Are you sure you want to delete:")'"</label></text>
	      <text><input>echo "$ITEM"</input></text>
      <hbox>
        <button ok>
          <variable>CONFIRM</variable>
          <action>rm "$NOTES_DIR"/"$ITEM"</action>
          <action>clear:ITEM</action>
          <action>refresh:ITEM</action>
          <action type="closewindow">CONFIRM</action>
        </button>
        <button cancel>
          <action type="closewindow">CONFIRM</action>
        </button>
      </hbox>
    </vbox>
  </window>
'



export MAIN_DIALOG='
<window title="'$(gettext "Manna Editor")'" icon-name="Com" resizable="false">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>launch:ADD_FILE</action>
</menuitem>
<menuitem stock-id="gtk-save">
<action>Save:EDITOR</action>
<action>Save:Saving</action>
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-refresh">
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-delete">
<action>launch:DEL_FILE</action>
</menuitem>
<menuitem stock-id="gtk-quit">
<action>exit:Quit</action>
</menuitem>
<label>"'$(gettext "_File")'"</label>
</menu>
<menu label="'$(gettext "_Edit")'" use-underline="true">
<menuitem stock-id="gtk-edit" label="'$(gettext "Send to Abiword")'">
		<action>defaultwordprocessor '"$WORKDIR"'/notes &</action>
	  </menuitem>
</menu>
<menu 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>'$WORKDIR'/Editor &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE14_ICON' label="14">
		<action>echo "14" > '$WORKDIR'/font_size</action>
		<action>'$WORKDIR'/Editor &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE16_ICON' label="16">
		<action>echo "16" > '$WORKDIR'/font_size</action>
		<action>'$WORKDIR'/Editor &</action>
		<action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE18_ICON' label="18">
		<action>echo "18" > '$WORKDIR'/font_size</action>
		<action>'$WORKDIR'/Editor &</action>
		<action type="exit">quit_now</action>
      </menuitem>
	 </menu>
	 <menu label="'$(gettext "_Help")'" use-underline="true">
	  <menuitem stock-id="gtk-info" label="'$(gettext "Help")'">
		<action>defaultbrowser '$WORKDIR'/editor-docs/MannaEditorHelp.html &</action>
	  </menuitem>
	  <menuitem stock-id="gtk-info" label="'$(gettext "About")'">
		<action>/tmp/Editor-help &</action>
	  </menuitem>
	 </menu>
</menubar>




   <comboboxentry has-focus="true" wrap-width="2">
    <variable>ITEM</variable>
     <input>ls '"$NOTES_DIR"'</input>
     <action>ln -f "/root/my-documents/Manna/$ITEM" '"$WORKDIR"'/note</action>
      <action>refresh:EDITOR</action>
   </comboboxentry>

  <hseparator></hseparator>

  <hbox>
   <edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="2">
     <variable>EDITOR</variable>
     <height>600</height>
     <width>780</width>
     <input file>'"$WORKDIR"'/note</input>
     <output file>'"$WORKDIR"'/note</output>
   </edit>
  </hbox>
  </vbox>
 </frame>
<action signal="hide">exit:Exit</action>
</window>
'

MM1RET="`gtkdialog --program=MAIN_DIALOG`" 

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#7 Post by zigbert »

oldyeller
This is not a final solution, but a showcase how I set up my external menus. In addition to the new function show_menu, see line 13, 14 and the <edit> code. The menus in pMusic are located in separate files, so it is easy to see more complex examples. Ie. /usr/local/pmusic/menu_sourcelist

Code: Select all

#!/bin/bash
#130617 i18n started


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

export WORKDIR="/usr/local/mannaeditor"
export NOTES_DIR="/root/my-documents/Manna"

export TEXTDOMAIN=Editor
export OUTPUT_CHARSET=UTF-8


#define special Sans-12 font for Editor
READER_FONTSIZE=`cat $WORKDIR/font_size`
[ "$READER_FONTSIZE" = "" ] && READER_FONTSIZE="12" && echo "12" > $WORKDIR/font_size

echo "style \"specialsize\"
{
  font_name=\"Sans $READER_FONTSIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"

export GTK2_RC_FILES="$WORKDIR/gtkrc_size:${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


add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'`   # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}

show_menu () {
MENUITEMS="`find "$NOTES_DIR" -type f -printf "<menuitem><label>\\\"%f\\\"</label><action>ln -f \\\"/root/my-documents/Manna/%f\\\" '"$WORKDIR"'/note</action><action>EXIT:exit</action></menuitem>\n" | sort`"
[ ! "$MENUITEMS" ] && MENUITEMS='<menuitem><label>"no files found"</label></menuitem>'
echo '
<window decorated="false" skip_taskbar_hint="true" resizable="false" height-request="50" width-request="240" modal="true">
 <hbox scrollable="true" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  <text width-request="1" space-expand="false" space-fill="false"><label>""</label></text>
  <vbox spacing="2">
   <text height-request="2" space-expand="false" space-fill="false"><label>""</label></text>
   <hbox height-request="22" spacing="2">
	<pixmap height-request="20" icon_size="1" space-expand="false" space-fill="false"><input file stock="gtk-open"></input></pixmap>
    <entry>
     <variable>ITEM</variable>
     <input>ls '"$NOTES_DIR"'</input>
     <action signal="activate">ln -f "/root/my-documents/Manna/$ITEM" '"$WORKDIR"'/note</action>
     <action signal="activate">EXIT:exit</action>
    </entry>
    <menubar>
     <menu>
     '"$MENUITEMS"'
     <label>..</label>
     </menu>
    </menubar>
   </hbox>
  </vbox>
 </hbox>
 <action signal="focus-out-event">EXIT:exit</action>
</window>' | gtkdialog -s -G +"$(($PTR_X_ROOT-5))"+"$(($PTR_Y_ROOT-5))" > /dev/null
}

export -f add_note show_menu

#About dlg...
echo '#!/bin/sh' > /tmp/Editor-help
echo 'export EDITORHELP_DIALOG="
<window title=\"About\" icon-name=\"Com\" resizable=\"false\">
 <vbox>
 <notebook labels=\"About|License|Translations\">
 <vbox>
  <text height-request=\"2\"><label>\" \"</label></text>
  <pixmap><input file>/usr/local/Manna/icons/Com.png</input></pixmap>
  <text height-request=\"2\"><label>\" \"</label></text>
  <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor 2.2</span></b>\"</label></text>
  <text><label>\"    This is a basic text Editor for making notes or Teachings
    and can be exported to Abiword. The user interface
    supports the display of text in multiple font sizes for
    general viewing comfort.
   \"</label></text>

  <text><label>\"Copyright © 2013 GPL
  \"</label></text>
</vbox>
 <vbox>
 <text height-request=\"8\"><label>\" \"</label></text>
 <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor</span></b>\"</label></text>
  <text use-markup=\"true\"><label>\"Is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
   <text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b><span color='"'red'"'>WITHOUT ANY WARRANTY</span></b>. See the GNU General Public License homepage for more details.\"</label></text>
    <hbox>
     <button>
      <label>\"http://www.gnu.org/licenses/\"</label>
      <action>defaultbrowser http:\/\/www.gnu.org\/licenses\/</action>
     </button>
    </hbox>
    </vbox>
   <vbox>
   <text height-request=\"8\"><label>\" \"</label></text>
   <text><label>\" German \"</label></text>
   <text><label>\" Spanish \"</label></text>
   </vbox>
  </notebook>
   <hbox homogeneous=\"true\">
     <button height-request=\"35\" width-request=\"100\">
      <label>\"Close\"</label>
     <input file stock=\"gtk-close\"></input>
     <action type=\"exit\">quit_now</action>
     </button>
   </hbox>
 </vbox>
</window>"
gtkdialog --center --program=EDITORHELP_DIALOG' >> /tmp/Editor-help
chmod 777 /tmp/Editor-help

export ADD_FILE='
  <window title="'$( gettext "Add Note")'" modal="true" icon-name="gtk-add" resizable="false">
    <vbox>
      <frame "'$(gettext "Note name:")'">
        <entry>
          <variable>NOTENAME</variable>
        </entry>
        <hbox>
          <button ok>
            <action>add_note</action>
            <action>clear:ITEM</action>
            <action>refresh:ITEM</action>
            <action type="closewindow">NOTENAME</action>
          </button>
          <button cancel>
            <action type="closewindow">NOTENAME</action>
          </button>
        </hbox>
      </frame>
    </vbox>
  </window>
'

export DEL_FILE='
  <window title="'$(gettext "Del Note")'" modal="true" icon-name="gtk-remove" resizable="false">
    <vbox>
      <text><label>"'$(gettext "Are you sure you want to delete:")'"</label></text>
         <text><input>echo "$ITEM"</input></text>
      <hbox>
        <button ok>
          <variable>CONFIRM</variable>
          <action>rm "$NOTES_DIR"/"$ITEM"</action>
          <action>clear:ITEM</action>
          <action>refresh:ITEM</action>
          <action type="closewindow">CONFIRM</action>
        </button>
        <button cancel>
          <action type="closewindow">CONFIRM</action>
        </button>
      </hbox>
    </vbox>
  </window>
'



export MAIN_DIALOG='
<window title="'$(gettext "Manna Editor")'" icon-name="Com" resizable="false">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>launch:ADD_FILE</action>
</menuitem>
<menuitem stock-id="gtk-save">
<action>Save:EDITOR</action>
<action>Save:Saving</action>
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-refresh">
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-delete">
<action>launch:DEL_FILE</action>
</menuitem>
<menuitem stock-id="gtk-quit">
<action>exit:Quit</action>
</menuitem>
<label>"'$(gettext "_File")'"</label>
</menu>
<menu label="'$(gettext "_Edit")'" use-underline="true">
<menuitem stock-id="gtk-edit" label="'$(gettext "Send to Abiword")'">
      <action>defaultwordprocessor '"$WORKDIR"'/notes &</action>
     </menuitem>
</menu>
<menu 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>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE14_ICON' label="14">
      <action>echo "14" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE16_ICON' label="16">
      <action>echo "16" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE18_ICON' label="18">
      <action>echo "18" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
    </menu>
    <menu label="'$(gettext "_Help")'" use-underline="true">
     <menuitem stock-id="gtk-info" label="'$(gettext "Help")'">
      <action>defaultbrowser '$WORKDIR'/editor-docs/MannaEditorHelp.html &</action>
     </menuitem>
     <menuitem stock-id="gtk-info" label="'$(gettext "About")'">
      <action>/tmp/Editor-help &</action>
     </menuitem>
    </menu>
</menubar>

  <hbox>
   <edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="2" file-monitor="true" auto-refresh="true">
     <variable>EDITOR</variable>
     <height>600</height>
     <width>780</width>
     <input file>'"$WORKDIR"'/note</input>
     <output file>'"$WORKDIR"'/note</output>
     <action signal="button-press-event">if [ $PTR_BTN -eq 3 ]; then show_menu; fi</action>
   </edit>
  </hbox>
  </vbox>
 </frame>
<action signal="hide">exit:Exit</action>
</window>
'

MM1RET="`gtkdialog --program=MAIN_DIALOG`" 

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

#8 Post by oldyeller »

Hi zigbert,

I'll copy the code and look at it and will also look at yours too. Will report back


Cheers

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

#9 Post by oldyeller »

@zigbert The only thing I have notice is that it does not refresh the editor. If I want to split up my code and put them in other files how do I do that?

I know that you said
oldyeller
This is not a final solution, but a showcase how I set up my external menus. In addition to the new function show_menu, see line 13, 14 and the <edit> code. The menus in pMusic are located in separate files, so it is easy to see more complex examples. Ie. /usr/local/pmusic/menu_sourcelist
Also this file /usr/local/pmusic/menu_sourcelist is not in the pmusic that I have pMusic 3.2.3

look forward to learning more thanks

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#10 Post by zigbert »

Hi again
It seems the <edit> widget fails with the file-monitor attribute.
We have to use another workaround. See line 15, 267 and the show_menu fundtion.

Code: Select all

#!/bin/bash
#130617 i18n started


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

export WORKDIR="/usr/local/mannaeditor"
export NOTES_DIR="/root/my-documents/Manna"
echo false > /tmp/UPDATE_EDITOR

export TEXTDOMAIN=Editor
export OUTPUT_CHARSET=UTF-8


#define special Sans-12 font for Editor
READER_FONTSIZE=`cat $WORKDIR/font_size`
[ "$READER_FONTSIZE" = "" ] && READER_FONTSIZE="12" && echo "12" > $WORKDIR/font_size

echo "style \"specialsize\"
{
  font_name=\"Sans $READER_FONTSIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"

export GTK2_RC_FILES="$WORKDIR/gtkrc_size:${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


add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'`   # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}

show_menu () {
MENUITEMS="`find "$NOTES_DIR" -type f -printf "<menuitem><label>\\\"%f\\\"</label><action>ln -f \\\"/root/my-documents/Manna/%f\\\" '"$WORKDIR"'/note</action><action>echo true > /tmp/UPDATE_EDITOR</action><action>EXIT:exit</action></menuitem>\n" | sort`"
[ ! "$MENUITEMS" ] && MENUITEMS='<menuitem><label>"no files found"</label></menuitem>'
echo '
<window decorated="false" skip_taskbar_hint="true" resizable="false" height-request="50" width-request="240" modal="true">
 <hbox scrollable="true" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  <text width-request="1" space-expand="false" space-fill="false"><label>""</label></text>
  <vbox spacing="2">
   <text height-request="2" space-expand="false" space-fill="false"><label>""</label></text>
   <hbox height-request="22" spacing="2">
	<pixmap height-request="20" icon_size="1" space-expand="false" space-fill="false"><input file stock="gtk-open"></input></pixmap>
    <entry>
     <variable>ITEM</variable>
     <input>ls '"$NOTES_DIR"'</input>
     <action signal="activate">ln -f "/root/my-documents/Manna/$ITEM" '"$WORKDIR"'/note</action>
     <action>echo true > /tmp/UPDATE_EDITOR</action><action>echo true > /tmp/UPDATE_EDITOR</action>
     <action signal="activate">EXIT:exit</action>
    </entry>
    <menubar>
     <menu>
     '"$MENUITEMS"'
     <label>..</label>
     </menu>
    </menubar>
   </hbox>
  </vbox>
 </hbox>
 <action signal="focus-out-event">EXIT:exit</action>
</window>' | gtkdialog -s -G +"$(($PTR_X_ROOT-5))"+"$(($PTR_Y_ROOT-5))" > /dev/null
}

export -f add_note show_menu

#About dlg...
echo '#!/bin/sh' > /tmp/Editor-help
echo 'export EDITORHELP_DIALOG="
<window title=\"About\" icon-name=\"Com\" resizable=\"false\">
 <vbox>
 <notebook labels=\"About|License|Translations\">
 <vbox>
  <text height-request=\"2\"><label>\" \"</label></text>
  <pixmap><input file>/usr/local/Manna/icons/Com.png</input></pixmap>
  <text height-request=\"2\"><label>\" \"</label></text>
  <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor 2.2</span></b>\"</label></text>
  <text><label>\"    This is a basic text Editor for making notes or Teachings
    and can be exported to Abiword. The user interface
    supports the display of text in multiple font sizes for
    general viewing comfort.
   \"</label></text>

  <text><label>\"Copyright © 2013 GPL
  \"</label></text>
</vbox>
 <vbox>
 <text height-request=\"8\"><label>\" \"</label></text>
 <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor</span></b>\"</label></text>
  <text use-markup=\"true\"><label>\"Is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
   <text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b><span color='"'red'"'>WITHOUT ANY WARRANTY</span></b>. See the GNU General Public License homepage for more details.\"</label></text>
    <hbox>
     <button>
      <label>\"http://www.gnu.org/licenses/\"</label>
      <action>defaultbrowser http:\/\/www.gnu.org\/licenses\/</action>
     </button>
    </hbox>
    </vbox>
   <vbox>
   <text height-request=\"8\"><label>\" \"</label></text>
   <text><label>\" German \"</label></text>
   <text><label>\" Spanish \"</label></text>
   </vbox>
  </notebook>
   <hbox homogeneous=\"true\">
     <button height-request=\"35\" width-request=\"100\">
      <label>\"Close\"</label>
     <input file stock=\"gtk-close\"></input>
     <action type=\"exit\">quit_now</action>
     </button>
   </hbox>
 </vbox>
</window>"
gtkdialog --center --program=EDITORHELP_DIALOG' >> /tmp/Editor-help
chmod 777 /tmp/Editor-help

export ADD_FILE='
  <window title="'$( gettext "Add Note")'" modal="true" icon-name="gtk-add" resizable="false">
    <vbox>
      <frame "'$(gettext "Note name:")'">
        <entry>
          <variable>NOTENAME</variable>
        </entry>
        <hbox>
          <button ok>
            <action>add_note</action>
            <action>clear:ITEM</action>
            <action>refresh:ITEM</action>
            <action type="closewindow">NOTENAME</action>
          </button>
          <button cancel>
            <action type="closewindow">NOTENAME</action>
          </button>
        </hbox>
      </frame>
    </vbox>
  </window>
'

export DEL_FILE='
  <window title="'$(gettext "Del Note")'" modal="true" icon-name="gtk-remove" resizable="false">
    <vbox>
      <text><label>"'$(gettext "Are you sure you want to delete:")'"</label></text>
         <text><input>echo "$ITEM"</input></text>
      <hbox>
        <button ok>
          <variable>CONFIRM</variable>
          <action>rm "$NOTES_DIR"/"$ITEM"</action>
          <action>clear:ITEM</action>
          <action>refresh:ITEM</action>
          <action type="closewindow">CONFIRM</action>
        </button>
        <button cancel>
          <action type="closewindow">CONFIRM</action>
        </button>
      </hbox>
    </vbox>
  </window>
'



export MAIN_DIALOG='
<window title="'$(gettext "Manna Editor")'" icon-name="Com" resizable="false">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>launch:ADD_FILE</action>
</menuitem>
<menuitem stock-id="gtk-save">
<action>Save:EDITOR</action>
<action>Save:Saving</action>
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-refresh">
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-delete">
<action>launch:DEL_FILE</action>
</menuitem>
<menuitem stock-id="gtk-quit">
<action>exit:Quit</action>
</menuitem>
<label>"'$(gettext "_File")'"</label>
</menu>
<menu label="'$(gettext "_Edit")'" use-underline="true">
<menuitem stock-id="gtk-edit" label="'$(gettext "Send to Abiword")'">
      <action>defaultwordprocessor '"$WORKDIR"'/notes &</action>
     </menuitem>
</menu>
<menu 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>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE14_ICON' label="14">
      <action>echo "14" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE16_ICON' label="16">
      <action>echo "16" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE18_ICON' label="18">
      <action>echo "18" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
    </menu>
    <menu label="'$(gettext "_Help")'" use-underline="true">
     <menuitem stock-id="gtk-info" label="'$(gettext "Help")'">
      <action>defaultbrowser '$WORKDIR'/editor-docs/MannaEditorHelp.html &</action>
     </menuitem>
     <menuitem stock-id="gtk-info" label="'$(gettext "About")'">
      <action>/tmp/Editor-help &</action>
     </menuitem>
    </menu>
</menubar>

  <hbox>
   <edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="2">
     <variable>EDITOR</variable>
     <height>600</height>
     <width>780</width>
     <input file>'"$WORKDIR"'/note</input>
     <output file>'"$WORKDIR"'/note</output>
     <action signal="button-press-event">if [ $PTR_BTN -eq 3 ]; then show_menu; fi</action>
   </edit>
  </hbox>
  <checkbox visible="false" file-monitor="true" auto-refresh="true">
   <variable>UPDATE_EDITOR</variable>
   <input file>/tmp/UPDATE_EDITOR</input>
   <action>if true refresh:EDITOR</action>
   <action>if true echo false > /tmp/UPDATE_EDITOR</action>
   <action>if true refresh:UPDATE_EDITOR</action>
  </checkbox>

  </vbox>
 </frame>
<action signal="hide">exit:Exit</action>
</window>
'

MM1RET="`gtkdialog --program=MAIN_DIALOG`" 

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

#11 Post by oldyeller »

Hi zigbert,

This code is not the easiest to learn but will get there. Now the Del_FILE don't work. I guess when improving one thing somethings can break and than ones needs to fix that as well.

Never ending chance at learning :D :D

I was thinking of taking this out, But not sure as of yet.

Post Reply