コード例 #1
0
ファイル: MetadataRoot.py プロジェクト: ennsk/fort-pymdwizard
    def build_ui(self):
        """
        Build and modify this widget's GUI

        Returns
        -------
        None
        """
        self.ui = self.ui_class()
        self.ui.setupUi(self)
        self.setup_dragdrop(self, enable=True)

        self.idinfo = IdInfo(root_widget=self, parent=self)
        self.ui.page_idinfo.layout().addWidget(self.idinfo)

        self.dataqual = DataQuality()
        self.ui.page_dataqual.layout().addWidget(self.dataqual)

        self.spatial_tab = SpatialTab(root_widget=self)
        self.ui.page_spatial.layout().addWidget(self.spatial_tab)

        self.eainfo = EA()
        self.ui.page_eainfo.layout().addWidget(self.eainfo)

        self.metainfo = MetaInfo(root_widget=self)
        self.ui.page_metainfo.layout().addWidget(self.metainfo)

        self.distinfo = DistInfo(root_widget=self)
        self.ui.page_distinfo.layout().addWidget(self.distinfo)
コード例 #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.metainfo = MetaInfo()

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

        self.ui.widget_distinfo.hide()
コード例 #3
0
class MetadataRoot(WizardWidget):

    drag_label = "Metadata <metadata>"

    ui_class = UI_MetadataRoot.Ui_metadata_root

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

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

        Returns
        -------
        None
        """
        self.ui = self.ui_class()
        self.ui.setupUi(self)
        self.setup_dragdrop(self, enable=True)

        self.idinfo = IdInfo(root_widget=self)
        self.ui.page_idinfo.layout().addWidget(self.idinfo)

        self.dataqual = DataQuality()
        self.ui.page_dataqual.setLayout(self.dataqual.layout())

        self.spatial_tab = SpatialTab(root_widget=self)
        self.ui.page_spatial.setLayout(self.spatial_tab.layout())

        self.eainfo = EA()
        self.ui.page_eainfo.setLayout(self.eainfo.layout())

        self.metainfo = MetaInfo(root_widget=self)
        self.ui.page_metainfo.layout().addWidget(self.metainfo)

        self.distinfo = DistInfo(root_widget=self)
        self.ui.page_distinfo.layout().addWidget(self.distinfo)

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

        Returns
        -------
        None
        """
        self.ui.idinfo_button.pressed.connect(self.section_changed)
        self.ui.dataquality_button.pressed.connect(self.section_changed)
        self.ui.spatial_button.pressed.connect(self.section_changed)
        self.ui.eainfo_button.pressed.connect(self.section_changed)
        self.ui.distinfo_button.pressed.connect(self.section_changed)
        self.ui.metainfo_button.pressed.connect(self.section_changed)

    def section_changed(self):

        button_name = self.sender().objectName()
        old_widget = self.ui.fgdc_metadata.currentWidget()

        index_lookup = {
            'idinfo_button': 0,
            'dataquality_button': 1,
            'spatial_button': 2,
            'eainfo_button': 3,
            'distinfo_button': 4,
            'metainfo_button': 5,
            'validation_button': 6
        }

        new_index = index_lookup[button_name]

        new_widget = self.ui.fgdc_metadata.widget(new_index)

        fader_widget = FaderWidget(old_widget, new_widget)
        self.ui.fgdc_metadata.setCurrentIndex(new_index)

    def switch_schema(self, schema):
        self.schema = schema
        self.idinfo.switch_schema(schema)
        self.spatial_tab.switch_schema(schema)

    def _to_xml(self):
        metadata_node = etree.Element('metadata')
        idinfo = self.idinfo._to_xml()
        metadata_node.append(idinfo)

        dataqual = self.dataqual._to_xml()
        metadata_node.append(dataqual)

        if self.spatial_tab.spdoinfo.has_content():
            spdoinfo = self.spatial_tab.spdoinfo._to_xml()
            metadata_node.append(spdoinfo)

        if self.spatial_tab.spref.has_content():
            spref = self.spatial_tab.spref._to_xml()
            metadata_node.append(spref)

        if self.eainfo.has_content():
            eainfo = self.eainfo._to_xml()
            metadata_node.append(eainfo)

        distinfo = self.distinfo._to_xml()
        metadata_node.append(distinfo)

        metainfo = self.metainfo._to_xml()
        metadata_node.append(metainfo)
        return metadata_node

    def _from_xml(self, metadata_element):
        self.idinfo._from_xml(metadata_element.xpath('idinfo')[0])

        dataqual = metadata_element.xpath('dataqual')
        if dataqual:
            self.dataqual._from_xml(dataqual[0])

        spdom = metadata_element.xpath('idinfo/spdom')
        if spdom:
            self.spatial_tab.spdom._from_xml(spdom[0])

        spdoinfo = metadata_element.xpath('spdoinfo')
        if spdoinfo:
            self.spatial_tab.spdoinfo._from_xml(spdoinfo[0])
        else:
            self.spatial_tab.spdoinfo.ui.rbtn_yes.setChecked(False)
            self.spatial_tab.spdoinfo.ui.rbtn_no.setChecked(True)

        spref = metadata_element.xpath('spref')
        if spref:
            self.spatial_tab.spref._from_xml(spref[0])
        else:
            self.spatial_tab.spref.ui.rbtn_yes.setChecked(False)
            self.spatial_tab.spref.ui.rbtn_no.setChecked(True)

        eainfo = metadata_element.xpath('eainfo')
        if eainfo:
            self.eainfo._from_xml(eainfo[0])
        else:
            self.eainfo.clear_widget()

        distinfo = metadata_element.xpath('distinfo')
        if distinfo:
            self.distinfo._from_xml(distinfo[0])

        self.metainfo._from_xml(metadata_element.xpath('metainfo')[0])
コード例 #4
0
ファイル: MetadataRoot.py プロジェクト: ennsk/fort-pymdwizard
class MetadataRoot(WizardWidget):

    drag_label = "Metadata <metadata>"
    acceptable_tags = ['abstract']

    ui_class = UI_MetadataRoot.Ui_metadata_root

    def __init__(self, parent=None):
        self.schema = 'bdp'
        super(self.__class__, self).__init__(parent=parent)
        self.use_dataqual = True
        self.use_spatial = True
        self.use_eainfo = True
        self.use_distinfo = True

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

        Returns
        -------
        None
        """
        self.ui = self.ui_class()
        self.ui.setupUi(self)
        self.setup_dragdrop(self, enable=True)

        self.idinfo = IdInfo(root_widget=self, parent=self)
        self.ui.page_idinfo.layout().addWidget(self.idinfo)

        self.dataqual = DataQuality()
        self.ui.page_dataqual.layout().addWidget(self.dataqual)

        self.spatial_tab = SpatialTab(root_widget=self)
        self.ui.page_spatial.layout().addWidget(self.spatial_tab)

        self.eainfo = EA()
        self.ui.page_eainfo.layout().addWidget(self.eainfo)

        self.metainfo = MetaInfo(root_widget=self)
        self.ui.page_metainfo.layout().addWidget(self.metainfo)

        self.distinfo = DistInfo(root_widget=self)
        self.ui.page_distinfo.layout().addWidget(self.distinfo)

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

        Returns
        -------
        None
        """
        self.ui.idinfo_button.pressed.connect(self.section_changed)
        self.ui.dataquality_button.pressed.connect(self.section_changed)
        self.ui.spatial_button.pressed.connect(self.section_changed)
        self.ui.eainfo_button.pressed.connect(self.section_changed)
        self.ui.distinfo_button.pressed.connect(self.section_changed)
        self.ui.metainfo_button.pressed.connect(self.section_changed)

    def section_changed(self):
        """
        The event which switches the currently displayed main section
        when a user clicks on one of the top level section header buttons.

        Returns
        -------
        None
        """

        button_name = self.sender().objectName()

        index_lookup = {
            'idinfo_button': 0,
            'dataquality_button': 1,
            'spatial_button': 2,
            'eainfo_button': 3,
            'distinfo_button': 4,
            'metainfo_button': 5
        }

        new_index = index_lookup[button_name]
        self.switch_section(which_index=new_index)

    def switch_section(self, which_index):
        """
        sub funtion that does the actual switching, creating a fader widget,
        etc.

        Parameters
        ----------
        which_index : int
            The index of the section to display

        Returns
        -------
        None
        """
        if which_index == 0:
            self.ui.idinfo_button.setChecked(True)
        elif which_index == 1:
            self.ui.dataquality_button.setChecked(True)
        elif which_index == 2:
            self.ui.spatial_button.setChecked(True)
        elif which_index == 3:
            self.ui.eainfo_button.setChecked(True)
        elif which_index == 4:
            self.ui.distinfo_button.setChecked(True)
        elif which_index == 5:
            self.ui.metainfo_button.setChecked(True)

        old_widget = self.ui.fgdc_metadata.currentWidget()
        new_widget = self.ui.fgdc_metadata.widget(which_index)

        FaderWidget(old_widget, new_widget)
        self.ui.fgdc_metadata.setCurrentIndex(which_index)

        return new_widget

    def switch_schema(self, schema):
        """
        Switch the displayed schema between straight FGDC and BDP

        Parameters
        ----------
        schema : str

        Returns
        -------

        """
        self.schema = schema
        self.idinfo.switch_schema(schema)
        self.spatial_tab.switch_schema(schema)

    def use_section(self, which, value):
        """
        enable or disable top optional top level sections

        Parameters
        ----------
        which : str
                Which section to change: ['dataqual', 'spatial', 'ea',
                                          'distinfo']
        value : bool
                Whether to enable (True) or disable (False)

        Returns
        -------
        None
        """
        if which == 'dataqual':
            self.use_dataqual = value
            self.dataqual.setVisible(value)
        if which == 'spatial':
            self.use_spatial = value
            self.spatial_tab.setVisible(value)
        if which == 'eainfo':
            self.use_eainfo = value
            self.eainfo.setVisible(value)
        if which == 'distinfo':
            self.use_distinfo = value
            self.distinfo.setVisible(value)

    def to_xml(self):
        metadata_node = xml_utils.xml_node(tag='metadata')
        idinfo = self.idinfo.to_xml()
        metadata_node.append(idinfo)

        if self.use_dataqual:
            dataqual = self.dataqual.to_xml()
            metadata_node.append(dataqual)

        if self.spatial_tab.spdoinfo.has_content() and self.use_spatial:
            spdoinfo = self.spatial_tab.spdoinfo.to_xml()
            metadata_node.append(spdoinfo)

        if self.spatial_tab.spref.has_content() and self.use_spatial:
            spref = self.spatial_tab.spref.to_xml()
            metadata_node.append(spref)

        if self.eainfo.has_content() and self.use_eainfo:
            eainfo = self.eainfo.to_xml()
            metadata_node.append(eainfo)

        if self.use_distinfo:
            distinfo = self.distinfo.to_xml()
            metadata_node.append(distinfo)

        metainfo = self.metainfo.to_xml()
        metadata_node.append(metainfo)
        return metadata_node

    def from_xml(self, metadata_element):

        self.populate_section(metadata_element, 'spdoinfo',
                              self.spatial_tab.spdoinfo)

        self.populate_section(metadata_element, 'spref',
                              self.spatial_tab.spref)

        self.populate_section(metadata_element, 'idinfo', self.idinfo)

        self.populate_section(metadata_element, 'dataqual', self.dataqual)

        self.populate_section(metadata_element, 'eainfo', self.eainfo)

        self.populate_section(metadata_element, 'distinfo', self.distinfo)

        self.populate_section(metadata_element, 'metainfo', self.metainfo)

    def populate_section(self, metadata_element, section_name, widget):
        """
        Since the content of top level sections might contain items that
        need to go to separate top level items, this function handles the
        divvying up of sub-content.

        Parameters
        ----------
        metadata_element : XML Element
        section_name : Section tag to populate
        widget :  The section widget

        Returns
        -------

        """
        just_this_one = type(metadata_element) == etree._Element

        if just_this_one and metadata_element.tag == section_name:
            section = metadata_element
        elif just_this_one:
            return True
        else:
            section = xml_utils.search_xpath(metadata_element, section_name)

        if section is not None:
            widget.from_xml(section)
        elif not just_this_one:
            widget.clear_widget()
コード例 #5
0
class MetadataRoot(WizardWidget):

    drag_label = "Metadata <metadata>"
    acceptable_tags = ['abstract']

    ui_class = UI_MetadataRoot.Ui_metadata_root

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

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

        Returns
        -------
        None
        """
        self.ui = self.ui_class()
        self.ui.setupUi(self)
        self.setup_dragdrop(self, enable=True)

        self.idinfo = IdInfo(root_widget=self, parent=self)
        self.ui.page_idinfo.layout().addWidget(self.idinfo)

        self.dataqual = DataQuality()
        self.ui.page_dataqual.layout().addWidget(self.dataqual)
        # self.ui.page_dataqual.setLayout(self.dataqual.layout())

        self.spatial_tab = SpatialTab(root_widget=self)
        self.ui.page_spatial.layout().addWidget(self.spatial_tab)

        self.eainfo = EA()
        self.ui.page_eainfo.layout().addWidget(self.eainfo)

        self.metainfo = MetaInfo(root_widget=self)
        self.ui.page_metainfo.layout().addWidget(self.metainfo)

        self.distinfo = DistInfo(root_widget=self)
        self.ui.page_distinfo.layout().addWidget(self.distinfo)

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

        Returns
        -------
        None
        """
        self.ui.idinfo_button.pressed.connect(self.section_changed)
        self.ui.dataquality_button.pressed.connect(self.section_changed)
        self.ui.spatial_button.pressed.connect(self.section_changed)
        self.ui.eainfo_button.pressed.connect(self.section_changed)
        self.ui.distinfo_button.pressed.connect(self.section_changed)
        self.ui.metainfo_button.pressed.connect(self.section_changed)

    def section_changed(self):

        button_name = self.sender().objectName()

        index_lookup = {
            'idinfo_button': 0,
            'dataquality_button': 1,
            'spatial_button': 2,
            'eainfo_button': 3,
            'distinfo_button': 4,
            'metainfo_button': 5
        }

        new_index = index_lookup[button_name]
        self.switch_section(which_index=new_index)

    def switch_section(self, which_index):
        if which_index == 0:
            self.ui.idinfo_button.setChecked(True)
        elif which_index == 1:
            self.ui.dataquality_button.setChecked(True)
        elif which_index == 2:
            self.ui.spatial_button.setChecked(True)
        elif which_index == 3:
            self.ui.eainfo_button.setChecked(True)
        elif which_index == 4:
            self.ui.distinfo_button.setChecked(True)
        elif which_index == 5:
            self.ui.metainfo_button.setChecked(True)

        old_widget = self.ui.fgdc_metadata.currentWidget()
        new_widget = self.ui.fgdc_metadata.widget(which_index)

        fader_widget = FaderWidget(old_widget, new_widget)
        self.ui.fgdc_metadata.setCurrentIndex(which_index)

    def switch_schema(self, schema):
        self.schema = schema
        self.idinfo.switch_schema(schema)
        self.spatial_tab.switch_schema(schema)

    def _to_xml(self):
        metadata_node = etree.Element('metadata')
        idinfo = self.idinfo._to_xml()
        metadata_node.append(idinfo)

        dataqual = self.dataqual._to_xml()
        metadata_node.append(dataqual)

        if self.spatial_tab.spdoinfo.has_content():
            spdoinfo = self.spatial_tab.spdoinfo._to_xml()
            metadata_node.append(spdoinfo)

        if self.spatial_tab.spref.has_content():
            spref = self.spatial_tab.spref._to_xml()
            metadata_node.append(spref)

        if self.eainfo.has_content():
            eainfo = self.eainfo._to_xml()
            metadata_node.append(eainfo)

        distinfo = self.distinfo._to_xml()
        metadata_node.append(distinfo)

        metainfo = self.metainfo._to_xml()
        metadata_node.append(metainfo)
        return metadata_node

    def _from_xml(self, metadata_element):

        self.populate_section(metadata_element, 'spdoinfo',
                              self.spatial_tab.spdoinfo)
        #
        self.populate_section(metadata_element, 'spref',
                              self.spatial_tab.spref)

        self.populate_section(metadata_element, 'idinfo', self.idinfo)

        self.populate_section(metadata_element, 'dataqual', self.dataqual)

        self.populate_section(metadata_element, 'eainfo', self.eainfo)

        self.populate_section(metadata_element, 'distinfo', self.distinfo)

        self.populate_section(metadata_element, 'metainfo', self.metainfo)

    def populate_section(self, metadata_element, section_name, widget):

        just_this_one = type(metadata_element) == etree._Element

        if just_this_one and metadata_element.tag == section_name:
            section = metadata_element
        elif just_this_one:
            return True
        else:
            section = xml_utils.search_xpath(metadata_element, section_name)

        if section is not None:
            widget._from_xml(section)
        elif not just_this_one:
            widget.clear_widget()