Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 22 Aug 2014, 17:52
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How can I make the menubar work with the New button. Solved
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
oldyeller


Joined: 15 Nov 2011
Posts: 779
Location: Mishawaka IN

PostPosted: Sat 10 Nov 2012, 17:40    Post subject:  How can I make the menubar work with the New button. Solved
Subject description: solved
 

Hello Everyone,

I have done an editor for Manna, but I have no glue on how to make a new note/file with the New button in the file menubar. Not sure if I need another widget or not.

Any help would be great thanks.

code
Quote:


#!/bin/bash

GTKDIALOG=gtkdialog

WORKDIR="/usr/local/Manna"
NOTES_DIR="$WORKDIR/notestxt"


#define special Sans-12 font for Reader
CURRFONTNAME=`cat $HOME/.gtkrc-2.0 | grep font_name | cut -d "=" -f2 | cut -d " " -f2 | sed 's/\"//g'` ##define current user-font
if [ "`cat $HOME/.gtkrc-2.0 | grep font_name | grep Sans`" != "" ] && [ "$CURRFONTNAME" != "Sans" ]; then
FONT_NAME="$CURRFONTNAME"
else
FONT_NAME=""
fi
if [ -f "/usr/local/Manna/xresourcesmarker" ]; then #Iguleder derivatives
echo "Xft.dpi: 78" > $HOME/.Xresources
FONT_SIZE="12"
else
FONT_SIZE="16"
fi
echo "style \"specialsize\"
{
font_name=\"$FONT_NAME Sans $FONT_SIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"


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



export TMPDIR=/tmp/notes
mkdir -p "$TMPDIR"

echo "$TMPDIR"/notes



export MAIN_DIALOG='
<window title="Notes" icon-name="Com">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>new: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-quit">
<action>exit:Quit</action>
</menuitem>
<label>"_File"</label>
</menu>
<menu label="_Edit" use-underline="true">
<menuitem stock-id="gtk-file" label="Send to Abiword">
<action>abiword '"$TMPDIR"'/notes &</action>
</menuitem>
</menu>
</menubar>
</vbox>


<hbox>
<vbox width-request="140">
<table>
<label>Notes</label>
<variable>ITEM</variable>
<input>'"$WORKDIR/gtkrc_size:${HOME}/.gtkrc-2.0"'</input>
<input>ls '"$NOTES_DIR"'</input>
<action>ln -sf "/usr/local/Manna/notestxt/$ITEM" '"$TMPDIR"'/notes</action>
<action>refresh:EDITOR</action>
</table>
</vbox>


<edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="1">
<variable>EDITOR</variable>
<height>450</height>
<width>500</width>
<input file>'"$TMPDIR"'/notes</input>
<output file>'"$TMPDIR"'/notes</output>
</edit>

</hbox>
</frame>
</window>
'

case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --center --program=MAIN_DIALOG ;;
esac

Last edited by oldyeller on Sun 11 Nov 2012, 15:38; edited 1 time in total
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1053

PostPosted: Sat 10 Nov 2012, 19:38    Post subject:  

Hey Oldyeller.

First of all - that's great you've found the way to control the font in Gtkdialog GUI.
I didn't know how to do it until now, thanks! Smile

As for adding a new note, here's an example (perhaps there are better methods, but I always use something like this).
I made it "stand-alone" for clarity, but I'm sure you can adapt it to your reader easily:

Code:
#! /bin/bash

export NOTES_DIR="/root/testdir"

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

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

export MAIN='
<window width-request="500" height-request="500">
  <vbox>
      <table>
        <variable>NOTES_LIST</variable>
        <input>ls '"$NOTES_DIR"'</input>
      </table>
    <button>
      <label>Create new note</label>
      <action>launch:ADD_FILE</action>
    </button>
  </vbox>
</window>
'

gtkdialog -p MAIN

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 779
Location: Mishawaka IN

PostPosted: Sun 11 Nov 2012, 00:05    Post subject:  

Hi SFR,

As far as the font goes all I did was go through a program that had it and took what I needed for my reader and editor. Works great, except one has to edit the file for a different size.

This works great.

Added refresh for the Table ITEM and the new notes show up when the refresh button is pressed.

So is there a way to delete a note if one no longer wants one?

This is so closer of being a basic word editor for my notes Very Happy Very Happy

Cheers
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1053

PostPosted: Sun 11 Nov 2012, 06:33    Post subject:  

oldyeller wrote:
So is there a way to delete a note if one no longer wants one?

This is so closer of being a basic word editor for my notes Very Happy Very Happy

Sure it is, even easier:

Code:
#! /bin/bash

export NOTES_DIR="/root/testdir"

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

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

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

export MAIN='
<window width-request="500" height-request="500">
  <vbox>
    <table>
      <variable>NOTES_LIST</variable>
      <input>ls '"$NOTES_DIR"'</input>
    </table>
    <hbox>
      <button>
        <label>Create new note</label>
        <action>launch:ADD_FILE</action>
      </button>
      <button>
        <label>Delete note</label>
        <action>launch:DEL_FILE</action>
      </button>
    </hbox>
  </vbox>
</window>
'

gtkdialog -p MAIN

You can rename a note too, just need to be checked if the new note name already exists (like in 'add_note' func).

Keep it up & Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 779
Location: Mishawaka IN

PostPosted: Sun 11 Nov 2012, 15:10    Post subject:  

Hi SFR,

This works great!!!

Thanks for all your help so far; may need more later Laughing Laughing

I keep it as stand alone and just have it in as addnotes script.

works great

Cheers
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0772s ][ Queries: 12 (0.0041s) ][ GZIP on ]