Change some strings.
[bertos.git] / wizard / qvariant_converter_old.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 """
37 Awful module for the conversion from python types to qvariant, for make the wizard compatible with older version of pyqt (<= 4.4.3)
38 """
39
40 from PyQt4.QtCore import *
41 import pickle
42
43 def getString(qvariant):
44     if type(qvariant) == str or type(qvariant) == unicode:
45         string = qvariant
46     else:
47         string = unicode(qvariant.toString())
48     return string
49
50 def convertString(string):
51     return QVariant(string)
52
53 def getStringList(qvariant):
54     string_list = []
55     if type(qvariant) == list:
56         string_list = qvariant
57     else:
58         for element in qvariant.toStringList():
59             string_list.append(unicode(element))
60     return string_list
61
62 def convertStringList(string_list):
63     result = []
64     for element in string_list:
65         result.append(QString(element))
66     return QVariant(QStringList(result))
67
68 def getStringDict(qvariant):
69     a = str(qvariant.toByteArray())
70     if len(a) == 0:
71         dict_str_str = {}
72     else:
73         dict_str_str = pickle.loads(a)
74     return dict_str_str
75
76 def convertStringDict(dict_str_str):
77     a = pickle.dumps(dict_str_str)
78     return QVariant(QByteArray(a))
79
80 def getBool(qvariant):
81     return qvariant.toBool()
82
83 def convertBool(boolean):
84     return QVariant(boolean)
85
86 def getBoolDict(qvariant):
87     a = str(qvariant.toByteArray())
88     if len(a) == 0:
89         dict_str_bool = {}
90     else:
91         dict_str_bool = pickle.loads(a)
92     return dict_str_bool
93
94 def convertBoolDict(dict_str_bool):
95     a = pickle.dumps(dict_str_bool)
96     return QVariant(QByteArray(a))
97
98 def getDict(qvariant):
99     a = str(qvariant.toByteArray())
100     if len(a) == 0:
101         dict_str_bool = {}
102     else:
103         dict_str_bool = pickle.loads(a)
104     return dict_str_bool
105
106 def convertDict(dict_str_variant):
107     a = pickle.dumps(dict_str_variant)
108     return QVariant(QByteArray(a))