New picture_viewer.py plugin in devel

98 views
Skip to first unread message

Edward K. Ream

unread,
Oct 21, 2021, 10:42:16 PM10/21/21
to leo-editor
See PR #2280, which contains the docstring.

My copy of myLeoSettings.leo contains @command nodes for slide shows.  For example:

@command slides

from leo.plugins.picture_viewer import Slides
Slides().run(full_screen = True, sort_kind = 'random')

Enjoy.

Edward

Edward K. Ream

unread,
Oct 21, 2021, 10:46:20 PM10/21/21
to leo-editor
On Thursday, October 21, 2021 at 9:42:16 PM UTC-5 Edward K. Ream wrote:
See PR #2280, which contains the docstring.

Note: there is no need to enable this plugin. The plugin exists only to support scripts.

Edward

tbp1...@gmail.com

unread,
Oct 22, 2021, 9:13:31 AM10/22/21
to leo-editor
What are the slides?  Image files? HTML bullet files? 

Edward K. Ream

unread,
Oct 22, 2021, 10:50:49 AM10/22/21
to leo-editor
On Fri, Oct 22, 2021 at 8:13 AM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
What are the slides?  Image files? HTML bullet files? 

Good question. As the docstrings says, by default the viewer will display all .jpeg, .jpg, and .png files in the root directory and all subdirectory. The show_slide method creates each image like this:

    pixmap = QtGui.QPixmap(file_name)

so you can display any file for which this call works.

Edward

tbp1...@gmail.com

unread,
Oct 22, 2021, 11:44:59 AM10/22/21
to leo-editor
picture_viewer.py is in the plugins directory but not in LeoPyRef.

tbp1...@gmail.com

unread,
Oct 22, 2021, 11:59:16 AM10/22/21
to leo-editor
Maybe the docstring said that at one time but it doesn't now : ). It says this:

A plugin for displaying slides from a folder and its subfolders.
And this:
The following keyword arguments may be supplied to the run method:
...
extensions = ['.jpeg', '.jpg', '.png'],  # List of file extensions.

And I see from the PixMap docs that it can actually support some other formats.

You may think it's the same thing, but I suggest spelling out just what the viewer can do would be helpful.

Edward K. Ream

unread,
Oct 22, 2021, 3:11:19 PM10/22/21
to leo-editor
On Fri, Oct 22, 2021 at 10:45 AM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
picture_viewer.py is in the plugins directory but not in LeoPyRef.

Thanks for this report.  Rev 2693456 in devel adds the missing @file node.

Edward

Edward K. Ream

unread,
Oct 22, 2021, 3:12:23 PM10/22/21
to leo-editor
On Fri, Oct 22, 2021 at 10:59 AM tbp1...@gmail.com <tbp1...@gmail.com> wrote:

And I see from the PixMap docs that it can actually support some other formats.

You may think it's the same thing, but I suggest spelling out just what the viewer can do would be helpful.

Ah, the curse of knowledge.

Please suggest some new words for the docstring.  Thanks.

Edward

tbp1...@gmail.com

unread,
Oct 22, 2021, 9:34:19 PM10/22/21
to leo-editor
Here's my stab at it.  Replace all the current text in the docstring ahead of the binding and API information with the following:

Display image files in a directory tree as a slide show.

This plugin will display all files in a directory tree that have
image extensions.  By default the recognized extensions are
'.jpeg', '.jpg', and '.png'.  Other types of image files can be
displayed as long as the they are types known by the Qt PixMap 
class, including '.gif' and '.bmp'. See, for example:


This plugin should be called from a script (or @command or @button node) as follows:

    from leo.plugins.picture_viewer import Slides
    Slides().run()  # See below for defaults.

*Note*: do not enable this plugin. It will be loaded by the calling script.

tbp1...@gmail.com

unread,
Oct 22, 2021, 9:47:22 PM10/22/21
to leo-editor
This is very nice, and one of the nice things about it is how it automatically ignores non-image files without the user having to do anything.

A suggestion for better usability - after you zoom or shrink a slide, the new zoom factor should stay in effect for all other slides until you change it again.  Currently the new zoom factor is forgotten for the next slide - or even if you go back to one you already resized - and that's really annoying.

tbp1...@gmail.com

unread,
Oct 22, 2021, 11:52:22 PM10/22/21
to leo-editor
In get_files(), there is 

os.path.splitext(str(z))[1].lower() in self.extensions

I'm just wondering why it isn't g.os_path_splitext() instead.  Are these g.os_path_* commands being phased out? (Actually, I never understood why we have them at all but given that we do, why not use it here?)

Edward K. Ream

unread,
Oct 23, 2021, 1:23:52 AM10/23/21
to leo-editor
On Fri, Oct 22, 2021 at 10:52 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
In get_files(), there is 

os.path.splitext(str(z))[1].lower() in self.extensions

I'm just wondering why it isn't g.os_path_splitext() instead.  Are these g.os_path_* commands being phased out? (Actually, I never understood why we have them at all but given that we do, why not use it here?)

Good question. 

The g.os_path functions have a long history. Iirc, at one point they were an essential part of the wrappers that hid differences between python 2 and python 3.  Today, some of the g.os_path functions do more than the corresponding os.path methods.  The differences between the g.os_path functions and the corresponding os.path methods are subtle enough that it would be madness to contemplate removing the g.os_path functions.

But for most scripts using os.path methods directly is clearer. So that's what I do.

Edward

Edward K. Ream

unread,
Oct 23, 2021, 1:25:15 AM10/23/21
to leo-editor
On Fri, Oct 22, 2021 at 8:47 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
This is very nice, and one of the nice things about it is how it automatically ignores non-image files without the user having to do anything.

A suggestion for better usability - after you zoom or shrink a slide, the new zoom factor should stay in effect for all other slides until you change it again.  Currently the new zoom factor is forgotten for the next slide - or even if you go back to one you already resized - and that's really annoying.

This will have to be an option because I would hate your way :-)  I'll add the option next.

Edward

Edward K. Ream

unread,
Oct 23, 2021, 1:41:43 AM10/23/21
to leo-editor
On Fri, Oct 22, 2021 at 8:34 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
Here's my stab at it.  Replace all the current text in the docstring ahead of the binding and API information with the following:

Done at rev 2f65d83 in devel.  The only change I made was to add the required 'c' arg to run.

This rev also adds the 'reset_zoom' kwarg to the run method. The default is True.

Many thanks, Thomas, for your testing and comments.

Edward

tbp1...@gmail.com

unread,
Oct 23, 2021, 9:39:14 AM10/23/21
to leo-editor
Those args in the docstring are not set in the Slides constructor:

exception executing script
TypeError: 'reset_zoom' is an unknown keyword argument
--------------------
  line 4: from leo.plugins.picture_viewer import Slides
* line 5: Slides(reset_zoom = False, width = 900, sort_kind = None).run(c)

The constructor only initializes scale, slide_number, and timer.

tbp1...@gmail.com

unread,
Oct 23, 2021, 10:01:23 AM10/23/21
to leo-editor
Oh, I see, those args are for run(), not the constructor.

tbp1...@gmail.com

unread,
Oct 23, 2021, 11:14:24 AM10/23/21
to leo-editor
I tried the width argument, and I had expected that the aspect ratio would be the original.  Instead, the width was set to my value but the original size was not changed.  So the image was clipped in width.  This is not very helpful.  I'd rather see the zoom factor set so that the specified width gets achieved.  Same for the height.  What should happen if they are both specified?  In that case, I expect that the entire image should be shown, with whichever of width or height can be satisfied.

Now that I've seen the effect of the width argument, I would also like to be able to specify the initial zoom factor.

I'm also thinking it might be useful to be able to optionally specify the target directory.

With all these quibbles, I really like the module.  Up until now, I have usually used IrfanView to look through a bunch of images.  When I don't need the other things it can do,  picture_viewer may possibly end up being my first choice.

tbp1...@gmail.com

unread,
Oct 23, 2021, 11:38:16 AM10/23/21
to leo-editor
Turns out you can set the initial zoom factor like this:

from leo.plugins.picture_viewer import Slides
Slides.scale = .5
Slides().run(c, reset_zoom = False)

So no need to change any code.  You must use reset_zoom = False for this to work. The one minor negative is that the window itself doesn't get zoomed, only the image itself.

tbp1...@gmail.com

unread,
Oct 23, 2021, 1:38:11 PM10/23/21
to leo-editor
On Saturday, October 23, 2021 at 11:14:24 AM UTC-4 tbp1...@gmail.com wrote:
I'm also thinking it might be useful to be able to optionally specify the target directory.

I now noticed that an initial path is already one of the run() arguments.  Great! 

Edward K. Ream

unread,
Oct 23, 2021, 3:25:11 PM10/23/21
to leo-editor
On Sat, Oct 23, 2021 at 12:38 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:

I now noticed that an initial path is already one of the run() arguments.  Great! 

:-)  It's remarkable how simple all the methods are.

Edward
Reply all
Reply to author
Forward
0 new messages