Even more endless hourglass avoidance

This commit is contained in:
Matthias Kuhn 2017-07-30 22:36:51 +02:00
parent 8473df562f
commit 3ce6fcd31d
No known key found for this signature in database
GPG Key ID: A0E766808764D73F
3 changed files with 43 additions and 52 deletions

View File

@ -32,6 +32,7 @@ from .db_plugins.plugin import BaseError, Table, Database
from .dlg_db_error import DlgDbError
from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils
from qgis.utils import OverrideCursor
from . import resources_rc # NOQA
@ -458,17 +459,15 @@ class DBModel(QAbstractItemModel):
if new_value == obj.name:
return False
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
obj.rename(new_value)
self._onDataChanged(index)
except BaseError as e:
DlgDbError.showError(e, self.treeView)
return False
finally:
QApplication.restoreOverrideCursor()
return True
with OverrideCursor(Qt.WaitCursor):
try:
obj.rename(new_value)
self._onDataChanged(index)
except BaseError as e:
DlgDbError.showError(e, self.treeView)
return False
else:
return True
return False
@ -480,27 +479,23 @@ class DBModel(QAbstractItemModel):
self.endRemoveRows()
def _refreshIndex(self, index, force=False):
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
item = index.internalPointer() if index.isValid() else self.rootItem
prevPopulated = item.populated
if prevPopulated:
self.removeRows(0, self.rowCount(index), index)
with OverrideCursor(Qt.WaitCursor):
try:
item = index.internalPointer() if index.isValid() else self.rootItem
prevPopulated = item.populated
if prevPopulated:
self.removeRows(0, self.rowCount(index), index)
item.populated = False
if prevPopulated or force:
if item.populate():
for child in item.childItems:
child.changed.connect(partial(self.refreshItem, child))
self._onDataChanged(index)
else:
self.notPopulated.emit(index)
except BaseError:
item.populated = False
if prevPopulated or force:
if item.populate():
for child in item.childItems:
child.changed.connect(partial(self.refreshItem, child))
self._onDataChanged(index)
else:
self.notPopulated.emit(index)
except BaseError:
item.populated = False
return
finally:
QApplication.restoreOverrideCursor()
def _onDataChanged(self, indexFrom, indexTo=None):
if indexTo is None:

View File

@ -297,19 +297,16 @@ class DlgCreateTable(QDialog, Ui_Dialog):
flds[pk_index].primaryKey = True
# commit to DB
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
if not useGeomColumn:
self.db.createTable(table, flds, schema)
else:
geom = geomColumn, geomType, geomSrid, geomDim, useSpatialIndex
self.db.createVectorTable(table, flds, geom, schema)
with OverrideCursor(Qt.WaitCursor):
try:
if not useGeomColumn:
self.db.createTable(table, flds, schema)
else:
geom = geomColumn, geomType, geomSrid, geomDim, useSpatialIndex
self.db.createVectorTable(table, flds, geom, schema)
except (ConnectionError, DbError) as e:
DlgDbError.showError(e, self)
except (ConnectionError, DbError) as e:
DlgDbError.showError(e, self)
return
finally:
QApplication.restoreOverrideCursor()
QMessageBox.information(self, self.tr("Good"), self.tr("everything went fine"))

View File

@ -38,7 +38,7 @@ from qgis.PyQt.QtWidgets import (QMessageBox,
QApplication)
from qgis.core import QgsApplication, QgsSettings
from qgis.utils import iface
from qgis.utils import iface, OverrideCursor
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.HelpEditionDialog import HelpEditionDialog
@ -207,15 +207,14 @@ class ScriptEditorDialog(BASE, WIDGET):
if self.filename == '':
return
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
with codecs.open(self.filename, 'r', encoding='utf-8') as f:
txt = f.read()
with OverrideCursor(Qt.WaitCursor):
with codecs.open(self.filename, 'r', encoding='utf-8') as f:
txt = f.read()
self.editor.setText(txt)
self.hasChanged = False
self.editor.setModified(False)
self.editor.recolor()
QApplication.restoreOverrideCursor()
self.editor.setText(txt)
self.hasChanged = False
self.editor.setModified(False)
self.editor.recolor()
def save(self):
self.saveScript(False)