Ejemplo n.º 1
0
    def from_xml(self, citeinfo):
        """
        parses the xml code into the relevant citation elements

        Parameters
        ----------
        citation - the xml element status and its contents

        Returns
        -------
        None
        """
        self.original_xml = citeinfo
        self.clear_widget()
        try:
            if citeinfo.tag == "citation":
                citeinfo = citeinfo.xpath("citeinfo")[0]
            if citeinfo.tag == "crossref":
                citeinfo = citeinfo.xpath("citeinfo")[0]
            elif citeinfo.tag != "citeinfo":
                print("The tag is not 'citation' or 'citeinfo'")
                return

            Citeinfo.from_xml(self, citeinfo)

        except KeyError:
            pass
Ejemplo n.º 2
0
    def build_ui(self, ):
        Citeinfo.build_ui(self)

        self.setObjectName("fgdc_crossref")
        self.ui.fgdc_lworkcit.hide()
        self.ui.lbl_dataset_title.setText("Crossref Title")
        self.ui.label_34.hide()
        self.ui.label_38.hide()
        self.ui.label_47.setText("Author/Originator")
        self.ui.label_53.setText("Format")
        self.ui.fgdc_geoform.setCurrentText("publication")
        self.ui.label_51.setText("Online Link to the Publication")
        self.ui.label_53.setText(
            "Can you provide more publication information?")
        self.ui.label_43.setText("Is this publication part of a series?")
Ejemplo n.º 3
0
    def build_ui(self):
        """
        Build and modify this widget's GUI

        Returns
        -------
        None
        """
        self.ui = UI_srcinfo.Ui_Form()
        self.ui.setupUi(self)
        self.timeinfo = Timeinfo()
        self.citation = Citeinfo(parent=self, include_lwork=False)

        self.ui.fgdc_srccite.layout().addWidget(self.citation)
        self.ui.fgdc_srctime.layout().insertWidget(0, self.timeinfo)

        self.setup_dragdrop(self)
Ejemplo n.º 4
0
    def build_ui(self):

        self.ui = self.ui_class()
        self.ui.setupUi(self)

        self.setup_dragdrop(self)

        self.ptcontac = ContactInfoPointOfContact(parent=self)
        self.taxonomy = Taxonomy(parent=self)
        self.keywords = Keywords(parent=self)
        self.accconst = Accconst(parent=self)
        self.useconst = Useconst(parent=self)
        self.status = Status(parent=self)
        self.timeperd = Timeperd(parent=self)
        self.citation = Citeinfo(parent=self)
        self.citation.ui.btn_import_doi.hide()
        self.datacredit = Datacred(parent=self)

        self.descript = Descript(parent=self)

        self.purpose = Purpose(parent=self)
        self.supplinf = SupplInf(parent=self)
        self.native = Native(parent=self)

        self.ui.fgdc_citation.layout().addWidget(self.citation)

        #bottom to top in layout
        time_hbox = QHBoxLayout()
        time_hbox.addWidget(self.status)
        time_hbox.addWidget(self.timeperd)
        self.ui.two_column_left.layout().insertWidget(0, self.native)
        self.ui.two_column_left.layout().insertLayout(0, time_hbox)
        self.ui.two_column_left.layout().insertWidget(0, self.datacredit)
        self.ui.two_column_left.layout().insertWidget(0, self.taxonomy)
        self.ui.two_column_left.layout().insertWidget(0, self.ptcontac)
        self.ui.two_column_left.layout().insertWidget(0, self.useconst)
        self.ui.two_column_left.layout().insertWidget(0, self.accconst)

        self.ui.two_column_right.layout().insertWidget(0, self.supplinf)
        self.ui.two_column_right.layout().insertWidget(0, self.keywords)
        self.ui.two_column_right.layout().insertWidget(0, self.purpose)
        self.ui.two_column_right.layout().insertWidget(0, self.descript)

        self.crossref_list = Crossref_list()
        self.ui.help_crossref.layout().addWidget(self.crossref_list)
Ejemplo n.º 5
0
    def to_xml(self):
        """
        encapsulates the QLineEdit text in an element tag

        Returns
        -------
        citation element tag in xml tree
        """
        citeinfo = Citeinfo.to_xml(self)
        crossref = xml_utils.xml_node("crossref")
        crossref.append(citeinfo)

        return crossref
Ejemplo n.º 6
0
class SRCInfo(WizardWidget):  #

    drag_label = "SRCInfo <srcinfo>"
    acceptable_tags = ['srcinfo']

    def build_ui(self):
        """
        Build and modify this widget's GUI

        Returns
        -------
        None
        """
        self.ui = UI_srcinfo.Ui_Form()
        self.ui.setupUi(self)
        self.timeinfo = Timeinfo()
        self.citation = Citeinfo(parent=self, include_lwork=False)

        self.ui.fgdc_srccite.layout().addWidget(self.citation)
        self.ui.fgdc_srctime.layout().insertWidget(0, self.timeinfo)

        self.setup_dragdrop(self)

    def connect_events(self):
        """
        Connect the appropriate GUI components with the corresponding functions

        Returns
        -------
        None
        """
        self.ui.fgdc_srccitea.editingFinished.connect(self.update_tab_label)
        self.ui.fgdc_srcscale.editingFinished.connect(self.format_scale)

    def update_tab_label(self):
        new_label = "Source: {}".format(self.ui.fgdc_srccitea.text()[:15])
        tab_widget = self.ui.fgdc_srccitea.parent().parent().parent().parent()
        current_index = tab_widget.currentIndex()
        tab_widget.setTabText(current_index, new_label)

    def format_scale(self):
        cur_text = self.ui.fgdc_srcscale.text().replace(',', '')
        try:
            if '.' in cur_text:
                formatted_text = '{:,}'.format(float(cur_text))
            else:
                formatted_text = '{:,}'.format(int(cur_text))
            self.ui.fgdc_srcscale.setText(formatted_text)
        except:
            pass

    def to_xml(self):
        """
        encapsulates the QLineEdit text in an element tag

        Returns
        -------
        srcinfo element tag in xml tree
        """
        srcinfo = xml_utils.xml_node('srcinfo')
        srccite = xml_utils.xml_node('srccite', parent_node=srcinfo)

        cite = self.citation.to_xml()
        srccite.append(cite)

        if self.ui.fgdc_srcscale.text():
            srcscale = xml_utils.xml_node(
                'srcscale',
                text=self.ui.fgdc_srcscale.text().replace(',', ''),
                parent_node=srcinfo)

        typesrc = xml_utils.xml_node('typesrc',
                                     text=self.ui.fgdc_typesrc.currentText(),
                                     parent_node=srcinfo)

        srctime = xml_utils.xml_node('srctime', parent_node=srcinfo)
        timeinfo = self.timeinfo.to_xml()
        srctime.append(timeinfo)

        srccurr = xml_utils.xml_node('srccurr',
                                     text=self.ui.fgdc_srccurr.currentText(),
                                     parent_node=srctime)

        srccitea = xml_utils.xml_node('srccitea',
                                      text=self.ui.fgdc_srccitea.text(),
                                      parent_node=srcinfo)

        srccontr = xml_utils.xml_node('srccontr',
                                      text=self.ui.fgdc_srccontr.toPlainText(),
                                      parent_node=srcinfo)

        return srcinfo

    def from_xml(self, srcinfo):
        """
        parses the xml code into the relevant srcinfo elements

        Parameters
        ----------
        srcinfo - the xml element status and its contents

        Returns
        -------
        None
        """
        try:
            if srcinfo.tag == "srcinfo":
                utils.populate_widget(self, srcinfo)
                srccite = srcinfo.xpath('srccite')[0]
                citeinfo = srccite.xpath('citeinfo')[0]
            elif srcinfo.tag != 'srcinfo':
                print("The tag is not 'srcinfo'")
                return

            self.citation.from_xml(citeinfo)

            utils.populate_widget_element(self.ui.fgdc_srcscale, srcinfo,
                                          'srcscale')
            self.format_scale()

            typesrc = srcinfo.xpath('typesrc/text()')
            typesrc_text = str(typesrc[0])
            self.findChild(QComboBox,
                           "fgdc_typesrc").setCurrentText(typesrc_text)

            utils.populate_widget_element(self.ui.fgdc_srccitea, srcinfo,
                                          'srccitea')
            utils.populate_widget_element(self.ui.fgdc_srccontr, srcinfo,
                                          'srccontr')

            if srcinfo.xpath('srctime'):
                timeinfo = srcinfo.xpath('srctime/timeinfo')[0]
                srccurr = srcinfo.xpath('srctime/srccurr')[0]
                self.timeinfo.from_xml(timeinfo)
                self.ui.fgdc_srccurr.setCurrentText(srccurr.text)

            self.update_tab_label()

        except KeyError:
            pass
Ejemplo n.º 7
0
class IdInfo(WizardWidget):

    drag_label = "Identification Information <idinfo>"
    acceptable_tags = ['abstract']

    ui_class = UI_IdInfo.Ui_fgdc_idinfo

    def __init__(self, root_widget=None, parent=None):
        super(self.__class__, self).__init__(parent=parent)
        self.schema = 'bdp'
        self.root_widget = root_widget

    def build_ui(self):

        self.ui = self.ui_class()
        self.ui.setupUi(self)

        self.setup_dragdrop(self)

        self.ptcontac = ContactInfoPointOfContact(parent=self)
        self.taxonomy = Taxonomy(parent=self)
        self.keywords = Keywords(parent=self)
        self.accconst = AccessConstraints(parent=self)
        self.useconst = UseConstraints(parent=self)
        self.status = Status(parent=self)
        self.timeperd = Timeperd(parent=self)
        self.citation = Citeinfo(parent=self)
        self.datacredit = DataCredit(parent=self)

        self.descript = Descript(parent=self)

        self.purpose = Purpose(parent=self)
        self.supplinf = SupplInf(parent=self)

        self.ui.fgdc_citation.layout().addWidget(self.citation)

        #bottom to top in layout
        time_hbox = QHBoxLayout()
        time_hbox.addWidget(self.status)
        time_hbox.addWidget(self.timeperd)
        self.ui.two_column_left.layout().insertLayout(0, time_hbox)
        self.ui.two_column_left.layout().insertWidget(0, self.datacredit)
        self.ui.two_column_left.layout().insertWidget(0, self.taxonomy)
        self.ui.two_column_left.layout().insertWidget(0, self.ptcontac)
        self.ui.two_column_left.layout().insertWidget(0, self.useconst)
        self.ui.two_column_left.layout().insertWidget(0, self.accconst)

        self.ui.two_column_right.layout().insertWidget(0, self.supplinf)
        self.ui.two_column_right.layout().insertWidget(0, self.keywords)
        self.ui.two_column_right.layout().insertWidget(0, self.purpose)
        self.ui.two_column_right.layout().insertWidget(0, self.descript)

    def dragEnterEvent(self, e):
        """

        Parameters
        ----------
        e : qt event

        Returns
        -------

        """
        print("idinfo drag enter")
        mime_data = e.mimeData()
        if e.mimeData().hasFormat('text/plain'):
            parser = etree.XMLParser(ns_clean=True,
                                     recover=True,
                                     encoding='utf-8')
            element = etree.fromstring(mime_data.text(), parser=parser)
            if element is not None and element.tag == 'idinfo':
                e.accept()
        else:
            e.ignore()

    def children(self):
        return super(IdInfo,
                     self).children() + [self.root_widget.spatial_tab.spdom]

    def switch_schema(self, schema):
        self.schema = schema
        if schema == 'bdp':
            self.taxonomy.show()
        else:
            self.taxonomy.hide()

    def clear_widget(self):
        self.root_widget.spatial_tab.spdom.clear_widget()
        WizardWidget.clear_widget(self)

    def _to_xml(self):
        # add code here to translate the form into xml representation
        idinfo_node = xml_utils.xml_node('idinfo')

        citation_node = xml_utils.xml_node('citation', parent_node=idinfo_node)
        citeinfo_node = self.citation._to_xml()
        citation_node.append(citeinfo_node)
        idinfo_node.append(citation_node)

        descript_node = xml_utils.xml_node('descript', parent_node=idinfo_node)
        abstract_node = self.descript._to_xml()
        descript_node.append(abstract_node)
        purpose_node = self.purpose._to_xml()
        descript_node.append(purpose_node)
        supplinf_node = self.supplinf._to_xml()
        if supplinf_node.text is not None:
            descript_node.append(supplinf_node)

        idinfo_node.append(descript_node)

        timeperd_node = self.timeperd._to_xml()
        idinfo_node.append(timeperd_node)

        status_node = self.status._to_xml()
        idinfo_node.append(status_node)

        spdom_node = self.root_widget.spatial_tab.spdom._to_xml()
        idinfo_node.append(spdom_node)

        keywords = self.keywords._to_xml()
        idinfo_node.append(keywords)

        if self.schema == 'bdp' and self.taxonomy.has_content():
            taxonomy = self.taxonomy._to_xml()
            idinfo_node.append(taxonomy)

        accconst_node = self.accconst._to_xml()
        idinfo_node.append(accconst_node)

        useconst_node = self.useconst._to_xml()
        idinfo_node.append(useconst_node)

        if self.ptcontac.has_content():
            ptcontac = self.ptcontac._to_xml()
            idinfo_node.append(ptcontac)

        datacredit_node = self.datacredit._to_xml()
        if datacredit_node.text:
            idinfo_node.append(datacredit_node)

        if self.original_xml is not None:
            secinfo = xml_utils.search_xpath(self.original_xml, 'secinfo')
            if secinfo is not None:
                idinfo_node.append(deepcopy(secinfo))

            native = xml_utils.search_xpath(self.original_xml, 'native')
            if native is not None:
                idinfo_node.append(deepcopy(native))

            crossref_list = xml_utils.search_xpath(self.original_xml,
                                                   'crossref',
                                                   only_first=False)
            for crossref in crossref_list:
                idinfo_node.append(deepcopy(crossref))

            tool = xml_utils.search_xpath(self.original_xml, 'tool')
            if tool is not None:
                idinfo_node.append(deepcopy(tool))

        return idinfo_node

    def _from_xml(self, xml_idinfo):

        self.original_xml = (xml_idinfo)

        citation = xml_utils.search_xpath(xml_idinfo, 'citation')
        if citation is not None:
            self.citation._from_xml(citation)

        abstract = xml_utils.search_xpath(xml_idinfo, 'descript/abstract')
        if abstract is not None:
            self.descript._from_xml(abstract)

        purpose = xml_utils.search_xpath(xml_idinfo, 'descript/purpose')
        if purpose is not None:
            self.purpose._from_xml(purpose)

        supplinf = xml_utils.search_xpath(xml_idinfo, 'descript/supplinf')
        if supplinf is not None:
            self.supplinf._from_xml(supplinf)

        timeperd = xml_utils.search_xpath(xml_idinfo, 'timeperd')
        if timeperd is not None:
            self.timeperd._from_xml(timeperd)

        status = xml_utils.search_xpath(xml_idinfo, 'status')
        if status is not None:
            self.status._from_xml(status)

        spdom = xml_utils.search_xpath(xml_idinfo, 'spdom')
        if spdom is not None:
            self.root_widget.spatial_tab.spdom._from_xml(spdom)

        keywords = xml_utils.search_xpath(xml_idinfo, 'keywords')
        if keywords is not None:
            self.keywords._from_xml(keywords)

        taxonomy = xml_utils.search_xpath(xml_idinfo, 'taxonomy')
        if taxonomy is not None:
            self.taxonomy._from_xml(taxonomy)

        accconst = xml_utils.search_xpath(xml_idinfo, 'accconst')
        if accconst is not None:
            self.accconst._from_xml(accconst)

        useconst = xml_utils.search_xpath(xml_idinfo, 'useconst')
        if useconst is not None:
            self.useconst._from_xml(useconst)

        ptcontac = xml_utils.search_xpath(xml_idinfo, 'ptcontac')
        if ptcontac is not None:
            self.ptcontac._from_xml(ptcontac)

        datacred = xml_utils.search_xpath(xml_idinfo, 'datacred')
        if datacred is not None:
            self.datacredit._from_xml(datacred)
Ejemplo n.º 8
0
class IdInfo(WizardWidget):

    drag_label = "Identification Information <idinfo>"
    acceptable_tags = ['idinfo']

    ui_class = UI_IdInfo.Ui_fgdc_idinfo

    def __init__(self, root_widget=None, parent=None):
        super(self.__class__, self).__init__(parent=parent)
        self.schema = 'bdp'
        self.root_widget = root_widget
        self.scroll_area = self.ui.idinfo_scroll_area

    def build_ui(self):

        self.ui = self.ui_class()
        self.ui.setupUi(self)

        self.setup_dragdrop(self)

        self.ptcontac = ContactInfoPointOfContact(parent=self)
        self.taxonomy = Taxonomy(parent=self)
        self.keywords = Keywords(parent=self)
        self.accconst = Accconst(parent=self)
        self.useconst = Useconst(parent=self)
        self.status = Status(parent=self)
        self.timeperd = Timeperd(parent=self)
        self.citation = Citeinfo(parent=self)
        self.citation.ui.btn_import_doi.hide()
        self.datacredit = Datacred(parent=self)

        self.descript = Descript(parent=self)

        self.purpose = Purpose(parent=self)
        self.supplinf = SupplInf(parent=self)
        self.native = Native(parent=self)

        self.ui.fgdc_citation.layout().addWidget(self.citation)

        #bottom to top in layout
        time_hbox = QHBoxLayout()
        time_hbox.addWidget(self.status)
        time_hbox.addWidget(self.timeperd)
        self.ui.two_column_left.layout().insertWidget(0, self.native)
        self.ui.two_column_left.layout().insertLayout(0, time_hbox)
        self.ui.two_column_left.layout().insertWidget(0, self.datacredit)
        self.ui.two_column_left.layout().insertWidget(0, self.taxonomy)
        self.ui.two_column_left.layout().insertWidget(0, self.ptcontac)
        self.ui.two_column_left.layout().insertWidget(0, self.useconst)
        self.ui.two_column_left.layout().insertWidget(0, self.accconst)

        self.ui.two_column_right.layout().insertWidget(0, self.supplinf)
        self.ui.two_column_right.layout().insertWidget(0, self.keywords)
        self.ui.two_column_right.layout().insertWidget(0, self.purpose)
        self.ui.two_column_right.layout().insertWidget(0, self.descript)

        self.crossref_list = Crossref_list()
        self.ui.help_crossref.layout().addWidget(self.crossref_list)

    def children(self):
        return super(IdInfo,
                     self).children() + [self.root_widget.spatial_tab.spdom]

    def switch_schema(self, schema):
        self.schema = schema
        if schema == 'bdp':
            self.taxonomy.show()
        else:
            self.taxonomy.hide()

    def clear_widget(self):
        self.root_widget.spatial_tab.spdom.clear_widget()
        self.taxonomy.clear_widget()
        self.taxonomy.ui.rbtn_no.setChecked(True)
        WizardWidget.clear_widget(self)

    def to_xml(self):
        # add code here to translate the form into xml representation
        idinfo_node = xml_utils.xml_node('idinfo')

        citation_node = xml_utils.xml_node('citation', parent_node=idinfo_node)
        citeinfo_node = self.citation.to_xml()
        citation_node.append(citeinfo_node)
        idinfo_node.append(citation_node)

        descript_node = xml_utils.xml_node('descript', parent_node=idinfo_node)
        abstract_node = self.descript.to_xml()
        descript_node.append(abstract_node)
        purpose_node = self.purpose.to_xml()
        descript_node.append(purpose_node)
        supplinf_node = self.supplinf.to_xml()
        if supplinf_node.text is not None:
            descript_node.append(supplinf_node)

        idinfo_node.append(descript_node)

        timeperd_node = self.timeperd.to_xml()
        idinfo_node.append(timeperd_node)

        status_node = self.status.to_xml()
        idinfo_node.append(status_node)

        if self.root_widget.use_spatial:
            spdom_node = self.root_widget.spatial_tab.spdom.to_xml()
            idinfo_node.append(spdom_node)

        keywords = self.keywords.to_xml()
        idinfo_node.append(keywords)

        if self.schema == 'bdp' and self.taxonomy.has_content():
            taxonomy = self.taxonomy.to_xml()
            idinfo_node.append(taxonomy)

        accconst_node = self.accconst.to_xml()
        idinfo_node.append(accconst_node)

        useconst_node = self.useconst.to_xml()
        idinfo_node.append(useconst_node)

        if self.ptcontac.has_content():
            ptcontac = self.ptcontac.to_xml()
            idinfo_node.append(ptcontac)

        if self.original_xml is not None:
            browse = xml_utils.search_xpath(self.original_xml, 'browse')
            if browse is not None:
                browse.tail = None
                idinfo_node.append(deepcopy(browse))

        datacredit_node = self.datacredit.to_xml()
        if datacredit_node.text:
            idinfo_node.append(datacredit_node)

        if self.original_xml is not None:
            secinfo = xml_utils.search_xpath(self.original_xml, 'secinfo')
            if secinfo is not None:
                secinfo.tail = None
                idinfo_node.append(deepcopy(secinfo))

        if self.native.has_content():
            idinfo_node.append(self.native.to_xml())

        if self.crossref_list.has_content():
            for crossref in self.crossref_list.get_children():
                idinfo_node.append(crossref.to_xml())

        if self.original_xml is not None:
            tools = xml_utils.search_xpath(self.original_xml,
                                           'tool',
                                           only_first=False)
            for tool in tools:
                tool.tail = None
                idinfo_node.append(deepcopy(tool))

        return idinfo_node

    def from_xml(self, xml_idinfo):

        self.original_xml = xml_idinfo

        citation = xml_utils.search_xpath(xml_idinfo, 'citation')
        if citation is not None:
            self.citation.from_xml(citation)

        abstract = xml_utils.search_xpath(xml_idinfo, 'descript/abstract')
        if abstract is not None:
            self.descript.from_xml(abstract)

        purpose = xml_utils.search_xpath(xml_idinfo, 'descript/purpose')
        if purpose is not None:
            self.purpose.from_xml(purpose)

        supplinf = xml_utils.search_xpath(xml_idinfo, 'descript/supplinf')
        if supplinf is not None:
            self.supplinf.from_xml(supplinf)

        timeperd = xml_utils.search_xpath(xml_idinfo, 'timeperd')
        if timeperd is not None:
            self.timeperd.from_xml(timeperd)

        status = xml_utils.search_xpath(xml_idinfo, 'status')
        if status is not None:
            self.status.from_xml(status)

        spdom = xml_utils.search_xpath(xml_idinfo, 'spdom')
        if spdom is not None:
            self.root_widget.spatial_tab.spdom.from_xml(spdom)

        keywords = xml_utils.search_xpath(xml_idinfo, 'keywords')
        if keywords is not None:
            self.keywords.from_xml(keywords)

        taxonomy = xml_utils.search_xpath(xml_idinfo, 'taxonomy')
        if taxonomy is not None:
            self.taxonomy.from_xml(taxonomy)

        accconst = xml_utils.search_xpath(xml_idinfo, 'accconst')
        if accconst is not None:
            self.accconst.from_xml(accconst)

        useconst = xml_utils.search_xpath(xml_idinfo, 'useconst')
        if useconst is not None:
            self.useconst.from_xml(useconst)

        ptcontac = xml_utils.search_xpath(xml_idinfo, 'ptcontac')
        if ptcontac is not None:
            self.ptcontac.from_xml(ptcontac)

        datacred = xml_utils.search_xpath(xml_idinfo, 'datacred')
        if datacred is not None:
            self.datacredit.from_xml(datacred)

        native = xml_utils.search_xpath(xml_idinfo, 'native')
        if native is not None:
            self.native.from_xml(native)

        crossref = xml_utils.search_xpath(xml_idinfo, 'crossref')
        if crossref is not None:
            self.crossref_list.from_xml(xml_idinfo)