Archive for May, 2008

Note for brazilian readers: this text was already posted as “GEdit completando código Python automaticamente” and we are making it available in English now.

It’s been a while since I’ve started to develop a plugin to make Gedit able of completing python code. After a while, it became clearer that this was a functionality desired by many users and it is also of interest for the group that keeps the project. Actually, I will be posting this to the wiki of plugins of the GEdit.

So, for this to happen, I decided to take a look at the code used on Vim to complete python codes. For my surprise, that code was also written in python and after some reading, I realized that it could be ported to other text editors. One of the reasons I chose GEdit is that it makes the plugin creation process very easy and understandable by new developers (I recommend the article the Python Plugin How, which explains how to develop plugins for this editor). Using Osmo Salomaa Autocomplete words plugin, made this process even easier.

Long story short, what I did was to connect the two parts: the code for Vim auto-complete (authored by Aaron Griffin) and the code for Autocomplete words (authored by Osmo Salomaa). This is, indeed, a good example of the benefits of free software: providing easy ways for me not having to repeat the work of both authors and rendering me able to use both codes to provide a new for another text editor.

During the trip, which came up being more complicated than expected, I lost many files at my old computer, so the work was stopped until I had the guts to start again. The restart was even better: development was faster and the old errors were quickly solved.

The plugin works on Gedit through the shortcut Ctrl+Alt+Space and allows fast code completing for python scripts and python modules are also supported. Basically, it works the same way it did on Vim, apart from some small adjustments I made in the code. Aaron Griffin alerted me that the code contained some small known problems and that would be corrected soon. I will keep myself up to date with Aaron for the plugin not to become outdated.

This is an alpha version which wasn’t by any means put through rough tests yet. That said, I believe it can already be used but, surely, bugs will come up. I am available to assist whoever is interested on the plugin. On the sequence, there are some screenshots demonstrating the use of the plugin. Today, Gedit has a lot of plugins for Python development, which is taking it nearer to becoming Python development environment. But I still use Vim.

The installation of plugin is relatively easy: the user must unpack the archive into the directory gnome2/gedit/plugins of its home, restart gedit and activate plugin in edit – > preferences – > plugins. This plugin will only work with python code. I hope the community can help on the development and that it makes it more and more usable over time.

Auto in completes code real teams.Show doc strings

The plugin of auto complete Python code is avaliable here.


Read Full Post »

Back Again and PyS60

we are sorry

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()

#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])

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>
        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():
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

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 😀

Read Full Post »