File: wx.lib.agw.scrolledthumbnail.txt

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (251 lines) | stat: -rw-r--r-- 10,002 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc

.. module:: wx.lib.agw.scrolledthumbnail

.. currentmodule:: wx.lib.agw.scrolledthumbnail

.. highlight:: python



.. _wx.lib.agw.scrolledthumbnail:

==========================================================================================================================================
|phoenix_title|  **wx.lib.agw.scrolledthumbnail**
==========================================================================================================================================

:class:`ScrolledThumbnail` is a widget that can be used to display a series of
thumbnails for files in a scrollable window.

Description
===========

:class:`ScrolledThumbnail` is a widget derived from :class:`wx.ScrolledWindow`
which will display the thumbnail image for a file in a scrollable, resizable
window.  It supports selecting one or more thumbnails, rotating the thumbnails,
displaying information for each thumbnail, and popups for both the window and
for individual thumbnails.

The class uses two support classes: :class:`Thumb` and :class:`ImageHandler`.

:class:`Thumb` contains all of the information for a particular thumbnail,
including filename, bitmaped thumbnail image, caption, and other data.  This
class also has methods to perform thumbnail operations such as rotation,
highlighting, setting a file name.

:class:`ImageHandler` provides file/image handling functions, including loading
a file and creating an image from it, rotating an image, or highlighting an image.

The implementations of these two classes included in this file support generating
thumbnails from supported image files, such as JPEG, GIF, PNG, etc., using either
WxPythons native support or the PIL image library.  Additional file types can be
supported by extending these classes, for example, to provide a thumbnail image
for an MP4 file, perhaps the cover photo, an MPEG by providing the image of a
title frame, or a PDF by providing an image of the cover page.  The images for
these files may be generated on the fly by a suitably extended :class:`ImageHandler`,
or may be provided with the instance of :class:`Thumb`.  The list of `Thumb`
instances passed to `ScrolledThumbnail` may contain different derived classes,
as long as each contains the required functions.

NB:  Use of :class:`ScrolledThumbnail` has not been tested with extended classes.

:class:`ScrolledThumbnail`, :class:`Thumb`, and :class:`ImageHandler`, implemented
here are derived from the similarly named classes included in :class:`agw.ThumbnailCtrl`,
written by Andrea Gavana.  That implementation was tightly integrated as a image
file browser application.  The current implementation removes dependencies between
the several classes and narrows the scope of `ScrolledThumbnail` to the placement
and management of thumbnails within a window.

An updated :class:`ThumbnailCtrl` which uses this implementation of
:class:`ScrolledThumbnail`, :class:`Thumb`, and :class:`ImageHandler` provides
all of the previous functionality, which described as a widget that can be used
to display a series of images in a "thumbnail" format; it mimics, for example,
the windows explorer behavior when you select the "view thumbnails" option.
Basically, by specifying a folder that contains some image files, the files
in the folder are displayed as miniature versions of the actual images in
a :class:`ScrolledWindow`.

The code in the previous implementation is partly based on `wxVillaLib`, a
wxWidgets implementation of the :class:`ThumbnailCtrl` control.  Andrea Gavana
notes that :class:`ThumbnailCtrl` wouldn't have been so fast and complete
without the suggestions and hints from Peter Damoc.

Usage:
=====

Usage example::

    import os
    import wx
    from scrolledthumbnail import ScrolledThumbnail, Thumb, NativeImageHandler

    class MyFrame(wx.Frame):

        def __init__(self, parent):
            wx.Frame.__init__(self, parent, -1, "ScrolledThumb Demo", size=(400,300))

            self.scroll = ScrolledThumbnail(self, -1, size=(400,300))

        def ShowDir(self, dir):
            dir = os.getcwd()
            files = os.listdir(dir)
            thumbs = []
            for f in files:
                if os.path.splitext(f)[1] in [".jpg", ".gif", ".png"]:
                    thumbs.append(Thumb(dir, f, caption=f, imagehandler=NativeImageHandler))
            self.scroll.ShowThumbs(thumbs)


    app = wx.App(False)
    frame = MyFrame(None)
    frame.ShowDir(os.getcwd())
    frame.Show(True)

    app.MainLoop()



Methods and Settings
====================

With :class:`ScrolledThumbnail` you can:

- Create different thumbnail outlines (none, images only, full, etc...);
- Highlight thumbnails on mouse hovering;
- Show/hide file names below thumbnails;
- Change thumbnail caption font;
- Zoom in/out thumbnails (done via ``Ctrl`` key + mouse wheel or with ``+`` and ``-`` chars,
  with zoom factor value customizable);
- Rotate thumbnails with these specifications:

  a) ``d`` key rotates 90 degrees clockwise;
  b) ``s`` key rotates 90 degrees counter-clockwise;
  c) ``a`` key rotates 180 degrees.

- Drag and drop thumbnails from :class:`ScrolledThumbnail` to whatever application you want;
- Use local (when at least one thumbnail is selected) or global (no need for
  thumbnail selection) popup menus;
- possibility to show tooltips on thumbnails, which display file information
  (like file name, size, last modification date and thumbnail size).

:note: Using highlight thumbnails on mouse hovering may be slow on slower
 computers.


Window Styles
=============

`No particular window styles are available for this class.`


Events Processing
=================

This class processes the following events:

This class processes the following events:

================================== ==================================================
Event Name                         Description
================================== ==================================================
``EVT_THUMBNAILS_CAPTION_CHANGED`` The thumbnail caption has been changed. Not used at present.
``EVT_THUMBNAILS_DCLICK``          The user has double-clicked on a thumbnail.
``EVT_THUMBNAILS_POINTED``         The mouse cursor is hovering over a thumbnail.
``EVT_THUMBNAILS_SEL_CHANGED``     The user has changed the selected thumbnail.
``EVT_THUMBNAILS_THUMB_CHANGED``   The thumbnail of an image has changed. Used internally.
``EVT_THUMBNAILS_CHAR``            A character has been typed
================================== ==================================================


License And Version
===================

:class:`ScrolledThumbnail` is distributed under the wxPython license.

Latest revision: Michael Eager @ 2 Oct 2020

Version 1.0


|function_summary| Functions Summary
====================================

================================================================================ ================================================================================
:func:`~wx.lib.agw.scrolledthumbnail.getDataBL`                                  Return the second part of the shadow dropped behind thumbnails.
:func:`~wx.lib.agw.scrolledthumbnail.getDataSH`                                  Return the first part of the shadow dropped behind thumbnails.
:func:`~wx.lib.agw.scrolledthumbnail.getDataTR`                                  Return the third part of the shadow dropped behind thumbnails.
:func:`~wx.lib.agw.scrolledthumbnail.getShadow`                                  Creates a shadow behind every thumbnail.
:func:`~wx.lib.agw.scrolledthumbnail.opj`                                        Convert paths to the platform-specific separator.
================================================================================ ================================================================================


|


|class_summary| Classes Summary
===============================

================================================================================ ================================================================================
:ref:`~wx.lib.agw.scrolledthumbnail.NativeImageHandler`                          This image handler loads and manipulates the thumbnails with the help of
:ref:`~wx.lib.agw.scrolledthumbnail.PILImageHandler`                             This image handler loads and manipulates the thumbnails with the help
:ref:`~wx.lib.agw.scrolledthumbnail.ScrolledThumbnail`                           This is the main class implementation of :class:`ThumbnailCtrl`.
:ref:`~wx.lib.agw.scrolledthumbnail.Thumb`                                       This is an auxiliary class, to handle single thumbnail information for every thumb.
:ref:`~wx.lib.agw.scrolledthumbnail.ThumbnailEvent`                              This class is used to send events when a thumbnail is hovered, selected,
================================================================================ ================================================================================


|


.. toctree::
   :maxdepth: 1
   :hidden:

   wx.lib.agw.scrolledthumbnail.NativeImageHandler
   wx.lib.agw.scrolledthumbnail.PILImageHandler
   wx.lib.agw.scrolledthumbnail.ScrolledThumbnail
   wx.lib.agw.scrolledthumbnail.Thumb
   wx.lib.agw.scrolledthumbnail.ThumbnailEvent





Functions
------------

.. function:: getDataBL()

   Return the second part of the shadow dropped behind thumbnails. 


.. function:: getDataSH()

   Return the first part of the shadow dropped behind thumbnails. 


.. function:: getDataTR()

   Return the third part of the shadow dropped behind thumbnails. 


.. function:: getShadow()

   Creates a shadow behind every thumbnail. 


.. function:: opj(path)

   Convert paths to the platform-specific separator.
   
   :param `path`: the path to convert.