Beispiel #1
0
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:
        color = profile.get_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)
Beispiel #2
0
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)
Beispiel #3
0
    def _notify_visible_cb(self, embed, param):
        self._embed.disconnect(self._vis_sid)

        if self._embed.type == Browser.TYPE_POPUP or self._embed.is_chrome:
            logging.debug('Show the popup')
            self._embed.show()
            self._dialog.set_transient_for(self._parent_window)
            self._dialog.show()

        else:
            logging.debug('Open a new activity for the popup')
            self._dialog.remove(self._embed)
            self._dialog.destroy()
            self._dialog = None

            # FIXME We need a better way to handle this.
            # It seem like a pretty special case though, I doubt
            # other activities will need something similar.
            from webactivity import WebActivity
            from sugar3.activity import activityfactory
            from sugar3.activity.activityhandle import ActivityHandle
            handle = ActivityHandle(activityfactory.create_activity_id())
            activity = WebActivity(handle, self._embed)
            activity.show()

        self.emit('popup-created')
Beispiel #4
0
    def _setup_activity(self):
        if 'SUGAR_BUNDLE_PATH' not in os.environ:
            _logger.error("SUGAR_BUNDLE_PATH must be set to run application")
            sys.exit(1)

        bundle_path = os.environ['SUGAR_BUNDLE_PATH']
        sys.path.insert(0, bundle_path)

        try:
            bundle = ActivityBundle(bundle_path)
        except MalformedBundleException as e:
            _logger.error(e)
            sys.exit(1)

        activity_root = GLib.get_user_data_dir()

        subdirs = [
            os.path.join(activity_root, 'tmp'),
            os.path.join(activity_root, 'data'),
            os.path.join(activity_root, 'instance'),
        ]
        for subdir in subdirs:
            try:
                os.makedirs(subdir)
            except:
                pass

        os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id()
        os.environ['SUGAR_ACTIVITY_ROOT'] = activity_root
        os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name()
        os.environ['SUGAR_BUNDLE_VERSION'] = str(bundle.get_activity_version())

        locale_path = config.locale_path
        gettext.bindtextdomain(bundle.get_bundle_id(), locale_path)
        gettext.bindtextdomain('sugar-toolkit-gtk3', config.locale_path)
        gettext.textdomain(bundle.get_bundle_id())

        activity_class = bundle.get_command().split(" ")[1]
        splitted_module = activity_class.rsplit('.', 1)
        module_name = splitted_module[0]
        class_name = splitted_module[1]

        module = __import__(module_name)
        for component in module_name.split('.')[1:]:
            module = getattr(module, component)

        constructor = getattr(module, class_name)
        handle = ActivityHandle(activity_id=bundle.get_bundle_id(),
                                uri=self._path)

        os.chdir(bundle_path)

        activity = constructor(handle)
        activity.connect('closing', self._quit)
        activity.show()
        return activity
    def __init__(self, parent):

        self.pydebug = parent
        #from hulahop.webview import WebView
        from browser import Browser

        self.help_id = None
        self.handle = ActivityHandle()
        self.handle.activity_id = util.unique_id()
        Window.__init__(self)
        self.connect('realize', self.realize_cb)

        self.props.max_participants = 1

        self._web_view = Browser()

        ##self.toolbox = Toolbox()
        ##self.toolbox.connect('current_toolbar_changed',self.goto_cb)
        ##self.set_toolbox(self.toolbox)
        ##self.toolbox.show()

        activitybar = Gtk.Toolbar()
        ##self.toolbox.add_toolbar(_('Activity'), activitybar)
        activitybar.show_all()

        editbar = Gtk.Toolbar()
        ##self.toolbox.add_toolbar(_('Edit'), editbar)
        #editbar.connect('current_toolbar_changed', self.goto_cb,1)
        editbar.show_all()

        projectbar = Gtk.Toolbar()
        ##self.toolbox.add_toolbar(_('Project'), projectbar)
        #projectbar.connect('current_toolbar_changed', self.goto_cb,2)
        projectbar.show_all()

        self.help_toolbar = Toolbar(self._web_view)
        self.help_toolbar.show()
        ##self.toolbox.add_toolbar(_('Help'), self.help_toolbar)
        ##self.toolbox._notebook.set_current_page(HELP_PANE)

        self.set_canvas(self._web_view)
        self._web_view.show()

        self.toolbox.set_current_toolbar(HELP_PANE)

        self._web_view.load_uri(HOME)
        self.pid = Popen(['/usr/bin/pydoc', '-p', '23432'])
    def __init__(self, parent):
        self.pydebug = parent

        self.help_id = None
        self.handle = ActivityHandle()
        self.handle.activity_id = util.unique_id()

        Window.__init__(self)
        self.connect('realize', self.realize_cb)

        self._web_view = Browser()

        #determine which language we are going to be using
        help_root = self.get_help_root()
        self.HOME = os.path.join(help_root, 'PyDebug.htm')

        self.toolbarbox = ToolbarBox()
        self.set_toolbar_box(self.toolbarbox)
        self.toolbarbox.show()

        ##activitybar = Gtk.Toolbar()
        ##self.toolbarbox.add_toolbar(_('Activity'), activitybar)
        ##activitybar.show_all()

        editbar = Gtk.Toolbar()
        self.toolbarbox.toolbar.insert(
            ToolbarButton(page=editbar, icon_name='toolbar-edit'), -1)
        editbar.show_all()

        projectbar = Gtk.Toolbar()
        self.toolbarbox.toolbar.insert(
            ToolbarButton(page=self, icon_name='system-run'), -1)
        projectbar.show_all()

        self.help_toolbar = Toolbar(self, self._web_view)
        self.help_toolbar.show()
        self.toolbarbox.toolbar.insert(
            ToolbarButton(page=self.help_toolbar, icon_name="help-about"), -1)

        self.set_canvas(self._web_view)
        self._web_view.show()

        self._web_view.load_uri(self.HOME)
        self.pid = Popen(['/usr/bin/pydoc', '-p', '23432'])
Beispiel #7
0
def launch_bundle(bundle_id=None, object_id=None):
    '''
    Launch a bundle with the given parameters.

    If an object_id is given, the bundle will be launched with the
    object that has that id.  Otherwise, the bundle with the given
    bundle_id will be launched.

    Note: this function should not be used out side of the sugar
    shell process.  The `JournalActivityDBusService` makes this
    avaliable over DBus.
    '''
    bundle = get_bundle(bundle_id, object_id)
    if bundle is None:
        return False

    activity_handle = ActivityHandle(activity_id=None,
                                     object_id=object_id,
                                     uri=None,
                                     invited=False)
    activityfactory.create(bundle, activity_handle)
    return True
Beispiel #8
0
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)

    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 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 create_with_object_id(bundle, object_id):
    """Create a new activity and pass the object id as handle."""
    activity_handle = ActivityHandle(object_id=object_id)
    return ActivityCreationHandler(bundle, activity_handle)
def create_with_uri(bundle, uri):
    """Create a new activity and pass the uri as handle."""
    activity_handle = ActivityHandle(uri=uri)
    return ActivityCreationHandler(bundle, activity_handle)
def create(bundle, activity_handle=None):
    """Create a new activity from its name."""
    if not activity_handle:
        activity_handle = ActivityHandle()
    return ActivityCreationHandler(bundle, activity_handle)