Пример #1
0
 def find_notebook_var(parent):
     for key in ShellAccess.keys():
         notebook_var = ShellAccess[key]
         if notebook_var is parent and key != "self" and not key.startswith(
                 "_"):
             return key, notebook_var
     # we didn't find it, maybe it's nested
     if parent.parent_pixieapp is not None:
         key, notebook_var = find_notebook_var(
             parent.parent_pixieapp)
         if key is not None:
             # find the current object by name and append it to the key
             return (key + "." +
                     find_child_var(parent.parent_pixieapp, parent),
                     notebook_var)
     return None, None
Пример #2
0
    def run(self, entity=None, **kwargs):
        is_running_child_pixieapp = kwargs.pop("is_running_child_pixieapp",
                                               False)
        for key, value in iteritems(kwargs):
            setattr(self, key, value)
        if entity is not None:
            self.pixieapp_entity = entity
        var = None
        if self.parent_pixieapp is not None:
            parent_key = None
            for key in ShellAccess.keys():
                notebook_var = ShellAccess[key]
                if notebook_var is self.parent_pixieapp and key != "self":
                    parent_key = key
                    break
            for child_key, child in iteritems(notebook_var.pixieapp_children):
                if child is self:
                    var = "{}.{}".format(parent_key, child_key)
                    break
        else:
            for key in ShellAccess.keys():
                notebook_var = ShellAccess[key]
                if notebook_var is self:
                    var = key
                    break

        if not hasattr(self, "pd_initialized"):
            run_method_with_super_classes(cls, self, "setup")
            self.nostore_params = True
            self.pd_initialized = True

        instance_namespace = ""
        if is_running_child_pixieapp:
            cell_id = kwargs.get("options", {}).get("cell_id", None)
            if cell_id:
                instance_namespace = "_" + cell_id
        if not var:
            #If we're here, the user must have created the instance inline, assign a variable dynamically
            var = cls.__name__ + "_instance" + instance_namespace
            ShellAccess[var] = self

        self.runInDialog = kwargs.get("runInDialog", "false") is "true"
        options = {
            "nostore_pixieapp": var,
            "nostore_ispix": "true",
            "runInDialog": "true" if self.runInDialog else "false"
        }
        if is_running_child_pixieapp:
            options["nostore_isrunningchildpixieapp"] = "true"

        #update with any custom options that the pixieapp may have
        options.update(self.get_custom_options())

        if self.runInDialog:
            options.update(self.getDialogOptions())

        options.update({'handlerId': decoName(cls, "id")})
        if "options" in kwargs and isinstance(kwargs['options'], dict):
            options.update(kwargs['options'])
        if pixieAppRunCustomizer is not None and callable(
                getattr(pixieAppRunCustomizer, "customizeOptions", None)):
            pixieAppRunCustomizer.customizeOptions(options)

        opts = [(k, str(v).lower() if isinstance(v, bool) else v)
                for (k, v) in iteritems(options) if v is not None]
        s = "display({}{})".format(
            var,
            reduce(lambda k, v: k + "," + v[0] + "='" + str(v[1]) + "'", opts,
                   ""))
        try:
            sys.modules['pixiedust.display'].pixiedust_display_callerText = s
            self._app_starting = True  #App lifecycle flag
            parts = var.split(".")
            locals()[parts[0]] = ShellAccess[parts[0]]
            self.debug("Running with command: {} and var {}".format(s, var))
            return eval(s, globals(), locals())
        finally:
            self._app_starting = False
            del sys.modules['pixiedust.display'].pixiedust_display_callerText
Пример #3
0
 def updateVarsDict(self, vars):
     ShellAccess.update(**vars)
Пример #4
0
 def find_notebook_var():
     for key in ShellAccess.keys():
         notebook_var = ShellAccess[key]
         if notebook_var is self.parent_pixieapp and key != "self":
             return key, notebook_var
     return None, None
Пример #5
0
 def updateVarsDict(self, vars):
     ShellAccess.update(**vars)