Exemplo n.º 1
0
    def set_launch_at_startup(self, launch):
        defaults = NSUserDefaults.standardUserDefaults()
        lwdomain = defaults.persistentDomainForName_('loginwindow')
        lwdomain = Conversion.pythonCollectionFromPropertyList(lwdomain)
        if lwdomain is None:
            lwdomain = dict()
        if 'AutoLaunchedApplicationDictionary' not in lwdomain:
            lwdomain['AutoLaunchedApplicationDictionary'] = list()
        launchedApps = lwdomain['AutoLaunchedApplicationDictionary']
        ourPath = NSBundle.mainBundle().bundlePath()
        ourEntry = None
        for entry in launchedApps:
            if entry.get('Path') == ourPath:
                ourEntry = entry
                break

        if launch and ourEntry is None:
            launchInfo = dict(Path=ourPath, Hide=NO)
            launchedApps.append(launchInfo)
        elif ourEntry is not None:
            launchedApps.remove(ourEntry)

        lwdomain = Conversion.propertyListFromPythonCollection(lwdomain)
        defaults.setPersistentDomain_forName_(lwdomain, 'loginwindow')
        defaults.synchronize()
Exemplo n.º 2
0
    def set_launch_at_startup(self, launch):
        defaults = NSUserDefaults.standardUserDefaults()
        lwdomain = defaults.persistentDomainForName_('loginwindow')
        lwdomain = Conversion.pythonCollectionFromPropertyList(lwdomain)
        if lwdomain is None:
            lwdomain = dict()
        if 'AutoLaunchedApplicationDictionary' not in lwdomain:
            lwdomain['AutoLaunchedApplicationDictionary'] = list()
        launchedApps = lwdomain['AutoLaunchedApplicationDictionary']
        ourPath = NSBundle.mainBundle().bundlePath()
        ourEntry = None
        for entry in launchedApps:
            if entry.get('Path') == ourPath:
                ourEntry = entry
                break

        if launch and ourEntry is None:
            launchInfo = dict(Path=ourPath, Hide=NO)
            launchedApps.append(launchInfo)
        elif ourEntry is not None:
            launchedApps.remove(ourEntry)

        lwdomain = Conversion.propertyListFromPythonCollection(lwdomain)
        defaults.setPersistentDomain_forName_(lwdomain, 'loginwindow')
        defaults.synchronize()
Exemplo n.º 3
0
    def add_task(self, task):
        '''Add a new task to the remote'''
        print "Adding new task"

        properties = NSDictionary.dictionaryWithObjectsAndKeys_(
            task.name, 'name',
            Conversion.propertyListFromPythonCollection(task.lastModifiedDate),
            'modificationDate', 'Pending', 'tagNames', task.notes, 'notes')

        #         Conversion.propertyListFromPythonCollection(task.dueDate), 'dueDate',

        if task.dueDate is not None and type(task.dueDate) != str:
            destination_list = self.get_list("Upcoming")
            date_string = task.dueDate.strftime("%Y-%m-%d %H:%M:%S")
            print date_string
            date = NSDate.dateWithString_(date_string + " +0000")

            properties = NSDictionary.dictionaryWithObjectsAndKeys_(
                task.name, 'name',
                Conversion.propertyListFromPythonCollection(
                    task.lastModifiedDate), 'modificationDate', date,
                'dueDate', 'Pending', 'tagNames', task.notes, 'notes')
        else:
            destination_list = self.get_list(self.status_to_names.get(
                "Inbox"))  #todo send proper state enum

        todo = self._app.classForScriptingClass_(
            'to do').alloc().initWithProperties_(properties)

        destination_list.toDos().addObject_(todo)

        for destination_list in self.list_sources.values():
            todo = self.get_pending_task(destination_list)

            if todo:
                break

        return todo.id(), todo
Exemplo n.º 4
0
    def test_propertyListFromPythonCollection(self):
        for value, result_type in (
            ({
                "a": 42
            }, Cocoa.NSDictionary),
            ([42], Cocoa.NSArray),
            ((42, ), Cocoa.NSArray),
            ({42}, Cocoa.NSSet),
            (frozenset({42}), Cocoa.NSSet),
            (datetime.datetime.now(), Cocoa.NSDate),
            (datetime.date.today(), Cocoa.NSDate),
        ):

            with self.subTest(value):
                v = Conversion.propertyListFromPythonCollection(value)
                self.assertIsInstance(v, result_type)
                self.assertEqual(v, value)

        with self.subTest("decimal"):
            v = Conversion.propertyListFromPythonCollection(decimal.Decimal(1))
            self.assertIsInstance(v, Cocoa.NSDecimalNumber)

        with self.subTest("invalid dict"):
            with self.assertRaises(TypeError):
                Conversion.propertyListFromPythonCollection({42: 43})

        with self.subTest("unknown type"):
            with self.assertRaises(TypeError):
                Conversion.propertyListFromPythonCollection(dir)

        with self.subTest("conversion helper"):

            def helper(v):
                return str(v)

            v = Conversion.propertyListFromPythonCollection(dir, helper)
            self.assertEqual(v, str(dir))

        with self.subTest("nested conversion"):
            value = [{"a": 42}, {"b": [1]}, {()}]

            v = Conversion.propertyListFromPythonCollection(value)

            self.assertIsInstance(v[0], Cocoa.NSDictionary)
            self.assertIsInstance(v[1], Cocoa.NSDictionary)
            self.assertIsInstance(v[1]["b"], Cocoa.NSArray)
            self.assertIsInstance(v[2], Cocoa.NSSet)
            self.assertIsInstance(next(iter(v[2])), Cocoa.NSArray)
Exemplo n.º 5
0
def save(data):
    data = data.copy()
    try:
        for k, v in data.iteritems():
            if v is None:
                data[k] = ""
            elif k == prefs.MOVIES_DIRECTORY.key:
                if isinstance(v, str):
                    data[k] = filename_type_to_os_filename(v)

        plist = Conversion.propertyListFromPythonCollection(data)
    except:
        print "WARNING!! Error while converting the settings dictionary to a property list:"
        print data
        raise
    else:
        domain = bundle.getBundleIdentifier()
        defaults = NSUserDefaults.standardUserDefaults()
        defaults.setPersistentDomain_forName_(plist, domain)
        defaults.synchronize()
Exemplo n.º 6
0
def save(data):
    data = data.copy()
    try:
        for k, v in data.iteritems():
            if v is None:
                data[k] = ""
            elif k == prefs.MOVIES_DIRECTORY.key:
                if isinstance(v, str):
                    data[k] = filename_type_to_os_filename(v)

        plist = Conversion.propertyListFromPythonCollection(data)
    except:
        print "WARNING!! Error while converting the settings dictionary to a property list:"
        print data
        raise
    else:
        domain = bundle.getBundleIdentifier()
        defaults = NSUserDefaults.standardUserDefaults()
        defaults.setPersistentDomain_forName_(plist, domain)
        defaults.synchronize()
Exemplo n.º 7
0
def native_to_corefoundation(native):
    return Conversion.propertyListFromPythonCollection(native)