-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmapzip.py
More file actions
33 lines (28 loc) · 706 Bytes
/
mapzip.py
File metadata and controls
33 lines (28 loc) · 706 Bytes
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
#!/usr/bin/python3
import os
import zipfile
import io
import wx
class MapZip() :
def __init__( self, fname ) :
self.fname = fname
if not os.path.isfile( fname ) :
self.zipf = None
self.namelist = []
else :
self.zipf = zipfile.ZipFile( fname, 'r' )
self.namelist = self.zipf.namelist()
def hasfile( self, fname ) :
return fname in self.namelist
# load fname and return as wx.Image
def load( self, fname ) :
assert self.hasfile( fname )
zs = self.zipf.open( fname ) # open stream
# but zs doesn't support seek() operation.
# read onto a buffer to support seek().
s = io.BytesIO( zs.read() )
img = wx.Image()
img.LoadFile( s )
s.close()
zs.close()
return img