diff options
author | Roman Lacko <backup.rlacko@gmail.com> | 2012-01-10 16:47:15 +0100 |
---|---|---|
committer | Roman Lacko <backup.rlacko@gmail.com> | 2012-01-10 16:47:15 +0100 |
commit | d085b29e937441d949c4918d7fab915dd6fcf90b (patch) | |
tree | 740352f84a4216bb91d5470a536b238f39415f43 | |
parent | e9df59462198429d2bac013028b72393a233a126 (diff) |
rcc - fix problem with non-utf8 characters in header + pysideuic - py3k port. Original author Miroslav Jezek.
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | pylupdate/main.cpp | 32 | ||||
-rw-r--r-- | pyrcc/rcc.cpp | 2 | ||||
-rw-r--r-- | pyside-uic | 5 | ||||
-rw-r--r-- | pysideuic/Compiler/qtproxies.py | 8 | ||||
-rw-r--r-- | pysideuic/objcreator.py | 6 | ||||
-rw-r--r-- | pysideuic/port_v3/__init__.py | 20 | ||||
-rw-r--r-- | pysideuic/port_v3/as_string.py | 41 | ||||
-rw-r--r-- | pysideuic/port_v3/ascii_upper.py | 30 | ||||
-rw-r--r-- | pysideuic/port_v3/invoke.py | 48 | ||||
-rw-r--r-- | pysideuic/port_v3/load_plugin.py | 39 | ||||
-rw-r--r-- | pysideuic/port_v3/proxy_base.py | 27 | ||||
-rw-r--r-- | pysideuic/port_v3/string_io.py | 24 | ||||
-rw-r--r-- | pysideuic/properties.py | 6 | ||||
-rw-r--r-- | pysideuic/uiparser.py | 16 |
15 files changed, 262 insertions, 47 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bbc8536..bcaf09f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,9 @@ option(BUILD_TESTS "Build tests." TRUE) # UIC stuff if (NOT SITE_PACKAGE) execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; \\ - print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}')" + COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; \\ + from distutils import sysconfig; \\ + print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE SITE_PACKAGE OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT SITE_PACKAGE) diff --git a/pylupdate/main.cpp b/pylupdate/main.cpp index 8bcb15b..453f41e 100644 --- a/pylupdate/main.cpp +++ b/pylupdate/main.cpp @@ -101,34 +101,6 @@ static void updateTsFiles( const MetaTranslator& fetchedTor, } } -/* The filename may contain double quotes when passing filenames with - * whitespaces. So we need to make it proper to be called with fopen() - * function. Handle them properly. -*/ -static inline const QStringList parseFileNames(const QString& line) -{ - QStringList retval; - - QString s; - unsigned int count = 0; - foreach(QChar c, line) { - if (c == '"') { /* we're still walking through the path... */ - count++; - } else if (c.isSpace() && !(count % 2)) { /* path is done! */ - /* append it to our list */ - retval << s; - s.clear(); - } else { - s += c; - } - } - - if (s.size()) - retval << s; /* append the last path to our list */ - - return retval; -} - int main( int argc, char **argv ) { QString defaultContext = "@default"; @@ -208,9 +180,9 @@ int main( int argc, char **argv ) QMap<QString, QString>::Iterator it; for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { - QStringList toks = parseFileNames(it.value()); - + QStringList toks = it.value().split(' '); QStringList::Iterator t; + for ( t = toks.begin(); t != toks.end(); ++t ) { if ( it.key() == "SOURCES" ) { fetchtr_py( (*t).toAscii(), &fetchedTor, defaultContext.toAscii(), true, codecForSource ); diff --git a/pyrcc/rcc.cpp b/pyrcc/rcc.cpp index 2fe89f2..abdf2a9 100644 --- a/pyrcc/rcc.cpp +++ b/pyrcc/rcc.cpp @@ -398,7 +398,7 @@ RCCResourceLibrary::writeHeader(FILE *out) fprintf(out, "# -*- coding: utf-8 -*-\n\n"); fprintf(out, "# Resource object code\n"); fprintf(out, "#\n"); - fprintf(out, "# Created: %s\n", QDateTime::currentDateTime().toString().toLatin1().constData()); + fprintf(out, "# Created: %s\n", QDateTime::currentDateTime().toString().toUtf8().constData()); fprintf(out, "# by: The Resource Compiler for PySide (Qt v%s)\n", QT_VERSION_STR); fprintf(out, "#\n"); fprintf(out, "# WARNING! All changes made in this file will be lost!\n"); @@ -32,7 +32,10 @@ from pysideuic import __version__ as PySideUicVersion Version = "PySide User Interface Compiler version %s, running on PySide %s." % (PySideUicVersion, PySideVersion) def main(): - from pysideuic.port_v2.invoke import invoke + if sys.hexversion >= 0x03000000: + from pysideuic.port_v3.invoke import invoke + else: + from pysideuic.port_v2.invoke import invoke parser = optparse.OptionParser(usage="pyside-uic [options] <ui-file>", version=Version) diff --git a/pysideuic/Compiler/qtproxies.py b/pysideuic/Compiler/qtproxies.py index 7f56b5b..c34b852 100644 --- a/pysideuic/Compiler/qtproxies.py +++ b/pysideuic/Compiler/qtproxies.py @@ -27,8 +27,12 @@ import re from pysideuic.Compiler.indenter import write_code from pysideuic.Compiler.misc import Literal, moduleMember -from pysideuic.port_v2.proxy_base import ProxyBase -from pysideuic.port_v2.as_string import as_string +if sys.hexversion >= 0x03000000: + from pysideuic.port_v3.proxy_base import ProxyBase + from pysideuic.port_v3.as_string import as_string +else: + from pysideuic.port_v2.proxy_base import ProxyBase + from pysideuic.port_v2.as_string import as_string i18n_strings = [] i18n_context = "" diff --git a/pysideuic/objcreator.py b/pysideuic/objcreator.py index 80c0a89..aa74023 100644 --- a/pysideuic/objcreator.py +++ b/pysideuic/objcreator.py @@ -24,7 +24,11 @@ import sys import os.path from pysideuic.exceptions import NoSuchWidgetError, WidgetPluginError -from port_v2.load_plugin import load_plugin + +if sys.hexversion >= 0x03000000: + from pysideuic.port_v3.load_plugin import load_plugin +else: + from pysideuic.port_v2.load_plugin import load_plugin # The list of directories that are searched for widget plugins. This is diff --git a/pysideuic/port_v3/__init__.py b/pysideuic/port_v3/__init__.py new file mode 100644 index 0000000..164c865 --- /dev/null +++ b/pysideuic/port_v3/__init__.py @@ -0,0 +1,20 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA diff --git a/pysideuic/port_v3/as_string.py b/pysideuic/port_v3/as_string.py new file mode 100644 index 0000000..51acccf --- /dev/null +++ b/pysideuic/port_v3/as_string.py @@ -0,0 +1,41 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +import re + + +def as_string(obj, encode=True): + if isinstance(obj, str): + s = '"' + _escape(obj) + '"' + + return s + + return str(obj) + + +_esc_regex = re.compile(r"(\"|\'|\\)") + +def _escape(text): + # This escapes any escaped single or double quote or backslash. + x = _esc_regex.sub(r"\\\1", text) + + # This replaces any '\n' with an escaped version and a real line break. + return re.sub(r'\n', r'\\n"\n"', x) diff --git a/pysideuic/port_v3/ascii_upper.py b/pysideuic/port_v3/ascii_upper.py new file mode 100644 index 0000000..00af8b8 --- /dev/null +++ b/pysideuic/port_v3/ascii_upper.py @@ -0,0 +1,30 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + + +# A translation table for converting ASCII lower case to upper case. +_ascii_trans_table = bytes.maketrans(b'abcdefghijklmnopqrstuvwxyz', + b'ABCDEFGHIJKLMNOPQRSTUVWXYZ') + + +# Convert a string to ASCII upper case irrespective of the current locale. +def ascii_upper(s): + return s.translate(_ascii_trans_table) diff --git a/pysideuic/port_v3/invoke.py b/pysideuic/port_v3/invoke.py new file mode 100644 index 0000000..5128092 --- /dev/null +++ b/pysideuic/port_v3/invoke.py @@ -0,0 +1,48 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# Copyright (C) 2009 Torsten Marek +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +from pysideuic.exceptions import NoSuchWidgetError + + +def invoke(driver): + """ Invoke the given command line driver. Return the exit status to be + passed back to the parent process. + """ + + exit_status = 1 + + try: + exit_status = driver.invoke() + + except IOError as e: + driver.on_IOError(e) + + except SyntaxError as e: + driver.on_SyntaxError(e) + + except NoSuchWidgetError as e: + driver.on_NoSuchWidgetError(e) + + except Exception as e: + driver.on_Exception(e) + + return exit_status diff --git a/pysideuic/port_v3/load_plugin.py b/pysideuic/port_v3/load_plugin.py new file mode 100644 index 0000000..b85ec76 --- /dev/null +++ b/pysideuic/port_v3/load_plugin.py @@ -0,0 +1,39 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# Copyright (C) 2009 Torsten Marek +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +from pysideuic.exceptions import WidgetPluginError + + +def load_plugin(plugin, plugin_globals, plugin_locals): + """ Load the given plugin (which is an open file). Return True if the + plugin was loaded, or False if it wanted to be ignored. Raise an exception + if there was an error. + """ + + try: + exec(plugin.read(), plugin_globals, plugin_locals) + except ImportError: + return False + except Exception as e: + raise WidgetPluginError("%s: %s" % (e.__class__, str(e))) + + return True diff --git a/pysideuic/port_v3/proxy_base.py b/pysideuic/port_v3/proxy_base.py new file mode 100644 index 0000000..928b03f --- /dev/null +++ b/pysideuic/port_v3/proxy_base.py @@ -0,0 +1,27 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# Copyright (C) 2009 Torsten Marek +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +from pysideuic.Compiler.proxy_type import ProxyType + + +class ProxyBase(metaclass=ProxyType): + pass diff --git a/pysideuic/port_v3/string_io.py b/pysideuic/port_v3/string_io.py new file mode 100644 index 0000000..cce6b3a --- /dev/null +++ b/pysideuic/port_v3/string_io.py @@ -0,0 +1,24 @@ +# This file is part of the PySide project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (C) 2010 Riverbank Computing Limited. +# +# Contact: PySide team <pyside@openbossa.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + + +# Import the StringIO object. +from io import StringIO diff --git a/pysideuic/properties.py b/pysideuic/properties.py index 36e70bb..9ef656e 100644 --- a/pysideuic/properties.py +++ b/pysideuic/properties.py @@ -27,8 +27,10 @@ import sys from pysideuic.exceptions import UnsupportedPropertyError from pysideuic.icon_cache import IconCache -from pysideuic.port_v2.ascii_upper import ascii_upper - +if sys.hexversion >= 0x03000000: + from pysideuic.port_v3.ascii_upper import ascii_upper +else: + from pysideuic.port_v2.ascii_upper import ascii_upper logger = logging.getLogger(__name__) DEBUG = logger.debug diff --git a/pysideuic/uiparser.py b/pysideuic/uiparser.py index 82258d1..9f86972 100644 --- a/pysideuic/uiparser.py +++ b/pysideuic/uiparser.py @@ -31,9 +31,9 @@ except ImportError: from xml.etree.ElementTree import parse, SubElement -from exceptions import NoSuchWidgetError -from objcreator import QObjectCreator -from properties import Properties +from pysideuic.exceptions import NoSuchWidgetError +from pysideuic.objcreator import QObjectCreator +from pysideuic.properties import Properties logger = logging.getLogger(__name__) @@ -559,6 +559,11 @@ class UIParser(object): elif isinstance(w, QtGui.QTableWidget): text = self.wprops.getProperty(elem, "text") + icon = self.wprops.getProperty(elem, "icon") + flags = self.wprops.getProperty(elem, "flags") + check_state = self.wprops.getProperty(elem, "checkState") + background = self.wprops.getProperty(elem, "background") + foreground = self.wprops.getProperty(elem, "foreground") item = self.factory.createQObject("QTableWidgetItem", "item", (), False) @@ -570,23 +575,18 @@ class UIParser(object): row = int(elem.attrib["row"]) col = int(elem.attrib["column"]) - icon = self.wprops.getProperty(elem, "icon") if icon: item.setIcon(icon) - flags = self.wprops.getProperty(elem, "flags") if flags: item.setFlags(flags) - check_state = self.wprops.getProperty(elem, "checkState") if check_state: item.setCheckState(check_state) - background = self.wprops.getProperty(elem, "background") if background: item.setBackground(background) - foreground = self.wprops.getProperty(elem, "foreground") if foreground: item.setForeground(foreground) |