Re: [QGIS-Developer] 2023 grant applications are now closed

2023-05-04 Thread Loïc Bartoletti via QGIS-Developer

Hi,

On 04/05/2023 22:08, Nyall Dawson via QGIS-Developer wrote:

Thanks Anita!

On Fri, 5 May 2023, 4:44 am Anita Graser via QGIS-Developer, 
 wrote:



8. Unify the geometric and topological verification and correction
features in QGIS -
https://github.com/qgis/QGIS-Enhancement-Proposals/issues/262


This link points to a different proposal, and I can't work out which 
is the correct one. Was a qep submitted for this grant?



It's https://github.com/qgis/QGIS-Enhancement-Proposals/issues/236

Sorry, if I miscopied the link :/


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 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] Override mouse events in Shape Digitizing Toolbar

2023-05-04 Thread Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
I have made a few posts here, so this might sound a bit repetitive, but 
specifies the specific QGIS tool I am using.

I want to override the right mouse click when using the Shape Digitizing 
Toolbar to end an edit session. I don't want it to end the session unless the 
shape is if of a specific size.  I tried getting the items on the canvas as the 
simplest way to get the shape as it is being drawn before becoming a permanent 
layer based on response to another post I made but I can only get rectangles.  
Circles don't seem to return the geometry when getting the canvas 
QgsGeometryRubberband objects.

I also have installed an event filter on the canvas that handles getting the 
size of the object being drawn.  It's become a bit of a monster of code, but it 
works other than when right clicking to end the edit session.  I want to end it 
on my terms not the terms of what is the Shape Digitizing Toolbar which is just 
close the edit session and complete the shape.  I can get it to work with a 
middle mouse click, but I want it to work with the Right mouse and it does not 
seem my event filter will stop the Shape Digitizing Toolbar from firing it's 
own end edit session.

Thanks again for the support.  Luke
___
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] RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

2023-05-04 Thread Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
So I discarded my changes and started over and I also changed the event to end 
the drawing from the left mouse button to the middle and managed to avoid the 
deleted object error.  I tested a multitude of shape drawings and clicking the 
middle button to end my edit session when the size is not large enough and it 
ignores ending the edit session and completing the polygon until I middle click 
and the size is valid.

If I change the event to the right mouse button I get the error again, so this 
is making me believe that I am not fully overriding the event for the right 
mouse button and it works for the middle button because the map canvas does not 
use the middle mouse button for any event when a feature is being drawn.

While this great that it works with middle mouse button, I want the edit 
session to stop when the user clicks right not middle as that is the way QGIS 
works for completing an edit session.

This is vert frustrating. 

From: QGIS-Developer  On Behalf Of 
Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
Sent: Thursday, May 4, 2023 2:05 PM
To: Benjamin Jakimow ; 
qgis-developer@lists.osgeo.org
Subject: Re: [QGIS-Developer] RuntimeError: wrapped C/C++ object of type 
QgsVectorLayer has been deleted

Thanks.  I’m just trying to figure out how this happens because I don’t remove 
the layer from the map.  It’s actually initially added as an empty layer and 
then the geometry is added and then the changes are committed, so I never 
remove it.  I’ll review my code again to see if I do anything odd.

From: QGIS-Developer 
mailto:qgis-developer-boun...@lists.osgeo.org>>
 On Behalf Of Benjamin Jakimow via QGIS-Developer
Sent: Thursday, May 4, 2023 3:21 AM
To: qgis-developer@lists.osgeo.org
Subject: Re: [QGIS-Developer] RuntimeError: wrapped C/C++ object of type 
QgsVectorLayer has been deleted


Hi Luke,

to my experience the "RuntimeError: wrapped C/C++ object of type QgsVectorLayer 
has been deleted" is raised when the C++ QgsVectorLayer has been deleted by a 
parent class.
This is often a QgsMapLayerStore, for example the 
QgsProject.instance().mapLayerStore(), from which a layer gets removed when it 
is removed from the layer tree.

In that case your self.aoi_layer python reference still exists, but not the 
underlying C++ object.

You could ensure that the aoi_layer is not removed from the layer store it is 
stored in, for example using QgsLayerStore::takeMapLayer(layer) instead 
QgsLayerStore::removeMapLayer(layer).
Or save the aoi_layer_id and test in your eventFilter, if the aoi_layer 
instance still exists:

aoi_layer = self.project().mapLayers().get(self.aoi_layer_id)

if isinstance(aoi_layer, QgsMapLayer):
   aoi_layer_data_provider = aoi_layer.dataProvider()

  ...



Greetings,

Benjamin
Am 04.05.2023 um 04:46 schrieb Catania, Luke A ERDC-RDE-GRL-VA CIV via 
QGIS-Developer:
I am trying to understand the general meaning of the message below.

RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

I step through my code in the debugger and at some point my variable, 
aoi_layer, is longer assigned to a specific vector layer, though the value 
comes back as QgsVectorLayer since I have a watch on it.  I though maybe 
somehow it got set to “None”, but it’s not None.

I’d like to post code, but I’d have way to much code to post.  I am basically 
trying to override the map canvas events with an eventFIlter while I go through 
a drawing process.  I want a particular action to occur when I right click on 
the map canvas.  I am trying to override the map canvas from completing a 
drawing of a shape if the shape is too small, but it does not seem to override 
it. The shape is completed when I right click, so it seems like I have not 
overridden the event even though I capture the event using the code below:

def eventFilter(self, source, event):
  if event.type() == QEvent.MouseButtonPress and event.button() == 
Qt.RightButton:
if self.valid_size(self.aoi_area):
aoi_layer_data_provider = 
self.aoi_layer.dataProvider()
self.aoi_feature.setGeometry(self.aoi_geometry)

aoi_layer_data_provider.addFeatures([self.aoi_feature])
self.aoi_layer.commitChanges()


self.aoi_layer.setExtent(self.aoi_feature.geometry().boundingBox())

self.add_area_perimeter()

self._refresh_and_zoom_to_layer(True)

self.AOI_SIZE_VALIDATOR_LABEL.close()
self.track_cursor = False
iface.mapCanvas().viewport().removeEventFilter(self)

Return False

I initially had the return to be “return super().eventFilter(source, event)”

So the shape is completed and it adds it to the layer that is open for editing. 
 My function allows the drawing to continue 

Re: [QGIS-Developer] [EXTERNAL] Re: Outdated WebKit engine version in QGIS

2023-05-04 Thread Nguyen, Huy Minh via QGIS-Developer
Thanks for the infos.

After some trial and error, I am able to use QtWebEngine as Qt QML component in 
python in QGIS 3.26.3 and QGIS 3.30.1 out-of-the-box. Example from Qt docs 
works as expected https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html

This approach doesn't work on macOS however. It shows QML errors module 
"QtWebEngine" is not installed, module "QtQuick.Window" is not installed . I 
think that this is due to lack of certain library in the QGIS bundle in macOS, 
similar to https://github.com/qgis/QGIS-Mac-Packager/issues/122. If this could 
be addressed for macOS, I think that using QtWebEngine as QML component in QGIS 
could be a notable alternative.


Regards,
Minh


From: Yoann Quenach de Quivillic 
Sent: Thursday, April 20, 2023 9:17 AM
To: Nyall Dawson 
Cc: Nguyen, Huy Minh ; qgis-developer@lists.osgeo.org
Subject: Re: [QGIS-Developer] [EXTERNAL] Re: Outdated WebKit engine version in 
QGIS

Sie erhalten nicht oft eine E-Mail von 
yoann.quen...@gmail.com. Erfahren Sie, warum 
dies wichtig ist
FYI, here's a (probably) related Qt bug report, but unfortunately it has not 
seen much activity lately: 
https://bugreports.qt.io/plugins/servlet/mobile#issue/QTBUG-85492.

Le jeu. 20 avr. 2023 à 00:31, Nyall Dawson via QGIS-Developer 
mailto:qgis-developer@lists.osgeo.org>> a écrit 
:
On Wed, 19 Apr 2023 at 16:55, Nguyen, Huy Minh 
mailto:huyminh.ngu...@here.com>> wrote:
>
> Hi,
>
> If Qt Webengine is in QGIS why it cannot be used ? Is there maybe any Qgs 
> class that uses Qt Webengine internally and can be reused ?

It's not in QGIS. It's in Qt, but can't be used from QGIS. QtWebengine
requires some initialization steps before construction of the
QApplication used by QGIS, and unfortunately these steps introduce an
incompatibility in OpenGL handling which breaks the QGIS 3D
functionality.

Pending an upstream Qt / Webengine fix we can't resolve this
situation, and Qt Webengine is not a possibility for use in QGIS.

Nyall


>
> Minh
>
>
> -Original Message-
> From: Nyall Dawson mailto:nyall.daw...@gmail.com>>
> Sent: Wednesday, April 19, 2023 7:28 AM
> To: Nguyen, Huy Minh mailto:huyminh.ngu...@here.com>>
> Cc: qgis-developer@lists.osgeo.org
> Subject: [EXTERNAL] Re: [QGIS-Developer] Outdated WebKit engine version in 
> QGIS
>
>
> On Wed, 19 Apr 2023 at 15:24, Nguyen, Huy Minh via QGIS-Developer 
> mailto:qgis-developer@lists.osgeo.org>> wrote:
> >
> > Hi,
> >
> >
> >
> > I have been using WebKit engine from the PyQt library built in QGIS 3.30 
> > when developing QGIS plugin in Python to load web pages directly in QGIS. 
> > The Webkit engine used seems to be very outdated and not possible to render 
> > modern web pages. For example, the engine used in QGIS 3.30 dated back to 
> > 2016: AppleWebKit/602.1 (KHTML, like Gecko) QGIS3 Version/10.0 Safari/602.1.
> >
> >
> >
> > Is there any chance to update the built-in Webkit engine version in next 
> > release of QGIS ?
> >
> > Otherwise, can the WebKit engine be updated locally and provided to the 
> > application ?
> >
> > Does QGIS offer any other built-in alternatives, like the Qt WebEngine or 
> > other web engine with python bindings ?
>
> It's an extremely messy and painful situation, but ultimately the answer is 
> NO. There's no alternative, no way of updating the webkit version used by 
> QtWebkit, and Qt Webengine CANNOT be used as it stands in QGIS.
>
> Nyall
>
> >
> >
> >
> > Thank you,
> >
> > Minh
> >
> >
> >
> >
> >
> > ___
> > QGIS-Developer mailing list
> > QGIS-Developer@lists.osgeo.org
> > List info:
> > https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> > s.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-developer=05%7C01%7Chuymi
> > nh.nguyen%40here.com%7C83865261759a4e94b02808db4096e273%7C6d4034cd7225
> > 4f72b85391feaea64919%7C0%7C0%7C638174789008955324%7CUnknown%7CTWFpbGZs
> > b3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D
> > %7C3000%7C%7C%7C=zsajlNbGjcZdZMAp%2BnBCgSAP1Tap5O6Ni8WbFSvKsuE%3
> > D=0
> > Unsubscribe:
> > https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> > s.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-developer=05%7C01%7Chuymi
> > nh.nguyen%40here.com%7C83865261759a4e94b02808db4096e273%7C6d4034cd7225
> > 4f72b85391feaea64919%7C0%7C0%7C638174789008955324%7CUnknown%7CTWFpbGZs
> > b3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D
> > %7C3000%7C%7C%7C=zsajlNbGjcZdZMAp%2BnBCgSAP1Tap5O6Ni8WbFSvKsuE%3
> > D=0
> LEARN FAST: This email originated outside of HERE.
> Please do not click on links or open attachments unless you recognize the 
> sender and know the content is safe. Thank you.
>

Re: [QGIS-Developer] 2023 grant applications are now closed

2023-05-04 Thread Nyall Dawson via QGIS-Developer
Thanks Anita!

On Fri, 5 May 2023, 4:44 am Anita Graser via QGIS-Developer, <
qgis-developer@lists.osgeo.org> wrote:

>
> 8. Unify the geometric and topological verification and correction
> features in QGIS -
> https://github.com/qgis/QGIS-Enhancement-Proposals/issues/262
>

This link points to a different proposal, and I can't work out which is the
correct one. Was a qep submitted for this grant?

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] 2023 grant applications are now closed

2023-05-04 Thread Anita Graser via QGIS-Developer
Dear QGIS Community,

 

This is to let you know that the form for grant applications is now closed and that we have received 9 complete applications totalling € 103,600.

 

As a quick teaser, here are the proposals:

 

1. QGIS Bug Tracker cleanup - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/266

2. Switch to clang-format for C++ code and implement pre-commit hooks - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/264 and https://github.com/qgis/QGIS-Enhancement-Proposals/issues/265

3. Add vertical CRS handling to QGIS - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/267

4. Improve test result handling on QGIS CI - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/268

5. Update older annotation items to new framework - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/269

6. QGIS Project Loading Performance - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/261

7. Conda Installer for macOS - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/270

8. Unify the geometric and topological verification and correction features in QGIS - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/262

9. Porting to C++ and harmonization of Processing algorithms - https://github.com/qgis/QGIS-Enhancement-Proposals/issues/271

 

We are now in the QEP discussion phase. Please tag all proposals with the Grant-2023 tag:

 

https://github.com/qgis/QGIS-Enhancement-Proposals/issues?q=is%3Aissue+is%3Aopen+label%3AGrant-2023

 

The QEP discussion phase takes two weeks and ends on Tuesday, 2023-05-16.

Afterwards, we will proceed to writing discussion summaries (by 2023-05-23),

followed by the voting phase with expected publication of voting results on 2023-06-06.

 

Thank you to everyone who submitted project proposals!


Regards,

Anita

 
___
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] RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

2023-05-04 Thread Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
Thanks.  I’m just trying to figure out how this happens because I don’t remove 
the layer from the map.  It’s actually initially added as an empty layer and 
then the geometry is added and then the changes are committed, so I never 
remove it.  I’ll review my code again to see if I do anything odd.

From: QGIS-Developer  On Behalf Of 
Benjamin Jakimow via QGIS-Developer
Sent: Thursday, May 4, 2023 3:21 AM
To: qgis-developer@lists.osgeo.org
Subject: Re: [QGIS-Developer] RuntimeError: wrapped C/C++ object of type 
QgsVectorLayer has been deleted


Hi Luke,

to my experience the "RuntimeError: wrapped C/C++ object of type QgsVectorLayer 
has been deleted" is raised when the C++ QgsVectorLayer has been deleted by a 
parent class.
This is often a QgsMapLayerStore, for example the 
QgsProject.instance().mapLayerStore(), from which a layer gets removed when it 
is removed from the layer tree.

In that case your self.aoi_layer python reference still exists, but not the 
underlying C++ object.

You could ensure that the aoi_layer is not removed from the layer store it is 
stored in, for example using QgsLayerStore::takeMapLayer(layer) instead 
QgsLayerStore::removeMapLayer(layer).
Or save the aoi_layer_id and test in your eventFilter, if the aoi_layer 
instance still exists:

aoi_layer = self.project().mapLayers().get(self.aoi_layer_id)

if isinstance(aoi_layer, QgsMapLayer):
   aoi_layer_data_provider = aoi_layer.dataProvider()

  ...



Greetings,

Benjamin
Am 04.05.2023 um 04:46 schrieb Catania, Luke A ERDC-RDE-GRL-VA CIV via 
QGIS-Developer:
I am trying to understand the general meaning of the message below.

RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

I step through my code in the debugger and at some point my variable, 
aoi_layer, is longer assigned to a specific vector layer, though the value 
comes back as QgsVectorLayer since I have a watch on it.  I though maybe 
somehow it got set to “None”, but it’s not None.

I’d like to post code, but I’d have way to much code to post.  I am basically 
trying to override the map canvas events with an eventFIlter while I go through 
a drawing process.  I want a particular action to occur when I right click on 
the map canvas.  I am trying to override the map canvas from completing a 
drawing of a shape if the shape is too small, but it does not seem to override 
it. The shape is completed when I right click, so it seems like I have not 
overridden the event even though I capture the event using the code below:

def eventFilter(self, source, event):
  if event.type() == QEvent.MouseButtonPress and event.button() == 
Qt.RightButton:
if self.valid_size(self.aoi_area):
aoi_layer_data_provider = 
self.aoi_layer.dataProvider()
self.aoi_feature.setGeometry(self.aoi_geometry)

aoi_layer_data_provider.addFeatures([self.aoi_feature])
self.aoi_layer.commitChanges()


self.aoi_layer.setExtent(self.aoi_feature.geometry().boundingBox())

self.add_area_perimeter()

self._refresh_and_zoom_to_layer(True)

self.AOI_SIZE_VALIDATOR_LABEL.close()
self.track_cursor = False
iface.mapCanvas().viewport().removeEventFilter(self)

Return False

I initially had the return to be “return super().eventFilter(source, event)”

So the shape is completed and it adds it to the layer that is open for editing. 
 My function allows the drawing to continue because my check indicates the 
shape is not large enough so the commit should not happen unless the size is 
valid.

I can continue drawing but I right click on the map canvas it completes the 
drawing a second time, so now I have two rectangles, both with the same start 
position, but one larger than the other.  It is when I create a second layer to 
draw that I get the runtime error.

So I have two problems.  I don’t seem to be completely overriding the build in 
event handler and QGIS is still completing the drawing when I right click. And 
somehow this may be contributing to the runtime error.

If I can understand in general how my object is deleted when I don’t have any 
statement that deletes the object maybe I can figure it out the second issue.



___

QGIS-Developer mailing list

QGIS-Developer@lists.osgeo.org

List info: Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked

Unsubscribe: 
Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked

--

Dr. Benjamin Jakimow

Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin



e-mail: 
benjamin.jaki...@geo.hu-berlin.de

web:Blockedhttps://hu-berlin.de/eo-labBlocked


Re: [QGIS-Developer] Multiple python scripts in python console?

2023-05-04 Thread Etienne Trimaille via QGIS-Developer
> For example, a newly defined function on the class was
> unknown in script_1. Might be a bug, but I'm not even sure.

Well, for me it works without any issue.
But you need to re-execute the script_2.py in the Python console, it will
refresh the class definition in the Python console context then you can
execute script_1 again.

But indeed, you are reaching the limit of using the Python console like
this ...


Le jeu. 4 mai 2023 à 16:02, Raymond Nijssen  a
écrit :

> Hi Etienne,
>
> Already tried what you are describing. Indeed it's inconvenient, and
> sometimes the changes in the class code did not end up in the class
> definition. For example, a newly defined function on the class was
> unknown in script_1. Might be a bug, but I'm not even sure.
>
> So the best way should be to tell QGIS to run another python script in
> the console. Or go the plugin way.
>
> Thanks and kind regards,
>
> Raymond
>
>
> On 04-05-2023 11:29, Etienne Trimaille wrote:
> > If you are talking about the simple Python console panel, and loading
> > Python files from there, then you can skip the " from .script_2 import
> > TestClass".
> >
> > If you notice, when you launch the script_2.py, you have a generated
> > line similar to :
> > exec(Path('/tmp/tmp5g244g4w.py').read_text())
> >
> > So it's reading and executing all the content of file 2 in the console
> > context already.
> > So then, when file 1 will be executed, there will already be the class
> > TestClass in the console context.
> >
> > But, then to manage multiple files, it's not convenient. You should
> > think about the smallest plugin, for instance
> > https://github.com/wonder-sk/qgis-minimal-plugin
> >  Otherwise, it's
> > difficult to manage IMHO.
> >
> > Le jeu. 4 mai 2023 à 08:59, Raymond Nijssen via QGIS-Developer
> > mailto:qgis-developer@lists.osgeo.org>>
>
> > a écrit :
> >
> > Hi developers,
> >
> > While writing a python script in the QGIS python console editor I
> > needed
> > to write a new class and for convenience I put that in its own
> > python file.
> >
> > Both files are in the same directory, but I cannot import my class in
> > the other script.
> >
> > Here's an example:
> >
> >
> > # script_1.py
> >
> > from .script_2 import TestClass
> > obj1 = TestClass('Ray')
> > print(obj1)
> >
> >
> >
> >
> > # script_2.py:
> >
> > class TestClass():
> >
> >   def __init__(self, name):
> > self.name  = name
> >
> >   def __str__(self):
> >   return f'TestClass[{self.name }]'
> >
> >
> >
> > It all works properly if I put my class definition in script_1 but as
> > the code is growing (and a customer of mine needs to understand this
> > too) it would really be nice to split the code over multiple files.
> > Is there a way? Or another approach?
> >
> > Kind regards,
> > Raymond
> > ___
> > QGIS-Developer mailing list
> > QGIS-Developer@lists.osgeo.org  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] Multiple python scripts in python console?

2023-05-04 Thread Raymond Nijssen via QGIS-Developer

Hi Etienne,

Already tried what you are describing. Indeed it's inconvenient, and 
sometimes the changes in the class code did not end up in the class 
definition. For example, a newly defined function on the class was 
unknown in script_1. Might be a bug, but I'm not even sure.


So the best way should be to tell QGIS to run another python script in 
the console. Or go the plugin way.


Thanks and kind regards,

Raymond


On 04-05-2023 11:29, Etienne Trimaille wrote:
If you are talking about the simple Python console panel, and loading 
Python files from there, then you can skip the " from .script_2 import 
TestClass".


If you notice, when you launch the script_2.py, you have a generated 
line similar to :

exec(Path('/tmp/tmp5g244g4w.py').read_text())

So it's reading and executing all the content of file 2 in the console 
context already.
So then, when file 1 will be executed, there will already be the class 
TestClass in the console context.


But, then to manage multiple files, it's not convenient. You should 
think about the smallest plugin, for instance 
https://github.com/wonder-sk/qgis-minimal-plugin 
 Otherwise, it's 
difficult to manage IMHO.


Le jeu. 4 mai 2023 à 08:59, Raymond Nijssen via QGIS-Developer 
mailto:qgis-developer@lists.osgeo.org>> 
a écrit :


Hi developers,

While writing a python script in the QGIS python console editor I
needed
to write a new class and for convenience I put that in its own
python file.

Both files are in the same directory, but I cannot import my class in
the other script.

Here's an example:


# script_1.py

from .script_2 import TestClass
obj1 = TestClass('Ray')
print(obj1)




# script_2.py:

class TestClass():

      def __init__(self, name):
self.name  = name

      def __str__(self):
          return f'TestClass[{self.name }]'



It all works properly if I put my class definition in script_1 but as
the code is growing (and a customer of mine needs to understand this
too) it would really be nice to split the code over multiple files.
Is there a way? Or another approach?

Kind regards,
Raymond
___
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 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] Multiple python scripts in python console?

2023-05-04 Thread Etienne Trimaille via QGIS-Developer
If you are talking about the simple Python console panel, and loading
Python files from there, then you can skip the " from .script_2 import
TestClass".

If you notice, when you launch the script_2.py, you have a generated line
similar to :
exec(Path('/tmp/tmp5g244g4w.py').read_text())

So it's reading and executing all the content of file 2 in the console
context already.
So then, when file 1 will be executed, there will already be the class
TestClass in the console context.

But, then to manage multiple files, it's not convenient. You should think
about the smallest plugin, for instance
https://github.com/wonder-sk/qgis-minimal-plugin Otherwise, it's difficult
to manage IMHO.

Le jeu. 4 mai 2023 à 08:59, Raymond Nijssen via QGIS-Developer <
qgis-developer@lists.osgeo.org> a écrit :

> Hi developers,
>
> While writing a python script in the QGIS python console editor I needed
> to write a new class and for convenience I put that in its own python file.
>
> Both files are in the same directory, but I cannot import my class in
> the other script.
>
> Here's an example:
>
>
> # script_1.py
>
> from .script_2 import TestClass
> obj1 = TestClass('Ray')
> print(obj1)
>
>
>
>
> # script_2.py:
>
> class TestClass():
>
>  def __init__(self, name):
>  self.name = name
>
>  def __str__(self):
>  return f'TestClass[{self.name}]'
>
>
>
> It all works properly if I put my class definition in script_1 but as
> the code is growing (and a customer of mine needs to understand this
> too) it would really be nice to split the code over multiple files.
> Is there a way? Or another approach?
>
> Kind regards,
> Raymond
> ___
> 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 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] RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

2023-05-04 Thread Benjamin Jakimow via QGIS-Developer

Hi Luke,

to my experience the "RuntimeError: wrapped C/C++ object of type 
QgsVectorLayer has been deleted" is raised when the C++ QgsVectorLayer 
has been deleted by a parent class.
This is often a QgsMapLayerStore, for example the 
QgsProject.instance().mapLayerStore(), from which a layer gets removed 
when it is removed from the layer tree.


In that case your self.aoi_layer python reference still exists, but not 
the underlying C++ object.


You could ensure that the aoi_layer is not removed from the layer store 
it is stored in, for example using QgsLayerStore::takeMapLayer(layer) 
instead QgsLayerStore::removeMapLayer(layer).
Or save the aoi_layer_id and test in your eventFilter, if the aoi_layer 
instance still exists:


aoi_layer = self.project().mapLayers().get(self.aoi_layer_id)

if isinstance(aoi_layer, QgsMapLayer):
   aoi_layer_data_provider = aoi_layer.dataProvider()

  ...


Greetings,

Benjamin

Am 04.05.2023 um 04:46 schrieb Catania, Luke A ERDC-RDE-GRL-VA CIV via 
QGIS-Developer:


I am trying to understand the general meaning of the message below.

RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted

I step through my code in the debugger and at some point my variable, 
aoi_layer, is longer assigned to a specific vector layer, though the 
value comes back as QgsVectorLayer since I have a watch on it.  I 
though maybe somehow it got set to “None”, but it’s not None.


I’d like to post code, but I’d have way to much code to post.  I am 
basically trying to override the map canvas events with an eventFIlter 
while I go through a drawing process.  I want a particular action to 
occur when I right click on the map canvas.  I am trying to override 
the map canvas from completing a drawing of a shape if the shape is 
too small, but it does not seem to override it. The shape is completed 
when I right click, so it seems like I have not overridden the event 
even though I capture the event using the code below:


    def eventFilter(self, source, event):

          if event.type() == QEvent.MouseButtonPress and 
event.button() == Qt.RightButton:


                        if self.valid_size(self.aoi_area):

aoi_layer_data_provider = self.aoi_layer.dataProvider()

self.aoi_feature.setGeometry(self.aoi_geometry)

aoi_layer_data_provider.addFeatures([self.aoi_feature])

self.aoi_layer.commitChanges()

self.aoi_layer.setExtent(self.aoi_feature.geometry().boundingBox())

self.add_area_perimeter()

self._refresh_and_zoom_to_layer(True)

self.AOI_SIZE_VALIDATOR_LABEL.close()

self.track_cursor = False

iface.mapCanvas().viewport().removeEventFilter(self)

    Return False

I initially had the return to be “return super().eventFilter(source, 
event)”


So the shape is completed and it adds it to the layer that is open for 
editing.  My function allows the drawing to continue because my check 
indicates the shape is not large enough so the commit should not 
happen unless the size is valid.


I can continue drawing but I right click on the map canvas it 
completes the drawing a second time, so now I have two rectangles, 
both with the same start position, but one larger than the other.  It 
is when I create a second layer to draw that I get the runtime error.


So I have two problems.  I don’t seem to be completely overriding the 
build in event handler and QGIS is still completing the drawing when I 
right click. And somehow this may be contributing to the runtime error.


If I can understand in general how my object is deleted when I don’t 
have any statement that deletes the object maybe I can figure it out 
the second issue.



___
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


--
Dr. Benjamin Jakimow
Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin

e-mail:benjamin.jaki...@geo.hu-berlin.de
web:https://hu-berlin.de/eo-lab
phone:  +49 (0) 30 2093 6846
mobile: +49 (0) 157 5656 8477
fax:+49 (0) 30 2093 6848
mail:   Unter den Linden 6 | 10099 Berlin | Germany
room: 2'211
linkedin:https://www.linkedin.com/in/benjamin-jakimow
matrix: @jakimowb:hu-berlin.de


smime.p7s
Description: S/MIME Cryptographic Signature
___
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] Multiple python scripts in python console?

2023-05-04 Thread Raymond Nijssen via QGIS-Developer

Hi developers,

While writing a python script in the QGIS python console editor I needed 
to write a new class and for convenience I put that in its own python file.


Both files are in the same directory, but I cannot import my class in 
the other script.


Here's an example:


# script_1.py

from .script_2 import TestClass
obj1 = TestClass('Ray')
print(obj1)




# script_2.py:

class TestClass():

def __init__(self, name):
self.name = name

def __str__(self):
return f'TestClass[{self.name}]'



It all works properly if I put my class definition in script_1 but as 
the code is growing (and a customer of mine needs to understand this 
too) it would really be nice to split the code over multiple files.

Is there a way? Or another approach?

Kind regards,
Raymond
___
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