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 Thu 14 Dec 2017, 11:36
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Building a universal file viewer
Post new topic   Reply to topic View previous topic :: View next topic
Page 8 of 12 [172 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, 11, 12 Next
Author Message
perdido


Joined: 09 Dec 2013
Posts: 720
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Wed 12 Apr 2017, 10:13    Post subject:  

MochiMoppel wrote:


@perdido I'm not sure what you are after. The behavior you describe is normal and intended, but maybe not well understood and the "no subdirectories" message is irritating ( a not dereferenced symlink can't have subdirectories by definition). After lot of hair pulling I concluded that it would be best to avoid any ambiguities by treating links like empty directories: Just a hint that it's a symlink to <target> and no additional F1 info. And while I'm at it I will do the same for the /proc directory. Just a hint that it's a virtual file system. Avoids needless processing and delays for calculating useless information.


I was expecting too much, I understand now that the program will not display contents of a sym-linked directory in the right-side window.

Quote:
Regarding [Esc]: Plans? It's already implemented. The [Esc] key serves as the panic key for stopping autoplay and was introduced with Update 2017-02-04 ("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.")
.


Yes, I missed that. I was attempting to use [esc] to go backwards in the directory structure in the left-side window.

Thanks for taking the time to explain.

.

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


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Wed 12 Apr 2017, 20:30    Post subject:  

perdido wrote:
I was attempting to use [esc] to go backwards in the directory structure in the left-side window.

Keyboard: Backspace
Mouse: Use button in "path-bar" (that's the button row above the file list, allowing a kind of a bread crumb navigation)
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Sat 15 Apr 2017, 18:31    Post subject:  

It looks pretty good so far, only a few pointers. Feel free to ignore since constructive criticism wasn't solicited.

If you want really fast MIME type detection by extension only first and then by magic values at an offset, you can use my simple MIMEtype program, but for the small number of filetypes a case statement is fine as long as you put the "multiple-dot" extensions first (Example follows).
Code:
do_tgz_stuff(){
#template
}

do_gz_stuff(){
#template
}

case "$filename" in
  *.tar.gz|*.tar.gzip|*.tgz)do_tgz_stuff "$filename";;
  *.gz|*.gzip)do_gz_stuff "$filename";;
  #more here
esac

When case statements get really long it is helpful to put each in its own function. Humans tend to be able to take code in better if it fits on a single screen.


Here is another snippet that might be useful ... checks for the first match in a list of programs
Code:
set_handler(){
   #$1 is the name of the variable you want to set
   #after shift the remaining $@ are executables you want to check for
   var="$1"
   shift
   while ! type -p "$1" 2>&1 >/dev/null; do
      shift #not found so go to next candidate
   done
   #this sets the variable to the value
   eval $var=\"\$1\"
}
#example usage
#note that there is no $ when you pass Do_sh to the function
[ "$Do_sh" ] || set_handler Do_sh loksh dash  hush ash sh bash
echo "$Do_sh is set as the preferred handler for .sh files"


Also rather than hardcoding urxvt, bash etc, you can use $TERM and $SHELL ... or for a text editor $EDITOR and web browser $BROWSER

BTW, I just finished compiling mupdf on fatdog64 and it has the ability to view or convert .xps, .pdf, .epub, .cbz and a few other formats and output them to png, pnm, pgm, ppm, pam, tga, pbm, pkm, pdf, svg or cbz ... it even comes with builtin javascript engine that allows you to do quite a bit of manipulation to build documents, but for this thread, the output to png and svg are the most significant (convert the first page of a pdf to an image for display). If you leave out the ridiculously large fonts (it's a PITA to do), the build is around 2MB.

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Sun 16 Apr 2017, 00:39    Post subject:  

technosaurus wrote:
If you want really fast MIME type detection by extension only first and then by magic values at an offset, you can use my simple MIMEtype program
Thanks. Currently I'm content with the speed. I'm more concerned with the correctness but haven't seen serious problems so far.

Quote:
Also rather than hardcoding urxvt, bash etc, you can use $TERM and $SHELL ... or for a text editor $EDITOR and web browser $BROWSER
Yes, I can, but I shouldn't Laughing . Using these global variables (if that's what you mean and not locally assigned variables) I would end up in Slacko and maybe other Puppies with mp as $EDITOR and the (non existent) rxvt-unicode as $TERM. Even the global "Puppy variable" $DEFAULTTEXTEDITOR (in Slacko assigned to Geany) would be problematic since I can't be sure that the user hasn't changed his default editor after starting X. Hardcoding gives me control and avoids using programs the script is not designed for.

Quote:
for this thread, the output to png and svg are the most significant (convert the first page of a pdf to an image for display)
IIRC converting pdf to an image can be done relatively easy with command line tools already available in Puppy, but then the question comes up if this is really worth it. However where I see a real potential are formats for which no suitable program is installed. In such cases an image could be a helpful work around and would be better than viewing nothing at all.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Sun 16 Apr 2017, 01:39    Post subject:  

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

Some new functions and support for additional archive formats.

Line numbers
"Show line numbers" (shortcut F2) adds line numbers to text in the viewer pane. This feature in itself can be useful when viewing scripts etc., but beyond that it complements the new "Find again" feature (see below).

Refresh
For removing above line numbers the new "Refresh" feature (Shortcut F5) comes handy. So far the user had to select a different file, then reselect the current file to achieve a refresh/reset. F5 is common in browsers to reload a page, so it looks like a natural choice. The shortcut for "Execute selected file in console" had to move from F5 to Ctrl+F5 (which also better prevents accidental file execution).

Find
Frankly I never thought it would be possible to implement decent search capabilities in gtkdialog. Too many tools are missing, particularly a tool to highlight matching search results...no, Pango markup is not an option.

Finally I came up with a "Find" dialog (shortcut Ctrl+F), which allows 2 alternative display options, each of them with pros and cons, but both already much better than Total Commander's QuickView.

Extract matching lines
This is the default and very similar to Geany's brilliant "Find document usage" (In Geany select a word, press Ctrl+Shift+D and Geany will present a list with all lines containing this word). MMview diplays a similar list. It's not possible to jump to a specific line, but with F2 (show line numbers) it's possible to display all lines. F3 (Find again) returns to the extracted match lines. Particularly for large documents the F2 / F3 combo allows a fast review of search matches.

Use inline markers
All document lines remain displayed and matching search strings are marked with a fat unicode character. Not as good as the impossible highlighting, but not bad either. Here again the F2 / F3 combo comes handy. Hawk-eyed users will notice a ':' after numbers of matching lines and a '-' after numbers of not matching lines. That's the way grep shows results.

Find again
In most applications F3 is a shortcut for "Find next" and would jump to the next match within a document. Gtkdialog can't jump. "Find again" performs the search definded in the Find dialog, but not only for the current file. After selecting a different file F3 will perform the same search on the newly selected file. Again and again...until the user changes the pattern in the Find dialog.

A summary of the search is displayed in the status bar.

New archive formats
MMview now diplays contents of initrd.gz , .iso, .zip and .7z archives
MMview-Find.jpg
 Description   
 Filesize   105.51 KB
 Viewed   568 Time(s)

MMview-Find.jpg

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


Joined: 23 Oct 2006
Posts: 1442
Location: Ukraine

PostPosted: Sun 16 Apr 2017, 06:09    Post subject:  

Dear MochiMoppel,

Great work and thank you. How about including a self-contained icon in the script, e.g.:
Code:

ICONFILE="<""svg width='128' height='128' viewBox='0 0 216 112'>
<g transform='translate(0.0,112.0) scale(1.0,-1.0)'
fill='#000000' stroke='none'>
<path d='M90 104 c-31 -6 -61 -24 -86 -52 -1 -2 1 0 6 4 63 57 129 57 185 0 8
-9 15 -9 15 0 0 5 -1 6 -10 13 -36 28 -76 41 -110 35z'/>
<path d='M86 92 c-20 -4 -47 -17 -66 -33 -14 -12 -14 -12 3 0 14 9 41 23 45
23 1 0 -1 -3 -3 -7 -13 -27 9 -58 39 -56 27 2 44 32 32 56 -1 4 -3 7 -2 7 5 0
25 -15 33 -25 12 -13 9 -20 -13 -35 -37 -24 -88 -20 -133 8 -8 5 -7 4 1 -2 35
-25 76 -31 115 -19 15 5 33 15 36 20 3 3 4 3 8 -1 4 -4 8 -4 12 0 13 13 -28
52 -66 63 -7 2 -33 2 -41 1z m21 -21 c13 -7 9 -27 -6 -27 -16 0 -21 21 -7 27
6 3 8 2 13 0z m-30 -11 c4 0 5 0 5 -2 0 -2 0 -4 1 -5 1 -3 1 -3 -6 -6 -9 -4
-10 -3 -11 9 l0 6 3 -1 c2 0 6 0 8 -1z'/>
</g>
</svg>"

echo "$ICONFILE" > /tmp/mmview.svg
ICON="/tmp/mmview.svg"


and then adding this to the main gtkdialog:

Code:

export MAIN_DIALOG='
<window title="'${0##*/}'"allow-shrink="true" margin="'$WINDOW_MARGIN'" image-name="'$ICON'">


Just an idea.... Smile

With kind regards,
vovchik
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Tue 25 Apr 2017, 04:28    Post subject:  

vovchik wrote:
How about including a self-contained icon in the script
Good idea, though I must admit that icons are the last thing on my mind.
Your SVG is a bit problematic since it doesn't scale well to 16x16. For such small icons I prefer XPM. Simple format and full control over every pixel:
Code:
echo '/* XPM */
static char *mmview_xpm[] = {
"16 16 3 1",
"0 c None","1 c Black","2 c White",
"0000000101000000","0000000010000000","0000001111000000","0000112222110000",
"0011222222221100","0122222222222210","1222222222222221","1221112222111221",
"2212221221222122","1122222112222211","2122222112222212","2212221221222122",
"2221112222111222","2222222222222222","2222222222222222","2222222222112222",
};' > $TEMPDIR/mmview.xpm

ICON="$TEMPDIR/mmview.xpm"

Adding to MAIN_DIALOG would be the same as your code.

Edit 2017-4-28: Fixed transparent left-overs (value 0) in the last 6 rows
  
  

Last edited by MochiMoppel on Fri 28 Apr 2017, 04:47; edited 1 time in total
Back to top
View user's profile Send private message 
greengeek


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

PostPosted: Tue 25 Apr 2017, 05:28    Post subject:  

I can view the icon with viewnior but mtpaint seems unable to open it. Does Mtpaint open it for you? If so which version please?
cheers
mmview.jpg
 Description   
 Filesize   8.57 KB
 Viewed   390 Time(s)

mmview.jpg

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


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Tue 25 Apr 2017, 06:21    Post subject:  

greengeek wrote:
I can view the icon with viewnior
..but you shouldn't, now that you have MMview Laughing
Viewnior shows ugly artefacts, MMview does not.

Quote:
Does Mtpaint open it for you?
No.

Edit 2017-4-29: I see now that Viewnior makes invisible/transparent backgrounds visible by replacing them with a gray pattern, hence the "dirty" look. No way to disable this stupid behavior.
MMview-Viewnior.png
 Description   
 Filesize   19.69 KB
 Viewed   409 Time(s)

MMview-Viewnior.png


Last edited by MochiMoppel on Sat 29 Apr 2017, 10:36; edited 1 time in total
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1442
Location: Ukraine

PostPosted: Thu 27 Apr 2017, 06:03    Post subject:  

Dear MochiMoppel,

Your not so little app is really well done, and deserves its own icon - and I like to see something unique in the taskbar, so thanks. Smile

With kind regards,
vovchik
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8660
Location: qld

PostPosted: Thu 27 Apr 2017, 08:25    Post subject:  

SVG icon based on based on MochiMoppel's XPM version..

Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 16 16">
  <path d="m 1,16 0,-7 -1,0 0,-1.5 q 0,-3 4,-4 l 4,-1 4,1 q 4,1 4,4 l 0,8.5 z" style="fill:#fff"/>
  <path d="m 0.5,7.5 q 0,-3 4,-4 l 3.5,-1 3.5,1 q 4,1 4,4 m -8.5,-7 1,1 1,-1 m 1,15 2,0 m -12,-6 2,0 a 2.75,2.75 0 1 1 0,0.1 z m 14,0 a 2.75,2.75 0 1 0 0,0.1 z l 2,0" style="fill:none;stroke:#000;stroke-width;1"/>
</svg>


Note: should open in mtpaint (recent), gpicview, viewnior, firefox, seamonkey (other recent browsers that support SVG). Fails in inklite (as do many hand crafted SVG images).

greengeek - MochiMoppel's XPM opens in mtpaint for me with some minor hacking.

MochiMoppel - very nice script by the way. Smile

(edit: whoops, stray backslash crept in, probably fumbling fingers.)
mmv.png
 Description   
 Filesize   28.61 KB
 Viewed   320 Time(s)

mmv.png


_________________
Puppy Linux Blog - contact me for access

Last edited by 01micko on Fri 28 Apr 2017, 04:08; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
greengeek


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

PostPosted: Fri 28 Apr 2017, 03:37    Post subject:  

Based on micko's hack I can get an mtpaint readable xpm by modifying the xpm build as follows:
Code:
echo $'/* XPM */
static char *mmview_xpm[] = {
"16 16 3 1",
"0 c None",\n"1 c Black",\n"2 c White",
"0000000101000000",\n"0000000010000000",\n"0000001111000000",\n"0000112222110000",
"0011222222221100",\n"0122222222222210",\n"1222222222222221",\n"1221112222111221",
"2212221221222122",\n"1122222112222211",\n"0122222112222212",\n"0212221221222122",
"0221112222111222",\n"0222222222222222",\n"0222222222222222",\n"0222222222112222",
};' > /tmp/mmview.xpm

Makes me happier to have it compatible with mtpaint. Hope that doesn't conflict with mmview.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8660
Location: qld

PostPosted: Fri 28 Apr 2017, 04:03    Post subject:  

Further to our pm discussion @greengeek I reckon it's an mtpaint bug.

Try this (anyone) and the icon displays. (compile line in the comment).

Code:
#include <gtk/gtk.h>
/* compile with
 *  gcc `pkg-config --cflags --libs gtk+-2.0` mmvicon.c -o mmvicon */
 
static char *mmview_xpm[] = {
"16 16 3 1",
"0 c None","1 c Black","2 c White",
"0000000101000000","0000000010000000","0000001111000000","0000112222110000",
"0011222222221100","0122222222222210","1222222222222221","1221112222111221",
"2212221221222122","1122222112222211","0122222112222212","0212221221222122",
"0221112222111222","0222222222222222","0222222222222222","0222222222112222",
};

int main(int argc, char *argv[]) {
   
  GtkWidget *window;
  GtkWidget *image;
  GdkPixbuf *x_pixbuf;
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "Image");
  x_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)mmview_xpm);
  image = gtk_image_new_from_pixbuf(x_pixbuf);
 
  gtk_container_add(GTK_CONTAINER(window), image);

  g_signal_connect(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), NULL);

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}


Apologies for OT MochiMoppel.

_________________
Puppy Linux Blog - contact me for access
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1398
Location: Japan

PostPosted: Fri 28 Apr 2017, 05:35    Post subject:  

01micko wrote:
I reckon it's an mtpaint bug.
Well, it's not completely unreasonable. Mtpaint expects each declaration on a separate line. That's how XPMs are normally written. On the other hand I found nothing in the specification that mandates this format, and since I like it more compact and other apps have no problem with it I grouped multiple declarations on one line. Mtpaint will happily open it in the "classic" format. I didn't use Mtpaint for creating the file, so I didn't notice.

Thanks for the SVG. Creating relative paths by hand is not my cup of tea. Anyway, since I had to correct my XPM (some transparent pixels on bottom left edge. See edited post above) I also took the liberty to change the SVG. The first path should probably read
Code:
<path d="m 0,16 0,-7  0,0 0,-1.5 q 0,-3 4,-4 l 4,-1 4,1 q 4,1 4,4 l 0,8.5 z" style="fill:#fff"/>

I'll see if I can come up with a similar 48x48 SVG so that it can be used as a desktop icon as well.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8660
Location: qld

PostPosted: Fri 28 Apr 2017, 16:07    Post subject:  

MochiMoppel wrote:
01micko wrote:
I reckon it's an mtpaint bug.
Well, it's not completely unreasonable. Mtpaint expects each declaration on a separate line. That's how XPMs are normally written. On the other hand I found nothing in the specification that mandates this format, and since I like it more compact and other apps have no problem with it I grouped multiple declarations on one line.
Agree & agree.

MochiMoppel wrote:
Thanks for the SVG. Creating relative paths by hand is not my cup of tea.
You're welcome.

MochiMoppel wrote:
Anyway, since I had to correct my XPM (some transparent pixels on bottom left edge. See edited post above) I also took the liberty to change the SVG. The first path should probably read
Code:
<path d="m 0,16 0,-7  0,0 0,-1.5 q 0,-3 4,-4 l 4,-1 4,1 q 4,1 4,4 l 0,8.5 z" style="fill:#fff"/>

I'll see if I can come up with a similar 48x48 SVG so that it can be used as a desktop icon as well.
I thought the missing pixels were intentional and in my opinion added a bit of character, but hey it's all yours in the end.

Also, there is absolutely no need to re-code the the svg for 48x48 (or any size for that matter). Just add height="48px" width="48px" to the header just before the viewBox. You'll see in the screen shot I also have a 500x500 version. Any larger and you can go into the T-shirt printing business. This is how the Puppy Icon Theme is built.

Later...

Hmm, I found a bug in my svg while scaling large with this script:
Code:
#!/bin/sh

[ -z "$1" ] && echo "you must specify at least 1 size!" && exit

TMP=${TMP:-/tmp/mmviewicon.html}

echo -e "<html>\n<head>\n<title>mmview icon demo</title>\n<head>\n<body bgcolor=\"#aaa\">" > $TMP

for size in "$@"
do
   cat >> $TMP << _EOF
<p>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="${size}px" width="${size}px" viewBox="0 0 16 16">
  <path d="m 0,16 0,-7  0,0 0,-1.5 q 0,-3 4,-4 l 4,-1 4,1 q 4,1 4,4 l 0,8.5 z"
   style="fill:#fff"/>
  <path d="m 0.5,7.5 q 0,-3 4,-4 l 3.5,-1 3.5,1 q 4,1 4,4 m -8.5,-7 1,1 1,-1
   m 1,15 2,0 m -12,-6 2,0 z m 2,0 a 2.75,2.75 0 1 1 0,0.01 z m 12,0 a 2.75,2.75 0 1 0 0,0.01 z
   l 2,0" style="fill:none;stroke:#000;stroke-width;1"/>
</svg>
${size} x ${size}</p>
_EOF
done

echo -e "</body>\n</html>" >> $TMP


It makes a demo web page.

Notice I've altered the svg path for the line.

The original is now changed to this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 16 16">
  <path d="m 0,16 0,-7  0,0 0,-1.5 q 0,-3 4,-4 l 4,-1 4,1 q 4,1 4,4 l 0,8.5 z" style="fill:#fff"/>
  <path d="m 0.5,7.5 q 0,-3 4,-4 l 3.5,-1 3.5,1 q 4,1 4,4 m -8.5,-7 1,1 1,-1 m 1,15 2,0 m -12,-6 2,0 z m 2,0 a 2.75,2.75 0 1 1 0,0.01 z m 12,0 a 2.75,2.75 0 1 0 0,0.01 z l 2,0" style="fill:none;stroke:#000;stroke-width;1"/>
</svg>
mmv2.png
 Description   
 Filesize   40.64 KB
 Viewed   193 Time(s)

mmv2.png


_________________
Puppy Linux Blog - contact me for access
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 8 of 12 [172 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, 11, 12 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.0913s ][ Queries: 14 (0.0096s) ][ GZIP on ]