Exemplo n.º 1
0
    def showSelectionDialog(self):
        settings = QSettings()
        text = unicode(self.cmbText.itemData(self.cmbText.currentIndex()))
        if os.path.isdir(text):
            path = text
        elif os.path.isdir(os.path.dirname(text)):
            path = os.path.dirname(text)
        elif settings.contains(utils.baseKey + '/LastInputPath'):
            path = unicode(settings.value(utils.baseKey + '/LastInputPath'))
        else:
            path = ''

        filename = unicode(
            QFileDialog.getOpenFileName(self, self.tr('Select file'), path,
                                        self.tr('TIFF files (*.tif)')))
        if filename:
            layer = QgsRasterLayer(filename)
            if layer.providerType() == 'gdal' and layer.source().lower(
            ).endswith(".tif"):
                settings.setValue(utils.baseKey + '/LastInputPath',
                                  os.path.dirname(unicode(filename)))
                self.cmbText.addItem(filename, filename)
                self.cmbText.setCurrentIndex(self.cmbText.count() - 1)