Esempio n. 1
0
    def __path_dlg(self, item: QListWidgetItem):
        """View path data."""
        name = item.text().split(":")[0]
        try:
            data = self.__path_data[name]
        except KeyError:
            return

        points_text = ", ".join(f"Point{i}" for i in range(len(data)))
        if QMessageBox.question(
            self,
            "Path data",
            f"This path data including {points_text}.",
            (QMessageBox.Save | QMessageBox.Close),
            QMessageBox.Close
        ) != QMessageBox.Save:
            return

        file_name = self.output_to(
            "path data",
            ["Comma-Separated Values (*.csv)", "Text file (*.txt)"]
        )
        if not file_name:
            return

        with open(file_name, 'w', encoding='utf-8', newline='') as stream:
            writer = csv.writer(stream)
            for point in data:
                for coordinate in point:
                    writer.writerow(coordinate)
                writer.writerow(())
        logger.info(f"Output path data: {file_name}")
Esempio n. 2
0
def on_mechanism_storage_restore_clicked(self, item: QListWidgetItem = None):
    """Restore the storage data."""
    if item is None:
        item = self.mechanism_storage.currentItem()
    if not item:
        return
    reply = QMessageBox.question(
        self, "Storage", "Restore mechanism will overwrite the canvas." +
        "\nDo you want to continue?")
    if reply != QMessageBox.Yes:
        return
    name = item.text()
    self.CommandStack.beginMacro("Restore from {{Mechanism: {}}}".format(name))
    _clearStorage(self)
    self.parseExpression(item.expr)
    self.CommandStack.push(
        DeleteStorage(self.mechanism_storage.row(item),
                      self.mechanism_storage))
    self.CommandStack.push(
        AddStorageName(name, self.mechanism_storage_name_tag))
    self.CommandStack.endMacro()