def _from_xml(self, edom): """ parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if edom.tag == 'edom': utils.populate_widget(self, edom) else: print("The tag is not udom") except KeyError: pass
def from_xml(self, spdom): self.original_xml = spdom self.clear_widget() utils.populate_widget(self, spdom) contents = xml_utils.node_to_dict(spdom, add_fgdc=False) if 'bounding' in contents: contents = contents['bounding'] try: if self.all_good_coords(): self.add_rect() self.update_map() else: self.remove_rect() except KeyError: self.remove_rect()
def _from_xml(self, detailed): """ parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if detailed.tag == 'detailed': utils.populate_widget(self, detailed) self.attributes._from_xml(detailed) else: print ("The tag is not a detailed") except KeyError: pass
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
def _from_xml(self, spdom): self.original_xml = spdom utils.populate_widget(self, spdom) contents = xml_utils.node_to_dict(spdom, add_fgdc=False) if 'bounding' in contents: contents = contents['bounding'] try: jstr = """east = {eastbc}; west = {westbc}; south = {southbc}; north = {northbc}; updateMap(); fitMap(); """.format(**contents) self.frame.evaluateJavaScript(jstr) except KeyError: pass
def from_xml(self, vertdef): """ parses the xml code into the relevant timeinfo elements Parameters ---------- metadata_date - the xml element timeinfo and its contents Returns ------- None """ self.clear_widget() try: if vertdef.tag == "vertdef": self.ui.rbtn_yes.setChecked(True) if vertdef.xpath("altsys"): self.ui.rbtn_yes_alt.setChecked(True) self.altres_list.clear_widgets(add_another=False) for altres in vertdef.xpath("altsys/altres"): altres_widget = self.altres_list.add_another() altres_widget.added_line.setPlainText(altres.text) if len(vertdef.xpath("altsys/altres")) == 0: self.altres_list.add_another() else: self.ui.rbtn_no_alt.setChecked(True) if vertdef.xpath("depthsys"): self.ui.rbtn_yes_depth.setChecked(True) self.depthres_list.clear_widgets(add_another=False) for depthres in vertdef.xpath("depthsys/depthres"): depthres_widget = self.depthres_list.add_another() depthres_widget.added_line.setPlainText(depthres.text) if len(vertdef.xpath("depthsys/depthres")) == 0: self.depthres_list.add_another() else: self.ui.rbtn_no_depth.setChecked(True) utils.populate_widget(self, vertdef) else: print("The tag is not a vertdef") except KeyError: pass
def from_xml(self, attr): """ Populate widget with a representation of the passed XML element Parameters ---------- attr : XML Element Returns ------- None """ try: self.clear_widget() if attr.tag == 'attr': utils.populate_widget(self, attr) attr_dict = xml_utils.node_to_dict(attr) if not 'fgdc_attrdomv' in attr_dict.keys(): self.ui.comboBox.setCurrentIndex(3) elif 'fgdc_udom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(3) self._domain_content[3] = attr.xpath('attrdomv/udom')[0] elif 'fgdc_rdom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(1) self._domain_content[1] = attr.xpath('attrdomv/rdom')[0] elif 'fgdc_edom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(0) self._domain_content[0] = attr elif 'fgdc_codesetd' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(2) self._domain_content[2] = attr.xpath( 'attrdomv/codesetd')[0] else: self.ui.comboBox.setCurrentIndex(3) else: print("The tag is not attr") except KeyError: pass
def _from_xml(self, attr): """ parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if attr.tag == 'attr': utils.populate_widget(self, attr) attr_dict = xml_utils.node_to_dict(attr) if not 'fgdc_attrdomv' in attr_dict.keys(): self.ui.comboBox.setCurrentIndex(3) elif 'fgdc_udom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(3) self.domain._from_xml(attr.xpath('attrdomv/udom')[0]) elif 'fgdc_rdom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(1) self.domain._from_xml(attr.xpath('attrdomv/rdom')[0]) elif 'fgdc_edom' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(0) self.change_domain(0) self.domain._from_xml(attr) elif 'fgdc_codesetd' in attr_dict['fgdc_attrdomv'].keys(): self.ui.comboBox.setCurrentIndex(2) self.domain._from_xml(attr.xpath('attrdomv/codesetd')[0]) else: self.ui.comboBox.setCurrentIndex(3) else: print("The tag is not udom") except KeyError: pass
def add_contact(self): username = self.usgs_contact_ui.le_usgs_ad_name.text() if not username: return try: contact_dict = utils.get_contact_info(username) self.clear_widget() utils.populate_widget(self, contact_dict) addrtype_widget = self.findChild(QComboBox, 'fgdc_addrtype') addrtype = contact_dict['addrtype'] addrtype_widget.setEditText(addrtype) if 'cntorgp' in contact_dict: rbtn_orgp = self.findChild(QRadioButton, 'rbtn_orgp') rbtn_orgp.setChecked(True) elif 'cntperp' in contact_dict: rbtn_perp = self.findChild(QRadioButton, 'rbtn_perp') rbtn_perp.setChecked(True) self.usgs_contact.deleteLater() except KeyError: pass except: msg_text = "Well, that didn't work." msg = QMessageBox(self) utils.set_window_icon(msg) msg.setIcon(QMessageBox.Information) msg.setText( "Issue encountered while searching contact information.") msg.setInformativeText(msg_text) msg.setWindowTitle("Problem encountered") msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def from_xml(self, attr): """ Populate widget with a representation of the passed XML element Parameters ---------- attr : XML Element Returns ------- None """ try: self.clear_widget() if attr.tag == 'attr': utils.populate_widget(self, attr) attr_node = xml_utils.XMLNode(attr) attrdomvs = attr_node.xpath('attrdomv', as_list=True) attr_domains = [a.children[0].tag for a in attrdomvs] # pull out the first no data attribute domain for attrdomv in attrdomvs: if attrdomv.children[0].tag == 'edom' and \ (attrdomv.children[0].children[0].text in self.nodata_matches or \ attrdomv.children[0].children[1].text.lower() in ['nodata', 'no data'] or (attr_domains.count('edom')==1) and len(attr_domains) > 1): self.ui.rbtn_nodata_yes.setChecked(True) self.nodata_content = (1, attrdomv.children[0].to_xml()) attrdomvs.remove(attrdomv) attr_domains.remove('edom') try: edomv = attr.xpath( "attrdomv/edom/edomv[text()='{}']".format( attrdomv.children[0].children[0].text))[0] nd_attrdomv = edomv.getparent().getparent() nd_attrdomv.getparent().remove(nd_attrdomv) except: pass break if len(set(attr_domains)) > 1: # multiple domain types present in this attr msg = "Multiple domain types found in the attribute/column '{}'." msg += "\ni.e. more than one of Enumerated, Range, " msg += "Codeset, and Unrepresentable was used to " msg += "was used to describe a single column.\n\n" msg += "While this is valid in the FGDC schema the " msg += "MetadataWizard is not designed to handle this." msg += "\n\nOnly the first of these domains will be displayed " msg += "and retained in the output saved from this tool." msg += "\n\nIf having this structure is import please use" msg += " a different tool for editing this section." msg = msg.format(self.ui.fgdc_attrlabl.text()) msgbox = QMessageBox(QMessageBox.Warning, "Too many domain types", msg) utils.set_window_icon(msgbox) msgbox.exec_() if len(attrdomvs) == 0: self.ui.comboBox.setCurrentIndex(3) elif attr_domains[0] == 'edom': self.ui.comboBox.setCurrentIndex(0) self._domain_content[0] = attr elif attr_domains[0] == 'udom': self.ui.comboBox.setCurrentIndex(3) self._domain_content[3] = attr.xpath('attrdomv/udom')[0] elif attr_domains[0] == 'rdom': self.ui.comboBox.setCurrentIndex(1) self._domain_content[1] = attr.xpath('attrdomv/rdom')[0] elif attr_domains[0] == 'codesetd': self.ui.comboBox.setCurrentIndex(2) self._domain_content[2] = attr.xpath( 'attrdomv/codesetd')[0] else: self.ui.comboBox.setCurrentIndex(3) else: print("The tag is not attr") except KeyError: pass
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 """ try: if citeinfo.tag == "citation": citeinfo = citeinfo.xpath('citeinfo')[0] elif citeinfo.tag != 'citeinfo': print("The tag is not 'citation' or 'citeinfo'") return self.fgdc_origin.clear_widgets() originators = citeinfo.findall("origin") if originators : self.fgdc_origin.clear_widgets(add_another=False) for origin in citeinfo.findall('origin'): origin_widget = self.fgdc_origin.add_another() origin_widget.added_line.setText(origin.text) else: self.fgdc_origin.add_another() if citeinfo.findall('geoform'): self.ui.fgdc_geoform.setEditText(citeinfo.findall('geoform')[0].text) utils.populate_widget_element(self.ui.pubdate_widget.ui.fgdc_caldate, citeinfo, 'pubdate') utils.populate_widget_element(self.ui.fgdc_title, citeinfo, 'title') self.onlink_list.clear_widgets() if citeinfo.findall("onlink"): for onlink in citeinfo.findall('onlink'): onlink_widget = self.onlink_list.widgets[0] onlink_widget.added_line.setText(onlink.text) if citeinfo.xpath('serinfo'): self.ui.radio_seriesyes.setChecked(True) utils.populate_widget(self, citeinfo.xpath('serinfo')[0]) else: self.ui.radio_seriesyes.setChecked(False) pubinfo = citeinfo.xpath('pubinfo') if pubinfo: self.ui.radio_pubinfoyes.setChecked(True) utils.populate_widget_element(self.ui.fgdc_publish, pubinfo[0], 'publish') utils.populate_widget_element(self.ui.fgdc_pubplace, pubinfo[0], 'pubplace') else: self.ui.radio_pubinfoyes.setChecked(False) self.ui.radioButton_8.setChecked(True) if citeinfo.xpath('lworkcit'): try: self.ui.radio_lworkyes.setChecked(True) self.lworkcit_widget._from_xml(citeinfo.xpath('lworkcit/citeinfo')[0]) except AttributeError: msg = 'you pasted a citation element into the larger work citation area' msg += '\n that contained a larger work citation' msg += '\n Multiple nested larger work citations are not currently supported in the tool' msg += '\n\n the larger work citation being pasted will be ignored' QMessageBox.warning(self, "Dropped Content Warning", msg) else: self.ui.radio_lworkno.setChecked(True) except KeyError: pass
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 """ try: if citeinfo.tag == "citation": citeinfo = citeinfo.xpath('citeinfo')[0] elif citeinfo.tag != 'citeinfo': print("The tag is not 'citation' or 'citeinfo'") return self.fgdc_origin.clear_widgets() if citeinfo.findall("origin"): for origin in citeinfo.findall('origin'): origin_widget = self.fgdc_origin.widgets[0] origin_widget.added_line.setText(origin.text) else: self.fgdc_origin.add_another() if citeinfo.findall('geoform'): self.ui.fgdc_geoform.setEditText( citeinfo.findall('geoform')[0].text) utils.populate_widget_element( self.ui.pubdate_widget.ui.fgdc_caldate, citeinfo, 'pubdate') utils.populate_widget_element(self.ui.fgdc_title, citeinfo, 'title') self.onlink_list.clear_widgets() if citeinfo.findall("onlink"): for onlink in citeinfo.findall('onlink'): onlink_widget = self.onlink_list.widgets[0] onlink_widget.added_line.setText(onlink.text) if citeinfo.xpath('serinfo'): self.ui.radio_seriesyes.setChecked(True) utils.populate_widget(self.ui.fgdc_serinfo, citeinfo.xpath('serinfo')[0]) else: self.ui.radio_seriesyes.setChecked(False) pubinfo = citeinfo.xpath('pubinfo') if pubinfo: self.ui.radio_pubinfoyes.setChecked(True) utils.populate_widget_element(self.ui.fgdc_publish, pubinfo[0], 'publish') utils.populate_widget_element(self.ui.fgdc_pubplace, pubinfo[0], 'pubplace') else: self.ui.radio_pubinfoyes.setChecked(False) if citeinfo.xpath('lworkcit'): self.ui.radio_lworkyes.setChecked(True) self.lworkcit_widget._from_xml( citeinfo.xpath('lworkcit/citeinfo')[0]) except KeyError: pass
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] elif citeinfo.tag != "citeinfo": print("The tag is not 'citation' or 'citeinfo'") return self.fgdc_origin.clear_widgets(add_another=False) originators = citeinfo.findall("origin") if originators: self.fgdc_origin.clear_widgets(add_another=False) for origin in citeinfo.findall("origin"): origin_widget = self.fgdc_origin.add_another() origin_widget.setText(origin.text) else: self.fgdc_origin.add_another() if citeinfo.findall("geoform"): self.ui.fgdc_geoform.setEditText( citeinfo.findall("geoform")[0].text) utils.populate_widget_element( self.ui.pubdate_widget.ui.fgdc_caldate, citeinfo, "pubdate") utils.populate_widget_element(self.ui.fgdc_title, citeinfo, "title") utils.populate_widget_element(self.ui.fgdc_edition, citeinfo, "edition") utils.populate_widget_element(self.ui.fgdc_othercit, citeinfo, "othercit") self.onlink_list.clear_widgets() if citeinfo.findall("onlink"): self.onlink_list.clear_widgets(add_another=False) for onlink in citeinfo.findall("onlink"): self.onlink_list.add_another() onlink_widget = self.onlink_list.widgets[-1] onlink_widget.setText(onlink.text) if citeinfo.xpath("serinfo"): self.ui.radio_seriesyes.setChecked(True) utils.populate_widget(self, citeinfo.xpath("serinfo")[0]) else: self.ui.radio_seriesyes.setChecked(False) pubinfo = citeinfo.xpath("pubinfo") if pubinfo: self.ui.radio_pubinfoyes.setChecked(True) utils.populate_widget_element(self.ui.fgdc_publish, pubinfo[0], "publish") utils.populate_widget_element(self.ui.fgdc_pubplace, pubinfo[0], "pubplace") else: self.ui.radio_pubinfoyes.setChecked(False) self.ui.radio_pubinfono.setChecked(True) if citeinfo.xpath("lworkcit"): try: self.ui.radio_lworkyes.setChecked(True) self.lworkcit_widget.from_xml( citeinfo.xpath("lworkcit/citeinfo")[0]) except AttributeError: msg = "you pasted a citation element into the larger work citation area" msg += "\n that contained a larger work citation" msg += "\n Multiple nested larger work citations are not currently supported in the tool" msg += "\n\n the larger work citation being pasted will be ignored" QMessageBox.warning(self, "Dropped Content Warning", msg) else: self.ui.radio_lworkno.setChecked(True) except KeyError: pass