1# -*- coding: utf-8 -*-

2

3"""

4***************************************************************************

5 projectdirtyblocker.py

6 ---------------------

7 Date : May 2018

8 Copyright : (C) 2018 by Denis Rouzaud

9 Email : denis@opengis.ch

10***************************************************************************

11* *

12* This program is free software; you can redistribute it and/or modify *

13* it under the terms of the GNU General Public License as published by *

14* the Free Software Foundation; either version 2 of the License, or *

15* (at your option) any later version. *

16* *

17***************************************************************************

18"""

19

20

21 from qgis._core import QgsProjectDirtyBlocker

22

23

24 class ProjectDirtyBlocker():

25 """

26 Context manager used to block project setDirty calls.

27

28 .. code-block:: python

29

30 project = QgsProject.instance()

31 with QgsProject.blockDirtying(project):

32 # do something

33

34 .. versionadded:: 3.2

35 """

36

37 def __init__(self, project):

38 self.project = project

39 self.blocker = None

40

41 def __enter__(self):

42 self.blocker = QgsProjectDirtyBlocker(self.project)

43 return self.project

44

45 def __exit__(self, ex_type, ex_value, traceback):

46 del self.blocker

47 return True