Modify the getString function
[bertos.git] / wizard / qvariant_converter_old.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 """
13 Awful module for the conversion from python types to qvariant, for make the wizard compatible with older version of pyqt (<= 4.4.3)
14 """
15
16 from PyQt4.QtCore import *
17 import pickle
18
19 def getString(qvariant):
20     if type(qvariant) == str or type(qvariant) == unicode:
21         string = qvariant
22     else:
23         string = unicode(qvariant.toString())
24     return string
25
26 def convertString(string):
27     return QVariant(string)
28
29 def getStringList(qvariant):
30     string_list = []
31     if type(qvariant) == list:
32         string_list = qvariant
33     else:
34         for element in qvariant.toStringList():
35             string_list.append(unicode(element))
36     return string_list
37
38 def convertStringList(string_list):
39     result = []
40     for element in string_list:
41         result.append(QString(element))
42     return QVariant(QStringList(result))
43
44 def getStringDict(qvariant):
45     if len(a) == 0:
46         dict_str_bool = {}
47     else:
48         dict_str_bool = pickle.loads(a)
49     return dict_str_bool
50
51 def convertStringDict(string_dict):
52     a = pickle.dumps(dict_str_str)
53     return QVariant(QByteArray(a))
54
55 def getBool(qvariant):
56     return qvariant.toBool()
57
58 def convertBool(boolean):
59     return QVariant(boolean)
60
61 def getBoolDict(qvariant):
62     a = str(qvariant.toByteArray())
63     if len(a) == 0:
64         dict_str_bool = {}
65     else:
66         dict_str_bool = pickle.loads(a)
67     return dict_str_bool
68
69 def convertBoolDict(dict_str_bool):
70     a = pickle.dumps(dict_str_bool)
71     return QVariant(QByteArray(a))
72
73 def getDict(qvariant):
74     a = str(qvariant.toByteArray())
75     if len(a) == 0:
76         dict_str_bool = {}
77     else:
78         dict_str_bool = pickle.loads(a)
79     return dict_str_bool
80
81 def convertDict(dict_str_variant):
82     a = pickle.dumps(dict_str_variant)
83     return QVariant(QByteArray(a))