Python gi.repository.Gtk.FileChooserDialog() Examples
The following are 30
code examples of gi.repository.Gtk.FileChooserDialog().
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: results.py From runsqlrun with MIT License | 6 votes |
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 #2
Source File: backend_gtk3.py From Computable with MIT License | 6 votes |
def __init__(self, canvas, window): """ figManager is the FigureManagerGTK3 instance that contains the toolbar, with attributes figure, window and drawingArea """ GObject.GObject.__init__(self) self.canvas = canvas # Note: Gtk.Toolbar already has a 'window' attribute self.win = window self.set_style(Gtk.ToolbarStyle.ICONS) self._create_toolitems() self.update = self._update self.fileselect = FileChooserDialog( title='Save the figure', parent=self.win, filetypes=self.canvas.get_supported_filetypes(), default_filetype=self.canvas.get_default_filetype()) self.show_all() self.update()
Example #3
Source File: backend_gtk3.py From matplotlib-4-abaqus with MIT License | 6 votes |
def __init__(self, canvas, window): """ figManager is the FigureManagerGTK3 instance that contains the toolbar, with attributes figure, window and drawingArea """ GObject.GObject.__init__(self) self.canvas = canvas # Note: Gtk.Toolbar already has a 'window' attribute self.win = window self.set_style(Gtk.ToolbarStyle.ICONS) self._create_toolitems() self.update = self._update self.fileselect = FileChooserDialog( title='Save the figure', parent=self.win, filetypes=self.canvas.get_supported_filetypes(), default_filetype=self.canvas.get_default_filetype()) self.show_all() self.update()
Example #4
Source File: modules.py From gpt with GNU General Public License v3.0 | 6 votes |
def on_folder_clicked(self): Gtk.Window.__init__(self, title=_("Change working directory")) dialog = Gtk.FileChooserDialog(_("Choose directory"), self, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, _("Apply"), Gtk.ResponseType.OK, ) ) dialog.set_default_size(800, 400) response = dialog.run() if response == Gtk.ResponseType.OK: self.selectedfolder = dialog.get_filename() elif response == Gtk.ResponseType.CANCEL: self.selectedfolder = cli.stdir dialog.destroy()
Example #5
Source File: lxmlGramplet.py From addons-source with GNU General Public License v2.0 | 6 votes |
def __select_file(self, obj): """ Call back function to handle the open button press """ my_action = Gtk.FileChooserAction.SAVE dialog = Gtk.FileChooserDialog('lxml', action=my_action, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) name = os.path.basename(self.entry.get_text()) dialog.set_current_name(name) dialog.set_current_folder(self.__base_path) dialog.present() status = dialog.run() if status == Gtk.ResponseType.OK: self.set_filename(dialog.get_filename()) dialog.destroy()
Example #6
Source File: etreeGramplet.py From addons-source with GNU General Public License v2.0 | 6 votes |
def __select_file(self, obj): """ Call back function to handle the open button press """ my_action = Gtk.FileChooserAction.SAVE dialog = Gtk.FileChooserDialog('lxml', action=my_action, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) name = os.path.basename(self.entry.get_text()) dialog.set_current_name(name) dialog.set_current_folder(self.__base_path) dialog.present() status = dialog.run() if status == Gtk.ResponseType.OK: self.set_filename(dialog.get_filename()) dialog.destroy()
Example #7
Source File: color_grid.py From wpgtk with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: window.py From pyWinUSB with MIT License | 6 votes |
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 #9
Source File: bruter.py From badKarma with GNU General Public License v3.0 | 6 votes |
def bruter_open_user_file(self ,widget): dialog = Gtk.FileChooserDialog("Please choose a file", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) file_filters.add_filter_txt(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() self.bruter_user_wl_path.set_text(file_selected) elif response == Gtk.ResponseType.CANCEL: dialog.destroy() dialog.destroy()
Example #10
Source File: bruter.py From badKarma with GNU General Public License v3.0 | 6 votes |
def bruter_open_pass_file(self ,widget): dialog = Gtk.FileChooserDialog("Please choose a file", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) file_filters.add_filter_txt(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() self.bruter_pass_wl_path.set_text(file_selected) elif response == Gtk.ResponseType.CANCEL: dialog.destroy() dialog.destroy()
Example #11
Source File: main.py From badKarma with GNU General Public License v3.0 | 6 votes |
def save_file_as(self, widget): """ save the project's sqlite database """ dialog = Gtk.FileChooserDialog("Please choose a filename", None, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) dialog.set_filename("project") file_filters.add_filter_database(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() try: shutil.copy(self.engine.database.db_loc, file_selected) except: pass elif response == Gtk.ResponseType.CANCEL: dialog.destroy() dialog.destroy()
Example #12
Source File: settings_dialog.py From SafeEyes with GNU General Public License v3.0 | 6 votes |
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 #13
Source File: docreport.py From amir with GNU General Public License v3.0 | 6 votes |
def exportToCSV(self, sender): report = self.createReport(False) if report == None: return content = "" for key in report["heading"]: content += key.replace(",", "") + "," content += "\n" for data in report["data"]: for item in data: content += item.replace(",", "") + "," content += "\n" dialog = Gtk.FileChooserDialog(None, self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT)) res = dialog.run() if res == Gtk.ResponseType.ACCEPT: filename = os.path.splitext(dialog.get_filename())[0] file = open(filename + ".csv", "w") file.write(content) file.close() dialog.destroy()
Example #14
Source File: tbalancereport.py From amir with GNU General Public License v3.0 | 6 votes |
def exportToCSV(self, sender): report = self.createReport() if report == None: return content = "" for key in report["heading"]: content += key.replace(",", "") + "," content += "\n" for data in report["data"]: for item in data: content += item.replace(",", "") + "," content += "\n" dialog = Gtk.FileChooserDialog(None, self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT)) dialog.run() filename = os.path.splitext(dialog.get_filename())[0] file = open(filename + ".csv", "w") file.write(content) file.close() dialog.destroy()
Example #15
Source File: notebookreport.py From amir with GNU General Public License v3.0 | 6 votes |
def exportToCSV(self, sender): report = self.createReport() if report == None: return content = "" for key in report["heading"]: content += key.replace(",", "") + "," content += "\n" for data in report["data"]: for item in data: content += item.replace(",", "") + "," content += "\n" dialog = Gtk.FileChooserDialog(None, self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT)) dialog.run() filename = os.path.splitext(dialog.get_filename())[0] file = open(filename + ".csv", "w") file.write(content) file.close() dialog.destroy()
Example #16
Source File: pyspc_gui.py From pyspc with GNU General Public License v3.0 | 6 votes |
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 #17
Source File: pyspc_gui.py From pyspc with GNU General Public License v3.0 | 6 votes |
def on_file_clicked(self, widget): # dialog = Gtk.FileChooserDialog("Please choose a file", self, # Gtk.FileChooserAction.OPEN, # (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, # Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) # response = dialog.run() # if response == Gtk.ResponseType.OK: # path = dialog.get_filename() # # self.open_file.set_label("File Selected: %s" % os.path.basename(path)) # self.data = pd.read_csv(path) # elif response == Gtk.ResponseType.CANCEL: # print("Cancel clicked") # dialog.destroy() dialog = FileDialog(self) # dialog.show_all() response = dialog.run() if response == Gtk.ResponseType.OK: self.data = dialog.data dialog.destroy()
Example #18
Source File: configwindow.py From autokey with GNU General Public License v3.0 | 6 votes |
def on_new_topfolder(self, widget, data=None): dlg = Gtk.FileChooserDialog(_("Create New Folder"), self.ui) dlg.set_action(Gtk.FileChooserAction.CREATE_FOLDER) dlg.set_local_only(True) dlg.add_buttons(_("Use Default"), Gtk.ResponseType.NONE, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK) response = dlg.run() if response == Gtk.ResponseType.OK: path = dlg.get_filename() self.__createFolder(os.path.basename(path), None, path) self.app.monitor.add_watch(path) dlg.destroy() self.app.config_altered(True) elif response == Gtk.ResponseType.NONE: dlg.destroy() name = self.__getNewItemName("Folder") self.__createFolder(name, None) self.app.config_altered(True) else: dlg.destroy()
Example #19
Source File: FlatCAMApp.py From FlatCAM with MIT License | 6 votes |
def file_chooser_save_action(self, on_success): """ Opens the file chooser and runs on_success upon completion of valid file choice. :param on_success: A function to run upon selection of a filename. Takes 2 parameters: The instance of the application (App) and the chosen filename. This gets run immediately in the same thread. :return: None """ dialog = Gtk.FileChooserDialog("Save file", self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) dialog.set_current_name("Untitled") response = dialog.run() if response == Gtk.ResponseType.OK: filename = dialog.get_filename() dialog.destroy() on_success(self, filename) elif response == Gtk.ResponseType.CANCEL: self.info("Save cancelled.") # print("Cancel clicked") dialog.destroy()
Example #20
Source File: gnomecast.py From gnomecast with GNU General Public License v3.0 | 6 votes |
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 #21
Source File: modules.py From gpt with GNU General Public License v3.0 | 6 votes |
def on_choose_other_location_clicked(self, widget): win = FileChooserDialog() win.on_folder_clicked() app.obj("act_othloc").set_text(win.selectedfolder) app.obj("dir_content_info").set_text(cli.card_content(win.selectedfolder)) if cli.abs_size == 0: app.obj("import_other").set_sensitive(False) cli.show_message(_("No files here to import...")) elif cli.freespace(win.selectedfolder, cli.stdir): app.obj("import_other").set_sensitive(True) cli.cardpath = win.selectedfolder else: app.obj("import_other").set_sensitive(False) app.obj("nospace_info").set_text( _("Not enough disc space.\nFree at least {}.").format(cli.needspace)) # treeview table
Example #22
Source File: gnomecast.py From gnomecast with GNU General Public License v3.0 | 6 votes |
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 #23
Source File: main.py From badKarma with GNU General Public License v3.0 | 5 votes |
def open_file(self, widget): """ open a sqlite project file""" dialog = Gtk.FileChooserDialog("Please choose a file", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) file_filters.add_filter_database(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() try: self.engine = karmaEngine(session_file=file_selected) # update the hostlist self._clear_workspace() self._sync(reset=True) except Exception as e: print (e) elif response == Gtk.ResponseType.CANCEL: dialog.destroy() dialog.destroy()
Example #24
Source File: workspace.py From badKarma with GNU General Public License v3.0 | 5 votes |
def export_log(self, widget, log_id): # export a log in a txt file log = self.database.get_logs(log_id) text = log.output dialog = Gtk.FileChooserDialog("Please choose a filename", None, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) dialog.set_filename("export output") file_filters.add_filter_txt(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() try: file = open(file_selected,"w") for line in text: file.write(line) file.close() except: pass elif response == Gtk.ResponseType.CANCEL: dialog.destroy() dialog.destroy()
Example #25
Source File: backend_gtk3.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def get_filechooser(self): fc = FileChooserDialog( title='Save the figure', parent=self.win, path=os.path.expanduser(rcParams['savefig.directory']), filetypes=self.canvas.get_supported_filetypes(), default_filetype=self.canvas.get_default_filetype()) fc.set_current_name(self.canvas.get_default_filename()) return fc
Example #26
Source File: dialog.py From Dindo-Bot with MIT License | 5 votes |
def __init__(self, title, transient_for=None, filter=None): Gtk.FileChooserDialog.__init__(self, title=title, transient_for=transient_for, action=Gtk.FileChooserAction.OPEN) 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) self.add_button('_Cancel', Gtk.ResponseType.CANCEL) self.add_button('_Open', Gtk.ResponseType.OK) self.set_default_response(Gtk.ResponseType.OK)
Example #27
Source File: dialog.py From Dindo-Bot with MIT License | 5 votes |
def __init__(self, title, transient_for=None, filter=None): Gtk.FileChooserDialog.__init__(self, title=title, transient_for=transient_for, action=Gtk.FileChooserAction.SAVE) 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) self.add_button('_Cancel', Gtk.ResponseType.CANCEL) self.add_button('_Save', Gtk.ResponseType.OK) self.set_default_response(Gtk.ResponseType.OK)
Example #28
Source File: asktext.py From textext with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_file_cb(_, text_buffer): """ Present file chooser to select a source code file :param text_buffer: The target text buffer to show the loaded text in """ chooser = Gtk.FileChooserDialog('Open file...', None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) response = chooser.run() if response == Gtk.ResponseType.OK: filename = chooser.get_filename() if filename: AskTextGTKSource.open_file(text_buffer, filename) chooser.destroy()
Example #29
Source File: main.py From oomox with GNU General Public License v3.0 | 5 votes |
def import_themix_colors(self): self.ask_unsaved_changes() filechooser_dialog = Gtk.FileChooserDialog( _("Please choose a file with oomox colors"), self, Gtk.FileChooserAction.OPEN, ( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK ) ) filechooser_response = filechooser_dialog.run() if filechooser_response in ( Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT ): filechooser_dialog.destroy() return import_theme_path = filechooser_dialog.get_filename() filechooser_dialog.destroy() import_theme_name = os.path.basename(import_theme_path) while True: dialog = RenameDialog(transient_for=self, entry_text=import_theme_name) if not dialog_is_yes(dialog): return new_theme_name = dialog.entry_text if not self.ask_colorscheme_exists(new_theme_name): self.import_theme_from_path( path=import_theme_path, new_name=new_theme_name ) return
Example #30
Source File: FlatCAMApp.py From FlatCAM with MIT License | 5 votes |
def file_chooser_action(self, on_success): """ Opens the file chooser and runs on_success on a separate thread upon completion of valid file choice. :param on_success: A function to run upon completion of a valid file selection. Takes 2 parameters: The app instance and the filename. Note that it is run on a separate thread, therefore it must take the appropriate precautions when accessing shared resources. :type on_success: func :return: None """ dialog = Gtk.FileChooserDialog("Please choose a file", self.ui, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) response = dialog.run() # Works here # t = Gtk.TextView() # print t if response == Gtk.ResponseType.OK: filename = dialog.get_filename() dialog.destroy() # Send to worker. self.worker.add_task(on_success, [self, filename]) elif response == Gtk.ResponseType.CANCEL: self.info("Open cancelled.") dialog.destroy() # Works here # t = Gtk.TextView() # print t