Beispiel #1
0
    def getListCard(self, content, datas):
        card = ListCard()
        #card.setContent(content)
        for data in datas:
            item = ListCardItem()
            item.set_title(data)
            # item.set_url("http://www.baidu.com")
            item.set_image(self.ICON_URL)
            #item.set_content(data)
            card.add_item(item)

        return card
Beispiel #2
0
        super(ListCard, self).__init__()
        self.data['type'] = 'list'

    def add_item(self, card_ietm):

        if isinstance(card_ietm, ListCardItem):

            if 'list' not in self.data:
                self.data['list'] = []
            self.data['list'].append(card_ietm.get_data())
        return self


if __name__ == '__main__':

    listCardItem1 = ListCardItem()
    listCardItem1.set_title('baidu')
    listCardItem1.set_url("http://www.baidu.com")
    listCardItem1.set_image("http://www.baidu.com")
    listCardItem1.set_content("http://www.baidu.com")

    print(id(listCardItem1))
    listCardItem2 = ListCardItem()
    listCardItem2.set_title("百度2")
    print(id(listCardItem2))

    listCardItem3 = ListCardItem()
    listCardItem3.set_title("百度3")
    print(id(listCardItem3))

    listCard = ListCard()
 def testAddItem(self):
     '''
     测试addItem方法
     :return:
     '''
     item = ListCardItem()
     item.set_title('title1')
     item.set_content('这是ListCardItem1')
     item.set_url('http://www.baidu.com')
     item.set_image('www.png1')
     item1 = ListCardItem()
     item1.set_title('title2')
     item1.set_content('这是ListCardItem2')
     item1.set_url('http://www.baidu.com')
     item1.set_image('www.png2')
     self.listCard.add_item(item)
     self.listCard.add_item(item1)
     card = {
         'type': 'list',
         'list': [
             {
                 'title': 'title1',
                 'content': '这是ListCardItem1',
                 'url': 'http://www.baidu.com',
                 'image': 'www.png1'
             },
             {
                 'title': 'title2',
                 'content': '这是ListCardItem2',
                 'url': 'http://www.baidu.com',
                 'image': 'www.png2'
             }
         ]
     }
     self.assertEqual(self.listCard.get_data(), card)
Beispiel #4
0
        super(ListCard, self).__init__()
        self.data['type'] = 'list'

    def addItem(self, listCardIetm):

        if isinstance(listCardIetm, ListCardItem):

            if not 'list' in self.data:
                self.data['list'] = []
            self.data['list'].append(listCardIetm.getData())
        return self


if __name__ == '__main__':

    listCardItem1 = ListCardItem()
    listCardItem1.setTitle('baidu')
    listCardItem1.setUrl("http://www.baidu.com")
    listCardItem1.setImage("http://www.baidu.com")
    listCardItem1.setContent("http://www.baidu.com")

    print(id(listCardItem1))
    listCardItem2 = ListCardItem()
    listCardItem2.setTitle("百度2")
    print(id(listCardItem2))

    listCardItem3 = ListCardItem()
    listCardItem3.setTitle("百度3")
    print(id(listCardItem3))

    listCard = ListCard()