home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pypil112.zip
/
PIL-1.1.2.zip
/
Lib
/
site-packages
/
PIL
/
ImageTk.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2001-12-25
|
7KB
|
192 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.2)
import Tkinter
import Image
_pilbitmap_ok = None
def _pilbitmap_check():
global _pilbitmap_ok
if _pilbitmap_ok is None:
try:
im = Image.new('1', (1, 1))
Tkinter.BitmapImage(data = 'PIL:%d' % im.im.id)
_pilbitmap_ok = 1
except:
_pilbitmap_ok = 0
return _pilbitmap_ok
class PhotoImage:
def __init__(self, image = None, size = None, **kw):
if image is None:
if kw.has_key('file'):
image = Image.open(kw['file'])
del kw['file']
elif kw.has_key('data'):
StringIO = StringIO
import StringIO
image = Image.open(StringIO(kw['data']))
del kw['data']
if hasattr(image, 'mode') and hasattr(image, 'size'):
mode = image.mode
if mode == 'P':
image.load()
try:
mode = image.palette.mode
except AttributeError:
mode = 'RGB'
size = image.size
(kw['width'], kw['height']) = size
else:
mode = image
image = None
if mode not in [
'1',
'L',
'RGB',
'RGBA']:
mode = Image.getmodebase(mode)
self._PhotoImage__mode = mode
self._PhotoImage__size = size
self._PhotoImage__photo = apply(Tkinter.PhotoImage, (), kw)
if image:
self.paste(image)
def __del__(self):
name = self._PhotoImage__photo.name
self._PhotoImage__photo.name = None
try:
self._PhotoImage__photo.tk.call('image', 'delete', name)
except:
pass
def __str__(self):
return str(self._PhotoImage__photo)
def width(self):
return self._PhotoImage__size[0]
def height(self):
return self._PhotoImage__size[1]
def paste(self, im, box = None):
im.load()
image = im.im
if image.isblock() and im.mode == self._PhotoImage__mode:
block = image
else:
block = image.new_block(self._PhotoImage__mode, im.size)
image.convert2(block, image)
tk = self._PhotoImage__photo.tk
try:
tk.call('PyImagingPhoto', self._PhotoImage__photo, block.id)
except Tkinter.TclError:
v = None
try:
import _imagingtk
try:
_imagingtk.tkinit(tk.interpaddr(), 1)
except AttributeError:
_imagingtk.tkinit(id(tk), 0)
tk.call('PyImagingPhoto', self._PhotoImage__photo, block.id)
except (ImportError, AttributeError, Tkinter.TclError):
raise
class BitmapImage:
def __init__(self, image = None, **kw):
if image is None:
if kw.has_key('file'):
image = Image.open(kw['file'])
del kw['file']
elif kw.has_key('data'):
StringIO = StringIO
import StringIO
image = Image.open(StringIO(kw['data']))
del kw['data']
self._BitmapImage__mode = image.mode
self._BitmapImage__size = image.size
if _pilbitmap_check():
image.load()
kw['data'] = 'PIL:%d' % image.im.id
self._BitmapImage__im = image
else:
kw['data'] = image.tobitmap()
self._BitmapImage__photo = apply(Tkinter.BitmapImage, (), kw)
def __del__(self):
name = self._BitmapImage__photo.name
self._BitmapImage__photo.name = None
try:
self._BitmapImage__photo.tk.call('image', 'delete', name)
except:
pass
def width(self):
return self._BitmapImage__size[0]
def height(self):
return self._BitmapImage__size[1]
def __str__(self):
return str(self._BitmapImage__photo)
def _show(image, title):
class UI(Tkinter.Label):
def __init__(self, master, im):
if im.mode == '1':
self.image = BitmapImage(im, foreground = 'white', master = master)
else:
self.image = PhotoImage(im, master = master)
Tkinter.Label.__init__(self, master, image = self.image, bg = 'black', bd = 0)
if not (Tkinter._default_root):
raise IOError, 'tkinter not initialized'
top = Tkinter.Toplevel()
if title:
top.title(title)
UI(top, image).pack()