1

I need to work with some layers and provide output in the form of an Excel file. I have applied a push button in my QT tool design. I have also defined function which is supposed to work after I press my push button but nothing appears in the console.

Here is an image of the button:

enter image description here

and here is an image of the Log panel where I want it to print.

enter image description here

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from qgis import processing

import sys

from operator import itemgetter
from qgis.analysis import (QgsGraphBuilder,QgsVectorLayerDirector,QgsGraphAnalyzer)
from qgis.utils import iface

class Layer(object):
    def __init__(self):
        print('TestDistributionCable')


class LayerUI(QtWidgets.QWidget):
    def __init__(self, iface, dlg):
        print('Testing')
        QtWidgets.QWidget.__init__(self)
        self.iface = iface
        self.dlg = dlg
        self.sf_lyr = None
        self.ui_manager()
        self.dlg.pushButton.clicked.connect(self.CMJSheetCreation)
    def __del__(self):
        pass

    def CMJSheetCreation(self):
        print("inside")
        QgisAll_layers = QgsProject.instance().mapLayers().values()
        path = QgsProject.instance().absolutePath()
        # output = str(path) + "//fibre_cable.shp"
        print("path - " + str(path))

        crs = QgsProject.instance().crs()
        print("CRS - " + str(crs))

        for layer in QgisAll_layers:
            print(layer)
            if layer.name() == "Fibre Joint":
                lyr_fj = polepointlayer.name()
                print("layr_fj")
                print(lyr_fj)
                crs = QgsProject.instance().crs()
                # Create the output layer
                break


        for chamberpointlayer in QgisAll_layers:
            if chamberpointlayer.name() == "Chamber":
                chamber_layer = chamberpointlayer.name()
                break
        for boundarieslayer in QgisAll_layers:
            if boundarieslayer.name() == "Boundaries":
                lyr_Boundaries = boundarieslayer.name()
                break
1
  • Could you please add a working example producing the issue? What is dlg, how/where do you open it? What is ui_manager(). These are missing. Therefore, we cannot test it. Jan 6 at 8:05
1

Check your indents, not sure if it is a formatting error when you copy-pasted or actually how your code is written. There is two lines that are in the class definition and not in function scope, so they are not actually ever called. Python is whitespace sensitive you cannot change indenting like you can in C or Javascript.

The two lines are:

self.dlg.pushButton.clicked.connect(self.CMJSheetCreation)

print("inside")

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from qgis import processing

import sys

from operator import itemgetter
from qgis.analysis import (QgsGraphBuilder,QgsVectorLayerDirector,QgsGraphAnalyzer)
from qgis.utils import iface

class Layer(object):
    def __init__(self):
        print('TestDistributionCable')


class LayerUI(QtWidgets.QWidget):
    def __init__(self, iface, dlg):
        print('Testing')
        QtWidgets.QWidget.__init__(self)
        self.iface = iface
        self.dlg = dlg
        self.sf_lyr = None
        self.ui_manager()
        self.dlg.pushButton.clicked.connect(self.CMJSheetCreation) # This lines needs indenting.
    def __del__(self):
        pass

    def CMJSheetCreation(self):
        print("inside") # This line needs indenting.
        QgisAll_layers = QgsProject.instance().mapLayers().values()
        path = QgsProject.instance().absolutePath()
        # output = str(path) + "//fibre_cable.shp"
        print("path - " + str(path))

        crs = QgsProject.instance().crs()
        print("CRS - " + str(crs))

        for layer in QgisAll_layers:
            print(layer)
            if layer.name() == "Fibre Joint":
                lyr_fj = polepointlayer.name()
                print("layr_fj")
                print(lyr_fj)
                crs = QgsProject.instance().crs()
                # Create the output layer
                break


        for chamberpointlayer in QgisAll_layers:
            if chamberpointlayer.name() == "Chamber":
                chamber_layer = chamberpointlayer.name()
                break
        for boundarieslayer in QgisAll_layers:
            if boundarieslayer.name() == "Boundaries":
                lyr_Boundaries = boundarieslayer.name()
                break
1
  • Hi @RomaH, the indenting issue occured while copy pasting and those are not the actual issue, the plug in button seems to not work , is there some issue in activating the plug in ? Jan 6 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.