Example #1
0
    def __init__(self, context, pipeline):
        super(MultiObjectsDisplay, self).__init__()
        self.__context = context
        self.__pipeline = pipeline
        self.__cancelled = False
        self.__default_odisp = None
        self.__queues = {}
        self.__ocount = 0
        self.__do_autoswitch = True
        self.__suppress_noyield = not not list(pipeline.get_status_commands())
        self.set_show_tabs(False)

        self.__inputqueue = None
        intype = self.__pipeline.get_input_type()
        _logger.debug("input type %s opt: %s", intype,
                      self.__pipeline.get_input_optional())
        # FIXME assume for the moment we can only input strings; also explicitly avoid allowing input for 'any'
        # Long term we might consider only allowing input for SysBuiltin.
        if intype not in (None, 'any') and Pipeline.streamtype_is_assignable(
                intype, str, False) and self.__pipeline.get_input_optional():
            self.__inputqueue = CommandQueue()
            self.__pipeline.set_input_queue(self.__inputqueue)
        self.append_ostream(pipeline.get_output_type(), None,
                            pipeline.get_output(), False)
        for aux in pipeline.get_auxstreams():
            self.append_ostream(aux.schema.otype, aux.name, aux.queue,
                                aux.schema.merge_default)
Example #2
0
 def get_output(self):
     # Can't just return objects directly as this can be
     # called from other threads
     # TODO make this actually async
     queue = CommandQueue()
     gobject.idle_add(self.__enqueue_output, queue)
     for obj in QueueIterator(queue):
         yield obj
Example #3
0
    def __init__(self, context, pipeline):
        super(MultiObjectsDisplay, self).__init__()
        self.__context = context
        self.__pipeline = pipeline
        self.__cancelled = False
        self.__default_odisp = None
        self.__queues = {}
        self.__ocount = 0
        self.__do_autoswitch = True
        self.__suppress_noyield = not not list(pipeline.get_status_commands())
        self.set_show_tabs(False)

        self.__inputqueue = None
        intype = self.__pipeline.get_input_type()
        _logger.debug("input type %s opt: %s", intype, self.__pipeline.get_input_optional())
        # FIXME assume for the moment we can only input strings; also explicitly avoid allowing input for 'any'
        # Long term we might consider only allowing input for SysBuiltin.
        if intype not in (None, 'any') and Pipeline.streamtype_is_assignable(intype, str, False) and self.__pipeline.get_input_optional():
            self.__inputqueue = CommandQueue()
            self.__pipeline.set_input_queue(self.__inputqueue)
        self.append_ostream(pipeline.get_output_type(), None, pipeline.get_output(), False)
        for aux in pipeline.get_auxstreams():
            self.append_ostream(aux.schema.otype, aux.name, aux.queue, aux.schema.merge_default)
Example #4
0
class MultiObjectsDisplay(gtk.Notebook):
    __gsignals__ = {
        "primary-complete" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
    }
        
    def __init__(self, context, pipeline):
        super(MultiObjectsDisplay, self).__init__()
        self.__context = context
        self.__pipeline = pipeline
        self.__cancelled = False
        self.__default_odisp = None
        self.__queues = {}
        self.__ocount = 0
        self.__do_autoswitch = True
        self.__suppress_noyield = not not list(pipeline.get_status_commands())
        self.set_show_tabs(False)

        self.__inputqueue = None
        intype = self.__pipeline.get_input_type()
        _logger.debug("input type %s opt: %s", intype, self.__pipeline.get_input_optional())
        # FIXME assume for the moment we can only input strings; also explicitly avoid allowing input for 'any'
        # Long term we might consider only allowing input for SysBuiltin.
        if intype not in (None, 'any') and Pipeline.streamtype_is_assignable(intype, str, False) and self.__pipeline.get_input_optional():
            self.__inputqueue = CommandQueue()
            self.__pipeline.set_input_queue(self.__inputqueue)
        self.append_ostream(pipeline.get_output_type(), None, pipeline.get_output(), False)
        for aux in pipeline.get_auxstreams():
            self.append_ostream(aux.schema.otype, aux.name, aux.queue, aux.schema.merge_default)

    def start_search(self, old_focus):
        self.__default_odisp.start_search(old_focus)

    def supports_input(self):
        return self.__default_odisp and self.__default_odisp.supports_input()

    def start_input(self, old_focus):
        self.__default_odisp.start_input(old_focus)

    def do_copy(self):
        return self.__default_odisp.do_copy()

    def get_opt_formats(self):
        if self.__default_odisp:
            return self.__default_odisp.get_opt_formats()
        return []

    def get_pipeline(self):
        return self.__pipeline

    def get_output_common_supertype(self):
        if self.__default_odisp:
            return self.__default_odisp.get_output_common_supertype()
        return None
    
    def make_snapshot(self, selected=False):
        odisp = self.__default_odisp
        if selected:
            objs = self.__default_odisp.get_selected_objects()
        else:          
            objs = self.__default_odisp.get_objects()
        # snapshot it - FIXME this should really be async
        objs = list(objs)      
        if self.__pipeline.is_singlevalue:
            return objs[0]
        return objs

    def append_ostream(self, otype, name, queue, merged):
        label = name or ''
        if merged:
            odisp = self.__default_odisp
        elif not (otype is None):
            odisp = ObjectsDisplay(otype, self.__context) 
            if name is None:
                self.__default_odisp = odisp
                odisp.connect('object-input', self.__on_object_input)
                odisp.connect('status-changed', self.__on_status_change)                
                self.__default_odisp
                self.insert_page(odisp, position=0)
                self.set_tab_label_text(odisp, name or 'Default')
                odisp.show_all()
        elif not self.__suppress_noyield:
            self.__noobjects = gtk.Label()
            self.__noobjects.set_alignment(0, 0)
            self.__noobjects.set_markup('<i>(Pipeline yields no objects)</i>')
            self.__noobjects.show()
            self.insert_page(self.__noobjects, position=0)
            odisp = None
        else:
            odisp = None
        self.__queues[queue] = (odisp, name, merged)
        queue.connect(self.__idle_handle_output, priority=gobject.PRIORITY_LOW)

    def cancel(self):
        self.__cancelled = True
        for queue in self.__queues.iterkeys():
            queue.disconnect()

    def get_ocount(self):
        return self.__ocount

    def get_status_str(self):
        return self.__default_odisp and self.__default_odisp.get_status_str()
    
    def get_default_output_type(self):
        return self.__default_odisp and self.__default_odisp.get_output_type()
    
    def __on_object_input(self, odisp, obj):
        self.__inputqueue.put(obj)
        
    def __on_status_change(self, odisp):
        self.emit("changed")
        
    def __idle_handle_output(self, queue):
        if self.__cancelled:
            _logger.debug("cancelled")
            return False
        empty = False
        changed = False
        (odisp, name, merged) = self.__queues[queue]
        odisp_displayed = odisp in self.get_children()
        active_odisp = False
        maxitems = 100
        i = 0
        append_kwargs = {}
        if queue.opt_type:
            append_kwargs['fmt'] = queue.opt_type
        try:
            while i < maxitems:
                i += 1
                item = queue.get(False)
                changed = True
                if item is None:
                    if name is None:
                        self.emit("primary-complete")
                    empty = True
                    queue.disconnect()
                    break
                _logger.debug("appending item: %s", item)
                if odisp:
                    if not odisp_displayed:
                        self.append_page(odisp)
                        odisp.show_all()
                        self.set_tab_label_text(odisp, name or 'Default')
                        self.set_show_tabs(True)
                        odisp_displayed = True
                    odisp.append_object(item, **append_kwargs)
                    self.__ocount += 1
                    if self.__do_autoswitch:
                        self.set_current_page(self.page_num(odisp))
                        self.__do_autoswitch = False
                    active_odisp = True
                else:
                    _logger.warn("Unexpected item %s from queue %s", item, name)
        except Queue.Empty:
            pass
        if empty:
            del self.__queues[queue]
        if active_odisp:
            odisp.do_autoscroll()
        if changed:
            self.emit("changed")
        readd_idle = (not empty) and (i == maxitems)
        _logger.debug("doing idle readd: %s", readd_idle)
        return readd_idle

    def scroll_up(self, full=False):
        self.get_nth_page(self.get_current_page()).scroll_up(full)
        
    def scroll_down(self, full=False):
        self.get_nth_page(self.get_current_page()).scroll_down(full)
Example #5
0
class MultiObjectsDisplay(gtk.Notebook):
    __gsignals__ = {
        "primary-complete": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        "changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
    }

    def __init__(self, context, pipeline):
        super(MultiObjectsDisplay, self).__init__()
        self.__context = context
        self.__pipeline = pipeline
        self.__cancelled = False
        self.__default_odisp = None
        self.__queues = {}
        self.__ocount = 0
        self.__do_autoswitch = True
        self.__suppress_noyield = not not list(pipeline.get_status_commands())
        self.set_show_tabs(False)

        self.__inputqueue = None
        intype = self.__pipeline.get_input_type()
        _logger.debug("input type %s opt: %s", intype,
                      self.__pipeline.get_input_optional())
        # FIXME assume for the moment we can only input strings; also explicitly avoid allowing input for 'any'
        # Long term we might consider only allowing input for SysBuiltin.
        if intype not in (None, 'any') and Pipeline.streamtype_is_assignable(
                intype, str, False) and self.__pipeline.get_input_optional():
            self.__inputqueue = CommandQueue()
            self.__pipeline.set_input_queue(self.__inputqueue)
        self.append_ostream(pipeline.get_output_type(), None,
                            pipeline.get_output(), False)
        for aux in pipeline.get_auxstreams():
            self.append_ostream(aux.schema.otype, aux.name, aux.queue,
                                aux.schema.merge_default)

    def start_search(self, old_focus):
        self.__default_odisp.start_search(old_focus)

    def supports_input(self):
        return self.__default_odisp and self.__default_odisp.supports_input()

    def start_input(self, old_focus):
        self.__default_odisp.start_input(old_focus)

    def do_copy(self):
        return self.__default_odisp.do_copy()

    def get_opt_formats(self):
        if self.__default_odisp:
            return self.__default_odisp.get_opt_formats()
        return []

    def get_pipeline(self):
        return self.__pipeline

    def get_output_common_supertype(self):
        if self.__default_odisp:
            return self.__default_odisp.get_output_common_supertype()
        return None

    def make_snapshot(self, selected=False):
        odisp = self.__default_odisp
        if selected:
            objs = self.__default_odisp.get_selected_objects()
        else:
            objs = self.__default_odisp.get_objects()
        # snapshot it - FIXME this should really be async
        objs = list(objs)
        if self.__pipeline.is_singlevalue:
            return objs[0]
        return objs

    def append_ostream(self, otype, name, queue, merged):
        label = name or ''
        if merged:
            odisp = self.__default_odisp
        elif not (otype is None):
            odisp = ObjectsDisplay(otype, self.__context)
            if name is None:
                self.__default_odisp = odisp
                odisp.connect('object-input', self.__on_object_input)
                odisp.connect('status-changed', self.__on_status_change)
                self.__default_odisp
                self.insert_page(odisp, position=0)
                self.set_tab_label_text(odisp, name or 'Default')
                odisp.show_all()
        elif not self.__suppress_noyield:
            self.__noobjects = gtk.Label()
            self.__noobjects.set_alignment(0, 0)
            self.__noobjects.set_markup('<i>(Pipeline yields no objects)</i>')
            self.__noobjects.show()
            self.insert_page(self.__noobjects, position=0)
            odisp = None
        else:
            odisp = None
        self.__queues[queue] = (odisp, name, merged)
        queue.connect(self.__idle_handle_output, priority=gobject.PRIORITY_LOW)

    def cancel(self):
        self.__cancelled = True
        for queue in self.__queues.keys():
            queue.disconnect()

    def get_ocount(self):
        return self.__ocount

    def get_status_str(self):
        return self.__default_odisp and self.__default_odisp.get_status_str()

    def get_default_output_type(self):
        return self.__default_odisp and self.__default_odisp.get_output_type()

    def __on_object_input(self, odisp, obj):
        self.__inputqueue.put(obj)

    def __on_status_change(self, odisp):
        self.emit("changed")

    def __idle_handle_output(self, queue):
        if self.__cancelled:
            _logger.debug("cancelled")
            return False
        empty = False
        changed = False
        (odisp, name, merged) = self.__queues[queue]
        odisp_displayed = odisp in self.get_children()
        active_odisp = False
        maxitems = 100
        i = 0
        append_kwargs = {}
        if queue.opt_type:
            append_kwargs['fmt'] = queue.opt_type
        try:
            while i < maxitems:
                i += 1
                item = queue.get(False)
                changed = True
                if item is None:
                    if name is None:
                        self.emit("primary-complete")
                    empty = True
                    queue.disconnect()
                    break
                _logger.debug("appending item: %s", item)
                if odisp:
                    if not odisp_displayed:
                        self.append_page(odisp)
                        odisp.show_all()
                        self.set_tab_label_text(odisp, name or 'Default')
                        self.set_show_tabs(True)
                        odisp_displayed = True
                    odisp.append_object(item, **append_kwargs)
                    self.__ocount += 1
                    if self.__do_autoswitch:
                        self.set_current_page(self.page_num(odisp))
                        self.__do_autoswitch = False
                    active_odisp = True
                else:
                    _logger.warn("Unexpected item %s from queue %s", item,
                                 name)
        except queue.Empty:
            pass
        if empty:
            del self.__queues[queue]
        if active_odisp:
            odisp.do_autoscroll()
        if changed:
            self.emit("changed")
        readd_idle = (not empty) and (i == maxitems)
        _logger.debug("doing idle readd: %s", readd_idle)
        return readd_idle

    def scroll_up(self, full=False):
        self.get_nth_page(self.get_current_page()).scroll_up(full)

    def scroll_down(self, full=False):
        self.get_nth_page(self.get_current_page()).scroll_down(full)