Building MMview, a universal file viewer

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#21 Post by MochiMoppel »

It solves the mystery. Doesn't match your earlier explanation ("when you click a button, say 'b'. Rox will select all files that has 'b' in it's name"). Your code shows that Fatdog has an additional menu entry Select > Reg Select... which can be accessed with shortcut '^' (aka asciicircum). This will open the Reg Select box. I don't know what you mean by "click a button b".
It is very different from the "jump to file" functionality and is very similar to Select > Select by name... , a standard feature in ROX. If you like you can assign the same '^' shortcut to it and it should give you exactly the same result. You only have to go to the trouble and type *bu* instead of bu.

drunkjedi, I think we should not follow up on this any more. At least I get the idea what makes Fatdog fat :lol:

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#22 Post by step »

@drunkjedi, Fatdog-710 ships with two ROX filer versions, the "legacy" version, and the enhanced "jun7" ROX filer. Enhanced "jun7" is set as system default. You can switch to the "legacy" ROX version this way:
1. Add this line to /root/.fatdog/defaultprograms

Code: Select all

  DEF_ROX="/usr/local/apps/ROX-Filer/AppRun"
2. Restart X or reboot.

This change is permanent until you revert /root/.fatdog/defaultprograms and reboot.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#23 Post by MochiMoppel »

Update 2017-02-04 (see also initial post)

Shift+Click opens file in editor
There is no elegant way to achieve this with gtkdialog but I tried to keep the code simple. It now functions (almost) the same as in ROX-Filer.

ID3 metadata (MP3 tags)
This requires ffprobe and displays the ffprobe output in the viewer pane. The output normally looks jagged with a proportional font. I tinkered with a combination of wide unicode spaces and most of the metada now line up vertically. May not work with all Puppies.

Autoplay
This requires ffplay and plays audio tracks in the background. This is largely functional but not yet final. Regard it as experimental. It is disabled by default. To hear this in action change the AUTOPLAY variable at the beginning to '1'.
To stop the audio: Press ESC key or change to non-audio file or close the window or dbl-click the file, which will stop ffplay and start to play the file in the default player.
Audio keeps playing when the user selects a different directory with the path-bar (that's the button row at the top). Look at it as feature: The music doesn't stop until the user selects a new song :lol:
Attachments
mm_quickview.png
QuickView has no problems with Japanese MP3 tags. MPlayer failed.
(86.28 KiB) Downloaded 907 times

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#24 Post by slavvo67 »

Interesting. The auto-play seems to work okay on MP3's and also seems to play the audio of MP4 files.

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#25 Post by dejan555 »

I see how this can be usefull, nice script. I might add some stuff. Works on dpup 487, I don't have the "pkill" command here though.
For bigger images maybe adding scrollbars for start? This could be solved with some external programs which would check for image dimensions first but it's a lot to require just for a little script. ffplay is ok since it comes with a lot of puppies I think but there isn't really some light and common app that would do it for images too. Does someone know if new mtpaint cmd feature can print image dimensions?

EDIT: Also scale could be a user-set variable, because if you turn it "off" you can just set width/height variable to -1 and it will ignore scaling.
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#26 Post by some1 »

MochiMoppel:
Thanks for the fish
Well constructed,coded.

I can imagine a lot of add-ons,implemented in various ways

For various reasons it may not be convenient to stuff everything into one script.
So to please everyone I think that it would be nice - if you ALSO maintained and published a barebone/blueprint-script- somewhat like your original script.
Just a suggestion.Its your thread/baby.
----
I gleaned the original code,and it seem rather puppy-distro agnostic.
Needs:
1)A Bash that can do regex
2)A newish MIME-database - thats woofed,I guess
3)The usuak busybox,no busybox problem - i.e. pkill
4) GTKCHOOSER seems ok.Nice digging,implementation
5)32 or 64 MB is irrelevant

I gave the code a spin on an oldish puppy:
1)I could not access the proc-dir,because proc did not have a MIME-type.
Thats a distroimplementation thing.Your script just hang,polling.No sweat - that was not a normal,newish puppy.
2)More important:
Clicking a header in the TREEVIEW-part of CHOOSER - i.e. sorting the column- had the result that afterwards I was unable to make a selection,the script became unusable.
RESORT - and the script was back to normal.
CHOOSER is a composite widget involving the TREEVIEW-widget.
In TREEVIEW we have the possibility of setting header-clickable="false".
That possibility seem to have been lost in construction of the composite
widget.Check it out.
--
You wrote,that you thought,that bash has a 128Kb limit.
The constraint is MAX_ARG - which nowadays is big enough to handle everything in normal usage.Max-content-size in a bash-variable is rather unrestricted.
The closest culprit is GTK/GTKDIALOG - which have various memoryconstraints.Try to view a big-enough-file in the viewpane - and your scripts crashes gracefully.
Big files load very slowly into the viewpane.
So - to reduce stutter/avoid crashes implementing a test for filesize
could be relevant for some uses/users - but that overhead is probably not needed generally.
---
Level up for everyone.
Thanks.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#27 Post by some1 »

I once did what dejan555 indicated,but in a different context.

The codepieces below works in your original script.

EDIT: 8-2
Correcting some sloppyness:
1) we obviously need to export the MAXUNSCALED-vars
2) we dont need x=$(NF-2) y=$NF in the "image"-awk-code - so the cruft is deleted
---------


1. Globalvars - inject f.x after GEOMETRY

Code: Select all

PR_X=500
PR_Y=500
export MAXUNSCALED_X="400"
export MAXUNSCALED_Y="400"
2. Make 2 pixmaps -instead of 1

Code: Select all


		<pixmap width-request="'$PR_X'" height-request="'$PR_Y'">
		<variable>vPMAP</variable>
		<input file>'"$IMGELNK"'</input>
		<width>-1</width><height>-1</height>
		</pixmap>
		</vbox>
		
		
		 <vbox>
		<pixmap width-request="'$PR_X'" height-request="'$PR_Y'">
		<variable>vPMAP2</variable>
		<input file>'"$IMGELNK"'</input>
		<width>'$MAXUNSCALED_X'</width><height>'$MAXUNSCALED_X'</height>
		</pixmap>
3. Imagehandling - light
Inject this instead of the vanilla image-handling

Code: Select all

#imagehandling
    *│*image*|*'.xpm '*|*'.svg '*|*'.gif '*)
    nbpic=0
    
    case $vSTATUSBAR in
    *'.xpm '*) nbpic=1;;
    *'.svg '*) nbpic=2;;
    *'.gif '*)
		      ctl=`file -b "$vCHOOSER"|awk -v mw="$MAXUNSCALED_X" -v mh="$MAXUNSCALED_Y" '{if ($(NF-2)*$NF!=0){if ($(NF-2)<=mw&&$NF<=mh){z=1} else z=2;print z;}}'`
		      case $ctl in 
				 1) nbpic=1;;
				 2) nbpic=2;;
				 *) echo : ;;
				esac      
      ;;
      
	*│*image*)
		      ctl=`exiv2 -ps "$vCHOOSER"|awk -v mw="$MAXUNSCALED_X" -v mh="$MAXUNSCALED_Y" 'NR==4&&NF>3{if ($(NF-2)*$NF!=0){if ($(NF-2)<=mw&&$NF<=mh){z=1} else z=2;print z;}}'`
				 case $ctl in 
				 1) nbpic=1;;
				 2) nbpic=2;;
				 *) echo : ;;
				esac
    ;;
		
	esac

	echo $nbpic > $NB_PAGE
	ln -fsn  "$vCHOOSER"  $IMGELNK
	ln -fsn  /dev/null    $FILELNK
	
;;
##imagehandling 

Some comments:
1. The above handles the most common image types in puppy-land.
2. In the light-version I assume that the size of xpm's allways are below the limit- so scaling xpm´s is not considered.
"Likewise" svg¨s is assumed to allways need scaling.
This implies that - if we encounter svg-icons - they will be scaled.
3. In case mtpaint dont have "identify"-code we have to resort to other tools presumably present.
Exiv2 covers several images - especially png,jpgs matters.
The fallback for not covered imagetypes is _file_
However each imagetype needs a special parsing of the _file_.output.
Gifs are normally smallsized - but do exist on every puppy -
so I used it as an example of using _file_.

xpms - and especially svgs are NOT identical with respect to the
the parsing needed to fetch the metrics.We have to write our own parser -
if we want a more heavier version.
Bottomline:The codesize surges if we want to cover all image-types
with specific parsingcode.
4. My construct above is a bit heavy on cases - because I wanted to get rid of the repititive lnk-lines
5. *) echo : ;; is there because if we dont get valid metrics i.e nbpic=0 - we could let it pass,display a default-error-pic or whatever we fancy.Otherwise we dont need that case.
6. Awk is just a validator,parser to resolve the ctl-value.
Bash,shell-scripters may be tempted to inject vars directly in
awk-code - but in doing so we plague awk with speedbumps.
Use the -v switch.
----
----
----
We can get a lot of kicks out of MochiMoppels baby - but as I
indicated in the previous post we might want to restrain ourselves a bit:
Showing the listings of every packer with a list option may not allways be what we want

Inquiring minds may want this:

Code: Select all

    *x-exec*|*sharedlib*)
     strings "$vCHOOSER" >$MSGFILE && $(hexdump -C "$vCHOOSER" >>$MSGFILE)
     ln -fsn  "$MSGFILE"   $FILELNK
     ;;
      *x-shell*)
      ln -fsn  "$vCHOOSER"  $FILELNK
      
      ;;
NOTE: the x-exec..: first comes strings,then the hexcodes.
Last edited by some1 on Wed 08 Feb 2017, 03:57, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#28 Post by MochiMoppel »

One general remark: I started this project to learn more about chooser and if it can be used as a text viewer. This is something I haven't found in Puppy so far. To build an image viewer was the last thing on my mind. There are plenty already available. So yes, it's basic, but it is functional and a "real" viewer for large images is only a (double) click away. Even the text support is still basic. I could post more code for less common codesets but this would only bloat the script and would make it more and more difficult to understand how this all is intended to work. Here is my rough roadmap:
1) Broaden the functionality with simple (sample) code
2) Look out for bugs (they are real - I've seen them already)
3) Deepen functionality
4) Streamline, prettify and clean the code (this job will never end)
dejan555 wrote:For bigger images maybe adding scrollbars for start?
AFAIK pixmap doesn't support scrollbars
some1 wrote:it would be nice - if you ALSO maintained and published a barebone/blueprint-script- somewhat like your original script.
Let me think of it. I can't promise anything :lol:
some1 wrote:1)I could not access the proc-dir,because proc did not have a MIME-type.
I doubt that this is the reason. /proc is accessible sometimes, sometimes it is not. When it is not accessible I also can't open it with chooser's big brothers, e.g. the Open dialog in Geany. I figured that this has nothing to do with the script or gtkdialog. Well behaving users shouldn't have business in /proc anyway :wink:
some1 wrote:Clicking a header in the TREEVIEW-part of CHOOSER - i.e. sorting the column- had the result that afterwards I was unable to make a selection,the script became unusable.
I can't reproduce this. I would appreciate if you could find the root cause or at least a scenario that triggers this bug.
some1 wrote:Big files load very slowly into the viewpane. So - to reduce stutter/avoid crashes implementing a test for filesize could be relevant for some uses/users
How slow is "very slowly"? Are you talking about text files? I don't expect anyone to read novels in the viewer. Log files can be big, but even 3MB monsters pose no problems. I've tested with insane and unrealistic 10MB files, that's not really smooth anymore but not unbearable either. Image files can cause stutter, but then I would assume that the user switches to a dedicated viewer.

Thanks for your sample code. I will respond separately and will also add a "special barebone edition" which will contain your code - and my changes :lol:

belham2
Posts: 1715
Joined: Mon 15 Aug 2016, 22:47

#29 Post by belham2 »

MochiMoppel wrote:Update 2017-02-04 (see also initial post)

Shift+Click opens file in editor
There is no elegant way to achieve this with gtkdialog but I tried to keep the code simple. It now functions (almost) the same as in ROX-Filer.

mochi,

It may not be elegant to you, but I think it is great. It's simple, and yes, elegant to me to shift+click open in file editor :wink: Thanks!!

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#30 Post by dejan555 »

MochiMoppel wrote:
dejan555 wrote:For bigger images maybe adding scrollbars for start?
AFAIK pixmap doesn't support scrollbars
hmm, maybe not by itself, but after wraping it in hbox it's possible:

Code: Select all

<hbox scrollable="true" hscrollbar-policy="1" vscrollbar-policy="1">
                <pixmap...

...</pixmap></hbox>
But then it wouldn't show the center of image by default but top-left corner and you would need to scroll for the rest
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#31 Post by some1 »

MochiMoppel:
I just noticed,that I was too much in a hurry when I wrote and posted the code above.
See the Edit.
---
I have done some testing on vanilla Tahr and Slacko539 - both on 2 "puppy-machines" i.e. 500MB and 1 GB.
The result was as described previously.
I have no solutions -
except some user-rules based on my experience -
1) dont sort
2) dont go into /proc - basically we have no business there
3) avoid using the keyboard-arrows in dirs with big-files.
BIG-files will load slowly and if big enough crash the gui.
That goes for Geany too - so its mostly a matter of getting
accustomed to having a quickview,when travelling a filelist.
NORTON Commander -Remember that?
'------
I think your script is much more than the gui.
The integration/hookup with rox gives a lot of power/choice.
Nice project.

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#32 Post by dejan555 »

some1 wrote: 3) avoid using the keyboard-arrows in dirs with big-files.
BIG-files will load slowly and if big enough crash the gui.
Use head to load only x lines of text files for preview?
Like, top 100?
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

User avatar
peebee
Posts: 4370
Joined: Sun 21 Sep 2008, 12:31
Location: Worcestershire, UK
Contact:

#33 Post by peebee »

Nice initiative....

Doubling clicking an item with spaces in the file name gives errors.....

Replacing rox by defaultfilemanager (2 places) cures this problem (on LxPupSc-17.02.1 with pcmanfm)

Cheers!
peebee
ImageLxPup = Puppy + LXDE
Main version used daily: LxPupSc; Assembler of UPups, ScPup & ScPup64, LxPup, LxPupSc & LxPupSc64

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#34 Post by MochiMoppel »

dejan555 wrote:But then it wouldn't show the center of image by default but top-left corner and you would need to scroll for the rest
No, this is perfect! Thank you! Here is what I will use for the next update:

Code: Select all

<hbox scrollable="true" space-expand="true">
  <pixmap>
  ...
  </pixmap>
</hbox>
@some1
I tested your proposal and it worked. I only had to add a missing refresh:vPMAP2 and I deleted the width-request="'$PR_X'" height-request="'$PR_Y'" stuff because it causes the pixmap to "spill out" of its frame (you will understand what I mean when you resize the window).

The idea certainly is clever and probably the best tweak possible considering the limits of the pixmap widget, but weighing all pros and cons I find too many cons. My biggest objection is that the scaling is not dynamic (e.g as in Viewnior) and that it has not clue how big or small the viewer pane really is, so the code may scale down an image even when the viewer pane could easily accommodate the original size. Nevertheless other members might reach different conclusions. I attach a very barebone test script which will show your tweak in action. Maybe this could also serve as the barebone template you proposed.
3) avoid using the keyboard-arrows in dirs with big-files.
clicking on them is not any better :wink:

What you really should avoid is using the LEFT and RIGHT arrow keys. They let you switch between the leftmost Places pane and the main files list... if you are lucky.
Make a test:
  • 1) in QuickView go to /usr/local (just as an example) and press the close button
    2) Restart QuickView. You should now be in /usr/local again.
    3) Press the LEFT key
    The Search box opens. This makes it not only impossible to switch back to the file list, it's even worse: the list is gone. The user might not remember were he came from.
    4) Now click on left "File system" and go to /usr/local. Try LEFT key again. It will take you to "File system" in Places pane, not the Search box. That's the way it should be.
Somehow chooser needs a know how a file/folder in the main file list is related to the Places items. Chooser "remembers" this when the selection starts in Places but it can't make this connection when it is thrown right into a directory with the <default> tag.
Peebee wrote:Doubling clicking an item with spaces in the file name gives errors.....
*Which* errors? Spaces in file names shouldn't be a problem, but if you don't use rox then of course the script may not work properly.
Attachments
mm_quickview_imagescaling_test.gz
Remove fake gz extension
THIS IS A STRIPPED DOWN VERSION FOR THE SOLE PURPOSE TO TEST
IMAGE RELATED CODE. NO FURTHER UPDATES, NO BUG FIXES.
(4.52 KiB) Downloaded 375 times
Last edited by MochiMoppel on Fri 10 Feb 2017, 00:19, edited 1 time in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#35 Post by vovchik »

Dear MochiMoppel,

I just tried your latest. It's great for viewing and is even fast on my relatively slow machine. Great work and nice improvment. Thanks.

With kind regards,
vovchik

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#36 Post by smokey01 »

MM nice little script, works well. I have one concern though. Each time a file is touched the filename is bolded and the date of the file is changed to the current date. I like to keep the original dates on my photos and other files.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#37 Post by MochiMoppel »

smokey01 wrote:Each time a file is touched the filename is bolded
bothers me too..
and the date of the file is changed to the current date.
Well, only the "access" and "change" timestamps are changed, not the important "modified" timestamp. So far I regarded it more as a nuisance, to be fixed on a rainy day when everything else is fixed.

Now that you mentioned it I investigated and found the culprit. The behavior is caused in the fill_statusbar function by the -p option of the file command:
  • MIME=$(file --separator " │ " -ip "$vCHOOSER" 2>&1)
    if [[ "$MIME" = *│*x-symlink* ]];then
    echo -n $vCHOOSER " ➡" $(file --separator " │ " -ip "$(realpath "$vCHOOSER")" 2>&1)
I used this option because I thought it would preserve the existing file dates
The manual wrote:-p, --preserve-date        preserve access times on files
It obviously means that the time of access by the command is preserved with a new timestamp ... on files, not of files. Sorry, lost in translation. I will update the script.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#38 Post by greengeek »

Hi Mochi - I am using the latest version and wondered the following:

- is there any way to set it for single click rather than double click? If I single click on an image or text file it displays ok immediately but if I single click on a directory it does not open - requiring me to doubleclick. Is this related to rox settings? Is it possible for this behaviour to be modified (or modifiable) within mmviewer regardless of how rox is set?

- is it possible to set mmviewer so that it slightly alters the display format of text files so that they have a leading space in the display panel? Xml files display in a nice readable way because they tend to have plenty of leading spaces and tabs - but flat text files seem crammed up against the left margin of the viewer and are harder to read for someone like me who suffers from astigmatism.

cheers!

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#39 Post by MochiMoppel »

greengeek wrote:- is there any way to set it for single click rather than double click?
No.
- is it possible to set mmviewer so that it slightly alters the display format of text files so that they have a leading space in the display panel?
I've now changed <edit> to <edit left-margin="0"> . Set a higher value to add margin.

User avatar
peebee
Posts: 4370
Joined: Sun 21 Sep 2008, 12:31
Location: Worcestershire, UK
Contact:

#40 Post by peebee »

MochiMoppel wrote:
Peebee wrote:Doubling clicking an item with spaces in the file name gives errors.....
*Which* errors? Spaces in file names shouldn't be a problem, but if you don't use rox then of course the script may not work properly.
If you could consider changing rox to defaultfilemanager then that would be appreciated - thanks.

I would like to include this facility in the next LxPupSc.....
Attachments
Screenshot.png
(121 KiB) Downloaded 496 times
ImageLxPup = Puppy + LXDE
Main version used daily: LxPupSc; Assembler of UPups, ScPup & ScPup64, LxPup, LxPupSc & LxPupSc64

Post Reply