[Python] How to create an "Open file" dialog box in Python for a GIMP 3 plugin with GIMP 3...

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I recently got into the world of plugins for GIMP 3, but I have a good knowledge of Python programming. I'm creating a plugin where I need to select .txt files to extract some information. Since I know practically nothing about GIMP 3's functions, methods, classes and packages, I've been using AI to perform some code snippets. The problem I'm currently facing is that I have this code below to create the .txt file selection window, but the window has the native graphic style of the operating system I'm using (Ubuntu). I saw something about defining the parent window in GIMP and inheriting its graphic style, but I can't do that at all. Could someone give me a tip on what to do in my code to make this work or is it not possible? I've tried codes that used get_main_window but I get the error "'gi.repository.Gimp' object has no attribute 'get_main_window'"

    def select_txt_file(parent_window=None):
    # Create file selection window
    dialog = Gtk.FileChooserDialog(
    title="Select a text file",
    action=Gtk.FileChooserAction.OPEN,
    buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
    Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
    )

    # Filter for .txt files
    filter_txt = Gtk.FileFilter()
    filter_txt.set_name("Text files")
    filter_txt.add_pattern("*.txt")
    dialog.add_filter(filter_txt)

    # Run dialog and get response
    response = dialog.run()
    filename = None

    if response == Gtk.ResponseType.OK:
    filename = dialog.get_filename()

    dialog.destroy()

    return filename

    Continue reading...

Compartilhe esta Página