Skip to content

Commit

Permalink
Even more endless hourglass avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jul 30, 2017
1 parent 8473df5 commit 3ce6fcd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 53 deletions.
57 changes: 26 additions & 31 deletions python/plugins/db_manager/db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .dlg_db_error import DlgDbError

from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils
from qgis.utils import OverrideCursor

from . import resources_rc # NOQA

Expand Down Expand Up @@ -458,17 +459,15 @@ def setData(self, index, value, role):
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

Expand All @@ -480,27 +479,23 @@ def removeRows(self, row, count, parent):
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)
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
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)

finally:
QApplication.restoreOverrideCursor()
except BaseError:
item.populated = False

def _onDataChanged(self, indexFrom, indexTo=None):
if indexTo is None:
Expand Down
23 changes: 10 additions & 13 deletions python/plugins/db_manager/dlg_create_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,16 @@ def createTable(self):
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)

except (ConnectionError, DbError) as e:
DlgDbError.showError(e, self)
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)
return

finally:
QApplication.restoreOverrideCursor()

QMessageBox.information(self, self.tr("Good"), self.tr("everything went fine"))
17 changes: 8 additions & 9 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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
Expand Down Expand Up @@ -207,15 +207,14 @@ def openScript(self):
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)
Expand Down

0 comments on commit 3ce6fcd

Please sign in to comment.