I created a Python plugin in QGIS which is working fine. Now I want that whenever a user clicks on the plugin button (located on top of QGIS bar) it counts the number of clicks. If the number of clicks is odd my plugin should start running and if the number of clicks is even it should stop running (interrupting its execution). How can I do this and how can I map my code to this button so that it knows the number of clicks?
What I've done so far
def initGui(self): icon_path = ':/plugins/my_tracker/icon.png' self.iconAction = self.add_action( icon_path, text=self.tr(u'My tracker plug'), callback=self.run, parent=self.iface.mainWindow()) def run(self): if (self.iconAction.isChecked()): print ('Checked') self.show_markers() // a method to do something else: print ('Unchecked') print("going to close socket", mySocket.close())
The problem is when I click on the plugin button it always runs the else part. It's not running the if part. Why?