コード例 #1
0
def test_objc_arr_adds_nil(array_without_nil, array_with_nil):
    a1 = objc_arr(*array_without_nil)
    a2 = objc_arr(*array_with_nil)
    assert a1.count() == a2.count() == len(array_without_nil)
    arr1 = [a1.objectAtIndex_(i).intValue() for i in range(a1.count())]
    arr2 = [a2.objectAtIndex_(i).intValue() for i in range(a2.count())]
    assert arr1 == arr2
コード例 #2
0
def test_objc_arr_behaviour(input_array):
    NSArray = lambda: autoclass('NSArray')
    a1 = NSArray().arrayWithObjects_(*input_array + [None])
    a2 = objc_arr(*input_array)
    arr1 = [a1.objectAtIndex_(i).intValue() for i in range(a1.count())]
    arr2 = [a2.objectAtIndex_(i).intValue() for i in range(a2.count())]
    assert arr1 == arr2
コード例 #3
0
    def run(self):
        panel = None
        if self.mode in ("open", "dir", "dir_and_files"):
            panel = NSOpenPanel.openPanel()

            panel.setCanChooseDirectories_(self.mode != "open")
            panel.setCanChooseFiles_(self.mode != "dir")

            if self.multiple:
                panel.setAllowsMultipleSelection_(True)
        elif self.mode == "save":
            panel = NSSavePanel.savePanel()
        else:
            assert False, self.mode

        panel.setCanCreateDirectories_(True)
        panel.setShowsHiddenFiles_(self.show_hidden)

        if self.title:
            panel.setTitle_(objc_str(self.title))

        # Mac OS X does not support wildcards unlike the other platforms.
        # This tries to convert wildcards to "extensions" when possible,
        # ans sets the panel to also allow other file types, just to be safe.
        if self.filters:
            filthies = []
            for f in self.filters:
                if type(f) == str:
                    f = (None, f)
                for s in f[1:]:
                    if not self.use_extensions:
                        if s.strip().endswith("*"):
                            continue
                    pystr = s.strip().split("*")[-1].split(".")[-1]
                    filthies.append(objc_str(pystr))

            ftypes_arr = objc_arr(*filthies)
            # todo: switch to allowedContentTypes
            panel.setAllowedFileTypes_(ftypes_arr)
            panel.setAllowsOtherFileTypes_(not self.use_extensions)

        if self.path:
            url = NSURL.fileURLWithPath_(self.path)
            panel.setDirectoryURL_(url)

        if panel.runModal():
            selection = None
            if self.mode == "save" or not self.multiple:
                selection = [panel.filename().UTF8String()]
            else:
                filename = panel.filenames()
                selection = [
                    filename.objectAtIndex_(x).UTF8String()
                    for x in range(filename.count())
                ]
            self._handle_selection(selection)
            return selection
        return None
コード例 #4
0
ファイル: filechooser.py プロジェクト: kivy/plyer
    def run(self):
        panel = None
        if self.mode in ("open", "dir"):
            panel = NSOpenPanel.openPanel()
        else:
            panel = NSSavePanel.savePanel()

        panel.setCanCreateDirectories_(True)

        panel.setCanChooseDirectories_(self.mode == "dir")
        panel.setCanChooseFiles_(self.mode != "dir")
        panel.setShowsHiddenFiles_(self.show_hidden)

        if self.title:
            panel.setTitle_(objc_str(self.title))

        if self.mode != "save" and self.multiple:
            panel.setAllowsMultipleSelection_(True)

        # Mac OS X does not support wildcards unlike the other platforms.
        # This tries to convert wildcards to "extensions" when possible,
        # ans sets the panel to also allow other file types, just to be safe.
        if len(self.filters) > 0:
            filthies = []
            for f in self.filters:
                if type(f) == str:
                    if not self.use_extensions:
                        if f.strip().endswith("*"):
                            continue
                        pystr = f.strip().split("*")[-1].split(".")[-1]
                    filthies.append(objc_str(pystr))
                else:
                    for _ in f[1:]:
                        if not self.use_extensions:
                            if f.strip().endswith("*"):
                                continue
                            pystr = f.strip().split("*")[-1].split(".")[-1]
                        filthies.append(objc_str(pystr))

            ftypes_arr = objc_arr(filthies)
            panel.setAllowedFileTypes_(ftypes_arr)
            panel.setAllowsOtherFileTypes_(not self.use_extensions)

        if self.path:
            url = NSURL.fileURLWithPath_(self.path)
            panel.setDirectoryURL_(url)

        if panel.runModal():
            selection = None
            if self.mode == "save" or not self.multiple:
                selection = [panel.filename().UTF8String()]
            else:
                selection = [i.UTF8String() for i in panel.filenames()]
            self._handle_selection(selection)
            return selection
        return None
コード例 #5
0
ファイル: filechooser.py プロジェクト: hcl91/plyer
    def run(self):
        panel = None
        if self.mode in ("open", "dir"):
            panel = NSOpenPanel.openPanel()
        else:
            panel = NSSavePanel.savePanel()

        panel.setCanCreateDirectories_(True)

        panel.setCanChooseDirectories_(self.mode == "dir")
        panel.setCanChooseFiles_(self.mode != "dir")
        panel.setShowsHiddenFiles_(self.show_hidden)

        if self.title:
            panel.setTitle_(objc_str(self.title))

        if self.mode != "save" and self.multiple:
            panel.setAllowsMultipleSelection_(True)

        # Mac OS X does not support wildcards unlike the other platforms.
        # This tries to convert wildcards to "extensions" when possible,
        # ans sets the panel to also allow other file types, just to be safe.
        if len(self.filters) > 0:
            filthies = []
            for f in self.filters:
                if type(f) == str:
                    if not self.use_extensions:
                        if f.strip().endswith("*"):
                            continue
                        pystr = f.strip().split("*")[-1].split(".")[-1]
                    filthies.append(objc_str(pystr))
                else:
                    for i in f[1:]:
                        if not self.use_extensions:
                            if f.strip().endswith("*"):
                                continue
                            pystr = f.strip().split("*")[-1].split(".")[-1]
                        filthies.append(objc_str(pystr))

            ftypes_arr = objc_arr(filthies)
            panel.setAllowedFileTypes_(ftypes_arr)
            panel.setAllowsOtherFileTypes_(not self.use_extensions)

        if self.path:
            url = NSURL.fileURLWithPath_(self.path)
            panel.setDirectoryURL_(url)

        if panel.runModal_():
            if self.mode == "save" or not self.multiple:
                return [panel.filename().UTF8String()]
            else:
                return [i.UTF8String() for i in panel.filenames()]
        return None
コード例 #6
0
ファイル: ble_peripheral.py プロジェクト: brvier/plyer
    def start_advertising(self, name):
        services = [
            iprop(s.service.UUID) for s in self.pending_services.values()
        ]
        servarray = objc_arr(*services) if services else None

        adv_dict = {CBAdvertisementDataKeys.LocalName: name}
        if servarray:
            adv_dict[CBAdvertisementDataKeys.ServiceUUIDs] = servarray
        data = objc_dict(adv_dict)

        self.peripheral.startAdvertising_(data)
        for service in self.pending_services.values():
            self.peripheral.addService_(service.service)
コード例 #7
0
ファイル: ble_peripheral.py プロジェクト: brvier/plyer
 def _add_characteristic(self, characteristic):
     chars = self.characteristics or {}
     chars[characteristic.characteristic] = characteristic
     characteristic.service = self
     self.characteristics = chars
     self.service.characteristics = objc_arr(*self.characteristics.keys())
コード例 #8
0
ファイル: test_literals.py プロジェクト: zendbit/pyobjus
 def test_array(self):
     self.assertEqual(objc_arr(objc_i(1), objc_i(2), objc_i(3)).count(), 3)
コード例 #9
0
ファイル: test_literals.py プロジェクト: Nesrider/pyobjus
 def test_array(self):
     self.assertEqual(objc_arr(objc_i(1), objc_i(2), objc_i(3)).count(), 3)