Пример #1
0
    def login(self):
        username = self.ui.inputUserName.text()
        pwd = self.ui.inputPwd.text()
        isPassed = False
        db = sqlite3.connect("./medicine_db.db")
        cursor = db.cursor()
        sql = "SELECT userName,userPwd From USER " \
              "WHERE  userName = '******' " % username  # 注意这里的''要加上
        try:
            cursor.execute(sql)
            results = cursor.fetchall()
            for r in results:
                if r[1] == pwd:  # 注意这里要加【0】,否则是元组对象
                    isPassed = True

        except:
            print("Error: unable to fetch data")
        finally:
            db.close()

        if isPassed == False:
            self._failToLogin.ErrorMsg.setText("用户名或密码错误!")
            self._failToLogin.exec_()
        else:
            # 此时登录成功,本页面关闭,传入用户名,
            self._mainPage = MainDialog(username)
            self.ui.close()
            self._mainPage.exec()
Пример #2
0
    def initGui(self):
        # Create toolbar
        self.toolbar = self.iface.addToolBar("Open Symos Toolbar")
        self.toolbar.setObjectName("Open Symos Toolbar")
        self.toolbar_search = QLineEdit()
        self.toolbar_search.setMaximumWidth(100)
        self.toolbar_search.setAlignment(Qt.AlignLeft)
        self.toolbar_search.setPlaceholderText(u"Location ...")
        self.toolbar.addWidget(self.toolbar_search)
        self.toolbar_search.returnPressed.connect(self.calculate)
        self.calculate_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "opensymos.png")),
            u"Počítat dle SYMOS", self.iface.mainWindow())
        QObject.connect(self.calculate_btn, SIGNAL("triggered()"),
                        self.calculate)
        self.show_project_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "project.png")),
            u"Načíst ukázkový project", self.iface.mainWindow())
        QObject.connect(self.show_project_btn, SIGNAL("triggered()"),
                        self.load_project)
        self.load_dem_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "dem.png")),
            u"Načíst DEM", self.iface.mainWindow())
        QObject.connect(self.load_dem_btn, SIGNAL("triggered()"),
                        self.load_dem)
        self.convert_line_to_points_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__),
                               "line_to_point.png")), u"Převést linie na body",
            self.iface.mainWindow())
        QObject.connect(self.convert_line_to_points_btn, SIGNAL("triggered()"),
                        self.convert_line_to_points)
        self.convert_polygon_to_points_btn = QAction(
            QIcon(
                os.path.join(os.path.dirname(__file__),
                             "polygon_to_point.png")),
            u"Převést polygony na body", self.iface.mainWindow())
        QObject.connect(self.convert_polygon_to_points_btn,
                        SIGNAL("triggered()"), self.convert_polygon_to_points)
        self.toolbar.addActions([
            self.calculate_btn, self.show_project_btn, self.load_dem_btn,
            self.convert_line_to_points_btn, self.convert_polygon_to_points_btn
        ])

        # Create action that will start plugin configuration
        self.action = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "opensymos.png")),
            u"Počítat dle SYMOS", self.iface.mainWindow())
        # connect the action to the run method
        self.action.triggered.connect(self.toolbar.show)

        # Add toolbar button and menu item
        self.iface.addPluginToMenu(u"&Open Symos", self.action)

        self.dlg = MainDialog()
Пример #3
0
class Login:
    def __init__(self):
        self.ui = uic.loadUi("ui/login.ui")
        self._registerWidget = ""
        self._forgetPwdWidget = ""
        self._failToLogin = uic.loadUi("ui/fail.ui")
        self._mainPage = ""
        self.ui.toRegister.clicked.connect(self.toRegister)
        self.ui.toForgetPwd.clicked.connect(self.toForgetPwd)
        self.ui.inputPwd.returnPressed.connect(self.login)
        self.ui.loginButton.clicked.connect(self.login)
        self.ui.setWindowIcon(QIcon("./images/icon.png"))

    def toRegister(self):
        self._registerWidget = Register()
        self._registerWidget.ui.exec()

    def toForgetPwd(self):
        self._forgetPwdWidget = ForgetPwd()
        self._forgetPwdWidget.ui.exec()

    def login(self):
        username = self.ui.inputUserName.text()
        pwd = self.ui.inputPwd.text()
        isPassed = False
        db = sqlite3.connect("./medicine_db.db")
        cursor = db.cursor()
        sql = "SELECT userName,userPwd From USER " \
              "WHERE  userName = '******' " % username  # 注意这里的''要加上
        try:
            cursor.execute(sql)
            results = cursor.fetchall()
            for r in results:
                if r[1] == pwd:  # 注意这里要加【0】,否则是元组对象
                    isPassed = True

        except:
            print("Error: unable to fetch data")
        finally:
            db.close()

        if isPassed == False:
            self._failToLogin.ErrorMsg.setText("用户名或密码错误!")
            self._failToLogin.exec_()
        else:
            # 此时登录成功,本页面关闭,传入用户名,
            self._mainPage = MainDialog(username)
            self.ui.close()
            self._mainPage.exec()
Пример #4
0
 def on_GoBack_pushButton_clicked(self):
     from main_dialog import MainDialog
     dialog = MainDialog(self.username)
     self.close()
     dialog.exec()
Пример #5
0
    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=None,
        whats_this=None,
        parent=None):
        """Add a toolbar icon to the toolbar.

        :param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
        :type icon_path: str

        :param text: Text that should be shown in menu items for this action.
        :type text: str

        :param callback: Function to be called when the action is triggered.
        :type callback: function

        :param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.
        :type enabled_flag: bool

        :param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.
        :type add_to_menu: bool

        :param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.
        :type add_to_toolbar: bool

        :param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.
        :type status_tip: str

        :param parent: Parent widget for the new action. Defaults None.
        :type parent: QWidget

        :param whats_this: Optional text to show in the status bar when the
            mouse pointer hovers over the action.

        :returns: The action that was created. Note that the action is also
            added to self.actions list.
        :rtype: QAction
        """

        # Create the dialog (after translation) and keep reference
        self.dlg = MainDialog()

        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.toolbar.addAction(action)

        if add_to_menu:
            self.iface.addPluginToMenu(
                self.menu,
                action)

        self.actions.append(action)

        return action
Пример #6
0
class Main:
    """QGIS Plugin Implementation."""

    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            'DataLoader_{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)


        # Declare instance attributes
        self.actions = []
        self.menu = self.tr(u'&Data Loader')
        # TODO: We are going to let the user set this up in a future iteration
        self.toolbar = self.iface.addToolBar(u'DataLoader')
        self.toolbar.setObjectName(u'DataLoader')

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        """Get the translation for a string using Qt translation API.

        We implement this ourselves since we do not inherit QObject.

        :param message: String for translation.
        :type message: str, QString

        :returns: Translated version of message.
        :rtype: QString
        """
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('DataLoader', message)


    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=None,
        whats_this=None,
        parent=None):
        """Add a toolbar icon to the toolbar.

        :param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
        :type icon_path: str

        :param text: Text that should be shown in menu items for this action.
        :type text: str

        :param callback: Function to be called when the action is triggered.
        :type callback: function

        :param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.
        :type enabled_flag: bool

        :param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.
        :type add_to_menu: bool

        :param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.
        :type add_to_toolbar: bool

        :param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.
        :type status_tip: str

        :param parent: Parent widget for the new action. Defaults None.
        :type parent: QWidget

        :param whats_this: Optional text to show in the status bar when the
            mouse pointer hovers over the action.

        :returns: The action that was created. Note that the action is also
            added to self.actions list.
        :rtype: QAction
        """

        # Create the dialog (after translation) and keep reference
        self.dlg = MainDialog()

        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.toolbar.addAction(action)

        if add_to_menu:
            self.iface.addPluginToMenu(
                self.menu,
                action)

        self.actions.append(action)

        return action

    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI."""

        icon_path = ':/plugins/DataLoader/icon.png'
        self.add_action(
            icon_path,
            text=self.tr(u'ECMWF loader'),
            callback=self.run,
            parent=self.iface.mainWindow())


    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
        for action in self.actions:
            self.iface.removePluginMenu(
                self.tr(u'&Data Loader'),
                action)
            self.iface.removeToolBarIcon(action)
        # remove the toolbar
        del self.toolbar


    def run(self):
        """Run method that performs all the real work"""

	print("Checking dependencies")
	depend = self.checkDependencies()
        print (depend)


        ChoiceList = ["Snow Depth", "Total Cloud Cover", "10m V Wind", "2m Temperature", "Total Column Water Vapour", "Specific Humidity", "Solar Duration", "Snowfall", "Relative Humidity", "Surface Pressure", "10m U Wind"]
        self.dlg.listWidget.clear() #widget needs to be cleared every time we open window, otherwise it would keep adding elements
        self.dlg.listWidget.addItems(ChoiceList)


        print("loading classes")
	#class creating
        load = loader()


        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()
        # See if OK was pressed
        if result:
	    resultlist = []
            items = self.dlg.listWidget.count()
            for i in range(items):
                if self.dlg.listWidget.isItemSelected(self.dlg.listWidget.item(i)) == True:
##                    selectedItems.append(self.dlg.listWidget.indexFromItem(self.dlg.listWidget.item(i)))
                    print(i)
                    resultlist.append(i)

            ch1 = self.dlg.checkBox.isChecked()
            ch2 = self.dlg.checkBox_2.isChecked()
            ch3 = self.dlg.checkBox_3.isChecked()
            ch4 = self.dlg.checkBox_4.isChecked()

            #calculating time from checkbox and putting it into right format
            time=""
            if(ch1):
                time+="00/"
            if(ch2):
                time+="06/"
            if(ch3):
                time+="12/"
            if(ch4):
                time+="18/"
            time = time[:-1]
	    if time == "" :
		self.popup = PopUpDialog("Choose at least one time of day")
		self.popup.show()
	    elif resultlist == []:
		self.popup = PopUpDialog("Choose at least one type of data")
		self.popup.show()
	    else:
		date1 = self.dlg.dateEdit.date().toPyDate()
                date2 = self.dlg.dateEdit_2.date().toPyDate()
                load.downloadData(time, date1.strftime("%Y-%m-%d")+"/to/"+date2.strftime("%Y-%m-%d"), resultlist)
 
                pass

    def checkDependencies(self):
        try:
	    import crayfish
	    import qgis
	    import ecmwfapi
	except ImportError:
	    print ("missing some imports: "+sys.exc_info()[0])
	    return "missing some imports: "+sys.exc_info()[0]
        return "All dependencies are installed"
Пример #7
0
 def on_exit_push_button_clicked(self):
     from main_dialog import MainDialog
     dialog = MainDialog(self.__username)
     self.close()
     dialog.exec()
Пример #8
0
class OpenSYMOS:
    def __init__(self, iface):
        # Save reference to the QGIS interface + canvas
        self.iface = iface
        self.canvas = iface.mapCanvas()
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value("locale/userLocale")[0:2]
        localePath = os.path.join(self.plugin_dir, 'i18n',
                                  'opensymos_{}.qm'.format(locale))

        if os.path.exists(localePath):
            self.translator = QTranslator()
            self.translator.load(localePath)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create various class references
        self.marker = None
        self.completer = None
        self.previous_searches = []

    def initGui(self):
        # Create toolbar
        self.toolbar = self.iface.addToolBar("Open Symos Toolbar")
        self.toolbar.setObjectName("Open Symos Toolbar")
        self.toolbar_search = QLineEdit()
        self.toolbar_search.setMaximumWidth(100)
        self.toolbar_search.setAlignment(Qt.AlignLeft)
        self.toolbar_search.setPlaceholderText(u"Location ...")
        self.toolbar.addWidget(self.toolbar_search)
        self.toolbar_search.returnPressed.connect(self.calculate)
        self.calculate_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "opensymos.png")),
            u"Počítat dle SYMOS", self.iface.mainWindow())
        QObject.connect(self.calculate_btn, SIGNAL("triggered()"),
                        self.calculate)
        self.show_project_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "project.png")),
            u"Načíst ukázkový project", self.iface.mainWindow())
        QObject.connect(self.show_project_btn, SIGNAL("triggered()"),
                        self.load_project)
        self.load_dem_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "dem.png")),
            u"Načíst DEM", self.iface.mainWindow())
        QObject.connect(self.load_dem_btn, SIGNAL("triggered()"),
                        self.load_dem)
        self.convert_line_to_points_btn = QAction(
            QIcon(os.path.join(os.path.dirname(__file__),
                               "line_to_point.png")), u"Převést linie na body",
            self.iface.mainWindow())
        QObject.connect(self.convert_line_to_points_btn, SIGNAL("triggered()"),
                        self.convert_line_to_points)
        self.convert_polygon_to_points_btn = QAction(
            QIcon(
                os.path.join(os.path.dirname(__file__),
                             "polygon_to_point.png")),
            u"Převést polygony na body", self.iface.mainWindow())
        QObject.connect(self.convert_polygon_to_points_btn,
                        SIGNAL("triggered()"), self.convert_polygon_to_points)
        self.toolbar.addActions([
            self.calculate_btn, self.show_project_btn, self.load_dem_btn,
            self.convert_line_to_points_btn, self.convert_polygon_to_points_btn
        ])

        # Create action that will start plugin configuration
        self.action = QAction(
            QIcon(os.path.join(os.path.dirname(__file__), "opensymos.png")),
            u"Počítat dle SYMOS", self.iface.mainWindow())
        # connect the action to the run method
        self.action.triggered.connect(self.toolbar.show)

        # Add toolbar button and menu item
        self.iface.addPluginToMenu(u"&Open Symos", self.action)

        self.dlg = MainDialog()

    def unload(self):
        # Remove the plugin menu item and toolbar
        self.iface.removePluginMenu(u"&Open Symos", self.action)
        del self.toolbar

    def calculate(self):
        self.dlg.populateTeren()
        self.dlg.populateReceptory()
        self.dlg.populateZdroje()
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()

    def convert_line_to_points(self):
        self.dlg_convert_line_to_points = LineToPointsDialog()
        self.dlg_convert_line_to_points.populateZdroje()
        self.dlg_convert_line_to_points.show()
        # Run the dialog event loop
        result = self.dlg_convert_line_to_points.exec_()

    def convert_polygon_to_points(self):
        self.dlg_convert_polygon_to_points = PolygonToPointsDialog()
        self.dlg_convert_polygon_to_points.populateZdroje()
        self.dlg_convert_polygon_to_points.show()
        # Run the dialog event loop
        result = self.dlg_convert_polygon_to_points.exec_()

    def load_project(self):
        project = QgsProject.instance()
        project.read(
            QFileInfo(os.path.dirname(__file__) + '/sample_data/project.qgs'))

    def load_dem(self):
        msg = u"Zvolili jste stažení DEM. To může chvíli trvat. Chcete opravdu pokračovat??"
        usercontinue = QMessageBox.question(self.iface.mainWindow(),
                                            u"Stažení DEM", msg,
                                            QMessageBox.Yes, QMessageBox.No)
        if usercontinue == QMessageBox.Yes:
            self.download_dem()
        else:
            pass

    def download_dem(self):
        # Used from ZoomToPostcode QGIS plugin
        dem_path = os.path.join(os.path.dirname(__file__),
                                'data/cr-gtiff-jtsk/dem_srtm.tif')
        if not os.path.exists(dem_path):
            url = "http://gisak.vsb.cz/geodata/cr-gtiff-jtsk-0.3.3.zip"
            os.umask(0002)
            try:
                req = urllib2.urlopen(url)
                total_size = int(
                    req.info().getheader('Content-Length').strip())
                downloaded = 0
                CHUNK = 256 * 10240
                pbar = QProgressBar()
                pbar.setMinimum(0)
                pbar.setMaximum(total_size)
                zip_temp = tempfile.NamedTemporaryFile(mode='w+b',
                                                       suffix='.zip',
                                                       delete=False)
                zip_temp_n = zip_temp.name
                zip_temp.seek(0)
                with open(zip_temp_n, 'wb') as fp:
                    while True:
                        pbar.show()
                        chunk = req.read(CHUNK)
                        downloaded += len(chunk)
                        pbar.setValue(downloaded)
                        if not chunk:
                            break
                        fp.write(chunk)
                dem_zip = zipfile.ZipFile(zip_temp)
                dem_path = os.path.join(os.path.dirname(__file__), 'data')
                dem_zip.extractall(dem_path)
                zip_temp.close()
                self.addRasterLayer(
                    os.path.join(os.path.dirname(__file__),
                                 'data/cr-gtiff-jtsk/dem_srtm.tif'),
                    "DEM_SRTM")
                self.addRasterLayer(
                    os.path.join(os.path.dirname(__file__),
                                 'data/cr-gtiff-jtsk/dem_gtopo30.tif'),
                    "DEM_GTOPO30")
            except URLError:
                QMessageBox.information(self.iface.mainWindow(), "HTTP Error",
                                        "Nepodařilo se stáhnout DEM")
        else:
            self.addRasterLayer(
                os.path.join(os.path.dirname(__file__),
                             'data/cr-gtiff-jtsk/dem_srtm.tif'), "DEM_SRTM")
            self.addRasterLayer(
                os.path.join(os.path.dirname(__file__),
                             'data/cr-gtiff-jtsk/dem_gtopo30.tif'),
                "DEM_GTOPO30")

    def addRasterLayer(self, path, label):
        raster = QgsRasterLayer(path, label, "gdal")
        if not raster.isValid():
            QgsMessageLog.logMessage("Layer " + path + " failed to load!",
                                     "Open SYMOS")
        else:
            ##            crs = QgsCoordinateReferenceSystem("EPSG:4326")
            QgsMapLayerRegistry.instance().addMapLayer(raster)