def draw(self): if self.selected: set_color(1, 0, 0, 0.3) drawRectangle(self.to_widget(*self.widget.pos), self.widget.size) set_color(1, .3, 0) for c in self.child_layout.children: drawLine((self.node_btn.centerright, c.node_btn.centerleft), width=2)
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('Kivy 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' % Clock.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('Kivy logger', pos=(w2, win.height - 100), font_size=40) # draw logs for log in reversed(kivy_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