diff --git a/wx/lib/agw/thumbnailctrl.py b/wx/lib/agw/thumbnailctrl.py index 13301ae1..5e950f78 100644 --- a/wx/lib/agw/thumbnailctrl.py +++ b/wx/lib/agw/thumbnailctrl.py @@ -59,18 +59,18 @@ Usage Usage example:: import os - + import wx import wx.lib.agw.thumbnailctrl as TC class MyFrame(wx.Frame): def __init__(self, parent): - + wx.Frame.__init__(self, parent, -1, "ThumbnailCtrl Demo") panel = wx.Panel(self) - + sizer = wx.BoxSizer(wx.VERTICAL) thumbnail = TC.ThumbnailCtrl(panel, imagehandler=TC.NativeImageHandler) @@ -108,7 +108,7 @@ With :class:`ThumbnailCtrl` you can: a) ``d`` key rotates 90 degrees clockwise; b) ``s`` key rotates 90 degrees counter-clockwise; c) ``a`` key rotates 180 degrees. - + - Delete files/thumbnails (via the ``del`` key); - Drag and drop thumbnails from :class:`ThumbnailCtrl` to whatever application you want; - Use local (when at least one thumbnail is selected) or global (no need for @@ -189,7 +189,7 @@ ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\ o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\ \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\ \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\ -\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82' +\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82' def GetMondrianBitmap(): @@ -276,7 +276,7 @@ file_broken = PyEmbeddedImage( def getDataSH(): """ Return the first part of the shadow dropped behind thumbnails. """ - + return zlib.decompress( b'x\xda\xeb\x0c\xf0s\xe7\xe5\x92\xe2b``\xe0\xf5\xf4p\t\x02\xd2_A\x98\x83\rHvl\ \xdc\x9c\n\xa4X\x8a\x9d= len(self._captionbreaks): return "" - + strs = self._caption - return strs + return strs def GetFileSize(self): """ Returns the file size associated to a thumbnail. """ - + return self._filesize def GetCreationDate(self): """ Returns the file last modification date associated to a thumbnail. """ - - return self._lastmod + + return self._lastmod def GetOriginalSize(self): """ Returns a tuple containing the original image width and height, in pixels. """ if hasattr(self, "_threadedimage"): - img = self._threadedimage + img = self._threadedimage else: img = GetMondrianImage() - + if hasattr(self, "_originalsize"): imgwidth, imgheight = self._originalsize else: imgwidth, imgheight = (img.GetWidth(), img.GetHeight()) return imgwidth, imgheight - + def GetCaptionLinesCount(self, width): """ @@ -819,7 +819,7 @@ class Thumb(object): :param `width`: the maximum width, in pixels, available for the caption text. """ - + self.BreakCaption(width) return len(self._captionbreaks) - 1 @@ -830,10 +830,10 @@ class Thumb(object): :param `width`: the maximum width, in pixels, available for the caption text. """ - + if len(self._captionbreaks) > 0 or width < 16: return - + self._captionbreaks.append(0) if len(self._caption) == 0: @@ -846,28 +846,28 @@ class Thumb(object): dc = wx.MemoryDC() bmp = wx.Bitmap(10, 10) dc.SelectObject(bmp) - + while 1: - + if pos >= len(self._caption): self._captionbreaks.append(len(self._caption)) break sw, sh = dc.GetTextExtent(self._caption[beg:pos-beg]) - + if sw > width: if end > 0: - + self._captionbreaks.append(end) beg = end - + else: - + self._captionbreaks.append(pos) beg = pos - + pos = beg + width//16 end = 0 @@ -878,28 +878,28 @@ class Thumb(object): dc.SelectObject(wx.NullBitmap) - + def SetRotation(self, angle=0): """ Sets the thumbnail rotation. - :param `angle`: the thumbnail rotation, in radians. + :param `angle`: the thumbnail rotation, in radians. """ - + self._rotation = angle def GetRotation(self): """ Returns the thumbnail rotation, in radians. """ - + return self._rotation - + # ---------------------------------------------------------------------------- # # Class ThumbnailCtrl # Auxiliary Class, All Useful Methods Are Defined On ScrolledThumbnail Class. -# ---------------------------------------------------------------------------- # +# ---------------------------------------------------------------------------- # class ThumbnailCtrl(wx.Panel): """ @@ -935,8 +935,8 @@ class ThumbnailCtrl(wx.Panel): :param `imagehandler`: can be :class:`PILImageHandler` if PIL is installed (faster), or :class:`NativeImageHandler` which only uses wxPython image methods. """ - - wx.Panel.__init__(self, parent, id, pos, size) + + wx.Panel.__init__(self, parent, id, pos, size) self._sizer = wx.BoxSizer(wx.VERTICAL) @@ -953,7 +953,7 @@ class ThumbnailCtrl(wx.Panel): self.SetSizer(self._sizer) - self._sizer.Show(0, False) + self._sizer.Show(0, False) self._sizer.Layout() methods = ["GetSelectedItem", "GetPointed", "GetHighlightPointed", "SetHighlightPointed", @@ -973,9 +973,9 @@ class ThumbnailCtrl(wx.Panel): self._combochoices = [] self._showcombo = False self._subsizer = subsizer - + self._combo.Bind(wx.EVT_COMBOBOX, self.OnComboBox) - + def ShowComboBox(self, show=True): """ @@ -983,7 +983,7 @@ class ThumbnailCtrl(wx.Panel): :param `show`: ``True`` to show the combobox, ``False`` otherwise. """ - + if show: self._showcombo = True self._sizer.Show(0, True) @@ -998,9 +998,9 @@ class ThumbnailCtrl(wx.Panel): def GetShowComboBox(self): """ Returns whether the folder combobox is shown. """ - + return self._showcombo - + def OnComboBox(self, event): """ @@ -1008,12 +1008,12 @@ class ThumbnailCtrl(wx.Panel): :param `event`: a :class:`CommandEvent` event to be processed. """ - + dirs = self._combo.GetValue() if os.path.isdir(opj(dirs)): self._scrolled.ShowDir(opj(dirs)) - + event.Skip() @@ -1023,9 +1023,9 @@ class ThumbnailCtrl(wx.Panel): :param `newdir`: the new folder to be explored. """ - + newdir = newdir.strip() - + if opj(newdir) in self._combochoices: return @@ -1037,9 +1037,9 @@ class ThumbnailCtrl(wx.Panel): self._combo.Destroy() subsizer = wx.BoxSizer(wx.HORIZONTAL) - + self._combochoices.insert(0, opj(newdir)) - + self._combo = wx.ComboBox(self, -1, value=newdir, choices=self._combochoices, style=wx.CB_DROPDOWN | wx.CB_READONLY) @@ -1049,23 +1049,23 @@ class ThumbnailCtrl(wx.Panel): self._sizer.Insert(0, subsizer, 0, wx.EXPAND | wx.ALL, 3) self._subsizer = subsizer - + self._subsizer.Layout() if not self.GetShowComboBox(): self._sizer.Show(0, False) - + self._sizer.Layout() self._combo.Bind(wx.EVT_COMBOBOX, self.OnComboBox) - + self.Thaw() - - + + # ---------------------------------------------------------------------------- # # Class ScrolledThumbnail # This Is The Main Class Implementation -# ---------------------------------------------------------------------------- # +# ---------------------------------------------------------------------------- # class ScrolledThumbnail(wx.ScrolledWindow): """ This is the main class implementation of :class:`ThumbnailCtrl`. """ @@ -1098,7 +1098,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `imagehandler`: can be :class:`PILImageHandler` if PIL is installed (faster), or :class:`NativeImageHandler` which only uses wxPython image methods. """ - + wx.ScrolledWindow.__init__(self, parent, id, pos, size) self.SetThumbSize(96, 80) @@ -1127,9 +1127,9 @@ class ScrolledThumbnail(wx.ScrolledWindow): self._items = [] self._enabletooltip = False - + self._parent = parent - + self._selectioncolour = "#009EFF" self.grayPen = wx.Pen("#A2A2D2", 1, wx.SHORT_DASH) self.grayPen.SetJoin(wx.JOIN_MITER) @@ -1138,7 +1138,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): t, b, s = getShadow() self.shadow = wx.MemoryDC() self.shadow.SelectObject(s) - + self.ShowFileNames(True) self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown) @@ -1151,7 +1151,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.Bind(EVT_THUMBNAILS_THUMB_CHANGED, self.OnThumbChanged) self.Bind(wx.EVT_CHAR, self.OnChar) self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) - + self.Bind(wx.EVT_SIZE, self.OnResize) self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None) self.Bind(wx.EVT_PAINT, self.OnPaint) @@ -1169,17 +1169,17 @@ class ScrolledThumbnail(wx.ScrolledWindow): def GetPointed(self): """ Returns the pointed thumbnail index. """ - + return self._pointed def GetHighlightPointed(self): """ Returns whether the thumbnail pointed should be highlighted or not. - + :note: Please be aware that this functionality may be slow on slower computers. """ - + return self._highlight @@ -1189,10 +1189,10 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `highlight`: ``True`` to enable highlight-on-point with the mouse, ``False`` otherwise. - + :note: Please be aware that this functionality may be slow on slower computers. """ - + self._highlight = highlight @@ -1211,14 +1211,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): ``THUMB_OUTLINE_RECT`` 2 Only thumbnail bounding rectangle is drawn on selection (default) ``THUMB_OUTLINE_IMAGE`` 4 Only image bounding rectangle is drawn. =========================== ======= ================================== - + """ if outline not in [THUMB_OUTLINE_NONE, THUMB_OUTLINE_FULL, THUMB_OUTLINE_RECT, THUMB_OUTLINE_IMAGE]: return - - self._tOutline = outline + + self._tOutline = outline def GetThumbOutline(self): @@ -1227,7 +1227,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :see: :meth:`~ScrolledThumbnail.SetThumbOutline` for a list of possible return values. """ - + return self._tOutline @@ -1240,7 +1240,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self._dropShadow = drop self.Refresh() - + def GetDropShadow(self): """ @@ -1248,13 +1248,13 @@ class ScrolledThumbnail(wx.ScrolledWindow): """ return self._dropShadow - + def GetPointedItem(self): """ Returns the pointed thumbnail. """ - + return self.GetItem(self._pointed) - + def GetItem(self, index): """ @@ -1275,7 +1275,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): def SortItems(self): """ Sorts the items accordingly to the :func:`~CmpThumb` function. """ - self._items.sort(key=KeyThumb) + self._items.sort(key=KeyThumb) def GetThumbWidth(self): @@ -1294,23 +1294,23 @@ class ScrolledThumbnail(wx.ScrolledWindow): """ Returns the thumbnail border. """ return self._tBorder - - + + def GetCaption(self): """ Returns the thumbnail caption. """ return self._caption - + def SetLabelControl(self, statictext): """ Sets the thumbnail label as :class:`StaticText`. :param `statictext`: an instance of :class:`StaticText`. """ - + self._labelcontrol = statictext - + def ShowFileNames(self, show=True): """ @@ -1318,10 +1318,10 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `show`: ``True`` to show file names under the thumbnails, ``False`` otherwise. """ - + self._showfilenames = show self.Refresh() - + def SetOrientation(self, orient=THUMB_VERTICAL): """ @@ -1329,9 +1329,9 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `orient`: one of ``THUMB_VERTICAL``, ``THUMB_HORIZONTAL``. - .. todo:: Correctly implement the ``THUMB_HORIZONTAL`` orientation. + .. todo:: Correctly implement the ``THUMB_HORIZONTAL`` orientation. """ - + self._orient = orient @@ -1341,14 +1341,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `menu`: an instance of :class:`wx.Menu`. """ - + self._pmenu = menu def GetPopupMenu(self): """ Returns the thumbnails popup menu when at least one thumbnail is selected. """ - - return self._pmenu + + return self._pmenu def SetGlobalPopupMenu(self, gpmenu): @@ -1357,19 +1357,19 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `gpmenu`: an instance of :class:`wx.Menu`. """ - + self._gpmenu = gpmenu def GetGlobalPopupMenu(self): """ Returns the global thumbnailss popup menu (no need of thumbnail selection). """ - + return self._gpmenu - + def GetSelectionColour(self): """ Returns the colour used to indicate a selected thumbnail. """ - + return self._selectioncolour @@ -1380,12 +1380,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `colour`: a valid :class:`wx.Colour` object. If defaulted to ``None``, it will be taken from the system settings. """ - + if colour is None: colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) self._selectioncolour = colour - + def EnableDragging(self, enable=True): """ @@ -1393,7 +1393,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `enable`: ``True`` to enable drag and drop, ``False`` to disable it. """ - + self._dragging = enable @@ -1405,10 +1405,10 @@ class ScrolledThumbnail(wx.ScrolledWindow): """ self._enabletooltip = enable - + if not enable and hasattr(self, "_tipwindow"): self._tipwindow.Enable(False) - + def GetThumbInfo(self, thumb=-1): """ @@ -1416,9 +1416,9 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `thumb`: the index of the thumbnail for which we are collecting information. """ - + thumbinfo = None - + if thumb >= 0: thumbinfo = "Name: " + self._items[thumb].GetFileName() + "\n" \ "Size: " + self._items[thumb].GetFileSize() + "\n" \ @@ -1427,7 +1427,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): "Thumb: " + str(self.GetThumbSize()[0:2]) return thumbinfo - + def SetThumbSize(self, width, height, border=6): """ @@ -1437,11 +1437,11 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `height`: the desired thumbnail height; :param `border`: the spacing between thumbnails. """ - + if width > 350 or height > 280: return - - self._tWidth = width + + self._tWidth = width self._tHeight = height self._tBorder = border self.SetScrollRate((self._tWidth + self._tBorder)/4, @@ -1452,13 +1452,13 @@ class ScrolledThumbnail(wx.ScrolledWindow): def GetThumbSize(self): """ Returns the thumbnail size as width, height and border. """ - + return self._tWidth, self._tHeight, self._tBorder def Clear(self): """ Clears :class:`ThumbnailCtrl`. """ - + self._items = [] self._selected = -1 self._selectedarray = [] @@ -1474,11 +1474,8 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `fileExtList`: a Python list of file extensions to consider. """ - fileList = [os.path.normcase(f) for f in os.listdir(directory)] - fileList = [f for f in fileList \ - if os.path.splitext(f)[1] in fileExtList] - - return fileList + lSplitExt = os.path.splitext + return [f for f in os.listdir(directory) if lSplitExt(f)[1].lower() in fileExtList] def ThreadImage(self, filenames): @@ -1487,27 +1484,27 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `filenames`: a Python list of file names containing images. """ - + count = 0 - + while count < len(filenames): if not self._isrunning: self._isrunning = False thread.exit() return - + self.LoadImages(filenames[count], count) if count < 4: self.Refresh() elif count%4 == 0: self.Refresh() - + count = count + 1 - self._isrunning = False + self._isrunning = False thread.exit() - + def LoadImages(self, newfile, imagecount): """ @@ -1520,7 +1517,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): if not self._isrunning: thread.exit() return - + img, originalsize, alpha = self._imageHandler.LoadThumbnail(newfile, (300, 240)) try: self._items[imagecount]._threadedimage = img @@ -1530,11 +1527,11 @@ class ScrolledThumbnail(wx.ScrolledWindow): except: return - + def ShowThumbs(self, thumbs, caption): """ Shows all the thumbnails. - + :param `thumbs`: should be a sequence with instances of :class:`Thumb`; :param `caption`: the caption text for the current selected thumbnail. """ @@ -1542,24 +1539,24 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.SetCaption(caption) self._isrunning = False - + # update items self._items = thumbs myfiles = [thumb.GetFullFileName() for thumb in thumbs] - + items = self._items[:] self._items.sort(key=KeyThumb) newfiles = SortFiles(items, self._items, myfiles) self._isrunning = True - + thread.start_new_thread(self.ThreadImage, (newfiles,)) wx.MilliSleep(20) self._selectedarray = [] self.UpdateProp() self.Refresh() - + def ShowDir(self, folder, filter=THUMB_FILTER_IMAGES): """ @@ -1571,13 +1568,13 @@ class ScrolledThumbnail(wx.ScrolledWindow): .. todo:: Find a way to create thumbnails of video, audio and other formats. """ - + self._dir = folder if filter >= 0: self._filter = filter - + self._parent.RecreateComboBox(folder) - + # update items thumbs = [] @@ -1592,7 +1589,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): stats = os.stat(fullfile) size = stats[6] - + if size < 1000: size = str(size) + " bytes" elif size < 1000000: @@ -1601,18 +1598,18 @@ class ScrolledThumbnail(wx.ScrolledWindow): size = str(round(size/1000000.0, 2)) + " Mb" lastmod = time.strftime(TIME_FMT, time.localtime(stats[8])) - + if self._filter & THUMB_FILTER_IMAGES: thumbs.append(Thumb(self, folder, files, caption, size, lastmod)) - + return self.ShowThumbs(thumbs, caption=self._dir) def GetShowDir(self): """ Returns the working directory with images. """ - + return self._dir - + def SetSelection(self, value=-1): """ @@ -1620,7 +1617,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `value`: the thumbnail index to select. """ - + self._selected = value if value != -1: @@ -1630,7 +1627,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.ScrollToSelected() self.Refresh() - + def SetZoomFactor(self, zoom=1.4): """ Sets the zoom factor. @@ -1638,18 +1635,18 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `zoom`: a floating point number representing the zoom factor. Must be greater than or equal to 1.0. """ - + if zoom <= 1.0: raise Exception("\nERROR: Zoom Factor Must Be Greater Than 1.0") - - self._zoomfactor = zoom + + self._zoomfactor = zoom def GetZoomFactor(self): """ Returns the zoom factor. """ - + return self._zoomfactor - + def IsAudioVideo(self, fname): """ @@ -1657,7 +1654,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): Currently unused as :class:`ThumbnailCtrl` recognizes only image files. :param `fname`: a file name. - + .. todo:: Find a way to create thumbnails of video, audio and other formats. """ @@ -1691,28 +1688,28 @@ class ScrolledThumbnail(wx.ScrolledWindow): return os.path.splitext(fname)[1].lower() in \ [".mpa", ".mp2", ".mp3", ".ac3", ".dts", ".pcm"] - + def UpdateItems(self): """ Updates thumbnail items. """ - + selected = self._selectedarray selectedfname = [] selecteditemid = [] - + for ii in range(len(self._selectedarray)): selectedfname.append(self.GetSelectedItem(ii).GetFileName()) selecteditemid.append(self.GetSelectedItem(ii).GetId()) - + self.UpdateShow() - + if len(selected) > 0: - self._selectedarray = [] + self._selectedarray = [] for ii in range(len(self._items)): for jj in range(len(selected)): if self._items[ii].GetFileName() == selectedfname[jj] and \ self._items[ii].GetId() == selecteditemid[jj]: - + self._selectedarray.append(ii) if len(self._selectedarray) == 1: self.ScrollToSelected() @@ -1721,7 +1718,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.Refresh() eventOut = ThumbnailEvent(wxEVT_THUMBNAILS_SEL_CHANGED, self.GetId()) self.GetEventHandler().ProcessEvent(eventOut) - + def SetCaption(self, caption=""): """ @@ -1729,7 +1726,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `caption`: the current caption string. """ - + self._caption = caption if self._labelcontrol: @@ -1750,22 +1747,22 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `font`: a valid :class:`wx.Font` object. If defaulted to ``None``, a standard font will be generated. """ - + if font is None: - font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD, False) + font = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) self._captionfont = font def GetCaptionFont(self): """ Returns the font for all the thumbnail captions. """ - + return self._captionfont - + def UpdateShow(self): """ Updates thumbnail items. """ - + self.ShowThumbs(self._items) @@ -1776,13 +1773,13 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `begRow`: the caption line at which we start measuring the height; :param `count`: the number of lines to measure. """ - + capHeight = 0 for ii in range(begRow, begRow + count): if ii < len(self._tCaptionHeight): capHeight = capHeight + self._tCaptionHeight[ii] - return capHeight*self._tTextHeight + return capHeight*self._tTextHeight def GetItemIndex(self, x, y): @@ -1792,15 +1789,15 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `x`: the mouse `x` position; :param `y`: the mouse `y` position. """ - + col = (x - self._tBorder)/(self._tWidth + self._tBorder) if col >= self._cols: col = self._cols - 1 - + row = -1 y = y - self._tBorder - + while y > 0: row = row + 1 @@ -1810,7 +1807,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): row = 0 index = row*self._cols + col - + if index >= len(self._items): index = -1 @@ -1827,26 +1824,26 @@ class ScrolledThumbnail(wx.ScrolledWindow): width = self.GetClientSize().GetWidth() self._cols = (width - self._tBorder)//(self._tWidth + self._tBorder) - + if self._cols <= 0: self._cols = 1 tmpvar = (len(self._items)%self._cols and [1] or [0])[0] self._rows = len(self._items)//self._cols + tmpvar - + self._tCaptionHeight = [] for row in range(self._rows): capHeight = 0 - + for col in range(self._cols): ii = row*self._cols + col - + if len(self._items) > ii and \ self._items[ii].GetCaptionLinesCount(self._tWidth - self._tCaptionBorder) > capHeight: - + capHeight = self._items[ii].GetCaptionLinesCount(self._tWidth - self._tCaptionBorder) self._tCaptionHeight.append(capHeight) @@ -1854,11 +1851,11 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.SetVirtualSize((self._cols*(self._tWidth + self._tBorder) + self._tBorder, self._rows*(self._tHeight + self._tBorder) + \ self.GetCaptionHeight(0, self._rows) + self._tBorder)) - + self.SetSizeHints(self._tWidth + 2*self._tBorder + 16, self._tHeight + 2*self._tBorder + 8 + \ (self._rows and [self.GetCaptionHeight(0)] or [0])[0]) - + if checkSize and width != self.GetClientSize().GetWidth(): self.UpdateProp(False) @@ -1869,12 +1866,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `pos`: the index at which we wish to insert the new thumbnail. """ - + if pos < 0 or pos > len(self._items): self._items.append(thumb) else: self._items.insert(pos, thumb) - + self.UpdateProp() @@ -1883,23 +1880,23 @@ class ScrolledThumbnail(wx.ScrolledWindow): Removes a thumbnail at the specified position. :param `pos`: the index at which we wish to remove the thumbnail. - """ + """ del self._items[pos] - + self.UpdateProp() def GetPaintRect(self): """ Returns the paint bounding rect for the :meth:`~ScrolledThumbnail.OnPaint` method. """ - + size = self.GetClientSize() paintRect = wx.Rect(0, 0, size.GetWidth(), size.GetHeight()) paintRect.x, paintRect.y = self.GetViewStart() xu, yu = self.GetScrollPixelsPerUnit() paintRect.x = paintRect.x*xu paintRect.y = paintRect.y*yu - + return paintRect @@ -1911,7 +1908,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): """ return self._selectedarray.count(indx) != 0 - + def GetSelection(self, selIndex=-1): """ @@ -1919,7 +1916,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `selIndex`: if not equal to -1, the index of the selected thumbnail. """ - + return (selIndex == -1 and [self._selected] or \ [self._selectedarray[selIndex]])[0] @@ -1934,20 +1931,20 @@ class ScrolledThumbnail(wx.ScrolledWindow): if index is None: index = self.GetSelection() - + return self._items[index].GetOriginalImage() def ScrollToSelected(self): """ Scrolls the :class:`ScrolledWindow` to the selected thumbnail. """ - + if self.GetSelection() == -1: return # get row row = self.GetSelection()/self._cols # calc position to scroll view - + paintRect = self.GetPaintRect() y1 = row*(self._tHeight + self._tBorder) + self.GetCaptionHeight(0, row) y2 = y1 + self._tBorder + self._tHeight + self.GetCaptionHeight(row) @@ -1958,12 +1955,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): sy = y2 - paintRect.height # scroll bottom else: return - + # scroll view xu, yu = self.GetScrollPixelsPerUnit() sy = sy/yu + (sy%yu and [1] or [0])[0] # convert sy to scroll units x, y = self.GetViewStart() - + self.Scroll(x,sy) @@ -1978,13 +1975,13 @@ class ScrolledThumbnail(wx.ScrolledWindow): """ caption = caption + "..." - + while sw > width: caption = caption[1:] sw, sh = dc.GetTextExtent(caption) - + return "..." + caption[0:-3] - + def DrawThumbnail(self, bmp, thumb, index): """ @@ -1997,15 +1994,15 @@ class ScrolledThumbnail(wx.ScrolledWindow): dc = wx.MemoryDC() dc.SelectObject(bmp) - + x = self._tBorder/2 y = self._tBorder/2 # background dc.SetPen(wx.Pen(wx.BLACK, 0, wx.TRANSPARENT)) - dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) + dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID)) dc.DrawRectangle(0, 0, bmp.GetWidth(), bmp.GetHeight()) - + # image img = thumb.GetBitmap(self._tWidth, self._tHeight) ww = img.GetWidth() @@ -2014,18 +2011,18 @@ class ScrolledThumbnail(wx.ScrolledWindow): if index == self.GetPointed() and self.GetHighlightPointed(): factor = 1.5 img = self._imageHandler.HighlightImage(img.ConvertToImage(), factor).ConvertToBitmap() - + imgRect = wx.Rect(x + (self._tWidth - img.GetWidth())/2, y + (self._tHeight - img.GetHeight())/2, img.GetWidth(), img.GetHeight()) if not thumb._alpha and self._dropShadow: - dc.Blit(imgRect.x+5, imgRect.y+5, imgRect.width, imgRect.height, self.shadow, 500-ww, 500-hh) + dc.Blit(imgRect.x+5, imgRect.y+5, imgRect.width, imgRect.height, self.shadow, 500-ww, 500-hh) dc.DrawBitmap(img, imgRect.x, imgRect.y, True) colour = self.GetSelectionColour() selected = self.IsSelected(index) - + colour = self.GetSelectionColour() # draw caption @@ -2039,14 +2036,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): if sw > self._tWidth: mycaption = self.CalculateBestCaption(dc, mycaption, sw, self._tWidth) sw = self._tWidth - + textWidth = sw + 8 tx = x + (self._tWidth - textWidth)/2 ty = y + self._tHeight txtcolour = "#7D7D7D" - dc.SetTextForeground(txtcolour) - + dc.SetTextForeground(txtcolour) + tx = x + (self._tWidth - sw)/2 if hh >= self._tHeight: ty = y + self._tHeight + (self._tTextHeight - sh)/2 + 3 @@ -2054,7 +2051,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): ty = y + hh + (self._tHeight-hh)/2 + (self._tTextHeight - sh)/2 + 3 dc.DrawText(mycaption, tx, ty) - + # outline if self._tOutline != THUMB_OUTLINE_NONE and (self._tOutlineNotSelected or self.IsSelected(index)): @@ -2063,11 +2060,11 @@ class ScrolledThumbnail(wx.ScrolledWindow): dotrect.y = y - 2 dotrect.width = bmp.GetWidth() - self._tBorder + 4 dotrect.height = bmp.GetHeight() - self._tBorder + 4 - + dc.SetPen(wx.Pen((self.IsSelected(index) and [colour] or [wx.LIGHT_GREY])[0], - 0, wx.SOLID)) - dc.SetBrush(wx.Brush(wx.BLACK, wx.TRANSPARENT)) - + 0, wx.PENSTYLE_SOLID)) + dc.SetBrush(wx.Brush(wx.BLACK, wx.BRUSHSTYLE_TRANSPARENT)) + if self._tOutline == THUMB_OUTLINE_FULL or self._tOutline == THUMB_OUTLINE_RECT: imgRect.x = x @@ -2076,7 +2073,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): imgRect.height = bmp.GetHeight() - self._tBorder if self._tOutline == THUMB_OUTLINE_RECT: - imgRect.height = self._tHeight + imgRect.height = self._tHeight dc.SetBrush(wx.TRANSPARENT_BRUSH) @@ -2084,7 +2081,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): dc.SetPen(self.grayPen) dc.DrawRoundedRectangle(dotrect, 2) - + dc.SetPen(wx.Pen(wx.WHITE)) dc.DrawRectangle(imgRect.x, imgRect.y, imgRect.width, imgRect.height) @@ -2103,8 +2100,8 @@ class ScrolledThumbnail(wx.ScrolledWindow): dc.DrawRectangle(imgRect.x - 1, imgRect.y - 1, imgRect.width + 2, imgRect.height + 2) - - + + dc.SelectObject(wx.NullBitmap) @@ -2114,16 +2111,16 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`PaintEvent` event to be processed. """ - + paintRect = self.GetPaintRect() - + dc = wx.BufferedPaintDC(self) self.PrepareDC(dc) - dc.SetPen(wx.Pen(wx.BLACK, 0, wx.TRANSPARENT)) - dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) + dc.SetPen(wx.Pen(wx.BLACK, 0, wx.PENSTYLE_TRANSPARENT)) + dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID)) - w, h = self.GetClientSize() + w, h = self.GetClientSize() # items row = -1 @@ -2134,7 +2131,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): col = ii%self._cols if col == 0: row = row + 1 - + xwhite = ((w - self._cols*(self._tWidth + self._tBorder)))/(self._cols+1) tx = xwhite + col*(self._tWidth + self._tBorder) @@ -2145,23 +2142,23 @@ class ScrolledThumbnail(wx.ScrolledWindow): # visible? if not paintRect.Intersects(wx.Rect(tx, ty, tw, th)): continue - + thmb = wx.Bitmap(tw, th) self.DrawThumbnail(thmb, self._items[ii], ii) dc.DrawBitmap(thmb, tx, ty) - + rect = wx.Rect(xwhite, self._tBorder/2, self._cols*(self._tWidth + self._tBorder), self._rows*(self._tHeight + self._tBorder) + \ self.GetCaptionHeight(0, self._rows)) - + w = max(self.GetClientSize().GetWidth(), rect.width) h = max(self.GetClientSize().GetHeight(), rect.height) dc.DrawRectangle(0, 0, w, rect.y) dc.DrawRectangle(0, 0, rect.x, h) dc.DrawRectangle(rect.GetRight(), 0, w - rect.GetRight(), h + 50) dc.DrawRectangle(0, rect.GetBottom(), w, h - rect.GetBottom() + 50) - + col = len(self._items)%self._cols if col > 0: @@ -2177,7 +2174,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`wx.SizeEvent` event to be processed. """ - + self.UpdateProp() self.ScrollToSelected() self.Refresh() @@ -2189,14 +2186,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`MouseEvent` event to be processed. """ - + x = event.GetX() y = event.GetY() x, y = self.CalcUnscrolledPosition(x, y) # get item number to select lastselected = self._selected self._selected = self.GetItemIndex(x, y) - + self._mouseeventhandled = False update = False @@ -2221,10 +2218,10 @@ class ScrolledThumbnail(wx.ScrolledWindow): self._selectedarray.append(ii) update = True - + self._selected = lastselected self._mouseeventhandled = True - + else: if self._selected == -1: @@ -2239,7 +2236,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self._selectedarray = [] self._selectedarray.append(self._selected) self._mouseeventhandled = True - + if update: self.ScrollToSelected() self.Refresh() @@ -2247,7 +2244,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.GetEventHandler().ProcessEvent(eventOut) self.SetFocus() - + def OnMouseUp(self, event): """ @@ -2255,7 +2252,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`MouseEvent` event to be processed. """ - + # get item number to select x = event.GetX() y = event.GetY() @@ -2268,7 +2265,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): if event.ControlDown(): if self._selected in self._selectedarray: self._selectedarray.remove(self._selected) - + self._selected = -1 else: self._selectedarray = [] @@ -2298,7 +2295,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`MouseEvent` event to be processed. """ - + eventOut = ThumbnailEvent(wxEVT_THUMBNAILS_DCLICK, self.GetId()) self.GetEventHandler().ProcessEvent(eventOut) @@ -2309,14 +2306,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`MouseEvent` event to be processed. """ - + # -- drag & drop -- if self._dragging and event.Dragging() and len(self._selectedarray) > 0: files = wx.FileDataObject() for ii in range(len(self._selectedarray)): files.AddFile(opj(self.GetSelectedItem(ii).GetFullFileName())) - + source = wx.DropSource(self) source.SetData(files) source.DoDragDrop(wx.Drag_DefaultMove) @@ -2338,14 +2335,14 @@ class ScrolledThumbnail(wx.ScrolledWindow): else: self._tipwindow.SetDelay(1000) self._tipwindow.SetTip(self.GetThumbInfo(sel)) - + event.Skip() return if self._enabletooltip: if hasattr(self, "_tipwindow"): self._tipwindow.Enable(False) - + # update thumbnail self._pointed = sel @@ -2359,12 +2356,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): self._tipwindow.SetDelay(1000) self._tipwindow.Enable(True) self._tipwindow.SetTip(self.GetThumbInfo(sel)) - + self.Refresh() eventOut = ThumbnailEvent(wxEVT_THUMBNAILS_POINTED, self.GetId()) self.GetEventHandler().ProcessEvent(eventOut) event.Skip() - + def OnMouseLeave(self, event): """ @@ -2379,7 +2376,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.Refresh() eventOut = ThumbnailEvent(wxEVT_THUMBNAILS_POINTED, self.GetId()) self.GetEventHandler().ProcessEvent(eventOut) - + def OnThumbChanged(self, event): """ @@ -2387,7 +2384,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `event`: a :class:`ThumbnailEvent` event to be processed. """ - + for ii in range(len(self._items)): if self._items[ii].GetFileName() == event.GetString(): @@ -2428,9 +2425,9 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.ZoomIn() elif event.KeyCode in [wx.WXK_SUBTRACT, wx.WXK_NUMPAD_SUBTRACT]: self.ZoomOut() - + event.Skip() - + def Rotate(self, angle=90): """ @@ -2438,12 +2435,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): :param `angle`: the rotation angle for the thumbnail, in degrees. """ - + wx.BeginBusyCursor() count = 0 selected = [] - + for ii in range(len(self._items)): if self.IsSelected(ii): selected.append(self._items[ii]) @@ -2467,15 +2464,15 @@ class ScrolledThumbnail(wx.ScrolledWindow): newangle = thumb.GetRotation() + angle*pi/180 thumb.SetRotation(newangle) img = img.Rotate(newangle, (img.GetWidth()/2, img.GetHeight()/2), True) - + thumb.SetRotatedImage(img) dlg.Update(count) wx.EndBusyCursor() dlg.Destroy() - + if self.GetSelection() != -1: - self.Refresh() + self.Refresh() def DeleteFiles(self): @@ -2488,15 +2485,15 @@ class ScrolledThumbnail(wx.ScrolledWindow): dlg = wx.MessageDialog(self, 'Are you sure you want to delete the files?', 'Confirmation', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) - + if dlg.ShowModal() == wx.ID_YES: errordelete = [] count = 0 dlg.Destroy() - + wx.BeginBusyCursor() - + for ii in range(len(self._items)): if self.IsSelected(ii): thumb = self._items[ii] @@ -2506,7 +2503,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): os.remove(filename) count = count + 1 except: - errordelete.append(files) + errordelete.append(files) wx.EndBusyCursor() @@ -2534,7 +2531,7 @@ class ScrolledThumbnail(wx.ScrolledWindow): :note: If you hold down the ``Ctrl`` key, you can zoom in/out with the mouse wheel. """ - + if event.ControlDown(): if event.GetWheelRotation() > 0: self.ZoomIn() @@ -2546,12 +2543,12 @@ class ScrolledThumbnail(wx.ScrolledWindow): def ZoomOut(self): """ Zooms the thumbnails out. """ - + w, h, b = self.GetThumbSize() if w < 40 or h < 40: return - + zoom = self.GetZoomFactor() neww = float(w)/zoom newh = float(h)/zoom @@ -2559,17 +2556,17 @@ class ScrolledThumbnail(wx.ScrolledWindow): self.SetThumbSize(int(neww), int(newh)) self.OnResize(None) self._checktext = True - + self.Refresh() def ZoomIn(self): """ Zooms the thumbnails in. """ - + size = self.GetClientSize() w, h, b = self.GetThumbSize() zoom = self.GetZoomFactor() - + if w*zoom + b > size.GetWidth() or h*zoom + b > size.GetHeight(): if w*zoom + b > size.GetWidth(): neww = size.GetWidth() - 2*self._tBorder