initial commit

This commit is contained in:
nobohan 2021-07-13 10:39:19 +02:00
commit ca258bc445
32 changed files with 3853 additions and 0 deletions

34
Notes.md Normal file
View File

@ -0,0 +1,34 @@
Test for a plugin that add an action in the layout
=================================================
13/07/2021, Longlaville
- created a new plugin using plugin builder
- make a symbolic link to the plugin folder
```
cd ~/.local/share/QGIS/QGIS3/profiles/default/python/plugins
ln -s /mnt/tera/ChampsLibres/Projets/FormationQGIS/pyQGIS/plugin_layout/plot_layout
```
- try to add a button in layout by copying the data plotly plugin
- copier à peu près le dossier gui de DataPlotly:
- gui/gui.py: PlotLayoutItemGuiMetadata, PlotLayoutItemWidget
- gui/gui_utils.py: GuiUtils
- gui/plot_settings_widget.py: DataPlotlyPanelWidget,
- copier à peu près le dossier Layout:
- layout/layout.py: PlotLayoutItemMetadata, PlotLayoutItem qui est un QgsLayoutItem: c'est le composant graphique dans un layout.
- ajouter dans PlotInLayout::__init__ :
self.plot_item_metadata = PlotLayoutItemMetadata()
self.plot_item_gui_metadata = None
QgsApplication.layoutItemRegistry().addLayoutItemType(self.plot_item_metadata)
- ajouter dans PlotInLayout::initGui:

244
plot_layout/Makefile Normal file
View File

@ -0,0 +1,244 @@
#/***************************************************************************
# PlotInLayout
#
# test for adding plot in layout
# -------------------
# begin : 2021-07-13
# git sha : $Format:%H$
# copyright : (C) 2021 by Champs-Libres
# email : julien.minet@champs-libres.coop
# ***************************************************************************/
#
#/***************************************************************************
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# ***************************************************************************/
#################################################
# Edit the following to match your sources lists
#################################################
#Add iso code for any locales you want to support here (space separated)
# default is no locales
# LOCALES = af
LOCALES =
# If locales are enabled, set the name of the lrelease binary on your system. If
# you have trouble compiling the translations, you may have to specify the full path to
# lrelease
#LRELEASE = lrelease
#LRELEASE = lrelease-qt4
# translation
SOURCES = \
__init__.py \
plot_layout.py plot_layout_dialog.py
PLUGINNAME = plot_layout
PY_FILES = \
__init__.py \
plot_layout.py plot_layout_dialog.py
UI_FILES = plot_layout_dialog_base.ui
EXTRAS = metadata.txt icon.png
EXTRA_DIRS =
COMPILED_RESOURCE_FILES = resources.py
PEP8EXCLUDE=pydev,resources.py,conf.py,third_party,ui
# QGISDIR points to the location where your plugin should be installed.
# This varies by platform, relative to your HOME directory:
# * Linux:
# .local/share/QGIS/QGIS3/profiles/default/python/plugins/
# * Mac OS X:
# Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
# * Windows:
# AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins'
QGISDIR=/home/julien/.local/share/QGIS/QGIS3/profiles/default/python/plugins/
#################################################
# Normally you would not need to edit below here
#################################################
HELP = help/build/html
PLUGIN_UPLOAD = $(c)/plugin_upload.py
RESOURCE_SRC=$(shell grep '^ *<file' resources.qrc | sed 's@</file>@@g;s/.*>//g' | tr '\n' ' ')
.PHONY: default
default:
@echo While you can use make to build and deploy your plugin, pb_tool
@echo is a much better solution.
@echo A Python script, pb_tool provides platform independent management of
@echo your plugins and runs anywhere.
@echo You can install pb_tool using: pip install pb_tool
@echo See https://g-sherman.github.io/plugin_build_tool/ for info.
compile: $(COMPILED_RESOURCE_FILES)
%.py : %.qrc $(RESOURCES_SRC)
pyrcc5 -o $*.py $<
%.qm : %.ts
$(LRELEASE) $<
test: compile transcompile
@echo
@echo "----------------------"
@echo "Regression Test Suite"
@echo "----------------------"
@# Preceding dash means that make will continue in case of errors
@-export PYTHONPATH=`pwd`:$(PYTHONPATH); \
export QGIS_DEBUG=0; \
export QGIS_LOG_FILE=/dev/null; \
nosetests -v --with-id --with-coverage --cover-package=. \
3>&1 1>&2 2>&3 3>&- || true
@echo "----------------------"
@echo "If you get a 'no module named qgis.core error, try sourcing"
@echo "the helper script we have provided first then run make test."
@echo "e.g. source run-env-linux.sh <path to qgis install>; make test"
@echo "----------------------"
deploy: compile doc transcompile
@echo
@echo "------------------------------------------"
@echo "Deploying plugin to your .qgis2 directory."
@echo "------------------------------------------"
# The deploy target only works on unix like operating system where
# the Python plugin directory is located at:
# $HOME/$(QGISDIR)/python/plugins
mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(COMPILED_RESOURCE_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(EXTRAS) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vfr i18n $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vfr $(HELP) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help
# Copy extra directories if any
(foreach EXTRA_DIR,(EXTRA_DIRS), cp -R (EXTRA_DIR) (HOME)/(QGISDIR)/python/plugins/(PLUGINNAME)/;)
# The dclean target removes compiled python files from plugin directory
# also deletes any .git entry
dclean:
@echo
@echo "-----------------------------------"
@echo "Removing any compiled python files."
@echo "-----------------------------------"
find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete
find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".git" -prune -exec rm -Rf {} \;
derase:
@echo
@echo "-------------------------"
@echo "Removing deployed plugin."
@echo "-------------------------"
rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
zip: deploy dclean
@echo
@echo "---------------------------"
@echo "Creating plugin zip bundle."
@echo "---------------------------"
# The zip target deploys the plugin and creates a zip file with the deployed
# content. You can then upload the zip file on http://plugins.qgis.org
rm -f $(PLUGINNAME).zip
cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME)
package: compile
# Create a zip package of the plugin named $(PLUGINNAME).zip.
# This requires use of git (your plugin development directory must be a
# git repository).
# To use, pass a valid commit or tag as follows:
# make package VERSION=Version_0.3.2
@echo
@echo "------------------------------------"
@echo "Exporting plugin to zip package. "
@echo "------------------------------------"
rm -f $(PLUGINNAME).zip
git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION)
echo "Created package: $(PLUGINNAME).zip"
upload: zip
@echo
@echo "-------------------------------------"
@echo "Uploading plugin to QGIS Plugin repo."
@echo "-------------------------------------"
$(PLUGIN_UPLOAD) $(PLUGINNAME).zip
transup:
@echo
@echo "------------------------------------------------"
@echo "Updating translation files with any new strings."
@echo "------------------------------------------------"
@chmod +x scripts/update-strings.sh
@scripts/update-strings.sh $(LOCALES)
transcompile:
@echo
@echo "----------------------------------------"
@echo "Compiled translation files to .qm files."
@echo "----------------------------------------"
@chmod +x scripts/compile-strings.sh
@scripts/compile-strings.sh $(LRELEASE) $(LOCALES)
transclean:
@echo
@echo "------------------------------------"
@echo "Removing compiled translation files."
@echo "------------------------------------"
rm -f i18n/*.qm
clean:
@echo
@echo "------------------------------------"
@echo "Removing uic and rcc generated files"
@echo "------------------------------------"
rm $(COMPILED_UI_FILES) $(COMPILED_RESOURCE_FILES)
doc:
@echo
@echo "------------------------------------"
@echo "Building documentation using sphinx."
@echo "------------------------------------"
cd help; make html
pylint:
@echo
@echo "-----------------"
@echo "Pylint violations"
@echo "-----------------"
@pylint --reports=n --rcfile=pylintrc . || true
@echo
@echo "----------------------"
@echo "If you get a 'no module named qgis.core' error, try sourcing"
@echo "the helper script we have provided first then run make pylint."
@echo "e.g. source run-env-linux.sh <path to qgis install>; make pylint"
@echo "----------------------"
# Run pep8 style checking
#http://pypi.python.org/pypi/pep8
pep8:
@echo
@echo "-----------"
@echo "PEP8 issues"
@echo "-----------"
@pep8 --repeat --ignore=E203,E121,E122,E123,E124,E125,E126,E127,E128 --exclude $(PEP8EXCLUDE) . || true
@echo "-----------"
@echo "Ignored in PEP8 check:"
@echo $(PEP8EXCLUDE)

42
plot_layout/README.html Normal file
View File

@ -0,0 +1,42 @@
<html>
<body>
<h3>Plugin Builder Results</h3>
Congratulations! You just built a plugin for QGIS!<br/><br />
<div id='help' style='font-size:.9em;'>
Your plugin <b>PlotInLayout</b> was created in:<br>
&nbsp;&nbsp;<b>/mnt/tera/ChampsLibres/Projets/FormationQGIS/pyQGIS/plugin_layout/plot_layout</b>
<p>
Your QGIS plugin directory is located at:<br>
&nbsp;&nbsp;<b>/home/julien/.local/share/QGIS/QGIS3/profiles/default/python/plugins</b>
<p>
<h3>What's Next</h3>
<ol>
<li>If resources.py is not present in your plugin directory, compile the resources file using pyrcc5 (simply use <b>pb_tool</b> or <b>make</b> if you have automake)
<li>Optionally, test the generated sources using <b>make test</b> (or run tests from your IDE)
<li>Copy the entire directory containing your new plugin to the QGIS plugin directory (see Notes below)
<li>Test the plugin by enabling it in the QGIS plugin manager
<li>Customize it by editing the implementation file <b>plot_layout.py</b>
<li>Create your own custom icon, replacing the default <b>icon.png</b>
<li>Modify your user interface by opening <b>plot_layout_dialog_base.ui</b> in Qt Designer
</ol>
Notes:
<ul>
<li>You can use <b>pb_tool</b> to compile, deploy, and manage your plugin. Tweak the <i>pb_tool.cfg</i> file included with your plugin as you add files. Install <b>pb_tool</b> using
<i>pip</i> or <i>easy_install</i>. See <b>http://loc8.cc/pb_tool</b> for more information.
<li>You can also use the <b>Makefile</b> to compile and deploy when you
make changes. This requires GNU make (gmake). The Makefile is ready to use, however you
will have to edit it to add addional Python source files, dialogs, and translations.
</ul>
</div>
<div style='font-size:.9em;'>
<p>
For information on writing PyQGIS code, see <b>http://loc8.cc/pyqgis_resources</b> for a list of resources.
</p>
</div>
<p>
&copy;2011-2019 GeoApt LLC - geoapt.com
</p>
</body>
</html>

32
plot_layout/README.txt Normal file
View File

@ -0,0 +1,32 @@
Plugin Builder Results
Your plugin PlotInLayout was created in:
/mnt/tera/ChampsLibres/Projets/FormationQGIS/pyQGIS/plugin_layout/plot_layout
Your QGIS plugin directory is located at:
/home/julien/.local/share/QGIS/QGIS3/profiles/default/python/plugins
What's Next:
* Copy the entire directory containing your new plugin to the QGIS plugin
directory
* Compile the resources file using pyrcc5
* Run the tests (``make test``)
* Test the plugin by enabling it in the QGIS plugin manager
* Customize it by editing the implementation file: ``plot_layout.py``
* Create your own custom icon, replacing the default icon.png
* Modify your user interface by opening PlotInLayout_dialog_base.ui in Qt Designer
* You can use the Makefile to compile your Ui and resource files when
you make changes. This requires GNU make (gmake)
For more information, see the PyQGIS Developer Cookbook at:
http://www.qgis.org/pyqgis-cookbook/index.html
(C) 2011-2018 GeoApt LLC - geoapt.com

36
plot_layout/__init__.py Normal file
View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
PlotInLayout
A QGIS plugin
test for adding plot in layout
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-07-13
copyright : (C) 2021 by Champs-Libres
email : julien.minet@champs-libres.coop
git sha : $Format:%H$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load PlotInLayout class from file PlotInLayout.
:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""
#
from .plot_layout import PlotInLayout
return PlotInLayout(iface)

Binary file not shown.

Binary file not shown.

Binary file not shown.

277
plot_layout/gui/gui.py Normal file
View File

@ -0,0 +1,277 @@
from qgis.PyQt.QtCore import (
QCoreApplication,
QItemSelectionModel
)
from qgis.PyQt.QtWidgets import (
QListWidget,
QHBoxLayout,
QPushButton,
QVBoxLayout
)
from qgis.gui import (
QgsLayoutItemAbstractGuiMetadata,
QgsLayoutItemBaseWidget,
QgsLayoutItemPropertiesWidget
)
from qgis.core import ( QgsLayoutItemRegistry )
from plot_settings_widget import DataPlotlyPanelWidget
from gui_utils import GuiUtils
ITEM_TYPE = QgsLayoutItemRegistry.PluginItem + 1338
class PlotLayoutItemWidget(QgsLayoutItemBaseWidget):
"""
Configuration widget for layout plot items
"""
def __init__(self, parent, layout_object):
super().__init__(parent, layout_object)
self.plot_item = layout_object
self.message_bar = None
# vl = QVBoxLayout()
# vl.setContentsMargins(0, 0, 0, 0)
# plot_tools_layout = QHBoxLayout()
# plot_add_button = QPushButton()
# plot_add_button.setIcon(GuiUtils.get_icon('symbologyAdd.svg'))
# plot_add_button.setToolTip('Add a new plot')
# plot_tools_layout.addWidget(plot_add_button)
# plot_add_button.clicked.connect(self.add_plot)
# plot_remove_button = QPushButton()
# plot_remove_button.setIcon(GuiUtils.get_icon('symbologyRemove.svg'))
# plot_remove_button.setToolTip('Remove selected plot')
# plot_tools_layout.addWidget(plot_remove_button)
# plot_remove_button.clicked.connect(self.remove_plot)
# plot_move_up_button = QPushButton()
# plot_move_up_button.setIcon(GuiUtils.get_icon('mActionArrowUp.svg'))
# plot_move_up_button.setToolTip('Move selected plot up')
# plot_tools_layout.addWidget(plot_move_up_button)
# plot_move_up_button.clicked.connect(self.move_up_plot)
# plot_move_down_button = QPushButton()
# plot_move_down_button.setIcon(GuiUtils.get_icon('mActionArrowDown.svg'))
# plot_move_down_button.setToolTip('Move selected plot down')
# plot_tools_layout.addWidget(plot_move_down_button)
# plot_move_down_button.clicked.connect(self.move_down_plot)
# vl.addLayout(plot_tools_layout)
# self.plot_list = QListWidget()
# self.plot_list.setSelectionMode(QListWidget.SingleSelection)
# vl.addWidget(self.plot_list)
# self.populate_plot_list()
# plot_properties_button = QPushButton(self.tr('Setup Selected Plot'))
# vl.addWidget(plot_properties_button)
# plot_properties_button.clicked.connect(self.show_properties)
# self.panel = None
# self.setPanelTitle(self.tr('Plot Properties'))
# self.item_properties_widget = QgsLayoutItemPropertiesWidget(self, layout_object)
# vl.addWidget(self.item_properties_widget)
# self.setLayout(vl)
# def populate_plot_list(self):
# """
# Clears and re-populates the plot list widget. The currently selection is retained
# """
# selected_index = self.plot_list.currentRow()
# self.plot_list.clear()
# for setting in self.plot_item.plot_settings:
# plot_type = setting.plot_type if setting.plot_type is not None else '(not set)'
# legend_title = ('[' + setting.properties.get('name') + ']') \
# if setting.properties.get('name', '') != '' else ''
# self.plot_list.addItem(plot_type + ' ' + legend_title)
# # select index within range [0, len(plot_settings)-1]
# selected_index = max(0, min(len(self.plot_item.plot_settings) - 1, selected_index))
# self.plot_list.setCurrentRow(selected_index, QItemSelectionModel.SelectCurrent)
# def add_plot(self):
# """
# Adds a new plot and updates the plot list and the plot item
# """
# self.plot_item.add_plot()
# self.populate_plot_list()
# self.plot_item.refresh()
# def remove_plot(self):
# """
# Removes the selected plot and updates the plot list and the plot item
# """
# selected_index = self.plot_list.currentRow()
# if selected_index < 0:
# return
# self.plot_item.remove_plot(selected_index)
# self.populate_plot_list()
# self.plot_item.refresh()
# def move_up_plot(self):
# """
# Moves the selected plot up and updates the plot list and the plot item
# """
# selected_index = self.plot_list.currentRow()
# if selected_index <= 0:
# return
# item = self.plot_item.plot_settings.pop(selected_index)
# self.plot_item.plot_settings.insert(selected_index - 1, item)
# self.plot_list.setCurrentRow(selected_index - 1, QItemSelectionModel.SelectCurrent)
# self.populate_plot_list()
# self.plot_item.refresh()
# def move_down_plot(self):
# """
# Moves the selected plot down and updates the plot list and the plot item
# """
# selected_index = self.plot_list.currentRow()
# if selected_index >= len(self.plot_item.plot_settings) - 1:
# return
# item = self.plot_item.plot_settings.pop(selected_index)
# self.plot_item.plot_settings.insert(selected_index + 1, item)
# self.plot_list.setCurrentRow(selected_index + 1, QItemSelectionModel.SelectCurrent)
# self.populate_plot_list()
# self.plot_item.refresh()
# def show_properties(self):
# """
# Shows the plot properties panel
# """
# selected_plot_index = self.plot_list.currentRow()
# if selected_plot_index < 0:
# return
# self.panel = DataPlotlyPanelWidget(mode=DataPlotlyPanelWidget.MODE_LAYOUT, message_bar=self.message_bar)
# # not quite right -- we ideally want to also add the source layer scope into the context given by plot item,
# # but that causes a hard lock in the Python GIL (because PyQt doesn't release the GIL when creating the menu
# # for the property override buttons). Nothing much we can do about that here (or in QGIS,
# # it's a Python/PyQt limitation)
# self.panel.registerExpressionContextGenerator(self.plot_item)
# self.panel.set_print_layout(self.plot_item.layout())
# self.panel.linked_map_combo.blockSignals(True)
# self.panel.linked_map_combo.setItem(self.plot_item.linked_map)
# self.panel.linked_map_combo.blockSignals(False)
# self.panel.filter_by_map_check.toggled.connect(self.filter_by_map_toggled)
# self.panel.filter_by_atlas_check.toggled.connect(self.filter_by_atlas_toggled)
# self.panel.linked_map_combo.itemChanged.connect(self.linked_map_changed)
# self.panel.filter_by_map_check.blockSignals(True)
# self.panel.filter_by_map_check.setChecked(self.plot_item.filter_by_map)
# self.panel.filter_by_map_check.blockSignals(False)
# self.panel.filter_by_atlas_check.blockSignals(True)
# self.panel.filter_by_atlas_check.setChecked(self.plot_item.filter_by_atlas)
# self.panel.filter_by_atlas_check.blockSignals(False)
# self.panel.set_settings(self.plot_item.plot_settings[selected_plot_index])
# # self.panel.set_settings(self.layoutItem().plot_settings)
# self.openPanel(self.panel)
# self.panel.widgetChanged.connect(self.update_item_settings)
# self.panel.panelAccepted.connect(self.set_item_settings)
# def update_item_settings(self):
# """
# Updates the plot item without dismissing the properties panel
# """
# if not self.panel:
# return
# self.plot_item.set_plot_settings(self.plot_list.currentRow(), self.panel.get_settings())
# self.populate_plot_list()
# self.plot_item.update()
# def set_item_settings(self):
# """
# Updates the plot item based on the settings from the properties panel
# """
# if not self.panel:
# return
# self.plot_item.set_plot_settings(self.plot_list.currentRow(), self.panel.get_settings())
# self.populate_plot_list()
# self.panel = None
# self.plot_item.update()
# def filter_by_map_toggled(self, value):
# """
# Triggered when the filter by map option is toggled
# """
# self.plot_item.filter_by_map = bool(value)
# self.plot_item.update()
# def filter_by_atlas_toggled(self, value):
# """
# Triggered when the filter by atlas option is toggled
# """
# self.plot_item.filter_by_atlas = bool(value)
# self.plot_item.update()
# def linked_map_changed(self, linked_map):
# """
# Triggered when the linked map is changed
# """
# self.plot_item.set_linked_map(linked_map)
# self.plot_item.update()
# def setNewItem(self, item): # pylint: disable=missing-docstring
# if item.type() != ITEM_TYPE:
# return False
# self.plot_item = item
# self.item_properties_widget.setItem(item)
# self.populate_plot_list()
# if self.panel is not None:
# self.panel.set_settings(self.plot_item.plot_settings[0])
# self.panel.filter_by_map_check.blockSignals(True)
# self.panel.filter_by_map_check.setChecked(item.filter_by_map)
# self.panel.filter_by_map_check.blockSignals(False)
# self.panel.filter_by_atlas_check.blockSignals(True)
# self.panel.filter_by_atlas_check.setChecked(item.filter_by_atlas)
# self.panel.filter_by_atlas_check.blockSignals(False)
# self.panel.linked_map_combo.blockSignals(True)
# self.panel.linked_map_combo.setItem(self.plot_item.linked_map)
# self.panel.linked_map_combo.blockSignals(False)
# return True
# def setDesignerInterface(self, iface): # pylint: disable=missing-docstring
# super().setDesignerInterface(iface)
# self.message_bar = iface.messageBar()
# if self.panel:
# self.panel.message_bar = self.message_bar
class PlotLayoutItemGuiMetadata(QgsLayoutItemAbstractGuiMetadata):
"""
Metadata for plot item GUI classes
"""
def __init__(self):
super().__init__(ITEM_TYPE, 'test')
def creationIcon(self): # pylint: disable=missing-docstring, no-self-use
return GuiUtils.get_icon('circle.svg')
def createItemWidget(self, item): # pylint: disable=missing-docstring, no-self-use
return PlotLayoutItemWidget(None, item)

View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
"""GUI Utilities
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import os
from qgis.PyQt.QtGui import QIcon
class GuiUtils:
"""
Utilities for GUI plugin components
"""
@staticmethod
def get_icon(icon: str) -> QIcon:
"""
Returns a plugin icon
:param icon: icon name (svg file name)
:return: QIcon
"""
path = GuiUtils.get_icon_svg(icon)
if not path:
return QIcon()
return QIcon(path)
@staticmethod
def get_icon_svg(icon: str) -> str:
"""
Returns a plugin icon's SVG file path
:param icon: icon name (svg file name)
:return: icon svg path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'icons',
icon)
if not os.path.exists(path):
return ''
return path
@staticmethod
def get_ui_file_path(file: str) -> str:
"""
Returns a UI file's path
:param file: file name (uifile name)
:return: ui file path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'ui',
file)
if not os.path.exists(path):
return ''
return path

File diff suppressed because it is too large Load Diff

130
plot_layout/help/Makefile Normal file
View File

@ -0,0 +1,130 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/template_class.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/template_class.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/template_class"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/template_class"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

155
plot_layout/help/make.bat Normal file
View File

@ -0,0 +1,155 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. changes to make an overview over all changed/added/deprecated items
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\template_class.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\template_class.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
:end

View File

@ -0,0 +1,216 @@
# -*- coding: utf-8 -*-
#
# PlotInLayout documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 12 17:11:03 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.todo', 'sphinx.ext.imgmath', 'sphinx.ext.viewcode']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'PlotInLayout'
copyright = u'2013, Champs-Libres'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_TemplateModuleNames = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'TemplateClassdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PlotInLayout.tex', u'PlotInLayout Documentation',
u'Champs-Libres', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'TemplateClass', u'PlotInLayout Documentation',
[u'Champs-Libres'], 1)
]

View File

@ -0,0 +1,20 @@
.. PlotInLayout documentation master file, created by
sphinx-quickstart on Sun Feb 12 17:11:03 2012.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to PlotInLayout's documentation!
============================================
Contents:
.. toctree::
:maxdepth: 2
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

11
plot_layout/i18n/af.ts Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0" language="af" sourcelanguage="en">
<context>
<name>@default</name>
<message>
<location filename="test_translations.py" line="48"/>
<source>Good morning</source>
<translation>Goeie more</translation>
</message>
</context>
</TS>

BIN
plot_layout/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

View File

@ -0,0 +1,53 @@
from qgis.core import (
QgsLayoutItem,
QgsLayoutItemRegistry,
QgsLayoutItemAbstractMetadata,
QgsNetworkAccessManager,
QgsMessageLog,
QgsGeometry
)
ITEM_TYPE = QgsLayoutItemRegistry.PluginItem + 1338
class PlotLayoutItem(QgsLayoutItem):
def __init__(self, layout):
super().__init__(layout)
# self.setCacheMode(QGraphicsItem.NoCache)
# self.plot_settings = []
# self.plot_settings.append(PlotSettings())
# self.linked_map_uuid = ''
# self.linked_map = None
# self.filter_by_map = False
# self.filter_by_atlas = False
# self.web_page = LoggingWebPage(self)
# self.web_page.setNetworkAccessManager(QgsNetworkAccessManager.instance())
# # This makes the background transparent. (copied from QgsLayoutItemLabel)
# palette = self.web_page.palette()
# palette.setBrush(QPalette.Base, Qt.transparent)
# self.web_page.setPalette(palette)
# self.web_page.mainFrame().setZoomFactor(10.0)
# self.web_page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
# self.web_page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
# self.web_page.loadFinished.connect(self.loading_html_finished)
# self.html_loaded = False
# self.html_units_to_layout_units = self.calculate_html_units_to_layout_units()
# self.sizePositionChanged.connect(self.refresh)
def type(self):
return ITEM_TYPE
class PlotLayoutItemMetadata(QgsLayoutItemAbstractMetadata):
def __init__(self):
super().__init__(ITEM_TYPE, 'test')
def createItem(self, layout):
return PlotLayoutItem(layout)

47
plot_layout/metadata.txt Normal file
View File

@ -0,0 +1,47 @@
# This file contains metadata for your plugin.
# This file should be included when you package your plugin.# Mandatory items:
[general]
name=PlotInLayout
qgisMinimumVersion=3.0
description=test for adding plot in layout
version=0.1
author=Champs-Libres
email=julien.minet@champs-libres.coop
about=test for setting a button in layout
tracker=http://bugs
repository=http://repo
# End of mandatory metadata
# Recommended items:
hasProcessingProvider=no
# Uncomment the following line and add your changelog:
# changelog=
# Tags are comma separated with spaces allowed
tags=python
homepage=http://homepage
category=Plugins
icon=icon.png
# experimental flag
experimental=True
# deprecated flag (applies to the whole plugin, not just a single version)
deprecated=False
# Since QGIS 3.8, a comma separated list of plugins to be installed
# (or upgraded) can be specified.
# Check the documentation for more information.
# plugin_dependencies=
Category of the plugin: Raster, Vector, Database or Web
# category=
# If the plugin can run on QGIS Server.
server=False

80
plot_layout/pb_tool.cfg Normal file
View File

@ -0,0 +1,80 @@
#/***************************************************************************
# PlotInLayout
#
# Configuration file for plugin builder tool (pb_tool)
# Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
# -------------------
# begin : 2021-07-13
# copyright : (C) 2021 by Champs-Libres
# email : julien.minet@champs-libres.coop
# ***************************************************************************/
#
#/***************************************************************************
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# ***************************************************************************/
#
#
# You can install pb_tool using:
# pip install http://geoapt.net/files/pb_tool.zip
#
# Consider doing your development (and install of pb_tool) in a virtualenv.
#
# For details on setting up and using pb_tool, see:
# http://g-sherman.github.io/plugin_build_tool/
#
# Issues and pull requests here:
# https://github.com/g-sherman/plugin_build_tool:
#
# Sane defaults for your plugin generated by the Plugin Builder are
# already set below.
#
# As you add Python source files and UI files to your plugin, add
# them to the appropriate [files] section below.
[plugin]
# Name of the plugin. This is the name of the directory that will
# be created in .qgis2/python/plugins
name: plot_layout
# Full path to where you want your plugin directory copied. If empty,
# the QGIS default path will be used. Don't include the plugin name in
# the path.
plugin_path:
[files]
# Python files that should be deployed with the plugin
python_files: __init__.py plot_layout.py plot_layout_dialog.py
# The main dialog file that is loaded (not compiled)
main_dialog: plot_layout_dialog_base.ui
# Other ui files for dialogs you create (these will be compiled)
compiled_ui_files:
# Resource file(s) that will be compiled
resource_files: resources.qrc
# Other files required for the plugin
extras: metadata.txt icon.png
# Other directories to be deployed with the plugin.
# These must be subdirectories under the plugin directory
extra_dirs:
# ISO code(s) for any locales (translations), separated by spaces.
# Corresponding .ts files must exist in the i18n directory
locales:
[help]
# the built help directory that should be deployed with the plugin
dir: help/build/html
# the name of the directory to target in the deployed plugin
target: help

215
plot_layout/plot_layout.py Normal file
View File

@ -0,0 +1,215 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
PlotInLayout
A QGIS plugin
test for adding plot in layout
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-07-13
git sha : $Format:%H$
copyright : (C) 2021 by Champs-Libres
email : julien.minet@champs-libres.coop
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.core import QgsApplication
from qgis.gui import QgsGui
# Initialize Qt resources from file resources.py
from .resources import *
# Import the code for the dialog
from .plot_layout_dialog import PlotInLayoutDialog
import os.path
# import layout classes
from .layouts.layout import PlotLayoutItemMetadata
from .gui.gui import PlotLayoutItemGuiMetadata
class PlotInLayout:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'PlotInLayout_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&PlotInLayout')
# Check if plugin was started the first time in current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None
self.plot_item_metadata = PlotLayoutItemMetadata()
self.plot_item_gui_metadata = None
QgsApplication.layoutItemRegistry().addLayoutItemType(self.plot_item_metadata)
print('INIT')
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('PlotInLayout', message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str
:param text: Text that should be shown in menu items for this action.
:type text: str
:param callback: Function to be called when the action is triggered.
:type callback: function
:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool