
from . import libui


class App:

    def __init__(self):
        """
        Creates a new pylibui app.

        """
        options = libui.uiInitOptions()
        libui.uiInit(options)

    def start(self):
        """
        Starts the application main loop.

        :return: None
        """
        libui.uiMain()

    def stop(self):
        """
        Stops the application main loop.

        :return: None
        """
        libui.uiQuit()

    def close(self):
        """
        Closes the application and frees resources.

        :return: None
        """
        libui.uiUninit()


from . import libui


class App:

    def __init__(self):
        """
        Creates a new pylibui app.

        """
        options = libui.uiInitOptions()
        libui.uiInit(options)

    def __enter__(self):
     self.start()
     
    def start(self):
        """
        Starts the application main loop.

        :return: None
        """
        libui.uiMain()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.stop()
        self.close()
        

    def stop(self):
        """
        Stops the application main loop.

        :return: None
        """
        libui.uiQuit()

    def close(self):
        """
        Closes the application and frees resources.

        :return: None
        """
        libui.uiUninit()

Make App a context manager
Make App a context manager

This means it can be used either as it is now unchanged or like this:

with libui.App():
    ... # code

Note that (1) the build instructions for libui appear to be wrong "make" vs "cmake ."; and (2) I can't build libui because of a bug in it or Ubuntu 14.04's cmake I don't know which. So this change is untested.
  
  from . import libui
  
  
  class App:
  
      def __init__(self):
          """
          Creates a new pylibui app.
  
          """
          options = libui.uiInitOptions()
          libui.uiInit(options)
  
+     def __enter__(self):
+      self.start()
+      
      def start(self):
          """
          Starts the application main loop.
  
          :return: None
          """
          libui.uiMain()
+ 
+     def __exit__(self, exc_type, exc_val, exc_tb):
+         self.stop()
+         self.close()
+         
  
      def stop(self):
          """
          Stops the application main loop.
  
          :return: None
          """
          libui.uiQuit()
  
      def close(self):
          """
          Closes the application and frees resources.
  
          :return: None
          """
          libui.uiUninit()
  
Make App a context manager
## Code Before:

from . import libui


class App:

    def __init__(self):
        """
        Creates a new pylibui app.

        """
        options = libui.uiInitOptions()
        libui.uiInit(options)

    def start(self):
        """
        Starts the application main loop.

        :return: None
        """
        libui.uiMain()

    def stop(self):
        """
        Stops the application main loop.

        :return: None
        """
        libui.uiQuit()

    def close(self):
        """
        Closes the application and frees resources.

        :return: None
        """
        libui.uiUninit()

## Instruction:
Make App a context manager
## Code After:

from . import libui


class App:

    def __init__(self):
        """
        Creates a new pylibui app.

        """
        options = libui.uiInitOptions()
        libui.uiInit(options)

    def __enter__(self):
     self.start()
     
    def start(self):
        """
        Starts the application main loop.

        :return: None
        """
        libui.uiMain()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.stop()
        self.close()
        

    def stop(self):
        """
        Stops the application main loop.

        :return: None
        """
        libui.uiQuit()

    def close(self):
        """
        Closes the application and frees resources.

        :return: None
        """
        libui.uiUninit()
