From 4fa9bf0336b75d453fd0ed8ab6a6db33b70a6aa9 Mon Sep 17 00:00:00 2001 From: duplo Date: Mon, 12 Jan 2009 17:40:03 +0000 Subject: [PATCH] Attempt to resolve the QVariant conversion problems on pyqt <= 4.4.3 git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2160 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/qvariant_converter_old.py | 52 ++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/wizard/qvariant_converter_old.py b/wizard/qvariant_converter_old.py index 0a41919d..7d3afe0f 100644 --- a/wizard/qvariant_converter_old.py +++ b/wizard/qvariant_converter_old.py @@ -12,25 +12,38 @@ from PyQt4.QtCore import * def getString(qvariant): - string = qvariant.toPyObject() + string = unicode(qvariant.toString()) return string def convertString(string): return QVariant(string) def getStringList(qvariant): - string_list = qvariant.toPyObject() + string_list = [] + for element in qvariant.toStringList(): + string_list.append(unicode(element)) return string_list def convertStringList(string_list): - return QVariant(string_list) + result = [] + for element in string_list: + result.append(QString(element)) + return QVariant(QStringList(result)) def getStringDict(qvariant): - dict_str_str = qvariant.toPyObject() + dict_str_str = {} + qvariant_item = qvariant.toPyObject() + if qvariant_item == NotImplemented: + qvariant_item = {} + for key, value in qvariant_item.items(): + dict_str_str[unicode(key)] = unicode(value.toString()) return dict_str_str def convertStringDict(string_dict): - return QVariant(string_dict) + result = {} + for key, value in string_dict.items(): + result[QString(key)] = QVariant(QString(value)) + return QVariant(result) def getBool(qvariant): return qvariant.toBool() @@ -39,15 +52,36 @@ def convertBool(boolean): return QVariant(boolean) def getBoolDict(qvariant): - dict_str_bool = qvariant.toPyObject() + dict_str_bool = {} + qvariant_item = qvariant.toPyObject() + if qvariant_item == NotImplemented: + qvariant_item = {} + for key, value in qvariant_item.items(): + dict_str_bool[unicode(key)] = value.toBool() return dict_str_bool def convertBoolDict(dict_str_bool): - return QVariant(dict_str_bool) + result = {} + for key, value in dict_str_bool: + result[QString(key)] = QVariant(value) + return QVariant(result) def getDict(qvariant): - dict_str_variant = qvariant.toPyObject() + dict_str_variant = {} + qvariant_item = qvariant.toPyObject() + if qvariant_item == NotImplemented: + qvariant_item = {} + for key, value in qvariant_item.items(): + dict_str_variant[unicode(key)] = value return dict_str_variant def convertDict(dict_str_variant): - return QVariant(dict_str_variant) + result = {} + for key, value in dict_str_variant.items(): + if type(value) == str or type(value) == unicode: + result[QString(key)] = QVariant(QString(value)) + elif type(value) == list: + result[QString(key)] = QVariant(QStringList(value)) + elif type(value) == dict: + result[QString(key)] = QVariant(convertDict(value)) + return QVariant(result) -- 2.25.1