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 Sun 21 Jul 2019, 17:14
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Building MMview, a universal file viewer
Post new topic   Reply to topic View previous topic :: View next topic
Page 18 of 19 [274 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19 Next
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Wed 31 Oct 2018, 10:42    Post subject:  

Update 2018-11-01 (see also initial post)

This update emulates the "Open With..." menu of ROX-Filer, aka Right-click options. Actually it's Shift+RightClick.

In MMview the "Open With... " menu item can be selected from the"File" menu or with the mouse by middle-clicking a file in the tree list (right-clicking would not be an option as it can't be configured).

By default MMview searches applications in directory /root/.config/rox.sourceforge.net/SendTo.
This is the same directory from which ROX-Filer constructs its Shift+RightClick menu.
As in ROX-Filer this menu is MIME type sensitive and - if properly maintained ! - only offers applications for the specific MIME type of a selected file. The menu is devided into up to 3 MIME type sections (see screenshot).

This makes it possible for a user to increase MMview's functionality while making it easier for me to keep MMview simple. The screenshot shows an example (of my private setup): Middle-clicking on a JPEG file provides as first item the option to rotate the image. Would be difficult to integrate such option in the normal MMview menu as it doesn't fit anywhere. As my script uses the tool jpegtran, which only works for JPEG files, such menu in MMview would have to be disabled for non-JPEG files. A lot of work. Here the "Open With... " menu comes to the rescue as the upper section is visible only when a JPEG file is selected.

Two differences between ROX-Filer and MMview:
- MMview uses Xdialog to keep the code small and efficient, resulting in a "frugal" look & feel ... no icons! Double-click instead of single-click to select an item.

- MMview tries to emulate ROX-Filer and I can't guarantee that it always succeeds. I haven't found problems so far but that doesn't mean much.

Have fun!
MMview_MiddleClick_menu.jpg
 Description   
 Filesize   96.74 KB
 Viewed   1092 Time(s)

MMview_MiddleClick_menu.jpg

Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Tue 09 Apr 2019, 07:47    Post subject:  

Update 2019-04-09 (see also initial post)

After covering plain text files, audio/video and - at great length - image files there is one category MMview doesn't yet support: the "raw" display of binary files. Starting with this update I'll add some tools which to my knowledge don't exist in Puppy and which will make the forensic analysis of binary "black boxes" easier.

I also experiment with a multifunctional button, allowing one button to perform up to 9 different actions.

Hexdump
This is the classic hexdump -C command, but with a twist: There are only 10 hex values in a row and the offsets at the left are displayed in decimal and not hexadecimal. Limiting a row to 10 values should make it easier to relate ASCIIs on the right to their hex values on the left. Offsets in dec instead of hex are much more useful when it comes to using commands like head and dd. They are also much easier to grasp. My brain doesn't like hex.

Since hexdumps can be huge, time consuming and can cause a temporary freeze, display in the viewer pane is limited to 10KB

Hexdump in Leafpad
Alternatively hexdump can be redirected to leafpad. This is done in the background and therefore does not disrupt MMview. *Theoretically* there is no size limit.

Hexview
I don't know if this name makes sense. It's a special hexdump format which I created to analyze corrupted text files. When an ASCII control character somehow finds its way into a text file, the MIME format turns to application/octet-stream and the file becomes unreadable (for a text editor). Finding this one toxic character with a normal hexdump is like searching for a needle in a haystack. With the hexview format this character becomes visible immediately. There are much more uses for this format, e.g. when analyzing content and format of binary wordprocessor formats like MS Word .doc files.

Note that this view is displayed with line wrapping by default.

Hexview in Leafpad
Same functionality as in "Hexdump in Leafpad"

Convert text string
Strictly speaking this is a tool and not a view option as it does not relate to the selected file, but it is created with hexdump and is immensely useful, so I put it here.

It can answer simple questions, e.g. what the last letter of MochiMoppel might be, or reveal that Oops is a 6-letter word or detect the components of ( ͡° ͜ʖ ͡°) ,rufwoof's lenny face. It is also possible to paste multiline text selections into the entry field and analyze line endings and whitespaces.

Multifunction button
Used with a 3-button mouse the HEX button can trigger 6 different actions (see tooltip). 9 would be possible and theoretically much more, but I figure that 9 is the practical limit for this feature. Which action is triggered is determined by the duration after which the mouse button is released. After 0.3 sec and up to 1 sec the press action is triggered (the 0.3 sec can be changed with the THRESHOLD variable).
I don't know if users find this useful. Needs a bit of practice. Anyway, all actions (except for the help display) are also accessible from the "View" menu.

Other changes
I deleted the "Preferences" menu and moved the only remaining item (Vertical layout) into the "View" menu.
binary_options.jpg
 Description   
 Filesize   180.4 KB
 Viewed   899 Time(s)

binary_options.jpg

Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Tue 14 May 2019, 23:13    Post subject:  

Tips & Tricks No.1

In the future I intend to throw in a couple of tips & tricks that I find noteworthy. I might also add some code snippets from my personal edition that will enhance the functionality but which I have no intention to add to the officially posted version.

Code folding
Someone kindly pointed me to the newest edition of Smokey's newsletter, which to my surprise contains a full code listing of MMview. Just for the record: I didn't write or suggested this contribution. I don't mind either.

1463 lines of code Shocked - this is heavy stuff for the readers and looks intimidating, even to me. Though I try my best to keep the code short I also like to keep everything in one file, which over time adds to quite an amount of bytes.

The trick to make this code digestible without losing one's sanity is code folding. In Geany it's Menu Document -> Fold All. This will shrink the whole stuff to just 47 lines and is the first thing I do whenever I open the script. It allows to examine/edit only the sections of interest. Code folding further applies to the case statements in functions view_instantly and view_on_demand. Code folding is achieved by surrounding the sections that should fold with curly braces.
mmview_folded.png
 Description   
 Filesize   72.45 KB
 Viewed   817 Time(s)

mmview_folded.png

Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15445
Location: Paradox Realm

PostPosted: Sat 18 May 2019, 06:28    Post subject:  

Outstanding GNU programming @MochiMoppel Very Happy

Many thanks Cool I will be studying the code ... and feeling inadequate Embarassed

Bravo. Well done. Idea

_________________
Raspberry Pi 4 to run Puppi
NEW BusterPup Beta - test now
Back to top
View user's profile Send private message Visit poster's website 
Leon

Joined: 22 Jun 2005
Posts: 259

PostPosted: Sat 18 May 2019, 14:47    Post subject:  

MochiMoppel wrote:
After covering plain text files, audio/video and - at great length - image files there is one category MMview doesn't yet support: the "raw" display of binary files. Starting with this update I'll add some tools which to my knowledge don't exist in Puppy and which will make the forensic analysis of binary "black boxes" easier.

I also experiment with a multifunctional button, allowing one button to perform up to 9 different actions.

Congratulation and thanks for MMview and thanks for improving it.

Using it in Quirky Beaver 8.7.1 is a pleasure.

I tried many viewers and in one particular case I found MMview really handy. Newer versions of Firefox browser offer an option to save a web page as a picture and that is often much longer than a single screen size. I found MMview is the best of all viewers that i tried when viewing web page contents saved in picture format. With a single left click inside the picture MMview properly maximizes it to a screen width and shows scrollbar when needed. With another single left click inside the picture MMview restores the picture to a previous size. When viewing a web page picture with MMview I sometimes forget that I’m not working with browser.

MochiMoppel wrote:
In the future I intend to throw in a couple of tips & tricks that I find noteworthy. I might also add some code snippets from my personal edition that will enhance the functionality but which I have no intention to add to the officially posted version.

From my experience with using MMview there is only one and only issue left to be solved to use it as default viewer and this is:

How to click a file name in Rox and pass it to MMview to open it?

Is there a trick to do that?
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Sun 19 May 2019, 22:13    Post subject:  

Lobster wrote:
I will be studying the code ...
Have fun! I'm sure you will find plenty of room for improvement. And thanks for the encouragement.

Leon wrote:
From my experience with using MMview there is only one and only issue left to be solved to use it as default viewer and this is:
How to click a file name in Rox and pass it to MMview to open it?
Is there a trick to do that?
I'm glad to hear that you like and actually use the script.
I don't quite agree that there is only one issue left Laughing

What you describe is not possible with the chooser widget. To be more precise: It would be possible to pass a filename to MMview and show the file content in the viewer, but it would not be possible to select the corresponding filename in the file list programmatically (a limitation of the chooser widget) . This would lead to an irritating status where the viewer content is not the content of the highlighted file in the list. If you are interested in such odd behavior I can provide the code but I don't think that I should implement it. It surely will be perceived as a bug.

My best advise is to keep MMview open and drag the filename from ROX-Filer to the MMview file list. This is the only way to have the chooser widget select a specific file (apart from manual selection). This also changes automatically to the relevant directory. I find this method pretty neat. Too bad that there is no other way to do that.
Back to top
View user's profile Send private message 
Leon

Joined: 22 Jun 2005
Posts: 259

PostPosted: Mon 20 May 2019, 09:40    Post subject:  

MochiMoppel wrote:
What you describe is not possible with the chooser widget. To be more precise: It would be possible to pass a filename to MMview and show the file content in the viewer, but it would not be possible to select the corresponding filename in the file list programmatically (a limitation of the chooser widget) . This would lead to an irritating status where the viewer content is not the content of the highlighted file in the list. If you are interested in such odd behavior I can provide the code but I don't think that I should implement it. It surely will be perceived as a bug.

My best advise is to keep MMview open and drag the filename from ROX-Filer to the MMview file list. This is the only way to have the chooser widget select a specific file (apart from manual selection). This also changes automatically to the relevant directory. I find this method pretty neat. Too bad that there is no other way to do that.
Thank you for the explanation and for the suggestion.

MochiMoppel wrote:
If you are interested in such odd behavior I can provide the code
Yes, I’m interested.
I could configure Rox right click to open two different versions of MMview. Idea

MochiMoppel wrote:
but I don't think that I should implement it. It surely will be perceived as a bug.
I agree. Very Happy
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Sat 25 May 2019, 06:15    Post subject:  

Leon wrote:
Yes, I’m interested.

Please check your mailbox.
Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 740

PostPosted: Sat 25 May 2019, 09:59    Post subject:  

I am not complaining nor fault-finding. This is only the off the cuff comments of a first time user of mmview.

I confess that I save web pages as html. At least 90% of the files on my system are .html.
It is perhaps logical that mmview shows an .html file in html code format, but unfortunately, most times I would want to see it in a browser.

The middle panel which has a fixed width is invariably too small for the file names. Mochi tries to overcome this by providing tool tips that display the full path. Commendable, but I'd much prefer resizable middle and right panels.

I have mmview.sh in /root/my-applications.bin. Just for the heck of it, I thought I'd allow emelfm2 to call it to display a text file. It did, but emelfm2 showed the following in its output pane.
Code:
 >mmview.sh "where_maffs_are (ordered).txt"  (16030)
sh: line 3: echo: write error: Broken pipe

Mochi, I'm just including this in case you think it is worth your while. No need to pursue on my behalf. A thought came to mind just now. Maybe emelfm2 needs mmview.sh %f. I'll check.

I'll continue to play with it intermittently. Thanks for the contribution.

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
tallboy


Joined: 21 Sep 2010
Posts: 1387
Location: Drøbak, Norway

PostPosted: Sat 25 May 2019, 10:42    Post subject:  

MochiMoppel, I now test the Dpup Stretch-7.5 RC4, which has mm-view in the menu. I like it very much! Could you please make room for an About menu item, or include some text elsewhere, showing which version is used?

BTW, I am aware of the date shown in the code and name.

_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Wed 05 Jun 2019, 05:51    Post subject:  

I'm very grateful for Leon's contribution because it pushed me to try again the seemingly impossible: to startup the chooser widget with a specific file and not just with a file's directory. Judging from my conversation with him it seems to work.

Well, I know that it does not always work, but even in cases where it doesn't work the result is better, at least not worse than the current situation.

The solution requires xdotool, a tool that I try to avoid because of its unreliability. Before implementing it into MMview I would appreciate if people try this out and report any bad effects or incompatibilities. Faster machines than mine or newer distribution may have a negative impact.

Basically there is only one line to add at the very end of the script:
    <action signal="delete-event">lastrites_cleanup save</action>
    <action signal="map-event">[[ -f "'$1'" && $(type -p xdotool) ]] && { F="'$1'"; F=${F##*/}; [[ ${#F} == $(printf "$F"|wc -c) ]] && D=12 || D=200; xdotool sleep .2 type --delay $D "$F" && xdotool key Escape F5 ;}&</action>
    </window>
How to test: Make above change, then create a ROX desktop icon for MMview and drag a file from a ROX-Filer window onto this icon. MMview should start as usual with the directory of the dropped file, but then the xdotool action kicks it. It uses the fact that typing the first letters of a filename opens a little search box at the bottom of the list and if the typed letters match a file the first matching file will be selected. The code lets xdotool do the typing. Typing the whole filename would - theoretically - match exactly the dropped file and MMview can display the contents of this file. This works pretty well if the filename contains only 7-bit ASCII characters (us-ascii), however when the name contains multibyte characters like Japanese or diacritics, xdotool tends to skip characters while typing. This can be fixed by increasing the delays between each typed character, but it is hard to predict how much delay is needed. Above code uses a delay of 200ms for filenames with multibyte characters and the default 12ms for ASCII characters. In my tests 200ms for Greek and Japanese characters were seldom enough but were sufficient for Slovene and French. Eventually any filename can be correctly typed given enough delay, but too much delay can stretch the patience of the user Wink .
I also added a small sleep of 0.2sec. When gtkdialog receives the "map-event" signal the dialog window is not yet displayed, so there is a danger that typing starts before the window is ready. Increasing the sleep may help to make typing more reliable.

No harm is done when xdotool is not installed. MMview will work as before. The line is processed only once at startup and only when a filename was passed. Has practically zero impact on performance.

If this change works reasonably well for most users I see very interesting implications. You can try this by changing line 1193 to
    <action>lastrites_save;exec "$APP_PATH" "$vCHOOSER" &</action>
Switching between vertical and horizontal layout (Menu > File > Vertical layout) requires a restart and currently it will take the user only to the same directory but not the same file. With the change MMview will "land" on the same file that was selected before the switch, and this nice effect will be possible for any other feature that requires a restart.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Tue 02 Jul 2019, 04:11    Post subject:  

Update 2019-07-02 (see also initial post)
Some small changes and fixes.

UTF-16 codepoints
"Convert text string" dialog now also generates each character's Unicode UTF-16 codepoint

Knowing a character's codepoint makes it possible to
1) find the name/meaning/pronunciation of this character and many more characteristics. Just input the codepoint in its usual notation U+nnnn into any internet search engine.
2) type the character on the keyboard. E.g. to produce the first letter in the screenshot type Ctrl+Shift+U223c

Note that a Unicode character's bytestring (e.g \xe2\x8b\x83) is also important because it makes it possible to
1) count a character's bytes
2) search/replace this character with command line tools like sed
3) print this character (e.g. using echo command: echo -e '\xe2\x8b\x83') even in older bash versions

File selection with xdotool
Explained in previous post. I didn't receive any complaints and take it as an indication that I can savely add it to the code.

Tooltip bug
Seems to be yet another bug in JWM2.3. The "tooltip" in text fullscreen mode is actually a gtkdialog window. I invented this "fake" tooltip because I found the normal tooltip too annoying as there would be no way to make it disappear in fullscreen mode. The window is supposed to close when it loses focus, e.g. when user clicks anywhere outside the tooltip, latest when the user right-clicks to leave fullscreen mode. In JWM 2.3 it doesn't and the tooltip stays on while in older versions and perhaps in other window managers it works correctly. As a workaround the tooltip now appears under the mouse pointer and does not rely anymore on the "focus-out-event" signal

Other changes
- Fixed an issue with junk metadata in raw images produced by Canon EOS 750D
- Last used directory and window size now always and "officially" saved on exit (was supposed to be saved only when user closed with Ctrl+Q or Quit button and worked this way in earlier versions. A bug caused the current "always save" behavior and I figured that some users may like it this way).
UTF-16_codepoints.png
 Description   
 Filesize   49.36 KB
 Viewed   293 Time(s)

UTF-16_codepoints.png

Back to top
View user's profile Send private message 
radky

Joined: 02 May 2010
Posts: 954

PostPosted: Sat 06 Jul 2019, 20:49    Post subject:  

Thanks for the update to MMview.

For your consideration, it seems recent Woof-CE builds have Busybox v1.30.1 and the usage syntax has changed for the 'timeout' utility -- i.e., the -t switch is no longer supported (replaced by the standalone numerical value for seconds).

BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.
Usage: timeout [-t SECS] [-s SIG] PROG ARGS
MMview line #230: MESSAGE=$(busybox timeout -t1 du -hs "$vCHOOSER")

BusyBox v1.30.1 (2019-04-24 21:49:26 UTC) multi-call binary.
Usage: timeout [-s SIG] SECS PROG ARGS
MMview line #230: MESSAGE=$(busybox timeout 1 du -hs "$vCHOOSER")

https://github.com/puppylinux-woof-CE/woof-CE/commit/bc891e5148ad5e3ba87a2e93ab94bb225a9415b8

Best Regards

_________________
PupMates
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5584
Location: Republic of Novo Zelande

PostPosted: Tue 09 Jul 2019, 05:21    Post subject:  

I just downloaded version 20190702.gz but seem unable to find how/where to activate "view hidden files".

I am pretty sure I have used it in previous versions (within "view" menu i thought) but cannot see it now.

Any tips please?

cheers!

EDIT : Sorry - ignore that request. I had not maximised the mmview window so had no whitespace within the file list to rightclick anywhere.

Confused

EDIT 2 : Actually - now that I have clicked "show hidden files" I now have no way to see any whitespace to turn "show hidden files" off.

Any way to include that option in the "View" menu?
no_whitespace_in_filepane.jpg
 Description   
 Filesize   57.27 KB
 Viewed   115 Time(s)

no_whitespace_in_filepane.jpg

Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Tue 09 Jul 2019, 06:17    Post subject:  

@radky: Oh boy. That has the potential to break every existing script using the timeout command. In almost all Puppies timeout is symlinked to busybox, requiring the now defunct -t option.
I'll adjust MMview to make it compatible with whatever busybox version is used:
Code:
[[ $(busybox timeout 2>&1)  = *-t* ]] && export TOPT=-t
.
.
MESSAGE=$(busybox timeout $TOPT 1 du -hs  "$vCHOOSER")


@greengeek: Why would you need whitespace? Just rightclick any item in the list.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 18 of 19 [274 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2447s ][ Queries: 12 (0.0572s) ][ GZIP on ]