示例#1
0
    def check_for_changes(self):
        try:
            if self.cur_fname and os.path.exists(self.cur_fname):
                cur_xml = xml_utils.node_to_string(self.metadata_root.to_xml())
                disk_xml = xml_utils.node_to_string(
                    xml_utils.fname_to_node(self.cur_fname)
                )

            if cur_xml != disk_xml:
                msg = "Do you want to save your changes?"
                alert = QDialog()
                self.last_updated = time.time()
                confirm = QMessageBox.question(
                    self,
                    "Save Changes",
                    msg,
                    QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
                )
                if confirm == QMessageBox.Yes:
                    xml_utils.save_to_file(self.metadata_root.to_xml(), self.cur_fname)
                elif confirm == QMessageBox.Cancel:
                    return "Cancel"
        except:
            pass
        return None
示例#2
0
    def exit(self):
        """
        Before exiting check if the current contents match what is on the
        file system.  If the do not match ask user if they would like to
        save or cancel the exit

        Returns
        -------
        str :
        'Close' or 'Cancel' depending on user choice.
        """
        if self.cur_fname:
            cur_xml = xml_utils.node_to_string(self.metadata_root._to_xml())
            disk_xml = xml_utils.node_to_string(xml_utils.fname_to_node(self.cur_fname))

            if cur_xml != disk_xml:
                msg = "Would you like to save before exiting?"
                alert = QDialog()
                self.last_updated = time.time()
                confirm = QMessageBox.question(self, "File Changed", msg, QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
                if confirm == QMessageBox.Yes:
                    self.save_file()
                elif confirm == QMessageBox.Cancel:
                    return 'Cancel'
                self.cur_fname = ''

        self.close()
        return 'Close'
示例#3
0
 def load_file_content(self, fname):
     QApplication.setOverrideCursor(Qt.WaitCursor)
     QApplication.processEvents()
     self.metadata_root.clear_widget()
     try:
         new_record = xml_utils.fname_to_node(fname)
         self.metadata_root.from_xml(new_record)
         self.statusBar().showMessage("File loaded", 10000)
     except BaseException as e:
         import traceback
         msg = "Cannot open file %s:\n%s." % (fname, traceback.format_exc())
         QApplication.restoreOverrideCursor()
         QMessageBox.warning(self, "Recent Files", msg)
     QApplication.restoreOverrideCursor()
示例#4
0
 def load_file_content(self, fname):
     QApplication.setOverrideCursor(Qt.WaitCursor)
     QApplication.processEvents()
     self.metadata_root.clear_widget()
     self.ui.actionData_Quality.setChecked(True)
     self.use_dataqual(True)
     self.ui.actionSpatial.setChecked(True)
     self.use_spatial(True)
     self.ui.actionEntity_and_Attribute.setChecked(True)
     self.use_eainfo(True)
     self.ui.actionDistribution.setChecked(True)
     self.use_distinfo(True)
     try:
         new_record = xml_utils.fname_to_node(fname)
         self.metadata_root.from_xml(new_record)
         self.statusBar().showMessage("File loaded", 10000)
     except BaseException as e:
         import traceback
         msg = "Cannot open file %s:\n%s." % (fname, traceback.format_exc())
         QApplication.restoreOverrideCursor()
         QMessageBox.warning(self, "Recent Files", msg)
     QApplication.restoreOverrideCursor()