コード例 #1
0
ファイル: LogInit.py プロジェクト: dustin/loginit
	def addEntry_(self, sender):
		self.addCommand(Command("do something"))
		ds=self.table.dataSource()
		row=len(ds.cmds)-1
		indexes=NSIndexSet.indexSetWithIndex_(row)
		self.table.selectRowIndexes_byExtendingSelection_(indexes, False)
		self.table.editColumn_row_withEvent_select_(2, row, None, True)
コード例 #2
0
ファイル: preference.py プロジェクト: pombredanne/safety-bar
    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()
コード例 #3
0
 def removeSite(self):
     self.tableView.beginUpdates()
     self.tableView.removeRowsAtIndexes_withAnimation_(
         NSIndexSet.indexSetWithIndex_(self.tableView.selectedRow()),
         NSTableViewAnimationEffectFade)
     self.tableView.endUpdates()
     self.data.liste.pop(self.row)
コード例 #4
0
    def addContact_withDisplayName_(self, uri, display_name):
        BlinkLogger().log_info(u"Adding contact %s <%s>" % (display_name, uri))

        contact = self.owner.model.addContact(address=uri, display_name=display_name)
        self.owner.contactOutline.reloadData()
        row = self.owner.contactOutline.rowForItem_(contact)
        if row != NSNotFound:
            self.owner.contactOutline.selectRowIndexes_byExtendingSelection_(NSIndexSet.indexSetWithIndex_(row), False)
            self.owner.contactOutline.scrollRowToVisible_(row)
コード例 #5
0
    def refreshLibrary(self):
        if not self.history:
            return

        settings = SIPSimpleSettings()
        own_icon_path = settings.presence_state.icon
        selected_icon = None

        def md5sum(filename):
            md5 = hashlib.md5()
            with open(filename, 'rb') as f:
                for chunk in iter(lambda: f.read(128 * md5.block_size), b''):
                    md5.update(chunk)
            return md5.hexdigest()

        if os.path.exists(self.storage_folder):
            files = os.listdir(self.storage_folder)
        else:
            files = []
        array = NSMutableArray.array()
        knownFiles = set()
        for item in self.contentArrayController.arrangedObjects():
            knownFiles.add(str(item.objectForKey_("path")))

        seen_md5sum = {}
        i = 0
        for f in files:
            if not f.startswith('user_icon') and not f.startswith(
                    'photo') and f != 'default_user_icon.tiff':
                continue
            p = os.path.normpath(self.storage_folder + "/" + f)
            if p not in knownFiles:
                photos_folder = unicodedata.normalize('NFC',
                                                      self.storage_folder)
                filename = os.path.join(photos_folder, f)
                checksum = md5sum(filename)
                try:
                    seen_md5sum[filename]
                except KeyError:
                    seen_md5sum[filename] = checksum
                    image = NSImage.alloc().initWithContentsOfFile_(p)
                    if not image:
                        continue
                    item = NSDictionary.dictionaryWithObjectsAndKeys_(
                        image, "picture", p, "path")
                    array.addObject_(item)
                    if own_icon_path is not None and filename == str(
                            own_icon_path):
                        selected_icon = i
                    i += 1

        if array.count() > 0:
            self.contentArrayController.addObjects_(array)
            if selected_icon is not None:
                self.libraryCollectionView.setSelectionIndexes_(
                    NSIndexSet.indexSetWithIndex_(selected_icon))
コード例 #6
0
ファイル: ui_delegates.py プロジェクト: mgax/tinymail
    def setView_(self, table_view):
        self.table_view = table_view
        if table_view is None:
            return

        table_view.selectRowIndexes_byExtendingSelection_(
                NSIndexSet.new(), False)
        table_view.setDelegate_(self)
        table_view.setDataSource_(self)
        table_view.reloadData()
コード例 #7
0
 def _NH_BlinkConferenceContactPresenceHasChanged(self, notification):
     try:
         contact = next((contact for contact in self.contacts[2:] if contact == notification.sender))
     except StopIteration:
         return
     else:
         try:
             idx = self.contacts.index(contact)
             self.contactTable.reloadDataForRowIndexes_columnIndexes_(NSIndexSet.indexSetWithIndex_(idx), NSIndexSet.indexSetWithIndex_(0))
         except ValueError:
             pass
コード例 #8
0
    def addContact_withDisplayName_(self, uri, display_name):
        BlinkLogger().log_info("Adding contact %s <%s>" % (display_name, uri))

        contact = self.owner.model.addContact(uri=[(uri, 'sip')],
                                              name=display_name)
        self.owner.contactOutline.reloadData()
        row = self.owner.contactOutline.rowForItem_(contact)
        if row != NSNotFound:
            self.owner.contactOutline.selectRowIndexes_byExtendingSelection_(
                NSIndexSet.indexSetWithIndex_(row), False)
            self.owner.contactOutline.scrollRowToVisible_(row)
コード例 #9
0
 def _NH_BlinkConferenceContactPresenceHasChanged(self, notification):
     try:
         contact = (contact for contact in self.contacts[2:] if contact == notification.sender).next()
     except StopIteration:
         return
     else:
         try:
             idx = self.contacts.index(contact)
             self.contactTable.reloadDataForRowIndexes_columnIndexes_(NSIndexSet.indexSetWithIndex_(idx), NSIndexSet.indexSetWithIndex_(0))
         except ValueError:
             pass
コード例 #10
0
    def searchContacts_(self, sender):
        text = unicode(self.searchContactBox.stringValue().strip())
        contacts = [contact for contact in self.contacts[2:] if text in contact] if text else self.contacts[2:]
        self.contacts = [self.all_contacts, self.bonjour_contact] + contacts
        self.contactTable.reloadData()
        self.contactTable.selectRowIndexes_byExtendingSelection_(NSIndexSet.indexSetWithIndex_(0), False)
        self.contactTable.scrollRowToVisible_(0)
        self.updateContactsColumnHeader()

        if not text:
            self.refreshContacts()
コード例 #11
0
    def searchContacts_(self, sender):
        text = str(self.searchContactBox.stringValue().strip())
        contacts = [contact for contact in self.contacts[2:] if text in contact] if text else self.contacts[2:]
        self.contacts = [self.all_contacts, self.bonjour_contact] + contacts
        self.contactTable.reloadData()
        self.contactTable.selectRowIndexes_byExtendingSelection_(NSIndexSet.indexSetWithIndex_(0), False)
        self.contactTable.scrollRowToVisible_(0)
        self.updateContactsColumnHeader()

        if not text:
            self.refreshContacts()
コード例 #12
0
 def addSite(self):
     self.data.liste += [{
         "Name": "default",
         "ServerName": "",
         "DocumentRoot": "",
         "default": 0
     }]
     self.tableView.beginUpdates()
     self.tableView.insertRowsAtIndexes_withAnimation_(
         NSIndexSet.indexSetWithIndex_(len(self.data.liste) + 1),
         NSTableViewAnimationEffectFade)
     self.tableView.endUpdates()
コード例 #13
0
    def refreshLibrary(self):
        if not self.history:
            return

        settings = SIPSimpleSettings()
        own_icon_path = settings.presence_state.icon
        selected_icon = None
        def md5sum(filename):
            md5 = hashlib.md5()
            with open(filename,'rb') as f:
                for chunk in iter(lambda: f.read(128*md5.block_size), b''):
                    md5.update(chunk)
            return md5.hexdigest()

        if os.path.exists(self.storage_folder):
          files = os.listdir(self.storage_folder)
        else:
          files = []
        array = NSMutableArray.array()
        knownFiles = set()
        for item in self.contentArrayController.arrangedObjects():
            knownFiles.add(unicode(item.objectForKey_("path")))

        seen_md5sum = {}
        i = 0
        for f in files:
            if not f.startswith('user_icon') and not f.startswith('photo') and f != 'default_user_icon.tiff':
                continue
            p = os.path.normpath(self.storage_folder + "/" + f)
            if p not in knownFiles:
                photos_folder = unicodedata.normalize('NFC', self.storage_folder)
                filename = os.path.join(photos_folder, f)
                checksum = md5sum(filename)
                try:
                    seen_md5sum[filename]
                except KeyError:
                    seen_md5sum[filename] = checksum
                    image = NSImage.alloc().initWithContentsOfFile_(p)
                    if not image:
                        continue
                    item = NSDictionary.dictionaryWithObjectsAndKeys_(image, "picture", p, "path")
                    array.addObject_(item)
                    if own_icon_path is not None and filename == unicode(own_icon_path):
                        selected_icon = i
                    i += 1

        if array.count() > 0:
            self.contentArrayController.addObjects_(array)
            if selected_icon is not None:
                self.libraryCollectionView.setSelectionIndexes_(NSIndexSet.indexSetWithIndex_(selected_icon))
コード例 #14
0
    def awakeFromNib(self):
        # Instantiate the Data model
        self.data = Data()
        self.rowcount = len(self.data.liste)
        self.row = 0
        # tableView is an outlet set in Interface Builder
        self.tableView.setAutosaveName_("TableView")
        self.tableView.setAutosaveTableColumns_(1)
        self.tableView.setTarget_(self)
        self.tableView.setDoubleAction_("doubleClick:")
        self.tableView.window().setDelegate_(self)

        # select the first row by default
        index = NSIndexSet.indexSetWithIndex_(0)
        self.tableView.selectRowIndexes_byExtendingSelection_(index, False)
コード例 #15
0
ファイル: preference.py プロジェクト: pombredanne/safety-bar
    def _removeDirectory(self):
        '''
        Remove directory from settings
        '''
        if self.tableView.selectedRow() == -1:
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                "Error", "Confirm", None, None, "Please select a row first.")
            alert.runModal()
        else:
            self.tableView.beginUpdates()
            self.data['paths'].removeObjectAtIndex_(
                self.tableView.selectedRow())
            index = NSIndexSet.indexSetWithIndex_(self.tableView.selectedRow())
            self.tableView.removeRowsAtIndexes_withAnimation_(
                index, NSTableViewAnimationEffectFade)
            self.tableView.endUpdates()

            # Save to file
            self.saveSettings()
コード例 #16
0
 def _set_selected_row_num(self, x):
     ns_tableview = self._ns_inner_view
     s = NSIndexSet.indexSetWithIndex_(x)
     ns_tableview.selectRowIndexes_byExtendingSelection_(s, False)
コード例 #17
0
    def renderContacts(self, results):
        index = 0
        found_uris = []

        for item in self.contacts:
            item.destroy()

        getFirstContactMatchingURI = NSApp.delegate().contactsWindowController.getFirstContactMatchingURI

        self.contacts = [self.all_contacts, self.bonjour_contact]

        if self.search_uris:
            for uri in self.search_uris:
                found_contact = getFirstContactMatchingURI(uri, exact_match=True)
                if found_contact:
                    contact_exist = False
                    for contact_uri in found_contact.uris:
                        if contact_uri.uri in found_uris:
                            contact_exist = True
                            break
                    if contact_exist:
                        continue
                    contact = BlinkHistoryViewerContact(found_contact.uri, name=found_contact.name, icon=found_contact.icon)
                    for contact_uri in found_contact.uris:
                        found_uris.append(contact_uri.uri)
                    self.contacts.append(contact)
                    if isinstance(found_contact, BlinkPresenceContact):
                        contact.setPresenceContact_(found_contact)
                else:
                    if uri in found_uris:
                        continue
                    found_uris.append(uri)
                    contact = BlinkHistoryViewerContact(unicode(uri), name=unicode(uri))

                try:
                    index = self.contacts.index(contact)
                except ValueError:
                    pass

        if results:
            for row in results:
                found_contact = getFirstContactMatchingURI(row[0], exact_match=True)
                if found_contact:
                    contact_exist = False
                    for contact_uri in found_contact.uris:
                        if contact_uri.uri in found_uris:
                            contact_exist = True
                            break
                    if contact_exist:
                        continue
                    contact = BlinkHistoryViewerContact(found_contact.uri, name=found_contact.name, icon=found_contact.icon, presence_contact=found_contact if isinstance(found_contact, BlinkPresenceContact) else None)
                    for contact_uri in found_contact.uris:
                        found_uris.append(contact_uri.uri)
                else:
                    if row[0] in found_uris:
                        continue
                    found_uris.append(row[0])
                    contact = BlinkHistoryViewerContact(unicode(row[0]), name=unicode(row[0]))

                self.contacts.append(contact)

        self.contactTable.reloadData()

        self.contactTable.selectRowIndexes_byExtendingSelection_(NSIndexSet.indexSetWithIndex_(index), False)
        self.contactTable.scrollRowToVisible_(index)

        self.updateContactsColumnHeader()
コード例 #18
0
    def renderContacts(self, results):
        index = 0
        found_uris = []
        uris_without_display_name = []

        for item in self.contacts:
            item.destroy()

        getFirstContactMatchingURI = NSApp.delegate().contactsWindowController.getFirstContactMatchingURI

        self.contacts = [self.all_contacts, self.bonjour_contact]

        if self.search_uris:
            for uri in self.search_uris:
                try:
                    found_contact = self.contact_cache[uri]
                except KeyError:
                    found_contact = getFirstContactMatchingURI(uri, exact_match=True)
                    self.contact_cache[uri] = found_contact

                if found_contact:
                    contact_exist = False
                    for contact_uri in found_contact.uris:
                        if contact_uri.uri in found_uris:
                            contact_exist = True
                            break
                    if contact_exist:
                        continue
                    contact = BlinkHistoryViewerContact(found_contact.uri, name=found_contact.name, icon=found_contact.icon)
                    for contact_uri in found_contact.uris:
                        found_uris.append(contact_uri.uri)
                    self.contacts.append(contact)
                    if isinstance(found_contact, BlinkPresenceContact):
                        contact.setPresenceContact_(found_contact)
                else:
                    if uri in found_uris:
                        continue
                    found_uris.append(uri)
                    contact = BlinkHistoryViewerContact(str(uri), name=str(uri))

                try:
                    index = self.contacts.index(contact)
                except ValueError:
                    pass

        if results:
            for row in results:
                try:
                    found_contact = self.contact_cache[row[0]]
                except KeyError:
                    found_contact = getFirstContactMatchingURI(row[0], exact_match=True)
                    self.contact_cache[row[0]] = found_contact
                if found_contact:
                    contact_exist = False
                    for contact_uri in found_contact.uris:
                        if contact_uri.uri in found_uris:
                            contact_exist = True
                            break
                    if contact_exist:
                        continue
                    contact = BlinkHistoryViewerContact(found_contact.uri, name=found_contact.name, icon=found_contact.icon, presence_contact=found_contact if isinstance(found_contact, BlinkPresenceContact) else None)
                    for contact_uri in found_contact.uris:
                        found_uris.append(contact_uri.uri)
                else:
                    if row[0] in found_uris:
                        continue
                    found_uris.append(row[0])
                    try:
                        display_name = self.display_name_cache[row[0]]
                    except KeyError:
                        display_name = str(row[0])
                        uris_without_display_name.append(row[0])
                    contact = BlinkHistoryViewerContact(str(row[0]), name=display_name)

                self.contacts.append(contact)
    
        self.update_display_names(uris_without_display_name)
        self.contactTable.reloadData()

        self.contactTable.selectRowIndexes_byExtendingSelection_(NSIndexSet.indexSetWithIndex_(index), False)
        self.contactTable.scrollRowToVisible_(index)

        self.updateContactsColumnHeader()
        self.refresh_in_progress = False