Beispiel #1
0
    def draw(self):
        px, py = self.style['padding']
        px2, py2 = px / 2, py / 2
        if self.orientation == 'vertical':
            pos = (self.x + px2, self.y + self.value_min * self.ratio + py2)
            size = (self.width - px, (self.value_max - self.value_min) *
                    self.ratio - py)
            textposmin = (self.x + self.width, self.y + self.value_min * self.ratio)
            textposmax = (self.x + self.width, self.y + self.value_max * self.ratio)
        elif self.orientation == 'horizontal':
            pos = (self.x + self.value_min * self.ratio + px2, self.y + py2)
            size = ((self.value_max - self.value_min) * self.ratio - px,
                    self.height - py)
            textposmin = (self.x + self.value_min * self.ratio, self.y + self.height)
            textposmax = (self.x + self.value_max * self.ratio, self.y + self.height)

        # draw outer rectangle
        set_color(*self.style.get('bg-color'))
        drawCSSRectangle(pos=self.pos, size=self.size, style=self.style)

        # draw inner rectangle
        set_color(*self.style.get('slider-color'))
        drawCSSRectangle(pos=pos, size=size, style=self.style, prefix='slider')
        if self.showtext and len(self.touchstarts):
            drawLabel(u'%.1f' % (self.value_min), pos=textposmin, font_size=self.style['font-size'])
            drawLabel(u'%.1f' % (self.value_max), pos=textposmax, font_size=self.style['font-size'])
Beispiel #2
0
 def draw(self):
     '''Draw the current image camera'''
     if self._texture:
         set_color(*self.color)
         drawTexturedRectangle(self._texture, pos=self.pos, size=self.size)
     else:
         drawRectangle(pos=self.pos, size=self.size)
         drawLabel('No Camera :(', pos=(self.width/2, self.height/2))
Beispiel #3
0
 def draw(self):
     if self.selected:
         selected_color = self.style.get('selected-color', (0.4,) * 4)
         set_color(*selected_color)
         drawCSSRectangle(pos=self.pos, size=self.size, style=self.style)
     pos = int(self.x + self.width / 2.), int(self.y + 10)
     drawLabel(label=self.striptext(self.label_txt, 10), pos=pos)
     self.image.x        = self.x + int(self.image.width / 2) - 5
     self.image.y        = self.y + int(self.image.height / 2) - 5
     self.image.draw()
Beispiel #4
0
 def draw(self):
     if self.selected:
         selected_color = self.style.get('selected-color', (0.4, ) * 4)
         set_color(*selected_color)
         drawCSSRectangle(pos=self.pos, size=self.size, style=self.style)
     pos = int(self.x + self.width / 2.), int(self.y + 10)
     drawLabel(label=self.striptext(self.label_txt, 10), pos=pos)
     self.image.x = self.x + int(self.image.width / 2) - 5
     self.image.y = self.y + int(self.image.height / 2) - 5
     self.image.draw()
Beispiel #5
0
    def draw(self):
        pos = self.image.width, self.y
        # Max number of chars for this entry's label
        max_chars = 20
        # Simple trick to get the maximum label width for the current font size
        self.width = getLabel('W'*max_chars, font_size=self.font_size).width
        if self.selected:
            selected_color = self.style.get('selected-color', (0.4,) * 4)
            set_color(*selected_color)
            drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style)
        kwargs = {'pos': pos, 'anchor_x': 'left', 'anchor_y': 'bottom', 'font_size':self.style['font-size'],
                  'color':self.style['color']}
        drawLabel(label=self.striptext(self.label_txt, max_chars), **kwargs )

        self.image.pos = (0, self.y)
        self.image.draw()
Beispiel #6
0
    def draw_label(self, dx=0, dy=0):
        '''Method to draw the label. Accept dx/dy to be added on label position.
        This can be used to draw shadow for example.'''
        # because the anchor_x/anchor_y is propagated to the drawLabel,
        # we don't care about the internal label size.
        pos = list(self.center)
        if self.anchor_x == 'left':
            pos[0] = self.x
        elif self.anchor_x == 'right':
            pos[0] = self.x + self.width
        if self.anchor_y == 'top':
            pos[1] = self.y + self.height
        elif self.anchor_y == 'bottom':
            pos[1] = self.y

        pos[0] += dx
        pos[1] += dy

        # ensure multiline
        if self.multiline:
            self.kwargs['size'] = (self.width, None)

        # force autosize
        if self.autosize or self.autowidth or self.autoheight:
            if 'size' in self.kwargs:
                del self.kwargs['size']

        w, h = drawLabel(label=self.label, pos=pos, **self.kwargs)
        self._used_label = getLastLabel()
        self._update_size(w, h)
Beispiel #7
0
    def on_draw(self):
        """Event called when window we are drawing window.
        This function are cleaning the buffer with bg-color css,
        and call children drawing + show fps timer on demand"""

        # draw our window
        self.draw()

        # then, draw childrens
        for w in self.children[:]:
            w.dispatch_event("on_draw")

        if self.show_fps:
            fps = getClock().get_fps()
            drawLabel(label="FPS: %.2f" % float(fps), center=False, pos=(0, 0), font_size=10, bold=False)

        self.draw_mouse_touch()
Beispiel #8
0
 def draw(self):
     pos = self.image.width, self.y
     # Max number of chars for this entry's label
     max_chars = 20
     # Simple trick to get the maximum label width for the current font size
     self.width = getLabel('W' * max_chars, font_size=self.font_size).width
     if self.selected:
         selected_color = self.style.get('selected-color', (0.4, ) * 4)
         set_color(*selected_color)
         drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style)
     drawLabel(label=self.striptext(self.label_txt, max_chars),
               pos=pos,
               anchor_x='left',
               anchor_y='bottom',
               font_size=self.style.get('font-size'),
               color=self.style.get('color'))
     self.image.pos = (0, self.y)
     self.image.draw()
Beispiel #9
0
    def on_draw(self):
        '''Event called when window we are drawing window.
        This function are cleaning the buffer with bg-color css,
        and call children drawing + show fps timer on demand'''

        # draw our window
        self.draw()

        # then, draw childrens
        for w in self.children[:]:
            w.dispatch_event('on_draw')

        if self.show_fps:
            fps = getClock().get_fps()
            drawLabel(label='FPS: %.2f' % float(fps),
                      center=False,
                      pos=(0, 0),
                      font_size=10,
                      bold=False)

        self.draw_mouse_touch()
Beispiel #10
0
    def draw_label(self, dx=0, dy=0):
        '''Method to draw the label. Accept dx/dy to be added on label position.
        This can be used to draw shadow for example.'''
        # because the anchor_x/anchor_y is propagated to the drawLabel,
        # we don't care about the internal label size.
        kwargs = self.kwargs
        pos = list(self.center)
        if self.anchor_x == 'left':
            pos[0] = self.x
        elif self.anchor_x == 'right':
            pos[0] = self.x + self.width
        if self.anchor_y == 'top':
            pos[1] = self.y + self.height
        elif self.anchor_y == 'bottom':
            pos[1] = self.y

        pos[0] += dx
        pos[1] += dy

        # ensure multiline
        if self.multiline:
            kwargs['size'] = (self.width, None)

        # force autosize
        if self.autosize or self.autowidth or self.autoheight:
            if 'size' in kwargs:
                if self.autoheight:
                    kwargs['size'] = (kwargs['size'][0], None)
                else:
                    del kwargs['size']
        else:
            # FIXME: found a way to cache this information
            # and not calculate it every frame.
            w, h = self.size
            px = self._used_label.options['padding_x']
            py = self._used_label.options['padding_y']
            w -= px * 2
            h -= py * 2
            kwargs['viewport_size'] = (w, h)

        w, h = drawLabel(label=self.label, pos=pos, **kwargs)
        self._used_label = getLastLabel()
        self._update_size(w, h)
Beispiel #11
0
    def draw_label(self, dx=0, dy=0):
        '''Method to draw the label. Accept dx/dy to be added on label position.
        This can be used to draw shadow for example.'''
        # because the anchor_x/anchor_y is propagated to the drawLabel,
        # we don't care about the internal label size.
        kwargs = self.kwargs
        pos = list(self.center)
        if self.anchor_x == 'left':
            pos[0] = self.x
        elif self.anchor_x == 'right':
            pos[0] = self.x + self.width
        if self.anchor_y == 'top':
            pos[1] = self.y + self.height
        elif self.anchor_y == 'bottom':
            pos[1] = self.y

        pos[0] += dx
        pos[1] += dy

        # ensure multiline
        if self.multiline:
            kwargs['size'] = (self.width, None)

        # force autosize
        if self.autosize or self.autowidth or self.autoheight:
            if 'size' in kwargs:
                if self.autoheight:
                    kwargs['size'] = (kwargs['size'][0], None)
                else:
                    del kwargs['size']
        else:
            # FIXME: found a way to cache this information
            # and not calculate it every frame.
            w, h = self.size
            px = self._used_label.options['padding_x']
            py = self._used_label.options['padding_y']
            w -= px * 2
            h -= py * 2
            kwargs['viewport_size'] = (w, h)

        w, h = drawLabel(label=self.label, pos=pos, **kwargs)
        self._used_label = getLastLabel()
        self._update_size(w, h)
Beispiel #12
0
    def _do_update(self, mode=None):
        # we absolutly want mode to update displaylist.
        if mode not in ('background', 'keys'):
            return

        # don't update background if it's already compiled
        if mode == 'background' and self._current_cache['background'].is_compiled():
            return

        # calculate margin
        s = self.scale
        w, h = self.container_width, self.container_height
        if mode == 'background':
            s = 1.
            w, h = self.size
        mtop, mright, mbottom, mleft = map(lambda x: x * s, self.style['margin'])
        self.texsize = Vector(w - mleft - mright,
                              h - mtop - mbottom)
        kx, ky = self.layout.SIZE
        self.keysize = Vector(self.texsize.x / kx, self.texsize.y / ky)
        m = 3 * s
        x, y = 0, self.texsize.y - self.keysize.y

        # update display list
        self._current_cache['usedlabel'] = []
        with self._current_cache[mode]:

            # draw lines
            for index in xrange(1, ky + 1):
                line = self.layout.__getattribute__('%s_%d' % (self.mode, index))

                # draw keys
                for key in line:
                    displayed_str, internal_str, internal_action, scale = key
                    kw = self.keysize.x * scale

                    # don't display empty keys
                    if displayed_str is not None:
                        set_color(*self.style['key-color'])
                        if mode == 'background':
                            if internal_action is not None:
                                set_color(*self.style['syskey-color'])
                            drawCSSRectangle(
                                pos=(x+m, y+m),
                                size=(kw-m*2, self.keysize.y-m*2),
                                style=self.style, prefix='key')
                        elif mode == 'keys':
                            font_size = int(14 * s)
                            if font_size < 8:
                                font_size = 8
                            color = self.style['color']
                            if internal_action is not None:
                                color = self.style['color-syskey']
                            drawLabel(label=displayed_str,
                                    pos=(x + kw / 2., y + self.keysize.y / 2.),
                                    font_size=font_size, bold=False,
                                    font_name=self.style.get('font-name'),
                                    color=color)
                            self._current_cache['usedlabel'].append(getLastLabel())
                    # advance X
                    x += kw
                # advance Y
                y -= self.keysize.y
                x = 0

        # update completed
        self._need_update = None
Beispiel #13
0
 def _draw_title(self, widget):
     if hasattr(widget, 'title'):
         y2 = self.center[1] - self.thumbnail_size[1] / 2.
         drawLabel(str(getattr(widget, 'title')),
                   pos=(self.center[0], y2 + self.title_position))
Beispiel #14
0
def _on_draw():
    global _toggle_state
    if _toggle_state == '':
        return

    win = getWindow()

    #
    # Show HELP screen
    #
    if _toggle_state == 'help':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        # prepare calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        y = 0
        k = {'font_size': 20}
        ydiff = 25

        # draw help
        drawLabel('PyMT Keybinding', pos=(w2, win.height - 100), font_size=40)
        drawLabel('Press F1 to leave help',
                  pos=(w2, win.height - 160),
                  font_size=12)
        drawLabel('FPS is %.3f' % getClock().get_fps(),
                  pos=(w2, win.height - 180),
                  font_size=12)
        drawLabel('F1 - Show Help', pos=(w2, h2), **k)
        y += ydiff
        drawLabel('F2 - Show FPS (%s)' % str(win.show_fps),
                  pos=(w2, h2 - y),
                  **k)
        y += ydiff
        drawLabel('F3 - Show Cache state', pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F4 - Show Calibration screen', pos=(w2, h2 - y), **k)
        if _can_fullscreen():
            y += ydiff
            drawLabel('F5 - Toggle fullscreen', pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F6 - Show log', pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F7 - Reload CSS', pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F8 - Show widget tree', pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F9 - Rotate the screen (%d)' % win.rotation,
                  pos=(w2, h2 - y),
                  **k)
        y += ydiff
        drawLabel('F12 - Screenshot', pos=(w2, h2 - y), **k)

        return True

    #
    # Draw cache state
    #
    elif _toggle_state == 'cachestat':
        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        y = 0
        for x in Cache._categories:
            y += 25
            cat = Cache._categories[x]
            count = 0
            usage = '-'
            limit = cat['limit']
            timeout = cat['timeout']
            try:
                count = len(Cache._objects[x])
            except:
                pass
            try:
                usage = 100 * count / limit
            except:
                pass
            args = (x, usage, count, limit, timeout)
            drawLabel('%s: usage=%s%% count=%d limit=%s timeout=%s' % args,
                      pos=(20, 20 + y),
                      font_size=20,
                      center=False,
                      nocache=True)

        return True

    #
    # Draw calibration screen
    #
    elif _toggle_state == 'calibration':
        step = 8
        ratio = win.height / float(win.width)
        stepx = win.width / step
        stepy = win.height / int(step * ratio)

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # draw lines
        set_color(1, 1, 1)
        for x in xrange(0, win.width, stepx):
            drawLine((x, 0, x, win.height))
        for y in xrange(0, win.height, stepy):
            drawLine((0, y, win.width, y))

        # draw circles
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=win.width / step,
                   linewidth=2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 2,
                   linewidth=2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 3,
                   linewidth=2.)

        return True

    #
    # Draw calibration screen 2 (colors)
    #
    elif _toggle_state == 'calibration2':

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # gray
        step = 25
        stepx = (win.width - 100) / step
        stepy = stepx * 2
        sizew = stepx * step
        sizeh = stepy * step
        w2 = win.width / 2.
        h2 = win.height / 2.
        for _x in xrange(step):
            x = w2 - sizew / 2. + _x * stepx
            drawLabel(chr(65 + _x), pos=(x + stepx / 2., h2 + 190))
            c = _x / float(step)

            # grey
            set_color(c, c, c)
            drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy))

            # red
            set_color(c, 0, 0)
            drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy))

            # green
            set_color(0, c, 0)
            drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy))

            # blue
            set_color(0, 0, c)
            drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy))
        return True

    #
    # Draw log screen
    #
    elif _toggle_state == 'log':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        # calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        k = {'font_size': 11, 'center': False}
        y = win.height - 20
        y = h2
        max = int((h2 / 20))
        levels = {
            logging.DEBUG: ('DEBUG', (.4, .4, 1)),
            logging.INFO: ('INFO', (.4, 1, .4)),
            logging.WARNING: ('WARNING', (1, 1, .4)),
            logging.ERROR: ('ERROR', (1, .4, .4)),
            logging.CRITICAL: ('CRITICAL', (1, .4, .4)),
        }

        # draw title
        drawLabel('PyMT logger', pos=(w2, win.height - 100), font_size=40)

        # draw logs
        for log in reversed(pymt_logger_history.history[:max]):
            levelname, color = levels[log.levelno]
            msg = log.message.split('\n')[0]
            x = 10
            s = drawLabel('[', pos=(x, y), **k)
            x += s[0]
            s = drawLabel(levelname, pos=(x, y), color=color, **k)
            x += s[0]
            s = drawLabel(']', pos=(x, y), **k)
            x += s[0]
            drawLabel(msg, pos=(100, y), **k)
            y -= 20
        return True
Beispiel #15
0
def _on_draw():
    global _toggle_state
    if _toggle_state == '':
        return

    win = getWindow()

    #
    # Show HELP screen
    #
    if _toggle_state == 'help':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        # prepare calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        k = {'font_size': 24}

        # draw help
        drawLabel('PyMT Keybinding',
                  pos=(w2, win.height - 100), font_size=40)
        drawLabel('Press F1 to leave help',
                  pos=(w2, win.height - 160), font_size=12)
        drawLabel('F1 - Show Help',
                  pos=(w2, h2), **k)
        drawLabel('F2 - Show FPS (%s)' % str(win.show_fps),
                  pos=(w2, h2 - 35), **k)
        drawLabel('F3 - Draw back gradient (%s)' % str(win.gradient),
                  pos=(w2, h2 - 70), **k)
        drawLabel('F4 - Show Calibration screen',
                  pos=(w2, h2 - 105), **k)
        drawLabel('F5 - Toggle fullscreen',
                  pos=(w2, h2 - 140), **k)
        drawLabel('F6 - Show log',
                  pos=(w2, h2 - 175), **k)

        return True

    # 
    # Draw calibration screen
    #
    elif _toggle_state == 'calibration':
        step = 8
        ratio = win.height / float(win.width)
        stepx = win.width / step
        stepy = win.height / int(step * ratio)

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # draw lines
        set_color(1, 1, 1)
        for x in xrange(0, win.width, stepx):
            drawLine((x, 0, x, win.height))
        for y in xrange(0, win.height, stepy):
            drawLine((0, y, win.width, y))

        # draw circles
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=win.width / step, linewidth = 2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 2, linewidth = 2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 3, linewidth = 2.)

        return True


    #
    # Draw calibration screen 2 (colors)
    #
    elif _toggle_state == 'calibration2':

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # gray
        step = 25
        stepx = (win.width - 100) / step
        stepy = stepx * 2
        sizew = stepx * step
        sizeh = stepy * step
        w2 = win.width / 2.
        h2 = win.height / 2.
        for _x in xrange(step):
            x = w2 - sizew / 2. + _x * stepx
            drawLabel(chr(65+_x), pos=(x + stepx / 2., h2 + 190))
            c = _x / float(step)

            # grey
            set_color(c, c, c)
            drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy))

            # red
            set_color(c, 0, 0)
            drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy))

            # green
            set_color(0, c, 0)
            drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy))

            # blue
            set_color(0, 0, c)
            drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy))
        return True


    #
    # Draw log screen
    #
    elif _toggle_state == 'log':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)


        # calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        k = {'font_size': 11, 'center': False}
        y = win.height - 20
        y = h2
        max = int((h2 / 20))
        levels = {
            logging.DEBUG:    ('DEBUG', (.4,.4,1)),
            logging.INFO:     ('INFO', (.4,1,.4)),
            logging.WARNING:  ('WARNING', (1,1,.4)),
            logging.ERROR:    ('ERROR', (1,.4,.4)),
            logging.CRITICAL: ('CRITICAL', (1,.4,.4)),
        }

        # draw title
        drawLabel('PyMT logger',
                  pos=(w2, win.height - 100), font_size=40)

        # draw logs
        for log in reversed(pymt_logger_history.history[:max]):
            levelname, color = levels[log.levelno]
            msg = log.message.split('\n')[0]
            x = 10
            x += drawLabel('[', pos=(x, y), **k)
            x += drawLabel(levelname, pos=(x, y), color=color, **k)
            x += drawLabel(']', pos=(x, y), **k)
            drawLabel(msg, pos=(100, y), **k)
            y -= 20
        return True
Beispiel #16
0
 def _draw_title(self, widget):
     if hasattr(widget, 'title'):
         y2 = self.center[1] - self.thumbnail_size[1] / 2.
         drawLabel(str(getattr(widget, 'title')),
                   pos=(self.center[0], y2 + self.title_position))
Beispiel #17
0
 def draw_value(self):
     drawLabel(self.value_format % (self.value), pos=self.center,
               **self.value_config)
Beispiel #18
0
    def _do_update(self, mode=None):
        # we absolutly want mode to update displaylist.
        if mode not in ('background', 'keys'):
            return

        # don't update background if it's already compiled
        if mode == 'background' and self._current_cache['background'].is_compiled():
            return

        # calculate margin
        s = self.scale
        w, h = self.container_width, self.container_height
        if mode == 'background':
            s = 1.
            w, h = self.size
        mtop, mright, mbottom, mleft = map(lambda x: x * s, self.style['margin'])
        self.texsize = Vector(w - mleft - mright,
                              h - mtop - mbottom)
        kx, ky = self.layout.SIZE
        self.keysize = Vector(self.texsize.x / kx, self.texsize.y / ky)
        m = 3 * s
        x, y = 0, self.texsize.y - self.keysize.y

        # update display list
        self._current_cache['usedlabel'] = []
        with self._current_cache[mode]:

            # draw lines
            for index in xrange(1, ky + 1):
                line = self.layout.__getattribute__('%s_%d' % (self.mode, index))

                # draw keys
                for key in line:
                    displayed_str, internal_str, internal_action, scale = key
                    kw = self.keysize.x * scale

                    # don't display empty keys
                    if displayed_str is not None:
                        set_color(*self.style['key-color'])
                        if mode == 'background':
                            if internal_action is not None:
                                set_color(*self.style['syskey-color'])
                            drawCSSRectangle(
                                pos=(x+m, y+m),
                                size=(kw-m*2, self.keysize.y-m*2),
                                style=self.style, prefix='key')
                        elif mode == 'keys':
                            font_size = int(14 * s)
                            if font_size < 8:
                                font_size = 8
                            color = self.style['color']
                            if internal_action is not None:
                                color = self.style['color-syskey']
                            drawLabel(label=displayed_str,
                                    pos=(x + kw / 2., y + self.keysize.y / 2.),
                                    font_size=font_size, bold=False,
                                    font_name=self.style.get('font-name'),
                                    color=color)
                            self._current_cache['usedlabel'].append(getLastLabel())
                    # advance X
                    x += kw
                # advance Y
                y -= self.keysize.y
                x = 0

        # update completed
        self._need_update = None
Beispiel #19
0
def _on_draw():
    global _toggle_state
    if _toggle_state == '':
        return

    win = getWindow()

    #
    # Show HELP screen
    #
    if _toggle_state == 'help':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        # prepare calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        y = 0
        k = {'font_size': 20}
        ydiff = 25

        # draw help
        drawLabel('PyMT Keybinding',
                  pos=(w2, win.height - 100), font_size=40)
        drawLabel('Press F1 to leave help',
                  pos=(w2, win.height - 160), font_size=12)
        drawLabel('FPS is %.3f' % getClock().get_fps(),
                  pos=(w2, win.height - 180), font_size=12)
        drawLabel('F1 - Show Help',
                  pos=(w2, h2), **k)
        y += ydiff
        drawLabel('F2 - Show FPS (%s)' % str(win.show_fps),
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F3 - Show Cache state',
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F4 - Show Calibration screen',
                  pos=(w2, h2 - y), **k)
        if _can_fullscreen():
            y += ydiff
            drawLabel('F5 - Toggle fullscreen',
                      pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F6 - Show log',
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F7 - Reload CSS',
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F8 - Show widget tree',
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F9 - Rotate the screen (%d)' % win.rotation,
                  pos=(w2, h2 - y), **k)
        y += ydiff
        drawLabel('F12 - Screenshot',
                  pos=(w2, h2 - y), **k)

        return True

    #
    # Draw cache state
    #
    elif _toggle_state == 'cachestat':
        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)

        y = 0
        for x in Cache._categories:
            y += 25
            cat = Cache._categories[x]
            count = 0
            usage = '-'
            limit = cat['limit']
            timeout = cat['timeout']
            try:
                count = len(Cache._objects[x])
            except:
                pass
            try:
                usage = 100 * count / limit
            except:
                pass
            args = (x, usage, count, limit, timeout)
            drawLabel('%s: usage=%s%% count=%d limit=%s timeout=%s' % args,
                      pos=(20, 20 + y), font_size=20, center=False, nocache=True)

        return True

    #
    # Draw calibration screen
    #
    elif _toggle_state == 'calibration':
        step = 8
        ratio = win.height / float(win.width)
        stepx = win.width / step
        stepy = win.height / int(step * ratio)

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # draw lines
        set_color(1, 1, 1)
        for x in xrange(0, win.width, stepx):
            drawLine((x, 0, x, win.height))
        for y in xrange(0, win.height, stepy):
            drawLine((0, y, win.width, y))

        # draw circles
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=win.width / step, linewidth = 2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 2, linewidth = 2.)
        drawCircle(pos=(win.width / 2., win.height / 2.),
                   radius=(win.width / step) * 3, linewidth = 2.)

        return True


    #
    # Draw calibration screen 2 (colors)
    #
    elif _toggle_state == 'calibration2':

        # draw black background
        set_color(0, 0, 0)
        drawRectangle(size=win.size)

        # gray
        step = 25
        stepx = (win.width - 100) / step
        stepy = stepx * 2
        sizew = stepx * step
        sizeh = stepy * step
        w2 = win.width / 2.
        h2 = win.height / 2.
        for _x in xrange(step):
            x = w2 - sizew / 2. + _x * stepx
            drawLabel(chr(65+_x), pos=(x + stepx / 2., h2 + 190))
            c = _x / float(step)

            # grey
            set_color(c, c, c)
            drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy))

            # red
            set_color(c, 0, 0)
            drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy))

            # green
            set_color(0, c, 0)
            drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy))

            # blue
            set_color(0, 0, c)
            drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy))
        return True


    #
    # Draw log screen
    #
    elif _toggle_state == 'log':

        # draw the usual window
        win.on_draw()

        # make background more black
        set_color(0, 0, 0, .8)
        drawRectangle(size=win.size)


        # calculation
        w2 = win.width / 2.
        h2 = win.height / 2.
        k = {'font_size': 11, 'center': False}
        y = win.height - 20
        y = h2
        max = int((h2 / 20))
        levels = {
            logging.DEBUG:    ('DEBUG', (.4,.4,1)),
            logging.INFO:     ('INFO', (.4,1,.4)),
            logging.WARNING:  ('WARNING', (1,1,.4)),
            logging.ERROR:    ('ERROR', (1,.4,.4)),
            logging.CRITICAL: ('CRITICAL', (1,.4,.4)),
        }

        # draw title
        drawLabel('PyMT logger',
                  pos=(w2, win.height - 100), font_size=40)

        # draw logs
        for log in reversed(pymt_logger_history.history[:max]):
            levelname, color = levels[log.levelno]
            msg = log.message.split('\n')[0]
            x = 10
            s = drawLabel('[', pos=(x, y), **k)
            x += s[0]
            s = drawLabel(levelname, pos=(x, y), color=color, **k)
            x += s[0]
            s = drawLabel(']', pos=(x, y), **k)
            x += s[0]
            drawLabel(msg, pos=(100, y), **k)
            y -= 20
        return True