-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImagePanel.py
96 lines (79 loc) · 3.11 KB
/
ImagePanel.py
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
################################################################################
# Copyright 2010 Andreas Neustifter (andreas.neustifter@gmail.com)
#
# This file is part of PhotoImport.
#
# PhotoImport is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# PhotoImport is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PhotoImport. If not, see <http://www.gnu.org/licenses/>.
################################################################################
""" An extension to the wx.Panel that easily shows images. """
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Sun Nov 7 13:00:52 2010
import wx
import io
import logging
import ExifHandler
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class ImagePanel(wx.Panel):
""" An extension to the wx.Panel that easily shows images. """
def __init__(self, *args, **kwds):
# begin wxGlade: ImagePanel.__init__
kwds["style"] = wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.__set_properties()
self.__do_layout()
# end wxGlade
self._imagedata = None
self._drawdata = None
self._loadedimage = ""
self.Bind(wx.EVT_PAINT, self.evt_onpaint, self)
def __set_properties(self):
# begin wxGlade: ImagePanel.__set_properties
pass
# end wxGlade
def __do_layout(self):
# begin wxGlade: ImagePanel.__do_layout
pass
# end wxGlade
def display(self, imagename):
""" Loads image from preview or file and converts it properly. """
if self._loadedimage != imagename:
self._imagedata = ExifHandler.getthumbnail(imagename)
if self._imagedata is not None:
self._loadedimage = imagename
try:
imagewidth = (float)(self._imagedata.GetWidth())
imageheigth = (float)(self._imagedata.GetHeight())
panelwidth, panelheight = self.GetSizeTuple()
scale = imagewidth/(float)(panelwidth)
if (imageheigth/panelheight) > scale:
scale = imageheigth/(float)(panelheight)
self._drawdata = self._imagedata.Copy()
self._drawdata.Rescale(imagewidth/scale, imageheigth/scale)
self.Refresh(True)
except:
logging.error("Can not convert image, no preview.")
def evt_onpaint(self, event):
"""
This paints the panel.
"""
try:
drawingcontext = wx.PaintDC(self)
if self._imagedata:
drawingcontext.DrawBitmap(self._drawdata.ConvertToBitmap(), 0, 0)
except:
logging.error("Can not display image, no preview.")
# end of class ImagePanel