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 31 Oct 2014, 04:36
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Documents
Simple GtkDialog editor and notetaker
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
svanya

Joined: 29 Sep 2014
Posts: 1

PostPosted: Mon 29 Sep 2014, 01:19    Post_subject:  Simple GtkDialog editor and notetaker
Sub_title: Simple editor to make quick note files
 

I needed a simple note editor, as I am a poet and do not need rich text, just something I can make quick and rapid poems with.

I had been using:
Code:

#!/bin/sh
#$1
NOTE=""
filename=$(basename "$@")

RESULTS=`Xdialog --fixed-font --wrap --left --stdout --title "$filename" --editbox "$@" 600x600`
EXIT_CODE=$?
EXISTS="FALSE"
ID=""
case $EXIT_CODE in
    0) # All OK. The $RESULTS variable holds everything entered/choosed by the user.
      NOTE="$RESULTS"

   RESULTS2=`Xdialog --stdout --fselect "$@" 480x520`
   EXIT_CODE2=$?
   case $EXIT_CODE2 in
      0)

   echo "$NOTE" > "$RESULTS2"
   esac
      
esac

exit 0


But was having to make allowances for it not wrapping and having to be religious about click OK every time so I did not miss a note.

So I decided today to upgrade to GTKDialog and made the following.

Be forewarned it is still in the experimental stages, and I think higher minds such as many in this community could clean it up very quickly to prevent overwriting files and accidentily failing to save.

Code:

#!/bin/sh

export currentfile="$@"

FILE1=$(cat "$@")
NOTE=""
filename=$(basename "$@")
FIL1=$(echo $FILE1)

confirm_function(){
      Xdialog --title "Are you sure you want to save?" --backtitle "Yes or No?" --yesno "Yes to continue and No to cancel" 0 0
      value=$?
      echo "the result is: $value"
      if [ "$value" = 0 ];
      then
         if [ "$INPUTFILE" = "" ];
         then
            echo "$EDITOR1" > "$currentfile"
         else
            echo "$EDITOR1" > "$INPUTFILE"
         fi
      else
         echo "Save cancelled"
      fi
}
export -f confirm_function

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
   <vbox>
      <hbox>
         <edit wrap-mode="3" use-markup="true" accepts-tab="true">
            <label>LEFT</label>
            <variable>EDITOR1</variable>
            <height>600</height>
            <width>600</width>
            <input file>'"$currentfile"'</input>
         </edit>
      </hbox>
      <vbox>
         <button use-stock="true" label="gtk-close"></button>
         <button use-stock="true" label="gtk-save">
            <action>confirm_function</action>
         </button>
         <hbox width-request="350">
              <entry accept="file">   
                 <variable>INPUTFILE</variable>
              </entry>
              <button tooltip-text="Select a file for saving">   
                 <input file stock="gtk-open"></input>
                 <action type="fileselect">INPUTFILE</action>
                 <action>confirm_function</action>
             </button>
         </hbox>
      </vbox>
   </vbox>
</window>
'
export MAIN_DIALOG

$GTKDIALOG --program=MAIN_DIALOG



You then just drop a link into /usr/local/bin and you set the Customize Menu to open any text file script or otherwise very very quickly.

Hope it helps someone.

The first incarnation has done wonders for me when I just needed to have a running clipboard, thrash off some ideas, and even more frequently work on shell scripts.

And I am hoping this second will do so, too.

Ciao all! Thanks for being such a great community.

Also, to create new notes (from a second script), in the same fashion (/usr/local/bin)

you change the first

Code:

export currentfile="$@"


to

Code:

seed=$(date +%Y%m%d%H%M%S)
touch /tmp/"newnoteeditorGTK""$seed"

export currentfile=/tmp/"newnoteeditorGTK""$seed"
Back to top
View user's profile Send_private_message 
dejan555


Joined: 30 Nov 2008
Posts: 2704
Location: Montenegro

PostPosted: Mon 29 Sep 2014, 04:04    Post_subject:  

Interesting, I'll have a look at this when I get time.
I did a little app for myself for taking notes/links/contacts maybe I should share it.

_________________


Back to top
View user's profile Send_private_message Visit_website MSNM 
dejan555


Joined: 30 Nov 2008
Posts: 2704
Location: Montenegro

PostPosted: Mon 29 Sep 2014, 17:16    Post_subject:  

Here's my simple version, if a file isn't specified, or given a name on command line, it creates new file with a $seed timestamp like you posted in a directory specified as $NOTESDIR and uses that to save to.

Code:
#!/bin/sh

export NOTESDIR="$HOME/gtknoteeditor"
[ ! -d "$NOTESDIR" ] && mkdir -p "$NOTESDIR"

if [ "$1" = "" ];then
   seed=$(date +%Y%m%d%H%M%S)
   touch "$NOTESDIR/$seed"
   EDITFILE="$NOTESDIR/$seed"
else
   EDITFILE="$1"
   [ ! -f "$EDITFILE" ] && touch "$EDITFILE"
fi
FNAME=$(basename "$EDITFILE")

export NOTE_EDIT='<window title="Note Editor - '"$FNAME"'" width-request="600" height-request="600"><vbox>
<edit wrap-mode="3" use-markup="true" accepts-tab="true">
<variable>NOTE</variable>
<input file>'"$EDITFILE"'</input>
</edit>
<hbox>
<button><label>"Open dir"</label><input file stock="gtk-open"></input>
<action>exec rox "$NOTESDIR"</action>
</button>
<button><label>"Save & Exit"</label><input file stock="gtk-save"></input>
<action>echo "$NOTE" > '"$EDITFILE"'</action>
<action>exit:Save</action>
</button>
<button cancel></button></hbox>
</vbox></window>'

gtkdialog --program=NOTE_EDIT --center


EDIT: Also, see this app:
http://www.murga-linux.com/puppy/viewtopic.php?t=95878

_________________


Back to top
View user's profile Send_private_message Visit_website MSNM 
oldyeller


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

PostPosted: Tue 30 Sep 2014, 15:18    Post_subject:  

Hi svanya,

Download this editor and look at the code and take out what will work for you and let me know how things go. http://www.murga-linux.com/puppy/viewtopic.php?t=85573

Cheers
Back to top
View user's profile Send_private_message 
slavvo67

Joined: 12 Oct 2012
Posts: 445
Location: The other Mr. 305

PostPosted: Tue 14 Oct 2014, 22:55    Post_subject:  

Hi guys:

The problem with the saved item is that when you go to open it, it defaults to Geany or whatever your default text editor is.

Oldyeller is probably right. He's spent a lot of time on his Manna product so if he's offering some code, it's probably a great base to work off of.

Best,

Slavvo67
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Documents
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0705s ][ Queries: 11 (0.0070s) ][ GZIP on ]