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) if __name__ == "__main__": utils.launch_widget(IdInfo, "IdInfo testing")
""" 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': self.clear_children() for attr_node in detailed.xpath('attr'): attr_widget = attr.Attr(parent=self) attr_widget._from_xml(attr_node) self.attrs.append(attr_widget) self.main_layout.insertWidget( len(self.main_layout) - 1, attr_widget) self.minimize_children() self.attrs[0].supersize_me() else: print("The tag is not udom") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Attributes, "attr_list testing")
if element is not None and \ element.tag == 'ptcontac' or element.tag == 'cntinfo': e.accept() else: e.ignore() def _to_xml(self): if self.ui.rbtn_yes.isChecked(): pntcontact = etree.Element('ptcontac') cntinfo = self.cntinfo._to_xml() pntcontact.append(cntinfo) else: pntcontact = None return pntcontact def _from_xml(self, contact_information): if contact_information.tag == 'cntinfo': cntinfo_node = contact_information else: cntinfo_node = contact_information.xpath('cntinfo')[0] self.cntinfo._from_xml(cntinfo_node) if __name__ == "__main__": utils.launch_widget(ContactInfoPointOfContact, "ContactInfoPointOfContact testing")
jupyter_exe_name = os.path.join(root_dname, 'Scripts', 'jupyter.exe') if self.ui.kernel.currentText() == 'root': cmds = ['"{}"'.format(jupyter_exe_name), 'notebook'] else: cmds = [ '"{}"'.format(activate_fname), self.ui.kernel.currentText(), '&&', '"{}"'.format(jupyter_exe_name), 'notebook' ] Popen(" ".join(cmds), cwd=jupyter_dname) msg = 'Jupyter launching...\nJupyter will start momentarily in a new tab in your default internet browser.' QMessageBox.information(self, "Launching Jupyter", msg) self.update_function(self.ui.kernel.currentText(), self.ui.dname.currentText()) self.close() def close_form(self): self.parent = None self.deleteLater() self.close() if __name__ == '__main__': utils.launch_widget(JupyterStarter, "JupyterStarter", previous_dnames=[r"c:\temp", r"c:\temp\junk"])
if len(cur_contents) not in (0, 4, 6, 8): msg = "An FGDC date needs to be 4, 6, or 8 numbers long, or be 'Unknown'" if not cur_contents.isdigit(): msg = "An FGDC date can only consist of numbers" if cur_contents == "Unknown": msg = "" if msg: msgbox = QMessageBox() msgbox.setIcon(QMessageBox.Information) msgbox.setText(msg) msgbox.setInformativeText( "YYYY or YYYYMM or YYYYMMDD or 'Unknown'") msgbox.setWindowTitle("Problem with FGDC date format") msgbox.setStandardButtons(QMessageBox.Ok) msgbox.exec_() def get_date(self): return self.date_widget.text() def set_date(self, date_str): self.date_widget.setText(date_str) if __name__ == "__main__": utils.launch_widget(FGDCDate, label="testing", show_format=False, parent_fgdc_name="fgdc_sngdate")
""" parses the xml code into the relevant purpose elements Parameters ---------- access_constraints - the xml element status and its contents Returns ------- None """ try: if purpose.tag == 'purpose': try: purpose_text = purpose.text purpose_box = self.findChild(QPlainTextEdit, "fgdc_purpose") purpose_box.setPlainText(purpose_text) except: pass else: print ("The tag is not purpose") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Purpose, "Purpose testing")
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) if __name__ == "__main__": utils.launch_widget(DistInfo, "DistInfo testing")
""" parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if keywtax.tag == 'keywtax': thesaurus = keywtax.xpath('taxonkt') if thesaurus: self.ui.fgdc_themekt.setText(thesaurus[0].text) keywords = keywtax.xpath('taxonkey') self.keywords.clear_widgets(add_another=False) for kw in keywords: kw_widget = self.keywords.add_another() kw_widget.added_line.setText(kw.text) else: print ("The tag is not keywtax") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Keywordtax, " testing")
text=self.ui.fgdc_edomvd.toPlainText(), parent_node=edom) edomvds = xml_utils.xml_node('edomvds', text=self.ui.fgdc_edomvds.text(), parent_node=edom) return edom 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': self.ui.fgdc_edomvds.setText('') utils.populate_widget(self, edom) else: print("The tag is not udom") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Edom, "edom testing")
parses the xml code into the relevant status elements Parameters ---------- status - the xml element status and its contents Returns ------- None """ #print "Status", status.tag #print "text", status.find('progress').text try: if status.tag == 'status': progress_box = self.findChild(QComboBox, 'fgdc_progress') progress_text = status.find('progress').text #print progress_text progress_box.setCurrentText(progress_text) update_box = self.findChild(QComboBox, 'fgdc_update') update_text = status.find('update').text #print update_text update_box.setCurrentText(update_text) else: print("The tag is not status") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Status, "Status testing")
self.ui = self.ui_class() self.ui.setupUi(self) self.theme_list = ThemeList(parent=self) self.ui.fgdc_keywords.layout().addWidget(self.theme_list) self.place_list = PlaceList(parent=self) self.ui.fgdc_keywords.layout().addWidget(self.place_list) spacerItem = QSpacerItem(24, 10, QSizePolicy.Preferred, QSizePolicy.Expanding) self.ui.fgdc_keywords.layout().addItem(spacerItem) self.setup_dragdrop(self) def _to_xml(self): keywords = self.theme_list._to_xml() place_keywords = self.place_list._to_xml() for child_node in place_keywords.xpath('place'): keywords.append(child_node) return keywords def _from_xml(self, keywords): self.theme_list._from_xml(keywords) self.place_list._from_xml(keywords) if __name__ == "__main__": utils.launch_widget(Keywords, "keywords testing")
------- datacred element tag in xml tree """ datacred = xml_utils.xml_node("datacred", text=self.ui.fgdc_datacred.toPlainText()) return datacred def from_xml(self, data_credit): """ parses the xml code into the relevant datacred elements Parameters ---------- data_credit - the xml element status and its contents Returns ------- None """ try: if data_credit.tag == "datacred": self.ui.fgdc_datacred.setPlainText(data_credit.text) else: print("The tag is not datacred") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Datacred, "Data Credit testing")
contact_dict = xml_utils.node_to_dict(contact_information) utils.populate_widget(self, contact_dict) addrtype_widget = self.findChild(QComboBox, 'fgdc_addrtype') if 'cntinfo' in contact_dict: contact_dict = contact_dict['cntinfo'] if 'fgdc_cntinfo' in contact_dict: contact_dict = contact_dict['fgdc_cntinfo'] try: addrtype = contact_dict['cntaddr']['addrtype'] addrtype_widget.setEditText(addrtype) except KeyError: pass try: if 'fgdc_cntorgp' in contact_dict: rbtn_orgp = self.findChild(QRadioButton, 'rbtn_orgp') rbtn_orgp.setChecked(True) elif 'fgdc_cntperp' in contact_dict: rbtn_perp = self.findChild(QRadioButton, 'rbtn_perp') rbtn_perp.setChecked(True) except KeyError: pass if __name__ == "__main__": utils.launch_widget(ContactInfo)
from pymdwizard.gui.ui_files import UI_error_list class ErrorList(QWidget): def __init__(self, main_form, parent=None): QWidget.__init__(self, parent=parent) self.ui = UI_error_list.Ui_error_list( ) # .Ui_USGSContactInfoWidgetMain() self.ui.setupUi(self) self.main_form = main_form self.errors = [] self.ui.listWidget.itemClicked.connect(self.main_form.goto_error) def add_error(self, error_msg, xpath): action = QListWidgetItem() action.setText(error_msg) action.setHidden(False) action.setData(1, xpath) self.ui.listWidget.addItem(action) self.errors.append((error_msg, xpath)) def clear_errors(self): self.ui.listWidget.clear() if __name__ == "__main__": utils.launch_widget(ErrorList, "ErrorList", url=r"c:/temp/text.html")
does not imply endorsement by the U.S. Geological Survey. Although this information product, for the most part, is in the public domain, it also contains copyrighted material as noted in the text. Permission to reproduce copyrighted items for other than personal use must be secured from the copyright owner. ------------------------------------------------------------------------------ """ from PyQt5.QtWidgets import QWidget from PyQt5.QtCore import QUrl from pymdwizard.core import utils from pymdwizard.gui.ui_files import UI_Preview class Preview(QWidget): def __init__(self, url=None, parent=None): QWidget.__init__(self, parent=parent) self.ui = UI_Preview.Ui_Form() # .Ui_USGSContactInfoWidgetMain() self.ui.setupUi(self) self.url = url if url: self.ui.webView.setUrl(QUrl.fromLocalFile(self.url)) if __name__ == "__main__": utils.launch_widget(Preview, "Preview", url=r"c:/temp/text.html")
attracc.append(deepcopy(qattracc)) return attracc def from_xml(self, attribute_accuracy): """ parses the xml code into the relevant attraccr elements Parameters ---------- attribute_accuracy - the xml element status and its contents Returns ------- None """ try: if attribute_accuracy.tag == "attracc": self.original_xml = attribute_accuracy attraccr_text = attribute_accuracy.findtext("attraccr") accost_box = self.findChild(QPlainTextEdit, "fgdc_attraccr") accost_box.setPlainText(attraccr_text) else: print("The tag is not attracc") except KeyError: pass if __name__ == "__main__": utils.launch_widget(AttributeAccuracy, "Attribute Accuracy testing")
if element is not None and element.tag == 'proccont' or element.tag == 'cntinfo': e.accept() else: e.ignore() def _to_xml(self): if self.ui.rbtn_yes.isChecked(): proccont = etree.Element('proccont') cntinfo = self.cntinfo._to_xml() proccont.append(cntinfo) else: self.ui.rbtn_no.setChecked(True) proccont = None return proccont def _from_xml(self, contact_information): if contact_information.tag == 'cntinfo': self.ui.rbtn_yes.setChecked(True) cntinfo_node = contact_information else: cntinfo_node = contact_information.xpath('cntinfo')[0] self.cntinfo._from_xml(cntinfo_node) if __name__ == "__main__": utils.launch_widget(ProcessContact, "ProcessContact testing")
self.ui.verticalLayout.addWidget(self.abstract) def to_xml(self): """ encapsulates the QPlainTextEdit text in an element tag Returns ------- abstract element tag in xml tree """ return self.abstract.to_xml() def from_xml(self, abstract): """ parses the xml code into the relevant abstract elements Parameters ---------- access_constraints - the xml element status and its contents Returns ------- None """ self.abstract.from_xml(abstract) if __name__ == "__main__": utils.launch_widget(Descript, "Abstract testing")
if link.url().startswith('http'): import webbrowser webbrowser.open(link.url(), new=0, autoraise=True) return else: self.ui.search_term.setText(link.url()) self.search_thesaurus() if parent is None: return parent_item = self.branch_lookup[parent] model = self.ui.treeview_results.model() for irow in range(parent_item.rowCount()): child = parent_item.child(irow) if child.text() == link.url(): self.ui.treeview_results.setCurrentIndex(child.index()) self.show_details(child.index()) def close_form(self): self.parent = None self.deleteLater() self.close() if __name__ == '__main__': utils.launch_widget(ThesaurusSearch, "Thesaurus Search testing")
purpose_text = purpose.text purpose_box = self.findChild(QPlainTextEdit, "fgdc_purpose") purpose_box.setPlainText(purpose.text) supplinf = descriptors[2] supplinf_text = supplinf.text supplinf_box = self.findChild(QPlainTextEdit, "fgdc_supplinf") supplinf_box.setPlainText(supplinf.text) except: abstract = descriptors[0] abstract_text = abstract.text abstract_box = self.findChild(QPlainTextEdit, "fgdc_abstract") abstract_box.setPlainText(abstract.text) purpose = descriptors[1] purpose_text = purpose.text purpose_box = self.findChild(QPlainTextEdit, "fgdc_purpose") purpose_box.setPlainText(purpose.text) else: print("The tag is not descript") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Descriptor, "Descriptor testing")
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 if __name__ == "__main__": utils.launch_widget(Citeinfo, "Citation testing")
self.ui.btn_localp.setChecked(True) utils.populate_widget_element(self.ui.fgdc_localpd, localp, 'localpd') utils.populate_widget_element(self.ui.fgdc_localpgi, localp, 'localpgi') utils.populate_widget_element(self.ui.fgdc_plance, planar, 'planci/plance') utils.populate_widget_element(self.ui.fgdc_plandu, planar, 'planci/plandu') utils.populate_widget_element(self.ui.fgdc_absres, planar, 'planci/coordrep/absres') utils.populate_widget_element(self.ui.fgdc_ordres, planar, 'planci/coordrep/ordres') self.planar_changed() geodetic = xml_utils.search_xpath(spref_node, 'horizsys/geodetic') if geodetic is not None: utils.populate_widget_element(self.ui.fgdc_horizdn, geodetic, 'horizdn') utils.populate_widget_element(self.ui.fgdc_ellips, geodetic, 'ellips') utils.populate_widget_element(self.ui.fgdc_semiaxis, geodetic, 'semiaxis') utils.populate_widget_element(self.ui.fgdc_denflat, geodetic, 'denflat') if __name__ == "__main__": utils.launch_widget(SpRef, "spref testing")
from lxml import etree from PyQt5.QtGui import QPainter, QFont, QPalette, QBrush, QColor, QPixmap from PyQt5.QtWidgets import QMainWindow, QApplication, QDialog, QMessageBox from PyQt5.QtWidgets import QWidget, QLineEdit, QSizePolicy, QComboBox, QTableView from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QPlainTextEdit from PyQt5.QtWidgets import QStyleOptionHeader, QHeaderView, QStyle from PyQt5.QtCore import QAbstractItemModel, QModelIndex, QSize, QRect, QPoint from pymdwizard.core import utils from pymdwizard.core import xml_utils from pymdwizard.gui.ui_files import UI_iso_keyword class IsoKeyword(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent=parent) self.ui = UI_iso_keyword.Ui_Form() self.ui.setupUi(self) if __name__ == "__main__": utils.launch_widget(IsoKeyword, "Abstract testing")
""" 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': self.edoms = [] self.ui.listWidget.clear() for edom in attr.xpath('attrdomv/edom'): edom_dict = xml_utils.node_to_dict(edom, False) self.add_edom(**edom_dict) else: print ("The tag is not udom") except KeyError: pass if __name__ == "__main__": utils.launch_widget(EdomList, "udom testing")
else: last_added = self.widgets.pop() last_added.deleteLater() elif len(self.widgets) == 1: self.clear_widgets() def get_widgets(self): return self.widgets def clear_widgets(self, add_another=True): for widget in self.widgets: widget.deleteLater() self.widgets = [] if add_another: self.add_another() if __name__ == "__main__": widget_kws = {'label': 'hello', 'required': True} utils.launch_widget( RepeatingElement, which='vertical', tab_label='Processing Step', add_text='test add', # widget = sourceinput.SourceInput, widget_kwargs=widget_kws, remove_text='test remove', italic_text='some instruction')
encapsulates the QTabWidget text for Metadata Time in an element tag Returns ------- timeperd element tag in xml tree """ udom = xml_utils.xml_node("udom", self.ui.fgdc_udom.toPlainText()) return udom def from_xml(self, udom): """ parses the xml code into the relevant timeperd elements Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if udom.tag == "udom": utils.populate_widget(self, udom) else: print("The tag is not udom") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Udom, "udom testing")
Parameters ---------- metadata_date - the xml element timeperd and its contents Returns ------- None """ try: if keywtax.tag == self.which: thesaurus = keywtax.xpath("{}kt".format(self.which)) if thesaurus: self.ui.fgdc_themekt.setText(thesaurus[0].text) keywords = keywtax.xpath("{}key".format(self.which)) for kw in keywords: if self.keywords.get_widgets()[0].added_line.text() == '': kw_widget = self.get_widgets()[0] else: kw_widget = self.keywords.add_another() kw_widget.added_line.setText(kw.text) else: print("The tag is not theme") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Theme, " testing", which='place')
if taxongen is not None: taxongen.tail = None taxonomy.append(deepcopy(taxongen)) taxonomy.append(self.taxoncl.to_xml()) return taxonomy def from_xml(self, taxonomy_element): self.original_xml = taxonomy_element self.clear_widget() self.ui.rbtn_yes.setChecked(True) keywtax = taxonomy_element.xpath('keywtax') if keywtax: self.keywtax.from_xml(taxonomy_element.xpath('keywtax')[0]) taxoncl = taxonomy_element.xpath('taxoncl') if taxoncl: self.taxoncl.from_xml(taxoncl[0]) if __name__ == "__main__": utils.launch_widget(Taxonomy, "Taxonomy testing")
parent_node=enttyp) attr = self.attributes.to_xml() for a in attr.xpath("attr"): detailed.append(a) return detailed 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": self.original_xml = detailed utils.populate_widget(self, detailed) self.attributes.from_xml(detailed) else: print("The tag is not a detailed") except KeyError: pass if __name__ == "__main__": utils.launch_widget(Detailed, "detailed testing")
self.keywords = RepeatingElement(add_text='Add keyword', remove_text='Remove last', widget_kwargs=widget_kwargs, ) self.keywords.ui.italic_label.setStyleSheet('') self.keywords.add_another() self.ui.keywords_layout.insertWidget(0, self.keywords) def lock(self): self.ui.fgdc_themekt.setReadOnly(True) self.keywords.ui.addAnother.setEnabled(False) def get_keywords(self): return [kw.added_line.text() for kw in self.keywords.get_widgets()] def add_another(self, locked=False): widget = self.keywords.add_another() widget.added_line.setReadOnly(locked) return widget def get_widgets(self): return self.keywords.get_widgets() if __name__ == "__main__": utils.launch_widget(KeywordsRepeater, " testing")