Skip to content

Commit efa9cbd

Browse files
gregornilw64
authored andcommitted
Library: Port 'Save File' to Python (#775)
1 parent cb43c4e commit efa9cbd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gio, Gtk
5+
import workbench
6+
7+
button = workbench.builder.get_object("button")
8+
9+
10+
def on_output_path_selected(_dialog, result):
11+
# "save_finish" returns a Gio.File you can write to
12+
file = _dialog.save_finish(result)
13+
print(f"Save file to {file.get_path()}")
14+
15+
16+
def save_file(button):
17+
dialog = Gtk.FileDialog(initial_name="Workbench.txt")
18+
dialog.save(workbench.window, None, on_output_path_selected)
19+
20+
21+
# Handle button click
22+
button.connect("clicked", save_file)

0 commit comments

Comments
 (0)