Package groupthink :: Module sugar_tools :: Class GroupActivity
[hide private]
[frames] | no frames]

Class GroupActivity

source code

        object --+                                
                 |                                
        ??.GObject --+                            
                     |                            
            gtk.Object --+                        
                         |                        
        object --+       |                        
                 |       |                        
gobject.GInterface --+   |                        
                     |   |                        
  atk.ImplementorIface --+                        
                         |                        
        object --+       |                        
                 |       |                        
gobject.GInterface --+   |                        
                     |   |                        
         gtk.Buildable --+                        
                         |                        
                gtk.Widget --+                    
                             |                    
                 gtk.Container --+                
                                 |                
                           gtk.Bin --+            
                                     |            
                            gtk.Window --+        
                                         |        
              sugar.graphics.window.Window --+    
                                             |    
                    object --+               |    
                             |               |    
                    ??.GObject --+           |    
                                 |           |    
                        gtk.Object --+       |    
                                     |       |    
                    object --+       |       |    
                             |       |       |    
            gobject.GInterface --+   |       |    
                                 |   |       |    
              atk.ImplementorIface --+       |    
                                     |       |    
                    object --+       |       |    
                             |       |       |    
            gobject.GInterface --+   |       |    
                                 |   |       |    
                     gtk.Buildable --+       |    
                                     |       |    
                            gtk.Widget --+   |    
                                         |   |    
                             gtk.Container --+    
                                             |    
              sugar.activity.activity.Activity --+
                                                 |
                                                GroupActivity

An abstract class for Activities using Groupthink. Activity authors who are writing a shared Activity should consider inheriting from GroupActivity instead of Sugar's standard Activity class. GroupActivity automates (and hides) handling of Telepathy tubes. It also initializes a Group and a TimeHandler allowing shared activities to be written with minimal boilerplate. For example, the following is a working shared text editor using GroupActivity:

   from groupthink import sugar_tools, gtk_tools
   import sugar
   class SharedTextDemoActivity(sugar_tools.GroupActivity):
       def initialize_display(self):
           self.cloud.textview = gtk_tools.SharedTextView()
           return self.cloud.textview

In addition to sharing code, GroupActivity also provides subclasses with more informative startup screens and optionally automated save/load to the datastore.

Caution: The methods required of a subclass of GroupActivity differ substantially from the methods required of a subclass of Activity. For example, subclasses of GroupActivity typically do not need to implement a __init__ method.

Instance Methods [hide private]
 
__init__(self, handle)
Initialise the Activity
source code
 
_initialize_cleanstart(self) source code
 
initialize_cleanstart(self)
Any subclass that needs to take any extra action in the case where the activity is launched locally without a sharing context or input file should override this method
source code
 
early_setup(self)
Any subclass that needs to take an action before any external interaction (e.g.
source code
 
_initialize_display(self) source code
gtk.Widget
initialize_display(self)
All subclasses must override this method, which is the principal means of initializing a GroupActivity.
source code
 
share(self, private=False)
The purpose of this function is solely to permit us to determine whether share() has been called.
source code
 
when_shared(self)
Inheritors should override this method to perform any special operations when the user shares the session
source code
 
when_initiating_sharing(self)
Inheritors should override this method to perform any special operations upon initiating sharing.
source code
 
_shared_cb(self, activity) source code
 
_sharing_setup(self) source code
 
_list_tubes_reply_cb(self, tubes) source code
 
_list_tubes_error_cb(self, e) source code
 
_joined_cb(self, activity) source code
 
_new_tube_cb(self, id, initiator, type, service, params, state) source code
 
read_file(self, file_path)
Subclasses implement this method if they support resuming objects from the journal.
source code
str
load_from_journal(self, file_path)
Inheritors wishing to control file saving should override this method.
source code
 
write_file(self, file_path)
Subclasses implement this method if they support saving data to objects in the journal.
source code
 
save_to_journal(self, file_path, cloudstring)
Any inheritor who wishes to control file output should override this method, and must be sure to include cloudstring in its write_file.
source code
 
_active_cb(self, widget, event) source code
 
_visible_cb(self, widget, event) source code
 
pause(self)
This method will be called when the display is not visible.
source code
 
resume(self)
This method will be called when the display becomes visible.
source code

Inherited from sugar.activity.activity.Activity: can_close, close, copy, do_get_property, do_set_property, get_active, get_activity_root, get_bundle_id, get_document_path, get_id, get_max_participants, get_metadata, get_preview, get_shared, get_shared_activity, handle_view_source, invite, save, set_active, set_canvas, set_max_participants

Inherited from sugar.activity.activity.Activity (private): _cleanup_jobject, _complete_close, _get_buddies, _invite_response_cb, _keep_failed_dialog_response_cb, _prepare_close, _send_invites, _show_keep_failed_dialog

Inherited from sugar.graphics.window.Window: add_alert, get_enable_fullscreen_mode, remove_alert, set_enable_fullscreen_mode, set_toolbox, set_tray

Inherited from gtk.Window: __iter__, activate_default, activate_focus, activate_key, add_accel_group, add_mnemonic, begin_move_drag, begin_resize_drag, deiconify, do_activate_default, do_activate_focus, do_frame_event, do_keys_changed, do_move_focus, do_set_focus, fullscreen, get_accept_focus, get_decorated, get_default_size, get_default_widget, get_deletable, get_destroy_with_parent, get_focus, get_focus_on_map, get_frame_dimensions, get_gravity, get_group, get_has_frame, get_icon, get_icon_list, get_icon_name, get_mnemonic_modifier, get_modal, get_opacity, get_position, get_resizable, get_role, get_screen, get_size, get_skip_pager_hint, get_skip_taskbar_hint, get_title, get_transient_for, get_type_hint, get_urgency_hint, has_toplevel_focus, iconify, is_active, maximize, mnemonic_activate, move, parse_geometry, present, present_with_time, propagate_key_event, remove_accel_group, remove_mnemonic, reshow_with_initial_size, resize, set_accept_focus, set_decorated, set_default, set_default_size, set_deletable, set_destroy_with_parent, set_focus, set_focus_on_map, set_frame_dimensions, set_geometry_hints, set_gravity, set_has_frame, set_icon, set_icon_from_file, set_icon_list, set_icon_name, set_keep_above, set_keep_below, set_mnemonic_modifier, set_modal, set_opacity, set_policy, set_position, set_resizable, set_role, set_screen, set_skip_pager_hint, set_skip_taskbar_hint, set_startup_id, set_title, set_transient_for, set_type_hint, set_urgency_hint, set_wmclass, stick, tooltips_get_info_from_tip_window, unfullscreen, unmaximize, unstick

Inherited from gtk.Bin: get_child

Inherited from gtk.Container: __len__, __nonzero__, add, add_with_properties, check_resize, child_get, child_get_property, child_set, child_set_property, child_type, children, do_add, do_check_resize, do_child_type, do_composite_name, do_forall, do_get_child_property, do_remove, do_set_child_property, do_set_focus_child, forall, foreach, get_border_width, get_children, get_focus_chain, get_focus_child, get_focus_hadjustment, get_focus_vadjustment, get_resize_mode, install_child_property, list_child_properties, propagate_expose, remove, resize_children, set_border_width, set_focus_chain, set_focus_child, set_focus_hadjustment, set_focus_vadjustment, set_reallocate_redraws, set_resize_mode, unset_focus_chain

Inherited from gtk.Widget: activate, add_accelerator, add_events, add_mnemonic_label, can_activate_accel, child_focus, child_notify, class_path, create_pango_context, create_pango_layout, destroy, do_button_press_event, do_button_release_event, do_can_activate_accel, do_client_event, do_composited_changed, do_configure_event, do_delete_event, do_destroy_event, do_direction_changed, do_drag_begin, do_drag_data_delete, do_drag_data_get, do_drag_data_received, do_drag_drop, do_drag_end, do_drag_leave, do_drag_motion, do_enter_notify_event, do_event, do_expose_event, do_focus, do_focus_in_event, do_focus_out_event, do_get_accessible, do_grab_broken_event, do_grab_focus, do_grab_notify, do_hide, do_hide_all, do_hierarchy_changed, do_key_press_event, do_key_release_event, do_leave_notify_event, do_map, do_map_event, do_mnemonic_activate, do_motion_notify_event, do_no_expose_event, do_parent_set, do_popup_menu, do_property_notify_event, do_proximity_in_event, do_proximity_out_event, do_realize, do_screen_changed, do_scroll_event, do_selection_clear_event, do_selection_get, do_selection_notify_event, do_selection_received, do_selection_request_event, do_show, do_show_all, do_show_help, do_size_allocate, do_size_request, do_state_changed, do_style_set, do_unmap, do_unmap_event, do_unrealize, do_visibility_notify_event, do_window_state_event, drag_begin, drag_check_threshold, drag_dest_add_image_targets, drag_dest_add_text_targets, drag_dest_add_uri_targets, drag_dest_find_target, drag_dest_get_target_list, drag_dest_get_track_motion, drag_dest_set, drag_dest_set_proxy, drag_dest_set_target_list, drag_dest_set_track_motion, drag_dest_unset, drag_get_data, drag_highlight, drag_source_add_image_targets, drag_source_add_text_targets, drag_source_add_uri_targets, drag_source_get_target_list, drag_source_set, drag_source_set_icon, drag_source_set_icon_name, drag_source_set_icon_pixbuf, drag_source_set_icon_stock, drag_source_set_target_list, drag_source_unset, drag_unhighlight, draw, ensure_style, error_bell, event, freeze_child_notify, get_accessible, get_action, get_activate_signal, get_allocation, get_ancestor, get_child_requisition, get_child_visible, get_clipboard, get_colormap, get_composite_name, get_direction, get_display, get_events, get_extension_events, get_has_tooltip, get_modifier_style, get_name, get_no_show_all, get_pango_context, get_parent, get_parent_window, get_pointer, get_root_window, get_settings, get_size_request, get_snapshot, get_style, get_tooltip_markup, get_tooltip_text, get_tooltip_window, get_toplevel, get_visual, get_window, grab_add, grab_default, grab_focus, grab_remove, has_screen, hide, hide_all, hide_on_delete, input_shape_combine_mask, intersect, is_ancestor, is_composited, is_focus, keynav_failed, list_mnemonic_labels, map, menu_get_for_attach_widget, modify_base, modify_bg, modify_cursor, modify_fg, modify_font, modify_style, modify_text, path, queue_clear, queue_clear_area, queue_draw, queue_draw_area, queue_resize, queue_resize_no_redraw, rc_get_style, realize, region_intersect, remove_accelerator, remove_mnemonic_label, render_icon, reparent, reset_rc_styles, reset_shapes, selection_add_target, selection_add_targets, selection_clear_targets, selection_convert, selection_owner_set, selection_remove_all, send_expose, set_accel_path, set_activate_signal, set_app_paintable, set_child_visible, set_colormap, set_composite_name, set_direction, set_double_buffered, set_events, set_extension_events, set_has_tooltip, set_name, set_no_show_all, set_parent, set_parent_window, set_redraw_on_allocate, set_scroll_adjustments, set_sensitive, set_set_scroll_adjustments_signal, set_size_request, set_state, set_style, set_tooltip_markup, set_tooltip_text, set_tooltip_window, set_uposition, set_usize, shape_combine_mask, show, show_all, show_now, size_allocate, size_request, style_get_property, thaw_child_notify, translate_coordinates, trigger_tooltip_query, unmap, unparent, unrealize

Inherited from gtk.Object: do_destroy, flags, remove_data, remove_no_notify, set_flags, unset_flags

Inherited from unreachable.GObject: __cmp__, __copy__, __deepcopy__, __delattr__, __gdoc__, __gobject_init__, __hash__, __new__, __repr__, __setattr__, chain, connect, connect_after, connect_object, connect_object_after, disconnect, disconnect_by_func, emit, emit_stop_by_name, freeze_notify, get_data, get_properties, get_property, handler_block, handler_block_by_func, handler_disconnect, handler_is_connected, handler_unblock, handler_unblock_by_func, notify, props, set_data, set_properties, set_property, stop_emission, thaw_notify, weak_ref

Inherited from atk.ImplementorIface: ref_accessible

Inherited from gtk.Buildable: add_child, construct_child, do_add_child, do_construct_child, do_get_internal_child, do_parser_finished, do_set_name, get_internal_child, parser_finished

Inherited from object: __getattribute__, __reduce__, __reduce_ex__, __str__

Class Variables [hide private]
  message_preparing = 'Preparing user interface'
  message_loading = 'Loading object from Journal'
  message_joining = 'Joining shared activity'

Inherited from sugar.activity.activity.Activity: __gsignals__, __gtype__, __gtype_name__, active, max_participants

Inherited from sugar.graphics.window.Window: enable_fullscreen_mode

Properties [hide private]

Inherited from sugar.activity.activity.Activity: metadata

Inherited from sugar.activity.activity.Activity (private): _shared_activity

Inherited from gtk.Window: allow_grow, allow_shrink, configure_notify_received, configure_request_count, decorated, default_widget, destroy_with_parent, focus_widget, frame, frame_bottom, frame_left, frame_right, frame_top, gravity, group, has_focus, has_frame, has_user_ref_count, iconify_initially, keys_changed_handler, maximize_initially, mnemonic_modifier, modal, need_default_position, need_default_size, position, stick_initially, title, transient_parent, type, type_hint, wm_role, wmclass_class, wmclass_name

Inherited from gtk.Bin: child

Inherited from gtk.Container: border_width, focus_child, has_focus_chain, need_resize, reallocate_redraws, resize_mode

Inherited from gtk.Widget: allocation, name, parent, requisition, saved_state, state, style, window

Inherited from unreachable.GObject: __grefcount__

Inherited from object: __class__

Method Details [hide private]

__init__(self, handle)
(Constructor)

source code 
Initialise the Activity 

handle -- sugar.activity.activityhandle.ActivityHandle
    instance providing the activity id and access to the 
    presence service which *may* provide sharing for this 
    application

create_jobject -- boolean
    define if it should create a journal object if we are
    not resuming

Side effects: 

    Sets the gdk screen DPI setting (resolution) to the 
    Sugar screen resolution.
    
    Connects our "destroy" message to our _destroy_cb
    method.

    Creates a base gtk.Window within this window.
    
    Creates an ActivityService (self._bus) servicing
    this application.

Usage:        
    If your Activity implements __init__(), it should call
    the base class __init()__ before doing Activity specific things.
    

Overrides: object.__init__
(inherited documentation)

early_setup(self)

source code 

Any subclass that needs to take an action before any external interaction (e.g. read_file, write_file) occurs should place that code in early_setup

initialize_display(self)

source code 

All subclasses must override this method, which is the principal means of initializing a GroupActivity.

Returns: gtk.Widget
The widget that will be the display for this activity (i.e. the canvas).

share(self, private=False)

source code 

The purpose of this function is solely to permit us to determine whether share() has been called. This is necessary because share() may be called during Activity.__init__, and thus emit the 'shared' signal before we have a chance to connect any signal handlers.

Overrides: sugar.activity.activity.Activity.share

when_initiating_sharing(self)

source code 

Inheritors should override this method to perform any special operations upon initiating sharing. This method will not be called for "joiners", only for "sharers".

read_file(self, file_path)

source code 

Subclasses implement this method if they support resuming objects from the journal. 'file_path' is the file to read from.

You should immediately open the file from the file_path, because the file_name will be deleted immediately after returning from read_file(). Once the file has been opened, you do not have to read it immediately: After you have opened it, the file will only be really gone when you close it.

Although not required, this is also a good time to read all meta-data: the file itself cannot be changed externally, but the title, description and other metadata['tags'] may change. So if it is important for you to notice changes, this is the time to record the originals.

Overrides: sugar.activity.activity.Activity.read_file
(inherited documentation)

load_from_journal(self, file_path)

source code 

Inheritors wishing to control file saving should override this method. Any inheritor overriding this method must return the string provided to save_to_journal as cloudstring. The default implementation of load_from_journal simply returns the contents of the file, matching the default implementation of save_to_journal.

Parameters:
  • file_path (str) - path to the file to read
Returns: str
a string previously passed to save_to_journal as cloudstring

write_file(self, file_path)

source code 

Subclasses implement this method if they support saving data to objects in the journal. 'file_path' is the file to write to.

If the user did make changes, you should create the file_path and save all document data to it.

Additionally, you should also write any metadata needed to resume your activity. For example, the Read activity saves the current page and zoom level, so it can display the page.

Note: Currently, the file_path *WILL* be different from the one you received in file_read(). Even if you kept the file_path from file_read() open until now, you must still write the entire file to this file_path.

Overrides: sugar.activity.activity.Activity.write_file
(inherited documentation)

save_to_journal(self, file_path, cloudstring)

source code 

Any inheritor who wishes to control file output should override this method, and must be sure to include cloudstring in its write_file. The default implementation of save_to_journal simply dumps the output of self.cloud.dumps() to disk.

Parameters:
  • file_path (str) - the path to which the activity should write
  • cloudstring (str) - an additional string representing the state of all objects associated with self.cloud. This string may be saved as the inheritor sees fit.

pause(self)

source code 

This method will be called when the display is not visible. Subclasses should override this function to stop updating the display when it is not visible.

resume(self)

source code 

This method will be called when the display becomes visible. Subclasses should override this function to resume updating the display, since it is now visible