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)
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)
Exemple #3
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)

        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_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)