Reader-how to code it right? Solved

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

Reader-how to code it right? Solved

#1 Post by oldyeller »

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.
#!/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.
Attachments
reader.png
(8.34 KiB) Downloaded 551 times
Last edited by oldyeller on Sat 10 Nov 2012, 18:15, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

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.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

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

#3 Post by oldyeller »

Hi musher0,

I am building this with gtkdialog for my next release of Manna OS.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post by SFR »

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: Select all

#!/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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#5 Post by oldyeller »

Hello SFR,

That works just fine thanks. OK once again what does it all mean in english;
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.
Last edited by oldyeller on Sat 03 Nov 2012, 21:46, edited 1 time in total.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#6 Post by SFR »

oldyeller wrote:Hello SFR,

That works just fine thanks. OK once again what does it all mean in english;
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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#7 Post by oldyeller »

Hi. SFR

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


Cheers

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#8 Post by SFR »

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: Select all

#!/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
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. :)

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#9 Post by oldyeller »

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

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#10 Post by SFR »

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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#11 Post by oldyeller »

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

Cheers

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#12 Post by SFR »

Let's take from my previous example:
...
<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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#13 Post by oldyeller »

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?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#14 Post by SFR »

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: Select all

#!/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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#15 Post by RSH »

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: Select all

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
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

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

#16 Post by oldyeller »

@ SFR,

The table widget worked out just fine as well as the radiobutton did thanks.

@ RSH,

I will give it a try, thanks

Cheers

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

#17 Post by oldyeller »

@ RSH,

Did try this out, but it was a no joy for me. Probably did not do it right.


Cheers

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#18 Post by RSH »

oldyeller wrote:@ RSH,

Did try this out, but it was a no joy for me. Probably did not do it right.


Cheers
Would you please send me your work? Maybe I can do something?

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

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

#19 Post by oldyeller »

RSH wrote:
oldyeller wrote:@ RSH,

Did try this out, but it was a no joy for me. Probably did not do it right.


Cheers
Would you please send me your work? Maybe I can do something?

RSH
Will send you my project by PM

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#20 Post by RSH »

Hi oldyeller.

Would you please package it as a .pet package?

I do need this in a form as it would be installed. Also I do need explanation of the files (what they do or shall do later) and at least one or two links to the applications that are used by your apps.

Thanks
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

Post Reply