text: # -*- coding: utf-8 -*-
  """
  /***************************************************************************
   ReadSDBDialog
                                   A QGIS plugin
   Read PySDB structural data into QGIS
   Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
                               -------------------
          begin                : 2018-11-03
          git sha              : $Format:%H$
          copyright            : (C) 2018 by Ondrej Lexa
          email                : lexa.ondrej@gmail.com
   ***************************************************************************/
  
  /***************************************************************************
   *                                                                         *
   *   This program is free software; you can redistribute it and/or modify  *
   *   it under the terms of the GNU General Public License as published by  *
   *   the Free Software Foundation; either version 2 of the License, or     *
   *   (at your option) any later version.                                   *
   *                                                                         *
   ***************************************************************************/
  """
  import os
  
  from PyQt5 import uic
  from PyQt5 import QtWidgets
  from PyQt5.QtCore import Qt, QFileInfo
  from qgis.core import QgsCoordinateReferenceSystem
  
  # Need latest APSG
  #import sys
  #sys.path.insert(0, '/home/ondro/develrepo/apsg')
  from apsg import SDB
  
  FORM_CLASS, _ = uic.loadUiType(os.path.join(
      os.path.dirname(__file__), 'ui/readsdb_connect.ui'))
  
  
  class ReadSDBConnectDialog(QtWidgets.QDialog, FORM_CLASS):
      def __init__(self, readsdb, parent=None):
          """Constructor."""
          super(ReadSDBConnectDialog, self).__init__(parent, Qt.WindowStaysOnTopHint)
          # Set up the user interface from Designer.
          # After setupUI you can access any designer object by doing
          # self.<objectname>, and you can use autoconnect slots - see
          # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
          # #widgets-and-dialogs-with-auto-connect
          self.setupUi(self)
          self.btnBrowse.clicked.connect(self.browse)
          self.readsdb = readsdb
          self.settings = self.readsdb.settings
  
          self.sdbinfo(self.settings.value("gui/sdbname", type=str))
  
      def sdbinfo(self, filename):
          """Populate dialog with current values"""
          self.sdbname.setText(filename)
          try:
              sdb = SDB(filename)
              crs = QgsCoordinateReferenceSystem()
              crs.createFromUserInput(sdb.meta("crs"))
              self.sdb_info_basic.setPlainText(sdb.info(report='basic') + '\nCRS parsed by QGIS:\n{}'.format(crs.description()))
              self.sdb_info_data.setPlainText(sdb.info(report='data'))
              self.sdb_info_tags.setPlainText(sdb.info(report='tags'))
              self.dbok = True
          except:
              self.sdb_info_basic.clear()
              self.sdb_info_data.clear()
              self.sdb_info_tags.clear()
              self.sdbname.clear()
              self.dbok = False
  
      def accept(self):
          if self.dbok:
              self.settings.setValue("gui/sdbname", self.sdbname.text())
              super(ReadSDBConnectDialog, self).accept()
          else:
              QtWidgets.QMessageBox.warning(self, 'Warning', self.readsdb.tr(u'Please specify correct SDB database'))
  
      def browse(self):
          file, _ = QtWidgets.QFileDialog.getOpenFileName(self, self.readsdb.tr(u'Open SDB database'), self.sdbname.text(), "SDB database (*.sdb);;All files (*.*)")
          if file:
              self.sdbinfo(QFileInfo(file).absoluteFilePath())
  