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
Expand Up @@ -32,6 +32,7 @@
from .dlg_db_error import DlgDbError from .dlg_db_error import DlgDbError


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


from . import resources_rc # NOQA from . import resources_rc # NOQA


Expand Down Expand Up @@ -458,17 +459,15 @@ def setData(self, index, value, role):
if new_value == obj.name: if new_value == obj.name:
return False return False


QApplication.setOverrideCursor(Qt.WaitCursor) with OverrideCursor(Qt.WaitCursor):
try: try:
obj.rename(new_value) obj.rename(new_value)
self._onDataChanged(index) self._onDataChanged(index)
except BaseError as e: except BaseError as e:
DlgDbError.showError(e, self.treeView) DlgDbError.showError(e, self.treeView)
return False return False
finally: else:
QApplication.restoreOverrideCursor() return True

return True


return False return False


Expand All @@ -480,27 +479,23 @@ def removeRows(self, row, count, parent):
self.endRemoveRows() self.endRemoveRows()


def _refreshIndex(self, index, force=False): def _refreshIndex(self, index, force=False):
QApplication.setOverrideCursor(Qt.WaitCursor) with OverrideCursor(Qt.WaitCursor):
try: try:
item = index.internalPointer() if index.isValid() else self.rootItem item = index.internalPointer() if index.isValid() else self.rootItem
prevPopulated = item.populated prevPopulated = item.populated
if prevPopulated: if prevPopulated:
self.removeRows(0, self.rowCount(index), index) self.removeRows(0, self.rowCount(index), index)
item.populated = False item.populated = False
if prevPopulated or force: if prevPopulated or force:
if item.populate(): if item.populate():
for child in item.childItems: for child in item.childItems:
child.changed.connect(partial(self.refreshItem, child)) child.changed.connect(partial(self.refreshItem, child))
self._onDataChanged(index) self._onDataChanged(index)
else: else:
self.notPopulated.emit(index) self.notPopulated.emit(index)

except BaseError:
item.populated = False
return


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


def _onDataChanged(self, indexFrom, indexTo=None): def _onDataChanged(self, indexFrom, indexTo=None):
if indexTo is None: if indexTo is None:
Expand Down
23 changes: 10 additions & 13 deletions python/plugins/db_manager/dlg_create_table.py
Expand Up @@ -297,19 +297,16 @@ def createTable(self):
flds[pk_index].primaryKey = True flds[pk_index].primaryKey = True


# commit to DB # commit to DB
QApplication.setOverrideCursor(Qt.WaitCursor) with OverrideCursor(Qt.WaitCursor):
try: try:
if not useGeomColumn: if not useGeomColumn:
self.db.createTable(table, flds, schema) self.db.createTable(table, flds, schema)
else: else:
geom = geomColumn, geomType, geomSrid, geomDim, useSpatialIndex geom = geomColumn, geomType, geomSrid, geomDim, useSpatialIndex
self.db.createVectorTable(table, flds, geom, schema) self.db.createVectorTable(table, flds, geom, schema)


except (ConnectionError, DbError) as e: except (ConnectionError, DbError) as e:
DlgDbError.showError(e, self) DlgDbError.showError(e, self)
return return


finally:
QApplication.restoreOverrideCursor()

QMessageBox.information(self, self.tr("Good"), self.tr("everything went fine")) QMessageBox.information(self, self.tr("Good"), self.tr("everything went fine"))
17 changes: 8 additions & 9 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Expand Up @@ -38,7 +38,7 @@
QApplication) QApplication)


from qgis.core import QgsApplication, QgsSettings 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.AlgorithmDialog import AlgorithmDialog
from processing.gui.HelpEditionDialog import HelpEditionDialog from processing.gui.HelpEditionDialog import HelpEditionDialog
Expand Down Expand Up @@ -207,15 +207,14 @@ def openScript(self):
if self.filename == '': if self.filename == '':
return return


QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) with OverrideCursor(Qt.WaitCursor):
with codecs.open(self.filename, 'r', encoding='utf-8') as f: with codecs.open(self.filename, 'r', encoding='utf-8') as f:
txt = f.read() txt = f.read()


self.editor.setText(txt) self.editor.setText(txt)
self.hasChanged = False self.hasChanged = False
self.editor.setModified(False) self.editor.setModified(False)
self.editor.recolor() self.editor.recolor()
QApplication.restoreOverrideCursor()


def save(self): def save(self):
self.saveScript(False) self.saveScript(False)
Expand Down

0 comments on commit 3ce6fcd

Please sign in to comment.