# Path: tilenol/widgets/base.py
# class Widget(metaclass=ABCMeta):
# 
#     bar = dependency(Bar, 'bar')
#     stretched = False
# 
#     def __init__(self, right=False):
#         self.right = right
# 
#     @abstractmethod
#     def draw(self, canvas, left, right):
#         return left, right
# 
# Path: tilenol/commands.py
# class CommandDispatcher(dict):
# 
#     def __init__(self):
#         self.events = Events()
# 
#     def __setitem__(self, name, value):
#         super().__setitem__(name, value)
#         ev = self.events.get(name)
#         if ev is not None:
#             ev.emit()
# 
#     def call(self, obj, meth, *args):
#         getattr(self[obj], 'cmd_' + meth)(*args)
# 
#     def callback(self, *args):
#         return partial(self.call, *args)
# 
# Path: tilenol/theme.py
# class Theme(SubTheme):
# 
#     def __init__(self):
# 
#         blue = 0x4c4c99
#         dark_blue = 0x191933
#         orange = 0x99994c
#         gray = 0x808080
#         red = 0x994c4c
#         black = 0x000000
#         white = 0xffffff
# 
#         self.window = SubTheme('window')
#         self.window.border_width = 2
#         self.window.set_color('active_border', blue)
#         self.window.set_color('inactive_border', gray)
#         self.window.set_color('background', black)
# 
#         self.bar = SubTheme('bar')
#         self.bar.set_color('background', black)
#         self.bar.font = Font('Consolas', 18)
#         self.bar.box_padding = Padding(2, 2, 2, 2)
#         self.bar.text_padding = Padding(2, 4, 7, 4)
#         self.bar.icon_spacing = 2
#         self.bar.set_color('text_color', white)
#         self.bar.set_color('dim_color', gray)
#         self.bar.set_color('bright_color', orange)
#         self.bar.set_color('active_border', blue)
#         self.bar.set_color('subactive_border', gray)
#         self.bar.set_color('urgent_border', red)
#         self.bar.border_width = 2
#         self.bar.height = 24
#         self.bar.set_color('graph_color', blue)
#         self.bar.set_color('graph_fill_color', dark_blue)
#         self.bar.graph_line_width = 2
#         self.bar.separator_width = 1
#         self.bar.set_color('separator_color', gray)
# 
#         self.menu = SubTheme('bar')
#         self.menu.set_color('background', gray)
#         self.menu.set_color('text', white)
#         self.menu.set_color('highlight', blue)
#         self.menu.set_color('selection', blue)
#         self.menu.set_color('selection_text', white)
#         self.menu.set_color('cursor', black)
#         self.menu.font = Font('Consolas', 18)
#         self.menu.padding = Padding(2, 4, 7, 4)
#         self.menu.line_height = 24
# 
#         self.hint = SubTheme('hint')
#         self.hint.font = Font('Consolas', 18)
#         self.hint.set_color('background', black)
#         self.hint.set_color('border_color', gray)
#         self.hint.set_color('text_color', white)
#         self.hint.border_width = 2
#         self.hint.padding = Padding(5, 6, 9, 6)
# 
#         self.tabs = SubTheme('tabs')
#         self.tabs.font = Font('Monofur', 12)
#         self.tabs.set_color('background', black)
#         self.tabs.set_color('inactive_title', gray)
#         self.tabs.set_color('inactive_bg', black)
#         self.tabs.set_color('active_title', white)
#         self.tabs.set_color('active_bg', blue)
#         self.tabs.set_color('urgent_title', white)
#         self.tabs.set_color('urgent_bg', orange)
#         self.tabs.section_font = Font('Monofur', 12)
#         self.tabs.set_color('section_color', gray)
#         self.tabs.padding = Padding(5, 6, 6, 4)
#         self.tabs.margin = Padding(4, 4, 4, 4)
#         self.tabs.border_radius = 5
#         self.tabs.spacing = 2
#         self.tabs.icon_size = 14
#         self.tabs.icon_spacing = 6
#         self.tabs.section_padding = Padding(6, 2, 2, 2)
# 
#     def update_from(self, dic):
#         for key, sub in self.__dict__.items():
#             if isinstance(sub, SubTheme) and key in dic:
#                 sub.update_from(dic[key])
# 
# Path: tilenol/ewmh.py
# def get_title(win):
#     return (win.props.get('_NET_WM_VISIBLE_NAME')
#             or win.props.get('_NET_WM_NAME')
#             or win.props.get('WM_NAME'))


from zorro.di import di, has_dependencies, dependency
from cairo import SolidPattern
from .base import Widget
from tilenol.commands import CommandDispatcher
from tilenol.theme import Theme
from tilenol.ewmh import get_title
import cairo
        self.font = bar.font
        self.padding = bar.text_padding
        self.dispatcher.events['window'].listen(self.window_changed)
        self.oldwin = None

    def window_changed(self):
        if self.oldwin is not None:
            self.oldwin.property_changed.unlisten(self.bar.redraw.emit)
        win = self.dispatcher.get('window', None)
        if win is not None:
            win.property_changed.listen(self.bar.redraw.emit)
        self.oldwin = win
        self.bar.redraw.emit()

    def draw(self, canvas, l, r):
        win = self.dispatcher.get('window', None)
        if not win:
            return r, r
        canvas.set_source(self.color)
        self.font.apply(canvas)
        canvas.move_to(l + self.padding.left,
                       self.height - self.padding.bottom)
        canvas.show_text(get_title(win) or '')
        return r, r


@has_dependencies
class Icon(Widget):

    dispatcher = dependency(CommandDispatcher, 'commander')

# Path: tilenol/widgets/base.py
# class Widget(metaclass=ABCMeta):
# 
#     bar = dependency(Bar, 'bar')
#     stretched = False
# 
#     def __init__(self, right=False):
#         self.right = right
# 
#     @abstractmethod
#     def draw(self, canvas, left, right):
#         return left, right
# 
# Path: tilenol/commands.py
# class CommandDispatcher(dict):
# 
#     def __init__(self):
#         self.events = Events()
# 
#     def __setitem__(self, name, value):
#         super().__setitem__(name, value)
#         ev = self.events.get(name)
#         if ev is not None:
#             ev.emit()
# 
#     def call(self, obj, meth, *args):
#         getattr(self[obj], 'cmd_' + meth)(*args)
# 
#     def callback(self, *args):
#         return partial(self.call, *args)
# 
# Path: tilenol/theme.py
# class Theme(SubTheme):
# 
#     def __init__(self):
# 
#         blue = 0x4c4c99
#         dark_blue = 0x191933
#         orange = 0x99994c
#         gray = 0x808080
#         red = 0x994c4c
#         black = 0x000000
#         white = 0xffffff
# 
#         self.window = SubTheme('window')
#         self.window.border_width = 2
#         self.window.set_color('active_border', blue)
#         self.window.set_color('inactive_border', gray)
#         self.window.set_color('background', black)
# 
#         self.bar = SubTheme('bar')
#         self.bar.set_color('background', black)
#         self.bar.font = Font('Consolas', 18)
#         self.bar.box_padding = Padding(2, 2, 2, 2)
#         self.bar.text_padding = Padding(2, 4, 7, 4)
#         self.bar.icon_spacing = 2
#         self.bar.set_color('text_color', white)
#         self.bar.set_color('dim_color', gray)
#         self.bar.set_color('bright_color', orange)
#         self.bar.set_color('active_border', blue)
#         self.bar.set_color('subactive_border', gray)
#         self.bar.set_color('urgent_border', red)
#         self.bar.border_width = 2
#         self.bar.height = 24
#         self.bar.set_color('graph_color', blue)
#         self.bar.set_color('graph_fill_color', dark_blue)
#         self.bar.graph_line_width = 2
#         self.bar.separator_width = 1
#         self.bar.set_color('separator_color', gray)
# 
#         self.menu = SubTheme('bar')
#         self.menu.set_color('background', gray)
#         self.menu.set_color('text', white)
#         self.menu.set_color('highlight', blue)
#         self.menu.set_color('selection', blue)
#         self.menu.set_color('selection_text', white)
#         self.menu.set_color('cursor', black)
#         self.menu.font = Font('Consolas', 18)
#         self.menu.padding = Padding(2, 4, 7, 4)
#         self.menu.line_height = 24
# 
#         self.hint = SubTheme('hint')
#         self.hint.font = Font('Consolas', 18)
#         self.hint.set_color('background', black)
#         self.hint.set_color('border_color', gray)
#         self.hint.set_color('text_color', white)
#         self.hint.border_width = 2
#         self.hint.padding = Padding(5, 6, 9, 6)
# 
#         self.tabs = SubTheme('tabs')
#         self.tabs.font = Font('Monofur', 12)
#         self.tabs.set_color('background', black)
#         self.tabs.set_color('inactive_title', gray)
#         self.tabs.set_color('inactive_bg', black)
#         self.tabs.set_color('active_title', white)
#         self.tabs.set_color('active_bg', blue)
#         self.tabs.set_color('urgent_title', white)
#         self.tabs.set_color('urgent_bg', orange)
#         self.tabs.section_font = Font('Monofur', 12)
#         self.tabs.set_color('section_color', gray)
#         self.tabs.padding = Padding(5, 6, 6, 4)
#         self.tabs.margin = Padding(4, 4, 4, 4)
#         self.tabs.border_radius = 5
#         self.tabs.spacing = 2
#         self.tabs.icon_size = 14
#         self.tabs.icon_spacing = 6
#         self.tabs.section_padding = Padding(6, 2, 2, 2)
# 
#     def update_from(self, dic):
#         for key, sub in self.__dict__.items():
#             if isinstance(sub, SubTheme) and key in dic:
#                 sub.update_from(dic[key])
# 
# Path: tilenol/ewmh.py
# def get_title(win):
#     return (win.props.get('_NET_WM_VISIBLE_NAME')
#             or win.props.get('_NET_WM_NAME')
#             or win.props.get('WM_NAME'))


# Path: tilenol/widgets/title.py
from zorro.di import di, has_dependencies, dependency
from cairo import SolidPattern
from .base import Widget
from tilenol.commands import CommandDispatcher
from tilenol.theme import Theme
from tilenol.ewmh import get_title
import cairo

        self.font = bar.font
        self.padding = bar.text_padding
        self.dispatcher.events['window'].listen(self.window_changed)
        self.oldwin = None

    def window_changed(self):
        if self.oldwin is not None:
            self.oldwin.property_changed.unlisten(self.bar.redraw.emit)
        win = self.dispatcher.get('window', None)
        if win is not None:
            win.property_changed.listen(self.bar.redraw.emit)
        self.oldwin = win
        self.bar.redraw.emit()

    def draw(self, canvas, l, r):
        win = self.dispatcher.get('window', None)
        if not win:
            return r, r
        canvas.set_source(self.color)
        self.font.apply(canvas)
        canvas.move_to(l + self.padding.left,
                       self.height - self.padding.bottom)
        canvas.show_text(get_title(win) or '')
        return r, r


@has_dependencies
class Icon(Widget):

    dispatcher = dependency(CommandDispatcher, 'commander')

    theme = dependency(Theme, 'theme')