Skip to content

Commit c6d9217

Browse files
committed
python fixes:
* 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?
1 parent cc5219b commit c6d9217

File tree

162 files changed

+269
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+269
-447
lines changed

python/PyQt/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SET(PYQT_COMPAT_FILES
1313
QtXml.py
1414
QtSql.py
1515
QtTest.py
16+
QtSvg.py
1617
Qsci.py
1718
uic/__init__.py
1819
uic/pyuic.py

python/PyQt/PyQt4/QtCore.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
__revision__ = '$Format:%H$'
2525

2626
import sip
27-
28-
try:
29-
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
30-
for api in apis:
31-
sip.setapi(api, 2)
32-
except ValueError:
33-
# API has already been set so we can't set it again.
34-
pass
27+
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
28+
sip.setapi(api, 2)
3529

3630
from PyQt4.QtCore import *
3731
from PyQt4.QtGui import QItemSelectionModel, QSortFilterProxyModel

python/PyQt/PyQt4/QtSvg.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
QtSvg.py
6+
---------------------
7+
Date : March 2016
8+
Copyright : (C) 2016 by Jürgen E. Fischer
9+
Email : jef at norbit dot de
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Jürgen E. Fischer'
21+
__date__ = 'March 2016'
22+
__copyright__ = '(C) 2016, Jürgen E. Fischer'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
from PyQt4.QtSvg import *

python/PyQt/PyQt5/QtSvg.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from PyQt5.QtSvg import *

python/__init__.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@
2525

2626
import sip
2727

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

3631
from qgis.core import QgsFeature, QgsGeometry
3732

python/console/console_compile_apis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import os
2323

24-
from PyQt4.Qsci import QsciAPIs, QsciLexerPython
24+
from PyQt4.Qsci import QsciAPIs
2525
from PyQt4.QtGui import QDialog, QDialogButtonBox
2626
from PyQt4.QtCore import QCoreApplication
2727

python/console/console_editor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Some portions of code were taken from https://code.google.com/p/pydee/
2020
"""
2121

22-
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, QDir, SIGNAL
22+
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, SIGNAL
2323
from PyQt4.QtGui import QFont, QFontMetrics, QColor, QShortcut, QKeySequence, QMenu, QApplication, QCursor, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
2424
from PyQt4.Qsci import (QsciScintilla,
2525
QsciLexerPython,

python/console/console_sci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def dropEvent(self, e):
544544
e.setDropAction(Qt.CopyAction)
545545
e.accept()
546546
else:
547-
QsciScintillaCompat.dropEvent(self, e)
547+
QsciScintillaCompat.dropEvent(self, e) # FIXME
548548

549549
def insertFromDropPaste(self, textDP):
550550
pasteList = unicode(textDP).splitlines()

python/plugins/GdalTools/GdalTools.py

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
from qgis.core import QGis
2424
import qgis.utils
2525

26-
# load icons for actions
27-
import resources_rc
28-
2926
# are all dependencies satisfied?
3027
valid = True
3128

python/plugins/db_manager/db_manager_plugin.py

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
from PyQt4.QtCore import Qt, QObject, SIGNAL
2424
from PyQt4.QtGui import QAction, QIcon, QApplication
2525

26-
try:
27-
from . import resources_rc
28-
except ImportError:
29-
pass
30-
3126

3227
class DBManagerPlugin:
3328

python/plugins/db_manager/db_model.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"""
2222

2323
from PyQt4.QtCore import Qt, QObject, SIGNAL, qDebug, QByteArray, QMimeData, QDataStream, QIODevice, QFileInfo, \
24-
QAbstractItemModel, QModelIndex, QSettings
24+
QAbstractItemModel, QModelIndex
2525
from PyQt4.QtGui import QApplication, QIcon, QMessageBox
2626

2727
from .db_plugins import supportedDbTypes, createDbPlugin
@@ -30,11 +30,6 @@
3030

3131
import qgis.core
3232

33-
try:
34-
from . import resources_rc
35-
except ImportError:
36-
pass
37-
3833

3934
class TreeItem(QObject):
4035

python/plugins/db_manager/db_plugins/oracle/connector.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
***************************************************************************/
2424
"""
2525

26+
from PyQt4.QtCore import QPyNullVariant
2627
from PyQt4.QtSql import QSqlDatabase
2728

2829
from ..connector import DBConnector
@@ -238,8 +239,6 @@ def getRawTablePrivileges(self, table, owner, grantee):
238239
user.
239240
"""
240241
result = [False, False, False, False]
241-
if owner != self.user:
242-
prefix = u"USER"
243242
# Inspect in all tab privs
244243
sql = u"""
245244
SELECT DISTINCT PRIVILEGE
@@ -338,7 +337,6 @@ def getTables(self, schema=None, add_sys_tables=False):
338337
# get all non geographic tables and views
339338
prefix = u"ALL"
340339
owner = u"o.owner"
341-
metatable = u"tab_columns"
342340
where = u""
343341
if self.userTablesOnly:
344342
prefix = u"USER"
@@ -1752,5 +1750,4 @@ def getSqlDictionary(self):
17521750

17531751
def getQueryBuilderDictionary(self):
17541752
from .sql_dictionary import getQueryBuilderDictionary
1755-
17561753
return getQueryBuilderDictionary()

python/plugins/db_manager/db_plugins/oracle/data_model.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
***************************************************************************/
2424
"""
2525

26-
from PyQt4.QtCore import QTime
26+
from PyQt4.QtCore import QTime, SIGNAL
2727

28-
from ..data_model import TableDataModel, SqlResultModel, \
29-
BaseTableModel, TableFieldsModel, SimpleTableModel
28+
from ..data_model import TableDataModel, SqlResultModel, BaseTableModel
3029
from ..plugin import DbError
31-
from qgis.core import *
3230

3331

3432
class ORTableDataModel(TableDataModel):

python/plugins/db_manager/db_plugins/oracle/info_model.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
from PyQt4.QtGui import QApplication
2727
from qgis.core import QGis
2828

29-
from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo, \
30-
SchemaInfo
29+
from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo
3130
from ..html_elems import HtmlContent, HtmlSection, HtmlParagraph, \
32-
HtmlList, HtmlTable, HtmlTableHeader, HtmlTableCol
31+
HtmlTable, HtmlTableHeader, HtmlTableCol
3332

3433
# Syntax Highlight for VIEWS/MVIEWS
3534
from pygments import highlight

python/plugins/db_manager/db_plugins/oracle/plugin.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@
2626
# this will disable the dbplugin if the connector raise an ImportError
2727
from .connector import OracleDBConnector
2828

29-
from PyQt4.QtCore import QSettings
30-
from PyQt4.QtGui import QIcon, QAction, QApplication, QMessageBox
29+
from PyQt4.QtCore import Qt, QSettings, QPyNullVariant
30+
from PyQt4.QtGui import QIcon, QAction, QApplication, QMessageBox, QKeySequence
31+
32+
from qgis.core import QgsVectorLayer
3133

3234
from ..plugin import ConnectionError, InvalidDataException, DBPlugin, \
3335
Database, Schema, Table, VectorTable, TableField, TableConstraint, \
34-
TableIndex, TableTrigger, TableRule
35-
36-
try:
37-
from . import resources_rc
38-
except ImportError:
39-
pass
36+
TableIndex, TableTrigger
4037

41-
from ..html_elems import HtmlParagraph, HtmlList, HtmlTable
4238

4339
from qgis.core import QgsCredentials
4440

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

203198
uri = self.uri()
204199
con = self.database().connector

python/plugins/db_manager/db_plugins/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def registerAllActions(self, mainWindow):
289289
def registerSubPluginActions(self, mainWindow):
290290
# load plugins!
291291
try:
292-
exec (u"from .%s.plugins import load" % self.dbplugin().typeName())
292+
exec (u"from .%s.plugins import load" % self.dbplugin().typeName(), globals())
293293
except ImportError:
294294
pass
295295
else:

python/plugins/db_manager/db_plugins/postgis/plugin.py

-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
from ..plugin import ConnectionError, InvalidDataException, DBPlugin, Database, Schema, Table, VectorTable, RasterTable, \
3131
TableField, TableConstraint, TableIndex, TableTrigger, TableRule
3232

33-
try:
34-
from . import resources_rc
35-
except ImportError:
36-
pass
37-
3833
import re
3934

4035

python/plugins/db_manager/db_plugins/spatialite/info_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from PyQt4.QtGui import QApplication
2424

2525
from ..info_model import DatabaseInfo
26-
from ..html_elems import HtmlTable
26+
from ..html_elems import HtmlTable, HtmlParagraph
2727

2828

2929
class SLDatabaseInfo(DatabaseInfo):

python/plugins/db_manager/db_plugins/spatialite/plugin.py

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
from ..plugin import DBPlugin, Database, Table, VectorTable, RasterTable, TableField, TableIndex, TableTrigger, \
3232
InvalidDataException
3333

34-
try:
35-
from . import resources_rc
36-
except ImportError:
37-
pass
38-
3934

4035
def classFactory():
4136
return SpatiaLiteDBPlugin

python/plugins/db_manager/db_plugins/vlayers/connector.py

+6-25
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,12 @@
1919
***************************************************************************/
2020
"""
2121

22-
from PyQt4.QtCore import (
23-
QFile,
24-
QUrl,
25-
QTemporaryFile
26-
)
27-
from PyQt4.QtGui import (
28-
QApplication
29-
)
30-
31-
from ..connector import (
32-
DBConnector
33-
)
34-
from ..plugin import (
35-
ConnectionError,
36-
DbError,
37-
Table
38-
)
39-
40-
from qgis.core import (
41-
QGis,
42-
QgsMapLayerRegistry,
43-
QgsMapLayer,
44-
QgsCoordinateReferenceSystem,
45-
QgsDataSourceURI
46-
)
22+
from PyQt4.QtCore import QUrl, QTemporaryFile
23+
24+
from ..connector import DBConnector
25+
from ..plugin import Table
26+
27+
from qgis.core import QGis, QgsDataSourceURI, QgsVirtualLayerDefinition, QgsMapLayerRegistry, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem
4728

4829
import sqlite3
4930

python/plugins/db_manager/db_plugins/vlayers/data_model.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
from ..plugin import DbError
2727

2828
from PyQt4.QtCore import QUrl, QTime, QTemporaryFile
29-
from qgis.core import QgsProviderRegistry, QgsErrorMessage, QGis, QgsVectorLayer
30-
31-
import os
29+
from qgis.core import QGis, QgsVectorLayer
3230

3331

3432
class LTableDataModel(TableDataModel):

python/plugins/db_manager/db_plugins/vlayers/plugin.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
# this will disable the dbplugin if the connector raise an ImportError
2323
from .connector import VLayerConnector
2424

25-
from PyQt4.QtCore import Qt, QSettings, QUrl
26-
from PyQt4.QtGui import QIcon, QApplication, QAction
25+
from PyQt4.QtCore import QUrl
26+
from PyQt4.QtGui import QIcon
2727
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
28-
from qgis.gui import QgsMessageBar
2928

30-
from ..plugin import DBPlugin, Database, Table, VectorTable, RasterTable, TableField, TableIndex, TableTrigger, InvalidDataException
31-
try:
32-
from . import resources_rc
33-
except ImportError:
34-
pass
29+
from ..plugin import DBPlugin, Database, Table, VectorTable, TableField
3530

3631

3732
def classFactory():

python/plugins/db_manager/db_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
***************************************************************************/
2121
"""
2222

23-
from PyQt4.QtCore import SIGNAL, SLOT, QSettings, Qt
23+
from PyQt4.QtCore import SIGNAL, SLOT
2424
from PyQt4.QtGui import QWidget, QTreeView, QMenu, QLabel
2525

2626
from qgis.core import QgsMapLayerRegistry, QgsMessageLog

python/plugins/db_manager/dlg_query_builder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
Query builder dialog, based on the QSpatialite plugin (GPLv2+) by Romain Riviere
2222
"""
2323

24-
from PyQt.QtCore import QObject, QEvent
25-
from PyQt.QtWidgets import QDialog, QMessageBox
24+
from PyQt4.QtCore import QObject, QEvent, SIGNAL
25+
from PyQt4.QtGui import QDialog, QMessageBox, QTextEdit
2626

2727
from .ui.ui_DlgQueryBuilder import Ui_DbManagerQueryBuilderDlg as Ui_Dialog
2828
from .db_plugins.plugin import VectorTable
@@ -301,7 +301,7 @@ def use_rtree(self):
301301
tab_idx = idx.split(".")[0][1:-1] # remove "
302302
col_idx = idx.split(".")[1][1:-1] # remove '
303303
except:
304-
pop_up_error("All fields are necessary", self)
304+
pop_up_error("All fields are necessary", self) # FIXME
305305
tgt = self.ui.table_target.currentText()
306306
if tgt in (None, "", " ", "Table (Target)"):
307307
return

python/plugins/db_manager/dlg_sql_window.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
***************************************************************************/
2323
"""
2424

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

3030
from qgis.core import QgsProject

python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import *
28+
from qgis.core import QgsMapLayerRegistry
2929
from PyQt4.QtGui import QWidget, QVBoxLayout, QPushButton, QLabel, QPlainTextEdit, QLineEdit, QComboBox, QCheckBox
3030
from processing.gui.AlgorithmDialog import AlgorithmDialog
3131
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase

0 commit comments

Comments
 (0)