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

2

3"""

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

5 readwritecontextentercategory.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 class ReadWriteContextEnterCategory():

22 """

23 Push a category to the stack

24

25 .. code-block:: python

26

27 context = QgsReadWriteContext()

28 with QgsReadWriteContext.enterCategory(context, category, details):

29 # do something

30

31 .. versionadded:: 3.2

32 """

33

34 def __init__(self, context, category_name, details=None):

35 self.context = context

36 self.category_name = category_name

37 self.details = details

38 self.popper = None

39

40 def __enter__(self):

41 self.popper = self.context._enterCategory(self.category_name, self.details)

42 return self.context

43

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

45 del self.popper

46 return True