[Qgis-user] Have QGIS prompt for profile to use everytime ?

Charles Dixon-Paver charles at kartoza.com
Wed Oct 21 11:35:24 PDT 2020


I tried to make a quick and dirty cross platform one with zenity that will
work OOTB without worrying about the python environment setup. Didn't work
as planned as the zenity portable app for windows seems a bit glitchy
(there's no way to cancel I could find). Anyway, it should work OOTB on
Gnome, and I share because it might be a handy way for someone to pass
other parameters to a program.

Windows:
--------------------------------------------------
@echo off
@setlocal enableextensions
@cd /d "%~dp0"
@ SETLOCAL EnableDelayedExpansion
@ if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0"
%* && exit

REM Get Zenity Portable and add it to your PATH
REM or keep it in the batchfile dir https://github.com/maravento/winzenity

Set "profilesDir=%APPDATA%\QGIS\QGIS3\profiles"

Set dirs=

for /f "tokens=* usebackq" %%I in (`dir %profilesDir% /A:D /O:N /B`) do (
  Set "dirs=!dirs! %%I"
)

for /f %%X in ('zenity --entry --timeout 10 --ok-label="OK"
--cancel-label="OK ANYWAY" --title "User Profile" --text "Select your
profile." !dirs!') do (
  Set "selectedProfile=%%X"
  ECHO %ERRORLEVEL%
)

REM if %ERRORLEVEL% == 1 exit

if "!selectedProfile!"=="" (
for /f "tokens=* usebackq" %%F in (`findstr /L /C:"defaultProfile"
%profilesDir%\profiles.ini`) do (
  Set defaultProfile=%%F
  for /F "tokens=2 delims==" %%A in ("!defaultProfile!") do (
    Set selectedProfile=%%A
  )
))

%COMSPEC% /C "CALL C:\OSGeo4W64\bin\qgis.bat --profile !selectedProfile!"

EXIT

------------------------------------------------------------


Linux:
------------------------------------------------------------
#!/usr/bin/env bash

qgisBin=$(which qgis)

profilesDir=~/.local/share/QGIS/QGIS3/profiles

dirList=$(ls -d $profilesDir/*/)

dirNames=$(for dir in "${dirList[@]}"; do echo "$(basename --suffix=/ -a
$dir)"; done)

dirs=()

for dir in ${dirNames[@]}
do
  dirs=(${dirs[@]} "$dir")
done

selectedProfile=$(zenity --entry --timeout 10 --title "User Profile" --text
"Select your profile." "${dirs[@]}")

# If cancelled, then exit

[[ "$?" != "0" ]] && exit 1

if [ -z "$selectedProfile" ]
then
  selectedProfile=$(awk -F "=" '/defaultProfile/ {print $2}'
$profilesDir/profiles.ini)
fi

$qgisBin --profile $selectedProfile & disown

exit
------------------------------------------------------------

On Wed, 21 Oct 2020 at 17:18, Raymond Nijssen <r.nijssen at terglobo.nl> wrote:

> This script works for me. But I'm not all sure about the way I start a
> new process for QGIS and quit the python script. I think ending the
> command with an "&" only works on unix kind of systems..
>
> ---
>
> import sys
> import os
> from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout,
> QComboBox, QPushButton
>
> # adjust these to your setup:
> qgis_bin = '/home/raymond/git/QGIS/build-master/output/bin/qgis'
> profile_path = '/home/raymond/.local/share/QGIS/QGIS3/profiles'
>
>
> def run_qgis():
>      profile_name = cb.currentText()
>      cmd = f'{qgis_bin} --profile {profile_name} &'
>      #print(cmd)
>      w.close()
>      os.system(cmd)
>
>
> app = QApplication(sys.argv)
>
> w = QWidget()
> w.setWindowTitle('Choose QGIS profile')
>
> l = QVBoxLayout()
>
> cb = QComboBox()
> for fn in os.scandir(profile_path):
>      if fn.is_dir():
>          cb.addItem(fn.name)
> l.addWidget(cb)
>
> btn = QPushButton('Run QGIS')
> btn.clicked.connect(run_qgis)
> l.addWidget(btn)
>
> w.setLayout(l)
>
> w.show()
>
> sys.exit(app.exec_())
>
> ---
>
> On 21-10-2020 14:00, Raymond Nijssen wrote:
> > Hi Lars,
> >
> > I don't think you can. You can make a startup.py script that runs every
> > time you start QGIS, but it sits in your profile folder. So when QGIS
> > runs it, QGIS must already be aware of the profile that is being used.
> > Also, changing the profile needs a QGIS restart, so it seems QGIS cannot
> > change profile anymore while running.
> >
> > Maybe you can make a small python (pyqt?) script that displays a dialog
> > with profile name picker and does a "qgis --profile NAME" for you?
> >
> > Regards,
> > Raymond
> >
> >
> > On 21-10-2020 13:21, Lars I. Nielsen, LIFA A/S wrote:
> >> Hi list.
> >>
> >> If I have multiple profiles defined, is it possible to have QGIS
> >> prompt me everytime for which profile to use ?
> >>
> >> I know that I can add “--profile NAME” to the command line, but is
> >> looking for a way to avoid having multiple start icons.
> >>
> >> Med venlig hilsen
> >>
> >> Lars I. Nielsen, LIFA A/S
> >> GIS-kons., FME+Python Certified Professional
> >> Geoinformatik
> >>
> >> *T*
> >>
> >>
> >>
> >> 6313 6800
> >>
> >>
> >>
> >> *@*
> >>
> >>
> >>
> >> lin at lifa.dk
> >>
> >> *D*
> >>
> >>
> >>
> >> 6313 6849
> >>
> >>
> >>
> >> *W*
> >>
> >>
> >>
> >> www.lifa.dk <http://www.lifa.dk>
> >>
> >> *M*
> >>
> >>
> >>
> >> *CVR*
> >>
> >>
> >>
> >> 20937289
> >>
> >>
> >> <https://www.linkedin.com/company/lifa-a-s/>
> >> Følg os på LinkedIn og læs de seneste nyheder fra LIFA A/S
> >>
> >>
> >> _______________________________________________
> >> Qgis-user mailing list
> >> Qgis-user at lists.osgeo.org
> >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> >>
> > _______________________________________________
> > Qgis-user mailing list
> > Qgis-user at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20201021/444f4ad8/attachment.html>


More information about the Qgis-user mailing list