How to use the kivy.metrics.dp function in Kivy

To help you get started, we’ve selected a few Kivy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samocooper / nuclitrack / nuclitrack / nuclitrack_guitools / graph.py View on Github external
vert[k * 8] = size[0] + (xpoints2[k - start] - xmin) * ratio
                vert[k * 8 + 1] = size[1]
                vert[k * 8 + 4] = vert[k * 8]
                vert[k * 8 + 5] = top
            start += len(xpoints2)
        if len(ypoints):
            top = size[2] if self.y_grid else metrics.dp(12) + size[0]
            ratio = (size[3] - size[1]) / float(ymax - ymin)
            for k in range(start, len(ypoints) + start):
                vert[k * 8 + 1] = size[1] + (ypoints[k - start] - ymin) * ratio
                vert[k * 8 + 5] = vert[k * 8 + 1]
                vert[k * 8] = size[0]
                vert[k * 8 + 4] = top
            start += len(ypoints)
        if len(ypoints2):
            top = metrics.dp(8) + size[0]
            ratio = (size[3] - size[1]) / float(ymax - ymin)
            for k in range(start, len(ypoints2) + start):
                vert[k * 8 + 1] = size[1] + (ypoints2[k - start] - ymin) * ratio
                vert[k * 8 + 5] = vert[k * 8 + 1]
                vert[k * 8] = size[0]
                vert[k * 8 + 4] = top
        mesh.vertices = vert
github AndreMiras / KivyMD / kivymd / material_resources.py View on Github external
# Feel free to override this const if you're designing for a device such as
# a GNU/Linux tablet.
if platform != "android" and platform != "ios":
    DEVICE_TYPE = "desktop"
elif Window.width >= dp(600) and Window.height >= dp(600):
    DEVICE_TYPE = "tablet"
else:
    DEVICE_TYPE = "mobile"

if DEVICE_TYPE == "mobile":
    MAX_NAV_DRAWER_WIDTH = dp(300)
    HORIZ_MARGINS = dp(16)
    STANDARD_INCREMENT = dp(56)
    PORTRAIT_TOOLBAR_HEIGHT = STANDARD_INCREMENT
    LANDSCAPE_TOOLBAR_HEIGHT = STANDARD_INCREMENT - dp(8)
else:
    MAX_NAV_DRAWER_WIDTH = dp(400)
    HORIZ_MARGINS = dp(24)
    STANDARD_INCREMENT = dp(64)
    PORTRAIT_TOOLBAR_HEIGHT = STANDARD_INCREMENT
    LANDSCAPE_TOOLBAR_HEIGHT = STANDARD_INCREMENT

TOUCH_TARGET_HEIGHT = dp(48)

FONTS = [
    {
        "name": "Roboto",
        "fn_regular": fonts_path + 'Roboto-Regular.ttf',
        "fn_bold": fonts_path + 'Roboto-Medium.ttf',
        "fn_italic": fonts_path + 'Roboto-Italic.ttf',
        "fn_bolditalic": fonts_path + 'Roboto-MediumItalic.ttf'
github kivy-garden / garden.rotabox / visual_editor / rotaboxer.py View on Github external
def __init__(self, **kwargs):
        super(ScrollLabel, self).__init__(**kwargs)
        self.scroll_type = ['bars', 'content']
        self.bar_color = (.3, .3, .4, .35)
        self.bar_inactive_color = (.3, .3, .4, .15)
        self.bar_width = dp(10)
        self.scroll_wheel_distance = dp(50)
github kivy-garden / garden.rotabox / visual_editor / rotaboxer.py View on Github external
rem_btn.text = 'Remove point'
        point_popup.add_widget(rem_btn)

        opn_btn = Button(background_color=(.13, .13, .2, 1),
                         on_release=self.root.open_polygon)
        opn_btn.text = self.root.open_btn.text
        point_popup.add_widget(opn_btn)

        clear_btn = Button(background_color=(.13, .13, .2, 1),
                           on_release=self.root.remove_polygon)
        clear_btn.text = 'Remove polygon'
        point_popup.add_widget(clear_btn)

        self.popup = AutoPopup(content=point_popup,
                               size_hint=(None, None),
                               size=(dp(240), dp(200)))
        self.popup.title = "Point menu:"
        self.popup.open()
github kivy-garden / garden.rotabox / visual_editor / rotaboxer.py View on Github external
def restore(self, snapshot, version):
        for f, sframe in iteritems(snapshot):
            if f in ('frame', 'pol', 'index', 'to_transfer'):
                continue
            self.rec[f] = {}
            for p, pol in iteritems(sframe):
                self.rec[f][p] = {}
                self.rec[f][p]['key'] = pol['key']
                self.rec[f][p]['number'] = pol['number']
                try:
                    self.rec[f][p]['open'] = pol['open']
                except Exception:
                    self.rec[f][p]['open'] = False
                self.rec[f][p]['color'] = tuple(pol['color'])
                self.rec[f][p]['label'] = Label(size=(dp(50), dp(50)), font_size='35sp',
                                                bold=True,
                                                color=self.rec[f][p]['color'][:-1] + (.3,))
                self.scat.add_widget(self.rec[f][p]['label'])
                self.rec[f][p]['btn_points'] = [Point(self.rec[f][p], self,
                                                      self.mag,
                                                      text=str(i),
                                                      pos=(point[0] +
                                                           self.sprite.x,
                                                           point[1] +
                                                           self.sprite.y))
                                                for i, point in enumerate(
                                                                pol['points'])]
                if f == self.frame:
                    for i in range(len(self.rec[f][p]['btn_points'])):
                        point = self.rec[f][p]['btn_points'][i]
                        self.scat.add_widget(point)
github ellisonleao / pybrapp / pybr / libs / garden / garden.mapview / mapview / geojson.py View on Github external
tess.add_contour(xy)

            tess.tesselate(WINDING_ODD, TYPE_POLYGONS)

            color = self._get_color_from(properties.get("color", "FF000088"))
            graphics.append(Color(*color))
            for vertices, indices in tess.meshes:
                graphics.append(
                    Mesh(
                        vertices=vertices,
                        indices=indices,
                        mode="triangle_fan"))

        elif tp == "LineString":
            stroke = get_color_from_hex(properties.get("stroke", "#ffffff"))
            stroke_width = dp(properties.get("stroke-width"))
            xy = list(self._lonlat_to_xy(geometry["coordinates"]))
            xy = flatten(xy)
            graphics.append(Color(*stroke))
            graphics.append(Line(points=xy, width=stroke_width))

        return graphics
github HeaTTheatR / KivyMD / kivymd / uix / accordionlistitem.py View on Github external
def anim_resize_open_item(self, *args):
        self.content.name_item = self.title
        anim = Animation(
            height=self.content.height + dp(70), d=0.2, t="in_cubic"
        )
        anim.bind(on_complete=self.add_content)
        anim.start(self)
github osava-nsit / osava / screens / cpu_screens.py View on Github external
"Response time: "+str(self.details[process['name']]['resp_time'])+" ms\n"+
                            "Turnaround time: "+str(self.details[process['name']]['turn_time'])) + " ms"
                    else:
                        if process['next_queue'] == 0:
                            content_str = ("Wait time: "+str(self.details[process['name']]['wait_time'])+" ms\n"+
                            "Response time: "+str(self.details[process['name']]['resp_time'])+" ms\n"+
                            "Turnaround time: "+str(self.details[process['name']]['turn_time'])+" ms\n"+
                            "Process "+process['name']+" is completed.")
                        else:
                            content_str = ("Wait time: "+str(self.details[process['name']]['wait_time'])+" ms\n"+
                            "Response time: "+str(self.details[process['name']]['resp_time'])+" ms\n"+
                            "Turnaround time: "+str(self.details[process['name']]['turn_time'])+" ms\n"+
                            process['name']+" moved to queue Q"+str(process['next_queue']+1)+".")

                    content_label = Label(text=content_str)
                    popup = Popup(title='Details of '+str(process['name']), content=content_label, size_hint=(None, None), size=(kivy.metrics.dp(200), kivy.metrics.dp(200)))
                    label_name.bind(on_ref_press=popup.open)
                    details_button.bind(on_release=popup.open)
                    popup.open()
                    popup.dismiss()
                else:
                    details_button.disabled = True

                grid.add_widget(box)

            # Display statistics
            box = BoxLayout(orientation='horizontal', size_hint_y=None, height=row_height)
            box.add_widget(Label(text='Average turnaround time: ' + str(int((self.stats['turn_time']*100)+0.5)/100.0) + ' ms'))
            grid.add_widget(box)

            box = BoxLayout(orientation='horizontal', size_hint_y=None, height=row_height)
            box.add_widget(Label(text='Average waiting time: ' + str(int((self.stats['wait_time']*100)+0.5)/100.0) + ' ms'))
github HeaTTheatR / KivyMD / kivymd / uix / list.py View on Github external
self.height = dp(56) if not self._height else self._height


class TwoLineAvatarListItem(OneLineAvatarListItem):
    _txt_top_pad = NumericProperty(dp(20))
    _txt_bot_pad = NumericProperty(dp(15))  # dp(20) - dp(5)
    _height = NumericProperty()
    _num_lines = 2

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.height = dp(72) if not self._height else self._height


class ThreeLineAvatarListItem(ContainerSupport, ThreeLineListItem):
    _txt_left_pad = NumericProperty(dp(72))


class OneLineIconListItem(ContainerSupport, OneLineListItem):
    _txt_left_pad = NumericProperty(dp(72))


class TwoLineIconListItem(OneLineIconListItem):
    _txt_top_pad = NumericProperty(dp(20))
    _txt_bot_pad = NumericProperty(dp(15))  # dp(20) - dp(5)
    _height = NumericProperty()
    _num_lines = 2

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.height = dp(72) if not self._height else self._height