[MouseFox logo]
The MouseFox Project
Join The Community Discord Server
[Discord logo]
Edit on GitHub

kvex.widgets.atlas

A widgets for viewing the textures in the defaulttheme atlas.

  1"""A widgets for viewing the textures in the defaulttheme atlas."""
  2
  3from ..util import from_atlas
  4from .layouts import XStack, XAnchor, XFrame, XBox
  5from .scroll import XScroll
  6from .label import XLabel
  7
  8
  9class XAtlasPreview(XScroll):
 10    """Widget to preview kivy defaulttheme atlas."""
 11
 12    def __init__(self, image_width: float = 100, image_height: float = 100):
 13        """Initialize the class."""
 14        self._image_width = image_width
 15        self._image_height = image_height
 16        super().__init__(view=self._get_stack())
 17        self.on_size()
 18        self.bind(size=self.on_size)
 19        self.register_event_type("on_item")
 20
 21    def on_touch_down(self, touch):
 22        """Dispatch `on_item` event if an item has been clicked."""
 23        consumed = super().on_touch_down(touch)
 24        if consumed:
 25            return consumed
 26        if touch.button != "left":
 27            return False
 28        if not self.collide_point(*touch.pos):
 29            return False
 30        for name, w in self._widgets.items():
 31            if w.collide_point(*w.to_widget(*touch.pos)):
 32                self.dispatch("on_item", name)
 33                return True
 34        return False
 35
 36    def on_item(self, item: str):
 37        """Dispatched when one of the atlas items has been clicked."""
 38        print(f"Atlas item: {item!r}")
 39
 40    def _get_stack(self):
 41        self._widgets = dict()
 42        stack = XStack()
 43        for item in ATLAS_ITEMS:
 44            label = XLabel(text=item, enable_theming=False)
 45            label.set_size(hy=0.5)
 46            image = XAnchor()
 47            image.make_fg(source=from_atlas(item))
 48            image.set_size(self._image_width, self._image_height)
 49            box = XBox(orientation="vertical")
 50            box.add_widgets(label, XAnchor.wrap(image, padding=10))
 51            frame = XFrame.wrap(box)
 52            frame.set_size(image.width + 20, image.height * 2)
 53            # frame.make_bg(
 54            #     XColor.from_name("grey"),
 55            #     source=from_atlas("textinput_active"),
 56            # )
 57            stack.add_widget(frame)
 58            self._widgets[item] = frame
 59        return stack
 60
 61    def on_size(self, *args):
 62        """Adjust view size based on our width and images size."""
 63        per_row = max(1, self.width // (self._image_width * 1.2))
 64        row_count = len(self._widgets) // per_row + 1
 65        self.view.set_size(y=2*self._image_height*row_count)
 66        self.scroll_y = 1
 67
 68
 69ATLAS_ITEMS = (
 70    "action_bar",
 71    "action_group",
 72    "action_group_disabled",
 73    "action_group_down",
 74    "action_item",
 75    "action_item_down",
 76    "action_view",
 77    "audio-volume-high",
 78    "audio-volume-low",
 79    "audio-volume-medium",
 80    "audio-volume-muted",
 81    "bubble",
 82    "bubble_arrow",
 83    "bubble_btn",
 84    "bubble_btn_pressed",
 85    "button",
 86    "button_disabled",
 87    "button_disabled_pressed",
 88    "button_pressed",
 89    "checkbox_disabled_off",
 90    "checkbox_disabled_on",
 91    "checkbox_off",
 92    "checkbox_on",
 93    "checkbox_radio_disabled_off",
 94    "checkbox_radio_disabled_on",
 95    "checkbox_radio_off",
 96    "checkbox_radio_on",
 97    "close",
 98    "filechooser_file",
 99    "filechooser_folder",
100    "filechooser_selected",
101    "image-missing",
102    "media-playback-pause",
103    "media-playback-start",
104    "media-playback-stop",
105    "modalview-background",
106    "overflow",
107    "player-background",
108    "player-play-overlay",
109    "previous_normal",
110    "progressbar",
111    "progressbar_background",
112    "ring",
113    "selector_left",
114    "selector_middle",
115    "selector_right",
116    "separator",
117    "slider_cursor",
118    "slider_cursor_disabled",
119    "sliderh_background",
120    "sliderh_background_disabled",
121    "sliderv_background",
122    "sliderv_background_disabled",
123    "spinner",
124    "spinner_disabled",
125    "spinner_pressed",
126    "splitter",
127    "splitter_disabled",
128    "splitter_disabled_down",
129    "splitter_disabled_down_h",
130    "splitter_disabled_h",
131    "splitter_down",
132    "splitter_down_h",
133    "splitter_grip",
134    "splitter_grip_h",
135    "splitter_h",
136    "switch-background",
137    "switch-background_disabled",
138    "switch-button",
139    "switch-button_disabled",
140    "tab",
141    "tab_btn",
142    "tab_btn_disabled",
143    "tab_btn_disabled_pressed",
144    "tab_btn_pressed",
145    "tab_disabled",
146    "textinput",
147    "textinput_active",
148    "textinput_disabled",
149    "textinput_disabled_active",
150    "tree_closed",
151    "tree_opened",
152    "vkeyboard_background",
153    "vkeyboard_disabled_background",
154    "vkeyboard_disabled_key_down",
155    "vkeyboard_disabled_key_normal",
156    "vkeyboard_key_down",
157    "vkeyboard_key_normal",
158)
159
160
161__all__ = (
162    "XAtlasPreview",
163)
class XAtlasPreview(kvex.widgets.scroll.XScroll):
10class XAtlasPreview(XScroll):
11    """Widget to preview kivy defaulttheme atlas."""
12
13    def __init__(self, image_width: float = 100, image_height: float = 100):
14        """Initialize the class."""
15        self._image_width = image_width
16        self._image_height = image_height
17        super().__init__(view=self._get_stack())
18        self.on_size()
19        self.bind(size=self.on_size)
20        self.register_event_type("on_item")
21
22    def on_touch_down(self, touch):
23        """Dispatch `on_item` event if an item has been clicked."""
24        consumed = super().on_touch_down(touch)
25        if consumed:
26            return consumed
27        if touch.button != "left":
28            return False
29        if not self.collide_point(*touch.pos):
30            return False
31        for name, w in self._widgets.items():
32            if w.collide_point(*w.to_widget(*touch.pos)):
33                self.dispatch("on_item", name)
34                return True
35        return False
36
37    def on_item(self, item: str):
38        """Dispatched when one of the atlas items has been clicked."""
39        print(f"Atlas item: {item!r}")
40
41    def _get_stack(self):
42        self._widgets = dict()
43        stack = XStack()
44        for item in ATLAS_ITEMS:
45            label = XLabel(text=item, enable_theming=False)
46            label.set_size(hy=0.5)
47            image = XAnchor()
48            image.make_fg(source=from_atlas(item))
49            image.set_size(self._image_width, self._image_height)
50            box = XBox(orientation="vertical")
51            box.add_widgets(label, XAnchor.wrap(image, padding=10))
52            frame = XFrame.wrap(box)
53            frame.set_size(image.width + 20, image.height * 2)
54            # frame.make_bg(
55            #     XColor.from_name("grey"),
56            #     source=from_atlas("textinput_active"),
57            # )
58            stack.add_widget(frame)
59            self._widgets[item] = frame
60        return stack
61
62    def on_size(self, *args):
63        """Adjust view size based on our width and images size."""
64        per_row = max(1, self.width // (self._image_width * 1.2))
65        row_count = len(self._widgets) // per_row + 1
66        self.view.set_size(y=2*self._image_height*row_count)
67        self.scroll_y = 1

Widget to preview kivy defaulttheme atlas.

XAtlasPreview(image_width: float = 100, image_height: float = 100)
13    def __init__(self, image_width: float = 100, image_height: float = 100):
14        """Initialize the class."""
15        self._image_width = image_width
16        self._image_height = image_height
17        super().__init__(view=self._get_stack())
18        self.on_size()
19        self.bind(size=self.on_size)
20        self.register_event_type("on_item")

Initialize the class.

def on_touch_down(self, touch):
22    def on_touch_down(self, touch):
23        """Dispatch `on_item` event if an item has been clicked."""
24        consumed = super().on_touch_down(touch)
25        if consumed:
26            return consumed
27        if touch.button != "left":
28            return False
29        if not self.collide_point(*touch.pos):
30            return False
31        for name, w in self._widgets.items():
32            if w.collide_point(*w.to_widget(*touch.pos)):
33                self.dispatch("on_item", name)
34                return True
35        return False

Dispatch on_item event if an item has been clicked.

def on_item(self, item: str):
37    def on_item(self, item: str):
38        """Dispatched when one of the atlas items has been clicked."""
39        print(f"Atlas item: {item!r}")

Dispatched when one of the atlas items has been clicked.

def on_size(self, *args):
62    def on_size(self, *args):
63        """Adjust view size based on our width and images size."""
64        per_row = max(1, self.width // (self._image_width * 1.2))
65        row_count = len(self._widgets) // per_row + 1
66        self.view.set_size(y=2*self._image_height*row_count)
67        self.scroll_y = 1

Adjust view size based on our width and images size.

Inherited Members
kivy.uix.scrollview.ScrollView
scroll_distance
scroll_wheel_distance
scroll_timeout
scroll_x
scroll_y
do_scroll_x
do_scroll_y
always_overscroll
vbar
hbar
bar_color
bar_inactive_color
bar_width
bar_pos_x
bar_pos_y
bar_pos
bar_margin
effect_cls
effect_x
effect_y
viewport_size
smooth_scroll_end
on__viewport
canvas
on_effect_x
on_effect_y
on_effect_cls
to_local
to_parent
simulate_touch_down
on_motion
on_scroll_start
on_touch_move
on_scroll_move
on_touch_up
on_scroll_stop
scroll_to
convert_distance_to_scroll
update_from_scroll
add_widget
remove_widget
kivy.uix.widget.Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_kv_post
clear_widgets
register_for_motion_event
unregister_for_motion_event
export_to_png
export_as_image
get_root_window
get_parent_window
walk
walk_reverse
to_widget
to_window
get_window_matrix
x
y
width
height
pos
size
get_right
set_right
right
get_top
set_top
top
get_center_x
set_center_x
center_x
get_center_y
set_center_y
center_y
center
cls
children
parent
size_hint_x
size_hint_y
size_hint
pos_hint
size_hint_min_x
size_hint_min_y
size_hint_min
size_hint_max_x
size_hint_max_y
size_hint_max
ids
opacity
on_opacity
get_disabled
set_disabled
inc_disabled
dec_disabled
disabled
motion_filter
kivy._event.EventDispatcher
register_event_type
unregister_event_types
unregister_event_type
is_event_type
bind
unbind
fbind
funbind
unbind_uid
get_property_observers
events
dispatch
dispatch_generic
dispatch_children
setter
getter
property
properties
create_property
apply_property