コード例 #1
0
    def populate(self, packet, proto_inst):
        """
        Populate the store with the fields of Protocol
        @param packet a Packet that cointains the proto_inst
               or None if not parent is setted
        @param proto_inst a Protocol object instance
        """

        if not proto_inst:
            return

        self.packet = packet
        root_iter = self.store.append(None, [proto_inst])

        # We have to use the get_fields method
        for field in backend.get_proto_fields(proto_inst):

            if not backend.is_showable_field(field, packet):
                continue

            tfield = TField(field, proto_inst)
            flag_iter = self.store.append(root_iter, [tfield])

            if backend.is_flags(field):
                for flag in backend.get_flag_keys(field):
                    self.store.append(flag_iter, [TFlag(flag, tfield)])

        self.tree.expand_row((0, ), False)
コード例 #2
0
    def __group_cell_func(self, col, cell, model, iter):
        obj = model.get_value(iter, 0)
        color, markup = self.style.mid[gtk.STATE_NORMAL], None

        if isinstance(obj, TFlag):
            color = None
            markup = '<b>%s</b>' % gobject.markup_escape_text(obj.ref)

        elif isinstance(obj, TField):
            # This is a property

            name = gobject.markup_escape_text(backend.get_field_name(obj.ref))
            proto = obj.proto

            if not backend.is_flags(obj.ref):
                color = None

            if backend.is_field_autofilled(obj.ref):
                markup = '<i>%s</i>' % name
            else:
                markup = '<b>%s</b>' % name
        else:
            # Ok. This is the protocol
            name = gobject.markup_escape_text(backend.get_proto_name(obj))
            markup = '<b>%s</b>' % name

        # Setting the values
        cell.set_property('cell-background-gdk', color)
        cell.set_property('markup', markup)
コード例 #3
0
    def __property_cell_func(self, col, cell, model, iter):
        cell.editor, cell.field = None, None
        cell.set_property('editable', False)
        cell.set_property('text', '')

        obj = model.get_value(iter, 0)

        if isinstance(obj, TField) and backend.is_flags(obj.ref):
            # Flag container

            cell.set_property('cell-background-gdk',
                              self.style.mid[gtk.STATE_NORMAL])

            value = backend.get_field_value_repr(obj.proto, obj.ref)

            try:
                if value:
                    cell.set_property('markup', '<tt>%s</tt>' % \
                                  gobject.markup_escape_text(unicode(value)))
            except UnicodeDecodeError:
                cell.set_property('markup', _('<tt>N/A</tt>'))


        # If we are a field or a string (a sub field of flags)
        elif isinstance(obj, (TField, TFlag)):

            cell.field = None
            cell.set_property('editable', True)
            cell.set_property('cell-background-gdk', None)

            # We have a standard field

            if isinstance(obj, TField):
                value = backend.get_field_value(obj.proto, obj.ref)

                if value is not None:
                    try:
                        value = gobject.markup_escape_text(unicode(value))
                    except UnicodeDecodeError:
                        value = None

                if not value:
                    value = _("N/A")

                cell.set_property('markup', '<tt>%s</tt>' % value)
                cell.editor = get_editor(obj.ref)

                if cell.editor:
                    cell.field = (obj.proto, obj.ref)

            elif isinstance(obj, TFlag):
                # We have a subkey of Flags

                cell.editor = BitEditor
                cell.field = (obj.proto, obj.field.ref, obj.ref)
        else:
            cell.set_property('cell-background-gdk',
                              self.style.mid[gtk.STATE_NORMAL])
コード例 #4
0
    def __pixbuf_cell_func(self, col, cell, model, iter):
        obj = model.get_value(iter, 0)

        icon, color = None, self.style.mid[gtk.STATE_NORMAL]

        if isinstance(obj, TFlag):
            color = None

        elif isinstance(obj, TField):
            if not backend.is_flags(obj.ref): # Not a flag container
                color = None

            if backend.is_field_autofilled(obj.ref):
                icon = self.icon_locked

        cell.set_property('cell-background-gdk', color)
        cell.set_property('pixbuf', icon)