
We, the Linil Team, would like to present our humble apologies for this enormous gap on our blog. Work, College and a lot of other aspects intended to get on the way.
That said, we would also like to let you all know: we are back
So getting back to business, let’s talk about PyS60.
As the idea of this post is not to present a full introduction, it would be good if you all got familiarized with the idea by reading this great article the guys at AllAboutSymbian wrote about it.
So, I bought my N73 on june, 2007. My cellphone plan only covers 50 text messages per month, and I usually pass that limit. One of many reasons this happened on the begining was because S60 platform won’t allow you to separate your messages by month. To keep track of that 50 messages, I needed to erase all my sent messages every first day of each month but I kept forgetting about it what made me pay a lot of extra message taxes.
I installed PyS60 on my phone somewhere between September and October last year, but until last week I still haven’t thought about using it to help solve that problem. So a solution came and it was simple (as Alan Kay says: “Simple things should be simple, complex things should be possible”).
The idea is to look through all the sent messages box and put them into a dictionary, using the months as keys and the number of messages sent on it as values as seen below on part 0 of the code.
#part 0
import inbox
from e32db import format_time
i = inbox.Inbox( inbox.ESent )
m = i.sms_messages()
message_by_time = {}
for message in m:
time_date = format_time(message_time).split(' ')[0]
month = time_date.split('/')[0]
message_time = i.time(message)
year = time_date.split('/')[2]
if not message_by_time.has_key( (year,month) ):
message_by_time[(year,month)] = 0
message_by_time[(year,month)] += 1
The first lines get a list of sent messages (m) and initialize the dictionary I will use. Through the for, all the messages are analyzed and their times are taken and formatted. After that, their years and months are used to create a tuple to index the dictionary and the element associated is incremented. The if test is used to avoid KeyError exceptions and will assign a number to the key if the dictionary doesn’t already has it.
After that, it was all about creating the interface to allow for better user experience. The idea was to provide a menu where the user could see how many messages he sent on the current month and an option to access a list and show how many messages he has sent on all months.
#part 1
k = message_by_time.keys()
k.sort()
#part 2
time_picker_list = []
for x in k:
a = u"%s/%s" % (x[1],x[0])
b = u"%s messages sent" % (message_by_time[x])
time_picker_list.append((a,b))</div>
Part 1 gets the keys of the dictionary (years and months of messages) and sorts them. After that, on part 2, a new list is created to contain pairs of strings (a,b), where ‘a’ stands for strings formatted as yyyy,mm and ‘b’ stands for another string containing the number of messages sent.
#part 3
time_picker = None
def list_handler():
month_year = k[time_picker.current()]
appuifw.note(u"You have sent %d messages on %s/%s" % (message_by_time[month_year], month_year[1], month_year[0]), "info")
#part 4
options = [u"This Month", u"Messages by time"]
options_menu = None
#part 5
def handler_options():
if options_menu.current() == 0 :
appuifw.note(u"You have sent %d messages this month" % (message_by_time[k[-1]]), "info")</div>
else:
global time_picker
time_picker = appuifw.Listbox(time_picker_list, list_handler)
appuifw.app.body = time_picker
appuifw.app.exit_key_handler = exit_picker
#part 6
options_menu = appuifw.Listbox(options, handler_options)
#part 7
def exit_key_handler():
app_lock.signal()
def exit_picker():
appuifw.app.body = options_menu
appuifw.app.exit_key_handler = exit_key_handler</div>
#part 8
app_lock = e32.Ao_lock()
appuifw.app.title = u'SentCounter'
appuifw.app.body = options_menu
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
From part 3, the interface begins to be described. This part defines the function that will be called every time the user selects a month on the list of messages sent through all months. On part 4, the initial menu is defined as a list of two options. Part 5 describes the function that will be called whenever the user select one of the initial menu options. Part 6 creates the menu and part 7 defines the exiting functions, first for when the exit key is pressed on the initial screen and then for when the user presses it on the list of messages by month.
Part 8, at last, creates the application, sets its name and exit functions, and displays it on the screen.
Please be aware that this explanation of PyS60 interface is superficial. For a real better understanding of it, you should take a look at the more than helpful. tutorials.
So the code will be posted in a while (as soon as I get home).
Hope you enjoyed 😀
Leave a comment