Python QGIS除非Map图层当前处于打开状态,否则不要打开对话框

时间:2018-01-22 15:37:35

标签: python qgis

    iface.messageBar().pushMessage("Error", "I'm sorry but you must open a map layer in order to fill in the Dialog Box", level=QgsMessageBar.CRITICAL)
    #Dialog Box
    qid = QInputDialog()
    canvas = iface.mapCanvas()
    #Features inside the dialog box 
    input, ok = QInputDialog.getText( qid, "Enter Coordinates", "Enter Coordinates (X,Y)", QLineEdit.Normal, "X" + "," + "Y")
    #If that works, goes through code and splits x,y 
    if ok:
        x = input.split( "," )[ 0 ]
        print x
        y = input.split( "," )[ 1 ]
        print y
        #If X and Y are right coordinates:
        if x.isnumeric() and y.isnumeric(): 
            scale=225
            rect = QgsRectangle(float(x)-scale,float(y)-scale, float(x)+scale,float(y)+scale)
            canvas.setExtent(rect)
            pt = QgsPoint(float(x),float(y))
            canvas.refresh()
            print x + "," + y

    else: 
        #MessageBox after cancel clicked 
        QMessageBox.information(None, "debug", "User Cancelled!") 

我想添加某种IF语句,因此如果地图图层尚未打开则会显示错误消息

0 个答案:

没有答案