How can I access to elements in dir(some_class) of PyQGIS without a dictionary in my

المشرف العام

Administrator
طاقم الإدارة
I'm developing a QGIS plugin to search class methods in the different classes of PyQGIS. I used three widgets: 2 objects of type QLineEdit (for classes and class methods) and one QTextBrowser (for results). The snipped code is below:

... def run(self): """Run method that performs all the real work""" text_search_class = self.dlg.lineEdit.text() text_search_line = self.dlg.lineEdit2.text() dict = {'QgsVectorLayer' : dir(QgsVectorLayer) 'QgsRasterLayer' : dir(QgsRasterLayer), 'QLineEdit' : dir(QLineEdit)} if ( text_search_class in dict.keys() ) == True: idx = dict.keys().index(text_search_class) elements = getPat2(text_search_line, dict.values()[idx]) n = len(elements) message = str(n) + " elements of '" + text_search_line + "' in " + text_search_class + "\n\n" for i in range(n - 1): message += elements + ', ' if n != 0: message += elements[n - 1] txtBox = self.dlg.textFeedback txtBox.setText(message) else: message = "The chosen class does not exist" txtBox = self.dlg.textFeedback txtBox.setText(message) # show the dialog self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: # Do something useful here - delete the line containing pass and # substitute with your code. passMy issue is that I had to use a dictionary to get the list of methods from dir(class) (in my code I only use QgsVectorLayer, QgsRasterLayer and QLineEdit; but they are more than 1200) because, for example, the true list is for dir(QgsVectorLayer); not for dir('QgsVectorLayer') when I don't use the dictionary. My question is how can I access to elements in dir(some_class) of PyQGIS without a dictionary.

The next pictures show the execution of the plugin.

Without any text to search:



Searching by pending, set y max, respectively, in QgsVectorLayer, QgsRasterLayer and QLineEdit:





أكثر...
 
أعلى