Skip to content

Commit

Permalink
launchoptions: Use Gtk.FileDialog for all file/path pickers
Browse files Browse the repository at this point in the history
Co-authored-by: Hari Rana <theevilskeleton@riseup.net>
  • Loading branch information
penguinpee and TheEvilSkeleton committed Dec 19, 2024
1 parent 12ab623 commit 5fd0a76
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions bottles/frontend/windows/launchoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,33 @@ def __reset_post_script(self, *_args):
self.btn_post_script_reset.set_visible(False)

def __choose_cwd(self, *_args):
def set_path(dialog, response):
if response != Gtk.ResponseType.ACCEPT:
self.action_cwd.set_subtitle(self.__default_cwd_msg)
return

directory_path = dialog.get_file().get_path()
self.program["folder"] = directory_path
self.action_cwd.set_subtitle(directory_path)
self.btn_cwd_reset.set_visible(True)
def set_path(dialog, result):
try:
directory = dialog.select_folder_finish(result)

dialog = Gtk.FileChooserNative.new(
title=_("Select Working Directory"),
parent=self.window,
action=Gtk.FileChooserAction.SELECT_FOLDER,
)
if directory is None:
self.action_cwd.set_subtitle(self.__default_cwd_msg)
return

directory_path = directory.get_path()
self.program["folder"] = directory_path
self.action_cwd.set_subtitle(directory_path)
self.btn_cwd_reset.set_visible(True)
except GLib.Error as error:
# also thrown when dialog has been cancelled
if error.code == 2:
# error 2 seems to be 'dismiss' or 'cancel'
if self.program["folder"] is None or self.program["folder"] == "":
self.action_cwd.set_subtitle(self.__default_cwd_msg)
else:
# something else happened...
logging.warning("Error selecting folder: %s" % error)
raise

dialog = Gtk.FileDialog.new()
dialog.set_title(_("Select Working Directory"))
dialog.set_modal(True)
dialog.connect("response", set_path)
dialog.show()
dialog.select_folder(parent=self.window, callback=set_path)

def __reset_cwd(self, *_args):
"""
Expand Down

0 comments on commit 5fd0a76

Please sign in to comment.