我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用gtk.FILE_CHOOSER_ACTION_OPEN。
def on_open_clicked(widget, window, box): dialog=gtk.FileChooserDialog(title="?? Flash ??", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) swf_filter=gtk.FileFilter() swf_filter.set_name("Flash ??(*.swf)") swf_filter.add_pattern("*.[Ss][Ww][Ff]") dialog.add_filter(swf_filter) response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() dialog.destroy() window.remove(box) play_args = pre_play(filename) display_html(window, play_args) dialog.destroy()
def importFile(self, *args): fn = gtk.FileChooserDialog(title="Import File", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) _filter = gtk.FileFilter() _filter.set_name("C++ Files") _filter.add_pattern("*.cpp") _filter.add_pattern("*.h") fn.add_filter(_filter) _filter = gtk.FileFilter() _filter.set_name("All Files") _filter.add_pattern("*") fn.add_filter(_filter) fn.show() resp = fn.run() if resp == gtk.RESPONSE_OK: text = open(fn.get_filename()).read() self.addNotebookPage(os.path.basename(fn.get_filename()), text) fn.destroy()
def on_open(self, action): chooser = gtk.FileChooserDialog(title="Open dot File", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_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.RESPONSE_OK: filename = chooser.get_filename() self.last_open_dir = chooser.get_current_folder() chooser.destroy() self.open_file(filename) else: chooser.destroy()
def keep_list_dialog(self, w): chooser = gtk.FileChooserDialog('Open..', None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_select_multiple(True) chooser.set_default_response(gtk.RESPONSE_OK) chooser.set_size_request(640,480) filter = gtk.FileFilter() filter.set_name("All Files") filter.add_pattern("*") chooser.add_filter(filter) response = chooser.run() if response == gtk.RESPONSE_OK: self.keep_list = chooser.get_filenames() chooser.destroy() if self.keep_list is not None: Thread(target=self._announce_keep_list).start()
def action_loadCfg(self, *arg) : filechooserdialog = gtk.FileChooserDialog(_("Open a cfg file"), None, \ gtk.FILE_CHOOSER_ACTION_OPEN, \ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) try: filt = gtk.FileFilter() filt.set_name(_("Config files")) filt.add_mime_type("text/xml") filt.add_pattern("*.cfg") filechooserdialog.add_filter(filt) filechooserdialog.set_current_folder(os.path.join(NCAM_DIR, CUSTOM_DIR)) filechooserdialog.set_keep_above(True) filechooserdialog.set_transient_for(self.get_toplevel()) if filechooserdialog.run() == gtk.RESPONSE_OK: self.add_feature(None, filechooserdialog.get_filename()) finally : filechooserdialog.destroy()
def on_open(self, action): chooser = gtk.FileChooserDialog(title="Open dot File", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) 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.RESPONSE_OK: filename = chooser.get_filename() chooser.destroy() self.open_file(filename) else: chooser.destroy()
def openFile(self, *args): if (not self.getModified()) or self.ask("There are unsaved files.\nContinue?"): fn = gtk.FileChooserDialog(title="Save File", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) _filter = gtk.FileFilter() _filter.set_name("Micro:Pi Files") _filter.add_pattern("*.%s" % SETTINGS['fileExtention']) fn.add_filter(_filter) _filter = gtk.FileFilter() _filter.set_name("All Files") _filter.add_pattern("*") fn.add_filter(_filter) fn.show() resp = fn.run() if resp == gtk.RESPONSE_OK: try: #text = open(fn.get_filename()).read() #try: #d = text.replace("\n", "") #d = base64.b64decode(d) #data = pickle.loads(d) #except: #data = pickle.loads(text) data = self.loadFilesFromFile(fn.get_filename()) mw = MainWin(data) yes = True mw.saveLocation = fn.get_filename() mw.setSaved() OPENWINDOWS.append(mw) except Exception as e: yes = False fn.destroy() if resp == gtk.RESPONSE_OK and not yes: self.message("File is not a Micro:Pi File")
def setup_gui_url_chooser(self): d = hildon.FileChooserDialog(self.parent_win, gtk.FILE_CHOOSER_ACTION_OPEN) self.gui_url_chooser = d # setup_gui_url_chooser()
def openFile(self, widget=None, default=False): """Reads from a config file. If default=True, open the tint2 default config.""" self.new() if not default: chooser = gtk.FileChooserDialog("Open Config File", self, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) if self.curDir != None: chooser.set_current_folder(self.curDir) chooserFilter = gtk.FileFilter() chooserFilter.set_name("All files") chooserFilter.add_pattern("*") chooser.add_filter(chooserFilter) chooser.show() response = chooser.run() if response == gtk.RESPONSE_OK: self.filename = chooser.get_filename() self.curDir = os.path.dirname(self.filename) else: chooser.destroy() return chooser.destroy() else: self.filename = os.path.expandvars("$HOME/.config/tint2/tint2rc") self.curDir = os.path.expandvars("$HOME/.config/tint2") self.readTint2Config() self.generateConfig() self.updateStatusBar()
def action_importXML(self, *arg) : filechooserdialog = gtk.FileChooserDialog(_("Import project"), None, \ gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, \ gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) try: filt = gtk.FileFilter() filt.set_name(_("NativeCAM projects")) filt.add_mime_type("text/xml") filt.add_pattern("*.xml") filechooserdialog.add_filter(filt) filt = gtk.FileFilter() filt.set_name(_("All files")) filt.add_pattern("*") filechooserdialog.add_filter(filt) filechooserdialog.set_current_folder(os.path.join(NCAM_DIR, CATALOGS_DIR, self.catalog_dir, PROJECTS_DIR)) filechooserdialog.set_keep_above(True) filechooserdialog.set_transient_for(self.get_toplevel()) if filechooserdialog.run() == gtk.RESPONSE_OK: fname = filechooserdialog.get_filename() try : xml = self.update_features(etree.parse(fname).getroot()) self.import_xml(xml) self.file_changed = True except etree.ParseError as err : mess_dlg(err, _("Import project")) finally: filechooserdialog.destroy() # will update with new features version and keep the previous values
def change_poster_select_file(self, number, handler = update_image): filename = gutils.file_chooser(_("Select image"), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK), name='', folder=self.locations['desktop'], picture=True) if filename and filename[0]: filename = filename[0].decode('UTF-8') if handler: return handler(self, number, filename) return False
def cover_image(self,number): filename = gutils.file_chooser(_("Select image"), \ action=gtk.FILE_CHOOSER_ACTION_OPEN, \ buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, \ gtk.STOCK_OPEN, gtk.RESPONSE_OK)) if filename[0]: cover_image_process(self, filename[0], number)
def on_btnBrowse_clicked(self, widget, *args): global wMain filename = show_open_dialog(parent=wMain.wMain, title=_("Abrir"), action=gtk.FILE_CHOOSER_ACTION_OPEN) if filename != None: self.txtPrivateKey.set_text(filename) #-- Whost.on_btnBrowse_clicked }
def gui_open_file(self, start_dir=None, types=[]): """Prompt the user to pick a file to open""" import gtk if not start_dir: start_dir = self._last_dir dlg = gtk.FileChooserDialog("Select a file to open", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) if start_dir and os.path.isdir(start_dir): dlg.set_current_folder(start_dir) for desc, spec in types: ff = gtk.FileFilter() ff.set_name(desc) ff.add_pattern(spec) dlg.add_filter(ff) res = dlg.run() fname = dlg.get_filename() dlg.destroy() if res == gtk.RESPONSE_OK: self._last_dir = os.path.dirname(fname) return fname else: return None
def action_open_project(self, *arg): global CURRENT_PROJECT if arg[1][0] == 0 : # user project dlg_title = _("Open project") flt_name = _("NativeCAM projects") dir_ = os.path.join(NCAM_DIR, CATALOGS_DIR, self.catalog_dir, PROJECTS_DIR) else : # example dlg_title = _("Open example project") flt_name = _("NativeCAM example projects") dir_ = os.path.join(NCAM_DIR, CATALOGS_DIR, self.catalog_dir, PROJECTS_DIR, EXAMPLES_DIR) filechooserdialog = gtk.FileChooserDialog(dlg_title, None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, \ gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) try: filt = gtk.FileFilter() filt.set_name(flt_name) if arg[1][0] == 0 : filt.add_mime_type("text/xml") filt.add_pattern("*.xml") else : filt.add_pattern("*.*") filechooserdialog.add_filter(filt) filechooserdialog.set_current_folder(dir_) filechooserdialog.set_keep_above(True) filechooserdialog.set_transient_for(self.get_toplevel()) if filechooserdialog.run() == gtk.RESPONSE_OK: filename = filechooserdialog.get_filename() src_data = open(filename).read() if src_data.find(XML_TAG) != 1 : subprocess.call(["xdg-open '%s'" % filename], shell = True) else : xml = etree.fromstring(src_data) xml = self.update_features(xml) self.treestore_from_xml(xml) self.expand_and_select(self.path_to_old_selected) self.clear_undo() CURRENT_PROJECT = filename self.file_changed = False self.action(xml) finally: self.display_proj_name() filechooserdialog.destroy()
def on_importar_servidores1_activate(self, widget, *args): filename = show_open_dialog(parent=self.wMain, title=_("Abrir"), action=gtk.FILE_CHOOSER_ACTION_OPEN) if filename != None: password = inputbox(_('Importar Servidores'), _('Ingrese clave: '), password=True) if password == None: return #abrir archivo con lista de servers y cargarlos en el arbol try: cp= ConfigParser.RawConfigParser( ) cp.read( filename ) #validar el pass s = decrypt(password, cp.get("gcm", "gcm")) if (s != password[::-1]): msgbox(_("Clave invalida")) return if msgconfirm(_(u'Se sobreescribirá la lista de servidores, continuar?')) != gtk.RESPONSE_OK: return grupos={} for section in cp.sections(): if not section.startswith("host "): continue host = HostUtils.load_host_from_ini(cp, section, password) if not grupos.has_key(host.group): grupos[host.group]=[] grupos[host.group].append( host ) except: msgbox(_("Archivo invalido")) return #sobreescribir lista de hosts global groups groups=grupos self.updateTree() #-- Wmain.on_importar_servidores1_activate } #-- Wmain.on_exportar_servidores1_activate {