Re: [QGIS-Developer] Deactivate QgsRasterLayer CRS prompt

2018-03-21 Thread KOHLMANN Hannes
Hey Nyall!

Unfortunately, it doesn't... would that really be the only way to do this?
Or what could someone do wrong for these three lines of code to fail their 
purpose?

Hannes

-Ursprüngliche Nachricht-
Von: Nyall Dawson [mailto:nyall.daw...@gmail.com] 
Gesendet: Dienstag, 20. März 2018 22:53
An: KOHLMANN Hannes
Cc: qgis-developer@lists.osgeo.org
Betreff: Re: [QGIS-Developer] Deactivate QgsRasterLayer CRS prompt

On 21 March 2018 at 04:30, KOHLMANN Hannes <h.kohlm...@ove.at> wrote:
> Hello again!
>
>
>
> I do the following to add a QgsRasterLayer:
>
> l = QgsRasterLayer("/path/file.dat", "Density")
>
>
>
> Now I am struggling with a problem, that has somehow always the same 
> suggested solution in all fora, namely to get rid of the prompt that 
> appears
>
> when adding a QgsRasterLayer, by using:
>
> s = QSettings()
>
> oldValidation = s.value( "/Projections/defaultBehaviour" )
>
> s.setValue( "/Projections/defaultBehaviour", "useGlobal" ) # it 
> doesn’t matter what property to take, be it “useProject”, “useGlobal” 
> or “prompt” …
>
> … before adding the layer. But on my Linux environment, this does not 
> work – and also not on my collegue’s Windows system.
>
> Has there something changed with the usage of QSettings w.r.t. to its 
> usage in QGIS in the step from QGIS 2 to QGIS 3?
>

That should still work.

Try using QgsSettings instead (but I don't think this should be necessary):

s = QgsSettings()


Nyall
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] Deactivate QgsRasterLayer CRS prompt

2018-03-20 Thread KOHLMANN Hannes
Hello again!

I do the following to add a QgsRasterLayer:
l = QgsRasterLayer("/path/file.dat", "Density")

Now I am struggling with a problem, that has somehow always the same suggested 
solution in all fora, namely to get rid of the prompt that appears
when adding a QgsRasterLayer, by using:
s = QSettings()
oldValidation = s.value( "/Projections/defaultBehaviour" )
s.setValue( "/Projections/defaultBehaviour", "useGlobal" ) # it doesn't matter 
what property to take, be it "useProject", "useGlobal" or "prompt" ...
... before adding the layer. But on my Linux environment, this does not work - 
and also not on my collegue's Windows system.
Has there something changed with the usage of QSettings w.r.t. to its usage in 
QGIS in the step from QGIS 2 to QGIS 3?

(Re)setting the layer CRS of course works normally and works as expected!

l.setCrs(QgsCoordinateReferenceSystem(31287))
QgsProject.instance().addMapLayer(l)

Do you have any suggestions, how I could tackle the problem?

Thank you very much in advance!

Best regards,
Hannes
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] Set text of QgsLayoutItemLabel

2018-03-16 Thread KOHLMANN Hannes
Hello!

I am facing difficulties trying to set the text of a  QgsLayoutItemLabel.
I do something like the following to load a .qpt composer template and print 
this to a .png file (which works)

path = "C:\\QGIS3\\apps\\qgis\\composer_templates"
template_file = open(path+"\\ANSR_print_composer2.qpt")
template_content = template_file.read()
template_file.close()

document = QDomDocument()
document.setContent(template_content)
composition = QgsLayout(QgsProject.instance())
composition.loadFromTemplate(document, QgsReadWriteContext())

map_item = composition.itemById('map')
legend_item = composition.itemById('legend')
text_item = composition.itemById('textbox')
QgsLayoutExporter(composition).exportToImage( path+"\\report.png", 
QgsLayoutExporter.ImageExportSettings())

And now I'd like to modify only the text of the QgsLayoutItemLabel, which is 
the "textbox":


1)  I can move it around with setX(), setY(), but I don't know how to edit 
the text of the label. I thought of something like text_item.setText() or 
text_item.setLabelText(), but I think that text_item is just an instance of 
QgsLayoutItem, not QgsLayoutItemLabel. And there I get stuck.

2)  How would you manually add another text label, set the main property 
etc, such that, at the end of the day, my above code would export a .png 
containing this QgsLayoutItem?
I would have begun this way:
new = QgsLayoutItemLabel(composition)
new.setText("New label")
But it does not quite work that way!

Would be of great help, if you could give me some hints on that.

Thank you in advance! :)

Hannes
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Unable to compile QGIS3 plugin

2018-03-16 Thread KOHLMANN Hannes
Hey Sophie!

Exactly. You first call …/pyrcc.bat without any arguments, and the console 
tells you what arguments pyrcc.bat takes.
Then you change directory, away from the pyrcc.bat and try to call after having 
changed to the directory where your resource file is.

Remain in the folder where the pyrcc5.bat is (otherwise the console will not 
know the command) and give the absolute paths of your target files in quotation 
mark (in case you have whitespaces in your dirs.) like I did in the below 
screenshot.

You might encounter the same problem with the pyuic5.bat -> which you use, when 
you want to translate the .ui file to python code with the pyqt5 bindings. In 
that case, I built myself a .bat file with the following commands, making the 
same as Jürgen suggested, (just in case of further tampering attempts ;) )

REM take all .ui files and apply it to the pyuic5.bat to all of them and output 
them as .py files
REM when calling this batch file the first argument needs to be the path to 
/python36/script
pushd %~dp0
echo off
call c:
cd %1
cd ../../../bin/
call "o4w_env.bat"
call qt5_env.bat
call py3_env.bat

path %OSGEO4W_ROOT%\apps\qgis-dev\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis-dev
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=100
set 
QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis-dev\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis-dev\python;%PYTHONPATH%

echo off

popd
for %%i in (*.ui) do (
call "%1\pyuic5.bat" -o "%%~ni.py" "%%~ni.ui"
)

I hope that helped

Cheers,
Hannes


[cid:image006.png@01D3BD18.F7381970]

Von: Sophie Crommelinck [mailto:sophie.crommeli...@gmail.com]
Gesendet: Freitag, 16. März 2018 10:53
An: KOHLMANN Hannes; j...@norbit.de
Cc: qgis-developer@lists.osgeo.org
Betreff: Re: [QGIS-Developer] Unable to compile QGIS3 plugin

I think my images broke while sending,
here they are again:

Jürgen's suggestion:
[cid:image002.jpg@01D3BD19.8B6D6230]
Hannes' suggestion:
[cid:image004.jpg@01D3BD19.8B6D6230]
python-core.bat
[cid:image005.png@01D3BD16.85DD2830]


2018-03-16 10:45 GMT+01:00 Sophie Crommelinck 
<sophie.crommeli...@gmail.com<mailto:sophie.crommeli...@gmail.com>>:
Hello Jürgen and Hannes,
thanks for your support. I tried both suggestions, with little success.
Jürgen's suggestion:
[http://?ui=2=ad514a8e24=att=1622e15a2bbbae15=0.1=safe=ii_jetq74350_1622e15a2bbbae15]
This creates the resources.py file (attached). However, when I open QGIS3 it 
crashes every time I reload the plugin (crash report attached).
Hannes' suggestion:
[http://?ui=2=ad514a8e24=att=1622e24472fdda7d=0.2=safe=ii_jetqrnzt1_1622e24472fdda7d]
which results in the same as above. However, here I am not entirely sure if I 
followed the suggestion correctly as I go back to the plugin folder for 
compiling.
Also, I wonder, why the result of calling python-qgis-dev.bat lists win32, 
while I have a win64 machine.

I also tried changing the python path as suggested in the stack exchange 
question to Python36 in C:\OSGeo4W64\etc\ini\python-core without success
[http://?ui=2=ad514a8e24=att=1622e29d99d79ebd=0.0.3=safe=ii_jetqzhre4_1622e29d99d79ebd]
Best,
Sophie




2018-03-16 1:11 GMT+01:00 KOHLMANN Hannes 
<h.kohlm...@ove.at<mailto:h.kohlm...@ove.at>>:
Hey Sophie!

There is one .bat file that does all the work of setting the Environment 
variables properly: /osgeo4w_root/bin/python-qgis-dev.bat
Call that file in the console and in the same console cd to the directory with 
the pyrcc.bat file (osgeo4w_root/apps/python36/scripts)

Here is the link to a gis.stackexchange question concerning that:
https://gis.stackexchange.com/questions/260743/how-to-compile-qtdesigner-user-interface-ui-and-resource-qrc-files-with-qg/264377#264377

Good luck and compiling ;)

Cheers,
Hannes
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org<mailto:QGIS-Developer@lists.osgeo.org>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Unable to compile QGIS3 plugin

2018-03-15 Thread KOHLMANN Hannes
Hey Sophie!

There is one .bat file that does all the work of setting the Environment 
variables properly: /osgeo4w_root/bin/python-qgis-dev.bat
Call that file in the console and in the same console cd to the directory with 
the pyrcc.bat file (osgeo4w_root/apps/python36/scripts)

Here is the link to a gis.stackexchange question concerning that:
https://gis.stackexchange.com/questions/260743/how-to-compile-qtdesigner-user-interface-ui-and-resource-qrc-files-with-qg/264377#264377

Good luck and compiling ;)

Cheers,
Hannes
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] QgsComposition in QGIS3

2018-03-15 Thread KOHLMANN Hannes
Hello everyone!

I have a short question concerning print composition, as I want to do that via 
PyQgis in QGIS3:
I stumbled across the QgsComposition class 
(http://kartoza.com/en/blog/how-to-create-a-qgis-pdf-report-with-a-few-lines-of-python)
I cannot find this class in the Qgis3 API. Usuallly, the Python console in QGIS 
will suggest me available classes as soon as I type the initials, but all Qgis 
shows me are some QgsCompound... classes
Since nothing is mentioned in the backwards incompatible changes 
(https://qgis.org/api/api_break.html) I wanted to ask here, maybe I have just 
overseen something or am searching for a wrong class (?)


QGIS-Version


3.0.0-Girona


QGIS-Codeversion


001c80b0c3


Kompiliert gegen Qt


5.9.2


Laufendes Qt


5.9.2


Kompiliert mit GDAL/OGR


2.2.3


Läuft mit GDAL/OGR


2.2.3


Kompiliert mit GEOS


3.5.0-CAPI-1.9.0


Läuft mit GEOS


3.5.0-CAPI-1.9.0 r4084


PostgreSQL-Client-Version


9.2.4


SpatiaLite-Version


4.3.0


QWT-Version


6.1.3


QScintilla2-Version


2.10.1


PROJ.4-Version


493


Thanks for help! :)

Best regards,
Hannes K.
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] Python27 still main version in Osgeo4W Shell? (QGIS 2.99)

2017-12-01 Thread KOHLMANN Hannes
Hi folks!

I have a question regarding the Python version in QGIS 3.
I installed the latest nightly build of Qgis 2.99 on Windows 64bit and wanted 
to start porting self-written QGIS 2 plugins to be QGIS 3 compatible!

My approach would have been to redo the conversion steps with pyuic5 and pyrcc5 
(for PyQt5) and then correcting for removed classes.

Now I faced quite exactly the same problem as here:
https://gis.stackexchange.com/questions/260743/how-to-compile-qtdesigner-user-interface-ui-and-resource-qrc-files-with-qg
though, I was not yet successful to get the suggested solution to work, because 
it is really painful on windows with environment variables. And since I have 
another independent Python installed, this sometimes becomes a big mess. [Side 
note: because of that very reason, I will go for NixOS very soon]

So my questions now are:

*) Do you think, that being unable to run pyrcc5.bat properly is caused by the 
fact that it is searching for Python27 instead of Python36? And as soon as I 
change the etc\ini\python-core.bat to point to Python36 instead, there seem to 
be problems with the PATH / PYTHONPATH environment varibles.

*) What is Python27 doing there in first place? Because from my understanding, 
one major change in QGis3 is to step from 2.7 to 3.6, removing 2.7 completely. 
Or why is it still there?

The reason of the quite vague formulation of my question might be, that I am 
not sure, whether the problem caused by me (w.r.t. the environment variables 
PATH/PYTHONPATH, which is usually the solution to problems with import errors 
of dlls, modules, etc. under Win) or is it still some early version issue of 
the Win-Version of QGis 2.99, as Python 2.7 seems still to be there? Or is it a 
mixture of both? About 15-20 hours of online research have contributed rather 
to my confusion than to insight :)

If anyone happens to have had similar issues with developing for QGis3 (2.99) 
on Win + working solutions (e.g. hints regarding the system setup when multiple 
QGis versions are installed and maybe even another independent Python36 
exists), I would really appreciate some help.

Thank you all in advance and best regards,
Hannes
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer