Exemple #1
0
    def sendBugReport(self):
        if not self._excInfoSet():
            exctype, excvalue, tracebackobj = sys.exc_info()
        else:
            exctype = self.exctype
            excvalue = self.excvalue
            tracebackobj = self.tracebackobj

        error = traceback.format_exception_only(exctype, excvalue)[-1].strip()
        appname = QtWidgets.QApplication.applicationName()
        if appname:
            subject = '[%s] Bug report - %s' % (appname, error)
        else:
            subject = 'Bug report - %s' % error
        body = '[Please insert your comments and additional info here.]'
        body += '\n\n' + '-' * 80 + '\n'
        body += ''.join(
            utils.format_bugreport(exctype,
                                   excvalue,
                                   tracebackobj,
                                   extra_info=qtsupport.format_qt_info()))

        url = QtCore.QUrl('mailto:%s <%s>' % (info.author, info.author_email))
        url.addQueryItem('subject', subject)
        url.addQueryItem('body', body)

        ret = QtGui.QDesktopServices.openUrl(url)
        if not ret:
            msg = self.tr('Unable to send the bug-report.\n'
                          'Please save the bug-report on file and send it '
                          'manually.')
            QtWidgets.QMessageBox.warning(self, self.tr('WARNING'), msg)
Exemple #2
0
    def openInGoogleMaps(self):
        '''Open google-maps centering the map on scene centre.

        .. seealso:: http://mapki.com/wiki/Google_Map_Parameters

        '''

        item = self._currentDatasetItem()
        if item is None:
            _log.info('no item selected.')
            QtWidgets.QMessageBox.information(self.app, self.tr('Information'),
                                              self.tr('No item selected.'))
            return

        try:
            cmapper = item.cmapper
        except AttributeError:
            _log.error('item "%s" seems to have no geographic info.',
                       item.filename)
            return

        lon, lat = cmapper.imgToGeoGrid([0.5, item.RasterXSize - 0.5],
                                        [0.5, item.RasterYSize - 0.5])
        deltalon = np.max(lon) - np.min(lon)
        deltalat = np.max(lat) - np.min(lat)
        zoomlon = np.floor(np.log2(360 / deltalon))
        zoomlat = np.floor(np.log2(180 / deltalat))
        zoomlevel = min(zoomlon, zoomlat) + 1

        pixel, line = item.RasterXSize / 2., item.RasterYSize / 2.
        lon, lat = cmapper.imgToGeoPoints(pixel, line)

        url = QtCore.QUrl('http://maps.google.com/maps')

        # @COMPATIBILITY: PyQt4 --> PyQt5
        try:
            query = QtCore.QUrlQuery()
        except AttributeError:
            query = url

        query.addQueryItem('q', '%fN,%fE' % (lat, lon))  # coordinates
        query.addQueryItem('t', 'h')  # map type (hybrid)
        query.addQueryItem('z', str(zoomlevel))  # zoom level (1, 20)

        # @COMPATIBILITY: PyQt4 --> PyQt5
        try:
            url.setQuery(query)
        except AttributeError:
            pass

        success = QtGui.QDesktopServices.openUrl(url)
        if not success:
            _log.warning('unable to open URL: "%s"', url)
            # @TODO: check
            QtWidgets.QMessageBox.warning(
                self.app, self.tr('Warning'),
                self.tr('Unable to open URL: "%s"') % str(url))
Exemple #3
0
    def addSoftwareVersion(self, sw, version, link=''):
        tablewidget = self.versionsTableWidget
        index = tablewidget.rowCount()
        tablewidget.setRowCount(index + 1)

        tablewidget.setItem(index, 0, QtWidgets.QTableWidgetItem(sw))
        tablewidget.setItem(index, 1, QtWidgets.QTableWidgetItem(version))
        #tablewidget.setItem(row, 2, QtWidgets.QTableWidgetItem(link))
        linkLabel = QtWidgets.QLabel('<a href="{0}">{0}</a>'.format(link))
        linkLabel.linkActivated.connect(
            lambda text: QtGui.QDesktopServices.openUrl(QtCore.QUrl(text)))
        tablewidget.setCellWidget(index, 2, linkLabel)
Exemple #4
0
    def _restoreFileDialogState(self, settings=None):
        if settings is None:
            settings = self.settings

        settings.beginGroup('filedialog')
        try:
            # state
            state = settings.value('state')
            if state is not None:
                try:
                    # QFileDialog.restoreState is new in Qt 4.3
                    self.filedialog.restoreState(state)
                except AttributeError:
                    _log.debug('unable to restore the file dialog state')

            # workdir
            workdir = settings.value('workdir', utils.default_workdir())
            workdir = os.path.expanduser(os.path.expandvars(workdir))
            self.filedialog.setDirectory(workdir)

            # history
            #history = settings.value('history')
            #if history:
            #    self.filedialog.setHistory(history)

            # sidebar urls
            try:
                # QFileDialog.setSidebarUrls is new in Qt 4.3
                sidebarurls = settings.value('sidebarurls')
                if sidebarurls:
                    sidebarurls = [QtCore.QUrl(item) for item in sidebarurls]
                    self.filedialog.setSidebarUrls(sidebarurls)
            except AttributeError:
                _log.debug('unable to restore sidebar URLs of the file dialog')
        finally:
            settings.endGroup()
Exemple #5
0
 def _linkActivated(self, link):
     # @TODO: better url parsing
     if 'mailto' in str(link):
         self.sendBugReport()
     else:
         QtGui.QDesktopServices.openUrl(QtCore.QUrl(link))