OSDN Git Service

library install
[simple-tornado-bot/simple-tornado-bot.git] / linebot / models / rich_menu.py
1 # -*- coding: utf-8 -*-
2
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
6 #
7 #       https://www.apache.org/licenses/LICENSE-2.0
8 #
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
13 #  under the License.
14
15 """linebot.models.rich_menu module."""
16
17 from __future__ import unicode_literals
18
19 from abc import ABCMeta
20
21 from future.utils import with_metaclass
22
23 from .actions import get_action
24 from .base import Base
25
26
27 class RichMenu(with_metaclass(ABCMeta, Base)):
28     """RichMenu.
29
30     https://developers.line.me/en/docs/messaging-api/reference/#rich-menu-object
31     """
32
33     def __init__(self, size=None, selected=None, name=None, chat_bar_text=None,
34                  areas=None, **kwargs):
35         """__init__ method.
36
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`]
48         :param kwargs:
49         """
50         super(RichMenu, self).__init__(**kwargs)
51
52         self.size = self.get_or_new_from_json_dict(size, RichMenuSize)
53         self.selected = selected
54         self.name = name
55         self.chat_bar_text = chat_bar_text
56
57         new_areas = []
58         if areas:
59             for area in areas:
60                 new_areas.append(
61                     self.get_or_new_from_json_dict(area, RichMenuArea)
62                 )
63         self.areas = new_areas
64
65
66 class RichMenuSize(with_metaclass(ABCMeta, Base)):
67     """RichMenuSize.
68
69     https://developers.line.me/en/docs/messaging-api/reference/#size-object
70     """
71
72     def __init__(self, width=None, height=None, **kwargs):
73         """__init__ method.
74
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.
77         :param kwargs:
78         """
79         super(RichMenuSize, self).__init__(**kwargs)
80
81         self.width = width
82         self.height = height
83
84
85 class RichMenuArea(with_metaclass(ABCMeta, Base)):
86     """RichMenuArea.
87
88     https://developers.line.me/en/docs/messaging-api/reference/#area-object
89     """
90
91     def __init__(self, bounds=None, action=None, **kwargs):
92         """__init__ method.
93
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`
98         :param kwargs:
99         """
100         super(RichMenuArea, self).__init__(**kwargs)
101
102         self.bounds = self.get_or_new_from_json_dict(bounds, RichMenuBounds)
103         self.action = get_action(action)
104
105
106 class RichMenuBounds(with_metaclass(ABCMeta, Base)):
107     """RichMenuBounds.
108
109     https://developers.line.me/en/docs/messaging-api/reference/#bounds-object
110     """
111
112     def __init__(self, x=None, y=None, width=None, height=None, **kwargs):
113         """__init__ method.
114
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.
119         :param kwargs:
120         """
121         super(RichMenuBounds, self).__init__(**kwargs)
122
123         self.x = x
124         self.y = y
125         self.width = width
126         self.height = height