flake8 pagerender

This commit is contained in:
Tom LAVEILLE 2025-07-29 14:34:32 +02:00
parent 3564209574
commit e503423e49
5 changed files with 405 additions and 294 deletions

View File

@ -4,14 +4,14 @@ __email__ = "info@3liz.org"
from qgis.core import QgsApplication from qgis.core import QgsApplication
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl from qgis.PyQt.QtCore import QUrl, QSettings
from qgis.PyQt.QtGui import QDesktopServices, QIcon from qgis.PyQt.QtGui import QDesktopServices, QIcon
from qgis.PyQt.QtWidgets import QAction, QMessageBox from qgis.PyQt.QtWidgets import QAction
from qgis.utils import iface from qgis.utils import iface
import qgis import qgis
#include <QSettings> # include <QSettings>
''' '''
from pg_metadata.connection_manager import ( from pg_metadata.connection_manager import (
store_connections, store_connections,
@ -25,15 +25,13 @@ from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
''' '''
import os import os
from .tools.resources import ( from .tools.resources import (
plugin_path, # plugin_path,
resources_path, resources_path,
maj_verif, maj_verif,
) )
from .canvas_editor import PageRender_Editor from .canvas_editor import PageRender_Editor
from .about_form import AboutDialog from .about_form import AboutDialog
from qgis.PyQt.QtCore import *
class PgPageRender: class PgPageRender:
def __init__(self): def __init__(self):
@ -45,18 +43,18 @@ class PgPageRender:
self.dock_action = None self.dock_action = None
self.help_action = None self.help_action = None
plugin_dir = os.path.dirname(__file__) plugin_dir = os.path.dirname(__file__)
end_find = plugin_dir.rfind('\\')+1 end_find = plugin_dir.rfind('\\') + 1
global NAME global NAME
NAME = plugin_dir[end_find:] NAME = plugin_dir[end_find:]
maj_verif(NAME) maj_verif(NAME)
# Display About window on first use # Display About window on first use
version = qgis.utils.pluginMetadata('CenRa_PAGERENDER','version') version = qgis.utils.pluginMetadata('CenRa_PAGERENDER', 'version')
s = QSettings() s = QSettings()
versionUse = s.value("pagerender/version", 1, type=str) versionUse = s.value("pagerender/version", 1, type=str)
if str(versionUse) != str(version) : if str(versionUse) != str(version):
s.setValue("pagerender/version", str(version)) s.setValue("pagerender/version", str(version))
print(versionUse,version) print(versionUse, version)
self.open_about_dialog() self.open_about_dialog()
def initGui(self): def initGui(self):
@ -74,8 +72,7 @@ class PgPageRender:
if not self.canvas_editor: if not self.canvas_editor:
self.canvas_editor = PageRender_Editor() self.canvas_editor = PageRender_Editor()
self.pagerender_action = QAction(icon, 'CenRa_PAGERENDER', None)
self.pagerender_action = QAction(icon, 'CenRa_PAGERENDER',None)
self.toolBar.addAction(self.pagerender_action) self.toolBar.addAction(self.pagerender_action)
self.pagerender_action.triggered.connect(self.open_editor) self.pagerender_action.triggered.connect(self.open_editor)
''' '''
@ -117,6 +114,7 @@ class PgPageRender:
""" """
dialog = AboutDialog(iface) dialog = AboutDialog(iface)
dialog.exec() dialog.exec()
def open_help(): def open_help():
""" Open the online help. """ """ Open the online help. """
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/')) QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
@ -128,7 +126,7 @@ class PgPageRender:
def unload(self): def unload(self):
""" Unload the plugin. """ """ Unload the plugin. """
if self.canvas_editor: if self.canvas_editor:
iface.removePluginMenu('CenRa_PAGERENDER',self.pagerender_action) iface.removePluginMenu('CenRa_PAGERENDER', self.pagerender_action)
if self.provider: if self.provider:
QgsApplication.processingRegistry().removeProvider(self.provider) QgsApplication.processingRegistry().removeProvider(self.provider)

View File

@ -3,7 +3,7 @@ import os.path
from pathlib import Path from pathlib import Path
from qgis.PyQt import uic from qgis.PyQt import uic
from qgis.PyQt.QtGui import QPixmap # from qgis.PyQt.QtGui import QPixmap
from qgis.PyQt.QtWidgets import QDialog from qgis.PyQt.QtWidgets import QDialog
from .tools.resources import devlog from .tools.resources import devlog

View File

@ -1,144 +1,84 @@
import logging import logging
import os import os
from collections import namedtuple # from collections import namedtuple
from enum import Enum # from enum import Enum
from functools import partial # from functools import partial
from pathlib import Path # from pathlib import Path
from xml.dom.minidom import parseString # from xml.dom.minidom import parseString
from qgis.gui import * # from qgis.gui import *
import qgis # import qgis
from qgis.core import ( from qgis.core import QgsSettings
NULL, from qgis.PyQt.QtCore import Qt
QgsApplication, # from qgis.PyQt.QtPrintSupport import QPrinter
QgsScaleBarSettings, # from qgis.PyQt.QtWebKitWidgets import QWebPage
QgsDataSourceUri,
QgsProject,
QgsProviderConnectionException,
QgsProviderRegistry,
QgsRasterLayer,
QgsSettings,
QgsVectorLayer,
QgsGeometry,
QgsPrintLayout,
QgsReadWriteContext,
QgsLayoutItemMap,
QgsLayoutItemPage,
QgsLayoutSize,
QgsUnitTypes,
QgsLayoutPoint,
QgsLayoutItemLabel,
QgsLayoutItemPicture,
QgsLayoutItemLegend,
QgsLegendStyle,
QgsLayoutItemScaleBar,
QgsLayerTreeGroup,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsLayerTree,
QgsLayoutTableColumn,
QgsRectangle,
QgsLayoutItemMapOverviewStack,
QgsLayoutItemHtml,
)
from qgis.PyQt.QtCore import QLocale, QUrl, QDateTime, Qt
from qgis.PyQt.QtGui import QDesktopServices, QIcon, QColor, QFont, QMovie
from qgis.PyQt.QtPrintSupport import QPrinter
#from qgis.PyQt.QtWebKitWidgets import QWebPage
from qgis.PyQt.QtWidgets import ( from qgis.PyQt.QtWidgets import (
QDialog, QDialog,
QAction,
QDockWidget,
QFileDialog, QFileDialog,
QInputDialog,
QMenu,
QToolButton,
QTableWidget,
QTableWidgetItem, QTableWidgetItem,
QVBoxLayout,
) )
from qgis.PyQt import QtGui from qgis.PyQt import QtGui
from qgis.PyQt.QtWidgets import QApplication from qgis.PyQt.QtWidgets import QApplication
from qgis.PyQt.QtCore import QSettings,QPointF from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtXml import QDomDocument # from qgis.PyQt.QtXml import QDomDocument
from qgis.utils import iface # from qgis.utils import iface
import glob # import glob
from .tools.resources import ( from .tools.resources import (
load_ui, load_ui,
resources_path, resources_path,
send_issues, # send_issues,
) )
from .issues import CenRa_Issues # from .issues import CenRa_Issues
from datetime import date # from datetime import date
last_select = None last_select = None
maxV=210 maxV = 210
maxH=296 maxH = 296
EDITOR_CLASS = load_ui('CenRa_PageRender_base.ui') EDITOR_CLASS = load_ui('CenRa_PageRender_base.ui')
LOGGER = logging.getLogger('CenRa_PageRender') LOGGER = logging.getLogger('CenRa_PageRender')
url_osm = 'https://osm.datagrandest.fr/mapcache/?crs=EPSG:2154&featureCount=10&format=image/png&layers=pure&maxHeight=256&maxWidth=256&styles=&url=https://osm.datagrandest.fr/mapcache' url_osm = 'https://osm.datagrandest.fr/mapcache/?crs=EPSG:2154&featureCount=10&format=image/png&layers=pure&maxHeight=256&maxWidth=256&styles=&url=https://osm.datagrandest.fr/mapcache'
url_ortho = 'http://tiles.craig.fr/ortho/service/?crs=EPSG:2154&featureCount=10&format=image/jpeg&layers=ortho&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/ortho/service' url_ortho = 'http://tiles.craig.fr/ortho/service/?crs=EPSG:2154&featureCount=10&format=image/jpeg&layers=ortho&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/ortho/service'
url_mnt = 'http://tiles.craig.fr/mnt/crs=EPSG:2154&featureCount=10&format=image/png&layers=relief&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/mnt' url_mnt = 'http://tiles.craig.fr/mnt/crs=EPSG:2154&featureCount=10&format=image/png&layers=relief&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/mnt'
url_pente = 'http://tiles.craig.fr/mnt/crs=EPSG:2154&featureCount=10&format=image/png&layers=pente&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/mnt' url_pente = 'http://tiles.craig.fr/mnt/crs=EPSG:2154&featureCount=10&format=image/png&layers=pente&maxHeight=256&maxWidth=256&styles=&url=http://tiles.craig.fr/mnt'
data_source = [ data_source = ['CENRA', 'IGN', 'CRAIG', 'OpenStreetMap', 'Sandre', 'BRGM', 'MUSÉUM NATIONAL DHISTOIRE NATURELLE', "Muséum national d'Histoire naturelle", 'ONF', '20xx LPO', 'ofb.gouv.fr', 'Stamen Design', 'MTES', 'MTES', 'FEDER', 'DREAL Auvergne-Rhône-Alpes', 'INSEE', 'DGFiP', 'Fédération des Conservatoires despaces naturels', 'Plan cadastral informatisé - Etalab - juillet 202X', 'Parcellaire Express - IGN - 202X']
'CENRA',
'IGN',
'CRAIG',
'OpenStreetMap',
'Sandre',
'BRGM',
'MUSÉUM NATIONAL DHISTOIRE NATURELLE',
"Muséum national d'Histoire naturelle",
'ONF',
'20xx LPO',
'ofb.gouv.fr',
'Stamen Design',
'MTES',
'MTES',
'FEDER',
'DREAL Auvergne-Rhône-Alpes',
'INSEE',
'DGFiP',
'Fédération des Conservatoires despaces naturels',
'Plan cadastral informatisé - Etalab - juillet 202X',
'Parcellaire Express - IGN - 202X',
]
class PageRender_Editor(QDialog, EDITOR_CLASS):
class PageRender_Editor(QDialog, EDITOR_CLASS):
def __init__(self, parent=None): def __init__(self, parent=None):
_ = parent _ = parent
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
self.settings = QgsSettings() self.settings = QgsSettings()
self.s = QSettings() self.s = QSettings()
self.setWindowIcon(QtGui.QIcon(resources_path('icons','icon.png'))) self.setWindowIcon(QtGui.QIcon(resources_path('icons', 'icon.png')))
self.varLandscape = {} self.varLandscape = {}
self.varPortrait = {} self.varPortrait = {}
self.rotate_object = { self.rotate_object = {
'Titre':0, 'Titre': 0,
'Sous_titre':0, 'Sous_titre': 0,
'Carte':0, 'Carte': 0,
'Carte_2':0, 'Carte_2': 0,
'Legande':0, 'Legande': 0,
'Arrow':0, 'Arrow': 0,
'Echelle':0, 'Echelle': 0,
'Logo':0, 'Logo': 0,
'Credit':0, 'Credit': 0,
'Source':0, 'Source': 0,
'Echelle_2':0, 'Echelle_2': 0,
'Logo_2':0,} 'Logo_2': 0}
path = '' path = ''
ix = 0 ix = 0
plugin_dir = str(os.path.dirname(os.path.abspath(__file__))).split(os.sep) plugin_dir = str(os.path.dirname(os.path.abspath(__file__))).split(os.sep)
for i in plugin_dir: for i in plugin_dir:
ix = ix+1 ix = ix + 1
path = path+'\\'+i path = path + '\\' + i
self.path = path[1:]+'\\demoV2.py' self.path = path[1:] + '\\demoV2.py'
#self.tabWidget.setStyleSheet('background-image: url('+path+'/tools/bg/Capture.png);') # self.tabWidget.setStyleSheet('background-image: url('+path+'/tools/bg/Capture.png);')
self.toolButton.setIcon(QtGui.QIcon(resources_path('ui','rotate.png'))) self.toolButton.setIcon(QtGui.QIcon(resources_path('ui', 'rotate.png')))
self.horizontalSlider.valueChanged.connect(self.horizontal) self.horizontalSlider.valueChanged.connect(self.horizontal)
self.verticalSlider.valueChanged.connect(self.vertical) self.verticalSlider.valueChanged.connect(self.vertical)
@ -151,44 +91,44 @@ class PageRender_Editor(QDialog, EDITOR_CLASS):
self.toolButton_2.clicked.connect(self.type_page) self.toolButton_2.clicked.connect(self.type_page)
self.pushButton_2.clicked.connect(self.load) self.pushButton_2.clicked.connect(self.load)
self.verticalScrollBar.valueChanged.connect(self.moveFrame) self.verticalScrollBar.valueChanged.connect(self.moveFrame)
#self.setAcceptHoverEvents(True) # self.setAcceptHoverEvents(True)
self.tableWidget.setTabKeyNavigation(False) self.tableWidget.setTabKeyNavigation(False)
def raise_(self): def raise_(self):
self.activateWindow() self.activateWindow()
self.setNavigator() self.setNavigator()
self.verticalScrollBar.setValue(self.frame.y()) self.verticalScrollBar.setValue(self.frame.y())
def mousePressEvent(self, event): def mousePressEvent(self, event):
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
QApplication.setOverrideCursor(Qt.CursorShape(18)) QApplication.setOverrideCursor(Qt.CursorShape(18))
global lastPos global lastPos
lastPos = {'x':event.pos().x(),'y':event.pos().y()} lastPos = {'x': event.pos().x(), 'y': event.pos().y()}
def moveFrame(self): def moveFrame(self):
self.frame.move(self.frame.x(),self.verticalScrollBar.value()) self.frame.move(self.frame.x(), self.verticalScrollBar.value())
def keyPressEvent(self, event): def keyPressEvent(self, event):
#if event.modifiers() & Qt.ControlModifier: # if event.modifiers() & Qt.ControlModifier:
if event.key() == Qt.Key(0x01000015): if event.key() == Qt.Key(0x01000015):
self.verticalSlider.setValue(self.spinBox_2.value()+1) self.verticalSlider.setValue(self.spinBox_2.value() + 1)
if event.key() == Qt.Key(0x01000013): if event.key() == Qt.Key(0x01000013):
self.verticalSlider.setValue(self.spinBox_2.value()-1) self.verticalSlider.setValue(self.spinBox_2.value() - 1)
if event.key() == Qt.Key(0x01000014): if event.key() == Qt.Key(0x01000014):
self.horizontalSlider.setValue(self.spinBox.value()+1) self.horizontalSlider.setValue(self.spinBox.value() + 1)
if event.key() == Qt.Key(0x01000012): if event.key() == Qt.Key(0x01000012):
self.horizontalSlider.setValue(self.spinBox.value()-1) self.horizontalSlider.setValue(self.spinBox.value() - 1)
def wheelEvent(self, event):
def wheelEvent(self,event):
if (event.angleDelta().y() >= 1): if (event.angleDelta().y() >= 1):
vsb = self.verticalScrollBar.value()+50 vsb = self.verticalScrollBar.value() + 50
else: else:
vsb = self.verticalScrollBar.value()-50 vsb = self.verticalScrollBar.value() - 50
self.verticalScrollBar.setValue(vsb) self.verticalScrollBar.setValue(vsb)
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
updated_cursor_position = event.pos() updated_cursor_position = event.pos()
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
selection_name = (self.tableWidget.currentItem()).text() selection_name = (self.tableWidget.currentItem()).text()
all_children = self.frame.children() all_children = self.frame.children()
selection = 0 selection = 0
@ -198,96 +138,97 @@ class PageRender_Editor(QDialog, EDITOR_CLASS):
frame_x = self.frame.x() frame_x = self.frame.x()
frame_y = self.frame.y() frame_y = self.frame.y()
frame_w = self.frame.width()+frame_x frame_w = self.frame.width() + frame_x
frame_h = self.frame.height()+frame_y frame_h = self.frame.height() + frame_y
global lastPos global lastPos
orig_position_w = selection.width() orig_position_w = selection.width()
orig_position_h = selection.height() orig_position_h = selection.height()
if (frame_x <= round(updated_cursor_position.x()) <= frame_w and self.radioButton.isChecked() == True): if (frame_x <= round(updated_cursor_position.x()) <= frame_w and self.radioButton.isChecked() is True):
updated_cursor_position_x = orig_position_w+(round(updated_cursor_position.x()-lastPos['x'])) updated_cursor_position_x = orig_position_w + (round(updated_cursor_position.x() - lastPos['x']))
lastPos['x'] = event.pos().x() lastPos['x'] = event.pos().x()
selection.resize(updated_cursor_position_x,orig_position_h) selection.resize(updated_cursor_position_x, orig_position_h)
self.horizontalSlider.setValue(round(updated_cursor_position_x/3.5)) self.horizontalSlider.setValue(round(updated_cursor_position_x / 3.5))
orig_position_w = selection.width() orig_position_w = selection.width()
orig_position_h = selection.height() orig_position_h = selection.height()
if (frame_y <= round(updated_cursor_position.y()) <= frame_h and self.radioButton.isChecked() == True): if (frame_y <= round(updated_cursor_position.y()) <= frame_h and self.radioButton.isChecked() is True):
updated_cursor_position_y = orig_position_h+(round(updated_cursor_position.y()-lastPos['y'])) updated_cursor_position_y = orig_position_h + (round(updated_cursor_position.y() - lastPos['y']))
lastPos['y'] = event.pos().y() lastPos['y'] = event.pos().y()
selection.resize(orig_position_w,updated_cursor_position_y) selection.resize(orig_position_w, updated_cursor_position_y)
self.verticalSlider.setValue(round(updated_cursor_position_y/3.5)) self.verticalSlider.setValue(round(updated_cursor_position_y / 3.5))
orig_position_x = selection.pos().x() orig_position_x = selection.pos().x()
orig_position_y = selection.pos().y() orig_position_y = selection.pos().y()
if (frame_x <= round(updated_cursor_position.x()) <= frame_w and self.radioButton.isChecked() == False): if (frame_x <= round(updated_cursor_position.x()) <= frame_w and self.radioButton.isChecked() is False):
updated_cursor_position_x = orig_position_x+(round(updated_cursor_position.x()-lastPos['x'])) updated_cursor_position_x = orig_position_x + (round(updated_cursor_position.x() - lastPos['x']))
lastPos['x'] = event.pos().x() lastPos['x'] = event.pos().x()
#print(updated_cursor_position_x) # print(updated_cursor_position_x)
selection.move(updated_cursor_position_x,orig_position_y) selection.move(updated_cursor_position_x, orig_position_y)
self.horizontalSlider.setValue(round(updated_cursor_position_x/3.5)) self.horizontalSlider.setValue(round(updated_cursor_position_x / 3.5))
orig_position_x = selection.pos().x() orig_position_x = selection.pos().x()
orig_position_y = selection.pos().y() orig_position_y = selection.pos().y()
if (frame_y <= round(updated_cursor_position.y()) <= frame_h and self.radioButton.isChecked() == False): if (frame_y <= round(updated_cursor_position.y()) <= frame_h and self.radioButton.isChecked() is False):
updated_cursor_position_y = orig_position_y+(round(updated_cursor_position.y()-lastPos['y'])) updated_cursor_position_y = orig_position_y + (round(updated_cursor_position.y() - lastPos['y']))
lastPos['y'] = event.pos().y() lastPos['y'] = event.pos().y()
#print(updated_cursor_position_y) # print(updated_cursor_position_y)
selection.move(orig_position_x,updated_cursor_position_y) selection.move(orig_position_x, updated_cursor_position_y)
self.verticalSlider.setValue(round(updated_cursor_position_y/3.5)) self.verticalSlider.setValue(round(updated_cursor_position_y / 3.5))
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
#print('x: {0}, y: {1}'.format(event.pos().x(), event.pos().y())) # print('x: {0}, y: {1}'.format(event.pos().x(), event.pos().y()))
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
def select_file(self): def select_file(self):
options = QFileDialog.Options() options = QFileDialog.Options()
options |= QFileDialog.ShowDirsOnly options |= QFileDialog.ShowDirsOnly
folder = QFileDialog.getOpenFileName(self, "Sélection du fichier ",'','Python(*.py)') folder = QFileDialog.getOpenFileName(self, "Sélection du fichier ", '', 'Python(*.py)')
if folder[0] != '': if folder[0] != '':
return folder[0] return folder[0]
else: else:
return '' return ''
def load(self): def load(self):
folder = self.select_file() folder = self.select_file()
logopath = folder logopath = folder
if logopath != '': if logopath != '':
#logopath = (os.path.dirname(logopath).split('/')) # logopath = (os.path.dirname(logopath).split('/'))
sourcefile = open(logopath, 'r') sourcefile = open(logopath, 'r')
splitsource = sourcefile.read().splitlines() splitsource = sourcefile.read().splitlines()
all_children = self.frame.children() all_children = self.frame.children()
all_element = ['_locals','_size','_rotate'] all_element = ['_locals', '_size', '_rotate']
for children in all_children: for children in all_children:
flen = 0 flen = 0
for element in all_element: for element in all_element:
flen = 0 flen = 0
recherche_element = children.objectName()+element recherche_element = children.objectName() + element
for find_it in splitsource: for find_it in splitsource:
if find_it.find(recherche_element) != -1: if find_it.find(recherche_element) != -1:
flen = flen+1 flen = flen + 1
if flen == 1: if flen == 1:
if element != '_rotate': if element != '_rotate':
value_find = (find_it[find_it[:].find('(')+1:-33]).split(',') value_find = (find_it[find_it[:].find('(') + 1:-33]).split(',')
if element == '_size': if element == '_size':
Psize_h = float(value_find[0])*3.5 Psize_h = float(value_find[0]) * 3.5
Psize_w = float(value_find[1])*3.5 Psize_w = float(value_find[1]) * 3.5
if element == '_locals': if element == '_locals':
Plocals_h = float(value_find[0])*3.5 Plocals_h = float(value_find[0]) * 3.5
Plocals_w = float(value_find[1])*3.5 Plocals_w = float(value_find[1]) * 3.5
else: else:
Protate = float((find_it[find_it[:].find('=')+2:]).split(',')[0]) Protate = float((find_it[find_it[:].find('=') + 2:]).split(',')[0])
if flen == 3: if flen == 3:
if element != '_rotate': if element != '_rotate':
value_find = (find_it[find_it[:].find('(')+1:-33]).split(',') value_find = (find_it[find_it[:].find('(') + 1:-33]).split(',')
if element == '_size': if element == '_size':
Lsize_h = float(value_find[0])*3.5 Lsize_h = float(value_find[0]) * 3.5
Lsize_w = float(value_find[1])*3.5 Lsize_w = float(value_find[1]) * 3.5
if element == '_locals': if element == '_locals':
Llocals_h = float(value_find[0])*3.5 Llocals_h = float(value_find[0]) * 3.5
Llocals_w = float(value_find[1])*3.5 Llocals_w = float(value_find[1]) * 3.5
else: else:
Lrotate = float((find_it[find_it[:].find('=')+2:]).split(',')[0]) Lrotate = float((find_it[find_it[:].find('=') + 2:]).split(',')[0])
#print('sh',Psize_h,',sw',Psize_w,',lh',Plocals_h,',lw',Plocals_w,',r',Protate) # print('sh',Psize_h,',sw',Psize_w,',lh',Plocals_h,',lw',Plocals_w,',r',Protate)
if Lrotate == 90 or Lrotate == 270: if Lrotate == 90 or Lrotate == 270:
old = Lsize_w old = Lsize_w
Lsize_w = Lsize_h Lsize_w = Lsize_h
@ -297,12 +238,12 @@ class PageRender_Editor(QDialog, EDITOR_CLASS):
Psize_w = Psize_h Psize_w = Psize_h
Psize_h = old Psize_h = old
if self.toolButton_2.text() == 'Landscape': if self.toolButton_2.text() == 'Landscape':
children.resize(round(Lsize_h),round(Lsize_w)) children.resize(round(Lsize_h), round(Lsize_w))
children.move(round(Llocals_h),round(Llocals_w)) children.move(round(Llocals_h), round(Llocals_w))
self.rotate_object[children.objectName()] = Lrotate self.rotate_object[children.objectName()] = Lrotate
if self.toolButton_2.text() == 'Portrait': if self.toolButton_2.text() == 'Portrait':
children.resize(round(Psize_h),round(Psize_w)) children.resize(round(Psize_h), round(Psize_w))
children.move(round(Plocals_h),round(Plocals_w)) children.move(round(Plocals_h), round(Plocals_w))
self.rotate_object[children.objectName()] = Protate self.rotate_object[children.objectName()] = Protate
def valueSlider(self): def valueSlider(self):
@ -311,23 +252,24 @@ class PageRender_Editor(QDialog, EDITOR_CLASS):
def setNavigator(self): def setNavigator(self):
all_children = self.frame.children() all_children = self.frame.children()
xR=0 xR = 0
baseRow = self.tableWidget.rowCount() baseRow = self.tableWidget.rowCount()
while baseRow >= xR: while baseRow >= xR:
self.tableWidget.removeRow(0) self.tableWidget.removeRow(0)
xR = xR+1 xR = xR + 1
self.tableWidget.clear() self.tableWidget.clear()
id=0 # id = 0
for children in all_children: for children in all_children:
position = self.tableWidget.rowCount() position = self.tableWidget.rowCount()
self.tableWidget.insertRow(position) self.tableWidget.insertRow(position)
self.tableWidget.setItem(position,0,QTableWidgetItem(children.objectName())) self.tableWidget.setItem(position, 0, QTableWidgetItem(children.objectName()))
#print(children.objectName()) # print(children.objectName())
def export(self): def export(self):
self.type_page() self.type_page()
self.type_page() self.type_page()
all_children = self.frame.children() all_children = self.frame.children()
#selection_name = (self.tableWidget.currentItem()).text() # selection_name = (self.tableWidget.currentItem()).text()
export_str = """ export_str = """
from qgis.core import ( from qgis.core import (
QgsLayoutSize, QgsLayoutSize,
@ -345,18 +287,18 @@ def fletch_canvas(self):
page_rotate = 'Landscape' page_rotate = 'Landscape'
""" """
type = ["Portrait","Landscape"] type = ["Portrait", "Landscape"]
page = ["A4","A3"] page = ["A4", "A3"]
for page_type in type: for page_type in type:
export_str = export_str+""" export_str = export_str + """
if page_rotate == '"""+page_type+"""':""" if page_rotate == '""" + page_type + """':"""
for page_size in page: for page_size in page:
export_str = export_str+""" export_str = export_str + """
if values_page == '"""+page_size+"""':""" if values_page == '""" + page_size + """':"""
for children in all_children: for children in all_children:
selection = children selection = children
if page_type == 'Portrait': if page_type == 'Portrait':
item_rotate_object=self.varPortrait[selection.objectName()+'_rotate'][0] item_rotate_object = self.varPortrait[selection.objectName() + '_rotate'][0]
if item_rotate_object == 0 or item_rotate_object == 180: if item_rotate_object == 0 or item_rotate_object == 180:
sw = 0 sw = 0
sh = 1 sh = 1
@ -364,17 +306,17 @@ def fletch_canvas(self):
sw = 1 sw = 1
sh = 0 sh = 0
if page_size == 'A3': if page_size == 'A3':
size_w = (round((self.varPortrait[selection.objectName()+'_size'][sw]/3.5)*1.41)) size_w = (round((self.varPortrait[selection.objectName() + '_size'][sw] / 3.5) * 1.41))
size_h = (round((self.varPortrait[selection.objectName()+'_size'][sh]/3.5)*1.41)) size_h = (round((self.varPortrait[selection.objectName() + '_size'][sh] / 3.5) * 1.41))
locals_w = (round((self.varPortrait[selection.objectName()+'_locals'][1]/3.5)*1.41)) locals_w = (round((self.varPortrait[selection.objectName() + '_locals'][1] / 3.5) * 1.41))
locals_h = (round((self.varPortrait[selection.objectName()+'_locals'][0]/3.5)*1.41)) locals_h = (round((self.varPortrait[selection.objectName() + '_locals'][0] / 3.5) * 1.41))
else: else:
size_w = (round(self.varPortrait[selection.objectName()+'_size'][sw])/3.5) size_w = (round(self.varPortrait[selection.objectName() + '_size'][sw]) / 3.5)
size_h = (round(self.varPortrait[selection.objectName()+'_size'][sh]/3.5)) size_h = (round(self.varPortrait[selection.objectName() + '_size'][sh] / 3.5))
locals_w = (round(self.varPortrait[selection.objectName()+'_locals'][1]/3.5)) locals_w = (round(self.varPortrait[selection.objectName() + '_locals'][1] / 3.5))
locals_h = (round(self.varPortrait[selection.objectName()+'_locals'][0]/3.5)) locals_h = (round(self.varPortrait[selection.objectName() + '_locals'][0] / 3.5))
if page_type == 'Landscape': if page_type == 'Landscape':
item_rotate_object=self.varLandscape[selection.objectName()+'_rotate'][0] item_rotate_object = self.varLandscape[selection.objectName() + '_rotate'][0]
if item_rotate_object == 0 or item_rotate_object == 180: if item_rotate_object == 0 or item_rotate_object == 180:
sw = 0 sw = 0
sh = 1 sh = 1
@ -382,42 +324,43 @@ def fletch_canvas(self):
sw = 1 sw = 1
sh = 0 sh = 0
if page_size == 'A3': if page_size == 'A3':
size_w = (round((self.varLandscape[selection.objectName()+'_size'][sw]/3.5)*1.41)) size_w = (round((self.varLandscape[selection.objectName() + '_size'][sw] / 3.5) * 1.41))
size_h = (round((self.varLandscape[selection.objectName()+'_size'][sh]/3.5)*1.41)) size_h = (round((self.varLandscape[selection.objectName() + '_size'][sh] / 3.5) * 1.41))
locals_w = (round((self.varLandscape[selection.objectName()+'_locals'][1]/3.5)*1.41)) locals_w = (round((self.varLandscape[selection.objectName() + '_locals'][1] / 3.5) * 1.41))
locals_h = (round((self.varLandscape[selection.objectName()+'_locals'][0]/3.5)*1.41)) locals_h = (round((self.varLandscape[selection.objectName() + '_locals'][0] / 3.5) * 1.41))
else: else:
size_w = (round(self.varLandscape[selection.objectName()+'_size'][sw])/3.5) size_w = (round(self.varLandscape[selection.objectName() + '_size'][sw]) / 3.5)
size_h = (round(self.varLandscape[selection.objectName()+'_size'][sh]/3.5)) size_h = (round(self.varLandscape[selection.objectName() + '_size'][sh] / 3.5))
locals_w = (round(self.varLandscape[selection.objectName()+'_locals'][1]/3.5)) locals_w = (round(self.varLandscape[selection.objectName() + '_locals'][1] / 3.5))
locals_h = (round(self.varLandscape[selection.objectName()+'_locals'][0]/3.5)) locals_h = (round(self.varLandscape[selection.objectName() + '_locals'][0] / 3.5))
if item_rotate_object == 270: if item_rotate_object == 270:
locals_h= locals_h + size_w locals_h = locals_h + size_w
if item_rotate_object == 180: if item_rotate_object == 180:
locals_h= locals_h + size_h locals_h = locals_h + size_h
locals_w= locals_w + size_w locals_w = locals_w + size_w
size_w = str(size_w) size_w = str(size_w)
size_h = str(size_h) size_h = str(size_h)
locals_w = str(locals_w) locals_w = str(locals_w)
locals_h = str(locals_h) locals_h = str(locals_h)
export_str = export_str+""" export_str = export_str + """
self.template_parameters['"""+selection.objectName()+"""_size'] = QgsLayoutSize("""+size_w+""","""+ size_h+""", QgsUnitTypes.LayoutMillimeters) self.template_parameters['""" + selection.objectName() + """_size'] = QgsLayoutSize(""" + size_w + """,""" + size_h + """, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['"""+selection.objectName()+"""_locals'] = QgsLayoutPoint("""+locals_w+""", """+locals_h+""", QgsUnitTypes.LayoutMillimeters) self.template_parameters['""" + selection.objectName() + """_locals'] = QgsLayoutPoint(""" + locals_w + """, """ + locals_h + """, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['"""+selection.objectName()+"""_rotate'] = """+str(item_rotate_object) self.template_parameters['""" + selection.objectName() + """_rotate'] = """ + str(item_rotate_object)
export_str= export_str+""" export_str = export_str + """
return self.template_parameters""" return self.template_parameters"""
sourceFile = open(self.path,'w') sourceFile = open(self.path, 'w')
print(export_str, file = sourceFile) print(export_str, file=sourceFile)
sourceFile.close() sourceFile.close()
def type_page(self): def type_page(self):
all_children = self.frame.children() all_children = self.frame.children()
if self.toolButton_2.text() == 'Landscape': if self.toolButton_2.text() == 'Landscape':
self.horizontalSlider.setMaximum(maxV) self.horizontalSlider.setMaximum(maxV)
self.verticalSlider.setMaximum(maxH) self.verticalSlider.setMaximum(maxH)
last_children=0 last_children = 0
for children in all_children: for children in all_children:
selection = children selection = children
size_w = selection.size().width() size_w = selection.size().width()
@ -425,20 +368,20 @@ def fletch_canvas(self):
locals_h = selection.x() locals_h = selection.x()
locals_w = selection.y() locals_w = selection.y()
item_rotate_object = self.rotate_object[selection.objectName()] item_rotate_object = self.rotate_object[selection.objectName()]
self.varLandscape[selection.objectName()+'_size'] = [size_w,size_h] self.varLandscape[selection.objectName() + '_size'] = [size_w, size_h]
self.varLandscape[selection.objectName()+'_locals'] = [locals_w,locals_h] self.varLandscape[selection.objectName() + '_locals'] = [locals_w, locals_h]
self.varLandscape[selection.objectName()+'_rotate'] = [item_rotate_object] self.varLandscape[selection.objectName() + '_rotate'] = [item_rotate_object]
if self.varPortrait != {}: if self.varPortrait != {}:
selection.move(self.varPortrait[selection.objectName()+'_locals'][1],self.varPortrait[selection.objectName()+'_locals'][0]) selection.move(self.varPortrait[selection.objectName() + '_locals'][1], self.varPortrait[selection.objectName() + '_locals'][0])
selection.resize(self.varPortrait[selection.objectName()+'_size'][0],self.varPortrait[selection.objectName()+'_size'][1]) selection.resize(self.varPortrait[selection.objectName() + '_size'][0], self.varPortrait[selection.objectName() + '_size'][1])
self.rotate_object[selection.objectName()] = self.varPortrait[selection.objectName()+'_rotate'][0] self.rotate_object[selection.objectName()] = self.varPortrait[selection.objectName() + '_rotate'][0]
self.rotate_color(selection,last_children) self.rotate_color(selection, last_children)
last_children = selection last_children = selection
self.toolButton_2.setText('Portrait') self.toolButton_2.setText('Portrait')
elif self.toolButton_2.text() == 'Portrait': elif self.toolButton_2.text() == 'Portrait':
self.horizontalSlider.setMaximum(maxH) self.horizontalSlider.setMaximum(maxH)
self.verticalSlider.setMaximum(maxV) self.verticalSlider.setMaximum(maxV)
last_children=0 last_children = 0
for children in all_children: for children in all_children:
selection = children selection = children
size_w = selection.size().width() size_w = selection.size().width()
@ -446,24 +389,25 @@ def fletch_canvas(self):
locals_h = selection.x() locals_h = selection.x()
locals_w = selection.y() locals_w = selection.y()
item_rotate_object = self.rotate_object[selection.objectName()] item_rotate_object = self.rotate_object[selection.objectName()]
self.varPortrait[selection.objectName()+'_size'] = [size_w,size_h] self.varPortrait[selection.objectName() + '_size'] = [size_w, size_h]
self.varPortrait[selection.objectName()+'_locals'] = [locals_w,locals_h] self.varPortrait[selection.objectName() + '_locals'] = [locals_w, locals_h]
self.varPortrait[selection.objectName()+'_rotate'] = [item_rotate_object] self.varPortrait[selection.objectName() + '_rotate'] = [item_rotate_object]
if self.varLandscape != {}: if self.varLandscape != {}:
selection.move(self.varLandscape[selection.objectName()+'_locals'][1],self.varLandscape[selection.objectName()+'_locals'][0]) selection.move(self.varLandscape[selection.objectName() + '_locals'][1], self.varLandscape[selection.objectName() + '_locals'][0])
selection.resize(self.varLandscape[selection.objectName()+'_size'][0],self.varLandscape[selection.objectName()+'_size'][1]) selection.resize(self.varLandscape[selection.objectName() + '_size'][0], self.varLandscape[selection.objectName() + '_size'][1])
self.rotate_object[selection.objectName()] = self.varLandscape[selection.objectName()+'_rotate'][0] self.rotate_object[selection.objectName()] = self.varLandscape[selection.objectName() + '_rotate'][0]
self.rotate_color(selection,last_children) self.rotate_color(selection, last_children)
last_children = selection last_children = selection
self.toolButton_2.setText('Landscape') self.toolButton_2.setText('Landscape')
frame_w = self.frame.width() frame_w = self.frame.width()
frame_h = self.frame.height() frame_h = self.frame.height()
self.frame.resize(frame_h,frame_w) self.frame.resize(frame_h, frame_w)
frame_x = round(frame_w / 3) frame_x = round(frame_w / 3)
frame_y = self.frame.y() frame_y = self.frame.y()
self.frame.move(frame_x,frame_y) self.frame.move(frame_x, frame_y)
def setSlider(self): def setSlider(self):
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
print(self.tableWidget.tabKeyNavigation()) print(self.tableWidget.tabKeyNavigation())
selection_name = (self.tableWidget.currentItem()).text() selection_name = (self.tableWidget.currentItem()).text()
all_children = self.frame.children() all_children = self.frame.children()
@ -475,33 +419,33 @@ def fletch_canvas(self):
if selection_name == children.objectName(): if selection_name == children.objectName():
selection = children selection = children
if selection != 0: if selection != 0:
self.rotate_color(selection,last_children) self.rotate_color(selection, last_children)
if self.radioButton.isChecked() == False: if self.radioButton.isChecked() is False:
xx = round(selection.x()/3.5) xx = round(selection.x() / 3.5)
yy = round(selection.y()/3.5) yy = round(selection.y() / 3.5)
else: else:
xx = round(selection.size().width()/3.5) xx = round(selection.size().width() / 3.5)
yy = round(selection.size().height()/3.5) yy = round(selection.size().height() / 3.5)
#print(xx,yy) # print(xx,yy)
self.horizontalSlider.setValue(xx) self.horizontalSlider.setValue(xx)
self.verticalSlider.setValue(yy) self.verticalSlider.setValue(yy)
self.spinBox.setValue(xx) self.spinBox.setValue(xx)
self.spinBox_2.setValue(yy) self.spinBox_2.setValue(yy)
def rotate_color(self,selection,last_children): def rotate_color(self, selection, last_children):
global last_select global last_select
if self.radioButton.isChecked() == False: if self.radioButton.isChecked() is False:
ColorCode = "10, 10, 80, 50" ColorCode = "10, 10, 80, 50"
else: else:
ColorCode = "249, 238, 148, 50" ColorCode = "249, 238, 148, 50"
if self.rotate_object[selection.objectName()] == 0: if self.rotate_object[selection.objectName()] == 0:
selection.setStyleSheet("border: 2px solid;border-color:red;border-bottom-color: blue;background-color: rgb("+ColorCode+")") selection.setStyleSheet("border: 2px solid;border-color:red;border-bottom-color: blue;background-color: rgb(" + ColorCode + ")")
elif self.rotate_object[selection.objectName()] == 90: elif self.rotate_object[selection.objectName()] == 90:
selection.setStyleSheet("border: 2px solid;border-color:red;border-left-color: blue;background-color: rgb("+ColorCode+")") selection.setStyleSheet("border: 2px solid;border-color:red;border-left-color: blue;background-color: rgb(" + ColorCode + ")")
elif self.rotate_object[selection.objectName()] == 180: elif self.rotate_object[selection.objectName()] == 180:
selection.setStyleSheet("border: 2px solid;border-color:red;border-top-color: blue;background-color: rgb("+ColorCode+")") selection.setStyleSheet("border: 2px solid;border-color:red;border-top-color: blue;background-color: rgb(" + ColorCode + ")")
elif self.rotate_object[selection.objectName()] == 270: elif self.rotate_object[selection.objectName()] == 270:
selection.setStyleSheet("border: 2px solid;border-color:red;border-right-color: blue;background-color: rgb("+ColorCode+")") selection.setStyleSheet("border: 2px solid;border-color:red;border-right-color: blue;background-color: rgb(" + ColorCode + ")")
if last_children != 0: if last_children != 0:
if last_select != selection.objectName(): if last_select != selection.objectName():
last_children.setStyleSheet("background-color: rgb(10, 10, 10, 50)") last_children.setStyleSheet("background-color: rgb(10, 10, 10, 50)")
@ -509,7 +453,7 @@ def fletch_canvas(self):
last_select = selection.objectName() last_select = selection.objectName()
def rotate(self): def rotate(self):
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
selection_name = (self.tableWidget.currentItem()).text() selection_name = (self.tableWidget.currentItem()).text()
all_children = self.frame.children() all_children = self.frame.children()
selection = 0 selection = 0
@ -522,21 +466,21 @@ def fletch_canvas(self):
if selection != 0: if selection != 0:
xx = round(selection.size().width()) xx = round(selection.size().width())
yy = round(selection.size().height()) yy = round(selection.size().height())
selection.resize(round(yy),round(xx)) selection.resize(round(yy), round(xx))
if self.radioButton.isChecked() == True: if self.radioButton.isChecked() is True:
self.spinBox.setValue(yy) self.spinBox.setValue(yy)
self.spinBox_2.setValue(xx) self.spinBox_2.setValue(xx)
self.horizontalSlider.setValue(round(yy/3.5)) self.horizontalSlider.setValue(round(yy / 3.5))
self.verticalSlider.setValue(round(xx/3.5)) self.verticalSlider.setValue(round(xx / 3.5))
if self.rotate_object[selection.objectName()] == 270: if self.rotate_object[selection.objectName()] == 270:
self.rotate_object[selection.objectName()] = 0 self.rotate_object[selection.objectName()] = 0
else: else:
self.rotate_object[selection.objectName()] = self.rotate_object[selection.objectName()] + 90 self.rotate_object[selection.objectName()] = self.rotate_object[selection.objectName()] + 90
self.rotate_color(selection,last_children) self.rotate_color(selection, last_children)
def vertical(self): def vertical(self):
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
selection_name = (self.tableWidget.currentItem()).text() selection_name = (self.tableWidget.currentItem()).text()
all_children = self.frame.children() all_children = self.frame.children()
selection = 0 selection = 0
@ -544,15 +488,15 @@ def fletch_canvas(self):
if selection_name == children.objectName(): if selection_name == children.objectName():
selection = children selection = children
if selection != 0: if selection != 0:
if self.radioButton.isChecked() == False: if self.radioButton.isChecked() is False:
selection.move(round(self.horizontalSlider.value()*3.5),round(self.verticalSlider.value()*3.5)) selection.move(round(self.horizontalSlider.value() * 3.5), round(self.verticalSlider.value() * 3.5))
else: else:
selection.resize(round(self.horizontalSlider.value()*3.5),round(self.verticalSlider.value()*3.5)) selection.resize(round(self.horizontalSlider.value() * 3.5), round(self.verticalSlider.value() * 3.5))
self.spinBox.setValue(round(self.horizontalSlider.value())) self.spinBox.setValue(round(self.horizontalSlider.value()))
self.spinBox_2.setValue(round(self.verticalSlider.value())) self.spinBox_2.setValue(round(self.verticalSlider.value()))
def horizontal(self): def horizontal(self):
if self.tableWidget.currentItem() != None: if self.tableWidget.currentItem() is not None:
selection_name = (self.tableWidget.currentItem()).text() selection_name = (self.tableWidget.currentItem()).text()
all_children = self.frame.children() all_children = self.frame.children()
selection = 0 selection = 0
@ -560,10 +504,9 @@ def fletch_canvas(self):
if selection_name == children.objectName(): if selection_name == children.objectName():
selection = children selection = children
if selection != 0: if selection != 0:
if self.radioButton.isChecked() == False: if self.radioButton.isChecked() is False:
selection.move(round(self.horizontalSlider.value()*3.5),round(self.verticalSlider.value()*3.5)) selection.move(round(self.horizontalSlider.value() * 3.5), round(self.verticalSlider.value() * 3.5))
else: else:
selection.resize(round(self.horizontalSlider.value()*3.5),round(self.verticalSlider.value()*3.5)) selection.resize(round(self.horizontalSlider.value() * 3.5), round(self.verticalSlider.value() * 3.5))
self.spinBox.setValue(round(self.horizontalSlider.value())) self.spinBox.setValue(round(self.horizontalSlider.value()))
self.spinBox_2.setValue(round(self.verticalSlider.value())) self.spinBox_2.setValue(round(self.verticalSlider.value()))

167
CenRa_PAGERENDER/demoV2.py Normal file
View File

@ -0,0 +1,167 @@
from qgis.core import (
QgsLayoutSize,
QgsUnitTypes,
QgsLayoutPoint,
)
def fletch_canvas(self):
if self.radioButton_6.isChecked():
values_page = 'A4'
else:
values_page = 'A3'
if self.radioButton_7.isChecked():
page_rotate = 'Portrait'
else:
page_rotate = 'Landscape'
if page_rotate == 'Portrait':
if values_page == 'A4':
self.template_parameters['Carte_size'] = QgsLayoutSize(200.0,200, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_locals'] = QgsLayoutPoint(6, 6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_rotate'] = 0
self.template_parameters['Carte_2_size'] = QgsLayoutSize(85.71428571428571,69, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_locals'] = QgsLayoutPoint(209, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_rotate'] = 0
self.template_parameters['Legande_size'] = QgsLayoutSize(140.0,147, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_locals'] = QgsLayoutPoint(41, 110, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_rotate'] = 0
self.template_parameters['Arrow_size'] = QgsLayoutSize(14.285714285714286,14, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_locals'] = QgsLayoutPoint(189, 20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_rotate'] = 0
self.template_parameters['Echelle_size'] = QgsLayoutSize(51.42857142857143,7, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_locals'] = QgsLayoutPoint(9, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_rotate'] = 0
self.template_parameters['Logo_size'] = QgsLayoutSize(45.714285714285715,11, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_locals'] = QgsLayoutPoint(3, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_rotate'] = 0
self.template_parameters['Titre_size'] = QgsLayoutSize(154.28571428571428,11, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_locals'] = QgsLayoutPoint(51, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_rotate'] = 0
self.template_parameters['Credit_size'] = QgsLayoutSize(51.42857142857143,6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_locals'] = QgsLayoutPoint(151, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_rotate'] = 0
self.template_parameters['Source_size'] = QgsLayoutSize(51.42857142857143,6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_locals'] = QgsLayoutPoint(229, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_rotate'] = 0
self.template_parameters['Sous_titre_size'] = QgsLayoutSize(125.71428571428571,14, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_locals'] = QgsLayoutPoint(60, 20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_rotate'] = 0
self.template_parameters['Echelle_2_size'] = QgsLayoutSize(51.42857142857143,13, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_locals'] = QgsLayoutPoint(9, 184, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_rotate'] = 0
self.template_parameters['Logo_2_size'] = QgsLayoutSize(28.571428571428573,29, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_locals'] = QgsLayoutPoint(9, 151, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_rotate'] = 0
if values_page == 'A3':
self.template_parameters['Carte_size'] = QgsLayoutSize(282,282, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_locals'] = QgsLayoutPoint(8, 8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_rotate'] = 0
self.template_parameters['Carte_2_size'] = QgsLayoutSize(121,97, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_locals'] = QgsLayoutPoint(294, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_rotate'] = 0
self.template_parameters['Legande_size'] = QgsLayoutSize(197,207, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_locals'] = QgsLayoutPoint(58, 156, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_rotate'] = 0
self.template_parameters['Arrow_size'] = QgsLayoutSize(20,20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_locals'] = QgsLayoutPoint(266, 28, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_rotate'] = 0
self.template_parameters['Echelle_size'] = QgsLayoutSize(73,10, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_locals'] = QgsLayoutPoint(12, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_rotate'] = 0
self.template_parameters['Logo_size'] = QgsLayoutSize(64,16, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_locals'] = QgsLayoutPoint(4, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_rotate'] = 0
self.template_parameters['Titre_size'] = QgsLayoutSize(218,16, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_locals'] = QgsLayoutPoint(73, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_rotate'] = 0
self.template_parameters['Credit_size'] = QgsLayoutSize(73,8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_locals'] = QgsLayoutPoint(214, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_rotate'] = 0
self.template_parameters['Source_size'] = QgsLayoutSize(73,8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_locals'] = QgsLayoutPoint(322, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_rotate'] = 0
self.template_parameters['Sous_titre_size'] = QgsLayoutSize(177,20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_locals'] = QgsLayoutPoint(85, 28, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_rotate'] = 0
self.template_parameters['Echelle_2_size'] = QgsLayoutSize(73,18, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_locals'] = QgsLayoutPoint(12, 260, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_rotate'] = 0
self.template_parameters['Logo_2_size'] = QgsLayoutSize(40,40, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_locals'] = QgsLayoutPoint(12, 214, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_rotate'] = 0
if page_rotate == 'Landscape':
if values_page == 'A4':
self.template_parameters['Carte_size'] = QgsLayoutSize(200.0,200, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_locals'] = QgsLayoutPoint(6, 6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_rotate'] = 0
self.template_parameters['Carte_2_size'] = QgsLayoutSize(85.71428571428571,69, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_locals'] = QgsLayoutPoint(209, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_rotate'] = 0
self.template_parameters['Legande_size'] = QgsLayoutSize(140.0,147, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_locals'] = QgsLayoutPoint(49, 15, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_rotate'] = 0
self.template_parameters['Arrow_size'] = QgsLayoutSize(14.285714285714286,14, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_locals'] = QgsLayoutPoint(189, 20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_rotate'] = 0
self.template_parameters['Echelle_size'] = QgsLayoutSize(51.42857142857143,7, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_locals'] = QgsLayoutPoint(9, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_rotate'] = 0
self.template_parameters['Logo_size'] = QgsLayoutSize(45.714285714285715,11, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_locals'] = QgsLayoutPoint(3, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_rotate'] = 0
self.template_parameters['Titre_size'] = QgsLayoutSize(154.28571428571428,11, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_locals'] = QgsLayoutPoint(51, 3, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_rotate'] = 0
self.template_parameters['Credit_size'] = QgsLayoutSize(51.42857142857143,6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_locals'] = QgsLayoutPoint(151, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_rotate'] = 0
self.template_parameters['Source_size'] = QgsLayoutSize(51.42857142857143,6, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_locals'] = QgsLayoutPoint(229, 197, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_rotate'] = 0
self.template_parameters['Sous_titre_size'] = QgsLayoutSize(125.71428571428571,14, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_locals'] = QgsLayoutPoint(60, 20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_rotate'] = 0
self.template_parameters['Echelle_2_size'] = QgsLayoutSize(51.42857142857143,13, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_locals'] = QgsLayoutPoint(9, 184, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_rotate'] = 0
self.template_parameters['Logo_2_size'] = QgsLayoutSize(28.571428571428573,29, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_locals'] = QgsLayoutPoint(9, 151, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_rotate'] = 0
if values_page == 'A3':
self.template_parameters['Carte_size'] = QgsLayoutSize(282,282, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_locals'] = QgsLayoutPoint(8, 8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_rotate'] = 0
self.template_parameters['Carte_2_size'] = QgsLayoutSize(121,97, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_locals'] = QgsLayoutPoint(294, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Carte_2_rotate'] = 0
self.template_parameters['Legande_size'] = QgsLayoutSize(197,207, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_locals'] = QgsLayoutPoint(69, 21, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Legande_rotate'] = 0
self.template_parameters['Arrow_size'] = QgsLayoutSize(20,20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_locals'] = QgsLayoutPoint(266, 28, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Arrow_rotate'] = 0
self.template_parameters['Echelle_size'] = QgsLayoutSize(73,10, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_locals'] = QgsLayoutPoint(12, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_rotate'] = 0
self.template_parameters['Logo_size'] = QgsLayoutSize(64,16, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_locals'] = QgsLayoutPoint(4, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_rotate'] = 0
self.template_parameters['Titre_size'] = QgsLayoutSize(218,16, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_locals'] = QgsLayoutPoint(73, 4, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Titre_rotate'] = 0
self.template_parameters['Credit_size'] = QgsLayoutSize(73,8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_locals'] = QgsLayoutPoint(214, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Credit_rotate'] = 0
self.template_parameters['Source_size'] = QgsLayoutSize(73,8, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_locals'] = QgsLayoutPoint(322, 278, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Source_rotate'] = 0
self.template_parameters['Sous_titre_size'] = QgsLayoutSize(177,20, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_locals'] = QgsLayoutPoint(85, 28, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Sous_titre_rotate'] = 0
self.template_parameters['Echelle_2_size'] = QgsLayoutSize(73,18, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_locals'] = QgsLayoutPoint(12, 260, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Echelle_2_rotate'] = 0
self.template_parameters['Logo_2_size'] = QgsLayoutSize(40,40, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_locals'] = QgsLayoutPoint(12, 214, QgsUnitTypes.LayoutMillimeters)
self.template_parameters['Logo_2_rotate'] = 0
return self.template_parameters

View File

@ -3,9 +3,9 @@
import configparser import configparser
import shutil import shutil
import tempfile import tempfile
import base64 # import base64
import psycopg2 # import psycopg2
import psycopg2.extras # import psycopg2.extras
from os.path import abspath, join, pardir, dirname from os.path import abspath, join, pardir, dirname
from qgis.PyQt.QtWidgets import QApplication from qgis.PyQt.QtWidgets import QApplication
from qgis.PyQt import uic from qgis.PyQt import uic
@ -107,65 +107,68 @@ def load_ui(*args):
return ui_class return ui_class
def send_issues(url,titre,body,labels):
def send_issues(url, titre, body, labels):
import requests import requests
import urllib.request
import json import json
import os # import os
import qgis
usr = os.environ['USERNAME'] # usr = os.environ['USERNAME']
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112' token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
url=url+'?token='+token url = url + '?token=' + token
headers = {'Authorization': 'token ' + token,'accept': 'application/json','Content-Type': 'application/json'}
headers = {'Authorization': 'token ' + token, 'accept': 'application/json', 'Content-Type': 'application/json'}
payload = {'title': titre, 'body': body, 'labels': labels} payload = {'title': titre, 'body': body, 'labels': labels}
try: try:
urllib.request.urlopen('https://google.com') urllib.request.urlopen('https://google.com')
binar = True binar = True
except: except urllib.requests.URLError:
binar = False binar = False
r = '' r = ''
if binar: if binar:
r = requests.post(url, data=json.dumps(payload), headers=headers) r = requests.post(url, data=json.dumps(payload), headers=headers)
return r return r
def maj_verif(NAME): def maj_verif(NAME):
import qgis import qgis
import urllib.request import urllib.request
iface = qgis.utils.iface iface = qgis.utils.iface
from qgis.core import Qgis from qgis.core import Qgis
url = qgis.utils.pluginMetadata(NAME,'repository') # url = qgis.utils.pluginMetadata(NAME, 'repository')
#URL = url+'/raw/branch/main/plugins.xml' # URL = url+'/raw/branch/main/plugins.xml'
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml' URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml'
# print(URL) # print(URL)
version = qgis.utils.pluginMetadata(NAME,'version') version = qgis.utils.pluginMetadata(NAME, 'version')
len_version = len(version) len_version = len(version)
try: try:
urllib.request.urlopen('https://google.com') urllib.request.urlopen('https://google.com')
binar = True binar = True
except: except urllib.requests.URLError:
binar = False binar = False
if binar: if binar:
try: try:
version_web = str(urllib.request.urlopen(URL).read()) version_web = str(urllib.request.urlopen(URL).read())
plugin_num = version_web.find(NAME) plugin_num = version_web.find(NAME)
valeur_version_web = version_web.find('<version>',plugin_num)+9 valeur_version_web = version_web.find('<version>', plugin_num) + 9
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version] version_plugin = version_web[valeur_version_web:valeur_version_web + len_version]
if version_plugin != version: if version_plugin != version:
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30) iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
except: except urllib.requests.URLError:
print("error gitea version ssl") print("error gitea version ssl")
else: else:
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30) iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
def tr(text, context="@default"): def tr(text, context="@default"):
return QApplication.translate(context, text) return QApplication.translate(context, text)
def devlog(NAME): def devlog(NAME):
import qgis import qgis
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>' devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
devmaj = devmaj+qgis.utils.pluginMetadata(NAME,'changelog') devmaj = devmaj + qgis.utils.pluginMetadata(NAME, 'changelog')
return devmaj return devmaj