Python kivy.metrics.dp() Examples
The following are 30
code examples of kivy.metrics.dp().
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.metrics
, or try the search function
.
Example #1
Source File: dialog.py From KivyMD with MIT License | 7 votes |
def add_action_button(self, text, action=None): """Add an :class:`FlatButton` to the right of the action area. :param icon: Unicode character for the icon :type icon: str or None :param action: Function set to trigger when on_release fires :type action: function or None """ button = MDFlatButton(text=text, size_hint=(None, None), height=dp(36)) if action: button.bind(on_release=action) button.text_color = self.theme_cls.primary_color button.background_color = self.theme_cls.bg_light self._action_buttons.append(button)
Example #2
Source File: presetview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def _on_update_check(self): def on_update_check_success(): def _success(): # do this in the UI thread popup.content.on_message('Processing...') Clock.schedule_once(lambda dt: self.refresh_view()) popup.dismiss() Clock.schedule_once(lambda dt: _success()) def on_update_check_error(details): def _error(details): # do this in the UI thread popup.dismiss() Clock.schedule_once(lambda dt: self.refresh_view()) Logger.error('PresetBrowserView: Error updating: {}'.format(details)) alertPopup('Error Updating', 'There was an error updating the presets.\n\nPlease check your network connection and try again') Clock.schedule_once(lambda dt: _error(details)) self.set_view_disabled(True) update_view = PresetUpdateStatusView() popup = Popup(title='Checking for updates', content=update_view, auto_dismiss=False, size_hint=(None, None), size=(dp(400), dp(200))) popup.open() self.preset_manager.refresh(update_view.on_progress, on_update_check_success, on_update_check_error)
Example #3
Source File: gauge.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def on_release(self): if not self.channel: self.showChannelSelectDialog() else: bubble = CustomizeGaugeBubble() buttons = [] if self.is_removable: buttons.append(BubbleButton(text='Remove', on_press=lambda a:self.removeChannel())) if self.is_channel_selectable: buttons.append(BubbleButton(text='Select Channel', on_press=lambda a:self.selectChannel())) buttons.append(BubbleButton(text='Customize', on_press=lambda a:self.customizeGauge())) if len(buttons) == 1: buttons[0].dispatch('on_press') else: for b in buttons: bubble.add_widget(b) bubble_height = dp(150) bubble_width = dp(200) bubble.size = (bubble_width, bubble_height) bubble.auto_dismiss_timeout(Gauge.POPUP_DISMISS_TIMEOUT_SHORT) self._customizeGaugeBubble = bubble self.add_widget(bubble) bubble.center_on_limited(self)
Example #4
Source File: source.py From PyCon-Mobile-App with GNU General Public License v3.0 | 6 votes |
def __init__(self, url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", cache_key=None, min_zoom=0, max_zoom=19, tile_size=256, image_ext="png", attribution="© OpenStreetMap contributors", subdomains="abc", **kwargs): super(MapSource, self).__init__() if cache_key is None: # possible cache hit, but very unlikely cache_key = hashlib.sha224(url.encode("utf8")).hexdigest()[:10] self.url = url self.cache_key = cache_key self.min_zoom = min_zoom self.max_zoom = max_zoom self.tile_size = tile_size self.image_ext = image_ext self.attribution = attribution self.subdomains = subdomains self.cache_fmt = "{cache_key}_{zoom}_{tile_x}_{tile_y}.{image_ext}" self.dp_tile_size = min(dp(self.tile_size), self.tile_size * 2) self.default_lat = self.default_lon = self.default_zoom = None self.bounds = None self.cache_dir = kwargs.get('cache_dir', CACHE_DIR)
Example #5
Source File: view.py From PyCon-Mobile-App with GNU General Public License v3.0 | 6 votes |
def reposition(self): if not self.markers: return mapview = self.parent set_marker_position = self.set_marker_position bbox = None latest_bbox_size = dp(48) # reposition the markers depending the latitude markers = sorted(self.markers, key=lambda x: -x.lat) margin = max((max(marker.size) for marker in markers)) bbox = mapview.get_bbox(margin) for marker in markers: if bbox.collide(marker.lat, marker.lon): set_marker_position(mapview, marker) if not marker.parent: self.insert_marker(marker) else: super(MarkerMapLayer, self).remove_widget(marker)
Example #6
Source File: tracksview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def init_tracks_list(self): if self.track_manager and self.track_db: matched_tracks = [] for track in self.track_db.tracks: matched_track = self.track_manager.find_track_by_short_id(track.trackId) if matched_track: matched_tracks.append(matched_track) grid = self.ids.tracksgrid grid.clear_widgets() if len(matched_tracks) == 0: grid.add_widget(EmptyTrackDbView()) grid.height = dp(self.TRACK_ITEM_MIN_HEIGHT) else: grid.height = dp(self.TRACK_ITEM_MIN_HEIGHT) * (len(matched_tracks) + 1) index = 0 for track in matched_tracks: track_db_view = TrackDbItemView(track=track, index=index) track_db_view.bind(on_remove_track=self.on_remove_track) track_db_view.size_hint_y = None track_db_view.height = dp(self.TRACK_ITEM_MIN_HEIGHT) grid.add_widget(track_db_view) index += 1 self.disableView(False)
Example #7
Source File: kitchen_sink.py From KivyMD with MIT License | 6 votes |
def show_example_dialog(self): content = MDLabel(font_style='Body1', theme_text_color='Secondary', text="This is a dialog with a title and some text. That's pretty awesome right!", valign='top') content.bind(size=content.setter('text_size')) self.dialog = MDDialog(title="This is a test dialog", content=content, size_hint=(.8, None), height=dp(200), auto_dismiss=False) self.dialog.add_action_button("Dismiss", action=lambda *x: self.dialog.dismiss()) self.dialog.open()
Example #8
Source File: main.py From nowallet with MIT License | 6 votes |
def show_dialog(self, title, message, qrdata=None, cb=None): if qrdata: dialog_height = 300 content = QRCodeWidget(data=qrdata, size=(dp(150), dp(150)), size_hint=(None, None)) else: dialog_height = 200 content = MDLabel(font_style='Body1', theme_text_color='Secondary', text=message, size_hint_y=None, valign='top') content.bind(texture_size=content.setter('size')) self.dialog = MDDialog(title=title, content=content, size_hint=(.8, None), height=dp(dialog_height), auto_dismiss=False) self.dialog.add_action_button( "Dismiss", action=cb if cb else lambda *x: self.dialog.dismiss()) self.dialog.open()
Example #9
Source File: modal_cursor.py From kivystudio with MIT License | 6 votes |
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 #10
Source File: gauge.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def showChannelConfigDialog(self): def popup_dismissed(instance): self.settings.userPrefs.set_alertrules(self.channel, alertrules) self.dashboard_state.clear_channel_states(self.channel) alertrules = self.settings.userPrefs.get_alertrules(self.channel) content = AlertRulesView(alertrules, channel=self.channel) content.min_value = self.min content.max_value = self.max content.precision = self.precision popup = Popup(title='Customize {}'.format(self.channel), content=content, size=(min(Window.width, dp(700)), min(Window.height, dp(400))), size_hint=(None, None)) popup.bind(on_dismiss=popup_dismissed) content.bind(title=lambda i, t: setattr(popup, 'title', t)) popup.open()
Example #11
Source File: elevationbehaviour.py From KivyMD with MIT License | 6 votes |
def _update_shadow(self, *args): if self.elevation > 0: width = self.width * 2 height = self.height * 2 x = self.center_x - width / 2 self._soft_shadow_size = (width, height) self._hard_shadow_size = (width, height) y = self.center_y - height / 2 - dp(.1 * 1.5 ** self.elevation) self._soft_shadow_pos = (x, y) self._soft_shadow_a = 0.1 * 1.1 ** self.elevation self._soft_shadow_texture = self._shadow.textures[ str(int(round(self.elevation)))] y = self.center_y - height / 2 - dp(.5 * 1.18 ** self.elevation) self._hard_shadow_pos = (x, y) self._hard_shadow_a = .4 * .9 ** self.elevation self._hard_shadow_texture = self._shadow.textures[ str(int(round(self.elevation - 1)))] else: self._soft_shadow_a = 0 self._hard_shadow_a = 0
Example #12
Source File: trackconfigview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def __init__(self, gps_sample, **kwargs): super(ManualTrackConfigScreen, self).__init__(**kwargs) self._track_cfg = None self._gps_sample = gps_sample self.ids.sep_startfinish.bind(on_setting=self.on_separate_start_finish) self.ids.sep_startfinish.setControl(SettingsSwitch()) self.ids.start_line.gps_sample = gps_sample self.ids.finish_line.gps_sample = gps_sample self.separate_startfinish = False self._init_sector_views() sectors_container = self.ids.sectors_grid sectors_container.height = dp(35) * CONFIG_SECTOR_COUNT sectors_container.size_hint = (1.0, None) self.register_event_type('on_modified') self.register_event_type('on_custom_editor')
Example #13
Source File: source.py From pydelhi_mobile with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", cache_key=None, min_zoom=0, max_zoom=19, tile_size=256, image_ext="png", attribution="© OpenStreetMap contributors", subdomains="abc", **kwargs): super(MapSource, self).__init__() if cache_key is None: # possible cache hit, but very unlikely cache_key = hashlib.sha224(url.encode("utf8")).hexdigest()[:10] self.url = url self.cache_key = cache_key self.min_zoom = min_zoom self.max_zoom = max_zoom self.tile_size = tile_size self.image_ext = image_ext self.attribution = attribution self.subdomains = subdomains self.cache_fmt = "{cache_key}_{zoom}_{tile_x}_{tile_y}.{image_ext}" self.dp_tile_size = min(dp(self.tile_size), self.tile_size * 2) self.default_lat = self.default_lon = self.default_zoom = None self.bounds = None self.cache_dir = kwargs.get('cache_dir', CACHE_DIR)
Example #14
Source File: source.py From garden.mapview with MIT License | 6 votes |
def __init__(self, url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", cache_key=None, min_zoom=0, max_zoom=19, tile_size=256, image_ext="png", attribution="© OpenStreetMap contributors", subdomains="abc", **kwargs): super(MapSource, self).__init__() if cache_key is None: # possible cache hit, but very unlikely cache_key = hashlib.sha224(url.encode("utf8")).hexdigest()[:10] self.url = url self.cache_key = cache_key self.min_zoom = min_zoom self.max_zoom = max_zoom self.tile_size = tile_size self.image_ext = image_ext self.attribution = attribution self.subdomains = subdomains self.cache_fmt = "{cache_key}_{zoom}_{tile_x}_{tile_y}.{image_ext}" self.dp_tile_size = min(dp(self.tile_size), self.tile_size * 2) self.default_lat = self.default_lon = self.default_zoom = None self.bounds = None self.cache_dir = kwargs.get('cache_dir', CACHE_DIR)
Example #15
Source File: main.py From KivyMD with MIT License | 6 votes |
def show_example_dialog(self): content = MDLabel(font_style='Body1', theme_text_color='Secondary', text="This is a dialog with a title and some text. That's pretty awesome right!", valign='top') content.bind(size=content.setter('text_size')) self.dialog = MDDialog(title="This is a test dialog", content=content, size_hint=(.8, None), height=dp(200), auto_dismiss=False) self.dialog.add_action_button("Dismiss", action=lambda *x: self.dialog.dismiss()) self.dialog.open()
Example #16
Source File: alertview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def editor_popup(title, content, answerCallback, size_hint=(None, None), size=(dp(500), dp(220)), hide_ok=False, auto_dismiss_time=None): def auto_dismiss(*args): popup.dismiss() def on_title(instance, title): popup.title = title content.bind(on_title=on_title) content = EditorPopup(content=content, hide_ok=hide_ok) content.bind(on_answer=answerCallback) popup = Popup(title=title, content=content, size=size, size_hint=size_hint, auto_dismiss=True, title_size=sp(18)) popup.open() if auto_dismiss_time: Clock.create_trigger(auto_dismiss, auto_dismiss_time)() return popup
Example #17
Source File: infoview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def write_rcp_config(self, info_msg, callback): def timeout(dt): progress_view.dismiss() Clock.schedule_once(lambda dt: callback(), 0.25) def write_win(details): msg.text += ' Success' self.rc_config.stale = False Clock.schedule_once(timeout, 1.5) def write_fail(details): progress_view.dismiss() okPopup('Oops!', 'We had a problem updating the device. Check the device connection and try again.\n\nError:\n\n{}'.format(details), lambda *args: None) progress_view = ModalView(size_hint=(None, None), size=(dp(600), dp(200))) msg = FieldLabel(text=info_msg, halign='center') progress_view.add_widget(msg) progress_view.open() self.rc_api.writeRcpCfg(self.rc_config, write_win, write_fail)
Example #18
Source File: modal_cursor.py From Snu-Photo-Manager with GNU Lesser General Public License v3.0 | 6 votes |
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 #19
Source File: sessionlistview.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def edit_session(self, instance, session_id): def _on_answer(instance, answer): if answer: session_name = session_editor.session_name if not session_name or len(session_name) == 0: alertPopup('Error', 'A session name must be specified') return # did the session name change? if so, refresh the view. new_name = session_editor.session_name if new_name != session.name: session.name = new_name session_accordion = self._find_session_accordion_item(session) session_accordion.title = new_name session.notes = session_editor.session_notes self.datastore.update_session(session) self.dispatch('on_session_updated', session) popup.dismiss() session = self.datastore.get_session_by_id(session_id, self.sessions) session_editor = SessionEditorView() session_editor.session_name = session.name session_editor.session_notes = session.notes popup = editor_popup('Edit Session', session_editor, _on_answer, size=(dp(600), dp(300)))
Example #20
Source File: alerteditor.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def _add_new_action(self, *args): def popup_dismissed(instance, result): if result: selected = instance.content.selected_item if selected is not None: alertaction = selected.key self.alertrule.alert_actions.append(alertaction) self.dispatch('on_edit_action', alertaction) self.refresh_view() popup.dismiss() alertaction_prototypes = get_alertaction_default_collection(exclude_filter=self.alertrule.alert_actions) items = [ItemSelectionRef(title=alertaction.title, image_source=alertaction.PREVIEW_IMAGE, key=alertaction) for alertaction in alertaction_prototypes] if len(items) == 0: toast('No more actions available') else: view = ItemSelectorView(item_references=items) popup = editor_popup('Select Action', view, popup_dismissed, size_hint=(None, None), size=(min(Window.width, dp(700)), min(Window.height,dp(400))), auto_dismiss_time=10)
Example #21
Source File: __init__.py From kivystudio with MIT License | 6 votes |
def change_scroll_y(self, txt, scroll): if self._do_cursor_scroll: lines_lenght = len(txt._lines) line_pos = txt.cursor_row +1 norm_y = float(line_pos) / lines_lenght scroll.scroll_y = abs(norm_y-1) if line_pos == 1: scroll.scroll_y = 1 # scroll scroll numbers line_num = txt.cursor_row + 1 children = self.ids.numbering.children[::-1] if children: child = children[line_num-1] self.ids.number_scroll.scroll_to(child, dp(5)) Clock.schedule_once(lambda dt: setattr(child, 'state', 'down')) def toggle(chd): if chd!=child: chd.state='normal' map(lambda child: toggle, ToggleButtonBehavior.get_widgets(child.group))
Example #22
Source File: view.py From pydelhi_mobile with GNU Affero General Public License v3.0 | 6 votes |
def reposition(self): if not self.markers: return mapview = self.parent set_marker_position = self.set_marker_position bbox = None latest_bbox_size = dp(48) # reposition the markers depending the latitude markers = sorted(self.markers, key=lambda x: -x.lat) margin = max((max(marker.size) for marker in markers)) bbox = mapview.get_bbox(margin) for marker in markers: if bbox.collide(marker.lat, marker.lon): set_marker_position(mapview, marker) if not marker.parent: super(MarkerMapLayer, self).add_widget(marker) else: super(MarkerMapLayer, self).remove_widget(marker)
Example #23
Source File: utils.py From garden.mapview with MIT License | 6 votes |
def get_zoom_for_radius(radius_km, lat=None, tile_size=256.): """See: https://wiki.openstreetmap.org/wiki/Zoom_levels""" radius = radius_km * 1000. if lat is None: lat = 0. # Do not compensate for the latitude # Calculate the equatorial circumference based on the WGS-84 radius earth_circumference = 2. * pi * 6378137. * cos(lat * pi / 180.) # Check how many tiles that are currently in view nr_tiles_shown = min(Window.size) / dp(tile_size) # Keep zooming in until we find a zoom level where the circle can fit inside the screen zoom = 1 while earth_circumference / (2 << (zoom - 1)) * nr_tiles_shown > 2 * radius: zoom += 1 return zoom - 1 # Go one zoom level back
Example #24
Source File: scrollcontainer.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def __init__(self, **kwargs): # The starting vertical scroll position self._start_y = None super(ScrollContainer, self).__init__(**kwargs) self.scroll_type = ['bars', 'content'] self.scroll_wheel_distance = dp(114) self.bar_width = dp(20)
Example #25
Source File: clustered_marker_layer.py From pydelhi_mobile with GNU Affero General Public License v3.0 | 5 votes |
def reposition(self): if self.cluster is None: self.build_cluster() margin = dp(48) mapview = self.parent set_marker_position = self.set_marker_position bbox = mapview.get_bbox(margin) bbox = (bbox[1], bbox[0], bbox[3], bbox[2]) self.clear_widgets() for point in self.cluster.get_clusters(bbox, mapview.zoom): widget = point.widget if widget is None: widget = self.create_widget_for(point) set_marker_position(mapview, widget) self.add_widget(widget)
Example #26
Source File: geojson.py From pydelhi_mobile with GNU Affero General Public License v3.0 | 5 votes |
def _geojson_part_geometry(self, geometry, properties): tp = geometry["type"] graphics = [] if tp == "Polygon": tess = Tesselator() for c in geometry["coordinates"]: xy = list(self._lonlat_to_xy(c)) xy = flatten(xy) 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
Example #27
Source File: clustered_marker_layer.py From garden.mapview with MIT License | 5 votes |
def reposition(self): if self.cluster is None: self.build_cluster() margin = dp(48) mapview = self.parent set_marker_position = self.set_marker_position bbox = mapview.get_bbox(margin) bbox = (bbox[1], bbox[0], bbox[3], bbox[2]) self.clear_widgets() for point in self.cluster.get_clusters(bbox, mapview.zoom): widget = point.widget if widget is None: widget = self.create_widget_for(point) set_marker_position(mapview, widget) self.add_widget(widget)
Example #28
Source File: settings.py From Tickeys-linux with MIT License | 5 votes |
def _create_popup(self, instance): # create popup layout content = BoxLayout(orientation='vertical', spacing='5dp') popup_width = min(0.95 * Window.width, dp(500)) self.popup = popup = Popup( title=self.title, content=content, size_hint=(None, None), size=(popup_width, '250dp')) # create the textinput used for numeric input self.textinput = textinput = TextInput( text=self.value, font_size='24sp', multiline=False, size_hint_y=None, height='42sp') textinput.bind(on_text_validate=self._validate) self.textinput = textinput # construct the content, widget are used as a spacer content.add_widget(Widget()) content.add_widget(textinput) content.add_widget(Widget()) content.add_widget(SettingSpacer()) # 2 buttons are created for accept or cancel the current value btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp') btn = Button(text='Ok') btn.bind(on_release=self._validate) btnlayout.add_widget(btn) btn = Button(text='Cancel') btn.bind(on_release=self._dismiss) btnlayout.add_widget(btn) content.add_widget(btnlayout) # all done, open the popup ! popup.open()
Example #29
Source File: settings.py From Tickeys-linux with MIT License | 5 votes |
def _create_popup(self, instance): # create popup layout content = BoxLayout(orientation='vertical', spacing=5) popup_width = min(0.95 * Window.width, dp(500)) self.popup = popup = Popup( title=self.title, content=content, size_hint=(None, 0.9), width=popup_width) # create the filechooser self.textinput = textinput = FileChooserListView( path=self.value, size_hint=(1, 1), dirselect=True) textinput.bind(on_path=self._validate) self.textinput = textinput # construct the content content.add_widget(textinput) content.add_widget(SettingSpacer()) # 2 buttons are created for accept or cancel the current value btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp') btn = Button(text='Ok') btn.bind(on_release=self._validate) btnlayout.add_widget(btn) btn = Button(text='Cancel') btn.bind(on_release=self._dismiss) btnlayout.add_widget(btn) content.add_widget(btnlayout) # all done, open the popup ! popup.open()
Example #30
Source File: imuview.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def _adjust_aspect(self, instance, value): rsize = self.renderer.size width = max(1, rsize[0]) height = max(1, rsize[1]) if height == 0: return self.renderer.camera.aspect = width / float(height) self.size_scaling = 1 / float(dp(1)) # width / (width * height) / (Window.size[0] * Window.size[1])