Exemple #1
0
    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
                self.clear_children()
                for attr_node in detailed.xpath("attr"):
                    attr_widget = mdattr.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()
                try:
                    self.attrs[0].supersize_me()
                except IndexError:
                    pass

            else:
                print("The tag is not udom")
        except KeyError:
            pass
Exemple #2
0
 def insert_after(self, this_attr):
     new_attrs = []
     for i, attribute in enumerate(self.attrs):
         new_attrs.append(attribute)
         if attribute == this_attr:
             new_attr = mdattr.Attr(parent=self)
             self.main_layout.insertWidget(i + 1, new_attr)
             new_attrs.append(new_attr)
     self.attrs = new_attrs
Exemple #3
0
    def load_pickle(self, contents):
        self.clear_children()

        if self.original_xml is not None:
            self.from_xml(self.original_xml)
        else:

            for col_label in contents.keys():
                attr_i = mdattr.Attr(parent=self)
                attr_i.ui.fgdc_attrlabl.setText(col_label)

                if contents[col_label][b"type"] == "String":
                    s = pd.Series(contents[col_label][b"contents"])
                    attr_i.set_series(s)
                    attr_i.guess_domain()
                elif contents[col_label][b"type"] in [
                        "Integer",
                        "Single",
                        "SmallInteger",
                        "Double",
                        "Date",
                ]:
                    s = pd.Series(contents[col_label][b"contents"])
                    attr_i.set_series(s)
                    attr_i.ui.comboBox.setCurrentIndex(1)
                else:
                    attr_i.populate_domain_content(3)
                    unrep = contents[col_label][b"contents"]

                    utils.set_text(attr_i.ui.fgdc_attrdef,
                                   unrep[0].decode("utf-8"))
                    utils.set_text(attr_i.domain.ui.fgdc_udom,
                                   unrep[1].decode("utf-8"))
                    utils.set_text(attr_i.ui.fgdc_attrdefs,
                                   unrep[2].decode("utf-8"))
                    attr_i.store_current_content()
                    attr_i.supersize_me()
                    attr_i.regularsize_me()
                self.append_attr(attr_i)

            try:
                self.attrs[0].supersize_me()
            except IndexError:
                pass
Exemple #4
0
    def load_df(self, df):
        if len(df.columns) > 100:
            msgbox = QMessageBox(self)
            utils.set_window_icon(msgbox)
            msgbox.setIcon(QMessageBox.Question)

            msg = "There are more than 100 columns in the dataset you are"
            msg += " trying to build an Entity and Attribute section for!\n\n"
            msg += "The application can become sluggish or unresponsive when "
            msg += " loading and displaying that many columns.\n\n"
            msg += "Displaying more than 250 columns can cause the application"
            msg += " to crash.\n\n"
            msg += "Often datasets with that many columns are documented with"
            msg += " an overview instead of a detailed section, or using a "
            msg += " external data dictionary.\n\n"
            msg += "You have {} columns in this dataset.".format(
                len(df.columns))
            msg += "\n\nAre you sure you want to continue?"

            msgbox.setText(msg)
            msgbox.setWindowTitle("Too Many Columns Warning")
            msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            confirm = msgbox.exec_()

            if confirm == QMessageBox.No:
                return

        self.clear_children()

        i = 0

        for col_label in df.columns:
            col = df[col_label]
            attr_i = mdattr.Attr(parent=self)
            attr_i.ui.fgdc_attrlabl.setText(str(col_label))

            attr_i.set_series(col)
            attr_i.sniff_nodata()
            attr_i.ui.comboBox.setCurrentIndex(attr_i.guess_domain())
            self.append_attr(attr_i)

        self.attrs[0].supersize_me()
Exemple #5
0
    def contextMenuEvent(self, event):
        self.in_context = True
        clicked_widget = self.childAt(event.pos())

        menu = QMenu(self)
        copy_action = menu.addAction(QIcon("copy.png"), "&Copy")
        copy_action.setStatusTip("Copy to the Clipboard")

        paste_action = menu.addAction(QIcon("paste.png"), "&Paste")
        paste_action.setStatusTip("Paste from the Clipboard")

        menu.addSeparator()
        add_attr = menu.addAction(QIcon("paste.png"), "Add attribute (column)")
        add_attr.setStatusTip("Add attribute")

        if hasattr(clicked_widget, "help_text") and clicked_widget.help_text:
            menu.addSeparator()
            help_action = menu.addAction("Help")
        else:
            help_action = None

        menu.addSeparator()
        clear_action = menu.addAction("Clear content")

        action = menu.exec_(self.mapToGlobal(event.pos()))

        if action == copy_action:
            if clicked_widget is None:
                pass
            elif clicked_widget.objectName() == "idinfo_button":
                self.idinfo.copy_mime()
            elif clicked_widget.objectName() == "dataquality_button":
                self.dataqual.copy_mime()
            elif clicked_widget.objectName() == "eainfo_button":
                self.eainfo.copy_mime()
            elif clicked_widget.objectName() == "distinfo_button":
                self.distinfo.copy_mime()
            elif clicked_widget.objectName() == "metainfo_button":
                self.metainfo.copy_mime()
            else:
                self.copy_mime()
        elif action == paste_action:
            self.paste_mime()
        elif action == clear_action:
            if clicked_widget is None:
                self.clear_widget()
            elif clicked_widget.objectName() == "idinfo_button":
                self.idinfo.clear_widget()
            elif clicked_widget.objectName() == "dataquality_button":
                self.dataqual.clear_widget()
            elif clicked_widget.objectName() == "eainfo_button":
                self.eainfo.clear_widget()
            elif clicked_widget.objectName() == "distinfo_button":
                self.distinfo.clear_widget()
            elif clicked_widget.objectName() == "metainfo_button":
                self.metainfo.clear_widget()
            else:
                self.clear_widget()
        elif action == add_attr:
            new_attr = mdattr.Attr(parent=self)
            self.append_attr(new_attr)
            self.minimize_children()
            new_attr.supersize_me()
        elif help_action is not None and action == help_action:
            msg = QMessageBox(self)
            # msg.setTextFormat(Qt.RichText)
            msg.setText(clicked_widget.help_text)
            msg.setWindowTitle("Help")
            msg.show()
        self.in_context = False