def _request_old(prompt, default_dir, file_types, dir, multiple): ns_panel = NSOpenPanel.openPanel() if prompt.endswith(":"): prompt = prompt[:-1] ns_panel.setTitle_(prompt) ns_panel.setCanChooseFiles_(not dir) ns_panel.setCanChooseDirectories_(dir) ns_panel.setAllowsMultipleSelection_(multiple) if default_dir: ns_dir = default_dir.path else: ns_dir = None if file_types: ns_types = [] for type in file_types: ns_types.extend(type._ns_file_types()) else: ns_types = None result = ns_panel.runModalForDirectory_file_types_(ns_dir, None, ns_types) if result == NSOKButton: if multiple: return [FileRef(path=path) for path in ns_panel.filenames()] else: return FileRef(path=ns_panel.filename()) else: return None
def _request_old(prompt, default_dir, file_types, dir, multiple): if prompt.endswith(":"): prompt = prompt[:-1] if dir: action = Gtk.FileChooserAction.SELECT_FOLDER else: action = Gtk.FileChooserAction.OPEN dlog = _FileDialog(title = prompt, action = action, ok_label = Gtk.STOCK_OPEN) dlog.set_select_multiple(multiple) if file_types: for file_type in file_types: dlog.add_file_type(file_type) if default_dir: dlog.set_current_folder(default_dir.path) if dlog.present_modally(): if multiple: result = [FileRef(path = path) for path in dlog.get_filenames()] else: result = FileRef(path = dlog.get_filename()) else: result = None dlog.destroy() return result
def _request_new(prompt, default_dir, default_name, file_type, dir): if dir: action = gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER else: action = gtk.FILE_CHOOSER_ACTION_SAVE if prompt.endswith(":"): prompt = prompt[:-1] dlog = _SaveFileDialog(title=prompt, action=action, ok_label=gtk.STOCK_SAVE) if file_type: dlog.add_file_type(file_type) if default_dir: dlog.set_current_folder(default_dir.path) if default_name: dlog.set_current_name(default_name) if dlog.present_modally(): path = dlog.get_filename() if file_type: path = file_type._add_suffix(path) result = FileRef(path=path) else: result = None dlog.destroy() return result
def fileref(path, file_type=None): if file_type: suffix = file_type.suffix if suffix: ext = "." + suffix if not path.endswith(suffix): path += ext return FileRef(path=path)
def _request_new(prompt, default_dir, default_name, file_type, dir): ns_panel = NSSavePanel.savePanel() #if prompt.endswith(":"): # prompt = prompt[:-1] #if prompt.lower().endswith(" as"): # prompt = prompt[:-3] #ns_panel.setTitle_(prompt) #print "_request_new: setting label to", repr(prompt) ### ns_panel.setNameFieldLabel_(prompt) if default_dir: ns_dir = default_dir.path else: ns_dir = None if file_type: suffix = file_type.suffix if suffix: ns_panel.setCanSelectHiddenExtension_(True) if not file_type.mac_type or file_type.mac_force_suffix: ns_panel.setRequiredFileType_(suffix) result = ns_panel.runModalForDirectory_file_(ns_dir, default_name) if result == NSOKButton: return FileRef(path=ns_panel.filename()) else: return None
def open_path(self, path): """Open document specified by a pathname. Called for each command line argument when the application is starting up.""" self.open_fileref(FileRef(path=path))