[Qgis-developer] QGIS plugin: very basic information

Filippo Gualla filippog16 at gmail.com
Wed May 13 03:15:07 PDT 2015


Hi everybody,

my name is Filippo and I am new in this forum. For my thesis I am trying to
develop a QGIS plugin with Python. I have already read many stuff from the
web (Python cookbook, all the official web-pages and other blog) and then I
started to go through some plugin downloaded from the repository and
compare them (I do not know if I am allowed to write with which plugin I am
doing my comparisons). I have already used PluginBuilder to make the
starting files (py, ui, ...) and I have created the GUI from PyQt and
translated the ui file into the py file via Prompt MS DOS. But now I have
some problem to understand the "frame" behind a plugin.
Here some very general and basic questions (I need to stress that on the
web I haven´t found any source which goes in detail to the basics):

01 - In general, in my plugin I need to import a raster DEM and a vector
layer + some parameters. In my GUI (from PyQt) I created the places where
insert vector, DEM and variables. Each of this spaces has its own proper
name that should be (as I understood) entered in the main py file script (I
checked my "ui_<name>.py" file and as expected I found the name I entered
in PyQt). Now my question is: where (in which method in the main py file)
and how I recall my variables and parameters(within __init__ or in the
method which perform the analysis)? I ask because it is not clear where I
access my input data (in one plugin I compared I assume it was from
__init__, in another only in the method that perform the analysis... I
understand that maybe these differences are due to different needs, but I
wonder which is the easiest way, now I do not need something perfect from a
"script" point of view;


02 - It is unclear the relationship among all the methods within the main
py file (aka the class defined in the main py file), like __init__, initGUI
+ all the others. Some of them are default once the user create the files
with PlugIn Builder but I assume there is something more to know because
most of the plugin show the default and others, an other plugin only
__init__ and initGUI. In any case in my mind I figured out a method which
recall all the data from the GUI through the name defined in PyQt, then
another def method which takes them as input and perform the analysis and
finally another method to show/print the result, but still I do not get the
relationship among all those methods (I have already written some script
both with python and matlab and now in my mind the process in quite
straightforward but here in the plugin, involving a class and method I
hardly understand the frame);


03 - (more theoretical) I know that on OO paradigm I can define a class and
several method within that class. I have created some very simple classes
and in the __init__ method I set some arguments, e.g. two (I save the class
as a py file). Then I recall that py file in the IDLE I set something like
var = <class_name>(arg1, arg2). That´s clear BUT when I look into a QGIS
plugin, some times I read:

def __init__(self, iface):
        self.iface = iface
self.canvas = self.iface.mapCanvas()

"Canvas" is not listed in the arguments of __init__, why? I assume is a
sort of "property" of the self object.

[in detail here, what is "mapCanvas"? Is it a method of the object "iface"?
How the developer knew that "mapCanvas" had to be invoked? I ask because if
I go through the API classes of QGIS there are thousand of them and I do
not know where to start to look for]

04 - In the main py file of a plugin (usually the name of the plugin) I
always find a class definition. What I do not understand is when I recall
this class? As written above (question 03) when I create my class in a py
file, I can use it via IDLE. Can someone explain me which is the logic path
in recalling the classes (also in other file like "...dialog.py" a class is
defined BUT this class is imported finally in the main py file)

I hope to not be "out of topic".

Regards,

Filippo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150513/fd700c88/attachment-0001.html>


More information about the Qgis-developer mailing list