def build_ui(self): """ Build and modify this widget's GUI Returns ------- None """ self.ui = UI_taxonomy.Ui_Taxonomy() self.ui.setupUi(self) self.setup_dragdrop(self) self.keywtax = Keywordtax() self.ui.kws_layout.addWidget(self.keywtax) self.taxoncl = Taxoncl() self.ui.taxoncl_contents.layout().addWidget(self.taxoncl) self.include_taxonomy_change(False)
class Taxonomy(WizardWidget): drag_label = "Taxonomy" acceptable_tags = ['taxonomy'] def build_ui(self): """ Build and modify this widget's GUI Returns ------- None """ self.ui = UI_taxonomy.Ui_Taxonomy() self.ui.setupUi(self) self.setup_dragdrop(self) self.keywtax = Keywordtax() self.ui.kws_layout.addWidget(self.keywtax) self.taxoncl = Taxoncl() self.ui.taxoncl_contents.layout().addWidget(self.taxoncl) self.include_taxonomy_change(False) def connect_events(self): """ Connect the appropriate GUI components with the corresponding functions Returns ------- None """ self.ui.btn_search.clicked.connect(self.search_itis) self.ui.rbtn_yes.toggled.connect(self.include_taxonomy_change) def include_taxonomy_change(self, b): if b: self.ui.widget_contents.show() else: self.ui.widget_contents.hide() def search_itis(self): self.tax_gui = taxonomy_gui.ItisMainForm(xml=self.to_xml(), fgdc_function=self.from_xml) fg = self.frameGeometry() self.tax_gui.move(fg.topRight() - QPoint(150, -25)) self.tax_gui.show() def remove_selected(self): indexes = self.ui.table_include.selectionModel().selectedRows() selected_indices = [int(index.row()) for index in list(indexes)] index = self.selected_items_df.index[selected_indices] self.selected_items_df.drop(index, inplace=True) self.ui.table_include.model().layoutChanged.emit() def has_content(self): """ Returns if the widget contains legitimate content that should be written out to xml By default this is always true but should be implement in each subclass with logic to check based on contents Returns ------- bool : True if there is content, False if no """ return self.ui.rbtn_yes.isChecked() def clear_widget(self): self.keywtax.clear_widget() self.taxoncl.clear_widget() def to_xml(self): taxonomy = xml_utils.xml_node('taxonomy') taxonomy.append(self.keywtax.to_xml()) if self.original_xml is not None: taxonsys = xml_utils.search_xpath(self.original_xml, 'taxonsys') if taxonsys is not None: taxonsys.tail = None taxonomy.append(deepcopy(taxonsys)) taxongen = xml_utils.search_xpath(self.original_xml, 'taxongen') 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])
class Taxonomy(WizardWidget): drag_label = "Taxonomy" def build_ui(self): """ Build and modify this widget's GUI Returns ------- None """ self.ui = UI_taxonomy2.Ui_Taxonomy() self.ui.setupUi(self) self.setup_dragdrop(self) self.keywtax = Keywordtax() self.ui.kws_layout.addWidget(self.keywtax) self.taxoncl = Taxoncl() self.ui.taxoncl_contents.layout().addWidget(self.taxoncl) self.include_taxonomy_change(False) def connect_events(self): """ Connect the appropriate GUI components with the corresponding functions Returns ------- None """ self.ui.btn_search.clicked.connect(self.search_itis) self.ui.rbtn_yes.toggled.connect(self.include_taxonomy_change) def include_taxonomy_change(self, b): if b: self.ui.widget_contents.show() else: self.ui.widget_contents.hide() def search_itis(self): self.tax_gui = taxonomy_gui.ItisMainForm(xml=self._to_xml(), fgdc_function=self._from_xml) fg = self.frameGeometry() self.tax_gui.move(fg.topRight() - QPoint(150, -25)) self.taxgui_dialog = QDialog(self) self.taxgui_dialog.setWindowTitle( 'Search Integrated Taxonomic Information System (ITIS)') self.taxgui_dialog.setLayout(self.tax_gui.layout()) self.taxgui_dialog.exec_() def remove_selected(self): indexes = self.ui.table_include.selectionModel().selectedRows() selected_indices = [int(index.row()) for index in list(indexes)] index = self.selected_items_df.index[selected_indices] self.selected_items_df.drop(index, inplace=True) self.ui.table_include.model().layoutChanged.emit() def dragEnterEvent(self, e): """ Only accept Dragged items that can be converted to an xml object with a root tag called 'taxonomy' Parameters ---------- e : qt event Returns ------- """ print("pc 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 == 'taxonomy': e.accept() else: e.ignore() def has_content(self): """ Returns if the widget contains legitimate content that should be written out to xml By default this is always true but should be implement in each subclass with logic to check based on contents Returns ------- bool : True if there is content, False if no """ return self.ui.rbtn_yes.isChecked() def clear_widget(self): self.keywtax.clear_widget() self.taxoncl.clear_widget() def _to_xml(self): taxonomy = xml_utils.xml_node('taxonomy') taxonomy.append(self.keywtax._to_xml()) taxonomy.append(self.taxoncl._to_xml()) return taxonomy def _from_xml(self, taxonomy_element): self.clear_widget() self.ui.rbtn_yes.setChecked(True) self.keywtax._from_xml(taxonomy_element.xpath('keywtax')[0]) self.taxoncl._from_xml(taxonomy_element.xpath('taxoncl')[0])