Skip to content

Commit

Permalink
python fixes:
Browse files Browse the repository at this point in the history
* issues identified by pyflakes (star and unused imports)
* pyqtwrapper: add QtSvg
* some exceptions e.message => unicode(e)
* some translations tr("..." % foo) => tr("...") % foo
* TODO:
  python/console/console_sci.py:547 QsciScintillaCompat?
  python/plugins/db_manager/dlg_query_builder.py:304 pop_up_error?
  • Loading branch information
jef-n committed Mar 15, 2016
1 parent cc5219b commit c6d9217
Show file tree
Hide file tree
Showing 162 changed files with 269 additions and 447 deletions.
1 change: 1 addition & 0 deletions python/PyQt/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ SET(PYQT_COMPAT_FILES
QtXml.py
QtSql.py
QtTest.py
QtSvg.py
Qsci.py
uic/__init__.py
uic/pyuic.py
Expand Down
10 changes: 2 additions & 8 deletions python/PyQt/PyQt4/QtCore.py
Expand Up @@ -24,14 +24,8 @@
__revision__ = '$Format:%H$'

import sip

try:
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
for api in apis:
sip.setapi(api, 2)
except ValueError:
# API has already been set so we can't set it again.
pass
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
sip.setapi(api, 2)

from PyQt4.QtCore import *
from PyQt4.QtGui import QItemSelectionModel, QSortFilterProxyModel
Expand Down
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/QtSvg.py
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
QtSvg.py
---------------------
Date : March 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'March 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtSvg import *
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/QtSvg.py
@@ -0,0 +1 @@
from PyQt5.QtSvg import *
9 changes: 2 additions & 7 deletions python/__init__.py
Expand Up @@ -25,13 +25,8 @@

import sip

try:
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
for api in apis:
sip.setapi(api, 2)
except ValueError:
# API has already been set so we can't set it again.
pass
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
sip.setapi(api, 2)

from qgis.core import QgsFeature, QgsGeometry

Expand Down
2 changes: 1 addition & 1 deletion python/console/console_compile_apis.py
Expand Up @@ -21,7 +21,7 @@

import os

from PyQt4.Qsci import QsciAPIs, QsciLexerPython
from PyQt4.Qsci import QsciAPIs
from PyQt4.QtGui import QDialog, QDialogButtonBox
from PyQt4.QtCore import QCoreApplication

Expand Down
2 changes: 1 addition & 1 deletion python/console/console_editor.py
Expand Up @@ -19,7 +19,7 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, QDir, SIGNAL
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, SIGNAL
from PyQt4.QtGui import QFont, QFontMetrics, QColor, QShortcut, QKeySequence, QMenu, QApplication, QCursor, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
from PyQt4.Qsci import (QsciScintilla,
QsciLexerPython,
Expand Down
2 changes: 1 addition & 1 deletion python/console/console_sci.py
Expand Up @@ -544,7 +544,7 @@ def dropEvent(self, e):
e.setDropAction(Qt.CopyAction)
e.accept()
else:
QsciScintillaCompat.dropEvent(self, e)
QsciScintillaCompat.dropEvent(self, e) # FIXME

def insertFromDropPaste(self, textDP):
pasteList = unicode(textDP).splitlines()
Expand Down
3 changes: 0 additions & 3 deletions python/plugins/GdalTools/GdalTools.py
Expand Up @@ -23,9 +23,6 @@
from qgis.core import QGis
import qgis.utils

# load icons for actions
import resources_rc

# are all dependencies satisfied?
valid = True

Expand Down
5 changes: 0 additions & 5 deletions python/plugins/db_manager/db_manager_plugin.py
Expand Up @@ -23,11 +23,6 @@
from PyQt4.QtCore import Qt, QObject, SIGNAL
from PyQt4.QtGui import QAction, QIcon, QApplication

try:
from . import resources_rc
except ImportError:
pass


class DBManagerPlugin:

Expand Down
7 changes: 1 addition & 6 deletions python/plugins/db_manager/db_model.py
Expand Up @@ -21,7 +21,7 @@
"""

from PyQt4.QtCore import Qt, QObject, SIGNAL, qDebug, QByteArray, QMimeData, QDataStream, QIODevice, QFileInfo, \
QAbstractItemModel, QModelIndex, QSettings
QAbstractItemModel, QModelIndex
from PyQt4.QtGui import QApplication, QIcon, QMessageBox

from .db_plugins import supportedDbTypes, createDbPlugin
Expand All @@ -30,11 +30,6 @@

import qgis.core

try:
from . import resources_rc
except ImportError:
pass


class TreeItem(QObject):

Expand Down
5 changes: 1 addition & 4 deletions python/plugins/db_manager/db_plugins/oracle/connector.py
Expand Up @@ -23,6 +23,7 @@
***************************************************************************/
"""

from PyQt4.QtCore import QPyNullVariant
from PyQt4.QtSql import QSqlDatabase

from ..connector import DBConnector
Expand Down Expand Up @@ -238,8 +239,6 @@ def getRawTablePrivileges(self, table, owner, grantee):
user.
"""
result = [False, False, False, False]
if owner != self.user:
prefix = u"USER"
# Inspect in all tab privs
sql = u"""
SELECT DISTINCT PRIVILEGE
Expand Down Expand Up @@ -338,7 +337,6 @@ def getTables(self, schema=None, add_sys_tables=False):
# get all non geographic tables and views
prefix = u"ALL"
owner = u"o.owner"
metatable = u"tab_columns"
where = u""
if self.userTablesOnly:
prefix = u"USER"
Expand Down Expand Up @@ -1752,5 +1750,4 @@ def getSqlDictionary(self):

def getQueryBuilderDictionary(self):
from .sql_dictionary import getQueryBuilderDictionary

return getQueryBuilderDictionary()
6 changes: 2 additions & 4 deletions python/plugins/db_manager/db_plugins/oracle/data_model.py
Expand Up @@ -23,12 +23,10 @@
***************************************************************************/
"""

from PyQt4.QtCore import QTime
from PyQt4.QtCore import QTime, SIGNAL

from ..data_model import TableDataModel, SqlResultModel, \
BaseTableModel, TableFieldsModel, SimpleTableModel
from ..data_model import TableDataModel, SqlResultModel, BaseTableModel
from ..plugin import DbError
from qgis.core import *


class ORTableDataModel(TableDataModel):
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/db_manager/db_plugins/oracle/info_model.py
Expand Up @@ -26,10 +26,9 @@
from PyQt4.QtGui import QApplication
from qgis.core import QGis

from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo, \
SchemaInfo
from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo
from ..html_elems import HtmlContent, HtmlSection, HtmlParagraph, \
HtmlList, HtmlTable, HtmlTableHeader, HtmlTableCol
HtmlTable, HtmlTableHeader, HtmlTableCol

# Syntax Highlight for VIEWS/MVIEWS
from pygments import highlight
Expand Down
15 changes: 5 additions & 10 deletions python/plugins/db_manager/db_plugins/oracle/plugin.py
Expand Up @@ -26,19 +26,15 @@
# this will disable the dbplugin if the connector raise an ImportError
from .connector import OracleDBConnector

from PyQt4.QtCore import QSettings
from PyQt4.QtGui import QIcon, QAction, QApplication, QMessageBox
from PyQt4.QtCore import Qt, QSettings, QPyNullVariant
from PyQt4.QtGui import QIcon, QAction, QApplication, QMessageBox, QKeySequence

from qgis.core import QgsVectorLayer

from ..plugin import ConnectionError, InvalidDataException, DBPlugin, \
Database, Schema, Table, VectorTable, TableField, TableConstraint, \
TableIndex, TableTrigger, TableRule

try:
from . import resources_rc
except ImportError:
pass
TableIndex, TableTrigger

from ..html_elems import HtmlParagraph, HtmlList, HtmlTable

from qgis.core import QgsCredentials

Expand Down Expand Up @@ -198,7 +194,6 @@ def sqlResultModel(self, sql, parent):
def toSqlLayer(self, sql, geomCol, uniqueCol,
layerName=u"QueryLayer", layerType=None,
avoidSelectById=False, filter=""):
from qgis.core import QgsMapLayer, QgsVectorLayer

uri = self.uri()
con = self.database().connector
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/plugin.py
Expand Up @@ -289,7 +289,7 @@ def registerAllActions(self, mainWindow):
def registerSubPluginActions(self, mainWindow):
# load plugins!
try:
exec (u"from .%s.plugins import load" % self.dbplugin().typeName())
exec (u"from .%s.plugins import load" % self.dbplugin().typeName(), globals())
except ImportError:
pass
else:
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -30,11 +30,6 @@
from ..plugin import ConnectionError, InvalidDataException, DBPlugin, Database, Schema, Table, VectorTable, RasterTable, \
TableField, TableConstraint, TableIndex, TableTrigger, TableRule

try:
from . import resources_rc
except ImportError:
pass

import re


Expand Down
Expand Up @@ -23,7 +23,7 @@
from PyQt4.QtGui import QApplication

from ..info_model import DatabaseInfo
from ..html_elems import HtmlTable
from ..html_elems import HtmlTable, HtmlParagraph


class SLDatabaseInfo(DatabaseInfo):
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/db_manager/db_plugins/spatialite/plugin.py
Expand Up @@ -31,11 +31,6 @@
from ..plugin import DBPlugin, Database, Table, VectorTable, RasterTable, TableField, TableIndex, TableTrigger, \
InvalidDataException

try:
from . import resources_rc
except ImportError:
pass


def classFactory():
return SpatiaLiteDBPlugin
Expand Down
31 changes: 6 additions & 25 deletions python/plugins/db_manager/db_plugins/vlayers/connector.py
Expand Up @@ -19,31 +19,12 @@
***************************************************************************/
"""

from PyQt4.QtCore import (
QFile,
QUrl,
QTemporaryFile
)
from PyQt4.QtGui import (
QApplication
)

from ..connector import (
DBConnector
)
from ..plugin import (
ConnectionError,
DbError,
Table
)

from qgis.core import (
QGis,
QgsMapLayerRegistry,
QgsMapLayer,
QgsCoordinateReferenceSystem,
QgsDataSourceURI
)
from PyQt4.QtCore import QUrl, QTemporaryFile

from ..connector import DBConnector
from ..plugin import Table

from qgis.core import QGis, QgsDataSourceURI, QgsVirtualLayerDefinition, QgsMapLayerRegistry, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem

import sqlite3

Expand Down
4 changes: 1 addition & 3 deletions python/plugins/db_manager/db_plugins/vlayers/data_model.py
Expand Up @@ -26,9 +26,7 @@
from ..plugin import DbError

from PyQt4.QtCore import QUrl, QTime, QTemporaryFile
from qgis.core import QgsProviderRegistry, QgsErrorMessage, QGis, QgsVectorLayer

import os
from qgis.core import QGis, QgsVectorLayer


class LTableDataModel(TableDataModel):
Expand Down
11 changes: 3 additions & 8 deletions python/plugins/db_manager/db_plugins/vlayers/plugin.py
Expand Up @@ -22,16 +22,11 @@
# this will disable the dbplugin if the connector raise an ImportError
from .connector import VLayerConnector

from PyQt4.QtCore import Qt, QSettings, QUrl
from PyQt4.QtGui import QIcon, QApplication, QAction
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QIcon
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
from qgis.gui import QgsMessageBar

from ..plugin import DBPlugin, Database, Table, VectorTable, RasterTable, TableField, TableIndex, TableTrigger, InvalidDataException
try:
from . import resources_rc
except ImportError:
pass
from ..plugin import DBPlugin, Database, Table, VectorTable, TableField


def classFactory():
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_tree.py
Expand Up @@ -20,7 +20,7 @@
***************************************************************************/
"""

from PyQt4.QtCore import SIGNAL, SLOT, QSettings, Qt
from PyQt4.QtCore import SIGNAL, SLOT
from PyQt4.QtGui import QWidget, QTreeView, QMenu, QLabel

from qgis.core import QgsMapLayerRegistry, QgsMessageLog
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/db_manager/dlg_query_builder.py
Expand Up @@ -21,8 +21,8 @@
Query builder dialog, based on the QSpatialite plugin (GPLv2+) by Romain Riviere
"""

from PyQt.QtCore import QObject, QEvent
from PyQt.QtWidgets import QDialog, QMessageBox
from PyQt4.QtCore import QObject, QEvent, SIGNAL
from PyQt4.QtGui import QDialog, QMessageBox, QTextEdit

from .ui.ui_DlgQueryBuilder import Ui_DbManagerQueryBuilderDlg as Ui_Dialog
from .db_plugins.plugin import VectorTable
Expand Down Expand Up @@ -301,7 +301,7 @@ def use_rtree(self):
tab_idx = idx.split(".")[0][1:-1] # remove "
col_idx = idx.split(".")[1][1:-1] # remove '
except:
pop_up_error("All fields are necessary", self)
pop_up_error("All fields are necessary", self) # FIXME
tgt = self.ui.table_target.currentText()
if tgt in (None, "", " ", "Table (Target)"):
return
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -22,9 +22,9 @@
***************************************************************************/
"""

from PyQt4.QtCore import Qt, QObject, QSettings, QByteArray, SIGNAL, pyqtSignal
from PyQt4.QtCore import Qt, pyqtSignal
from PyQt4.QtGui import QDialog, QWidget, QAction, QKeySequence, \
QDialogButtonBox, QApplication, QCursor, QMessageBox, QClipboard, QInputDialog, QIcon, QStyledItemDelegate, QStandardItemModel, QStandardItem
QApplication, QCursor, QClipboard, QInputDialog, QIcon, QStyledItemDelegate, QStandardItemModel, QStandardItem
from PyQt4.Qsci import QsciAPIs

from qgis.core import QgsProject
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
Expand Up @@ -25,7 +25,7 @@

__revision__ = '$Format:%H$'

from qgis.core import *
from qgis.core import QgsMapLayerRegistry
from PyQt4.QtGui import QWidget, QVBoxLayout, QPushButton, QLabel, QPlainTextEdit, QLineEdit, QComboBox, QCheckBox
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
Expand Down

0 comments on commit c6d9217

Please sign in to comment.