Exemplo n.º 1
0
    def _render(self, cr):
        Window._render(self, cr)
        
        text = DictProxy(self.style, 'text.')
        if (not self.style
            or not self.text
            or not text
            or not 'color' in text
            and text['color']):
            return 
    
        family = text.get('family', 'sans-serif')
        weight = getattr(
                cairo, 
                'FONT_WEIGHT_' + text.get('weight', 'normal').upper(), 
                cairo.FONT_WEIGHT_NORMAL,
        )
        slant = getattr(
                cairo,
                'FONT_SLANT_' + text.get('slant', 'normal').upper(),
                cairo.FONT_SLANT_NORMAL,
        )
        cr.select_font_face(family, weight, slant)

        lines = self.text.split('\n')

        valign = text.get('vertical-align', 'top')
        assert valign in ('top', 'middle', 'bottom')

        extents = cairo.font_extents_t()
        cr.font_extents(byref(extents))
        line_height = extents.height
        total_height = len(lines) * line_height
        y = self.ry

        if valign == 'top':
            y = self.ry + line_height
        elif valign == 'middle':
            y = self.ry + (self.rheight / 2) - (total_height / 2)
        elif valign == 'bottom':
            y = self.ry + self.rheight - total_height

        extents = cairo.text_extents_t()

        cr.set_source_rgb(*text['color'])

        for line in lines:
            cr.text_extents(line, byref(extents))

            align = text.get('align', 'centre')
            assert align in ('left', 'centre', 'right')
            if align == 'centre':
                cr.move_to(self.rx+(self.rwidth/2)-(extents.width/2), y)
            elif align == 'left':
                cr.move_to(self.rx, y)
            elif align == 'right':
                cr.move_to(self.rx+self.rwidth - extents.width, y)

            cr.show_text(line)
            y += line_height
Exemplo n.º 2
0
class SXMoveResize(Plugin):
    key = 'moveresize'

    def __init__(self, app):
        self.app = app
        app.push_handlers(self)

        app.plugins['actions'].register('moveresize.move', self.action_move)
        app.plugins['actions'].register('moveresize.resize', self.action_resize)

    def on_load_config(self, config):
        self.config = DictProxy(config, self.key+'.')

    def action_move(self, info):
        client = info.get('client', info['screen'].focused_client)
        if client is not None:
            client.screen.root.push_handlers(
                    MoveHandler(client, info.get('x', 0), info.get('y', 0), 
                            border_move=self.config.get('border-move', True),
                            hide_win=self.config.get('hide-win', True),
                    )
            )

    def action_resize(self, info):
        client = info.get('client', info['screen'].focused_client)
        if client is not None:
            client.screen.root.push_handlers(
                    ResizeHandler(client, info.get('x', 0), info.get('y', 0),
                            border_move=self.config.get('border-move', True),
                            hide_win=self.config.get('hide-win', True),
                    )
            )
Exemplo n.º 3
0
class SXWeb(Plugin):
    key = 'web'

    def __init__(self, app):
        self.app = app
        app.push_handlers(self)

        PluginsTab(self, 'Plugins')
        #Tab(self, 'Config')
        InteractiveTab(self, 'interactive')

    def on_load_config(self, config):
        self.config = DictProxy(config, self.key+'.')
        self.port = self.config.get('port', 8000)

    def on_ready(self, app):
        log.info('serving on port %s', self.port)
        
        wsgiapp = WSGIApp(self)

        try:
            self.httpd = simple_server.make_server('', self.port, wsgiapp)
        except socket.error, e:
            log.error('cannot launch web server: %s', str(e))
            return 

        app.add_fd_handler('read', self.httpd.socket, self.httpd.handle_request)
Exemplo n.º 4
0
    def fit(self):
        width = 0
        height = 0

        for child in self.container.children:
            child_layout_style = DictProxy(child.style, 'layout.')
            margin = child_layout_style.get('margin', 0)
            if 'width' in child.style and child.style['width']:
                width = max(width, child.style['width'] + (2 * margin))

            if 'height' in child.style and child.style['height']:
                height += child.style['height'] + (2 * margin)

        layout_style = DictProxy(self.container.style, 'layout.')
        padding = layout_style.get('padding', 0)
        width += padding * 2
        height += padding * 2

        self.container.set_size(width, height)

        if self.container.parent and hasattr(self.container.parent, 'layout'):
            self.container.parent.fit()