From b383ccd0d4bf1269539b0187bccb3bfaea93ce99 Mon Sep 17 00:00:00 2001 From: DamnBack Date: Thu, 18 May 2017 12:06:19 +0200 Subject: [PATCH] Added feature from request #234. --- QGIS Plugin/Makefile | 2 +- QGIS Plugin/defaults.txt | 2 ++ QGIS Plugin/install.bat | 4 ++-- QGIS Plugin/metadata.txt | 7 +++++-- QGIS Plugin/settingsdialog.py | 35 ++++++++++++++++++++--------------- 5 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 QGIS Plugin/defaults.txt diff --git a/QGIS Plugin/Makefile b/QGIS Plugin/Makefile index d817d13..a40ff5e 100644 --- a/QGIS Plugin/Makefile +++ b/QGIS Plugin/Makefile @@ -35,7 +35,7 @@ PLUGINNAME = projectselector PY_FILES = projectselector.py projectselectordialog.py __init__.py -EXTRAS = icon.png metadata.txt +EXTRAS = icon.png metadata.txt defaults.txt UI_FILES = ui_projectselector.py diff --git a/QGIS Plugin/defaults.txt b/QGIS Plugin/defaults.txt new file mode 100644 index 0000000..0b9ae7b --- /dev/null +++ b/QGIS Plugin/defaults.txt @@ -0,0 +1,2 @@ +projects: +templates: diff --git a/QGIS Plugin/install.bat b/QGIS Plugin/install.bat index ace7bf9..35c6765 100644 --- a/QGIS Plugin/install.bat +++ b/QGIS Plugin/install.bat @@ -8,7 +8,7 @@ PAUSE SET NAME=moor-tools rem Install for current user -SET DEST=%HOMEPATH%\.qgis2\python\plugins\%NAME% +SET DEST=%USERPROFILE%\.qgis2\python\plugins\%NAME% rem Install for all users (required script to be run as Administrator) rem SET DEST=C:\Program Files (x86)\Quantum GIS Lisboa\apps\qgis\python\plugins\%NAME% @@ -19,8 +19,8 @@ mkdir %DEST%\Templates\Logos xcopy /y *.py %DEST% xcopy /y *.png %DEST% xcopy /y metadata.txt %DEST% +xcopy /y defaults.txt %DEST% xcopy /y *.ui %DEST% xcopy /y examples\*.* %DEST%\examples xcopy /y Templates\*.* %DEST%\Templates xcopy /y Templates\Logos\*.* %DEST%\Templates\Logos - diff --git a/QGIS Plugin/metadata.txt b/QGIS Plugin/metadata.txt index 28d96bb..c1a27c1 100644 --- a/QGIS Plugin/metadata.txt +++ b/QGIS Plugin/metadata.txt @@ -13,7 +13,7 @@ name=Project Selector qgisMinimumVersion=2.0 qgisMaximumVersion=2.99 description=Tool for selecting pre-defined QGIS projects. -version=1.1.2 +version=1.1.3 author=Dartmoor National Park Authority email=gi@dartmoor.gov.uk about=Tools for simplifying and automating common tasks for national parks and other protected areas. Catchy name courtesy of Dartmoor National Park, UK. @@ -24,7 +24,10 @@ about=Tools for simplifying and automating common tasks for national parks and o # Uncomment the following line and add your changelog entries: -changelog=1.1.2 - Bug fixes and new features: +changelog=1.1.3 - New features: + - added defaults.txt with predefined paths to projects and templates +

1.1.2 - Bug fixes: + - Fixed plugin crashing when choosing current map canvas scale - Added Autofit button to adjust map scales to paper format - Fixed mixed up combo boxes with scales - Fixed example templates diff --git a/QGIS Plugin/settingsdialog.py b/QGIS Plugin/settingsdialog.py index a3687e2..ab38c61 100644 --- a/QGIS Plugin/settingsdialog.py +++ b/QGIS Plugin/settingsdialog.py @@ -26,10 +26,12 @@ import os +PARENT_DIR = os.path.dirname(os.path.abspath(__file__)) +DEFAULTS = os.path.join(PARENT_DIR, 'defaults.txt') + class SettingsDialog(QtGui.QDialog): - - + def __init__(self): QtGui.QDialog.__init__(self) @@ -40,27 +42,30 @@ def __init__(self): self.settings = QtCore.QSettings() # Populate the values - v = self.settings.value('MoorTools/ProjectSelector/projectRoot', '', type=str) - self.ui.projectsFolderLineEdit.setText(v) - v = self.settings.value('MoorTools/TemplateSelector/templateRoot', '', type=str) - self.ui.templateRootLineEdit.setText(v) - + with open(DEFAULTS) as paths: + projects = paths.readline().strip().split(':', 1)[-1] + templates = paths.readline().strip().split(':', 1)[-1] + self.ui.projectsFolderLineEdit.setText(projects) + self.ui.templateRootLineEdit.setText(templates) def browseForProjectRoot(self): startingDir = str(self.settings.value("MoorTools/ProjectSelector/projectRoot", os.path.expanduser("~"), type=str)) - d = str( QtGui.QFileDialog.getExistingDirectory(None, 'Select Projects Folder', startingDir) ) - if d <> os.sep and d.lower() <> 'c:\\' and d <> '': + d = str(QtGui.QFileDialog.getExistingDirectory(None, 'Select Projects Folder', startingDir)) + if d != os.sep and d.lower() != 'c:\\' and d != '': self.ui.projectsFolderLineEdit.setText(d) def browseForTemplateRoot(self): startingDir = str(self.settings.value("MoorTools/TemplateSelector/templateRoot", os.path.expanduser("~"), type=str)) - d = str( QtGui.QFileDialog.getExistingDirectory(None, 'Select Root of Template Folder Structure', startingDir) ) - if d <> os.sep and d.lower() <> 'c:\\' and d <> '': + d = str(QtGui.QFileDialog.getExistingDirectory(None, 'Select Root of Template Folder Structure', startingDir)) + if d != os.sep and d.lower() != 'c:\\' and d != '': self.ui.templateRootLineEdit.setText(d) def accept(self): - d = self.ui.projectsFolderLineEdit.text() - self.settings.setValue("MoorTools/ProjectSelector/projectRoot", d) - d = self.ui.templateRootLineEdit.text() - self.settings.setValue("MoorTools/TemplateSelector/templateRoot", d) + projects = self.ui.projectsFolderLineEdit.text() + self.settings.setValue("MoorTools/ProjectSelector/projectRoot", projects) + templates = self.ui.templateRootLineEdit.text() + self.settings.setValue("MoorTools/TemplateSelector/templateRoot", templates) + with open(DEFAULTS, 'w') as paths: + paths.write('projects:{}\n'.format(projects)) + paths.write('templates:{}\n'.format(templates)) QtGui.QDialog.accept(self)