# Path: wimpiggy/log.py
# class Logger(object):
#     def __init__(self, base=None):
#         if base is None:
#             base = sys._getframe(1).f_globals["__name__"]
#         self._base = base
# 
#     def getLogger(self, type=None):
#         name = self._base
#         if type:
#             name += ". " + type
#         return logging.getLogger(name)
# 
#     def log(self, level, msg, *args, **kwargs):
#         if kwargs.get("exc_info") is True:
#             kwargs["exc_info"] = sys.exc_info()
#         type = None
#         if "type" in kwargs:
#             type = kwargs["type"]
#             del kwargs["type"]
#         self.getLogger(type).log(level, msg, *args, **kwargs)
# 
#     def _method_maker(level):
#         return (lambda self, msg, *args, **kwargs:
#                 self.log(level, msg, *args, **kwargs))
# 
#     debug = _method_maker(logging.DEBUG)
#     __call__ = debug
#     info = _method_maker(logging.INFO)
#     warn = _method_maker(logging.WARNING)
#     error = _method_maker(logging.ERROR)


import gtk
import gobject
import wimpiggy.lowlevel
import wimpiggy.window
import wimpiggy.prop
from wimpiggy.error import *
from wimpiggy.log import Logger

    def do_focus_out_event(self, *args):
        # Do nothing -- harder:
        self.stop_emission("focus-out-event")
        return False

    def _take_focus(self):
        log("Focus -> world window", type="focus")
        assert self.flags() & gtk.REALIZED
        # Weird hack: we are a GDK window, and the only way to properly get
        # input focus to a GDK window is to send it WM_TAKE_FOCUS.  So this is
        # sending a WM_TAKE_FOCUS to our own window, which will go to the X
        # server and then come back to our own process, which will then issue
        # an XSetInputFocus on itself.  Note not swallowing errors here, this
        # should always succeed.
        now = gtk.gdk.x11_get_server_time(self.window)
        wimpiggy.lowlevel.send_wm_take_focus(self.window, now)

    def reset_x_focus(self):
        focus = self.get_focus()
        log("widget with focus: %s", focus, type="focus")
        if isinstance(focus, wimpiggy.window.WindowView):
            # FIXME: ugly:
            focus.model.give_client_focus()
            trap.swallow(wimpiggy.prop.prop_set, gtk.gdk.get_default_root_window(),
                         "_NET_ACTIVE_WINDOW", "window",
                         focus.model.get_property("client-window"))
        else:
            self._take_focus()
            wimpiggy.prop.prop_set(gtk.gdk.get_default_root_window(),

# Path: wimpiggy/log.py
# class Logger(object):
#     def __init__(self, base=None):
#         if base is None:
#             base = sys._getframe(1).f_globals["__name__"]
#         self._base = base
# 
#     def getLogger(self, type=None):
#         name = self._base
#         if type:
#             name += ". " + type
#         return logging.getLogger(name)
# 
#     def log(self, level, msg, *args, **kwargs):
#         if kwargs.get("exc_info") is True:
#             kwargs["exc_info"] = sys.exc_info()
#         type = None
#         if "type" in kwargs:
#             type = kwargs["type"]
#             del kwargs["type"]
#         self.getLogger(type).log(level, msg, *args, **kwargs)
# 
#     def _method_maker(level):
#         return (lambda self, msg, *args, **kwargs:
#                 self.log(level, msg, *args, **kwargs))
# 
#     debug = _method_maker(logging.DEBUG)
#     __call__ = debug
#     info = _method_maker(logging.INFO)
#     warn = _method_maker(logging.WARNING)
#     error = _method_maker(logging.ERROR)


# Path: wimpiggy/world_window.py
import gtk
import gobject
import wimpiggy.lowlevel
import wimpiggy.window
import wimpiggy.prop
from wimpiggy.error import *
from wimpiggy.log import Logger


    def do_focus_out_event(self, *args):
        # Do nothing -- harder:
        self.stop_emission("focus-out-event")
        return False

    def _take_focus(self):
        log("Focus -> world window", type="focus")
        assert self.flags() & gtk.REALIZED
        # Weird hack: we are a GDK window, and the only way to properly get
        # input focus to a GDK window is to send it WM_TAKE_FOCUS.  So this is
        # sending a WM_TAKE_FOCUS to our own window, which will go to the X
        # server and then come back to our own process, which will then issue
        # an XSetInputFocus on itself.  Note not swallowing errors here, this
        # should always succeed.
        now = gtk.gdk.x11_get_server_time(self.window)
        wimpiggy.lowlevel.send_wm_take_focus(self.window, now)

    def reset_x_focus(self):
        focus = self.get_focus()
        log("widget with focus: %s", focus, type="focus")
        if isinstance(focus, wimpiggy.window.WindowView):
            # FIXME: ugly:
            focus.model.give_client_focus()
            trap.swallow(wimpiggy.prop.prop_set, gtk.gdk.get_default_root_window(),
                         "_NET_ACTIVE_WINDOW", "window",
                         focus.model.get_property("client-window"))
        else:
            self._take_focus()
            wimpiggy.prop.prop_set(gtk.gdk.get_default_root_window(),

                                   "_NET_ACTIVE_WINDOW", "u32",