def OnRecoverWikiDatabase(self, evt): # if self.mainControl.stdDialog("yn", _(u"Continue?"), # _(u"You should run this function only if you know what you are doing\n" # "Continue?")) == "no": # return with wxHelper.TopLevelLocker: wf = wx.FileSelector(_("Wiki file"), "", wildcard="*.wiki", flags=wx.FD_OPEN, parent=self.mainControl) if not wf: return exportDest = wx.FileSelector(_("MPT export target file"), "", wildcard="*.mpt", flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, parent=self.mainControl) if not exportDest: return wikiDoc = WikiDocument.WikiDocument(wf, None, None, ignoreLock=True, createLock=False, recoveryMode=True) wikiDoc.connect() exp = Exporters.MultiPageTextExporter(self.mainControl) exp.recoveryExport(wikiDoc, exportDest, progressHandler=None)
def OnLoadFile(self, evt): file_name_1 = wx.FileSelector( "Reflections file 1", wildcard="Reflection files (*.mtz, *.sca, *.hkl)|*.mtz;*.sca;*.hkl", default_path="", flags=wx.OPEN) file_name_2 = wx.FileSelector( "Reflections file 2", wildcard="Reflection files (*.mtz, *.sca, *.hkl)|*.mtz;*.sca;*.hkl", default_path="", flags=wx.OPEN) self.load_files(file_name_1, file_name_2)
def OnSelectPath(self, evt): """ The "..." button after the "path or URL" field was pressed """ # # Build wildcard string # wcs = [] # for wd, wp in expDestWildcards: # wcs.append(wd) # wcs.append(wp) # # wcs.append(_(u"All files (*.*)")) # wcs.append(u"*") # # wcs = u"|".join(wcs) selfile = wx.FileSelector(_("Select wiki for favorites"), self.ctrls.tfPathOrUrl.GetValue(), default_filename="", default_extension="", wildcard="*.wiki", flags=wx.FD_OPEN, parent=self) if selfile: self.ctrls.tfPathOrUrl.SetValue(selfile)
def GetProgramPath(self, ID): programpath = wx.FileSelector() panel = ID.GetEventObject().GetParent() panel.programentry.SetValue(programpath)
def OnUpload(self, event): fname = wx.FileSelector("Choose file to upload") if os.path.exists(fname) and os.path.isfile(fname): title = wx.GetTextFromUser("Please enter document title", "Enter Document Title", "MyDocTitle") if title: self.node.UploadDoc(fname, self.frame.session, title=title) self.frame.RefreshNode(self.treeid, recursive=False)
def save_browse(self): config = wx.ConfigBase.Get() config.SetPath("/Scanning") use_meta4 = config.ReadBool("use_meta4_default", use_meta4_default) default_type = ".metalink" if use_meta4: default_type = ".meta4" if self.filename != "": default_path, default_name = os.path.split(self.filename) default_name = default_name.rsplit('.', 1)[0] default_name += default_type else: default_path, default_name = "", "" filename = wx.FileSelector( "Save as...", default_path, default_name, default_type, "All files (*.*)|*.*|Metalink4 files (*.meta4)|*.meta4|Metalink files (*.metalink)|*.metalink", wx.SAVE) if filename == "": return False else: if filename != self.filename: self.new_file = True self.filename = filename self.update() return True
def save_as_png(view): filename = wx.FileSelector('Save current view as', wildcard="PNG files(*.png)|*.png", flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if filename.strip(): view.GrabPNG(filename)
def load(self, event): file_name = wx.FileSelector('Open View-JSON file') if file_name: with open(file_name, 'r') as f: data = json.load(f) for view in data[self.JSON_LIST_NAME]: self.add_snapshot_to_list(VideoView.decode_json(view))
def BrowseProduct(self, filename=None): if filename is None: filename = wx.FileSelector("Browse Product File", default_path=wx.Config.Get().Read( 'DirectoryLocation/Products'), wildcard="All Files|*", flags=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, parent=self.frame) if filename: try: browser = ProductBrowser(self.frame, filename) except coda.CodacError as ex: message = wx.MessageDialog( self.frame, "Could not open product.\n\nCODA error message: \"%s\"" % str(ex), "CODA error", style=wx.OK | wx.ICON_ERROR | wx.STAY_ON_TOP) message.ShowModal() return browser.SetPosition( WindowHandler.GetNextPosition(browser.GetSize())) if wx.Config.Get().Read("IconFile"): browser.SetIcon(wx.Icon(wx.Config.Get().Read("IconFile"))) browser.Show() wx.Config.Get().Write('DirectoryLocation/Products', os.path.dirname(filename))
def OnScreenShot(self, event): file_name = wx.FileSelector(default_filename="xray.png", default_path="", wildcard="PNG image (*.png)|*.png", flags=wx.SAVE) if (file_name != ""): self.viewer.save_image(file_name)
def save_snapshot(canvas): #FIXME - This is the WRONG way to do pixel sizes - we should be using a value in nm # we also shouldn't be calling a static method of an unrelated class to do this. #pixel_size = float(VideoPanel.ask(canvas, message='Please enter the pixel size (1 pixel on the screen = x pixel ' # 'in the snapshot', default_value='1')) #dlg = wx.TextEntryDialog(canvas, "Snapshot pixel size", "Please enter the desired pixel size in the snapshot", "5") #if dlg.ShowModal() == wx.ID_OK: if True: #pixel_size = float(dlg.GetValue()) pixel_size=None #dlg.Destroy() file_name = wx.FileSelector('Save current view as', wildcard="PNG files(*.png)|*.png", flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if file_name: # snap = canvas.getIm(pixel_size, GL_LUMINANCE) snap = canvas.getIm(pixel_size, GL_RGB) print(snap.dtype, snap.shape, snap.max()) if snap.ndim == 3: img = PIL.Image.fromarray(snap.transpose(1, 0, 2)) #img = toimage(snap.transpose(1, 0, 2)) else: img = PIL.Image.fromarray(snap.transpose()) #img = toimage(snap.transpose()) img = img.transpose(PIL.Image.FLIP_TOP_BOTTOM) if not file_name.endswith('.png'): img.save('{}.png'.format(file_name)) else: img.save('{}'.format(file_name))
def handle_button_select(self, _): application_file_name = wx.FileSelector("Select application", wildcard='*.exe') self.application_ctrl.SetValue(application_file_name) current_extension = self.viewer_type_list_box.GetString( self.viewer_type_list_box.GetSelection()) self.extension_to_viewer[current_extension] = application_file_name
def OnSSLButton(self, event): """ Handle the Browse buttons for the SSL Client Certificate and the SSL CLient Key file fields """ # Define the File Type as *.pem files fileType = '*.pem' fileTypesString = _("SSL Certificate Files (*.pem)|*.pem|All files (*.*)|*.*") if event.GetId() == self.sslClientCertBrowse.GetId(): prompt = _("Select the SSL Client Certificate file") fileName = self.sslClientCert.GetValue() elif event.GetId() == self.sslClientKeyBrowse.GetId(): prompt = _("Select the SSL Client Key file") fileName = self.sslClientKey.GetValue() elif event.GetId() == self.sslMsgSrvCertBrowse.GetId(): prompt = _("Select the SSL Message Server Certificate file") fileName = self.sslMsgSrvCert.GetValue() (path, flnm) = os.path.split(fileName) if path != '': self.sslDir = path # Invoke the File Selector with the proper default directory, filename, file type, and style fs = wx.FileSelector(prompt, self.sslDir, fileName, fileType, fileTypesString, wx.OPEN | wx.FILE_MUST_EXIST) # If user didn't cancel .. if fs != "": # Mac Filenames use a different encoding system. We need to adjust the string returned by the FileSelector. # Surely there's an easier way, but I can't figure it out. if 'wxMac' in wx.PlatformInfo: import Misc fs = Misc.convertMacFilename(fs) if event.GetId() == self.sslClientCertBrowse.GetId(): self.sslClientCert.SetValue(fs) elif event.GetId() == self.sslClientKeyBrowse.GetId(): self.sslClientKey.SetValue(fs) elif event.GetId() == self.sslMsgSrvCertBrowse.GetId(): self.sslMsgSrvCert.SetValue(fs) (path, flnm) = os.path.split(fs) if path != '': self.sslDir = path
def OnShowInsertFileUrlDialog(self, evt): if self.mainControl.isReadOnlyPage(): return actEd = self.mainControl.getActiveEditor() if actEd is None: return with wxHelper.TopLevelLocker: path = wx.FileSelector(_(u"Choose a file to create URL for"), self.mainControl.getLastActiveDir(), wildcard="*.*", flags=wx.FD_OPEN, parent=self.mainControl) if path: url = StringOps.urlFromPathname(path) if path.endswith(".wiki"): url = "wiki:" + url else: # Absolute file: URL url = "file:" + url actEd.AddText(url) self.mainControl.getConfig().set("main", "last_active_dir", os.path.dirname(path))
def OnBLoadEmpiricalHistButton(self, event): fn = wx.FileSelector('Read point positions from file') if fn is None: print('No file selected') else: self.sim_controller.load_empirical_histogram(fn) self.stEmpiricalHist.SetLabel('File: %s' % fn)
def DoOpen(self, event): # Respond to the "Open" menu command. fileName = wx.FileSelector("Load File", default_extension=".fasta", flags = wx.OPEN | wx.FILE_MUST_EXIST) if fileName == "": return fileName = os.path.join(os.getcwd(), fileName) self.textSQ.write(open(fileName).read())
def OnLoadClassifier(self, event=None): from PYME.Analysis import svmSegment filename = wx.FileSelector("Load Classifier:", wildcard="*.pkl", flags=wx.FD_OPEN) if not filename == '': self.cf = svmSegment.svmClassifier(filename=filename)
def openkfcmd(event): fn = wx.FileSelector( "Open K file", wildcard="K file (*.kwn;*.kgc;*.kp2)|*.kwn;*.kgc;*.kp2", flags=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if fn.strip(): open_kfile(fn)
def OnLoadFile(self, evt): file_name = wx.FileSelector( "Reflections file", wildcard="Reflection files (*.mtz, *.sca, *.hkl)|*.mtz;*.sca;*.hkl", default_path=os.getcwd(), flags=wx.FD_OPEN) self.load_reflections_file(to_str(file_name))
def treeexportchunk(event): td = tree.GetItemData(treemenuitem) fn = wx.FileSelector("Export chunk data", flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if not fn.strip(): return with open(fn, 'wb') as f: f.write(td.data)
def AskIfUserWantsToSave(self, action): """ Give the user the opportunity to save the current document. 'action' is a string describing the action about to be taken. If the user wants to save the document, it is saved immediately. If the user cancels, we return False. """ response = wx.MessageBox("Save changes before " + action + "?", "Confirm", wx.YES_NO | wx.CANCEL, self) if response == wx.YES: if self.fileName == None: fileName = wx.FileSelector("Save File As", "Saving", default_extension="psk", wildcard="*.psk", flags=wx.SAVE | wx.OVERWRITE_PROMPT) if fileName == "": return False # User cancelled. self.fileName = fileName #self.SaveContents() return True elif response == wx.NO: return True # User doesn't want changes saved. elif response == wx.CANCEL: return False # User cancelled.
def treeimportchunk(event): td = tree.GetItemData(treemenuitem) fn = wx.FileSelector("Import chunk data", flags=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if not fn.strip(): return with open(fn, 'rb') as f: td.data = f.read()
def ApplyChange(self, event): global cfg # save config changes if (event is not None and event.GetId() == self.SAVEAS_COMMAND): filename = wx.FileSelector("Save As...", flags=wx.SAVE | wx.OVERWRITE_PROMPT) if (filename == ""): return else: self.targetFile = filename print("Changes Applied...") cfg.save_into_file_wbackup(self.targetFile) # deallocate del cfg #reinitialize cfg = cgWParams.GlideinParams('', '', ['', self.targetFile]) wx.MessageBox("Changes Applied.", "", wx.OK, self)
def ShowModal(self): """\ Show a FileDialog or a DirDialog as a modal dialog. The selected file or directory is stored in L{value} on success. @return: C{ID_OK} or C{ID_CANCEL} @see: L{get_value()} """ if self.parent.multiple_files == 0: self.value = wx.FileSelector(self.file_message, self.prev_dir, wildcard=self.wildcard, flags=self.file_style) # check for file extension and add default extension if missing if self.value and self.default_extension: ext = os.path.splitext(self.value)[1].lower() if not ext: self.value = "%s%s" % (self.value, self.default_extension) else: self.value = wx.DirSelector(self.dir_message, self.prev_dir, style=self.dir_style) if self.value: self.prev_dir = self.value if not os.path.isdir(self.prev_dir): self.prev_dir = os.path.dirname(self.prev_dir) return wx.ID_OK return wx.ID_CANCEL
def OnLoadSites (self, event) : from iotbx import file_reader wildcards = file_reader.get_wildcard_strings(["pdb"]) file_name = wx.FileSelector( wildcard=wildcards) if (file_name != "") : self.LoadFile(file_name)
def bufferSave(self): appname = wx.GetApp().GetAppName() default = appname + '-' + time.strftime("%Y%m%d-%H%M.py") filename = wx.FileSelector("Save File As", "Saving", default_filename=default, default_extension="py", wildcard="*.py", flags=wx.SAVE | wx.OVERWRITE_PROMPT) if not filename: return text = self.GetText() try: f = open(filename, 'w') f.write(text) f.close() except: # TODO: Find error type d = wx.MessageDialog(self, "Error saving session", "Error", wx.OK | wx.ICON_ERROR) d.ShowModal() d.Destroy()
def bufferSave(self): import time appname = wx.GetApp().GetAppName() default = appname + '-' + time.strftime("%Y%m%d-%H%M.py") fileName = wx.FileSelector("Save File As", "Saving", default_filename=default, default_extension="py", wildcard="*.py", flags=wx.SAVE | wx.OVERWRITE_PROMPT) if not fileName: return text = self.shell.GetText() ## This isn't working currently... ## d = wx.MessageDialog(self,u'Save source code only?\n' + \ ## 'Answering yes will only save lines starting with >>> and ...', ## u'Question', wx.YES_NO | wx.ICON_QUESTION) ## yes_no = d.ShowModal() ## if yes_no == wx.ID_YES: ## m = re.findall('^[>\.]{3,3} (.*)\r', text, re.MULTILINE | re.LOCALE) ## text = '\n'.join(m) ## d.Destroy() try: with open(fileName, "w") as f: f.write(text) except: d = wx.MessageDialog(self, 'Error saving session', 'Error', wx.OK | wx.ICON_ERROR) d.ShowModal() d.Destroy()
def on_open_selected(self, evt): path = wx.FileSelector(_("Select file"), wildcard=wildcard, flags=wx.OPEN | wx.FD_FILE_MUST_EXIST, parent=self) if path: self.open_file(path)
def open_surface(visFr): import wx # from PYME.experimental import triangle_mesh from PYME.experimental import _triangle_mesh as triangle_mesh from PYME.LMVis.layers.mesh import TriangleRenderLayer filename = wx.FileSelector( "Choose a file to open", default_extension='stl', wildcard='STL mesh (*.stl)|*.stl|PLY mesh (*.ply)|*.ply') #print filename if not filename == '': surf_count = 0 surf_name = 'surf%d' % surf_count while surf_name in visFr.pipeline.dataSources.keys(): surf_count += 1 surf_name = 'surf%d' % surf_count ext = filename.split('.')[-1] if ext == 'stl': visFr.pipeline.dataSources[ surf_name] = triangle_mesh.TriangleMesh.from_stl(filename) elif ext == 'ply': visFr.pipeline.dataSources[ surf_name] = triangle_mesh.TriangleMesh.from_ply(filename) else: raise ValueError('Invalid file extension .' + str(ext)) layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='shaded') visFr.add_layer(layer)
def makeSnapshot(self): """ Take a snapshot of our repository. Try to do a backup first. If that fails, take a full snapshot of the __repository__ directory instead. """ tarPath = wx.FileSelector(_(u"Save snapshot as..."), unicode(getDesktopDir(), sys.getfilesystemencoding()), _(u"ChandlerSnapshot.tgz"), u".tgz", u"*.tgz", flags=wx.SAVE | wx.OVERWRITE_PROMPT, parent=self) if not tarPath: return False # user canceled. repoDir = makeUncompressedBackup(Globals.options, masterPassword=True) archive = tarfile.open(tarPath, 'w:gz') archive.add(repoDir, '.') archive.add('version.py') for log in ('chandler.log', 'chandler.log.1', 'chandler.log.2', 'chandler.prefs'): logPath = os.path.join(Globals.options.profileDir, log) if os.path.isfile(logPath): archive.add(logPath, log) archive.close() return True