Skip to content

Commit

Permalink
use filechoosernative
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Jun 12, 2023
1 parent 6f3ec8d commit 4691bb4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
1 change: 0 additions & 1 deletion io.github.nokse22.teleprompter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"--socket=fallback-x11",
"--device=dri",
"--socket=wayland",
"--filesystem=home:ro"
],
"cleanup" : [
"/include",
Expand Down
43 changes: 29 additions & 14 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4691bb4

Please sign in to comment.