Skip to content

Instantly share code, notes, and snippets.

@achadwick
Created January 29, 2016 01:57
Show Gist options
  • Save achadwick/98244f445e3b64ba040a to your computer and use it in GitHub Desktop.
Save achadwick/98244f445e3b64ba040a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# All rights waived: https://creativecommons.org/publicdomain/zero/1.0/
# Andrew Chadwick, 29 Jan 2016.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio
import os
import os.path
import logging
logger = logging.getLogger(__name__)
def _main():
flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR
parent = None
filename = os.path.join(
os.getcwd(),
"desktop/icons/hicolor/512x512/apps/mypaint.png",
)
logger.info("filename: %r", filename)
gfile = Gio.File.new_for_path(filename)
app_dialog = Gtk.AppChooserDialog.new(parent, flags, gfile)
logger.info("Constructing dialog...")
app_dialog.set_heading("MyPaint needs to open a file...")
app_widget = app_dialog.get_widget()
#app_widget.set_show_fallback(True)
#app_widget.set_show_recommended(True)
logger.info("Running dialog...")
resp = Gtk.ResponseType(app_dialog.run())
logger.info("Dialog response: %r", resp)
positive_resps = [Gtk.ResponseType.OK]
negative_resps = [Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT]
if resp in positive_resps:
logger.info("User selected an app")
app_info = app_dialog.get_app_info()
logger.info("User chose: %r", app_info.get_name())
elif resp in negative_resps:
logger.info("User cancelled dialog")
else:
logger.warning("Unexpected response from dialog: %r", resp)
if __name__ == "__main__":
logging.basicConfig(level = logging.DEBUG)
_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment