Ejemplo n.º 1
0
 def run(self):
     self.panel = NSOpenPanel.alloc().init()
     if self.messageText:
         self.panel.setMessage_(self.messageText)
     if self.title:
         self.panel.setTitle_(self.title)
     if self.fileName:
         self.panel.setNameFieldLabel_(self.fileName)
     if self.directory:
         self.panel.setDirectoryURL_(NSURL.fileURLWithPath_(self.directory))
     if self.fileTypes:
         self.panel.setAllowedFileTypes_(self.fileTypes)
     self.panel.setCanChooseDirectories_(self.canChooseDirectories)
     self.panel.setCanChooseFiles_(self.canChooseFiles)
     self.panel.setAllowsMultipleSelection_(self.allowsMultipleSelection)
     self.panel.setResolvesAliases_(self.resolvesAliases)
     self.panel.setAccessoryView_(self.accessoryView)
     if self._parentWindow is not None:
         self.panel.beginSheetModalForWindow_completionHandler_(
             self._parentWindow, self.completionHandler_)
     else:
         isOK = self.panel.runModalForDirectory_file_types_(
             self.directory, self.fileName, self.fileTypes)
         if isOK == NSOKButton:
             self._result = self.panel.filenames()
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
 def webView_runOpenPanelForFileButtonWithResultListener_(
         self, sender, resultListener):
     panel = NSOpenPanel.openPanel()
     if panel.runModal() == NSFileHandlingPanelOKButton:
         resultListener.chooseFilename_(panel.filename())
     else:
         resultListener.cancel()
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
Ejemplo n.º 5
0
    def _addDirectory(self):
        '''
        Add directory to settings
        '''
        panel = NSOpenPanel.openPanel()
        panel.setCanChooseFiles_(False)
        panel.setCanChooseDirectories_(True)
        panel.setAllowsMultipleSelection_(True)
        if panel.runModal() == NSModalResponseOK:
            for url in panel.URLs():
                pred = NSPredicate.predicateWithFormat_(
                    "path == %@", url.path())
                if self.data['paths'].filteredArrayUsingPredicate_(
                        pred).count() > 0:
                    continue

                directory = Directory.alloc().init()
                directory.path = url.path()
                directory.enable = True
                directory.depth = 1

                self.tableView.beginUpdates()
                self.data['paths'].addObject_(directory)
                index = NSIndexSet.indexSetWithIndex_(
                    self.data['paths'].count() - 1)
                self.tableView.insertRowsAtIndexes_withAnimation_(
                    index, NSTableViewAnimationSlideUp)
                self.tableView.endUpdates()

                # Save to file
                self.saveSettings()
Ejemplo n.º 6
0
def dialog():
    from AppKit import NSApplication, NSAutoreleasePool, NSOpenPanel

    app = NSApplication.sharedApplication()
    assert app
    pool = NSAutoreleasePool.alloc().init()
    assert pool
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseFiles_(True)
    if panel.runModal():
        return panel.URL().path()
    return None
Ejemplo n.º 7
0
def dialog():
    from AppKit import NSApplication, NSAutoreleasePool, NSOpenPanel

    app = NSApplication.sharedApplication()
    assert app
    pool = NSAutoreleasePool.alloc().init()
    assert pool
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseFiles_(True)
    if panel.runModal():
        return panel.URL().path()
    return None
	def openDocument_(self, sender):
		openPanel = NSOpenPanel.openPanel()
		openPanel.setAllowsMultipleSelection_(False)
		openPanel.setCanChooseDirectories_(True)
		openPanel.setCanChooseFiles_(False)
		openPanel.runModalForTypes_(None)
		a =EYETestWindowController.testWindowController()
		a.showWindow_(sender)
		aw = a.window()
		if aw:
			aw.setTitle_(unicode(`openPanel.filenames()`[2:-2]))
		a._server=`openPanel.filenames()`[2:-2]
Ejemplo n.º 9
0
    def openOpenDocumentDialog(self):
        u"""
        Open document dialog.
        """
        self.closeStartDialog()

        panel = NSOpenPanel.openPanel()
        panel.setCanChooseDirectories_(False)
        panel.setCanChooseFiles_(True)
        panel.setAllowsMultipleSelection_(False)
        panel.setAllowedFileTypes_(['wf'])

        if panel.runModal() == NSOKButton:
            added, document = self.model.openDocument(panel.filenames()[0])
            self.initDocument(added, document)
Ejemplo n.º 10
0
    def _file_dialog_callback(self, message=None):
        try:
            panel = NSOpenPanel.openPanel()
            panel.setCanCreateDirectories_(True)
            panel.setCanChooseDirectories_(True)
            panel.setCanChooseFiles_(False)
            panel.setAllowsMultipleSelection_(False)

            if panel.runModal() == 1:
                for item in panel.URLs():
                    new_url = '/' + str(item).strip('file:/')
                    self.w.path.set(new_url)
                    return new_url
            else:
                pass
        except Exception as e:
            raise e
Ejemplo n.º 11
0
def _get_file_applepython():
    "NOT_RPYTHON"
    from AppKit import NSOpenPanel, NSOKButton
    panel = NSOpenPanel.openPanel()
    panel.setTitle_("Select a Squeak image file to open")
    panel.setFloatingPanel_(True)
    panel.setOneShot_(True)
    panel.setReleasedWhenClosed_(True)
    panel.setAllowedFileTypes_(["image"])
    panel.center()
    if (panel.runModal() == NSOKButton):
        urls = panel.URLs()
        if (urls.count() ==  1):
            path = urls.objectAtIndex_(0).path()
            try:
                return path.encode('utf_8', 'ignore')
            except ValueError:
                pass
    return "SqueakImage.imgae"
Ejemplo n.º 12
0
 def run(self):
     panel = NSOpenPanel.alloc().init()
     if self.messageText:
         panel.setMessage_(self.messageText)
     if self.title:
         panel.setTitle_(self.title)
     if self.directory:
         panel.setDirectory_(self.directory)
     if self.fileTypes:
         panel.setAllowedFileTypes_(self.fileTypes)
     panel.setCanChooseDirectories_(self.canChooseDirectories)
     panel.setCanChooseFiles_(self.canChooseFiles)
     panel.setAllowsMultipleSelection_(self.allowsMultipleSelection)
     panel.setResolvesAliases_(self.resolvesAliases)
     if self._parentWindow is not None:
         panel.beginSheetForDirectory_file_types_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
                 self.directory, self.fileName, self.fileTypes, self._parentWindow, self, "openPanelDidEnd:returnCode:contextInfo:", 0)
     else:
         isOK = panel.runModalForDirectory_file_types_(self.directory, self.fileName, self.fileTypes)
         if isOK == NSOKButton:
             self._result = panel.filenames()
Ejemplo n.º 13
0
def darwin_open_dialog(window, title, directory):
    # http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/AppFileMgmt/Concepts/SaveOpenPanels.html#//apple_ref/doc/uid/20000771-BBCFDGFC
    # http://scottr.org/blog/2008/jul/04/building-cocoa-guis-python-pyobjc-part-four/
    from objc import NO
    from AppKit import NSOpenPanel
    from translate.storage import factory
    from locale import strcoll
    file_types = []
    _sorted = sorted(factory.supported_files(), cmp=strcoll, key=lambda x: x[0])
    for name, extension, mimetype in _sorted:
        file_types.extend(extension)
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseDirectories_(NO)
    panel.setTitle_(title or _("Choose a Translation File"))
    panel.setAllowsMultipleSelection_(NO)
    panel.setAllowedFileTypes_(file_types)
    panel.setDirectoryURL_(u"file:///%s" % directory)
    ret_value = panel.runModalForTypes_(file_types)
    if ret_value:
        return (panel.filenames()[0], panel.URLs()[0].absoluteString())
    else:
        return ()
Ejemplo n.º 14
0
def darwin_open_dialog(window, title, directory):
    # http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/AppFileMgmt/Concepts/SaveOpenPanels.html#//apple_ref/doc/uid/20000771-BBCFDGFC
    # http://scottr.org/blog/2008/jul/04/building-cocoa-guis-python-pyobjc-part-four/
    from objc import NO
    from AppKit import NSOpenPanel
    from translate.storage import factory
    from locale import strcoll
    file_types = []
    _sorted = sorted(factory.supported_files(),
                     cmp=strcoll,
                     key=lambda x: x[0])
    for name, extension, mimetype in _sorted:
        file_types.extend(extension)
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseDirectories_(NO)
    panel.setTitle_(title or _("Choose a Translation File"))
    panel.setAllowsMultipleSelection_(NO)
    panel.setAllowedFileTypes_(file_types)
    panel.setDirectoryURL_(u"file:///%s" % directory)
    ret_value = panel.runModalForTypes_(file_types)
    if ret_value:
        return (panel.filenames()[0], panel.URLs()[0].absoluteString())
    else:
        return ()
Ejemplo n.º 15
0
 def run(self):
     panel = NSOpenPanel.alloc().init()
     if self.messageText:
         panel.setMessage_(self.messageText)
     if self.title:
         panel.setTitle_(self.title)
     if self.directory:
         panel.setDirectory_(self.directory)
     if self.fileTypes:
         panel.setAllowedFileTypes_(self.fileTypes)
     panel.setCanChooseDirectories_(self.canChooseDirectories)
     panel.setCanChooseFiles_(self.canChooseFiles)
     panel.setAllowsMultipleSelection_(self.allowsMultipleSelection)
     panel.setResolvesAliases_(self.resolvesAliases)
     if self._parentWindow is not None:
         panel.beginSheetForDirectory_file_types_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
             self.directory, self.fileName, self.fileTypes,
             self._parentWindow, self,
             "openPanelDidEnd:returnCode:contextInfo:", 0)
     else:
         isOK = panel.runModalForDirectory_file_types_(
             self.directory, self.fileName, self.fileTypes)
         if isOK == NSOKButton:
             self._result = panel.filenames()
Ejemplo n.º 16
0
 def webView_runOpenPanelForFileButtonWithResultListener_(self, sender, resultListener):
     panel = NSOpenPanel.openPanel()
     if panel.runModal() == NSFileHandlingPanelOKButton:
         resultListener.chooseFilename_(panel.filename())
     else:
         resultListener.cancel()