[Sugar-devel] question about jarabe/view/palette.py

Tomeu Vizoso tomeu at sugarlabs.org
Mon Jul 12 07:43:13 EDT 2010


On Mon, Jul 12, 2010 at 13:27, Walter Bender <walter.bender at gmail.com> wrote:
> I am experimenting with moving the naming alert to the Frame (as per
> the discussion in this weekend's design meeting.) It seems the place
> to do it is in jarabe/view/palette.py however I cannot seem to
> properly navigate the class hierarchy. My code is pretty simple:
>
>    menu_item = MenuItem(_('Write to Journal'), 'journal-write')
>        menu_item.connect('activate', self.__journal_write__cb)
>        self.menu.append(menu_item)
>        menu_item.show()
>
>    def __journal_write__cb(self, menu_item):
>        title_alert = NamingAlert(self._home_activity, # TODO: what is what?
>                                  self._home_activity.get_bundle_path())
>        title_alert.set_transient_for(self.get_toplevel())
>        title_alert.show()
>        self.reveal()
>
> However self._home_activity is not an activity.
>
> Question: how do I find the activity from _home_activity?

grep should help you find what is what (as long as we keep respecting
the code guidelines):

[tomeu at tresne sugar]$ git grep "_home_activity ="
src/jarabe/desktop/favoritesview.py:        self._home_activity =
self._home_model.get_active_activity()
...
[tomeu at tresne sugar]$ git grep "_home_model ="
src/jarabe/desktop/favoritesview.py:        self._home_model = shell.get_model()
...
[tomeu at tresne sugar]$ git grep "import shell"
extensions/globalkey/screenshot.py:from jarabe.model import shell
...
And if you read jarabe/model/shell.py, you can see that
get_active_activity() returns an instance of a class called "Activity"
defined in this module.

Another way of finding out the class of an instance is adding some
prints to the code where you know this instance is being used:

[tomeu at tresne sugar]$ python
>>> from jarabe.model import shell
>>> a = shell.Activity('', '')
>>> print a
<Activity object at 0x8237d4c (SugarHomeActivity at 0x84bc0d0)>
>>> print a.__module__
jarabe.model.shell

You could also use pdb or ipython to inspect the state at runtime.

We probably should have only one class named Activity in all Sugar,
but given Python's dynamicness you need to find out the class either
by inspecting at runtime or by analysing the source code.

Regards,

Tomeu

> -walter
>
> --
> Walter Bender
> Sugar Labs
> http://www.sugarlabs.org
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


More information about the Sugar-devel mailing list