Пример #1
0
 def showContacts(self, contacts):
     if contacts is not None:
         for c in contacts:
             contact_model = ContactModel()
             contact_model.setAllFields(c[0], c[1], c[2], c[3], c[4], c[5],
                                        c[6])
             c_button = ContactButton(contact_model, self)
             self.view.buttonListLayout.setAlignment(Qt.AlignTop)
             self.view.buttonListLayout.addWidget(c_button)
Пример #2
0
    def showFields(self):
        contact_model = ContactModel()
        contact_fields = contact_model.getContactFields()

        self.field_list = list()
        self.field_list.append([contact_fields[1], "First Name"])
        self.field_list.append([contact_fields[2], "Last Name"])

        for field in self.field_list:
            self.view.orderby.addItem(field[1])
    def addContact(self):
        first_name = self.view.first_name.text()
        last_name = self.view.last_name.text()
        telephone = self.view.telephone.text()
        email = self.view.email.text()
        url = self.view.url.text()
        notes = self.view.notes.toPlainText()

        # check for minimum data required
        if ((first_name is not None and first_name != "")
                or (last_name is not None and last_name != "")
                and telephone is not None and telephone != ""):
            new_contact = ContactModel()
            new_contact.setFields(first_name, last_name, telephone, email, url,
                                  notes)
            new_contact.addContact()

            # get the contact id from Contacts table in "ContactsManager.db".
            c_id = new_contact.getContactIdFromNameTel()

            # select checked tags and add the info in ContactsTags table as a tuple (c_id, t_id)
            tags = self.view.scrollAreaWidgetContents.layout()
            items = (tags.itemAt(i).widget() for i in range(tags.count()))
            for i in items:
                if i.isChecked():
                    # print("checked", i)
                    tag_model = TagModel()
                    tag_id = tag_model.getTagIdfromName(i.text())
                    contact_tag_model = ContactTagModel()
                    contact_tag_model.setContactId(c_id)
                    contact_tag_model.setTagId(tag_id)
                    contact_tag_model.addContactTag()
        self.showContactList()
    def asyncUpdateContact(self):
        v = self.view
        c_id = self.contact.c_id
        first_name = v.first_name.text()
        last_name = v.last_name.text()
        tel = v.telephone.text()
        email = v.email.text()
        url = v.url.text()
        notes = v.notes.toPlainText()

        if (first_name != "" and first_name is not None and last_name != ""
                and last_name is not None):
            modified_contact = ContactModel()
            modified_contact.setFields(first_name, last_name, tel, email, url,
                                       notes)
            modified_contact.updateContact(c_id)

            tag_contact_model = ContactTagModel()
            tag_contact_model.setContactId(c_id)

            tag_contact_model.deleteContactTagsFromId()

            tags = v.scrollAreaWidgetContents.layout()

            items = (tags.itemAt(i).widget() for i in range(tags.count()))
            # select checked tags and add the info in ContactsTags table as a tuple (c_id, t_id)
            for i in items:
                if i.isChecked():
                    tag_model = TagModel()
                    tag_id = tag_model.getTagIdfromName(i.text())
                    contact_tag_model = ContactTagModel()
                    contact_tag_model.setContactId(c_id)
                    contact_tag_model.setTagId(tag_id)
                    contact_tag_model.addContactTag()
Пример #5
0
    def realTimeSearch(self):
        # contact_model = ContactModel()
        # print("inputchanged")

        text_to_search = self.view.searchbar.toPlainText()
        # convert orderby selection into db exact field
        orderby = next(x[0] for x in self.field_list
                       if x[1] == self.view.orderby.currentText())
        if self.view.scroll_tag.currentText() != "Select a tag...":
            selected_tag = self.view.scroll_tag.currentText()
        else:
            selected_tag = None
        # clear contactList
        for i in reversed(range(self.view.buttonListLayout.count())):
            self.view.buttonListLayout.itemAt(i).widget().setParent(None)
        # print("selected tag", selected_tag)
        # print("order by", orderby)
        contacts = ContactModel().contactSearch(text_to_search, orderby,
                                                selected_tag)

        self.showContacts(contacts)
    def deleteContact(self):
        v = self.view
        first_name = v.first_name.text()
        last_name = v.last_name.text()
        telephone = v.telephone.text()
        email = v.email.text()
        url = v.url.text()
        notes = v.notes.toPlainText()

        # delete this contact from Contacts table
        contact_to_delete = ContactModel()
        c_id = self.contact.getId()
        contact_to_delete.setAllFields(c_id, first_name, last_name, telephone,
                                       email, url, notes)
        contact_to_delete.deleteContact()

        # delete tuples (c_id, t_id) from ContactsTags table
        contact_tag = ContactTagModel()
        contact_tag.setContactId(c_id)
        contact_tag.deleteContactTagsFromId()

        self.showContactList()
Пример #7
0
        for t in current_tags:
            tag = QLabel()
            tag.setText(t)
            self.view.scrollAreaWidgetContents.layout().addWidget(tag)

    # change view from ContactViewer to ContactList
    def showContactList(self):
        self.parentWidget().setCentralWidget(cl.ContactList())

    # change view from ContactViewer to ContactEditor
    def showContactEditor(self):
        self.parentWidget().setCentralWidget(ce.ContactEditor(self.contact))


if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    window = QMainWindow()
    # Prova
    a = ContactModel()
    a.setFirstName("ale")
    a.setLastName("alfa")
    a.setTelephone("00555")
    ###
    ca = ContactViewer(a)
    window.setCentralWidget(ca)
    window.show()
    sys.exit(app.exec_())


    def showContactViewer(self):
        up_contact = ContactModel()
        up_contact.getContactFromId_v2(self.contact.c_id)

        self.parentWidget().setCentralWidget(cv.ContactViewer(up_contact))