Esempio n. 1
0
def dispatch(eeobject):
    """ General dispatcher """
    info = eeobject.getInfo()
    local_type = eeobject.__class__.__name__
    try:
        server_type = info.get('type')
    except AttributeError:
        server_type = local_type

    # Create Widget
    if belongToEE(eeobject):
        # DISPATCH!!
        if server_type == 'Image':
            widget = dispatchImage(info)
        elif server_type == 'Date':
            widget = dispatchDate(info)
        elif server_type == 'DateRange':
            widget = dispatchDaterange(info)
        # ADD MORE ABOVE ME!
        else:
            info = eeobject.getInfo()
            if isinstance(info, (dict, )):
                widget = utils.create_accordion(info)
            else:
                widget = HTML(str(info) + '<br/>')
    else:
        info = str(eeobject)
        widget = Label(info)

    return EEWidget(widget, server_type, local_type)
Esempio n. 2
0
    def __call__(self, *args):
        size = len(args)

        # Output structure
        def structure():
            acc = Accordion([Output()])
            acc.set_title(0, 'Loading...')
            return acc

        # VERTICAL GRID WIDGET TO OUTPUT RESULTS
        # infowin = VBox([Output()]*len(args))
        vbox_arg = []
        for arg in args:
            if belongToEE(arg):
                vbox_arg.append(structure())
            else:
                vbox_arg.append(Label(str(arg)))
        # infowin = VBox([structure]*len(args))
        infowin = VBox(vbox_arg)

        # HELPER
        def setchildren(vbox, i, val, local_type, server_type):
            children = list(vbox.children)
            wid = children[i]
            if isinstance(wid, (Accordion, )):
                if local_type != server_type:
                    title = '{} (local) / {} (server)'.format(
                        local_type, server_type)
                else:
                    title = server_type
                wid.set_title(0, title)
                wid.children = [val]
                wid.selected_index = None if size > 1 else 0

        def get_info(eeobject, index):
            """ Get Info """
            eewidget = dispatcher.dispatch(eeobject)
            widget = eewidget.widget
            setchildren(infowin, index, widget, eewidget.local_type,
                        eewidget.server_type)

        for i, eeobject in enumerate(args):
            # DO THE SAME FOR EVERY OBJECT
            if self.ASYNC:
                thread = threading.Thread(target=get_info, args=(eeobject, i))
                thread.start()
            else:
                get_info(eeobject, i)

        display(infowin)
Esempio n. 3
0
def dispatch(obj):
    """ General dispatcher """
    local_type = obj.__class__.__name__

    start = time()

    try:
        # Create Widget
        if belongToEE(obj):
            info = obj.getInfo()
            try:
                obj_type = info['type']
            except:
                obj_type = local_type

            if obj_type in DISPATCHERS.keys():
                widget = DISPATCHERS[obj_type](info)
            else:
                if isinstance(info, (dict,)):
                    widget = utils.create_accordion(info)
                else:
                    widget = HTML(str(info)+'<br/>')
        else:
            try:
                obj_type = obj['type']
            except:
                obj_type = local_type

            if obj_type in DISPATCHERS.keys():
                widget = DISPATCHERS[obj_type](obj)
            else:
                info = str(obj)
                widget = Label(info)

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        trace = traceback.format_exception(exc_type, exc_value,
                                           exc_traceback)

        # Widget
        widget = ErrorAccordion(e, trace)
        obj_type = 'ERROR'
        local_type = 'ERROR'

    end = time()
    dt = end-start

    return EEWidget(widget, obj_type, local_type, dt)