0
|
1 |
# SMS sending example application
|
|
2 |
|
|
3 |
# Copyright (c) 2005 Nokia Corporation
|
|
4 |
#
|
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6 |
# you may not use this file except in compliance with the License.
|
|
7 |
# You may obtain a copy of the License at
|
|
8 |
#
|
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10 |
#
|
|
11 |
# Unless required by applicable law or agreed to in writing, software
|
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14 |
# See the License for the specific language governing permissions and
|
|
15 |
# limitations under the License.
|
|
16 |
|
|
17 |
|
|
18 |
import appuifw
|
|
19 |
import e32
|
|
20 |
# import messaging
|
|
21 |
|
|
22 |
old_title = appuifw.app.title
|
|
23 |
appuifw.app.title = u"SMS sending"
|
|
24 |
|
|
25 |
|
|
26 |
class NumbersView:
|
|
27 |
def __init__(self, SMS_multiviewApp):
|
|
28 |
self.SMS_multiviewApp = SMS_multiviewApp
|
|
29 |
self.dict = [(u"Jim", "55512345"), (u"Jane", "55567890")]
|
|
30 |
self.names = [item[0] for item in self.dict]
|
|
31 |
self.numbers = [item[1] for item in self.dict]
|
|
32 |
|
|
33 |
self.numbers_list = appuifw.Listbox(self.names, self.handle_select)
|
|
34 |
self.index = None
|
|
35 |
appuifw.app.body = self.numbers_list
|
|
36 |
|
|
37 |
def activate(self):
|
|
38 |
appuifw.app.body = self.numbers_list
|
|
39 |
appuifw.app.menu = [(u"Select", self.handle_select)]
|
|
40 |
|
|
41 |
def handle_select(self):
|
|
42 |
n = self.get_name()
|
|
43 |
appuifw.note(u"Selected: "+ n, 'info')
|
|
44 |
|
|
45 |
def get_current(self):
|
|
46 |
return self.numbers_list.current()
|
|
47 |
|
|
48 |
def get_name(self):
|
|
49 |
i = self.get_current()
|
|
50 |
return self.names[i]
|
|
51 |
|
|
52 |
def get_number(self):
|
|
53 |
i = self.get_current()
|
|
54 |
return self.numbers[i]
|
|
55 |
|
|
56 |
|
|
57 |
class ChoiceView:
|
|
58 |
def __init__(self, SMS_multiviewApp):
|
|
59 |
self.SMS_multiviewApp = SMS_multiviewApp
|
|
60 |
self.texts = [u"I am late",
|
|
61 |
u"What is for dinner?",
|
|
62 |
u"Do you need anything from the supermarket?",
|
|
63 |
u"How about a round of golf after work?"]
|
|
64 |
self.listbox = appuifw.Listbox(self.texts, self.handle_select)
|
|
65 |
|
|
66 |
def activate(self):
|
|
67 |
appuifw.app.body = self.listbox
|
|
68 |
appuifw.app.menu = [(u"Select", self.handle_select),
|
|
69 |
(u"Send", self.handle_send)]
|
|
70 |
|
|
71 |
def handle_select(self):
|
|
72 |
i = self.listbox.current()
|
|
73 |
appuifw.note(u"Selected: " + self.get_text(),'info')
|
|
74 |
|
|
75 |
def handle_send(self):
|
|
76 |
appuifw.app.activate_tab(3)
|
|
77 |
self.SMS_multiviewApp.handle_tab(3)
|
|
78 |
|
|
79 |
def get_text(self):
|
|
80 |
return self.texts[self.listbox.current()]
|
|
81 |
|
|
82 |
|
|
83 |
class TextView:
|
|
84 |
def __init__(self, SMS_multiviewApp):
|
|
85 |
self.SMS_multiviewApp = SMS_multiviewApp
|
|
86 |
self.view_text = appuifw.Text()
|
|
87 |
|
|
88 |
def activate(self):
|
|
89 |
t = self.SMS_multiviewApp.get_text()
|
|
90 |
self.view_text.set(t)
|
|
91 |
appuifw.app.body = self.view_text
|
|
92 |
appuifw.app.menu = [(u"Send", self.handle_send)]
|
|
93 |
self.view_text.focus = True
|
|
94 |
|
|
95 |
def handle_send(self):
|
|
96 |
appuifw.app.activate_tab(3)
|
|
97 |
self.SMS_multiviewApp.handle_tab(3)
|
|
98 |
|
|
99 |
|
|
100 |
class SendView:
|
|
101 |
def __init__(self, SMS_multiviewApp):
|
|
102 |
self.SMS_multiviewApp = SMS_multiviewApp
|
|
103 |
self.log_text = appuifw.Text()
|
|
104 |
self.log_contents = u""
|
|
105 |
|
|
106 |
def activate(self):
|
|
107 |
self.log_text.set(self.log_contents)
|
|
108 |
appuifw.app.body = self.log_text
|
|
109 |
appuifw.app.menu = []
|
|
110 |
nbr = self.SMS_multiviewApp.get_number()
|
|
111 |
txt = self.SMS_multiviewApp.get_text()
|
|
112 |
nam = self.SMS_multiviewApp.get_name()
|
|
113 |
if appuifw.query(u"Send message to " + nam + "?", 'query'):
|
|
114 |
t = u"Sent " + txt + " to " + nbr + " (" + nam + ")\n"
|
|
115 |
self.log_contents += t
|
|
116 |
self.log_text.add(t)
|
|
117 |
# messaging.sms_send(nbr, txt)
|
|
118 |
|
|
119 |
|
|
120 |
class SMS_multiviewApp:
|
|
121 |
def __init__(self):
|
|
122 |
self.lock = e32.Ao_lock()
|
|
123 |
appuifw.app.exit_key_handler = self.exit_key_handler
|
|
124 |
|
|
125 |
self.n_view = NumbersView(self)
|
|
126 |
self.c_view = ChoiceView(self)
|
|
127 |
self.t_view = TextView(self)
|
|
128 |
self.s_view = SendView(self)
|
|
129 |
self.views = [self.n_view, self.c_view, self.t_view, self.s_view]
|
|
130 |
appuifw.app.set_tabs([u"Numbers", u"Choice", u"Text", u"Send"],
|
|
131 |
self.handle_tab)
|
|
132 |
|
|
133 |
def run(self):
|
|
134 |
self.handle_tab(0)
|
|
135 |
self.lock.wait()
|
|
136 |
self.close()
|
|
137 |
|
|
138 |
def get_name(self):
|
|
139 |
return self.n_view.get_name()
|
|
140 |
|
|
141 |
def get_number(self):
|
|
142 |
return self.n_view.get_number()
|
|
143 |
|
|
144 |
def get_text(self):
|
|
145 |
return self.c_view.get_text()
|
|
146 |
|
|
147 |
def handle_tab(self, index):
|
|
148 |
self.views[index].activate()
|
|
149 |
|
|
150 |
def exit_key_handler(self):
|
|
151 |
self.lock.signal()
|
|
152 |
|
|
153 |
def close(self):
|
|
154 |
appuifw.app.exit_key_handler = None
|
|
155 |
appuifw.app.set_tabs([u"Back to normal"], lambda x: None)
|
|
156 |
del self.t_view
|
|
157 |
del self.s_view
|
|
158 |
|
|
159 |
myApp = SMS_multiviewApp()
|
|
160 |
myApp.run()
|
|
161 |
|
|
162 |
appuifw.app.title = old_title
|
|
163 |
appuifw.menu = None
|