Skip to content

Commit

Permalink
Handle cancelled save-as
Browse files Browse the repository at this point in the history
  • Loading branch information
jrm5100 committed Jun 15, 2020
1 parent 49dd14a commit a58e002
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions gui/main_window/main_window_widgets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def read_color_settings(self):
settings.beginGroup("display/data")
data_colors = dict()
data_colors["Unknown"] = QColor(settings.value("bgcolor_unknown",
defaultValue=QColor.fromRgb(255, 255, 255)))
defaultValue=QColor.fromRgb(255, 255, 255)))
data_colors["Binary"] = QColor(settings.value("bgcolor_binary",
defaultValue=QColor.fromRgb(255, 204, 153)))
defaultValue=QColor.fromRgb(255, 204, 153)))
data_colors["Categorical"] = QColor(settings.value("bgcolor_categorical",
defaultValue=QColor.fromRgb(153, 204, 255)))
defaultValue=QColor.fromRgb(153, 204, 255)))
data_colors["Continuous"] = QColor(settings.value("bgcolor_continuous",
defaultValue=QColor.fromRgb(204, 153, 255)))
defaultValue=QColor.fromRgb(204, 153, 255)))
settings.endGroup()

return data_colors
Expand Down Expand Up @@ -204,7 +204,11 @@ def save_dataset(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
filename, _ = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "",
"All Files (*);;Text Files (*.txt)", options=options)
"All Files (*);;Text Files (*.txt)", options=options)

# Return without doing anything if a valid file wasn't selected
if not filename:
return

# Define a no-parameter function to save the data using a thread
dataset = self.appctx.datasets[self.appctx.current_dataset_idx]
Expand All @@ -231,13 +235,11 @@ def save_func():
# Log Info
save_str = f"\nSaved {len(dataset.df):,} observations of {len(list(dataset.df)):,} variables" \
f" in '{dataset.get_selector_name()}' to '{filename}'\n"
self.appctx.log_info("\n" + "="*80 + save_str + "="*80)
self.appctx.log_info("\n" + "=" * 80 + save_str + "=" * 80)

# Log Python
self.appctx.log_python(f"# Save data and it's associated datatypes\n"
f"{dataset.get_python_name()}.to_csv({filename}, sep='\t')\n")
# TODO: Save datatypes file similar to the commandline?

f"{dataset.get_python_name()}.to_csv({filename}, sep='\t')\n")

@pyqtSlot()
def delete_dataset(self):
Expand Down
4 changes: 2 additions & 2 deletions gui/main_window/main_window_widgets/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def save_log(self):
"""Save the log"""
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
filename, ok = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "",
filename, _ = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "",
self.filetype, options=options)

# Return without doing anything if a valid file wasn't selected
if not ok:
if not filename:
return

# Define a no-parameter function to save the data using a thread
Expand Down

0 comments on commit a58e002

Please sign in to comment.