1 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
15 """linebot.models.rich_menu module."""
17 from __future__ import unicode_literals
19 from abc import ABCMeta
21 from future.utils import with_metaclass
23 from .actions import get_action
24 from .base import Base
27 class RichMenu(with_metaclass(ABCMeta, Base)):
30 https://developers.line.me/en/docs/messaging-api/reference/#rich-menu-object
33 def __init__(self, size=None, selected=None, name=None, chat_bar_text=None,
34 areas=None, **kwargs):
37 :param size: size object which describe the rich menu displayed in the chat.
38 Rich menu images must be one of the following sizes: 2500x1686, 2500x843.
39 :type size: :py:class:`linebot.models.rich_menu.RichMenuSize`
40 :param bool selected: true to display the rich menu by default. Otherwise, false.
41 :param str name: Name of the rich menu.
42 Maximum of 300 characters.
43 :param str chatBarText: Text displayed in the chat bar.
44 Maximum of 14 characters.
45 :param areas: Array of area objects which define coordinates and size of tappable areas.
46 Maximum of 20 area objects.
47 :type areas: list[T <= :py:class:`linebot.models.rich_menu.RichMenuArea`]
50 super(RichMenu, self).__init__(**kwargs)
52 self.size = self.get_or_new_from_json_dict(size, RichMenuSize)
53 self.selected = selected
55 self.chat_bar_text = chat_bar_text
61 self.get_or_new_from_json_dict(area, RichMenuArea)
63 self.areas = new_areas
66 class RichMenuSize(with_metaclass(ABCMeta, Base)):
69 https://developers.line.me/en/docs/messaging-api/reference/#size-object
72 def __init__(self, width=None, height=None, **kwargs):
75 :param int width: Width of the rich menu. Must be 2500.
76 :param int height: Height of the rich menu. Possible values: 1686, 843.
79 super(RichMenuSize, self).__init__(**kwargs)
85 class RichMenuArea(with_metaclass(ABCMeta, Base)):
88 https://developers.line.me/en/docs/messaging-api/reference/#area-object
91 def __init__(self, bounds=None, action=None, **kwargs):
94 :param bounds: Object describing the boundaries of the area in pixels. See bounds object.
95 :type bounds: :py:class:`linebot.models.rich_menu.RichMenuBound`
96 :param action: Action performed when the area is tapped. See action objects.
97 :type action: T <= :py:class:`linebot.models.actions.Action`
100 super(RichMenuArea, self).__init__(**kwargs)
102 self.bounds = self.get_or_new_from_json_dict(bounds, RichMenuBounds)
103 self.action = get_action(action)
106 class RichMenuBounds(with_metaclass(ABCMeta, Base)):
109 https://developers.line.me/en/docs/messaging-api/reference/#bounds-object
112 def __init__(self, x=None, y=None, width=None, height=None, **kwargs):
115 :param int x: Horizontal position relative to the top-left corner of the area.
116 :param int y: Vertical position relative to the top-left corner of the area.
117 :param int width: Width of the area.
118 :param int height: Height of the area.
121 super(RichMenuBounds, self).__init__(**kwargs)