class MainModule(BaseModule): """Implementation of the main module. The main module is an owner of the main loop, so it is able to start and stop the application. """ def __init__(self): super().__init__() self._loop = EventLoop() @property def loop(self): """Return the loop.""" return self._loop def run(self): """Run the module's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.debug("Start the loop.") self._loop.run() def stop(self): """Stop the module's loop.""" DBus.disconnect() Timer().timeout_sec(1, self.loop.quit)
class BaseModule(ABC): """Base implementation of a module.""" def __init__(self): self._loop = EventLoop() @property def loop(self): """Return the loop.""" return self._loop def run(self): """Run the module's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.debug("Start the loop.") self._loop.run() def publish(self): """Publish DBus objects and register a DBus service. Nothing is published by default. """ pass def stop(self): """Stop the module's loop.""" DBus.disconnect() Timer().timeout_sec(1, self.loop.quit)
class MainModule(BaseModule): """Implementation of the main module. The main module is an owner of the main loop, so it is able to start and stop the application. """ def __init__(self): super().__init__() self._loop = EventLoop() @property def loop(self): """Return the loop.""" return self._loop def run(self): """Run the module's loop.""" log.debug("Publish the module.") self.publish() log.debug("Start the loop.") self._loop.run() def stop(self): """Stop the module's loop.""" DBus.disconnect() Timer().timeout_sec(1, self.loop.quit) def set_locale(self, locale): """Set the locale for the module. This function modifies the process environment, which is not thread-safe. It should be called before any threads are run. We cannot get around setting $LANG. Python's gettext implementation differs from C in that consults only the environment for the current language and not the data set via setlocale. If we want translations from python modules to work, something needs to be set in the environment when the language changes. :param str locale: locale to set """ os.environ["LANG"] = locale # pylint: disable=environment-modify setlocale(LC_ALL, locale) # Set locale for child processes setenv("LANG", locale) log.debug("Locale is set to %s.", locale)
def __init__(self): super().__init__() self._loop = EventLoop()
def __init__(self): self._loop = EventLoop()