import wx import os from tilefetcher import TileFetcher class TileFetcher_Disc(TileFetcher): dirnamelength = 2 saveextension = ".png" savetype = wx.BITMAP_TYPE_PNG def _init(self, path): self.path = path def getpath(self, coords): zoomdir = "zoom-%d" % coords.zoom dirid = str(hash(coords) % (10 ** self.dirnamelength)) filename = "tile-%d-%d-%d" % (coords.x, coords.y, coords.zoom) filename += self.saveextension return os.path.join(self.path, zoomdir, dirid, filename) def has_tile(self, coords): path = self.getpath(coords) return os.path.exists(path) def _get_tile(self, coords, block): path = self.getpath(coords) image = wx.Image(path) return image def _put_tile(self, coords, image): path = self.getpath(coords) directory = os.path.dirname(path) if not os.path.isdir(directory): os.makedirs(os.path.dirname(path)) image.SaveFile(path, self.savetype)