Skip to content
Permalink
Browse files

Merge pull request #4944 from m-kuhn/PyOverrideCursor

Safer cursor overriding for python
  • Loading branch information
m-kuhn committed Jul 31, 2017
2 parents cf753e9 + 1da9c60 commit 0db8a5816b26ba4e33e1818aef4ba9f3e90e7501
@@ -27,6 +27,7 @@
from qgis.PyQt.Qsci import QsciScintilla, QsciLexerPython, QsciAPIs, QsciStyle
from qgis.core import QgsApplication, QgsSettings
from qgis.gui import QgsMessageBar
from qgis.utils import OverrideCursor
import sys
import os
import subprocess
@@ -726,10 +727,9 @@ def focusInEvent(self, e):
file = open(pathfile, "r")
fileLines = file.readlines()
file.close()
QApplication.setOverrideCursor(Qt.WaitCursor)
for line in reversed(fileLines):
self.insert(line)
QApplication.restoreOverrideCursor()
with OverrideCursor(Qt.WaitCursor):
for line in reversed(fileLines):
self.insert(line)
self.setModified(False)
self.endUndoAction()

@@ -785,11 +785,10 @@ def loadFile(self, filename, modified):
fn = codecs.open(filename, "rb", encoding='utf-8')
txt = fn.read()
fn.close()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.newEditor.setText(txt)
if self.readOnly:
self.newEditor.setReadOnly(self.readOnly)
QApplication.restoreOverrideCursor()
with OverrideCursor(Qt.WaitCursor):
self.newEditor.setText(txt)
if self.readOnly:
self.newEditor.setReadOnly(self.readOnly)
self.newEditor.setModified(modified)
self.newEditor.recolor()

@@ -1259,9 +1258,8 @@ def refreshSettingsEditor(self):
if objInspectorEnabled:
cW = self.currentWidget()
if cW and not self.parent.listClassMethod.isVisible():
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.listObject(cW)
QApplication.restoreOverrideCursor()
with OverrideCursor(Qt.WaitCursor):
self.listObject(cW)

def changeLastDirPath(self, tab):
tabWidget = self.widget(tab)
@@ -46,6 +46,7 @@
QgsCoordinateTransform, QgsGeometry, QgsPointXY,
QgsProviderRegistry, QgsSettings)
from qgis.gui import QgsRubberBand
from qgis.utils import OverrideCursor

from owslib.csw import CatalogueServiceWeb # spellok
from owslib.fes import BBox, PropertyIsLike
@@ -281,8 +282,6 @@ def connection_info(self):
if not self._get_csw():
return

QApplication.restoreOverrideCursor()

if self.catalog: # display service metadata
self.btnCapabilities.setEnabled(True)
metadata = render_template('en', self.context,
@@ -490,25 +489,22 @@ def search(self):
# TODO: allow users to select resources types
# to find ('service', 'dataset', etc.)
try:
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords, esn='full')
with OverrideCursor(Qt.WaitCursor):
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords, esn='full')
except ExceptionReport as err:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('Search error'),
self.tr('Search error: {0}').format(err))
return
except Exception as err:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('Connection error'),
self.tr('Connection error: {0}').format(err))
return

if self.catalog.results['matches'] == 0:
QApplication.restoreOverrideCursor()
self.lblResults.setText(self.tr('0 results'))
return

QApplication.restoreOverrideCursor()
self.display_results()

def display_results(self):
@@ -675,25 +671,20 @@ def navigate(self):
else:
return

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

try:
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords,
startposition=self.startfrom, esn='full')
with OverrideCursor(Qt.WaitCursor):
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords,
startposition=self.startfrom, esn='full')
except ExceptionReport as err:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('Search error'),
self.tr('Search error: {0}').format(err))
return
except Exception as err:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('Connection error'),
self.tr('Connection error: {0}').format(err))
return

QApplication.restoreOverrideCursor()

self.display_results()

def add_to_ows(self):
@@ -727,8 +718,6 @@ def add_to_ows(self):
stype = ['ESRI:ArcGIS:FeatureServer', 'afs', 'arcgisfeatureserver']
data_url = item_data['afs'].split('FeatureServer')[0] + 'FeatureServer'

QApplication.restoreOverrideCursor()

sname = '%s from MetaSearch' % stype[1]

# store connection
@@ -820,26 +809,22 @@ def show_metadata(self):
identifier = get_item_data(item, 'identifier')

try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
cat = CatalogueServiceWeb(self.catalog_url, timeout=self.timeout, # spellok
username=self.catalog_username,
password=self.catalog_password)
cat.getrecordbyid(
[self.catalog.records[identifier].identifier])
with OverrideCursor(Qt.WaitCursor):
cat = CatalogueServiceWeb(self.catalog_url, timeout=self.timeout, # spellok
username=self.catalog_username,
password=self.catalog_password)
cat.getrecordbyid(
[self.catalog.records[identifier].identifier])
except ExceptionReport as err:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('GetRecords error'),
self.tr('Error getting response: {0}').format(err))
return
except KeyError as err:
QMessageBox.warning(self,
self.tr('Record parsing error'),
self.tr('Unable to locate record identifier'))
QApplication.restoreOverrideCursor()
return

QApplication.restoreOverrideCursor()

record = cat.records[identifier]
record.xml_url = cat.request

@@ -902,21 +887,20 @@ def _get_csw(self):
"""convenience function to init owslib.csw.CatalogueServiceWeb""" # spellok

# connect to the server
try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.catalog = CatalogueServiceWeb(self.catalog_url, # spellok
timeout=self.timeout,
username=self.catalog_username,
password=self.catalog_password)
return True
except ExceptionReport as err:
msg = self.tr('Error connecting to service: {0}').format(err)
except ValueError as err:
msg = self.tr('Value Error: {0}').format(err)
except Exception as err:
msg = self.tr('Unknown Error: {0}').format(err)
with OverrideCursor(Qt.WaitCursor):
try:
self.catalog = CatalogueServiceWeb(self.catalog_url, # spellok
timeout=self.timeout,
username=self.catalog_username,
password=self.catalog_password)
return True
except ExceptionReport as err:
msg = self.tr('Error connecting to service: {0}').format(err)
except ValueError as err:
msg = self.tr('Value Error: {0}').format(err)
except Exception as err:
msg = self.tr('Unknown Error: {0}').format(err)

QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('CSW Connection error'), msg)
return False

@@ -6,35 +6,74 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>224</height>
<width>585</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
<string>Create a new Catalog connection</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="2">
<widget class="QLineEdit" name="leURL"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>URL</string>
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
<string>URL</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="leName"/>
<item row="1" column="1">
<widget class="QLineEdit" name="leURL"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="authenticationGroupBox">
<property name="title">
<string>Authentication</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>If the service requires basic authentication, enter a user name and optional password</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>User name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leUsername"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lePassword"/>
</item>
</layout>
</widget>
</item>
<item row="5" column="2">
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -44,85 +83,11 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QTabWidget" name="tabNewConnectionOptions">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Authentication</string>
</attribute>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>421</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>If the service requires basic authentication, enter a user name and optional password</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>51</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>User name</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>46</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
<widget class="QLineEdit" name="leUsername">
<property name="geometry">
<rect>
<x>80</x>
<y>30</y>
<width>341</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lePassword">
<property name="geometry">
<rect>
<x>80</x>
<y>60</y>
<width>341</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>leName</tabstop>
<tabstop>leURL</tabstop>
<tabstop>leUsername</tabstop>
<tabstop>lePassword</tabstop>
<tabstop>tabNewConnectionOptions</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>

0 comments on commit 0db8a58

Please sign in to comment.
You can’t perform that action at this time.