def __init__(self): logging.debug('STARTUP: Loading the desktop window') Gtk.Window.__init__(self) self.set_has_resize_grip(False) accel_group = Gtk.AccelGroup() self.sugar_accel_group = accel_group self.add_accel_group(accel_group) self._active = False self._fully_obscured = True screen = self.get_screen() screen.connect('size-changed', self.__screen_size_change_cb) self.set_default_size(screen.get_width(), screen.get_height()) self.realize() self._busy_count = 0 self.busy() self.set_type_hint(Gdk.WindowTypeHint.DESKTOP) self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color()) self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK) self.connect('visibility-notify-event', self._visibility_notify_event_cb) self.connect('map-event', self.__map_event_cb) self.connect('key-press-event', self.__key_press_event_cb) self.connect('key-release-event', self.__key_release_event_cb) self._box = HomeBackgroundBox() self._toolbar = ViewToolbar() self._box.pack_start(self._toolbar, False, True, 0) self._toolbar.show() self._alert = None self._home_box = HomeBox(self._toolbar) self._box.pack_start(self._home_box, True, True, 0) self._home_box.show() self._toolbar.show_view_buttons() self._group_box = GroupBox(self._toolbar) self._mesh_box = MeshBox(self._toolbar) self._transition_box = TransitionBox() self.add(self._box) self._box.show() self._transition_box.connect('completed', self._transition_completed_cb) shell.get_model().zoom_level_changed.connect( self.__zoom_level_changed_cb) self._alt_timeout_sid = None
def __realize_cb(self, widget): self.set_type_hint(Gdk.WindowTypeHint.DIALOG) window = self.get_window() window.set_accept_focus(True) display = Gdk.Display.get_default() parent = GdkX11.X11Window.foreign_new_for_display(display, self.parent_window_xid) window.set_transient_for(parent) shell.get_model().push_modal()
def __realize_cb(self, widget): self.set_type_hint(Gdk.WindowTypeHint.DIALOG) window = self.get_window() window.set_accept_focus(True) if self.parent_window_xid > 0: display = Gdk.Display.get_default() parent = GdkX11.X11Window.foreign_new_for_display(display, self.parent_window_xid) window.set_transient_for(parent) # the modal windows counter is updated to disable hot keys - SL#4601 shell.get_model().push_modal()
def __init__(self): VTray.__init__(self) self._shared_activity = None self._buddies = {} shell.get_model().connect('active-activity-changed', self.__active_activity_changed_cb) neighborhood.get_model().connect('activity-added', self.__neighborhood_activity_added_cb)
def _visibility_notify_event_cb(self, window, event): fully_obscured = ( event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED) if self._fully_obscured == fully_obscured: return self._fully_obscured = fully_obscured if fully_obscured: self._deactivate_view(shell.get_model().zoom_level) else: self._activate_view(shell.get_model().zoom_level)
def _destroy_launcher(home_activity): activity_id = home_activity.get_activity_id() launcher = shell.get_model().get_launcher(activity_id) if launcher is None: if not home_activity.is_journal(): logging.error('Launcher was not registered for %s', activity_id) return shell.get_model().unregister_launcher(activity_id) launcher.destroy()
def __init__(self): HTray.__init__(self) self._buttons = {} self._buttons_by_name = {} self._invite_to_item = {} self._freeze_button_clicks = False self._home_model = shell.get_model() self._home_model.connect('activity-added', self.__activity_added_cb) self._home_model.connect('activity-removed', self.__activity_removed_cb) self._home_model.connect('active-activity-changed', self.__activity_changed_cb) self._home_model.connect('tabbing-activity-changed', self.__tabbing_activity_changed_cb) self._invites = invites.get_instance() for invite in self._invites: self._add_invite(invite) self._invites.connect('invite-added', self.__invite_added_cb) self._invites.connect('invite-removed', self.__invite_removed_cb) filetransfer.new_file_transfer.connect(self.__new_file_transfer_cb) service = notifications.get_service() service.notification_received.connect(self.__notification_received_cb) service.buffer_cleared.connect(self.__buffer_cleared_cb)
def _object_added_cb(self, cb_service, cb_object): """ Code snippet to tag clipboard objects from shared activities """ shell = get_model() logging.debug(shell.get_active_activity()) current = shell.get_active_activity() active_id = current.get_activity_id() logging.debug(active_id) pservice = presenceservice.get_instance() instance = pservice.get_activity(active_id, warn_if_none=False) """ For a shared activity should have a pservice entry """ if instance is None: return logging.debug("cbobject path " + str(cb_object.get_id())) if self._icons: group = self._icons.values()[0] else: group = None icon = ClipboardIcon(cb_object, group) self.add_item(icon) icon.show() self._icons[cb_object.get_id()] = icon objects_to_delete = self.get_children()[:-self.MAX_ITEMS] for icon in objects_to_delete: logging.debug('ClipboardTray: deleting surplus object') cb_service = clipboard.get_instance() cb_service.delete_object(icon.get_object_id()) logging.debug('ClipboardTray: %r was added', cb_object.get_id())
def __init__(self, client): self._client = client self._activity = None for activity in shell.get_model(): if activity.get_activity_id() == client.activity_id: self._activity = activity
def __init__(self): GObject.GObject.__init__(self) self._buddies = {None: get_owner_instance()} self._activities = {} self._link_local_account = None self._server_account = None self._shell_model = shell.get_model() client = GConf.Client.get_default() client.add_dir('/desktop/sugar/collaboration', GConf.ClientPreloadType.PRELOAD_NONE) client.notify_add('/desktop/sugar/collaboration/jabber_server', self.__jabber_server_changed_cb, None) client.add_dir( '/desktop/sugar/user/nick', GConf.ClientPreloadType.PRELOAD_NONE) client.notify_add( '/desktop/sugar/user/nick', self.__nick_changed_cb, None) bus = dbus.Bus() obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH) account_manager = dbus.Interface(obj, ACCOUNT_MANAGER) account_manager.Get(ACCOUNT_MANAGER, 'ValidAccounts', dbus_interface=PROPERTIES_IFACE, reply_handler=self.__got_accounts_cb, error_handler=self.__error_handler_cb)
def __view_source__cb(self, menu_item): setup_view_source(self._home_activity) shell_model = shell.get_model() if self._home_activity is not shell_model.get_active_activity(): self._home_activity.get_window().activate( Gtk.get_current_event_time()) self.emit('done')
def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, invited=False): if activity_id is None or not activity_id: activity_id = activityfactory.create_activity_id() logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s', bundle.get_bundle_id(), activity_id, object_id, uri) shell_model = shell.get_model() activity = shell_model.get_activity_by_id(activity_id) if activity is not None: logging.debug('re-launch %r', activity.get_window()) activity.get_window().activate(Gtk.get_current_event_time()) return if color is None: client = GConf.Client.get_default() color = XoColor(client.get_string('/desktop/sugar/user/color')) launcher.add_launcher(activity_id, bundle.get_icon(), color) activity_handle = ActivityHandle(activity_id=activity_id, object_id=object_id, uri=uri, invited=invited) activityfactory.create(bundle, activity_handle)
def _update_buddy_activities(self, buddy_handle, activities): logging.debug('_Account._update_buddy_activities') if not buddy_handle in self._activities_per_buddy: self._activities_per_buddy[buddy_handle] = set() for activity_id, room_handle in activities: if room_handle not in self._activity_handles: self._activity_handles[room_handle] = activity_id if buddy_handle == self._self_handle: home_model = shell.get_model() activity = home_model.get_active_activity() if activity.get_activity_id() == activity_id: connection = self._connection[ CONNECTION_INTERFACE_BUDDY_INFO] connection.SetCurrentActivity( activity_id, room_handle, reply_handler=self.__set_current_activity_cb, error_handler=self.__set_current_activity_error_cb) self.emit('activity-added', room_handle, activity_id) connection = self._connection[ CONNECTION_INTERFACE_ACTIVITY_PROPERTIES] connection.GetProperties(room_handle, reply_handler=partial(self.__get_properties_cb, room_handle), error_handler=partial(self.__error_handler_cb, 'ActivityProperties.GetProperties')) if buddy_handle != self._self_handle: # Sometimes we'll get CurrentActivityChanged before we get # to know about the activity so we miss the event. In that # case, request again the current activity for this buddy. connection = self._connection[ CONNECTION_INTERFACE_BUDDY_INFO] connection.GetCurrentActivity( buddy_handle, reply_handler=partial(self.__get_current_activity_cb, buddy_handle), error_handler=partial(self.__error_handler_cb, 'BuddyInfo.GetCurrentActivity')) if not activity_id in self._buddies_per_activity: self._buddies_per_activity[activity_id] = set() self._buddies_per_activity[activity_id].add(buddy_handle) if activity_id not in self._activities_per_buddy[buddy_handle]: self._activities_per_buddy[buddy_handle].add(activity_id) if buddy_handle != self._self_handle: self.emit('buddy-joined-activity', self._buddy_handles[buddy_handle], activity_id) current_activity_ids = \ [activity_id for activity_id, room_handle in activities] for activity_id in self._activities_per_buddy[buddy_handle].copy(): if not activity_id in current_activity_ids: self._remove_buddy_from_activity(buddy_handle, activity_id)
def __init__(self): Gtk.Toolbar.__init__(self) # we shouldn't be mirrored in RTL locales self.set_direction(Gtk.TextDirection.LTR) # ask not to be collapsed if possible self.set_size_request(4 * style.GRID_CELL_SIZE, -1) self._mesh_button = self._add_button('zoom-neighborhood', _('Neighborhood'), _('F1'), shell.ShellModel.ZOOM_MESH) self._groups_button = self._add_button('zoom-groups', _('Group'), _('F2'), shell.ShellModel.ZOOM_GROUP) self._home_button = self._add_button('zoom-home', _('Home'), _('F3'), shell.ShellModel.ZOOM_HOME) self._activity_button = \ self._add_button('zoom-activity', _('Activity'), _('F4'), shell.ShellModel.ZOOM_ACTIVITY) shell_model = shell.get_model() self._set_zoom_level(shell_model.zoom_level) shell_model.zoom_level_changed.connect(self.__zoom_level_changed_cb)
def handle_open_controlpanel(self, event_time): if shell.get_model().has_modal(): return self._frame.hide() panel = ControlPanel() panel.show()
def _visibility_notify_event_cb(self, window, event): fully_obscured = event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED if self._fully_obscured == fully_obscured: return self._fully_obscured = fully_obscured if fully_obscured: self._deactivate_view(shell.get_model().zoom_level) else: display = Gdk.Display.get_default() screen_, x_, y_, modmask = display.get_pointer() if modmask & Gdk.ModifierType.MOD1_MASK: self._home_box.set_resume_mode(False) else: self._home_box.set_resume_mode(True) self._activate_view(shell.get_model().zoom_level)
def _visibility_notify_event_cb(self, window, event): fully_obscured = (event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED) if self._fully_obscured == fully_obscured: return self._fully_obscured = fully_obscured if fully_obscured: self._deactivate_view(shell.get_model().zoom_level) else: display = gtk.gdk.display_get_default() screen_, x_, y_, modmask = display.get_pointer() if modmask & gtk.gdk.MOD1_MASK: self._home_box.set_resume_mode(False) else: self._home_box.set_resume_mode(True) self._activate_view(shell.get_model().zoom_level)
def take_screenshot(): tmp_dir = os.path.join(env.get_profile_path(), 'data') fd, file_path = tempfile.mkstemp(dir=tmp_dir) os.close(fd) window = Gdk.get_default_root_window() width, height = window.get_width(), window.get_height() screenshot_surface = Gdk.Window.create_similar_surface( window, cairo.CONTENT_COLOR, width, height) cr = cairo.Context(screenshot_surface) Gdk.cairo_set_source_window(cr, window, 0, 0) cr.paint() screenshot_surface.write_to_png(file_path) settings = Gio.Settings('org.sugarlabs.user') color = settings.get_string('color') content_title = None shell_model = shell.get_model() zoom_level = shell_model.zoom_level # TRANS: Nouns of what a screenshot contains if zoom_level == shell_model.ZOOM_MESH: content_title = _('Mesh') elif zoom_level == shell_model.ZOOM_GROUP: content_title = _('Group') elif zoom_level == shell_model.ZOOM_HOME: content_title = _('Home') elif zoom_level == shell_model.ZOOM_ACTIVITY: activity = shell_model.get_active_activity() if activity is not None: content_title = activity.get_title() if content_title is None: content_title = _('Activity') if content_title is None: title = _('Screenshot') else: title = _('Screenshot of \"%s\"') % content_title jobject = datastore.create() try: jobject.metadata['title'] = title jobject.metadata['keep'] = '0' jobject.metadata['buddies'] = '' jobject.metadata['preview'] = _get_preview_data(screenshot_surface) jobject.metadata['icon-color'] = color jobject.metadata['mime_type'] = 'image/png' jobject.file_path = file_path datastore.write(jobject, transfer_ownership=True) finally: jobject.destroy() del jobject return title
def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, invited=False, alert_window=None): bundle_id = bundle.get_bundle_id() if activity_id is None or not activity_id: activity_id = activityfactory.create_activity_id() logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s', bundle.get_bundle_id(), activity_id, object_id, uri) if isinstance(bundle, ContentBundle): # Content bundles are a special case: we treat them as launching # Browse with a specific URI. uri = bundle.get_start_uri() activities = _get_activities_for_mime('text/html') if len(activities) == 0: logging.error("No browser available for content bundle") return bundle = activities[0] logging.debug('Launching content bundle with uri %s', uri) shell_model = shell.get_model() activity = shell_model.get_activity_by_id(activity_id) if activity is not None: logging.debug('re-launch %r', activity.get_window()) activity.get_window().activate(Gtk.get_current_event_time()) return if not shell_model.can_launch_activity(): if alert_window is None: from jarabe.desktop import homewindow alert_window = homewindow.get_instance() if alert_window is not None: alerts.show_max_open_activities_alert(alert_window) return if not shell_model.can_launch_activity_instance(bundle): if alert_window is None: from jarabe.desktop import homewindow alert_window = homewindow.get_instance() if alert_window is not None: alerts.show_multiple_instance_alert( alert_window, shell_model.get_name_from_bundle_id(bundle_id)) return if color is None: client = GConf.Client.get_default() color = XoColor(client.get_string('/desktop/sugar/user/color')) launcher.add_launcher(activity_id, bundle.get_icon(), color) activity_handle = ActivityHandle(activity_id=activity_id, object_id=object_id, uri=uri, invited=invited) activityfactory.create(bundle, activity_handle)
def __init__(self, activity_id, icon_path, icon_color): Gtk.Window.__init__(self) self.set_has_resize_grip(False) self.props.type_hint = Gdk.WindowTypeHint.SPLASHSCREEN self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color()) canvas = Gtk.VBox() canvas.show() self.add(canvas) bar_size = Gdk.Screen.height() / 5 * 2 header = Gtk.VBox() header.set_size_request(-1, bar_size) header.show() canvas.pack_start(header, False, True, 0) self._activity_id = activity_id self._activity_icon = PulsingIcon(file=icon_path, pixel_size=style.XLARGE_ICON_SIZE) self._activity_icon.set_base_color(icon_color) self._activity_icon.set_zooming(style.SMALL_ICON_SIZE, style.XLARGE_ICON_SIZE, 10) self._activity_icon.set_pulsing(True) self._activity_icon.show() canvas.pack_start(self._activity_icon, True, True, 0) footer = Gtk.VBox(spacing=style.DEFAULT_SPACING) footer.set_size_request(-1, bar_size) footer.show() canvas.pack_end(footer, False, True, 0) self.error_text = Gtk.Label() self.error_text.props.use_markup = True footer.pack_start(self.error_text, False, True, 0) button_box = Gtk.Alignment.new(0.5, 0, 0, 0) button_box.show() footer.pack_start(button_box, False, True, 0) self.cancel_button = Gtk.Button(stock=Gtk.STOCK_STOP) button_box.add(self.cancel_button) self.connect('realize', self.__realize_cb) screen = Gdk.Screen.get_default() screen.connect('size-changed', self.__size_changed_cb) self._home = shell.get_model() self._home.connect('active-activity-changed', self.__active_activity_changed_cb) self.connect('destroy', self.__destroy_cb) self._update_size()
def __init__(self, activity_id, icon_path, icon_color): gobject.GObject.__init__(self) self.props.type_hint = gtk.gdk.WINDOW_TYPE_HINT_NORMAL self.props.decorated = False self.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) canvas = gtk.VBox() canvas.show() self.add(canvas) bar_size = gtk.gdk.screen_height() / 5 * 2 header = gtk.VBox() header.set_size_request(-1, bar_size) header.show() canvas.pack_start(header, expand=False) self._activity_id = activity_id self._activity_icon = PulsingIcon(file=icon_path, pixel_size=style.XLARGE_ICON_SIZE) self._activity_icon.set_base_color(icon_color) self._activity_icon.set_zooming(style.SMALL_ICON_SIZE, style.XLARGE_ICON_SIZE, 10) self._activity_icon.set_pulsing(True) self._activity_icon.show() canvas.pack_start(self._activity_icon) footer = gtk.VBox(spacing=style.DEFAULT_SPACING) footer.set_size_request(-1, bar_size) footer.show() canvas.pack_end(footer, expand=False) self.error_text = gtk.Label() self.error_text.props.use_markup = True footer.pack_start(self.error_text, expand=False) button_box = gtk.Alignment(xalign=0.5) button_box.show() footer.pack_start(button_box, expand=False) self.cancel_button = gtk.Button(stock=gtk.STOCK_STOP) button_box.add(self.cancel_button) self.connect('realize', self.__realize_cb) screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self.__size_changed_cb) self._home = shell.get_model() self._home.connect('active-activity-changed', self.__active_activity_changed_cb) self.connect('destroy', self.__destroy_cb) self._update_size()
def setup(): global _INTERVAL settings = Gio.Settings('org.sugarlabs.desktop') _INTERVAL = settings.get_int('launcher-interval') model = shell.get_model() model.connect('launch-started', __launch_started_cb) model.connect('launch-failed', __launch_failed_cb) model.connect('launch-completed', __launch_completed_cb)
def add_launcher(activity_id, icon_path, icon_color): model = shell.get_model() if model.get_launcher(activity_id) is not None: return launch_window = LaunchWindow(activity_id, icon_path, icon_color) launch_window.show() model.register_launcher(activity_id, launch_window)
def __add_new_activate_cb(self, bar, title): shell_model = shell.get_model() activity = shell_model.get_active_activity() if activity.has_shell_window(): return if shell.get_model().has_modal(): return chooser = ActivityChooser() activity.push_shell_window(chooser) chooser.connect('hide', activity.pop_shell_window) text = _("Choose an activity to start '%s' with") % title chooser.set_title(text) chooser.connect('activity-selected', self.__activity_selected_cb, title) chooser.show_all()
def handle_key_press(key): tmp_dir = os.path.join(env.get_profile_path(), 'data') fd, file_path = tempfile.mkstemp(dir=tmp_dir) os.close(fd) window = gtk.gdk.get_default_root_window() width, height = window.get_size() x_orig, y_orig = window.get_origin() screenshot = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=False, bits_per_sample=8, width=width, height=height) screenshot.get_from_drawable(window, window.get_colormap(), x_orig, y_orig, 0, 0, width, height) screenshot.save(file_path, 'png') client = gconf.client_get_default() color = client.get_string('/desktop/sugar/user/color') content_title = None shell_model = shell.get_model() zoom_level = shell_model.zoom_level # TRANS: Nouns of what a screenshot contains if zoom_level == shell_model.ZOOM_MESH: content_title = _('Mesh') elif zoom_level == shell_model.ZOOM_GROUP: content_title = _('Group') elif zoom_level == shell_model.ZOOM_HOME: content_title = _('Home') elif zoom_level == shell_model.ZOOM_ACTIVITY: activity = shell_model.get_active_activity() if activity != None: content_title = activity.get_title() if content_title == None: content_title = _('Activity') if content_title is None: title = _('Screenshot') else: title = _('Screenshot of \"%s\"') % content_title jobject = datastore.create() try: jobject.metadata['title'] = title jobject.metadata['keep'] = '0' jobject.metadata['buddies'] = '' jobject.metadata['preview'] = _get_preview_data(screenshot) jobject.metadata['icon-color'] = color jobject.metadata['mime_type'] = 'image/png' jobject.file_path = file_path datastore.write(jobject, transfer_ownership=True) finally: jobject.destroy() del jobject
def handle_key_press(key): tmp_dir = os.path.join(env.get_profile_path(), 'data') fd, file_path = tempfile.mkstemp(dir=tmp_dir) os.close(fd) window = Gdk.get_default_root_window() width, height = window.get_width(), window.get_height() window_cr = Gdk.cairo_create(window) window_surface = window_cr.get_target() screenshot_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) cr = cairo.Context(screenshot_surface) cr.set_source_surface(window_surface) cr.paint() screenshot_surface.write_to_png(file_path) client = GConf.Client.get_default() color = client.get_string('/desktop/sugar/user/color') content_title = None shell_model = shell.get_model() zoom_level = shell_model.zoom_level # TRANS: Nouns of what a screenshot contains if zoom_level == shell_model.ZOOM_MESH: content_title = _('Mesh') elif zoom_level == shell_model.ZOOM_GROUP: content_title = _('Group') elif zoom_level == shell_model.ZOOM_HOME: content_title = _('Home') elif zoom_level == shell_model.ZOOM_ACTIVITY: activity = shell_model.get_active_activity() if activity != None: content_title = activity.get_title() if content_title == None: content_title = _('Activity') if content_title is None: title = _('Screenshot') else: title = _('Screenshot of \"%s\"') % content_title jobject = datastore.create() try: jobject.metadata['title'] = title jobject.metadata['keep'] = '0' jobject.metadata['buddies'] = '' jobject.metadata['preview'] = _get_preview_data(screenshot_surface) jobject.metadata['icon-color'] = color jobject.metadata['mime_type'] = 'image/png' jobject.file_path = file_path datastore.write(jobject, transfer_ownership=True) finally: jobject.destroy() del jobject
def __init__(self): GObject.GObject.__init__(self) address = SugarExt.xsmp_init() os.environ['SESSION_MANAGER'] = address SugarExt.xsmp_run() self.session = SugarExt.Session.create_global() self._shell_model = shell.get_model() self._shutdown_tries = 0 self._logout_mode = None
def __init__(self): logging.debug('Tracker __init__') self._activity = None self._state = None self._model = shell.get_model() self._model.zoom_level_changed.connect(self.__zoom_changed_cb) self._monitor = Gio.File.new_for_path(self.DCON_SLEEP_PATH)\ .monitor_file(Gio.FileMonitorFlags.NONE, None) self._monitor.connect('changed', self.__file_changed_cb)
def __init__(self): CanvasIcon.__init__(self, cache=True) self._home_model = shell.get_model() self._home_activity = self._home_model.get_active_activity() if self._home_activity is not None: self._update() self._home_model.connect('active-activity-changed', self.__active_activity_changed_cb) self.connect('button-release-event', self.__button_release_event_cb)
def stop(self, event_time): self._keyboard.ungrab(event_time) self._mouse.ungrab(event_time) self._tabbing = False self._frame.hide() self._cancel_timeout() self._activate_current(event_time) home_model = shell.get_model() home_model.set_tabbing_activity(None)
def __stop_clicked_cb(self, widget): shell.get_model().pop_modal() self.destroy()
import os from gettext import gettext as _ #major packages from gi.repository import Gtk from gi.repository import Gdk import hashlib import time #sugar stuff from sugar3.graphics.alert import * from sugar3.graphics.alert import ConfirmationAlert from jarabe.model import shell home_model = shell.get_model() import logging from pydebug_logging import _logger __pdb = None class Utilities(): def __init__(self, activity): self._activity = __pdb = activity self.home_model = None ##################### ALERT ROUTINES ################################## def alert(self, msg, title=None):
def __init__(self): bus = dbus.SessionBus() bus_name = dbus.service.BusName(_DBUS_SERVICE, bus=bus) dbus.service.Object.__init__(self, bus_name, _DBUS_PATH) self._shell_model = shell.get_model()
def NotifyLaunch(self, bundle_id, activity_id): shell.get_model().notify_launch(activity_id, bundle_id)
def NotifyLaunchFailure(self, activity_id): shell.get_model().notify_launch_failed(activity_id)
def __destroy_cb(self, menu): if self._active_activity_changed_hid is not None: home_model = shell.get_model() home_model.disconnect(self._active_activity_changed_hid) self._buddy.disconnect_by_func(self.__buddy_notify_nick_cb)
def _transition_completed_cb(self, transition_box): self._update_view(shell.get_model().zoom_level)
def _close_connection(self): self._connection = None if self._home_changed_hid is not None: model = shell.get_model() model.disconnect(self._home_changed_hid) self._home_changed_hid = None
def __get_self_handle_cb(self, self_handle): self._self_handle = self_handle if CONNECTION_INTERFACE_CONTACT_CAPABILITIES in self._connection: interface = CONNECTION_INTERFACE_CONTACT_CAPABILITIES connection = self._connection[interface] client_name = CLIENT + '.Sugar.FileTransfer' file_transfer_channel_class = { CHANNEL + '.ChannelType': CHANNEL_TYPE_FILE_TRANSFER, CHANNEL + '.TargetHandleType': HANDLE_TYPE_CONTACT } capabilities = [] connection.UpdateCapabilities( [(client_name, [file_transfer_channel_class], capabilities)], reply_handler=self.__update_capabilities_cb, error_handler=partial(self.__error_handler_cb, 'Connection.UpdateCapabilities')) connection = self._connection[CONNECTION_INTERFACE_ALIASING] connection.connect_to_signal('AliasesChanged', self.__aliases_changed_cb) connection = self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE] connection.connect_to_signal('PresencesChanged', self.__presences_changed_cb) if CONNECTION_INTERFACE_BUDDY_INFO in self._connection: connection = self._connection[CONNECTION_INTERFACE_BUDDY_INFO] connection.connect_to_signal('PropertiesChanged', self.__buddy_info_updated_cb, byte_arrays=True) connection.connect_to_signal('ActivitiesChanged', self.__buddy_activities_changed_cb) connection.connect_to_signal('CurrentActivityChanged', self.__current_activity_changed_cb) if self._home_changed_hid is None: home_model = shell.get_model() self._home_changed_hid = home_model.connect( 'active-activity-changed', self.__active_activity_changed_cb) else: logging.warning( 'Connection %s does not support OLPC buddy ' 'properties', self._object_path) if CONNECTION_INTERFACE_ACTIVITY_PROPERTIES in self._connection: connection = self._connection[ CONNECTION_INTERFACE_ACTIVITY_PROPERTIES] connection.connect_to_signal('ActivityPropertiesChanged', self.__activity_properties_changed_cb) else: logging.warning( 'Connection %s does not support OLPC activity ' 'properties', self._object_path) properties = { CHANNEL + '.ChannelType': CHANNEL_TYPE_CONTACT_LIST, CHANNEL + '.TargetHandleType': HANDLE_TYPE_LIST, CHANNEL + '.TargetID': 'subscribe', } properties = dbus.Dictionary(properties, signature='sv') connection = self._connection[CONNECTION_INTERFACE_REQUESTS] is_ours, channel_path, properties = \ connection.EnsureChannel(properties) channel = {} service_name = self._object_path.replace('/', '.')[1:] text_proxy = dbus.Bus().get_object(service_name, channel_path) channel[PROPERTIES_IFACE] = dbus.Interface(text_proxy, PROPERTIES_IFACE) channel[CHANNEL_INTERFACE_GROUP] = \ dbus.Interface(text_proxy, CHANNEL_INTERFACE_GROUP) channel[CHANNEL_INTERFACE_GROUP].connect_to_signal( 'MembersChanged', self.__members_changed_cb) channel[PROPERTIES_IFACE].Get( CHANNEL_INTERFACE_GROUP, 'Members', reply_handler=self.__get_members_ready_cb, error_handler=partial(self.__error_handler_cb, 'Connection.GetMembers'))
def handle_close_window(self, event_time): active_activity = shell.get_model().get_active_activity() if active_activity.is_journal(): return active_activity.stop()
def handle_zoom_mesh(self, event_time): shell.get_model().set_zoom_level(ShellModel.ZOOM_MESH, event_time)