| Author |
Message |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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.
| Description |
|
| Filesize |
8.34 KB |
| Viewed |
338 Time(s) |

|
Last edited by oldyeller on Sat 10 Nov 2012, 14:15; edited 1 time in total
|
|
Back to top
|
|
 |
musher0

Joined: 04 Jan 2009 Posts: 2209 Location: Gatineau (Qc), Canada
|
Posted: 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.
_________________
"...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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.
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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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;
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, 17:46; edited 1 time in total
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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;
|
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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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.
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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 471 Location: Mishawaka IN
|
Posted: 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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: 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
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
|