class EdgeWidget(Widget): _cost = StringProperty("") _cost_disabled = BooleanProperty(True) _color = ColorProperty(DEFAULT_COLOR) _x1 = NumericProperty() _y1 = NumericProperty() _x2 = NumericProperty() _y2 = NumericProperty() _points = ListProperty() _width = NumericProperty(1) # noinspection PyArgumentList def __init__(self, edge: PathEdge, widget: Widget, node_pair: Tuple[NodeWidget, NodeWidget], show_props: ShowProps, **__: Any) -> None: self._edge = edge self._widget = widget self._node_pair = node_pair self._cost = str(edge.cost) self._node_pair[0].bind(size=self.update_widget_position) self._node_pair[1].bind(size=self.update_widget_position) self._cost_disabled = not show_props.show_edge_costs show_props.bind(_show_edge_costs=self.update_show_edge_cost) edge.observe(self.on_is_final, "is_final") Widget.__init__(self, **__) def update_widget_position(self, _: Any = None, __: Any = None) -> None: node_1, node_2 = self._node_pair self._x1 = node_1._pos_x + node_1._size / 2 self._y1 = node_1._pos_y + node_1._size / 2 self._x2 = node_2._pos_x + node_2._size / 2 self._y2 = node_2._pos_y + node_2._size / 2 xn, yn = DrawingMath.cross_coordinates( # .. self._x1, self._y1, self._x2, self._y2) xm, ym = DrawingMath.cross_coordinates( # .. self._x2, self._y2, self._x1, self._y1) self._points = [xn, yn, xm, ym] def on_is_final(self, change: Dict[str, Any]) -> None: _, _, is_final = TraitletSplitter.split(change) self._color = BLUE_COLOR if is_final else DEFAULT_COLOR def update_show_edge_cost(self, _: Any, x: str) -> None: self._cost_disabled = not bool(x)
class AImage(LoadingBar, ImageButton): kv_file = os.path.join( os.getenv(constants.KV_FOLDER), 'image.kv') background_color = ColorProperty() clickable = BooleanProperty() image_bytes: BytesIO = None image_ext: str = None def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def load_image(self, image: BytesIO, ext: str): self.image_bytes = image self.image_ext = ext self.image_bytes.seek(0) coreimage = CoreImage(self.image_bytes, ext=self.image_ext) self.texture = coreimage.texture self.stop_loading() def reset(self): self.texture = None self.image_ext = None self.image_bytes = None def on_press(self): if self.clickable and self.image_bytes is not None: PImage.open(self.image_bytes).show()
class MDNavigationDrawerDivider(MDBoxLayout): """ Implements a divider for a menu for :class:`~MDNavigationDrawer` class. .. versionadded:: 1.0.0 .. code-block:: kv MDNavigationDrawer: MDNavigationDrawerMenu: MDNavigationDrawerLabel: text: "Mail" MDNavigationDrawerDivider: .. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/navigation-drawer-divider.png :align: center """ padding = VariableListProperty(["20dp", "12dp", 0, "12dp"]) """ Padding between layout box and children: [padding_left, padding_top, padding_right, padding_bottom]. Padding also accepts a two argument form [padding_horizontal, padding_vertical] and a one argument form [padding]. :attr:`padding` is a :class:`~kivy.properties.VariableListProperty` and defaults to `['20dp', '12dp', 0, '12dp']`. """ color = ColorProperty(None) """
class TabbedPanelBase(ThemableBehavior, SpecificBackgroundColorBehavior, BoxLayout): """ A class that contains all variables a :class:`~kivy.properties.TabPannel` must have. It is here so I (zingballyhoo) don't get mad about the :class:`~kivy.properties.TabbedPannels` not being DRY. """ current = StringProperty(None) """ Current tab name. :attr:`current` is an :class:`~kivy.properties.StringProperty` and defaults to `None`. """ previous_tab = ObjectProperty() """ :attr:`previous_tab` is an :class:`~MDTab` and defaults to `None`. """ panel_color = ColorProperty(None) """ Panel color of bottom navigation. :attr:`panel_color` is an :class:`~kivy.properties.ColorProperty` and defaults to `None`. """ tabs = ListProperty()
class Progress_Bar(BoxLayout): """A widget representing a progressbar consisting of 20 seperate pieces \n Type:BoxLayout Uses Color_Block class \n Parameters: \n active_blocks: NumericProperty(how many out of 20 blocks will be lit) color: ColorProperty(list of 3 or 4 floats between (0.0-1.0) representing [red,green,blue,alpha]) orientation: OptionProperty inherited from BoxLayout, defaults to ‘horizontal’. Can be ‘vertical’ or ‘horizontal\n Update Functionality: Changing the value of active blocks automatically updates the active color blocks """ active_blocks = NumericProperty() color = ColorProperty() def __init__(self, **kwargs): super(Progress_Bar, self).__init__(**kwargs) #widgets go in reverse self.add_widget(Color_Block(color=[1, 0, 0, 1])) for i in range(18, -1, -1): self.add_widget(Color_Block(color=self.color)) self.bind(active_blocks=self.update_active) def update_active(self, obj, value): s = value for i in self.children: a = 1 if s > 0 else 0 i.opacity = a s -= 1
class CupertinoSymbol(Label): """ Display an iOS style symbol. .. image:: ../_static/symbol.png """ symbol = StringProperty(' ') """ A :class:`~kivy.properties.StringProperty` defining the symbol to be displayed by :class:`~kivycupertino.uix.symbol.CupertinoSymbol`. """ color = ColorProperty([0, 0, 0, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the color of :class:`~kivycupertino.uix.symbol.CupertinoSymbol` """ def on_symbol(self, widget, symbol): """ Callback when symbol of :class:`~kivy.uix.symbol.CupertinoSymbol` is changed :param widget: Instance of :class:`~kivy.uix.symbol.CupertinoSymbol` :param symbol: Symbol to be displayed """ with open(root_path + 'symbols.json', 'r') as json: symbols = load(json) self.text = chr(eval(symbols[symbol])) if symbol != ' ' else '\u2800'
class SmartTileWithLabel(SmartTile): font_style = StringProperty("Caption") """ Tile font style. :attr:`font_style` is a :class:`~kivy.properties.StringProperty` and defaults to `'Caption'`. """ tile_text_color = ColorProperty((1, 1, 1, 1)) """ Tile text color in ``rgba`` format. :attr:`tile_text_color` is a :class:`~kivy.properties.ColorProperty` and defaults to `(1, 1, 1, 1)`. """ text = StringProperty() """ Determines the text for the box `footer/header`. :attr:`text` is a :class:`~kivy.properties.StringProperty` and defaults to `''`. """ _box_label = ObjectProperty()
class PresenceSelector(RelativeLayout, PresenceColor): background_color = ColorProperty([0, 0, 0, 1]) """Background color, in the format (r, g, b, a). :attr:`background_color` is a :class:`~kivy.properties.ColorProperty` and defaults to [1, 1, 1, 1]. """ border_color = ColorProperty([77 / 256, 77 / 256, 76 / 256, 1]) """Border color, in the format (r, g, b, a). :attr:`border_color` is a :class:`~kivy.properties.ColorProperty` and defaults to [77 / 256, 77 / 256, 76 / 256, 1]. """ text_color = ColorProperty([249 / 256, 176 / 256, 0 / 256, 1]) """Border color, in the format (r, g, b, a). :attr:`text_color` is a :class:`~kivy.properties.ColorProperty` and defaults to [249 / 256, 176 / 256, 0 / 256, 1]. """ active_presence = StringProperty(None) requested_presence = StringProperty(None) _ind_circle_color = ColorProperty([0, 0, 0, 1]) _btn_absent_color = ColorProperty([0, 0, 0, 1]) _btn_present_color = ColorProperty([0, 0, 0, 1]) _btn_occupied_color = ColorProperty([0, 0, 0, 1]) _btn_away_color = ColorProperty([0, 0, 0, 1]) def __init__(self, **kwargs): super(PresenceSelector, self).__init__(**kwargs) self.bind(active_presence=self._update_active_presence_color) self.bind(requested_presence=self._update_requested_presence_color) def _update_active_presence_color(self, instance, value): c = self.color_for(value) if c is None: c = self.background_color instance._ind_circle_color = c def _update_requested_presence_color(self, instance, value): instance._btn_absent_color = [0, 0, 0, 1] instance._btn_present_color = [0, 0, 0, 1] instance._btn_occupied_color = [0, 0, 0, 1] instance._btn_away_color = [0, 0, 0, 1] if value == "present": instance._btn_present_color = self.present_color_rgba elif value == "occupied": instance._btn_occupied_color = self.occupied_color_rgba elif value == "away": instance._btn_away_color = self.away_color_rgba elif value == "absent": instance._btn_absent_color = self.absent_color_rgba
class MDTabsLabel(ToggleButtonBehavior, RectangularRippleBehavior, MDLabel): """This class it represent the label of each tab.""" text_color_normal = ColorProperty(None) text_color_active = ColorProperty(None) tab = ObjectProperty() tab_bar = ObjectProperty() font_name = StringProperty("Roboto") def __init__(self, **kwargs): self.split_str = " ,-" super().__init__(**kwargs) self.max_lines = 2 self.size_hint_x = None self.size_hint_min_x = dp(90) self.min_space = dp(98) self.bind(text=self._update_text_size, ) def on_release(self) -> NoReturn: self.tab_bar.parent.dispatch("on_tab_switch", self.tab, self, self.text) # If the label is selected load the relative tab from carousel. if self.state == "down": self.tab_bar.parent.carousel.load_slide(self.tab) def on_texture(self, instance_tabs_label, texture: Texture) -> NoReturn: # Just save the minimum width of the label based of the content. if texture: max_width = dp(360) min_width = dp(90) if texture.width > max_width: self.width = max_width self.text_size = (max_width, None) elif texture.width < min_width: self.width = min_width else: self.width = texture.width def _update_text_size(self, *args): if not self.tab_bar: return if self.tab_bar.parent.allow_stretch is True: self.text_size = (None, None) else: self.width = self.tab_bar.parent.fixed_tab_label_width self.text_size = (self.width, None) Clock.schedule_once(self.tab_bar._label_request_indicator_update, 0)
class CircularMilitaryHourPicker(FloatLayout): am = ObjectProperty() pm = ObjectProperty() inner_clock_percent = NumericProperty(1) selected = NumericProperty(12) selector_alpha = NumericProperty(0.3) selector_color = ColorProperty([1, 1, 1, 1]) color = ListProperty([0, 0, 0]) scale = NumericProperty(1) _grabed_clock = None def __init__(self, **kwargs): super().__init__(**kwargs) Clock.schedule_once(self._update) def _update(self, *args): self.pm.bind(selected=self._set_selected) self.am.bind(selected=self._set_selected) self.am.selector_alpha = self.selector_alpha def on_touch_down(self, touch): if self.pm.collide_point(*touch.pos): self._select_pm(touch) else: self._select_am(touch) def _select_pm(self, touch): self.pm.selector_alpha = 0.3 self.am.selector_alpha = 0 self._grabed_clock = self.pm self.pm.on_touch_down(touch) def _select_am(self, touch): self.pm.selector_alpha = 0 self.am.selector_alpha = 0.3 self._grabed_clock = self.am self.am.on_touch_down(touch) def _set_selected(self, instance, selected): self.selected = self._grabed_clock.selected def on_touch_up(self, touch): if self._grabed_clock == self.pm: self.selected = self.pm.selected elif self._grabed_clock == self.am: self.selected = self.am.selected else: pass self._grabed_clock = None return super().on_touch_up(touch) def on_touch_move(self, touch): if self.pm.collide_point(*touch.pos): self._select_pm(touch) self.am.selected += 1 else: self._select_am(touch) self.am.selected -= 1
class SmartTile( ThemableBehavior, RectangularRippleBehavior, ButtonBehavior, MDFloatLayout ): """ A tile for more complex needs. Includes an image, a container to place overlays and a box that can act as a header or a footer, as described in the Material Design specs. """ box_color = ColorProperty((0, 0, 0, 0.5)) """ Sets the color and opacity for the information box. :attr:`box_color` is a :class:`~kivy.properties.ColorProperty` and defaults to `(0, 0, 0, 0.5)`. """ box_position = OptionProperty("footer", options=["footer", "header"]) """ Determines wether the information box acts as a header or footer to the image. Available are options: `'footer'`, `'header'`. :attr:`box_position` is a :class:`~kivy.properties.OptionProperty` and defaults to `'footer'`. """ lines = OptionProperty(1, options=[1, 2]) """ Number of lines in the `header/footer`. As per `Material Design specs`, only 1 and 2 are valid values. Available are options: ``1``, ``2``. :attr:`lines` is a :class:`~kivy.properties.OptionProperty` and defaults to `1`. """ overlap = BooleanProperty(True) """ Determines if the `header/footer` overlaps on top of the image or not. :attr:`overlap` is a :class:`~kivy.properties.BooleanProperty` and defaults to `True`. """ source = StringProperty() """ Path to tile image. See :attr:`~kivy.uix.image.Image.source`. :attr:`source` is a :class:`~kivy.properties.StringProperty` and defaults to `''`. """ _img_widget = ObjectProperty() _img_overlay = ObjectProperty() _box_overlay = ObjectProperty() _box_label = ObjectProperty() def reload(self): self._img_widget.reload()
class MDTextFieldRect(ThemableBehavior, TextInput): line_anim = BooleanProperty(True) """ If True, then text field shows animated line when on focus. :attr:`line_anim` is an :class:`~kivy.properties.BooleanProperty` and defaults to `True`. """ def get_rect_instruction(self): canvas_instructions = self.canvas.after.get_group("rectangle") return canvas_instructions[0] _rectangle = AliasProperty(get_rect_instruction, cache=True) """ It is the :class:`~kivy.graphics.vertex_instructions.Line` instruction reference of the field rectangle. :attr:`_rectangle` is an :class:`~kivy.properties.AliasProperty`. """ def get_color_instruction(self): canvas_instructions = self.canvas.after.get_group("color") return canvas_instructions[0] _rectangle_color = AliasProperty(get_color_instruction, cache=True) """ It is the :class:`~kivy.graphics.context_instructions.Color` instruction reference of the field rectangle. :attr:`_rectangle_color` is an :class:`~kivy.properties.AliasProperty`. """ _primary_color = ColorProperty((0, 0, 0, 0)) def __init__(self, **kwargs): super().__init__(**kwargs) self._update_primary_color() self.theme_cls.bind(primary_color=self._update_primary_color) def anim_rect(self, points, alpha): if alpha == 1: d_line = 0.3 d_color = 0.4 else: d_line = 0.05 d_color = 0.05 Animation( points=points, d=(d_line if self.line_anim else 0), t="out_cubic" ).start(self._rectangle) Animation(a=alpha, d=(d_color if self.line_anim else 0)).start( self._rectangle_color ) def _update_primary_color(self, *args): self._primary_color = self.theme_cls.primary_color self._primary_color[3] = 0
class ContextButton(Button): notify_state = OptionProperty( "None", options=["None", "Info", "Warning", "Critical", "Alert"]) notify_colors = { "None": [0 / 256, 0 / 256, 0 / 256, 1], "Info": [0 / 256, 132 / 256, 176 / 256, 1], "Warning": [249 / 256, 176 / 256, 0 / 256, 1], "Critical": [228 / 256, 5 / 256, 41 / 256, 1], "Alert": [228 / 256, 5 / 256, 41 / 256, 1] } def on_notify_state(self, _instance, value): if value == "Alert": self._notify_color = [0, 0, 0, 0] self._alert_anim.start(self) else: self._alert_anim.cancel(self) self._notify_color = self.notify_colors[value] _notify_color = ColorProperty() icon_active_color = ColorProperty([249 / 256, 176 / 256, 0 / 256, 1]) icon_inactive_color = ColorProperty([77 / 256, 77 / 256, 76 / 256, 1]) icon_path = StringProperty(None) active = BooleanProperty(False) index = NumericProperty(0) def __init__(self, icon_path=None, **kwargs): self.icon_path = icon_path # Alert animation anim_in = Animation(_notify_color=[228 / 256, 5 / 256, 41 / 256, 1], duration=1., t='out_cubic') anim_out = Animation(_notify_color=[228 / 256, 5 / 256, 41 / 256, 0], duration=1., t='in_cubic') self._alert_anim = anim_in + anim_out self._alert_anim.repeat = True super(Button, self).__init__(**kwargs, text="") self.on_notify_state(self, "None")
class ThemeManager(EventDispatcher): primary_color = ColorProperty("684bbf") primary_light = ColorProperty("9b78f2") primary_dark = ColorProperty("34218e") bg_normal = ColorProperty() bg_light = ColorProperty() bg_dark = ColorProperty() text_color = ColorProperty() theme_style = OptionProperty("Light", options=["Light", "Dark"]) def on_theme_style(self, instance, value): Window.clearcolor = gch("FAFAFA" if value == "Light" else "121212") if value == "Light": self.text_color = "000000" self.bg_light = "ffffff" self.bg_dark = "c7c7c7" self.bg_normal = "FAFAFA" else: self.text_color = "FFFFFF" self.bg_light = "383838" self.bg_dark = "000000" self.bg_normal = "121212" def __init__(self, **kwargs): super().__init__(**kwargs) font_definitions.register_fonts() Clock.schedule_once( lambda x: self.on_theme_style(None, self.theme_style))
class Pair(StackLayout): "Paire clé/valeur d'un tableau" key = StringProperty() value = NumericProperty() color = ColorProperty([1, 1, 1]) def __init__(self, key: str, value: int, **kwargs): super().__init__(key=key, value=value, **kwargs)
class CupertinoSymbol(Label): """ Display an iOS style symbol. .. image:: ../_static/symbol/demo.png """ symbol = StringProperty(' ') """ Symbol to be displayed by :class:`CupertinoSymbol`. .. image:: ../_static/symbol/symbol.png **Python** .. code-block:: python CupertinoSymbol(symbol='alarm_fill') **KV** .. code-block:: CupertinoSymbol: symbol: 'alarm_fill' """ color = ColorProperty([0, 0, 0, 1]) """ Color of :class:`CupertinoSymbol` .. image:: ../_static/symbol/color.png **Python** .. code-block:: python CupertinoSymbol(color=(1, 0, 0, 1)) **KV** .. code-block:: CupertinoSymbol: color: 1, 0, 0, 1 """ def on_symbol(self, instance, symbol): """ Callback when symbol of :class:`~kivy.uix.symbol.CupertinoSymbol` is changed :param instance: Instance of :class:`CupertinoSymbol` :param symbol: Symbol to be displayed """ with open(root_path + 'symbols.json', 'r') as json: symbols = load(json) self.text = chr(symbols[symbol]) if symbol != ' ' else '\u2800'
class _CupertinoScreen(ButtonBehavior, Widget): """ Dot to be added to :class:`CupertinoPageControls` indicating a screen on :class:`CupertinoScreenManager` """ selected = BooleanProperty(False) """ If the screen represented by :class:`_CupertinoScreen` is currently selected """ color_selected = ColorProperty() """ Color of :class:`_CupertinoScreen` when selected """ color_unselected = ColorProperty() """
class CupertinoSwitch(ButtonBehavior, Widget): """ iOS style Switch. To comply with iOS standard, keep the width to height ratio of :class:`~kivycupertino.uix.switch.CupertinoSwitch` at 2:1 .. image:: ../_static/switch.gif """ toggled = BooleanProperty(False) """ A :class:`~kivy.properties.BooleanProperty` defining if :class:`~kivycupertino.uix.switch.CupertinoSwitch` is on """ thumb_color = ColorProperty([1, 1, 1, 1]) """ A :class:`~kivy.properties.ColorProperty` that degines the color of thumb of :class:`~kivycupertino.uix.switch.CupertinoSwitch` """ background_toggled = ColorProperty([0.3, 0.85, 0.4, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the background color of :class:`~kivycupertino.uix.switch.CupertinoSwitch` when on """ background_untoggled = ColorProperty([0.95, 0.95, 0.95, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the background color of :class:`~kivycupertino.uix.switch.CupertinoSwitch` when off """ padding = NumericProperty(2) """ A :class:`~kivy.properties.ColorProperty` defining the padding around the thumb of :class:`~kivycupertino.uix.switch.CupertinoSwitch` """ def on_press(self): """ Callback when :class:`~kivycupertino.uix.switch.CupertinoSwitch` is pressed """ self.toggled = not self.toggled
class FinishPage(Screen): primary_color = ColorProperty() def __init__(self,contents, **kw): super().__init__(**kw) for index, content in contents.items(): item = Item(content) if "has_answer" in content: self.ids.boxs.add_widget(item)
class CupertinoToolbar(FloatLayout): """ iOS style Toolbar. :class:`~kivycupertino.uix.bar.CupertinoToolbar` is a :class:`~kivy.uix.floatlayout.FloatLayout` and can accept any number of widgets .. image:: ../_static/toolbar.png """ color = ColorProperty([0.95, 0.95, 0.95, 1]) """
class Arrow(Widget): clr = ColorProperty((1, 2 / 3, 0, 0.8)) tileTo = ObjectProperty(None, rebind=True) tileFrom = ObjectProperty(None, rebind=True) vertical = BooleanProperty(False) horizontal = BooleanProperty(False) diagonal = BooleanProperty(False) rotated = BooleanProperty(False) # defines the angles function of the horizontal and vertical flip (in this order) diagonalAngle = [[45, -45], [135, 225]]
class TrayIcon(RelativeLayout): label = StringProperty(None) icon = StringProperty(None) icon_color = ColorProperty([77 / 256, 77 / 256, 76 / 256, 1]) def __init__(self, label=None, icon=None, **kwargs): self.label = label self.icon = icon super(RelativeLayout, self).__init__(**kwargs)
class CupertinoNavigationBar(RelativeLayout): """ iOS style Navigation Bar. :class:`CupertinoNavigationBar` is a :class:`~kivy.uix.relativelayout.RelativeLayout` and can accept any number of widgets .. image:: ../_static/navigation_bar/demo.png """ color = ColorProperty([0.95, 0.95, 0.95, 1]) """
class HotReloadErrorText(ThemableBehavior, ScrollView): text = StringProperty() """Text errors. :attr:`text` is an :class:`~kivy.properties.StringProperty` and defaults to `''`. """ errors_text_color = ColorProperty(None) """
def test_color_property(self): from kivy.properties import ColorProperty color = ColorProperty() color.link(wid, 'color') color.link_deps(wid, 'color') self.assertEqual(color.get(wid), [1, 1, 1, 1]) color2 = ColorProperty() color2.link(wid, 'color2') color2.link_deps(wid, 'color2') self.assertEqual(color2.get(wid), [1, 1, 1, 1]) color.set(wid, 'yellow') self.assertEqual(color.get(wid), [1.0, 1.0, 0.0, 1.0]) color.set(wid, "#00ff00") self.assertEqual(color.get(wid), [0, 1, 0, 1]) color.set(wid, "#7f7fff7f") self.assertEqual(color.get(wid)[0], 127 / 255.) self.assertEqual(color.get(wid)[1], 127 / 255.) self.assertEqual(color.get(wid)[2], 1) self.assertEqual(color.get(wid)[3], 127 / 255.) color.set(wid, (1, 1, 0)) self.assertEqual(color.get(wid), [1, 1, 0, 1]) color.set(wid, (1, 1, 0, 0)) self.assertEqual(color.get(wid), [1, 1, 0, 0]) color.set(wid, [1, 1, 1, 1]) color_value = color.get(wid) color_value[0] = 0.5 self.assertEqual(color.get(wid), [0.5, 1, 1, 1]) self.assertEqual(color2.get(wid), [1, 1, 1, 1]) color2.set(wid, color.get(wid)) self.assertEqual(color2.get(wid), [0.5, 1, 1, 1]) color.set(wid, [1, 1, 1, 1]) color_value = color.get(wid) color_value[:] = [0, 1, 0, 1] self.assertEqual(color.get(wid), [0, 1, 0, 1])
class FlexTreeViewNode(object): def __init__(self, **kwargs): if self.__class__ is FlexTreeViewNode: raise TreeViewException( 'You cannot use directly FlexTreeViewNode.') super(FlexTreeViewNode, self).__init__(**kwargs) is_leaf = BooleanProperty(True) is_open = BooleanProperty(False) is_loaded = BooleanProperty(False) is_selected = BooleanProperty(False) no_selection = BooleanProperty(False) nodes = ListProperty([]) parent_node = ObjectProperty(None, allownone=True) level = NumericProperty(-1) color_selected = ColorProperty([.3, .3, .3, 1.]) odd = BooleanProperty(False) odd_color = ColorProperty([1., 1., 1., .0]) even_color = ColorProperty([0.5, 0.5, 0.5, 0.1])
class Debris(SpaceObject): rotation = NumericProperty(0) velocity = Velocity() size = NumericProperty(100) default_colour = 0.6, 0.65, 1, 0.5 colour = ColorProperty(default_colour) destroyed: bool = False mass = NumericProperty(100) def __init__(self, position: Vector, rotation: int = 0, size: int = 100, **kwargs): super().__init__(**kwargs) self.center = tuple(position) self.rotation = rotation self.size = size * Scale.width_factor # Scales to screen size self.mass = size def highlight(self, colour=(0.8, 0.9, 1, 0.6)): self.colour = colour def remove_highlight(self): self.colour = self.default_colour @property def position(self): return Point(self.center_x, self.center_y) @position.setter def position(self, pos: Point): self.center_x, self.center_y = pos def move(self, dt=1, ds=0) -> Displacement: displacement = self.velocity.to_displacement(dt) self.center_x += displacement.x self.center_y += displacement.y - ds return displacement def destruct(self, t=0.2): self.destroyed = True anim = Animation(a=0, duration=t) anim.start(self.canvas.children[1]) @property def points(self): return ( Point(*point).rotate_about(Point(*self.center), self.rotation) for point in zip(self.canvas.children[3].points[::2], self.canvas.children[3].points[1::2]) ) @property def target_points(self): for point, next_point in zip(self.points, list(self.points)[1:]): yield point yield (point + next_point) / 2 yield next_point yield (next_point + next(self.points)) / 2
class Parametric_Bar(FloatLayout): """A widget facilitating a parametric progressbar consisting of 20 seperate pieces \n Type:FloatLayout Uses Progress_Bar class \n Parameters: \n name: StringProperty value: NumericProperty max_value: NumericProperty active_blocks: NumericProperty(how many out of 20 blocks will be lit) color: ColorProperty(list of 3 or 4 floats between (0.0-1.0) representing [red,green,blue,alpha]) orientation: OptionProperty inherited from BoxLayout, defaults to ‘horizontal’. Can be ‘vertical’ or ‘horizontal\n Update Functionality: Changing the value of value automatically updates the active_blocks and triggers an update of the actual progressbar. """ name = StringProperty() value = NumericProperty() max_value = NumericProperty() orientation = StringProperty() color = ColorProperty() active_blocks = NumericProperty() def __init__(self, **kwargs): super(Parametric_Bar, self).__init__(**kwargs) #calculating active sectors (x/20) self.active_blocks = (self.value * 20) / self.max_value #setting up widgets self.label = Label(text=self.name, pos_hint={ "x": 0, "y": 0 }, size_hint=(1, 0.1)) self.progress = Progress_Bar(pos_hint={ "x": 0, "y": 0.15 }, size_hint=(0.5, 0.9), orientation=self.orientation, color=self.color, active_blocks=self.active_blocks) #adding widgets self.add_widget(self.label) self.add_widget(self.progress) self.bind(value=self.update) #for testing, random def update(self, obj, value): self.active_blocks = (self.value * 20) / self.max_value self.progress.active_blocks = self.active_blocks
class CupertinoStepper(BoxLayout): """ iOS style Stepper .. image:: ../_static/stepper.gif """ color_normal = ColorProperty([0.95, 0.95, 0.95, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the background color of button of :class:`~kivycupertino.uix.control.CupertinoStepper` when not pressed """ color_down = ColorProperty([0.8, 0.8, 0.8, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the background color of button of :class:`~kivycupertino.uix.control.CupertinoStepper` when pressed """ text_color = ColorProperty([0, 0, 0, 1]) """ A :class:`~kivy.properties.ColorProperty` defining the color of text of button of :class:`~kivycupertino.uix.control.CupertinoStepper` """ def __init__(self, **kwargs): """ Initialize :class:`~kivycupertino.uix.control.CupertinoStepper` and register events :param kwargs: Keyword arguments of :class:`~kivycupertino.uix.control.CupertinoStepper` """ super().__init__(**kwargs) self.register_event_type('on_minus') self.register_event_type('on_plus') def on_minus(self): """ Callback when minus button is pressed """ def on_plus(self): """
class TimeInput(MDRelativeLayout): """Implements two text fields for displaying and entering a time value.""" bg_color = ColorProperty() bg_color_active = ColorProperty() text_color = ColorProperty() disabled = BooleanProperty(True) minute_radius = ListProperty([0, 0, 0, 0]) hour_radius = ListProperty([0, 0, 0, 0]) state = StringProperty("hour") _hour = ObjectProperty() _minute = ObjectProperty() def __init__(self, **kwargs): super().__init__(**kwargs) self.register_event_type("on_time_input") self.register_event_type("on_hour_select") self.register_event_type("on_minute_select") def set_time(self, time_list) -> None: hour, minute = time_list self._hour.text = hour self._minute.text = minute def get_time(self) -> list[str, str]: hour = self._hour.text.strip() minute = self._minute.text.strip() return [hour, minute] def on_time_input(self, *args) -> None: pass def on_minute_select(self, *args) -> None: pass def on_hour_select(self, *args) -> None: pass def _update_padding(self, *args): self._hour.set_text() self._minute.set_text()