Python plugin.Plugin() Examples

The following are 3 code examples of plugin.Plugin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module plugin , or try the search function .
Example #1
Source File: PluginManager.py    From Jarvis with MIT License 6 votes vote down vote up
def check(self, plugin):
        """
        Parses plugin.require(). Plase refere plugin.Plugin-documentation
        """
        plugin_requirements = self._plugin_get_requirements(plugin.require())

        if not self._check_platform(plugin_requirements["platform"]):
            required_platform = ", ".join(plugin_requirements["platform"])
            return "Requires os {}".format(required_platform)

        if not self._check_network(plugin_requirements["network"], plugin):
            return "Requires networking"

        natives_ok = self._check_native(plugin_requirements["native"], plugin)
        if natives_ok is not True:
            return natives_ok

        return True 
Example #2
Source File: plugin_test.py    From qgis-versioning with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, host, pguser):

        self.host = host
        self.pguser = pguser

        # create the test database
        os.system(f"psql -h {host} -U {pguser} {dbname} -f {sql_file}")

        pg_conn_info = f"dbname={dbname} host={host} user={pguser}"
        pcon = psycopg2.connect(pg_conn_info)
        pcur = pcon.cursor()
        pcur.execute("""
        INSERT INTO epanet.junctions (id, elevation, geom)
        VALUES (33, 30, ST_GeometryFromText('POINT(3 3)',2154));
        """)
        pcur.execute("""
        INSERT INTO epanet.junctions (id, elevation, geom)
        VALUES (44, 40, ST_GeometryFromText('POINT(4 4)',2154));
        """)
        pcon.commit()
        pcon.close()

        # Initialize project
        layer_source = f"""host='{host}' dbname='{dbname}' user='{pguser}'
        srid=2154 table="epanet"."junctions" (geom) sql="""
        j_layer = QgsVectorLayer(layer_source, "junctions", "postgres")
        assert(j_layer and j_layer.isValid() and
               j_layer.featureCount() == 4)
        assert(QgsProject.instance().addMapLayer(j_layer, False))

        root = QgsProject.instance().layerTreeRoot()
        group = root.addGroup("epanet_group")
        group.addLayer(j_layer)

        self.versioning_plugin = plugin.Plugin(iface)
        self.versioning_plugin.current_layers = [j_layer]
        self.versioning_plugin.current_group = group

        self.historize() 
Example #3
Source File: PluginManager.py    From Jarvis with MIT License 4 votes vote down vote up
def _load_plugin(self, plugin_to_add, plugin_storage):
        def handle_aliases(plugin_to_add):
            add_plugin(
                plugin_to_add.get_name().split(' '),
                plugin_to_add,
                plugin_storage)

            for name in plugin_to_add.alias():
                add_plugin(
                    name.lower().split(' '),
                    plugin_to_add,
                    plugin_storage)

        def add_plugin(name, plugin_to_add, parent):
            if len(name) == 1:
                add_plugin_single(name[0], plugin_to_add, parent)
            else:
                add_plugin_compose(name[0], name[1:], plugin_to_add, parent)

        def add_plugin_single(name, plugin_to_add, parent):
            plugin_existing = parent.get_plugins(name)
            if plugin_existing is None:
                parent.add_plugin(name, plugin_to_add)
            else:
                if not plugin_existing.is_callable_plugin():
                    plugin_existing.change_with(plugin_to_add)
                    parent.add_plugin(name, plugin_to_add)
                else:
                    error("Duplicated plugin {}!".format(name))

        def add_plugin_compose(
                name_first,
                name_remaining,
                plugin_to_add,
                parent):
            plugin_existing = parent.get_plugins(name_first)

            if plugin_existing is None:
                plugin_existing = plugin.Plugin()
                plugin_existing._name = name_first
                plugin_existing.__doc__ = ''
                parent.add_plugin(name_first, plugin_existing)

            add_plugin(name_remaining, plugin_to_add, plugin_existing)

        return handle_aliases(plugin_to_add)