Python kivy.graphics.Rectangle() Examples

The following are 29 code examples of kivy.graphics.Rectangle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kivy.graphics , or try the search function .
Example #1
Source File: touchring.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _mouse_move(win, pos, *args):
    global cursor_size
    if hasattr(win, '_cursor'):
        c = win._cursor
    else:
        with win.canvas.after:
            img = Image(cursor_image)
            Color(1, 1, 1, 1, mode='rgba')
            size = (
                cursor_size[0] or img.texture.size[0],
                cursor_size[1] or img.texture.size[1]
            )
            print(size)
            win._cursor = c = Rectangle(texture=img.texture,
                                        size=size)

    c.pos = pos[0] + cursor_offset[0], pos[1] - c.size[1] + cursor_offset[1] 
Example #2
Source File: labels.py    From kivy-material-ui with MIT License 6 votes vote down vote up
def on_touch_move( self, touch ) :
        if self._touched :
            self._d = touch.pos
            self._hover_size, self._hover_pos = self._get_hover()

            if self.root_layout :
                self._clear_canvas()

                with self.root_layout.canvas :
                    kg.Color( *self.hover_color, **self._unique_group )
                    kg.Rectangle( 
                        size=self._hover_size, \
                        pos=self._hover_pos, \
                        **self._unique_group 
                    )
            return True 
Example #3
Source File: textinput.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _refresh_hint_text(self):
        _lines, self._hint_text_flags = self._split_smart(self.hint_text)
        _hint_text_labels = []
        _hint_text_rects = []
        _create_label = self._create_line_label

        for x in _lines:
            lbl = _create_label(x, hint=True)
            _hint_text_labels.append(lbl)
            _hint_text_rects.append(Rectangle(size=lbl.size))

        self._hint_text_lines = _lines
        self._hint_text_labels = _hint_text_labels
        self._hint_text_rects = _hint_text_rects

        # Remember to update graphics
        self._trigger_update_graphics()

    #
    # Properties
    # 
Example #4
Source File: gesturesurface.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def init_gesture(self, touch):
        '''Create a new gesture from touch, ie it's the first on
        surface, or was not close enough to any existing gesture (yet)'''
        col = self.color
        if self.use_random_color is True:
            col = hsv_to_rgb(random(), 1., 1.)

        g = GestureContainer(touch, max_strokes=self.max_strokes,
                             line_width=self.line_width, color=col)

        # Create the bounding box Rectangle for the gesture
        if self.draw_bbox:
            bb = g.bbox
            with self.canvas:
                Color(col[0], col[1], col[2], self.bbox_alpha, mode='rgba',
                      group=g.id)

                g._bbrect = Rectangle(
                    group=g.id,
                    pos=(bb['minx'], bb['miny']),
                    size=(bb['maxx'] - bb['minx'],
                          bb['maxy'] - bb['miny']))

        self._gestures.append(g)
        return g 
Example #5
Source File: touchring.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _mouse_move(win, pos, *args):
    global cursor_size
    if hasattr(win, '_cursor'):
        c = win._cursor
    else:
        with win.canvas.after:
            img = Image(cursor_image)
            Color(1, 1, 1, 1, mode='rgba')
            size = (
                cursor_size[0] or img.texture.size[0],
                cursor_size[1] or img.texture.size[1]
            )
            print(size)
            win._cursor = c = Rectangle(texture=img.texture,
                                        size=size)

    c.pos = pos[0] + cursor_offset[0], pos[1] - c.size[1] + cursor_offset[1] 
Example #6
Source File: touchring.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _touch_down(win, touch):
    ud = touch.ud
    touch.scale_for_screen(win.width, win.height)
    with win.canvas.after:
        ud['tr.color'] = Color(1, 1, 1, pointer_alpha)
        iw, ih = pointer_image.size
        ud['tr.rect'] = Rectangle(
            pos=(
                touch.x - (pointer_image.width / 2. * pointer_scale),
                touch.y - (pointer_image.height / 2. * pointer_scale)),
            size=(iw * pointer_scale, ih * pointer_scale),
            texture=pointer_image.texture)

    if not ud.get('tr.grab', False):
        ud['tr.grab'] = True
        touch.grab(win) 
Example #7
Source File: monitor.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def start(win, ctx):
    # late import to avoid breaking module loading
    from kivy.input.postproc import kivy_postproc_modules
    kivy_postproc_modules['fps'] = StatsInput()
    global _ctx
    ctx.label = Label(text='FPS: 0.0')
    ctx.inputstats = 0
    ctx.stats = []
    ctx.statsr = []
    with win.canvas.after:
        ctx.color = Color(1, 0, 0, .5)
        ctx.rectangle = Rectangle(pos=(0, win.height - 25),
                                  size=(win.width, 25))
        ctx.color = Color(1, 1, 1)
        ctx.rectangle = Rectangle(pos=(5, win.height - 20))
        ctx.color = Color(1, 1, 1, .5)
        for x in range(64):
            ctx.stats.append(0)
            ctx.statsr.append(
                Rectangle(pos=(win.width - 64 * 4 + x * 4, win.height - 25),
                          size=(4, 0)))
    Clock.schedule_interval(partial(update_fps, ctx), .5)
    Clock.schedule_interval(partial(update_stats, ctx), 1 / 60.) 
Example #8
Source File: textinput.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _refresh_hint_text(self):
        _lines, self._hint_text_flags = self._split_smart(self.hint_text)
        _hint_text_labels = []
        _hint_text_rects = []
        _create_label = self._create_line_label

        for x in _lines:
            lbl = _create_label(x, hint=True)
            _hint_text_labels.append(lbl)
            _hint_text_rects.append(Rectangle(size=lbl.size))

        self._hint_text_lines = _lines
        self._hint_text_labels = _hint_text_labels
        self._hint_text_rects = _hint_text_rects

        # Remember to update graphics
        self._trigger_update_graphics()

    #
    # Properties
    # 
Example #9
Source File: gesturesurface.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def init_gesture(self, touch):
        '''Create a new gesture from touch, ie it's the first on
        surface, or was not close enough to any existing gesture (yet)'''
        col = self.color
        if self.use_random_color is True:
            col = hsv_to_rgb(random(), 1., 1.)

        g = GestureContainer(touch, max_strokes=self.max_strokes,
                             line_width=self.line_width, color=col)

        # Create the bounding box Rectangle for the gesture
        if self.draw_bbox:
            bb = g.bbox
            with self.canvas:
                Color(col[0], col[1], col[2], self.bbox_alpha, mode='rgba',
                      group=g.id)

                g._bbrect = Rectangle(
                    group=g.id,
                    pos=(bb['minx'], bb['miny']),
                    size=(bb['maxx'] - bb['minx'],
                          bb['maxy'] - bb['miny']))

        self._gestures.append(g)
        return g 
Example #10
Source File: touchring.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _touch_down(win, touch):
    ud = touch.ud
    touch.scale_for_screen(win.width, win.height)
    with win.canvas.after:
        ud['tr.color'] = Color(1, 1, 1, pointer_alpha)
        iw, ih = pointer_image.size
        ud['tr.rect'] = Rectangle(
            pos=(
                touch.x - (pointer_image.width / 2. * pointer_scale),
                touch.y - (pointer_image.height / 2. * pointer_scale)),
            size=(iw * pointer_scale, ih * pointer_scale),
            texture=pointer_image.texture)

    if not ud.get('tr.grab', False):
        ud['tr.grab'] = True
        touch.grab(win) 
Example #11
Source File: monitor.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def start(win, ctx):
    # late import to avoid breaking module loading
    from kivy.input.postproc import kivy_postproc_modules
    kivy_postproc_modules['fps'] = StatsInput()
    global _ctx
    ctx.label = Label(text='FPS: 0.0')
    ctx.inputstats = 0
    ctx.stats = []
    ctx.statsr = []
    with win.canvas.after:
        ctx.color = Color(1, 0, 0, .5)
        ctx.rectangle = Rectangle(pos=(0, win.height - 25),
                                  size=(win.width, 25))
        ctx.color = Color(1, 1, 1)
        ctx.rectangle = Rectangle(pos=(5, win.height - 20))
        ctx.color = Color(1, 1, 1, .5)
        for x in range(64):
            ctx.stats.append(0)
            ctx.statsr.append(
                Rectangle(pos=(win.width - 64 * 4 + x * 4, win.height - 25),
                          size=(4, 0)))
    Clock.schedule_interval(partial(update_fps, ctx), .5)
    Clock.schedule_interval(partial(update_stats, ctx), 1 / 60.) 
Example #12
Source File: modal_cursor.py    From kivystudio with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        super(ResizeCursor, self).__init__(**kwargs)
        self.size_hint = (None, None)
        self.pos_hint = (None, None)
        self.source = ''
        self.rect = Rectangle(pos=(-9998,-9998), size=(1, 1))
        self.size = (dp(22), dp(22))
        self.pos = [-9998, -9998]

        # Makes an instruction group with a rectangle and
        # loads an image inside it
        # Binds its properties to mouse positional changes and events triggered
        instr = InstructionGroup()
        instr.add(self.rect)
        self.canvas.after.add(instr)
        self.bind(pos=lambda obj, val: setattr(self.rect, 'pos', val))
        self.bind(source=lambda obj, val: setattr(self.rect, 'source', val))
        self.bind(hidden=lambda obj, val: self.on_mouse_move(Window.mouse_pos))
        Window.bind(mouse_pos=lambda obj, val: self.on_mouse_move(val)) 
Example #13
Source File: modal_cursor.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, **kwargs):
        super(ResizeCursor, self).__init__(**kwargs)
        self.size_hint = (None, None)
        self.pos_hint = (None, None)
        self.source = ''
        self.rect = Rectangle(pos=(-9998,-9998), size=(1, 1))
        self.size = (dp(22), dp(22))
        self.pos = [-9998, -9998]

        # Makes an instruction group with a rectangle and
        # loads an image inside it
        # Binds its properties to mouse positional changes and events triggered
        instr = InstructionGroup()
        instr.add(self.rect)
        self.canvas.after.add(instr)
        self.bind(pos=lambda obj, val: setattr(self.rect, 'pos', val))
        self.bind(source=lambda obj, val: setattr(self.rect, 'source', val))
        self.bind(hidden=lambda obj, val: self.on_mouse_move(Window.mouse_pos))
        Window.bind(mouse_pos=lambda obj, val: self.on_mouse_move(val)) 
Example #14
Source File: backend_kivy.py    From garden.matplotlib with MIT License 6 votes vote down vote up
def draw_rubberband(self, event, x0, y0, x1, y1):
        w = abs(x1 - x0)
        h = abs(y1 - y0)
        rect = [int(val)for val in (min(x0, x1) + self.canvas.x, min(y0, y1)
                        + self.canvas.y, w, h)]
        if self.lastrect is None:
            self.canvas.canvas.add(Color(*self.rubberband_color))
        else:
            self.canvas.canvas.remove(self.lastrect)
        self.lastrect = InstructionGroup()
        self.lastrect.add(Line(rectangle=rect, width=1.0, dash_length=5.0,
                dash_offset=5.0))
        self.lastrect.add(Color(1.0, 0.0, 0.0, 0.2))
        self.lastrect.add(Rectangle(pos=(rect[0], rect[1]),
                                    size=(rect[2], rect[3])))
        self.canvas.canvas.add(self.lastrect) 
Example #15
Source File: backend_kivy.py    From garden.matplotlib with MIT License 6 votes vote down vote up
def draw_mathtext(self, gc, x, y, s, prop, angle):
        '''Draw the math text using matplotlib.mathtext. The position
           x,y is given in Kivy coordinates.
        '''
        ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
        w = ftimage.get_width()
        h = ftimage.get_height()
        texture = Texture.create(size=(w, h))
        if _mpl_ge_1_5:
            texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba',
                                bufferfmt='ubyte')
        else:
            texture.blit_buffer(ftimage.as_rgba_str(), colorfmt='rgba',
                                bufferfmt='ubyte')
        texture.flip_vertical()
        with self.widget.canvas:
            Rectangle(texture=texture, pos=(x, y), size=(w, h)) 
Example #16
Source File: __init__.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def create_drawings(self):
        self._image = Rectangle()
        self._color = Color([1, 1, 1, 1])
        self.bind(color=lambda instr, value: setattr(self._color, 'rgba', value))
        return [self._color, self._image] 
Example #17
Source File: __init__.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def create_drawings(self):
        self._image = Rectangle()
        self._color = Color([1, 1, 1, 1])
        self.bind(color=lambda instr, value: setattr(self._color, 'rgba', value))
        return [self._color, self._image] 
Example #18
Source File: __init__.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        with self.canvas:
            self._fbo = Fbo(size=self.size)
            self._marker_color = Color(self.marker_color)
            self._marker = Line()

        with self._fbo:
            self._background_color = Color(*self.background_color)
            self._background_rect = Rectangle(size=self.size)
            self._mesh_ticks_color = Color(*self.tick_color)
            self._mesh_ticks = Mesh(mode='lines')
            self._mesh_rect_color = Color(*self.border_color)
            self._mesh_rect = Mesh(mode='line_strip')

        with self.canvas:
            Color(1, 1, 1)
            self._fbo_rect = Rectangle(size=self.size)

        mesh = self._mesh_rect
        mesh.vertices = [0] * (5 * 4)
        mesh.indices = range(5)

        self._plot_area = StencilView()
        self.add_widget(self._plot_area)

        t = self._trigger = Clock.create_trigger(self._redraw_all)
        ts = self._trigger_size = Clock.create_trigger(self._redraw_size)
        tc = self._trigger_color = Clock.create_trigger(self._update_colors)

        self.bind(center=ts, padding=ts, precision=ts, plots=ts, x_grid=ts,
                  y_grid=ts, draw_border=ts)
        self.bind(xmin=t, xmax=t, xlog=t, x_ticks_major=t, x_ticks_minor=t,
                  xlabel=t, x_grid_label=t, ymin=t, ymax=t, ylog=t,
                  y_ticks_major=t, y_ticks_minor=t, ylabel=t, y_grid_label=t,
                  font_size=t, label_options=t)
        self.bind(tick_color=tc, background_color=tc, border_color=tc)
        self._trigger() 
Example #19
Source File: __init__.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def get_rect_instruction(self):

        for i in self.layout.canvas.after.children:
            if isinstance(i, Rectangle):
                return i 
Example #20
Source File: textinput.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def _draw_selection(self, *largs):
        pos, size, line_num, (s1c, s1r), (s2c, s2r),\
            _lines, _get_text_width, tab_width, _label_cached, width,\
            padding_left, padding_right, x, canvas_add, selection_color = largs
        # Draw the current selection on the widget.
        if line_num < s1r or line_num > s2r:
            return
        x, y = pos
        w, h = size
        x1 = x
        x2 = x + w
        if line_num == s1r:
            lines = _lines[line_num]
            x1 -= self.scroll_x
            x1 += _get_text_width(lines[:s1c], tab_width, _label_cached)
        if line_num == s2r:
            lines = _lines[line_num]
            x2 = (x - self.scroll_x) + _get_text_width(lines[:s2c],
                                                       tab_width,
                                                       _label_cached)
        width_minus_padding = width - (padding_right + padding_left)
        maxx = x + width_minus_padding
        if x1 > maxx:
            return
        x1 = max(x1, x)
        x2 = min(x2, x + width_minus_padding)
        canvas_add(Color(*selection_color, group='selection'))
        canvas_add(Rectangle(
            pos=(x1, pos[1]), size=(x2 - x1, size[1]), group='selection')) 
Example #21
Source File: viewer.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def start_cursor(self, x, y):
        tx, ty = self.transform_to_wpos(x, y)
        label = CoreLabel(text="{:1.2f},{:1.2f}".format(tx, ty))
        label.refresh()
        texture = label.texture
        px, py = (x, y)
        with self.ids.surface.canvas.after:
            Color(0, 0, 1, mode='rgb', group='cursor_group')
            self.crossx = [
                Rectangle(pos=(px, 0), size=(1, self.height), group='cursor_group'),
                Rectangle(pos=(0, py), size=(self.width, 1), group='cursor_group'),
                Line(circle=(px, py, 20), group='cursor_group'),
                Rectangle(texture=texture, pos=(px - texture.size[0] / 2, py - 40), size=texture.size, group='cursor_group')
            ] 
Example #22
Source File: backend_kivyagg.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def draw(self):
        '''
        Draw the figure using the agg renderer
        '''
        self.canvas.clear()
        FigureCanvasAgg.draw(self)
        if self.blitbox is None:
            l, b, w, h = self.figure.bbox.bounds
            w, h = int(w), int(h)
            buf_rgba = self.get_renderer().buffer_rgba()
        else:
            bbox = self.blitbox
            l, b, r, t = bbox.extents
            w = int(r) - int(l)
            h = int(t) - int(b)
            t = int(b) + h
            reg = self.copy_from_bbox(bbox)
            buf_rgba = reg.to_string()
        texture = Texture.create(size=(w, h))
        texture.flip_vertical()
        color = self.figure.get_facecolor()
        with self.canvas:
            Color(*color)
            Rectangle(pos=self.pos, size=(w, h))
            Color(1.0, 1.0, 1.0, 1.0)
            self.img_rect = Rectangle(texture=texture, pos=self.pos,
                                      size=(w, h))
        texture.blit_buffer(bytes(buf_rgba), colorfmt='rgba', bufferfmt='ubyte')
        self.img_texture = texture 
Example #23
Source File: __init__.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        with self.canvas:
            self._fbo = Fbo(size=self.size, with_stencilbuffer=self._with_stencilbuffer)

        with self._fbo:
            self._background_color = Color(*self.background_color)
            self._background_rect = Rectangle(size=self.size)
            self._mesh_ticks_color = Color(*self.tick_color)
            self._mesh_ticks = Mesh(mode='lines')
            self._mesh_rect_color = Color(*self.border_color)
            self._mesh_rect = Mesh(mode='line_strip')

        with self.canvas:
            Color(1, 1, 1)
            self._fbo_rect = Rectangle(size=self.size, texture=self._fbo.texture)

        mesh = self._mesh_rect
        mesh.vertices = [0] * (5 * 4)
        mesh.indices = range(5)

        self._plot_area = StencilView()
        self.add_widget(self._plot_area)

        t = self._trigger = Clock.create_trigger(self._redraw_all)
        ts = self._trigger_size = Clock.create_trigger(self._redraw_size)
        tc = self._trigger_color = Clock.create_trigger(self._update_colors)

        self.bind(center=ts, padding=ts, precision=ts, plots=ts, x_grid=ts,
                  y_grid=ts, draw_border=ts)
        self.bind(xmin=t, xmax=t, xlog=t, x_ticks_major=t, x_ticks_minor=t,
                  xlabel=t, x_grid_label=t, ymin=t, ymax=t, ylog=t,
                  y_ticks_major=t, y_ticks_minor=t, ylabel=t, y_grid_label=t,
                  font_size=t, label_options=t, x_ticks_angle=t)
        self.bind(tick_color=tc, background_color=tc, border_color=tc)
        self._trigger() 
Example #24
Source File: highlightbehavior.py    From kivystudio with MIT License 5 votes vote down vote up
def redraw_canvas(self, *args):
        if self.current_highlighted_child:
            self.instruction_canvas.clear()
            self.instruction_canvas.add(Color(*self.highlighted_color))

            if self.highlighted_shape =='rectangle':
                self.instruction_canvas.add(Rectangle(pos=self.current_highlighted_child.pos, size=self.current_highlighted_child.size))
            elif self.highlighted_shape =='rounded_rectangle':
                self.instruction_canvas.add(RoundedRectangle(pos=self.current_highlighted_child.pos, size=self.current_highlighted_child.size))
            else:
                raise Exception('Invalid highlighted shape {}'.format(self.highlighted_shape)) 
Example #25
Source File: backend_kivy.py    From garden.matplotlib with MIT License 4 votes vote down vote up
def draw_image(self, gc, x, y, im):
        '''Render images that can be displayed on a matplotlib figure.
           These images are generally called using imshow method from pyplot.
           A Texture is applied to the FigureCanvas. The position x, y is
           given in matplotlib coordinates.
        '''
        # Clip path to define an area to mask.
        clippath, clippath_trans = gc.get_clip_path()
        # Normal coordinates calculated and image added.
        x = self.widget.x + x
        y = self.widget.y + y
        bbox = gc.get_clip_rectangle()
        if bbox is not None:
            l, b, w, h = bbox.bounds
        else:
            l = 0
            b = 0
            w = self.widget.width
            h = self.widget.height
        h, w = im.get_size_out()
        rows, cols, image_str = im.as_rgba_str()
        texture = Texture.create(size=(w, h))
        texture.blit_buffer(image_str, colorfmt='rgba', bufferfmt='ubyte')
        if clippath is None:
            with self.widget.canvas:
                Color(1.0, 1.0, 1.0, 1.0)
                Rectangle(texture=texture, pos=(x, y), size=(w, h))
        else:
            if _mpl_ge_2_0:
                polygons = clippath.to_polygons(clippath_trans, closed_only=False)
            else:
                polygons = clippath.to_polygons(clippath_trans)
            list_canvas_instruction = self.get_path_instructions(gc, polygons,
                                                rgbFace=(1.0, 1.0, 1.0, 1.0))
            for widget, instructions in list_canvas_instruction:
                widget.canvas.add(StencilPush())
                widget.canvas.add(instructions)
                widget.canvas.add(StencilUse())
                widget.canvas.add(Color(1.0, 1.0, 1.0, 1.0))
                widget.canvas.add(Rectangle(texture=texture,
                                            pos=(x, y), size=(w, h)))
                widget.canvas.add(StencilUnUse())
                widget.canvas.add(StencilPop()) 
Example #26
Source File: dial-gauge.py    From kivy-smoothie-host with GNU General Public License v3.0 4 votes vote down vote up
def draw_ticks(self):
        scangle = self.angle_stop - self.angle_start
        inc = scangle / ((self.scale_max - self.scale_min) / self.scale_increment)
        inc /= self.tic_frequency
        cnt = 0

        # create an instruction group so we can remove it and recall draw_ticks to update when pos or size changes
        self.ticks = InstructionGroup()

        self.ticks.add(Color(*self.tic_color))

        labi = self.scale_min
        x = -180.0 + self.angle_start + self.angle_offset  # start
        while x <= self.angle_stop - 180 + self.angle_offset:
            a = x if(x < 0.0) else x + 360.0

            need_label = True
            ticlen = self.tic_length

            if(cnt % self.tic_frequency != 0):
                ticlen = self.tic_length / 2
                need_label = False

            cnt += 1

            self.ticks.add(PushMatrix())
            self.ticks.add(Rotate(angle=a, axis=(0, 0, -1), origin=(self.dial_center[0], self.dial_center[1])))
            self.ticks.add(Translate(0, self.tic_radius - ticlen))
            self.ticks.add(Line(points=[self.dial_center[0], self.dial_center[1], self.dial_center[0], self.dial_center[1] + ticlen], width=self.tic_width, cap='none', joint='none'))

            if need_label:
                # print("label: " + str(labi))
                # kw['font_size'] = self.tic_length * 2
                label = CoreLabel(text=str(int(round(labi))), font_size=self.scale_font_size)
                label.refresh()
                texture = label.texture
                self.ticks.add(Translate(-texture.size[0] / 2, -texture.size[1] - 2))
                self.ticks.add(Rectangle(texture=texture, pos=self.dial_center, size=texture.size))
                labi += self.scale_increment

            self.ticks.add(PopMatrix())
            x += inc

        self.canvas.add(self.ticks) 
Example #27
Source File: core.py    From pypercard with MIT License 4 votes vote down vote up
def screen(self, screen_manager, data_store):
        """
        Return a screen instance containing all the necessary UI items that
        have been associated with the expected event handlers.

        :param kivy.uix.screenmanager.ScreenManager screen_manager: The UI
            stack of screens which controls which card is to be displayed.
        :param dict data_store: A dictionary containing application state.
        :return: A graphical representation of the card.
        """
        # References to app related objects.
        self.screen_manager = screen_manager
        self.data_store = data_store
        # The Kivy Screen instance used to draw the UI.
        screen = Screen(name=self.title)
        # Bind event handlers to life-cycle events.
        screen.bind(on_enter=self._enter)
        screen.bind(on_pre_enter=self._pre_enter)
        screen.bind(on_pre_leave=self._leave)
        # The main layout that defines how UI elements are drawn.
        self.layout = BoxLayout(orientation="vertical")
        screen.add_widget(self.layout)
        # The sound player for this card.
        self.player = None
        # Text font size for the Screen instance.
        self.font_size = "{}sp".format(self.text_size)
        if self.form:
            self._draw_form()
        elif self.text:
            self._draw_text()
        else:
            # For padding purposes.
            self.layout.add_widget(Label(text=" "))
        if self.sound:
            self.player = SoundLoader.load(self.sound)
            self.player.loop = self.sound_repeat
        if self.background:
            self.layout.bind(size=self._update_rect, pos=self._update_rect)
            with self.layout.canvas.before:
                if isinstance(self.background, tuple):
                    Color(*self.background)
                    self.rect = Rectangle(
                        size=self.layout.size, pos=self.layout.pos
                    )
                else:
                    self.rect = Rectangle(
                        source=self.background,
                        size=self.layout.size,
                        pos=self.layout.pos,
                    )
        if self.buttons:
            self._draw_buttons()
        return screen 
Example #28
Source File: textinput.py    From Tickeys-linux with MIT License 4 votes vote down vote up
def _refresh_text(self, text, *largs):
        # Refresh all the lines from a new text.
        # By using cache in internal functions, this method should be fast.
        mode = 'all'
        if len(largs) > 1:
            mode, start, finish, _lines, _lines_flags, len_lines = largs
            #start = max(0, start)
            cursor = None
        else:
            cursor = self.cursor_index()
            _lines, self._lines_flags = self._split_smart(text)
        _lines_labels = []
        _line_rects = []
        _create_label = self._create_line_label

        for x in _lines:
            lbl = _create_label(x)
            _lines_labels.append(lbl)
            _line_rects.append(Rectangle(size=lbl.size))

        if mode == 'all':
            self._lines_labels = _lines_labels
            self._lines_rects = _line_rects
            self._lines = _lines
        elif mode == 'del':
            if finish > start:
                self._insert_lines(start,
                                   finish if start == finish else (finish + 1),
                                   len_lines, _lines_flags,
                                   _lines, _lines_labels, _line_rects)
        elif mode == 'insert':
            self._insert_lines(
                start,
                finish if (start == finish and not len_lines)
                else (finish + 1),
                len_lines, _lines_flags, _lines, _lines_labels,
                _line_rects)

        min_line_ht = self._label_cached.get_extents('_')[1]
        # with markup texture can be of height `1`
        self.line_height = max(_lines_labels[0].height, min_line_ht)
        #self.line_spacing = 2
        # now, if the text change, maybe the cursor is not at the same place as
        # before. so, try to set the cursor on the good place
        row = self.cursor_row
        self.cursor = self.get_cursor_from_index(self.cursor_index()
                                                 if cursor is None else cursor)
        # if we back to a new line, reset the scroll, otherwise, the effect is
        # ugly
        if self.cursor_row != row:
            self.scroll_x = 0
        # with the new text don't forget to update graphics again
        self._trigger_update_graphics() 
Example #29
Source File: fbowidget.py    From kivy3dgui with MIT License 4 votes vote down vote up
def __init__(self, **kwargs):
        self.canvas = Canvas()
        with self.canvas.before:
            Callback(self._set_blend_func)
        #self.size
        self.fbo_texture = Texture.create(size=self.size,
                                          colorfmt='rgba')

        self.fbo_texture.mag_filter = 'linear'
        self.fbo_texture.min_filter = 'linear'

        with self.canvas:
            #self.cbs = Callback(self.prepare_canvas)
           
            self.fbo = Fbo(size=self.size, texture=self.fbo_texture)
            #Color(0, 0, 0, 1)
            #self.fbo_rect = Rectangle(size=self.size)            


        with self.fbo:
            ClearColor(0.0, 0.0, 0.0, 1.0)
            ClearBuffers()
            self.fbo_rect = Rectangle(size=self.size)


        #self.fbo.shader.source = resource_find('./kivy3dgui/gles2.0/shaders/invert.glsl')
        #with self.fbo.after:
        #    self.cbr = Callback(self.reset_gl_context)
        #    PopMatrix()

        with self.canvas.before:
            Callback(self._set_blend_func)

        # wait that all the instructions are in the canvas to set texture

        self.texture = self.fbo.texture
        try:
            self.size = kwargs.pop("size")
            self.size_hint = kwargs.pop("size_hint")
            self.clear_color = kwargs.pop("clear_color")
            super(FboFloatLayout, self).__init__(**kwargs)
        except:
            print(kwargs)