From 4691bb4ef65516829bedfac768e2f955bac9d1c4 Mon Sep 17 00:00:00 2001 From: Nokse22 Date: Mon, 12 Jun 2023 14:53:59 +0200 Subject: [PATCH] use filechoosernative --- io.github.nokse22.teleprompter.json | 1 - src/window.py | 43 +++++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/io.github.nokse22.teleprompter.json b/io.github.nokse22.teleprompter.json index 8bf2c8a..8caa076 100644 --- a/io.github.nokse22.teleprompter.json +++ b/io.github.nokse22.teleprompter.json @@ -9,7 +9,6 @@ "--socket=fallback-x11", "--device=dri", "--socket=wayland", - "--filesystem=home:ro" ], "cleanup" : [ "/include", diff --git a/src/window.py b/src/window.py index 50ad2dd..dfa6b2d 100644 --- a/src/window.py +++ b/src/window.py @@ -48,9 +48,8 @@ def save_app_settings(settings): gio_settings.set_int("slow-speed", settings.slowSpeed * 10) def on_file_selected(dialog, response, self): - if response == Gtk.ResponseType.OK: - # filename = file_obj.get_path() if file_obj else None - # print("Selected file: {}".format(filename)) + print(response) + if response == -3: selected_file = dialog.get_file() if selected_file: file_path = selected_file.get_path() @@ -79,23 +78,39 @@ def on_file_selected(dialog, response, self): dialog.destroy() def show_file_chooser_dialog(self): - dialog = Gtk.FileChooserDialog( + + # Create a Gtk.FileChooserNative instance + dialog = Gtk.FileChooserNative( title="Open File", + transient_for=None, action=Gtk.FileChooserAction.OPEN, - transient_for=None ) - dialog.add_button("Open", Gtk.ResponseType.OK) - dialog.add_button("Close", Gtk.ResponseType.CANCEL) - # Create a filter to display only .txt files - filter_txt = Gtk.FileFilter() - filter_txt.set_name("Text files") - filter_txt.add_pattern("*.txt") - dialog.add_filter(filter_txt) - dialog.set_filter(filter_txt) + dialog.set_accept_label("Open") + dialog.set_cancel_label("Cancel") + + # Show the dialog and get the response + response = dialog.show() dialog.connect("response", on_file_selected, self) - dialog.show() + + # dialog = Gtk.FileChooserDialog( + # title="Open File", + # action=Gtk.FileChooserAction.OPEN, + # transient_for=None + # ) + # dialog.add_button("Open", Gtk.ResponseType.OK) + # dialog.add_button("Close", Gtk.ResponseType.CANCEL) + + # Create a filter to display only .txt files + # filter_txt = Gtk.FileFilter() + # filter_txt.set_name("Text files") + # filter_txt.add_pattern("*.txt") + # dialog.add_filter(filter_txt) + # dialog.set_filter(filter_txt) + + # dialog.connect("response", on_file_selected, self) + # dialog.show() def load_app_settings(): print("loading")