def init_stroke(self, g, touch):
        l = [touch.x, touch.y]
        col = g.color

        new_line = Line(points=l, width=self.line_width, group=g.id)
        g._strokes[str(touch.uid)] = new_line

        if self.line_width:
            canvas_add = self.canvas.add
            canvas_add(Color(col[0], col[1], col[2], mode='rgb', group=g.id))
            canvas_add(new_line)

        # Update the bbox in case; this will normally be done in on_touch_move,
        # but we want to update it also for a single press, force that here:
        g.update_bbox(touch)
        if self.draw_bbox:
            self._update_canvas_bbox(g)

        # Register the stroke in GestureContainer so we can look it up later
        g.add_stroke(touch, new_line)
 def _drawLine(self, preValue, aValue, dispIdx, isLastFlag):
     """
     繪製曲線
     """
     groupStr = self.instGroup
     if isLastFlag == True:
         groupStr += "_lastData"
     else:
         groupStr += "_curvData"    
     instg = InstructionGroup(group=groupStr)
     color = Color()
     color.rgba = self.CURV_COLOR
     instg.add(color)
     #(self.tickWide + self.tickGap)代表顯示一筆資料,在x軸方向所需的總點數
     x1 = self.chartPos[0] + dispIdx * (self.tickWide + self.tickGap) - self.backGap
     y1 = self.chartPos[1] + (preValue - self.lowestValue) * self.yscale
     x2 = x1 + (self.tickWide + self.tickGap)
     y2 = self.chartPos[1] + (aValue - self.lowestValue) * self.yscale
     instg.add(Line(points=(x1, y1, x2, y2), width=1))
     self.canvas.add(instg)
    def PrintLayer(self, l_num):
        with self.canvas:
            self.line_list = list()
            Color(1, 1, 1, 1)
            self.layer = self.all_layers[l_num]
            for li in self.layer:
                # print(li)
                line_l = Line(points=(), width=1)
                self.line_list.append(line_l)

            # print('test')
            # print(self.Parcer.parced_layers)
            for x, line in enumerate(self.line_list):
                # print('test')
                # print(self.layer[x])

                for num_, point in enumerate(self.layer[x]):
                    if num_ % 2 == 0:
                        line.points += (self.layer[x][num_],
                                        self.layer[x][num_ + 1])
Beispiel #4
0
    def build(self, *args):
        self.canvas.clear()
        if not self.points:
            return

        with self.canvas:
            if self.fill:
                Color(rgba=self.fill_color)
                t = Tesselator()
                t.add_contour(self.points)
                if t.tesselate:
                    for vertices, indices in t.meshes:
                        Mesh(vertices=vertices,
                             indices=indices,
                             mode='triangle fan')
                    else:
                        print("Mesh didn't tesselate!")
            if self.stroke:
                Color(rgba=self.color)
                Line(points=self.points, width=self.line_width)
    def _update_rect(self, instance, *args):

        snames = self.manager.screen_names
        initial_pos = [29, 4]
        for s_screen in snames:
            if self.name == s_screen:
                self.add_widget(
                    buttons.PipButton(selected=True,
                                      text=s_screen.capitalize(),
                                      size_hint=(0, 0),
                                      size=(70, 20),
                                      pos=initial_pos))
                initial_pos[0] += 96
            else:
                self.add_widget(
                    buttons.PipButton(text=s_screen.capitalize(),
                                      size_hint=(0, 0),
                                      size=(70, 20),
                                      pos=initial_pos,
                                      screen=s_screen,
                                      screenmanager=self.manager))
                initial_pos[0] += 96

        self.rect.pos = instance.pos
        self.rect.size = instance.size

        with self.canvas.before:
            Line(points=[10, 20, 10, 14], width=1.3)  # Bottom Left
            # Bottom right
            Line(points=[self.width - 10, 20, self.width - 10, 14], width=1.3)
            aux = 20
            for x in range(1, 9):
                Color(100 / 256., 254 / 256., 181 / 256., .9 - x / 10.)
                # Gradient bottom right
                Line(points=[self.width - 10, aux, self.width - 10, aux + 2],
                     width=1.3)
                Line(points=[
                    self.width - 8, self.height - aux - 5, self.width - 8,
                    self.height + 5 - aux
                ],
                     width=1.3)  # Gradient top right
                Line(points=[
                    self.x + 8, self.height - aux - 5, self.x + 8,
                    self.height + 5 - aux
                ],
                     width=1.3)  # Gradient top left
                # Gradient bottom left
                Line(points=[10, aux, 10, aux + 2], width=1.3)
                aux += 2
Beispiel #6
0
class Motor(Widget):
    pos = 0, 0
    r = 50
    c = 0, 0
    theta = 0
    l_pts = []
    l = Line()

    def __init__(self, x_pos, y_pos):
        super(Motor, self).__init__()
        self.pos = x_pos, y_pos
        self.c = self.pos[0] + self.r, self.pos[1] + self.r
        self.l_pts = [self.c[0], self.c[1], self.c[0] + self.r, self.c[1]]
        with self.canvas.before:
            Color(0, 0, 1)
            Ellipse(pos=self.pos, size=(100, 100))
            self.add_widget(Label(pos=(400, 125), text='X Stepper'))
        with self.canvas:
            Color(0, 0, 0)
            self.l = Line(points=self.l_pts, width=2)
Beispiel #7
0
    def on_touch_down(self, touch):
        if super(TouchWidget, self).on_touch_down(touch):
            return True

        if self.align_widget is not None:
            if self.last_touch is not None:
                return True

            touch.ud['alignment'] = True
            self.last_pos = touch.pos
            self.last_touch = touch
            self.callback_trigger()
        else:
            pos = np.ones((3, ))
            pos[:2] = touch.pos
            x, y = np.dot(self.trans_mat, pos)[:2]
            with self.canvas:
                touch.ud['circle'] = Line(circle=(x, y, dp(25)))

        return True
    def start(self):
        # if border_option is active, draw rectangle around the game area
        if self.border_option:
            with self.canvas.before:
                Line(width=3.,
                     rectangle=(self.x, self.y, self.width, self.height))

        # compute time coeff used as refresh rate for the game using the
        # options provided (default 1.1, max 2)
        # we store the value twice in order to keep a reference in case of
        # reset (indeed the running_time_coeff will be incremented in game if
        # a fruit is eaten)
        self.start_time_coeff += (self.start_speed / 10)
        self.running_time_coeff = self.start_time_coeff

        # draw new snake on board
        self.new_snake()

        # start update loop
        self.update()
 async def main(cls, *, widgets, ctx):
     from kivy.graphics import Line, Color, InstructionGroup
     import asynckivy as ak
     abs_ = abs
     target = widgets['target']
     to_local = target.to_local
     is_inside = _is_inside
     while True:
         __, touch = await ak.event(target, 'on_touch_down', filter=is_inside, stop_dispatching=True)
         target.canvas.add(ig := InstructionGroup())
         ig.add(Color(*ctx.line_color))
         ig.add(line := Line(width=ctx.line_width, points=[*to_local(*touch.opos)]))
         precision = ctx.freehand_precision
         last_x, last_y = touch.opos
         async for __ in ak.rest_of_touch_moves(target, touch):
             if abs_(last_x - touch.x) + abs_(last_y - touch.y) > precision:
                 p = line.points
                 p.extend(to_local(*touch.pos))
                 line.points = p
                 last_x, last_y = touch.pos
Beispiel #10
0
    def create_drawings(self):
        from kivy.graphics import Line, RenderContext
        from kivy.graphics.texture import Texture

        # very first time, create a texture for the shader
        if not hasattr(SmoothLinePlot, '_texture'):
            tex = Texture.create(size=(1, 64), colorfmt='rgb')
            tex.add_reload_observer(SmoothLinePlot._smooth_reload_observer)
            SmoothLinePlot._texture = tex
            SmoothLinePlot._smooth_reload_observer(tex)

        self._grc = RenderContext(fs=SmoothLinePlot.SMOOTH_FS,
                use_parent_modelview=True,
                use_parent_projection=True)
        with self._grc:
            self._gcolor = Color(*self.color)
            self._gline = Line(points=[], cap='none', width=2.,
                    texture=SmoothLinePlot._texture)

        return [self._grc]
 async def main(cls, *, widgets, ctx):
     from kivy.graphics import Line, Color, InstructionGroup
     import asynckivy as ak
     target = widgets['target']
     to_local = target.to_local
     shape_name = cls._shape_name
     is_inside = _is_inside
     while True:
         __, touch = await ak.event(target, 'on_touch_down', filter=is_inside, stop_dispatching=True)
         ox, oy = x, y = to_local(*touch.opos)
         target.canvas.add(ig := InstructionGroup())
         ig.add(Color(*ctx.line_color))
         ig.add(line := Line(width=ctx.line_width))
         async for __ in ak.rest_of_touch_moves(target, touch):
             x, y = to_local(*touch.pos)
             min_x, max_x = (x, ox) if x < ox else (ox, x)
             min_y, max_y = (y, oy) if y < oy else (oy, y)
             setattr(line, shape_name, (min_x, min_y, max_x - min_x, max_y - min_y, ))
         if x == ox and y == oy:
             target.canvas.remove(ig)
Beispiel #12
0
    def callBackMechanism(self, callback):
        '''
        
        Call the loadNextLine function periodically in a non-blocking way to
        update the gcode.
        
        '''

        with self.scatterObject.canvas:
            self.line = Line(points=(), width=1, group='gcode')

        #Draw numberOfTimesToCall lines on the canvas
        numberOfTimesToCall = 500
        for _ in range(numberOfTimesToCall):
            self.loadNextLine()

        #Repeat until end of file
        if self.lineNumber < min(len(self.data.gcode),
                                 self.maxNumberOfLinesToRead):
            Clock.schedule_once(self.callBackMechanism)
Beispiel #13
0
    def draw(self, x, y):
        x1, y1 = self.init_pos

        if self.draw_triangle is not None:
            mouse_x_y = x, y

            vertices = utils.constructTriangleFromLine(self.init_pos,
                                                       mouse_x_y)
            self.draw_triangle.points = vertices
            self.draw_altitude.points = [x, y, x1, y1]
        else:
            with self.game.canvas:
                self.color = utils.random_color()
                Color(*self.color, mode="rgba")
                self.draw_triangle = Triangle(
                    points=utils.get_triangle_points(x1, y1, x, y))
                Color(*utils.random_color(), mode="rgba")
                self.draw_altitude = \
                    Line(points=[x1, y1, x, y],
                         width=LINE_WIDTH, cap="square")
Beispiel #14
0
	def on_touch_down(self, touch):
		#texture testing
		brush_name = "textures/brush" + str(self.brush_count) + ".jpg"
		self.texture0 = kImage(brush_name).texture
		#Ellipse(texture = self.texture0, pos=(touch.x,touch.y), size=(self.pen_width,self.pen_width))
		#print(self.texture0)
		#print(self.size)
		if touch.y < 600 and touch.x > 0:
			with self.canvas:
				#simple line
				#Color(self.r / 255.0, self.g / 255.0, self.b / 255.0, self.t / 255.0)
				#touch.ud['line'] = Line(points=(touch.x, touch.y),width=self.pen_width, joint = 'bevel',cap = 'square')
				#with texture
				Color(1,1,1,0.5)
				touch.ud['line'] = Line(texture=self.texture0, points=(touch.x, touch.y),width=self.pen_width, joint = 'bevel',cap = 'square')

			self.num_strokes += 1
			self.stroke_data.append([int(touch.x), int(touch.y), 0])
		else:
			pass
Beispiel #15
0
    def redraw_regions(self, size=None, pos=None):

        if size is None:
            size = self.size
            pos = self.pos
        ax, bx, ay, by = self.calculate_coefficients(size, pos)

        self.canvas.after.clear()
        self.update_rect()

        with self.canvas.after:
            for region in self.marked_regions:
                new_points = [(x * ax + bx, y * ay + by) for x, y in region]
                for x1, y1 in new_points:
                    Color(1, 1, 0, 1)
                    d = 5.
                    Ellipse(pos=(x1 - d / 2, y1 - d / 2), size=(d, d))

                points_flatten = list(sum(new_points, ()))
                Line(points=points_flatten, width=1, close=True)
Beispiel #16
0
    def __init__(self, style=None, **kwargs):
        """
        Construtor do FormCard, acrescentando características próprias a ele:
        :param style: Padrão de estilo a ser utilizado no desenho do componente
        :param background_color: Cor de fundo do Widget (lista de 4 componentes)
        :param border_color: Cor da borda do Widget (lista de 4 componentes)
        :param kwargs: Demais parâmetros de um GridLayout
        """
        if style is None:
            self.style = ngstyle.getDefault().get('GridCard', {})
        else:
            self.style = style.get('GridCard', {})        
        if 'background_color' in kwargs:
            self.style['background_color'] = kwargs['background_color']
            del kwargs['background_color']
        if 'border_color' in kwargs:
            self.style['border_color'] = kwargs['border_color']
            del kwargs['border_color']
        if 'border_width' in kwargs:
            self.style['border_width'] = kwargs['border_width']
            del kwargs['border_width']
        self._widgets = [] #  Relacao de widgets do card (todos)
        kwargs['cols'] = 2
        
        super().__init__(**kwargs)
        
        with self.canvas.before:
            if 'background_color' in self.style and self.style['background_color']:
                Color(rgba=self.style['background_color'])
                self._rect = Rectangle(pos=self.pos, size=self.size)
            else:
                self._rect = None
            if 'border_color' in self.style and 'border_width' in self.style \
                and self.style['border_color'] and self.style['border_width']:
                Color(rgba=self.style['border_color'])
                self._border = Line(rectangle=(self.x, self.y, self.width, self.height),
                                    width=self.style['border_width'])
            else:
                self._border = None

        self.bind(size=self._update_rect, pos=self._update_rect)
Beispiel #17
0
 def draw_cord(self):
     global px_point, center_y, center_x, n, color_graph, color_lines, height, width, step
     with self.canvas:
         Color(color_lines[0], color_lines[1], color_lines[2], 1)
         '''Drawing two main lines'''
         if n == defoult_n:
             Line(points=(center_x, height, center_x, 0))
             Line(points=(width * 0.2, center_y, width, center_y))
         else:
             Line(points=(center_x, n * px_point, center_x, -n * px_point))
             Line(points=(-n * px_point, center_y, n * px_point, center_y))
         '''Small segmaents of lines'''
         for i in range(-n + 1, n):
             Line(points=(i * px_point + center_x, center_y - 5, i * px_point + center_x, center_y + 5))
             Line(points=(center_x - 5, i * px_point + center_y, center_x + 5, i * px_point + center_y))
Beispiel #18
0
    def render_canvas(self, *args):
        center_position = Position(*self.center)
        corner_positions = KivyHexagon.create_hexagon_corner_positions(
            center_position, self.EDGE_LEN)

        self.canvas.before.clear()

        with self.canvas.before:
            Color(*self.MESH_COLOR)
            KivyHexagon.make_hexagon_mesh(center_position, self.EDGE_LEN)

            Color(*self.EDGE_COLOR)
            KivyHexagon.make_hexagon_outline(center_position, self.EDGE_LEN)

            Line(points=KivyHexagon.convert_line_points(
                [corner_positions[0], center_position, corner_positions[-1]]))

        corner_angle_degs = KivyHexagon.create_hexagon_corner_angles()
        for corner_label, corner_angle_deg in zip(self.corner_labels,
                                                  corner_angle_degs):
            corner_label.text = u"{0}°".format(corner_angle_deg)

        for corner_label, corner_position in zip(self.corner_labels,
                                                 corner_positions):
            if corner_position.x < center_position.x:
                corner_label.center = (corner_position.x - 20,
                                       corner_position.y)
            elif corner_position.x > center_position.x:
                corner_label.center = (corner_position.x + 20,
                                       corner_position.y)
            else:
                if corner_position.y < center_position.y:
                    corner_label.center = (corner_position.x,
                                           corner_position.y - 15)
                elif corner_position.y > center_position.y:
                    corner_label.center = (corner_position.x,
                                           corner_position.y + 15)

        wedge_position = KivyHexagon.create_hexagon_corner_position(
            center_position, self.EDGE_LEN * 0.3, 5.5)
        self.wedge_angle_label.center = wedge_position.to_tuple()
Beispiel #19
0
    def update_map(self, *args):
        self.canvas.clear()

        paddingBothSides = self.MIN_PADDING * 2

        width = self.size[0]
        height = self.size[1]

        left = self.pos[0]
        bottom = self.pos[1]

        # the actual drawing space for the map on the image
        mapWidth = width - paddingBothSides
        mapHeight = height - paddingBothSides

        #determine the width and height ratio because we need to magnify the map to fit into the given image dimension
        mapWidthRatio = float(mapWidth) / float(self.maxXY.x)
        mapHeightRatio = float(mapHeight) / float(self.maxXY.y)

        # using different ratios for width and height will cause the map to be stretched. So, we have to determine
        # the global ratio that will perfectly fit into the given image dimension
        self.globalRatio = min(mapWidthRatio, mapHeightRatio)

        #now we need to readjust the padding to ensure the map is always drawn on the center of the given image dimension
        self.heightPadding = (height - (self.globalRatio * self.maxXY.y)) / 2.0
        self.widthPadding = (width - (self.globalRatio * self.maxXY.x)) / 2.0
        self.offsetPoint = self.minXY

        points = self.mapPoints
        linePoints = []
        for point in points:
            scaledPoint = self.scalePoint(point, self.height, left, bottom)
            linePoints.append(scaledPoint.x)
            linePoints.append(scaledPoint.y)
        self.linePoints = linePoints

        with self.canvas:
            Color(*self.trackColor)
            Line(points=self.linePoints,
                 width=dp(self.trackWidthScale * self.height),
                 closed=True)
Beispiel #20
0
    def on_touch_down(self, touch):
        global brushSize

        if (touch.x > self.pos[0] + self.size[0] - brushSize):
            return
        elif (touch.x < self.pos[0] + brushSize):
            return
        elif (touch.y > self.pos[1] + self.size[1] - brushSize):
            return
        elif (touch.y < self.pos[1] + brushSize):
            return
        with self.canvas:
            global color
            if color == 1:
                Color(1, 1, 1)
            else:
                Color(0, 0, 0)

            Ellipse(pos=(touch.x - brushSize / 2, touch.y - brushSize / 2),
                    size=(brushSize, brushSize))
            touch.ud['line'] = Line(points=(touch.x, touch.y), width=brushSize)
 def __init__(self, gridchannels, **kwargs):
     super(PopupAddChannel, self).__init__(**kwargs)
     self.pieces = [
         "bumbo", "caixa", "chimbal", "hhc", "splash", "crash", "china",
         "ride", "bell", "rotomtom", "tom8", "tom10", "tom12", "surdo16",
         "block", "hhc3"
     ]
     with self.canvas:
         Color(0.1, 0.45, 1)
         self.line_selection = Line(width=3, rectangle=(0, 0, 0, 0))
     self.selected_canvas = self.canvas  #usado para guardar o canvas do ultimo elemento clicado para apaalo se precisar
     self.selected_image = ""
     self.gridchannels = gridchannels
     for piece in self.pieces:
         box = BoxLayout()
         image = ImageButton(on_press=self.click_image_popup,
                             id=piece,
                             source="resources/images/PNG/" + piece +
                             ".png")
         box.add_widget(image)
         self.ids.grid_images_add_channel.add_widget(box)
Beispiel #22
0
    def on_touch_down(self,touch): #down ile basıldığına işle mdevreye girecektir
        
        with self.canvas: # ardından canvas ile yap dedik
            if renk == "red":
                Color(1,0,0)
            elif renk == "yesil":
                Color(0,1,0)
            elif renk == "mavi":
                Color(0,0,1)
            else:
                Color(1,1,2)

            #Color(1,1,1) # canvasın içinden renk seçimini yaptık

            
            if sekil == "cizgi":
                touch.ud["Line"] = Line(points = (touch.x, touch.y)) #daha sonra ise line x ve y koordinatlari ile aldık yani bastığımız yerden itibaren çizmeye başlayacaktır
            elif sekil == "kare":
                touch.ud["kare"] = Rectangle(pos = (touch.x,touch.y),size=(10,10))
            elif sekil == "elips":
                touch.ud["elips"] = Ellipse(pos = (touch.x,touch.y), size=(10,10))
Beispiel #23
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.Grid1 = InstructionGroup()
        self.Grid1.add(Color(1, 0, 0, 0.5))
        self.Grid1.add(
            Line(points=[self.x, self.y + 75, self.x + 225, self.y + 75]))
        self.Grid1.add(
            Line(points=[
                self.x, self.y + 75 * 2, self.x + 225, self.y + 75 * 2
            ]))
        self.Grid1.add(
            Line(points=[
                self.x, self.y, self.x + 225, self.y, self.x + 225, self.y +
                225, self.x, self.y + 225
            ]))

        self.Grid2 = InstructionGroup()
        self.Grid2.add(Color(1, 0, 0, 0.5))
        self.Grid2.add(Rectangle(pos=(self.x, self.y)))
        self.Grid2.add(
            Line(points=[self.x + 75, self.y, self.x + 75, self.y + 225]))
        self.Grid2.add(
            Line(points=[
                self.x + 75 * 2, self.y, self.x + 75 * 2, self.y + 225
            ]))
        self.Grid2.add(
            Line(points=[self.x, self.y + 75, self.x + 225, self.y + 75]))
        self.Grid2.add(
            Line(points=[
                self.x, self.y + 75 * 2, self.x + 225, self.y + 75 * 2
            ]))
        self.Grid2.add(
            Line(points=[
                self.x, self.y, self.x + 225, self.y, self.x + 225,
                self.y + 225, self.x, self.y + 225
            ],
                 close=True))
Beispiel #24
0
    def draw_background(self):
        if self.canvas == None:
            return
        
        self.canvas.before.clear()        

        with self.canvas.before:
            
            Color(.3, .3, .3)
            
            Rectangle(pos=self.pos, size=self.size)
            
            Color(.23, .68, .85)
            Line(rectangle=(self.x-self.quad_separation, 
                                self.y-self.quad_separation, 
                                self.width+self.quad_separation*2, 
                                self.height+self.quad_separation*2),
                cap=None,
                joint='round',
                close=True,
                width=4)
Beispiel #25
0
    def __init__(self, points=[], loop=False, *args, **kwargs):
        super(SignalDraw, self).__init__(*args, **kwargs)
        self.d = 10  # pixel tolerance when clicking on a point
        self.points = points
        self.loop = loop
        self.current_point = None  # index of point being dragged
        self.previous_touch = None
        self.previous_point = None
        self.previous_value = None
        self.data = []
        for i in range(1000):
            self.data.append(0)

        with self.canvas:
            Color(1.0, 0.0, 1.0)
            self.line = Line(points=self.points,
                             close=False,
                             dash_offset=0,
                             dash_length=0)

        self.set_data(self.data)
Beispiel #26
0
    def on_touch_up(self, touch):
        if self.current_tool == 'Line tool':
            try:
                touch.ud['line'].points += [touch.x, touch.y]
                self.clear_preview_lines()
            except:
                pass

        if self.current_tool == 'Square tool':
            try:
                with self.canvas:
                    Color(self.tool_color[0], self.tool_color[1],
                          self.tool_color[2], self.tool_color[3])
                    points = self.lines[-1].children[
                        -1].points  # Get all 4 points from the last square preview
                    Line(points=(points),
                         width=(self.tool_size / 2),
                         close=True)
                self.clear_preview_lines()
            except:
                pass
Beispiel #27
0
 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')
         ]
    def on_size(self, button_value='', *args):
        self.canvas.before.clear()
        self.bind(size=self.setter('texture_size'))
        self.background_normal = ""
        self.bold = True
        self.font = 128
        self.background_color = (0.97, 0.99, 0.98, 1)
        with self.canvas.before:
            Color(1, 1, 1, 1)
            Rectangle(pos=self.pos, size=self.size, size_hint_y=None, size_hint_x=None, font=160, bold=True)

        # Add black border around button
        self.canvas.after.clear()
        with self.canvas.after:
            Color(0, 0, 0, 1)
            self.line = Line(width=1.05,
                             points=(self.x, self.y,
                                     self.x, self.y + self.height,
                                     self.x + self.width, self.y + self.height,
                                     self.x + self.width, self.y,
                                     self.x, self.y,), color=(0, 0, 0, 1))
Beispiel #29
0
    def update_pizza(self, *args):
        '''
        Draw pizza on canvas

        '''
        with self.canvas:
            self.canvas.clear()
            offset_rotation = 0  # In degrees

            # Fix legend color
            Color(
                get_color_from_hex(self.legend_color)[0],
                get_color_from_hex(self.legend_color)[1],
                get_color_from_hex(self.legend_color)[2], 100)

            # Draw pie chart border circle
            border_circle = Line(circle=(self.chart_center, self.chart_center,
                                         self.chart_center),
                                 width=self.chart_border)

            for title, value, color in self.serie:
                angle = math.radians(((value * 3.6) / 2.0) + offset_rotation)
                title_x_pt = (math.sin(angle)) * self.legend_title_rayon
                title_y_pt = (math.cos(angle)) * self.legend_title_rayon

                # Fix color for each zone
                Color(
                    get_color_from_hex(color)[0],
                    get_color_from_hex(color)[1],
                    get_color_from_hex(color)[2], 100)

                # Draw zone animation
                zone = Ellipse(size=(self.chart_size, self.chart_size),
                               segments=value * 3.6,
                               angle_start=offset_rotation,
                               angle_end=offset_rotation + (value * 3.6),
                               t='in_quad')

                # Offset control of each zone, drawing starts on offset
                offset_rotation += value * 3.6
Beispiel #30
0
    def on_touch_down(self, touch):
        """ called by the framework, if a widget is touched """
        global oDownWidget

        uButton = "left"
        if hasattr(touch,"button"):
            uButton = touch.button

        if self.IsMyTouch(touch) and uButton=="left":
            # Logger.debug("on_touch_down")
            for child in self.children[:]:
                if child.dispatch('on_touch_down', touch):
                    return True
            if touch.is_double_tap:
                self.Delete_LongPressClock(touch)
                self.Delete_RepeatClock(touch)
                self.Delete_DoublePressClock(touch)
                # rest will be managed by the up event
                return True

            self.uTapType          = u"down"
            self.bProcessed        = False
            self.bFirstRepeat      = True
            oDownWidget            = self
            oDownWidget.bProcessUp = False
            userdata = touch.ud
            userdata['line'] = Line(points=(touch.x, touch.y))
            if not self.bWaitForDouble:
                self.dispatch('on_q_press')
            self.bIsDown = True
            # we start the clocks after the first triggered action, to make sure, that we don't miss
            # timing on lenghly actions
            # but not on right klick to bypass kivy bug
            if uButton=="left":
                self.Create_DoublePressClock(touch)
                self.Create_LongPressClock(touch)
                self.Create_RepeatClock(touch)
            return True
        return False