My plugin gui is attached below which has two functions one is selecting state, cities from the combo box and distance to be entered in the lineedit and the other is if we click a pushbutton it will automatically allows user to select features from mapcanvas and provided the distance is entered in lineedit, it will find buffer for all the selected features. But Run button is common for both the functions. I want my code to do one function when run button is clicked. To be more detail, the 1st part has 3 functions 1.add state names 2.find city names 3.calc buffer

And 2nd part, Select area from map has 1 function 1.Bufferarea

Now i want my run button to perform one part when clicked depends on the user selection. FOr example, if the user clicks select area from map (2nd part) it should call bufferarea function and should give result and it should not check the functions under first part and throws error. How this can be done in my py file and what changes should be done in the codes?

It would be more clear if you can see my image.

enter image description here

1 Answer 1


One way to achive this is store the user activity in a variable like


then in your accept() method (which is called when you click Run button), use it to determine what to do

def accept():
  if self.user_action == 'DROPDOWN_SELECTION':
  elif self.user_action == 'MAP_SELECTION':
  • Thank you for the response! But still Map_SELECTION has only one function that wont create a problem. But in case of DROPDOWN SELECTION I have 3 functions say add state names, find city names , calc buffer. How should I cover all these three under "DROPDOWNSELECTION". Am new to QGIS Plugins.
    – User123
    Mar 12, 2015 at 7:25
  • In case of MAP_SELECTION, you will need all 3 fields in Part1 to be filled to perform the calculation, right? You can make sure the Run button is disabled until the user has filled out the State, City and Distance. Once they are filled, the Run button gets enabled and you call the function that performs calculation based on those values. Mar 12, 2015 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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