本文整理汇总了Python中kivy.metrics.dp方法的典型用法代码示例。如果您正苦于以下问题:Python metrics.dp方法的具体用法?Python metrics.dp怎么用?Python metrics.dp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.metrics
的用法示例。
在下文中一共展示了metrics.dp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_action_button
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例2: show_example_dialog
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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()
示例3: _update_shadow
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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
示例4: reposition
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例5: __init__
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例6: __init__
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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))
示例7: change_scroll_y
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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))
示例8: get_zoom_for_radius
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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
示例9: __init__
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例10: reposition
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例11: show_dialog
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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()
示例12: _on_update_check
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例13: write_rcp_config
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)
示例14: showChannelConfigDialog
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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()
示例15: on_release
# 需要导入模块: from kivy import metrics [as 别名]
# 或者: from kivy.metrics import dp [as 别名]
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)