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 Sat 25 Oct 2014, 04:57
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Reader-how to code it right? Solved
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Author Message
oldyeller


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

PostPosted: Sat 03 Nov 2012, 16:48    Post_subject:  Reader-how to code it right? Solved  

Hello Everyone,


I have tried different ways on getting my text into the reader/editor. But am having trouble figuring it out. Here is the code that I have so far.

Quote:

#!/bin/bash

GTKDIALOG=gtkdialog

WORKDIR="/usr/local/Manna"
BOOKS_DIR="$WORKDIR/books"
ICONS_DIR="$WORKDIR/icons"
TEXT_DIR="$WORKDIR/text"
MATTHEW_DIR="$WORKDIR/matthewtxt"



export MAIN_DIALOG='
<window title="Matthew" icon-name="Com">
<frame Chapters>

<hbox>
<vbox width-request="40">
<radiobutton auto-refresh="true"><label>1</label><variable>EDITOR</variable><input file>'"$MATTHEW_DIR/chapter1"'</input></radiobutton>
<radiobutton auto-refresh="true"><label>2</label><variable>EDITOR</variable><input file>'"$MATTHEW_DIR/chapter2"'</input></radiobutton>
<radiobutton><label>3</label></radiobutton>
<radiobutton><label>4</label></radiobutton>
<radiobutton><label>5</label></radiobutton>
</vbox>
<edit editable="false" indent="25">
<variable>EDITOR</variable>
<height>300</height>
<width>530</width>
</edit>

</hbox>
<vbox>
<button ok></button>
</vbox>
</frame>
</window>
'

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


Also here is a picture of it as well. Any help would be great thanks.
reader.png
 Description   
 Filesize   8.34 KB
 Viewed   481 Time(s)

reader.png


Edited_time_total
Back to top
View user's profile Send_private_message 
musher0


Joined: 04 Jan 2009
Posts: 4257
Location: Gatineau (Qc), Canada

PostPosted: Sat 03 Nov 2012, 17:20    Post_subject:  

Hi, oldyeller.

The full less program (not the shrinked busybox version) is excellent as a *.txt reader (has bookmarks among many more features), but I gather from your image that you are talking about a non-CLI reader? Which one, please?

BFN.

_________________
"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send_private_message Visit_website 
oldyeller


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

PostPosted: Sat 03 Nov 2012, 17:27    Post_subject:  

Hi musher0,

I am building this with gtkdialog for my next release of Manna OS.
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 17:32    Post_subject:  

Hello again Oldyeller.

As far as I know when the GUI is already exported, there's no way to change <edit> widget's contents in some "nice" way. Wink
But nothing's impossible, here's my old workaround:

Code:
#!/bin/bash

# Make some two test files in /root named text1.txt and text2.txt

ln -sf /root/text1.txt /tmp/current_text    # to avoid empty window on the first run

export MAIN='
<window title="Edit Refresh Example">
  <frame Texts>

    <hbox>
      <vbox width-request="40">

        <radiobutton>
          <label>1</label>
          <action>ln -sf /root/text1.txt /tmp/current_text</action>
          <action>refresh:EDITOR</action>
        </radiobutton>

        <radiobutton>
          <label>2</label>
          <action>ln -sf /root/text2.txt /tmp/current_text</action>
          <action>refresh:EDITOR</action>
        </radiobutton>
      </vbox>
 
      <edit editable="false" indent="25">
        <variable>EDITOR</variable>
        <height>300</height>
        <width>530</width>
        <input file>/tmp/current_text</input>
      </edit>

    </hbox>
    <button ok></button>

  </frame>
</window>
 '

gtkdialog -p MAIN


It's enough to make new symlink and refresh EDITOR variable every time when user chooses a certain radiobutton.

I hope this is what you're looking for.

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: 812
Location: Mishawaka IN

PostPosted: Sat 03 Nov 2012, 17:39    Post_subject:  

Hello SFR,

That works just fine thanks. OK once again what does it all mean in english;
Quote:
ln -sf
So why is it important to have a file in the tmp dir? I was thinking about doing a file in tmp, But was not sure if it would be needed.
Edited_time_total
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 17:44    Post_subject:  

oldyeller wrote:
Hello SFR,

That works just fine thanks. OK once again what does it all mean in english;
Quote:
ln -sf

ln -s <- command to create a symbolic link to a file/folder, but
-f (force) argument lets you to overwrite the previously created symlink.
Without it you would have to delete old symlink before creating a new one.

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: 812
Location: Mishawaka IN

PostPosted: Sat 03 Nov 2012, 17:49    Post_subject:  

Hi. SFR

Maybe you can help with this as well. how can I export whats in the editor to geany or abiword?


Cheers
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 17:58    Post_subject:  

oldyeller wrote:
Maybe you can help with this as well. how can I export whats in the editor to geany or abiword?

Try this:
Code:
#!/bin/bash

export MAIN='
<window>
  <vbox>
    <edit>
      <variable>EDITOR</variable>
      <height>300</height>
      <width>530</width>
      <output file>/tmp/file_for_geany</output>
    </edit>
    <button>
      <label>Show in Geany</label>
      <action>save:EDITOR</action>
      <action>geany /tmp/file_for_geany</action>
    </button>
  </vbox>
</window>
 '

gtkdialog -p MAIN


Quote:
So why is it important to have a file in the tmp dir? I was thinking about doing a file in tmp, But was not sure if it would be needed.

It's not important really, you can put a symlink/file whereever you want; it's just a good practice to put temporary stuff there. Smile

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: 812
Location: Mishawaka IN

PostPosted: Sat 03 Nov 2012, 18:12    Post_subject:  

Will this save any changes to the original document? Lets say one want to highlight a word and have it for the next time for reading.

Cheers
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 18:32    Post_subject:  

I'm not sure if I get it...
No, not that type of changes.
If the <edit> widget is editable, both <input> and <output> directives point the same file and you'll use the "save" command then yes, this will modify currently opened doc.

But AFAIK "highlighting" isn't saved anywhere, no matter if one uses Gtkdialog's <edit> or Geany or Abiword...

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: 812
Location: Mishawaka IN

PostPosted: Sat 03 Nov 2012, 18:41    Post_subject:  

I know that I am asking a lot of questions. How do I use the save command and where does it go?

Cheers
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 19:00    Post_subject:  

Let's take from my previous example:

Quote:
...
<edit>
<variable>EDITOR</variable>
<output file>/tmp/file_for_geany</output>
</edit>

<button>
<label>Save</label>
<action>save:EDITOR</action>
</button>
...


Pressing the button makes that file (no matter if it exists at the moment, or not) that is wrapped by <output file></ouput> tags will be created/overwritten by contents of EDITOR variable (which is the text entered by user, in this example).

And how to use it? There's a lot of possibilities, I did bind it with <button>, but it can be triggered by different widgets too.

BTW, did you see that?
http://code.google.com/p/gtkdialog/w/list

It's a great reference of all Gtkdialog widgets.

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: 812
Location: Mishawaka IN

PostPosted: Sat 03 Nov 2012, 19:15    Post_subject:  

Hi SFR,

I did look at the site and tried some of it, that is what I started out with when I could not get things to work right.

Than I posted what I did and this is that thread.

Would I be able to do this with a directory ln -sd
would d be for directory?
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Sat 03 Nov 2012, 20:29    Post_subject:  

Nope, the taget file for <edit> must be a pure text file...

Anyway, play with this:
(but first create /root/testdir/ directory and copy a few text files there)

Code:
#!/bin/bash

export MAIN='
<window>
  <vbox>

    <table>
      <label>File name</label>
      <variable>ITEM</variable>
      <input>ls /root/testdir</input>
      <action>ln -sfT "/root/testdir/$ITEM" /tmp/tempfile_for_reading</action>
      <action>refresh:EDITOR</action>
    </table>

    <edit editable="false">
      <variable>EDITOR</variable>
      <height>300</height>
      <width>530</width>
      <input file>/tmp/tempfile_for_reading</input>
    </edit>

  </vbox>
</window>
 '

gtkdialog -p MAIN

<intput>ls /root/testdir</input> will display all filenames from /root/testdir as a table from which you can choose text file to be displayed.

BTW, I've noticed that if in /root/testdir are subdirectories and user will choose one of them instead of normal text file, symlink becomes somehow broken and stops working.
But -T parameter next to ln prevents that.

I have to go now - it's quite late, so good night &
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 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Sat 03 Nov 2012, 22:20    Post_subject:  

Hi Oldyeller.

I do use a feature (thanks to seaside for the xclip tip) in LazY ReCo, to save a highlighted url to a list that is read out by LazY FReD.

Code:
function AddRepoToList(){
   # Save to List
   xclip -o >> $serverlist
   echo "" >> $serverlist
   # Save to get the last saved list into a file read out by the gui
   xclip -o > /tmp/xclip_servername
   NEWSERVER=`cat /tmp/xclip_servername`
   # $NEWSERVER goes into the gui
   echo 'NEWSERVER="'$NEWSERVER'"' > $APPDIR/server_added
   rm /tmp/xclip_servername
}


Highlighted text usually goes automatically to the clipboard, so you don't need to press ctrl-c. If you have saved the highlighted text like shown above you could read out this file to get the last highlighted text.

Then need to search for the text at next start and jump to the line. It might give better results by using sentences or parts of them instead of words...

Just some thoughts...

RSH

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
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.0930s ][ Queries: 12 (0.0043s) ][ GZIP on ]