Add an experimental conversion module from QVariant to the needed python types
[bertos.git] / wizard / qvariant_converter.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 from PyQt4.QtCore import *
13
14 def getString(qvariant):
15     string = unicode(qvariant.toString())
16     return string
17
18 def getStringList(qvariant):
19     string_list = [unicode(string) for string in qvariant.toStringList()]
20     return string_list
21
22 def getStringDict(qvariant):
23     dict_str_str = {}
24     for key, value in qvariant.toMap().items():
25         dict_str_str[unicode(key)] = unicode(value.toString())
26     return dict_str_str
27
28 def getBool(qvariant):
29     return qvariant.toBool()
30
31 def getDict(qvariant):
32     dict_str_variant = {}
33     for key, value in qvariant.toMap().items():
34         dict_str_variant[unicode(key)] = value
35     return dict_str_variant