예제 #1
0
    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metainfo = MetaInfo()

        self.ui.fgdc_distrib.layout().addWidget(self.contactinfo)

        self.ui.widget_distinfo.hide()
예제 #2
0
    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metd = FGDCDate(parent=self, fgdc_name='fgdc_metd')

        self.ui.help_metd.layout().addWidget(self.metd)

        self.ui.fgdc_metc.layout().addWidget(self.contactinfo)
예제 #3
0
    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.fgdc_metd = SingleDate(parent=self)

        self.ui.group_metd.layout().addWidget(self.fgdc_metd)

        self.ui.fgdc_metc.layout().addWidget(self.contactinfo)
예제 #4
0
class DistInfo(WizardWidget):

    drag_label = "Distribution Information <distinfo>"
    acceptable_tags = ["distinfo"]

    ui_class = UI_distinfo.Ui_fgdc_distinfo

    def __init__(self, root_widget=None):
        super(self.__class__, self).__init__()
        self.root_widget = root_widget
        self.scroll_area = self.ui.scrollArea

    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metainfo = MetaInfo()

        self.ui.fgdc_distrib.layout().addWidget(self.contactinfo)

        self.ui.widget_distinfo.hide()

    def connect_events(self):
        self.ui.radio_distyes.toggled.connect(self.include_dist_contacts)
        self.ui.radio_online.toggled.connect(self.online_toggle)
        self.ui.radio_otherdist.toggled.connect(self.other_dist_toggle)
        self.ui.radio_dist.toggled.connect(self.dist_toggle)
        self.ui.button_use_sb.clicked.connect(self.pull_datasetcontact)

    def online_toggle(self, b):
        if b:
            self.ui.fgdc_networkr.setEnabled(True)
            self.ui.fgdc_distliab.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(True)
        else:
            self.ui.fgdc_networkr.setEnabled(False)

    def other_dist_toggle(self, b):
        if b:
            self.ui.fgdc_custom.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(False)
            self.ui.fgdc_distliab.setEnabled(True)
        else:
            self.ui.fgdc_custom.setEnabled(False)

    def dist_toggle(self, b):
        if b:
            self.ui.fgdc_distliab.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(False)
        else:
            self.ui.fgdc_distliab.setEnabled(False)

    def include_dist_contacts(self, b):
        if b:
            self.ui.widget_distinfo.show()
        else:
            self.ui.widget_distinfo.hide()

    def pull_datasetcontact(self):
        try:
            sb_info = utils.get_usgs_contact_info("sciencebase",
                                                  as_dictionary=False)
            self.contactinfo.from_xml(sb_info)
        except:
            msg = "Having trouble getting sciencebase contact info now.\n"
            msg += "Check internet connection or try again latter."
            QMessageBox.warning(self, "Problem encountered", msg)

    def has_content(self):
        return self.ui.radio_distyes.isChecked()

    def to_xml(self):
        distinfo_node = xml_utils.xml_node("distinfo")

        dist = xml_utils.xml_node("distrib", parent_node=distinfo_node)
        cntinfo = self.contactinfo.to_xml()
        dist.append(cntinfo)

        if self.original_xml is not None:
            resdesc = xml_utils.search_xpath(self.original_xml, "resdesc")
            if resdesc is not None:
                resdesc.tail = None
                distinfo_node.append(deepcopy(resdesc))

        if self.ui.radio_online.isChecked():
            liab = xml_utils.xml_node(
                "distliab",
                text=self.ui.fgdc_distliab.toPlainText(),
                parent_node=distinfo_node,
            )
            stdorder = xml_utils.xml_node("stdorder",
                                          parent_node=distinfo_node)
            digform = xml_utils.xml_node("digform", parent_node=stdorder)

            if self.original_xml is not None and self.original_xml.xpath(
                    "stdorder/digform/digtinfo/formname"):
                digtinfo = self.original_xml.xpath("stdorder/digform/digtinfo")
                digform.append(deepcopy(digtinfo[0]))
            else:
                digtinfo = xml_utils.xml_node("digtinfo", parent_node=digform)
                formname = xml_utils.xml_node("formname",
                                              parent_node=digtinfo,
                                              text="Digital Data")

            digtopt = xml_utils.xml_node("digtopt", parent_node=digform)
            onlinopt = xml_utils.xml_node("onlinopt", parent_node=digtopt)
            computer = xml_utils.xml_node("computer", parent_node=onlinopt)
            networka = xml_utils.xml_node("networka", parent_node=computer)
            networkr = xml_utils.xml_node("networkr",
                                          text=self.ui.fgdc_networkr.text(),
                                          parent_node=networka)
            fees = xml_utils.xml_node("fees",
                                      text=self.ui.fgdc_fees.toPlainText(),
                                      parent_node=stdorder)

        if self.ui.radio_otherdist.isChecked():
            liab = xml_utils.xml_node(
                "distliab",
                text=self.ui.fgdc_distliab.toPlainText(),
                parent_node=distinfo_node,
            )
            other = xml_utils.xml_node(
                "custom",
                text=self.ui.fgdc_custom.toPlainText(),
                parent_node=distinfo_node,
            )

        if self.ui.radio_dist.isChecked():
            liab = xml_utils.xml_node(
                "distliab",
                text=self.ui.fgdc_distliab.toPlainText(),
                parent_node=distinfo_node,
            )

        if self.original_xml is not None:
            techpreq = xml_utils.search_xpath(self.original_xml, "techpreq")
            if techpreq is not None:
                techpreq.tail = None
                distinfo_node.append(deepcopy(techpreq))

        return distinfo_node

    def from_xml(self, xml_distinfo):

        self.original_xml = xml_distinfo
        self.clear_widget()

        if xml_distinfo.tag == "distinfo":
            self.original_xml = xml_distinfo
            self.ui.radio_distyes.setChecked(True)
            if xml_distinfo.xpath("distrib/cntinfo"):
                self.contactinfo.from_xml(
                    xml_distinfo.xpath("distrib/cntinfo")[0])
            if xml_distinfo.xpath("distliab"):
                self.ui.radio_dist.setChecked(True)
                utils.populate_widget_element(widget=self.ui.fgdc_distliab,
                                              element=xml_distinfo,
                                              xpath="distliab")
                self.ui.fgdc_distliab.sizeChange()
            if xml_distinfo.xpath("custom"):
                self.ui.radio_otherdist.setChecked(True)
                utils.populate_widget_element(widget=self.ui.fgdc_custom,
                                              element=xml_distinfo,
                                              xpath="custom")
            if xml_distinfo.xpath("stdorder"):
                self.ui.radio_online.setChecked(True)
                utils.populate_widget_element(
                    widget=self.ui.fgdc_networkr,
                    element=xml_distinfo,
                    xpath=
                    "stdorder/digform/digtopt/onlinopt/computer/networka/networkr",
                )
                utils.populate_widget_element(
                    widget=self.ui.fgdc_fees,
                    element=xml_distinfo,
                    xpath="stdorder/fees",
                )
예제 #5
0
class DistInfo(WizardWidget):

    drag_label = "Distribution Information <distinfo>"

    ui_class = UI_distinfo.Ui_fgdc_distinfo

    def __init__(self, root_widget=None):
        super(self.__class__, self).__init__()
        self.root_widget = root_widget

    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metainfo = MetaInfo()

        self.ui.fgdc_distrib.layout().addWidget(self.contactinfo)

        self.ui.widget_distinfo.hide()

    def connect_events(self):
        self.ui.radio_distyes.toggled.connect(self.include_dist_contacts)
        self.ui.radio_online.toggled.connect(self.online_toggle)
        self.ui.radio_otherdist.toggled.connect(self.other_dist_toggle)
        self.ui.radio_dist.toggled.connect(self.dist_toggle)
        self.ui.button_use_dataset.clicked.connect(self.pull_datasetcontact)
        self.ui.button_use_metadata.clicked.connect(self.pull_metadatacontact)

    def online_toggle(self, b):
        if b:
            self.ui.fgdc_networkr.setEnabled(True)
            self.ui.fgdc_distliab.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(True)
        else:
            self.ui.fgdc_networkr.setEnabled(False)

    def other_dist_toggle(self, b):
        if b:
            self.ui.fgdc_custom.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(False)
            self.ui.fgdc_distliab.setEnabled(True)
        else:
            self.ui.fgdc_custom.setEnabled(False)

    def dist_toggle(self, b):
        if b:
            self.ui.fgdc_distliab.setEnabled(True)
            self.ui.fgdc_fees.setEnabled(False)
        else:
            self.ui.fgdc_distliab.setEnabled(False)

    def include_dist_contacts(self, b):
        if b:
            self.ui.widget_distinfo.show()
        else:
            self.ui.widget_distinfo.hide()

    def pull_datasetcontact(self):
        self.contactinfo._from_xml(self.root_widget.idinfo.ptcontac._to_xml())

    def pull_metadatacontact(self):
        self.contactinfo._from_xml(
            self.root_widget.metainfo.contactinfo._to_xml())

    def dragEnterEvent(self, e):
        """

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

        Returns
        -------

        """
        print("distinfo 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.tag == 'distinfo':
                e.accept()
        else:
            e.ignore()

    def _to_xml(self):
        distinfo_node = xml_utils.xml_node('distinfo')

        dist = xml_utils.xml_node('distrib', parent_node=distinfo_node)
        cntinfo = self.contactinfo._to_xml()
        dist.append(cntinfo)

        if self.ui.radio_online.isChecked():
            liab = xml_utils.xml_node('distliab',
                                      text=self.ui.fgdc_distliab.toPlainText(),
                                      parent_node=distinfo_node)
            stdorder = xml_utils.xml_node('stdorder',
                                          parent_node=distinfo_node)
            digform = xml_utils.xml_node('digform', parent_node=stdorder)
            digtinfo = xml_utils.xml_node('digtinfo', parent_node=digform)
            formname = xml_utils.xml_node('formname',
                                          parent_node=digtinfo,
                                          text='Digital Data')
            digtopt = xml_utils.xml_node('digtopt', parent_node=digform)
            onlinopt = xml_utils.xml_node('onlinopt', parent_node=digtopt)
            computer = xml_utils.xml_node('computer', parent_node=onlinopt)
            networka = xml_utils.xml_node('networka', parent_node=computer)
            networkr = xml_utils.xml_node('networkr',
                                          text=self.ui.fgdc_networkr.text(),
                                          parent_node=networka)
            fees = xml_utils.xml_node('fees',
                                      text=self.ui.fgdc_fees.toPlainText(),
                                      parent_node=stdorder)

        if self.ui.radio_otherdist.isChecked():
            liab = xml_utils.xml_node('distliab',
                                      text=self.ui.fgdc_distliab.toPlainText(),
                                      parent_node=distinfo_node)
            other = xml_utils.xml_node('custom',
                                       text=self.ui.fgdc_custom.toPlainText(),
                                       parent_node=distinfo_node)

        if self.ui.radio_dist.isChecked():
            liab = xml_utils.xml_node('distliab',
                                      text=self.ui.fgdc_distliab.toPlainText(),
                                      parent_node=distinfo_node)
            # other = xml_utils.xml_node('custom', text=self.ui.fgdc_custom.toPlainText(),
            #                            parent_node=distinfo_node)

        return distinfo_node

    def _from_xml(self, xml_distinfo):

        if xml_distinfo.tag == 'distinfo':
            self.ui.radio_distyes.setChecked(True)
            if xml_distinfo.xpath('distrib/cntinfo'):
                self.contactinfo._from_xml(
                    xml_distinfo.xpath('distrib/cntinfo')[0])

            if xml_distinfo.xpath('distliab'):
                self.ui.radio_dist.setChecked(True)
                self.ui.fgdc_distliab.setPlainText(
                    xml_distinfo.xpath('distliab')[0].text)
            if xml_distinfo.xpath('custom'):
                self.ui.radio_otherdist.setChecked(True)
                self.ui.fgdc_custom.setPlainText(
                    xml_distinfo.xpath('custom')[0].text)
            if xml_distinfo.xpath('stdorder'):
                self.ui.radio_online.setChecked(True)
                self.ui.fgdc_networkr.setText(
                    xml_distinfo.xpath(
                        'stdorder/digform/digtopt/'
                        'onlinopt/computer/networka/networkr')[0].text)
                self.ui.fgdc_fees.setPlainText(
                    xml_distinfo.xpath('stdorder/fees')[0].text)
예제 #6
0
class MetaInfo(WizardWidget):

    drag_label = "Metadata Information <metainfo>"
    acceptable_tags = ['metainfo', 'cntinfo', 'ptcontact']

    ui_class = UI_metainfo.Ui_fgdc_metainfo

    def __init__(self, root_widget=None):
        super(self.__class__, self).__init__()
        self.root_widget = root_widget

    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metd = FGDCDate(parent=self, fgdc_name='fgdc_metd')

        self.ui.help_metd.layout().addWidget(self.metd)

        self.ui.fgdc_metc.layout().addWidget(self.contactinfo)

    def connect_events(self):
        self.ui.fgdc_metstdn.currentTextChanged.connect(self.update_metstdv)
        self.ui.fgdc_metstdv.currentIndexChanged.connect(self.update_metstdn)
        self.ui.button_use_dataset.clicked.connect(self.pull_datasetcontact)

    def update_metstdn(self):
        if self.ui.fgdc_metstdv.currentText() == 'FGDC-STD-001-1998':
            self.ui.fgdc_metstdn.setCurrentIndex(0)
            self.root_widget.switch_schema('fgdc')
        elif self.ui.fgdc_metstdv.currentText() == 'FGDC-STD-001.1-1999':
            self.ui.fgdc_metstdn.setCurrentIndex(1)
            self.root_widget.switch_schema('bdp')

    def update_metstdv(self):
        if 'biological' in self.ui.fgdc_metstdn.currentText().lower() or \
           'bdp' in self.ui.fgdc_metstdn.currentText().lower():
            self.ui.fgdc_metstdv.setCurrentIndex(1)
            self.root_widget.switch_schema('bdp')
        else:
            self.ui.fgdc_metstdv.setCurrentIndex(0)
            self.root_widget.switch_schema('fgdc')

    def pull_datasetcontact(self):
        self.contactinfo.from_xml(self.root_widget.idinfo.ptcontac.to_xml())

    def to_xml(self):
        # add code here to translate the form into xml representation
        metainfo_node = xml_utils.xml_node('metainfo')
        metd = xml_utils.xml_node('metd', text=self.metd.get_date(),
                                  parent_node=metainfo_node)

        if self.original_xml is not None:
            metrd = xml_utils.search_xpath(self.original_xml, 'metrd')
            if metrd is not None:
                metrd.tail = None
                metainfo_node.append(deepcopy(metrd))
        if self.original_xml is not None:
            metfrd = xml_utils.search_xpath(self.original_xml, 'metfrd')
            if metfrd is not None:
                metfrd.tail = None
                metainfo_node.append(deepcopy(metfrd))

        metc = xml_utils.xml_node('metc', parent_node=metainfo_node)
        cntinfo = self.contactinfo.to_xml()
        metc.append(cntinfo)

        metstdn = xml_utils.xml_node('metstdn',
                                     text=self.ui.fgdc_metstdn.currentText(),
                                     parent_node=metainfo_node)
        metstdv = xml_utils.xml_node('metstdv',
                                     text=self.ui.fgdc_metstdv.currentText(),
                                     parent_node=metainfo_node)

        if self.original_xml is not None:
            mettc = xml_utils.search_xpath(self.original_xml, 'mettc')
            if mettc is not None:
                mettc.tail = None
                metainfo_node.append(deepcopy(mettc))
        if self.original_xml is not None:
            metac = xml_utils.search_xpath(self.original_xml, 'metac')
            if metac is not None:
                metac.tail = None
                metainfo_node.append(deepcopy(metac))


        if self.original_xml is not None:
            metuc = xml_utils.search_xpath(self.original_xml, 'metuc')
            if metuc is not None:
                metuc_str = xml_utils.get_text_content(self.original_xml, 'metuc')
                metuc = xml_utils.xml_node('metuc',
                                           text=metuc_str,
                                           parent_node=metainfo_node)

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

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

        return metainfo_node

    def from_xml(self, xml_metainfo):

        if xml_metainfo.tag == 'metainfo':
            self.original_xml = xml_metainfo

            if xml_metainfo.xpath('metc/cntinfo'):
                self.contactinfo.from_xml(xml_metainfo.xpath('metc/cntinfo')[0])

            if xml_metainfo.xpath('metstdn'):
                standard = xml_utils.get_text_content(xml_metainfo, 'metstdn')
                self.ui.fgdc_metstdn.setCurrentText(standard)
                # switch wizard content to reflect the standard in this record
                if "biological" in standard.lower() \
                        or 'bdp' in standard.lower():
                    self.root_widget.switch_schema('bdp')
                else:
                    self.root_widget.switch_schema('fgdc')

            metstdv = xml_utils.get_text_content(xml_metainfo, 'metstdv')
            self.ui.fgdc_metstdv.setCurrentText(metstdv)

            metd = xml_utils.get_text_content(xml_metainfo, 'metd')
            self.metd.set_date(metd)
        elif xml_metainfo.tag in ['ptcontac', 'cntinfo']:
            if xml_metainfo.tag == 'ptcontac':
                xml_metainfo = xml_utils.search_xpath(xml_metainfo, 'cntinfo')
            self.contactinfo.from_xml(xml_metainfo)
예제 #7
0
class MetaInfo(WizardWidget):

    drag_label = "Metadata Information <metainfo>"
    acceptable_tags = ["metainfo", "cntinfo", "ptcontact"]

    ui_class = UI_metainfo.Ui_fgdc_metainfo

    def __init__(self, root_widget=None):
        super().__init__()
        self.root_widget = root_widget

    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.metd = FGDCDate(parent=self, fgdc_name="fgdc_metd")

        self.ui.help_metd.layout().addWidget(self.metd)

        self.ui.fgdc_metc.layout().addWidget(self.contactinfo)

    def connect_events(self):
        self.ui.fgdc_metstdn.currentTextChanged.connect(self.update_metstdv)
        self.ui.fgdc_metstdv.currentIndexChanged.connect(self.update_metstdn)
        self.ui.button_use_dataset.clicked.connect(self.pull_datasetcontact)
        self.ui.button_today.clicked.connect(self.todays_date)

    def update_metstdn(self):
        if self.ui.fgdc_metstdv.currentText() == "FGDC-STD-001-1998":
            self.ui.fgdc_metstdn.setCurrentIndex(0)
            self.root_widget.switch_schema("fgdc")
        elif self.ui.fgdc_metstdv.currentText() == "FGDC-STD-001.1-1999":
            self.ui.fgdc_metstdn.setCurrentIndex(1)
            self.root_widget.switch_schema("bdp")

    def update_metstdv(self):
        if ("biological" in self.ui.fgdc_metstdn.currentText().lower()
                or "bdp" in self.ui.fgdc_metstdn.currentText().lower()):
            self.ui.fgdc_metstdv.setCurrentIndex(1)
            self.root_widget.switch_schema("bdp")
        else:
            self.ui.fgdc_metstdv.setCurrentIndex(0)
            self.root_widget.switch_schema("fgdc")

    def pull_datasetcontact(self):
        self.contactinfo.from_xml(self.root_widget.idinfo.ptcontac.to_xml())

    def todays_date(self):
        newdate = datetime.date.today()
        metd = newdate.strftime("%Y%m%d")
        self.metd.set_date(metd)

    def to_xml(self):
        # add code here to translate the form into xml representation
        metainfo_node = xml_utils.xml_node("metainfo")
        metc = xml_utils.xml_node('metc', parent_node=metainfo_node)

        if self.metd.has_content():
            metd = self.metd.to_xml()
            metainfo_node.append(metd)

        if self.contactinfo.has_content():
            cntinfo = self.contactinfo.to_xml()
            metc.append(cntinfo)
            metainfo_node.append(metc)

        if self.original_xml is not None:
            metstdn = xml_utils.search_xpath(self.original_xml, "metstdn")
            metstdv = xml_utils.search_xpath(self.original_xml, "metstdv")

            if metstdn is not None:
                metstdn.tail = None
                metainfo_node.append(deepcopy(metstdn))
                metstdv.tail = None
                metainfo_node.append(deepcopy(metstdv))
            else:
                metstdn = xml_utils.xml_node(
                    'metstdn',
                    text=self.ui.fgdc_metstdn.currentText(),
                    parent_node=metainfo_node)
                metstdv = xml_utils.xml_node(
                    'metstdv',
                    text=self.ui.fgdc_metstdv.currentText(),
                    parent_node=metainfo_node)

        # if self.original_xml is not None:
        #     metd = xml_utils.xml_node("metd", parent_node=metainfo_node,
        #                               text=self.metd.get_date())
        #     if metd is not None:
        #         metainfo_node.append(deepcopy(metd))

        #     metrd = xml_utils.search_xpath(self.original_xml, "metrd")
        #     if metrd is not None:
        #         metrd.tail = None
        #         metainfo_node.append(deepcopy(metrd))

        #     metfrd = xml_utils.search_xpath(self.original_xml, "metfrd")
        #     if metfrd is not None:
        #         metfrd.tail = None
        #         metainfo_node.append(deepcopy(metfrd))

        #     mettc = xml_utils.search_xpath(self.original_xml, "mettc")
        #     if mettc is not None:
        #         mettc.tail = None
        #         metainfo_node.append(deepcopy(mettc))

        #     metac = xml_utils.search_xpath(self.original_xml, "metac")
        #     if metac is not None:
        #         metac.tail = None
        #         metainfo_node.append(deepcopy(metac))

        #     metuc = xml_utils.search_xpath(self.original_xml, "metuc")
        #     if metuc is not None:
        #         metuc_str = xml_utils.get_text_content(self.original_xml, "metuc")
        #         metuc = xml_utils.xml_node(
        #             "metuc", text=metuc_str, parent_node=metainfo_node
        #         )

        #     metsi = xml_utils.search_xpath(self.original_xml, "metsi")
        #     if metsi is not None:
        #         metsi.tail = None
        #         metainfo_node.append(deepcopy(metsi))

        #     metextns = xml_utils.search_xpath(self.original_xml, "metextns")
        #     if metextns is not None:
        #         metextns.tail = None
        #         metainfo_node.append(deepcopy(metextns))

        # else:
        #     metc = xml_utils.xml_node('metc', parent_node=metainfo_node)
        #     cntinfo = self.contactinfo.to_xml()
        #     metc.append(cntinfo)

        #     metstdn = xml_utils.xml_node('metstdn',
        #                               text=self.ui.fgdc_metstdn.currentText(),
        #                               parent_node=metainfo_node)
        #     metstdv = xml_utils.xml_node('metstdv',
        #                               text=self.ui.fgdc_metstdv.currentText(),
        #                               parent_node=metainfo_node)

        return metainfo_node

    def from_xml(self, xml_metainfo):

        if xml_metainfo.tag == "metainfo":
            self.original_xml = xml_metainfo

            if xml_metainfo.xpath("metc/cntinfo"):
                self.contactinfo.from_xml(
                    xml_metainfo.xpath("metc/cntinfo")[0])

            if xml_metainfo.xpath("metstdn"):
                standard = xml_utils.get_text_content(xml_metainfo, "metstdn")
                self.ui.fgdc_metstdn.setCurrentText(standard)
                # switch wizard content to reflect the standard in this record
                if "biological" in standard.lower() or "bdp" in standard.lower(
                ):
                    self.root_widget.switch_schema("bdp")
                else:
                    self.root_widget.switch_schema("fgdc")

            metstdv = xml_utils.get_text_content(xml_metainfo, "metstdv")
            self.ui.fgdc_metstdv.setCurrentText(metstdv)

            metd = xml_utils.get_text_content(xml_metainfo, "metd")
            self.metd.set_date(metd)
        elif xml_metainfo.tag in ["ptcontac", "cntinfo"]:
            if xml_metainfo.tag == "ptcontac":
                xml_metainfo = xml_utils.search_xpath(xml_metainfo, "cntinfo")
            self.contactinfo.from_xml(xml_metainfo)
예제 #8
0
class MetaInfo(WizardWidget):

    drag_label = "Metadata Information <metainfo>"

    ui_class = UI_metainfo.Ui_fgdc_metainfo

    def __init__(self, root_widget=None):
        super(self.__class__, self).__init__()
        self.root_widget = root_widget

    def build_ui(self):

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

        self.setup_dragdrop(self)

        self.contactinfo = ContactInfo(parent=self)
        self.fgdc_metd = SingleDate(parent=self)

        self.ui.group_metd.layout().addWidget(self.fgdc_metd)

        self.ui.fgdc_metc.layout().addWidget(self.contactinfo)

    def connect_events(self):
        self.ui.fgdc_metstdn.currentIndexChanged.connect(self.update_metstdv)
        self.ui.fgdc_metstdv.currentIndexChanged.connect(self.update_metstdn)
        self.ui.button_use_dataset.clicked.connect(self.pull_datasetcontact)

    def update_metstdn(self):
        if self.ui.fgdc_metstdv.currentText() == 'FGDC-STD-001-1998':
            self.ui.fgdc_metstdn.setCurrentIndex(0)
            self.root_widget.switch_schema('fgdc')
        elif self.ui.fgdc_metstdv.currentText() == 'FGDC-STD-001.1-1999':
            self.ui.fgdc_metstdn.setCurrentIndex(1)
            self.root_widget.switch_schema('bdp')

    def update_metstdv(self):
        if self.ui.fgdc_metstdn.currentText() == 'FGDC CSDGM':
            self.ui.fgdc_metstdv.setCurrentIndex(0)
            self.root_widget.switch_schema('fgdc')
        elif self.ui.fgdc_metstdn.currentText(
        ) == 'FGDC Biological Data Profile of the CDGSM':
            self.ui.fgdc_metstdv.setCurrentIndex(1)
            self.root_widget.switch_schema('bdp')

    def pull_datasetcontact(self):
        self.contactinfo._from_xml(self.root_widget.idinfo.ptcontac._to_xml())

    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.tag == 'metainfo':
                e.accept()
        else:
            e.ignore()

    def _to_xml(self):
        # add code here to translate the form into xml representation
        metainfo_node = xml_utils.xml_node('metainfo')
        metd = xml_utils.xml_node('metd',
                                  text=self.fgdc_metd.get_date(),
                                  parent_node=metainfo_node)

        metc = xml_utils.xml_node('metc', parent_node=metainfo_node)
        cntinfo = self.contactinfo._to_xml()
        metc.append(cntinfo)

        metstdn = xml_utils.xml_node('metstdn',
                                     text=self.ui.fgdc_metstdn.currentText(),
                                     parent_node=metainfo_node)
        metstdv = xml_utils.xml_node('metstdv',
                                     text=self.ui.fgdc_metstdv.currentText(),
                                     parent_node=metainfo_node)

        return metainfo_node

    def _from_xml(self, xml_metainfo):

        if xml_metainfo.tag == 'metainfo':
            if xml_metainfo.xpath('metc/cntinfo'):
                self.contactinfo._from_xml(
                    xml_metainfo.xpath('metc/cntinfo')[0])

            if xml_metainfo.xpath('metstdn'):
                standard = xml_metainfo.xpath('metstdn')[0].text
                self.ui.fgdc_metstdn.setCurrentText(standard)
                # switch wizard content to reflect the standard in this record
                if "biological" in standard.lower() \
                        or 'bdp' in standard.lower():
                    self.root_widget.switch_schema('bdp')
                else:
                    self.root_widget.switch_schema('fgdc')

            if xml_metainfo.xpath('metstdv'):
                self.ui.fgdc_metstdv.setCurrentText(
                    xml_metainfo.xpath('metstdv')[0].text)

            if xml_metainfo.xpath('metd'):
                self.fgdc_metd.set_date(xml_metainfo.xpath('metd')[0].text)