Example #1
0
    def build_widget(self):
        hbox=gtk.HBox()

        if self.predefined:
            preselect=self.tales2text(self.predefined[0][0])
        else:
            preselect=None
        self.combo=dialog.list_selector_widget(members=[ (self.tales2text(e), d) for (e, d) in self.predefined ],
                                               preselect=preselect,
                                               entry=True)
        self.entry=self.combo.child
        self.entry.connect('changed', lambda e: self.entry.set_tooltip_text(self.combo.get_current_element()))
        self.entry.set_tooltip_text(self.combo.get_current_element())

        hbox.pack_start(self.combo, expand=True)

        if config.data.preferences['expert-mode']:
            b=gtk.Button(stock=gtk.STOCK_FIND)
            b.connect('clicked', self.browse_expression)
            hbox.pack_start(b, expand=False)

        hbox.show_all()
        return hbox
Example #2
0
    def build_widget(self):
        frame=gtk.Frame()
        self.framelabel=gtk.Label()
        self.framelabel.set_markup(_("Rule <b>%s</b>") % self.model.name.replace('<', '&lt;'))
        self.framelabel.show()
        frame.set_label_widget(self.framelabel)

        vbox=gtk.VBox()
        frame.add(vbox)
        vbox.show()

        # Rule name
        hbox=gtk.HBox()

        hbox.pack_start(gtk.Label(_("Rule name")), expand=False)
        self.name_entry=gtk.Entry()
        self.name_entry.set_text(self.model.name)
        self.name_entry.set_editable(self.editable)
        self.name_entry.connect('changed', self.update_name)
        hbox.add(self.name_entry)

        b=gtk.Button(stock=gtk.STOCK_COPY)
        b.connect('drag-data-get', self.drag_sent)
        b.drag_source_set(gtk.gdk.BUTTON1_MASK,
                          config.data.drag_type['rule'], gtk.gdk.ACTION_COPY)
        hbox.pack_start(b, expand=False)

        hbox.show_all()
        vbox.pack_start(hbox, expand=False)

        # Event
        ef=gtk.Frame(_("Event"))
        self.editevent=EditEvent(self.model.event, catalog=self.catalog,
                                 editable=self.editable, controller=self.controller)
        ef.add(self.editevent.get_widget())
        ef.show_all()
        vbox.pack_start(ef, expand=False)

        # Conditions
        cf=gtk.Frame(_("If"))
        conditionsbox=gtk.VBox()
        cf.add(conditionsbox)

        # "Add condition" button
        hb=gtk.HBox()
        b=gtk.Button(stock=gtk.STOCK_ADD)
        b.connect('clicked', self.add_condition, conditionsbox)
        b.set_sensitive(self.editable)
        hb.pack_start(b, expand=False)
        hb.set_homogeneous(False)

        hb.add(gtk.HBox())

        def change_composition(combo):
            self.composition=combo.get_current_element()
            return True

        c=dialog.list_selector_widget( [ ('and', _("All conditions must be met") ),
                                         ('or', _("Any condition can be met") ) ],
                                       preselect=self.composition,
                                       callback=change_composition)
        hb.pack_start(c, expand=False)

        conditionsbox.pack_start(hb, expand=False, fill=False)

        cf.show_all()

        if isinstance(self.model.condition, advene.rules.elements.ConditionList):
            for c in self.model.condition:
                self.add_condition_widget(c, conditionsbox)
        else:
            if self.model.condition != self.model.default_condition:
                # Should not happen
                raise Exception("condition should be a conditionlist")

        vbox.pack_start(cf, expand=False)

        # Actions
        af=gtk.Frame(_("Then"))
        actionsbox=gtk.VBox()
        af.add(actionsbox)
        hb=gtk.HBox()
        # Add Action button
        b=gtk.Button(stock=gtk.STOCK_ADD)
        b.connect('clicked', self.add_action, actionsbox)
        b.set_sensitive(self.editable)
        hb.pack_start(b, expand=False)
        hb.set_homogeneous(False)
        actionsbox.pack_start(hb, expand=False, fill=False)

        for a in self.model.action:
            self.add_action_widget(a, actionsbox)

        vbox.pack_start(af, expand=False)
        af.show_all()

        frame.show()

        return frame
Example #3
0
    def build_widget(self):
        frame=gtk.Frame()

        vbox=gtk.VBox()
        frame.add(vbox)
        vbox.show()

        # Event
        ef=gtk.Frame(_("For all elements in "))
        predef=[ ('package/annotations', _("All annotations of the package")),
                 ('package/views', _("All views of the package")),
                 ('here/annotations', _("The context annotations")),
                 ('here/type/annotations', _("The annotations of the context type"))]
        for at in self.controller.package.annotationTypes:
            predef.append( ('package/annotationTypes/%s/annotations' % at.id,
                            _("Annotations of type %s") % self.controller.get_title(at) ) )
        self.sourceentry=TALESEntry(context=self.model,
                                    controller=self.controller,
                                    predefined=predef)
        self.sourceentry.set_text(";".join(self.model.sources))
        self.sourceentry.set_editable(self.editable)
        ef.add(self.sourceentry.widget)
        ef.show_all()
        vbox.pack_start(ef, expand=False)

        if config.data.preferences['expert-mode']:
            # Return value
            vf=gtk.Frame(_("Return "))
            self.valueentry=TALESEntry(context=self.model,
                                       predefined=[ ('element', _("The element")),
                                                    ('element/content/data', _("The element's content")) ],
                                       controller=self.controller)
            v=self.model.rvalue
            if v is None or v == '':
                v='element'
            self.valueentry.set_text(v)
            self.valueentry.set_editable(self.editable)
            vf.add(self.valueentry.widget)
            vf.show_all()
            vbox.pack_start(vf, expand=False)
        else:
            self.valueentry=None

        # Conditions
        if config.data.preferences['expert-mode']:
            cf=gtk.Frame(_("If the element matches "))
        else:
            cf=gtk.Frame(_("Return the element if it matches "))
        conditionsbox=gtk.VBox()
        cf.add(conditionsbox)

        # "Add condition" button
        hb=gtk.HBox()
        b=gtk.Button(stock=gtk.STOCK_ADD)
        b.connect('clicked', self.add_condition, conditionsbox)
        b.set_sensitive(self.editable)
        hb.pack_start(b, expand=False)
        hb.set_homogeneous(False)

        hb.add(gtk.HBox())

        def change_composition(combo):
            self.composition=combo.get_current_element()
            return True

        c=dialog.list_selector_widget( [ ('and', _("All conditions must be met") ),
                                         ('or', _("Any condition can be met") ) ],
                                       preselect=self.composition,
                                       callback=change_composition)
        hb.pack_start(c, expand=False)

        conditionsbox.pack_start(hb, expand=False, fill=False)

        cf.show_all()

        if isinstance(self.model.condition, advene.rules.elements.ConditionList):
            for c in self.model.condition:
                self.add_condition_widget(c, conditionsbox)

        vbox.pack_start(cf, expand=False)

        frame.show()

        return frame
Example #4
0
    def convert_transcription_cb(self, button=None):
        if not self.controller.gui:
            self.message(_("Cannot convert the data: no associated package"))
            return True

        d = Gtk.Dialog(title=_("Converting transcription"),
                       parent=self.controller.gui.gui.win,
                       flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
                       buttons=( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                 Gtk.STOCK_OK, Gtk.ResponseType.OK,
                                 ))
        l=Gtk.Label(label=_("Choose the annotation-type where to create annotations.\n"))
        l.set_line_wrap(True)
        l.show()
        d.vbox.pack_start(l, False, True, 0)

        # Anticipated declaration of some widgets, which need to be
        # updated in the handle_new_type_selection callback.
        new_type_dialog=Gtk.VBox()
        delete_existing_toggle=Gtk.CheckButton(_("Delete existing annotations in this type"))
        delete_existing_toggle.set_active(False)

        ats=list(self.controller.package.annotationTypes)
        newat=helper.TitledElement(value=None,
                                   title=_("Create a new annotation type"))
        ats.append(newat)

        def handle_new_type_selection(combo):
            el=combo.get_current_element()
            if el == newat:
                new_type_dialog.show()
                delete_existing_toggle.set_sensitive(False)
            else:
                new_type_dialog.hide()
                delete_existing_toggle.set_sensitive(True)
            return True

        type_selection=dialog.list_selector_widget(members=[ (a, self.controller.get_title(a), self.controller.get_element_color(a)) for a in ats],
                                                   callback=handle_new_type_selection,
                                                   preselect=self.controller.package.get_element_by_id(self.options['annotation-type-id']))

        hb=Gtk.HBox()
        hb.pack_start(Gtk.Label(_("Select type") + " "), False, False, 0)
        hb.pack_start(type_selection, False, True, 0)
        d.vbox.pack_start(hb, False, True, 0)

        l=Gtk.Label(label=_("You want to create a new type. Please specify its schema and title."))
        l.set_line_wrap(True)
        l.show()
        new_type_dialog.pack_start(l, False, True, 0)

        hb=Gtk.HBox()
        hb.pack_start(Gtk.Label(_("Title") + " "), False, False, 0)
        new_title=Gtk.Entry()
        hb.pack_start(new_title, True, True, 0)
        new_type_dialog.pack_start(hb, False, True, 0)

        hb=Gtk.HBox()
        hb.pack_start(Gtk.Label(_("Containing schema") + " "), False, False, 0)
        schemas=list(self.controller.package.schemas)
        schema_selection=dialog.list_selector_widget(members=[ (s, self.controller.get_title(s)) for s in schemas])
        hb.pack_start(schema_selection, False, True, 0)
        new_type_dialog.pack_start(hb, False, True, 0)

        new_type_dialog.show_all()
        new_type_dialog.set_no_show_all(True)
        new_type_dialog.hide()

        d.vbox.pack_start(new_type_dialog, True, True, 0)

        l=Gtk.Label()
        l.set_markup("<b>" + _("Export options") + "</b>")
        d.vbox.pack_start(l, False, True, 0)

        d.vbox.pack_start(delete_existing_toggle, False, True, 0)

        empty_contents_toggle=Gtk.CheckButton(_("Generate annotations for empty contents"))
        empty_contents_toggle.set_active(self.options['empty-annotations'])
        d.vbox.pack_start(empty_contents_toggle, False, True, 0)

        d.connect('key-press-event', dialog.dialog_keypressed_cb)

        d.show_all()
        dialog.center_on_mouse(d)

        finished=None
        while not finished:
            res=d.run()
            if res == Gtk.ResponseType.OK:
                at=type_selection.get_current_element()
                if at == newat:
                    new_type_title=new_title.get_text()
                    if new_type_title == '':
                        # Empty title. Generate one.
                        id_=self.controller.package._idgenerator.get_id(AnnotationType)
                        new_type_title=id_
                    else:
                        id_=helper.title2id(new_type_title)
                        # Check that the id is available
                        if self.controller.package._idgenerator.exists(id_):
                            dialog.message_dialog(
                                _("The %s identifier already exists. Choose another one.") % id_,
                                icon=Gtk.MessageType.WARNING)
                            at=None
                            continue
                    # Creating a new type
                    s=schema_selection.get_current_element()
                    at=s.createAnnotationType(ident=id_)
                    at.author=config.data.userid
                    at.date=helper.get_timestamp()
                    at.title=new_type_title
                    at.mimetype='text/plain'
                    at.setMetaData(config.data.namespace, 'color', next(s.rootPackage._color_palette))
                    at.setMetaData(config.data.namespace, 'item_color', 'here/tag_color')
                    s.annotationTypes.append(at)
                    self.controller.notify('AnnotationTypeCreate', annotationtype=at)

                if delete_existing_toggle.get_active():
                    # Remove all annotations of at type
                    batch_id=object()
                    for a in at.annotations:
                        self.controller.delete_element(a, batch=batch_id)

                self.options['empty-annotations']=empty_contents_toggle.get_active()
                finished=True
            else:
                at=None
                finished=True
        d.destroy()

        if at is not None:
            self.options['annotation-type-id'] = at.id
            ti=TranscriptionImporter(package=self.controller.package,
                                     controller=self.controller,
                                     defaulttype=at,
                                     transcription_edit=self)
            ti.process_file('transcription')

            self.controller.package._modified=True
            self.controller.notify("PackageActivate", package=ti.package)
            self.message(_('Notes converted'))
            self.log(ti.statistics_formatted())
            # Feedback
            dialog.message_dialog(
                _("Conversion completed.\n%s annotations generated.") % ti.statistics['annotation'])

        return True
Example #5
0
    def build_widget(self):
        vbox=gtk.VBox()

        def updated_filename(entry):
            self.update_importers()
            return True

        def select_filename(b):
            if config.data.path['data']:
                d=config.data.path['data']
            else:
                d=None
            filename=dialog.get_filename(title=_("Choose the file to import"),
                                                  action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                                  button=gtk.STOCK_OPEN,
                                                  default_dir=d,
                                                  filter='any')
            if not filename:
                return True
            self.filename_entry.set_text(filename)
            return True

        line=gtk.HBox()
        vbox.pack_start(line, expand=False)

        line.pack_start(gtk.Label(_("Filename")), expand=False)
        self.filename_entry=gtk.Entry()
        self.filename_entry.connect('changed', updated_filename)
        line.pack_start(self.filename_entry)

        self.progressbar=gtk.ProgressBar()
        vbox.pack_start(self.progressbar, expand=False)

        b=gtk.Button(stock=gtk.STOCK_OPEN)
        b.connect('clicked', select_filename)
        line.pack_start(b, expand=False)

        # Importer choice list
        line=gtk.HBox()
        vbox.pack_start(line, expand=False)

        line.pack_start(gtk.Label(_("Import filter")), expand=False)
        self.importers=dialog.list_selector_widget([], None)
        line.pack_start(self.importers, expand=False)

        bb=gtk.HButtonBox()

        b=gtk.Button(stock=gtk.STOCK_CONVERT)
        b.connect('clicked', self.convert_file)
        b.set_sensitive(False)
        bb.pack_start(b, expand=False)
        self.convert_button=b

        vbox.buttonbox=bb
        vbox.pack_start(bb, expand=False)

        self.update_importers()

        vbox.show_all()

        return vbox
Example #6
0
    def build_widget(self, modal=False):
        i=self.generate_id()
        if modal:
            flags=gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL
        else:
            flags=gtk.DIALOG_DESTROY_WITH_PARENT

        d=dialog.title_id_dialog(title=_("%s creation")  % element_label[self.type_],
                                          text=_("To create a new element of type %s,\nyou must give the following information.") % element_label[self.type_],
                                          element_title=i,
                                          element_id=i,
                                          flags=flags)
        d.type_combo=None

        # Choose a type if possible
        if self.type_ in (Annotation, Relation, AnnotationType, RelationType,
                          View, Query, Resources, ResourceData):
            hbox = gtk.HBox()
            l = gtk.Label(_("Type"))
            hbox.pack_start(l)

            if self.type_ == Annotation:
                if isinstance(self.parent, AnnotationType):
                    type_list = [ self.parent ]
                else:
                    type_list = self.parent.annotationTypes
            elif self.type_ == Relation:
                if isinstance(self.parent, RelationType):
                    type_list = [ self.parent ]
                else:
                    type_list = self.parent.relationTypes
            elif self.type_ in (AnnotationType, RelationType):
                type_list = [ ViewType('text/plain', _("Plain text content")),
                              ViewType('application/x-advene-structured', _("Simple-structured content")),
                              ViewType('image/svg+xml', _("SVG graphics content")),
                              ]
            elif self.type_ == View:
                type_list = [ ViewType('application/x-advene-ruleset', _("Dynamic view")),
                              ViewType('text/html', _("HTML template")),
                              ViewType('application/xml', _("Plain XML")),
                              ViewType('image/svg+xml', _("SVG template")),
                              ViewType('text/plain', _("Plain text template")),
                              ]
            elif self.type_ == Query:
                type_list = [ ViewType('application/x-advene-simplequery', _("Simple query")) ]
            elif self.type_ == Resources:
                type_list = [ ViewType(Resources.DIRECTORY_TYPE, _("Directory")) ]
            elif self.type_ == ResourceData:
                type_list = [ ViewType("file", _("Resource File")) ]
            else:
                print "Error in advene.gui.edit.create.build_widget: invalid type %s" % self.type_
                return None

            if not type_list:
                dialog.message_dialog(_("No available type."))
                return None

            # Check for self.mimetype
            if self.mimetype is None:
                preselect=type_list[0]
            else:
                l=[ e for e in type_list if e.id == self.mimetype ]
                if l:
                    preselect=l[0]
                else:
                    # Insert self.mimetype in the list
                    preselect=ViewType(self.mimetype, self.mimetype)
                    type_list.insert(0, preselect)
            d.type_combo = dialog.list_selector_widget(
                members=[ (t, self.controller.get_title(t)) for t in type_list  ],
                preselect=preselect)
            hbox.pack_start(d.type_combo)

            d.vbox.add(hbox)

        d.show_all()
        return d
Example #7
0
    def build_widget(self):
        self.zoom_adjustment=gtk.Adjustment(value=1.0, lower=0.01, upper=2.0)

        def zoom_adj_change(adj):
            # Update the value of self.scale accordingly
            # Get the window size
            if not self.mainbox.window:
                # The widget is not yet realized
                return True
            display_size=self.mainbox.parent.window.get_size()[0]
            # Dropzones are approximately 10 pixels wide, and should
            # be taken into account, but it enforces handling the corner cases
            self.scale.value = 1.0 * self.duration / (display_size / adj.value )

            # Update the zoom combobox value
            self.zoom_combobox.child.set_text('%d%%' % long(100 * adj.value))
            return True

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['uri-list']:
                m=re.match('advene:/adhoc/%d/(.+)' % hash(self),
                           selection.data)
                if m:
                    h=long(m.group(1))
                    l=[ w for w in self.contents if hash(w) == h ]
                    if l:
                        # Found the element. Remove it.
                        self.contents.remove(l[0])
                        self.refresh()
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        self.zoom_adjustment.connect('value-changed', zoom_adj_change)

        v=gtk.VBox()

        # Toolbar
        tb=gtk.Toolbar()
        tb.set_style(gtk.TOOLBAR_ICONS)

        b=get_small_stock_button(gtk.STOCK_DELETE)
        b.set_tooltip_text(_("Drop an annotation here to remove it from the list"))
        b.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                        gtk.DEST_DEFAULT_HIGHLIGHT |
                        gtk.DEST_DEFAULT_ALL,
                        config.data.drag_type['uri-list'], gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK)
        b.connect('drag-data-received', remove_drag_received)
        ti=gtk.ToolItem()
        ti.add(b)
        tb.insert(ti, -1)

        b=gtk.ToolButton(gtk.STOCK_MEDIA_PLAY)
        b.set_tooltip_text(_("Play the montage"))
        b.connect('clicked', self.play)
        tb.insert(b, -1)

        b = gtk.ToolButton(gtk.STOCK_SAVE)
        b.set_tooltip_text(_("Save the view in the package"))
        b.connect('clicked', self.save_view)
        tb.insert(b, -1)

        def zoom_entry(entry):
            f=unicode(entry.get_text())

            i=re.findall(r'\d+', f)
            if i:
                f=int(i[0])/100.0
            else:
                return True
            self.zoom_adjustment.value=f
            return True

        def zoom_change(combo):
            v=combo.get_current_element()
            if isinstance(v, float):
                self.zoom_adjustment.value=v
            return True

        def zoom(i, factor):
            self.zoom_adjustment.value=self.zoom_adjustment.value * factor
            return True

        b=gtk.ToolButton(gtk.STOCK_ZOOM_OUT)
        b.connect('clicked', zoom, 1.3)
        b.set_tooltip_text(_("Zoom out"))
        tb.insert(b, -1)

        b=gtk.ToolButton(gtk.STOCK_ZOOM_IN)
        b.connect('clicked', zoom, .7)
        b.set_tooltip_text(_("Zoom in"))
        tb.insert(b, -1)

        self.zoom_combobox=dialog.list_selector_widget(members=[
                ( f, "%d%%" % long(100*f) )
                for f in [
                    (1.0 / pow(1.5, n)) for n in range(0, 10)
                    ]
                ],
                                                       entry=True,
                                                       callback=zoom_change)
        self.zoom_combobox.child.connect('activate', zoom_entry)
        self.zoom_combobox.child.set_width_chars(4)

        ti=gtk.ToolItem()
        ti.add(self.zoom_combobox)
        ti.set_tooltip_text(_("Set zoom level"))
        tb.insert(ti, -1)

        b=gtk.ToolButton(gtk.STOCK_ZOOM_100)
        b.connect('clicked', lambda i: self.zoom_adjustment.set_value(1.0))
        b.set_tooltip_text(_("Set 100% zoom"))
        tb.insert(b, -1)

        def toggle_highlight(b):
            if b.highlight:
                event="AnnotationActivate"
                label= _("Unhighlight annotations")
                b.highlight=False
            else:
                event="AnnotationDeactivate"
                label=_("Highlight annotations")
                b.highlight=True
            b.set_tooltip_text(label)
            for a in set( [ w.annotation for w in self.contents ] ):
                self.controller.notify(event, annotation=a)
            return True
        i=gtk.Image()
        i.set_from_file(config.data.advenefile( ( 'pixmaps', 'highlight.png') ))
        b=gtk.ToggleToolButton()
        b.set_tooltip_text(_("Highlight annotations"))
        b.set_icon_widget(i)
        b.highlight=True
        b.connect('clicked', toggle_highlight)
        tb.insert(b, -1)

        v.pack_start(tb, expand=False)

        self.mainbox=gtk.HBox()

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['annotation']:
                sources=[ self.controller.package.annotations.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ]
                for ann in sources:
                    if ann is None:
                        self.log("Problem when getting annotation from DND")
                        pass
                    self.insert(ann)
                    # If the origin is from the same montage, then
                    # consider it is a move and remove the origin
                    # annotation
                    w=context.get_source_widget()
                    if w in self.contents:
                        self.contents.remove(w)
                self.refresh()
                return True
            elif targetType == config.data.target_type['annotation-type']:
                at=self.controller.package.annotationTypes.get(unicode(selection.data, 'utf8'))
                for a in at.annotations:
                    self.insert(a)
                self.refresh()
                return True
            else:
                print "Unknown target type for drag: %d" % targetType
            return False
        v.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                   gtk.DEST_DEFAULT_HIGHLIGHT |
                                   gtk.DEST_DEFAULT_ALL,
                                   config.data.drag_type['annotation']
                                   + config.data.drag_type['annotation-type'],
                                   gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE)
        v.connect('drag-data-received', mainbox_drag_received)

        sw=gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER)
        sw.add_with_viewport(self.mainbox)
        self.scrollwindow=sw

        v.pack_start(sw, expand=False)

        a=AnnotationDisplay(controller=self.controller)
        f=gtk.Frame(_("Inspector"))
        f.add(a.widget)
        v.add(f)
        self.controller.gui.register_view (a)
        a.set_master_view(self)
        a.widget.show_all()

        v.pack_start(gtk.VBox(), expand=True)

        hb=gtk.HBox()
        l=gtk.Label(_("Total duration:"))
        hb.pack_start(l, expand=False)
        self.duration_label=gtk.Label('??')
        hb.pack_start(self.duration_label, expand=False)
        v.pack_start(hb, expand=False)

        return v
Example #8
0
    def build_widget(self, modal=False):
        i = self.generate_id()
        if modal:
            flags = Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL
        else:
            flags = Gtk.DialogFlags.DESTROY_WITH_PARENT

        d = dialog.title_id_dialog(
            title=_("%s creation") % element_label[self.type_],
            text=
            _("To create a new element of type %s,\nyou must give the following information."
              ) % element_label[self.type_],
            element_title=i,
            element_id=i,
            flags=flags)
        d.type_combo = None

        # Choose a type if possible
        if self.type_ in (Annotation, Relation, AnnotationType, RelationType,
                          View, Query, Resources, ResourceData):
            hbox = Gtk.HBox()
            l = Gtk.Label(label=_("Type"))
            hbox.pack_start(l, True, True, 0)

            if self.type_ == Annotation:
                if isinstance(self.parent, AnnotationType):
                    type_list = [self.parent]
                else:
                    type_list = self.parent.annotationTypes
            elif self.type_ == Relation:
                if isinstance(self.parent, RelationType):
                    type_list = [self.parent]
                else:
                    type_list = self.parent.relationTypes
            elif self.type_ in (AnnotationType, RelationType):
                type_list = [
                    ViewType('text/plain', _("Plain text content")),
                    ViewType('application/x-advene-structured',
                             _("Simple-structured content")),
                    ViewType('text/x-advene-keyword-list',
                             _("Keyword list content")),
                    ViewType('image/svg+xml', _("SVG graphics content")),
                ]
            elif self.type_ == View:
                type_list = [
                    ViewType('application/x-advene-ruleset',
                             _("Dynamic view")),
                    ViewType('text/html', _("HTML template")),
                    ViewType('application/xml', _("Plain XML")),
                    ViewType('image/svg+xml', _("SVG template")),
                    ViewType('text/plain', _("Plain text template")),
                ]
            elif self.type_ == Query:
                type_list = [
                    ViewType('application/x-advene-simplequery',
                             _("Simple query"))
                ]
            elif self.type_ == Resources:
                type_list = [
                    ViewType(Resources.DIRECTORY_TYPE, _("Directory"))
                ]
            elif self.type_ == ResourceData:
                type_list = [ViewType("file", _("Resource File"))]
            else:
                logger.error(
                    "Error in advene.gui.edit.create.build_widget: invalid type %s",
                    self.type_)
                return None

            if not type_list:
                dialog.message_dialog(_("No available type."))
                return None

            # Check for self.mimetype
            if self.mimetype is None:
                preselect = type_list[0]
            else:
                l = [e for e in type_list if e.id == self.mimetype]
                if l:
                    preselect = l[0]
                else:
                    # Insert self.mimetype in the list
                    preselect = ViewType(self.mimetype, self.mimetype)
                    type_list.insert(0, preselect)
            d.type_combo = dialog.list_selector_widget(members=[
                (t, self.controller.get_title(t)) for t in type_list
            ],
                                                       preselect=preselect)
            hbox.pack_start(d.type_combo, True, True, 0)

            d.vbox.add(hbox)

        d.show_all()
        return d