Skip to content

Commit

Permalink
save File
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 28, 2024
1 parent a81173f commit dd0dcdb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions demos/Save File/main.blp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Adw.StatusPage {
}
}
}

5 changes: 3 additions & 2 deletions demos/Save File/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Gio._promisify(
const button = workbench.builder.get_object("button");

async function saveFile() {
const dialog = new Gtk.FileDialog({
const file_dialog = new Gtk.FileDialog({
initial_name: "Workbench.txt",
});
// "dialog.save" returns a Gio.File you can write to
const file = await dialog.save(workbench.window, null);
const file = await file_dialog.save(workbench.window, null);

const contents = new TextEncoder().encode("Hello from Workbench!");
await file.replace_contents_async(
Expand All @@ -33,3 +33,4 @@ async function saveFile() {
button.connect("clicked", () => {
saveFile().catch(console.error);
});

9 changes: 5 additions & 4 deletions demos/Save File/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@


def save_file(button):
dialog = Gtk.FileDialog(initial_name="Workbench.txt")
dialog.save(parent=workbench.window, cancellable=None, callback=on_save)
file_dialog = Gtk.FileDialog(initial_name="Workbench.txt")
file_dialog.save(parent=workbench.window, cancellable=None, callback=on_save)


def on_save(dialog, result):
def on_save(file_dialog, result):
# "save_finish" returns a Gio.File you can write to
file = dialog.save_finish(result)
file = file_dialog.save_finish(result)
contents = "Hello from Workbench!".encode("UTF-8")
file.replace_contents_async(
contents,
Expand All @@ -33,3 +33,4 @@ def on_replace_contents(file, result):

# Handle button click
button.connect("clicked", save_file)

0 comments on commit dd0dcdb

Please sign in to comment.