Python gi.repository.Gtk.FileFilter() Examples

The following are 30 code examples of gi.repository.Gtk.FileFilter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: xdot.py    From bokken with GNU General Public License v2.0 6 votes vote down vote up
def on_open(self, action):
        chooser = Gtk.FileChooserDialog(title="Open dot File",
                                        action=Gtk.FileChooserAction.OPEN,
                                        buttons=(Gtk.STOCK_CANCEL,
                                                 Gtk.ResponseType.CANCEL,
                                                 Gtk.STOCK_OPEN,
                                                 Gtk.ResponseType.OK))
        chooser.set_default_response(Gtk.ResponseType.OK)
        chooser.set_current_folder(self.last_open_dir)
        filter = Gtk.FileFilter()
        filter.set_name("Graphviz dot files")
        filter.add_pattern("*.dot")
        chooser.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        chooser.add_filter(filter)
        if chooser.run() == Gtk.ResponseType.OK:
            filename = chooser.get_filename()
            self.last_open_dir = chooser.get_current_folder()
            chooser.destroy()
            self.open_file(filename)
        else:
            chooser.destroy() 
Example #2
Source File: file_dialog.py    From hazzy with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(FileDialog, self).__init__(*args, **kwargs)

        self.set_titlebar(Gtk.HeaderBar(show_close_button=True))
        self.set_title("Open File")
        self.add_button("_Open", Gtk.ResponseType.OK)
        self.add_button("_Cancel", Gtk.ResponseType.CANCEL)
        self.set_default_response(Gtk.ResponseType.OK)

        #TODO Add file filters based on extensions given in INI

        filefiler = Gtk.FileFilter()
        filefiler.add_pattern('*.ngc')
        filefiler.set_name('G-code')
        self.add_filter(filefiler)

        filefiler = Gtk.FileFilter()
        filefiler.add_pattern('*')
        filefiler.set_name('All Files')
        self.add_filter(filefiler)

        self.show_all() 
Example #3
Source File: file_chooser.py    From ebook-viewer with GNU General Public License v3.0 6 votes vote down vote up
def __add_filters(self, dialog, importing):
        """
        Adds filters to indicate opening only .epub files.
        :param dialog:
        """
        if not importing:
            self.__add_native(dialog)
            if os.path.exists("/usr/bin/ebook-convert"):
                self.__add_imports(dialog)
        else:
            self.__add_imports(dialog)

        filter_any = Gtk.FileFilter()
        filter_any.set_name(_("Any files"))
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any) 
Example #4
Source File: window.py    From pyWinUSB with MIT License 6 votes vote down vote up
def __show_file_chooser(self, button):
        """ Tworzenie dialogu wyboru pliku obrazu
        """
        dialog = Gtk.FileChooserDialog("Please choose a file", self, Gtk.FileChooserAction.OPEN, (
              Gtk.STOCK_CANCEL
            , Gtk.ResponseType.CANCEL
            , Gtk.STOCK_OPEN
            , Gtk.ResponseType.OK
        ))

        filters = {
            "application/x-cd-image": "CD/DVD image"
        }
        for key, val in filters.items():
            filter_text = Gtk.FileFilter()
            filter_text.set_name(val)
            filter_text.add_mime_type(key)
            dialog.add_filter(filter_text)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.path.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")
        dialog.destroy() 
Example #5
Source File: results.py    From runsqlrun with MIT License 6 votes vote down vote up
def export_selected(self):
        def to_csv(value):
            if value is None:
                return ''
            elif isinstance(value, memoryview):
                return ''
            return str(value)

        dlg = Gtk.FileChooserDialog(
            'Export Selection', self.win, Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        file_filter = Gtk.FileFilter()
        file_filter.set_name('CSV files')
        file_filter.add_mime_type('text/csv')
        dlg.add_filter(file_filter)
        dlg.set_current_name('export.csv')
        if dlg.run() == Gtk.ResponseType.ACCEPT:
            with open(dlg.get_filename(), 'w') as f:
                writer = csv.writer(f)
                for row in self._selection.get_export_data():
                    writer.writerow(list(map(to_csv, row)))
        dlg.destroy() 
Example #6
Source File: dialog_windows.py    From innstereo with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, main_window, open_project):
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain(i18n().get_ts_domain())
        script_dir = os.path.dirname(__file__)
        rel_path = "gui_layout.glade"
        abs_path = os.path.join(script_dir, rel_path)
        self.builder.add_objects_from_file(abs_path,
            ("filechooserdialog_open", ""))
        self.dialog = self.builder.get_object("filechooserdialog_open")
        self.dialog.set_transient_for(main_window)
        filter_json = Gtk.FileFilter()
        filter_json.add_pattern("*.json")
        filter_json.set_name("JSON")
        self.dialog.add_filter(filter_json)
        filter_all = Gtk.FileFilter()
        filter_all.add_pattern("*")
        filter_all.set_name(_("All Files"))
        self.dialog.add_filter(filter_all)
        self.open_project = open_project
        self.builder.connect_signals(self)
        if sys.platform == "win32":
            translate_gui(self.builder) 
Example #7
Source File: gnomecast.py    From gnomecast with GNU General Public License v3.0 6 votes vote down vote up
def on_download_subtitle_clicked(self):
      dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
          Gtk.FileChooserAction.OPEN,
          (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
           Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

      if self.fn:
        dialog.set_current_folder(os.path.dirname(self.fn))

      filter_py = Gtk.FileFilter()
      filter_py.set_name("Subtitles")
      filter_py.add_pattern("*.srt")
      filter_py.add_pattern("*.vtt")
      dialog.add_filter(filter_py)

      response = dialog.run()
      if response == Gtk.ResponseType.OK:
          print("Open clicked")
          print("File selected: " + dialog.get_filename())
          self.select_subtitles_file(dialog.get_filename())
      elif response == Gtk.ResponseType.CANCEL:
          print("Cancel clicked")
          self.subtitle_combo.set_active(0)

      dialog.destroy() 
Example #8
Source File: file_filters.py    From badKarma with GNU General Public License v3.0 6 votes vote down vote up
def add_filter_nmap(dialog):
	filter_text = Gtk.FileFilter()
	filter_text.set_name("nmap/masscan XML files")
	filter_text.add_mime_type("text/xml")
	dialog.add_filter(filter_text)

	filter_text = Gtk.FileFilter()
	filter_text.set_name("smap json files")
	filter_text.add_mime_type("application/json")
	filter_text.add_mime_type("text/xml")
	dialog.add_filter(filter_text)

	filter_any = Gtk.FileFilter()
	filter_any.set_name("Any files")
	filter_any.add_pattern("*")
	dialog.add_filter(filter_any) 
Example #9
Source File: color_grid.py    From wpgtk with GNU General Public License v2.0 6 votes vote down vote up
def on_import_click(self, widget):
        fcd = Gtk.FileChooserDialog(
                      'Select a colorscheme', self.parent,
                      Gtk.FileChooserAction.OPEN,
                      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        filter = Gtk.FileFilter()
        filter.set_name("JSON colorscheme")
        filter.add_mime_type("application/json")
        fcd.add_filter(filter)
        response = fcd.run()

        if response == Gtk.ResponseType.OK:
            self.color_list = color.get_color_list(fcd.get_filename(), True)
            self.render_buttons()
            self.render_sample()
        fcd.destroy() 
Example #10
Source File: gnomecast.py    From gnomecast with GNU General Public License v3.0 6 votes vote down vote up
def on_new_subtitle_clicked(self):
      dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
          Gtk.FileChooserAction.OPEN,
          (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
           Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

      if self.fn:
        dialog.set_current_folder(os.path.dirname(self.fn))

      filter_py = Gtk.FileFilter()
      filter_py.set_name("Subtitles")
      filter_py.add_pattern("*.srt")
      filter_py.add_pattern("*.vtt")
      dialog.add_filter(filter_py)

      response = dialog.run()
      if response == Gtk.ResponseType.OK:
          print("Open clicked")
          print("File selected: " + dialog.get_filename())
          self.select_subtitles_file(dialog.get_filename())
      elif response == Gtk.ResponseType.CANCEL:
          print("Cancel clicked")
          self.subtitle_combo.set_active(0)

      dialog.destroy() 
Example #11
Source File: misc.py    From dynamic-wallpaper-editor with GNU General Public License v3.0 6 votes vote down vote up
def add_pic_dialog_filters(dialog):
	"""Add file filters for images to a file chooser dialog."""
	allPictures = Gtk.FileFilter()
	allPictures.set_name(_("All pictures"))
	allPictures.add_mime_type('image/png')
	allPictures.add_mime_type('image/jpeg')
	allPictures.add_mime_type('image/bmp')
	allPictures.add_mime_type('image/svg')
	allPictures.add_mime_type('image/tiff')

	pngPictures = Gtk.FileFilter()
	pngPictures.set_name(_("PNG images"))
	pngPictures.add_mime_type('image/png')

	jpegPictures = Gtk.FileFilter()
	jpegPictures.set_name(_("JPEG images"))
	jpegPictures.add_mime_type('image/jpeg')

	dialog.add_filter(allPictures)
	dialog.add_filter(pngPictures)
	dialog.add_filter(jpegPictures) 
Example #12
Source File: pyspc_gui.py    From pyspc with GNU General Public License v3.0 6 votes vote down vote up
def on_file(self, button):

        dialog = Gtk.FileChooserDialog("Please choose a file", self,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        filter_csv = Gtk.FileFilter()
        filter_csv.set_name("CSV Files")
        filter_csv.add_pattern("*.csv")
        dialog.add_filter(filter_csv)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            path = dialog.get_filename()
            self.data = pd.read_csv(path)
            self.verticalbox.remove(self.scrollable_treelist)
            self.add_treeview()

        dialog.destroy() 
Example #13
Source File: extras.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def quick_add_filter(self, name, patterns):
		"""
		Add a filter for displaying files, this is useful in conjunction
		with :py:meth:`.run_quick_open`.

		:param str name: The name of the filter.
		:param patterns: The pattern(s) to match.
		:type patterns: list, str
		"""
		if not isinstance(patterns, (list, tuple)):
			patterns = (patterns,)
		new_filter = Gtk.FileFilter()
		new_filter.set_name(name)
		for pattern in patterns:
			new_filter.add_pattern(pattern)
		self.add_filter(new_filter) 
Example #14
Source File: settings_dialog.py    From SafeEyes with GNU General Public License v3.0 6 votes vote down vote up
def select_image(self, button):
        """
        Show a file chooser dialog and let the user to select an image.
        """
        dialog = Gtk.FileChooserDialog(_('Please select an image'), self.window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        png_filter = Gtk.FileFilter()
        png_filter.set_name("PNG files")
        png_filter.add_mime_type("image/png")
        png_filter.add_pattern("*.png")
        dialog.add_filter(png_filter)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.break_config['image'] = dialog.get_filename()
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.break_config['image'], 16, 16, True)
            self.img_break.set_from_pixbuf(pixbuf)
        elif response == Gtk.ResponseType.CANCEL:
            self.break_config.pop('image', None)
            self.img_break.set_from_stock('gtk-missing-image', Gtk.IconSize.BUTTON)

        dialog.destroy() 
Example #15
Source File: file_chooser.py    From ebook-viewer with GNU General Public License v3.0 5 votes vote down vote up
def __add_native(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name(_("ePub files"))
        for extension in constants.NATIVE:
            filter_text.add_pattern("*" + extension.upper())
            filter_text.add_pattern("*" + extension.lower())
        dialog.add_filter(filter_text) 
Example #16
Source File: gnomecast.py    From gnomecast with GNU General Public License v3.0 5 votes vote down vote up
def on_file_clicked(self, widget):
      dialog = Gtk.FileChooserDialog("Please choose an audio or video file...", self.win,
          Gtk.FileChooserAction.OPEN,
          (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
           Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
      dialog.set_select_multiple(True)

      downloads_dir = os.path.expanduser('~/Downloads')
      if os.path.isdir(downloads_dir):
        dialog.set_current_folder(downloads_dir)

      filter_py = Gtk.FileFilter()
      filter_py.set_name("Videos")
      filter_py.add_mime_type("video/*")
      filter_py.add_mime_type("audio/*")
      dialog.add_filter(filter_py)

      response = dialog.run()
      if response == Gtk.ResponseType.OK:
          print("Open clicked")
          print("File selected:", dialog.get_filenames())
          self.queue_files(dialog.get_filenames())
          #self.select_file(dialog.get_filename())
      elif response == Gtk.ResponseType.CANCEL:
          print("Cancel clicked")

      dialog.destroy() 
Example #17
Source File: pdf_quench.py    From pdf-quench with GNU General Public License v2.0 5 votes vote down vote up
def __open_file(self):
    dialog = Gtk.FileChooserDialog(title='Load pdf file',
                                   parent=self,
                                   action=Gtk.FileChooserAction.OPEN,
                                   buttons=(Gtk.STOCK_CANCEL,
                                            Gtk.ResponseType.CANCEL,
                                            Gtk.STOCK_OK,
                                            Gtk.ResponseType.OK))
    global LAST_OPEN_FOLDER
    if LAST_OPEN_FOLDER:
      dialog.set_current_folder(LAST_OPEN_FOLDER)
    else:
      dialog.set_current_folder(os.getcwd())
    file_filter = Gtk.FileFilter()
    file_filter.add_pattern("*.pdf")
    dialog.set_filter(file_filter)
    pdf_file_name = None

    try:
      response = dialog.run()
      if response == Gtk.ResponseType.OK:
        pdf_file_name = dialog.get_filename()
        LAST_OPEN_FOLDER = os.path.dirname(pdf_file_name)
      dialog.hide()
    finally:
      dialog.destroy()

    if pdf_file_name:
      self.__load_pdf_file(pdf_file_name)
      self.__pages_view.get_selection().select_iter(
          self.__pages_model.get_iter_first())

    return True 
Example #18
Source File: ui.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def pick_file(self, *args):
        """ Ask the user which file he means to open.
        """
        # Use a GTK file dialog to choose file
        dialog = Gtk.FileChooserDialog(title = _('Open...'), transient_for = self.p_win,
                                       action = Gtk.FileChooserAction.OPEN)
        dialog.add_buttons(Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
        dialog.set_default_response(Gtk.ResponseType.OK)
        dialog.set_position(Gtk.WindowPosition.CENTER)

        filter = Gtk.FileFilter()
        filter.set_name(_('PDF files'))
        filter.add_mime_type('application/pdf')
        filter.add_pattern('*.pdf')
        dialog.add_filter(filter)

        filter = Gtk.FileFilter()
        filter.set_name(_('All files'))
        filter.add_pattern('*')
        dialog.add_filter(filter)

        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            self.swap_document(os.path.abspath(dialog.get_filename()))

        dialog.destroy() 
Example #19
Source File: custom.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def __init__(self, title, filter=None):
		Gtk.FileChooserButton.__init__(self, title=title)
		if filter is not None and len(filter) > 1:
			name, pattern = filter
			file_filter = Gtk.FileFilter()
			file_filter.set_name('%s (%s)' % (name, pattern))
			file_filter.add_pattern(pattern)
			self.add_filter(file_filter) 
Example #20
Source File: file_chooser.py    From ebook-viewer with GNU General Public License v3.0 5 votes vote down vote up
def __add_imports(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name(_("Importable files"))
        for extension in constants.IMPORTABLES:
            filter_text.add_pattern("*" + extension.upper())
            filter_text.add_pattern("*" + extension.lower())
        dialog.add_filter(filter_text) 
Example #21
Source File: simpledialog.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def add_filters(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name("Text files")
        filter_text.add_mime_type("text/plain")
        dialog.add_filter(filter_text)

        filter_py = Gtk.FileFilter()
        filter_py.set_name("Python files")
        filter_py.add_mime_type("text/x-python")
        dialog.add_filter(filter_py)

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any) 
Example #22
Source File: gtk.py    From pywebview with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _add_file_filters(self, dialog, file_types):
        for s in file_types:
            description, extensions = parse_file_type(s)

            f = gtk.FileFilter()
            f.set_name(description)
            for e in extensions.split(';'):
                f.add_pattern(e)

            dialog.add_filter(f) 
Example #23
Source File: utilities.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def utilities_add_filechooser_filters(dialog):
	"""Add file filters for images to file chooser dialogs."""
	allPictures = Gtk.FileFilter()
	allPictures.set_name(_("All pictures"))
	allPictures.add_mime_type('image/png')
	allPictures.add_mime_type('image/jpeg')
	allPictures.add_mime_type('image/bmp')

	pngPictures = Gtk.FileFilter()
	pngPictures.set_name(_("PNG images"))
	pngPictures.add_mime_type('image/png')

	jpegPictures = Gtk.FileFilter()
	jpegPictures.set_name(_("JPEG images"))
	jpegPictures.add_mime_type('image/jpeg')

	bmpPictures = Gtk.FileFilter()
	bmpPictures.set_name(_("BMP images"))
	bmpPictures.add_mime_type('image/bmp')

	dialog.add_filter(allPictures)
	dialog.add_filter(pngPictures)
	dialog.add_filter(jpegPictures)
	dialog.add_filter(bmpPictures)

################################################################################ 
Example #24
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def _add_filter_all(self):
		filter = Gtk.FileFilter()
		filter.set_name(_('All Files'))
			# T: Filter in open file dialog, shows all files (*)
		filter.add_pattern('*')
		self.filechooser.add_filter(filter) 
Example #25
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def add_filter(self, name, glob):
		'''Add a filter for files with specific extensions in the dialog
		@param name: the label to display in the filter selection
		@param glob: a file pattern (e.g. "*.txt")
		@returns: the C{Gtk.FileFilter} object
		'''
		if len(self.filechooser.list_filters()) == 0:
			self._add_filter_all()
		filter = Gtk.FileFilter()
		filter.set_name(name)
		filter.add_pattern(glob)
		self.filechooser.add_filter(filter)
		self.filechooser.set_filter(filter)
		return filter 
Example #26
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def add_filter_images(self):
		'''Add a standard file filter for selecting image files.
		@returns: the C{Gtk.FileFilter} object
		'''
		if len(self.filechooser.list_filters()) == 0:
			self._add_filter_all()
		filter = Gtk.FileFilter()
		filter.set_name(_('Images'))
			# T: Filter in open file dialog, shows image files only
		filter.add_pixbuf_formats()
		filter.add_mime_type('image/*') # to allow types like .ico
		self.filechooser.add_filter(filter)
		self.filechooser.set_filter(filter)
		return filter 
Example #27
Source File: backup.py    From rednotebook with GNU General Public License v2.0 5 votes vote down vote up
def _get_backup_file(self):
        if self.journal.title == "data":
            name = ""
        else:
            name = "-" + self.journal.title

        proposed_filename = "RedNotebook-Backup{}-{}.zip".format(
            name, datetime.date.today()
        )
        proposed_directory = self.journal.config.read(
            "lastBackupDir", os.path.expanduser("~")
        )

        backup_dialog = self.journal.frame.builder.get_object("backup_dialog")
        backup_dialog.set_transient_for(self.journal.frame.main_frame)
        backup_dialog.set_current_folder(proposed_directory)
        backup_dialog.set_current_name(proposed_filename)

        filter = Gtk.FileFilter()
        filter.set_name("Zip")
        filter.add_pattern("*.zip")
        backup_dialog.add_filter(filter)

        response = backup_dialog.run()
        backup_dialog.hide()

        if response == Gtk.ResponseType.OK:
            path = backup_dialog.get_filename()
            return path 
Example #28
Source File: customwidgets.py    From rednotebook with GNU General Public License v2.0 5 votes vote down vote up
def prepare(self, porter):
        self._remove_filters()

        self.path_type = porter.PATHTYPE.upper()
        path = porter.DEFAULTPATH
        extension = porter.EXTENSION
        helptext = porter.PATHTEXT

        if helptext:
            self.set_header(helptext)

        if self.path_type == "DIR":
            self.chooser.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
        elif self.path_type == "FILE":
            self.chooser.set_action(Gtk.FileChooserAction.OPEN)
        elif self.path_type == "NEWFILE":
            self.chooser.set_action(Gtk.FileChooserAction.SAVE)
        else:
            logging.error('Wrong path_type "%s"' % self.path_type)

        if self.path_type in ["FILE", "NEWFILE"] and extension:
            filter = Gtk.FileFilter()
            filter.set_name(extension)
            filter.add_pattern("*." + extension)
            self.chooser.add_filter(filter)

        if self.last_path and os.path.exists(self.last_path):
            path = self.last_path

        if os.path.isdir(path):
            self.chooser.set_current_folder(path)
        else:
            dirname, basename = os.path.split(path)
            filename, _ = os.path.splitext(basename)
            self.chooser.set_current_folder(dirname)
            self.chooser.set_current_name(filename + "." + extension) 
Example #29
Source File: template_grid.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def on_add_clicked(self, widget):
        filechooser = Gtk.FileChooserDialog("Select an Image", self.parent,
                                            Gtk.FileChooserAction.OPEN,
                                            (Gtk.STOCK_CANCEL,
                                             Gtk.ResponseType.CANCEL,
                                             Gtk.STOCK_OPEN,
                                             Gtk.ResponseType.OK))
        filefilter = Gtk.FileFilter()
        filechooser.set_select_multiple(True)
        filefilter.set_name("Text")
        filefilter.add_mime_type("text/*")
        filechooser.add_filter(filefilter)
        response = filechooser.run()

        if response == Gtk.ResponseType.OK:
            for f in filechooser.get_filenames():
                files.add_template(f)
            self.item_names = [f for f in
                               files.get_file_list(OPT_DIR, False)
                               if '.base' in f]
            self.liststore = Gtk.ListStore(Pixbuf, str)
            for filen in self.item_names:
                pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0)
                self.liststore.append([pixbuf, filen])
            self.file_view.set_model(self.liststore)
        filechooser.destroy()
        self.file_view.unselect_all() 
Example #30
Source File: launcher_wine.py    From games_nebula with GNU General Public License v3.0 5 votes vote down vote up
def setup_custom_exe(self, button):
        file_path = ''
        file_name = ''

        dialog = Gtk.FileChooserDialog(
            _("Select an executable"),
            self.main_window,
            Gtk.FileChooserAction.OPEN,
            (
                Gtk.STOCK_CANCEL,
                Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OPEN,
                Gtk.ResponseType.OK
            )
        )

        dialog.set_current_folder(self.wineprefix + '/drive_c/Games/' + self.game_name)

        file_filter = Gtk.FileFilter()
        file_filter.set_name("*.exe")
        file_filter.add_pattern("*.exe")
        dialog.add_filter(file_filter)

        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            file_path = dialog.get_current_folder()
            file_name = dialog.get_filename().split('/')[-1]
            if '.exe' in file_name:
                button.set_label(file_name)
                button.get_parent().get_children()[-1].set_sensitive(True)
            dialog.destroy()
        else:
            dialog.destroy()

        return file_path, file_name