summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-12-04 21:01:34 +0100
committerTreeki <treeki@gmail.com>2011-12-04 21:01:34 +0100
commit5e44650b39381787e4b0ae769e7e194bca83f717 (patch)
tree6610c4cf143de37f59a58a72b0526b04b7aa87c3
parentbd62c887e956b658d3ec1b47099fa07882386d1f (diff)
downloadkoopatlas-5e44650b39381787e4b0ae769e7e194bca83f717.tar.gz
koopatlas-5e44650b39381787e4b0ae769e7e194bca83f717.zip
moved Pixmap dumping into mapfile.py, added QString dumping
-rw-r--r--src/mapdata.py15
-rw-r--r--src/mapfile.py27
2 files changed, 25 insertions, 17 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index ea62111..ec0feff 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -7,21 +7,6 @@ TILE_SIZE = (24,24)
MAP_SIZE_IN_TILES = (512,512)
MAP_SIZE = (MAP_SIZE_IN_TILES[0] * TILE_SIZE[0], MAP_SIZE_IN_TILES[1] * TILE_SIZE[1])
-@mapfile.dumpClassAs(QtGui.QPixmap, 'pixmap')
-def dumpPixmap(pm):
- buf = QtCore.QBuffer()
- buf.open(buf.WriteOnly)
- pm.save(buf, 'PNG')
- data = str(buf.data())
- buf.close()
- return {'png': base64.b64encode(data)}
-
-@mapfile.loadClassFrom('pixmap')
-def loadPixmap(source):
- pm = QtGui.QPixmap()
- pm.loadFromData(base64.b64decode(source['png']), 'PNG')
- return pm
-
@mapfile.dumpable('layer')
class KPLayer(object):
__dump_attribs__ = ('name', '_visible')
diff --git a/src/mapfile.py b/src/mapfile.py
index eb05a4a..16d57db 100644
--- a/src/mapfile.py
+++ b/src/mapfile.py
@@ -7,7 +7,7 @@ DUMPABLE_CLASS_NAMES = {}
DUMPABLE_PROXIES = {}
LOADABLE_PROXIES = {}
-def dumpClassAs(cls, name):
+def dumpClassAs(cls, name=None):
def __add_it(function):
DUMPABLE_PROXIES[cls] = (name, function)
return function
@@ -39,7 +39,8 @@ def dump(rootObj):
return piece
dest = dumpFunc(piece)
- dest['_t'] = dumpName
+ if dumpName is not None:
+ dest['_t'] = dumpName
return dest
@@ -94,3 +95,25 @@ def load(string):
return root
+
+
+
+@dumpClassAs(QtGui.QPixmap, 'pixmap')
+def dumpPixmap(pm):
+ buf = QtCore.QBuffer()
+ buf.open(buf.WriteOnly)
+ pm.save(buf, 'PNG')
+ data = str(buf.data())
+ buf.close()
+ return {'png': base64.b64encode(data)}
+
+@loadClassFrom('pixmap')
+def loadPixmap(source):
+ pm = QtGui.QPixmap()
+ pm.loadFromData(base64.b64decode(source['png']), 'PNG')
+ return pm
+
+@dumpClassAs(QtCore.QString)
+def dumpQString(string):
+ return str(string)
+