Exemple #1
0
    def __init__(self):
        '''
        一些初始设置
        '''
        super().__init__()
        self.setWindowTitle('公众号:学点编程吧--QQ')
        self.setWindowFlags(Qt.Dialog)
        self.setMinimumSize(200, 600)
        self.setWhatsThis('这个一个模拟QQ软件')
        self.setWindowIcon(QIcon('./res/log.ico'))
        pListView = ListView()
        pListView.setViewMode(QListView.ListMode)
        # 设置模型

        pListView.setStyleSheet("QListView{icon-size:70px}")
        # 设置QListView图标的大小70像素

        dic_list = {'listview': pListView, 'groupname': "我的好友"}
        # 当前listview对象和分组名称放入到一个字典

        pListView.setListMap(dic_list)
        # 这个字典放入到map_listview这个列表

        self.addItem(pListView, "我的好友")
        self.show()
Exemple #2
0
    def addGroupSlot(self):
        '''
        增加分组
        '''
        groupname = QInputDialog.getText(self, "输入分组名", "")
        # groupname这里返回的是一个元组,其中第0个元素是分组名,第1个元素返回是否按了确定键

        if groupname[0] and groupname[1]:
            pListView1 = ListView()
            pListView1.setViewMode(QListView.ListMode)
            pListView1.setStyleSheet("QListView{icon-size:70px}")
            self.addItem(pListView1, groupname[0])
            dic_list = {'listview': pListView1, 'groupname': groupname[0]}
            pListView1.setListMap(dic_list)
            # 新建一个ListView对象并将其与分组名称添加到字典当中,然后通过setListMap()将这个字典放入到map_listview这个列表中

        elif groupname[0] == '' and groupname[1]:
            QMessageBox.warning(self, "警告", "我说你没有填写分组名哦~!")
Exemple #3
0
class ScrapyGUI(QMainWindow):
    def __init__(self):
        global ss, vgs, us, ts
        super().__init__()
        self.initUI()

        ss.ps.connect(self.search_user)
        vgs.ps.connect(self.start_user)
        us.ps.connect(self.run_user)

        ts.ps.connect(self.topic_finished)

    def initUI(self):
        self.statusBar().showMessage('准备就绪')
        self.setGeometry(100, 100, 800, 600)
        self.setWindowTitle('关注微信公众号:月小水长')
        self.setWindowIcon(QIcon('logo.jpg'))

        fpAct = QAction(QIcon('fp.png'), '找人(&FP)', self)
        fpAct.setShortcut('Ctrl+P')
        fpAct.setStatusTip('请输入微博用户昵称')
        fpAct.triggered.connect(self.findUser)

        fbAct = QAction(QIcon('fb.png'), '搜微博(&FB)', self)
        fbAct.setShortcut('Ctrl+B')
        fbAct.setStatusTip('请输入微博内容关键词')
        fbAct.triggered.connect(self.findTopic)

        menubar = self.menuBar()
        weiboMenu = menubar.addMenu('微博(&B)')
        weiboMenu.addAction(fpAct)
        weiboMenu.addSeparator()
        weiboMenu.addAction(fbAct)

        settingsMenu = menubar.addMenu('设置(&S)')

        aaAct = QAction(QIcon('aa.png'), '关于作者(&AA)', self)
        aaAct.setShortcut('Ctrl+A')
        aaAct.setStatusTip('产品作者的详细信息')
        aaAct.triggered.connect(self.aboutAuthor)

        aboutMenu = menubar.addMenu('关于(&A)')
        aboutMenu.addAction(aaAct)

        aboutMenu.addSeparator()

        oaAct = QAction(QIcon('oa.png'), '打开官网(&OA)', self)
        oaAct.setShortcut('Ctrl+O')
        oaAct.setStatusTip('打开产品官网')
        oaAct.triggered.connect(self.openAuthority)
        aboutMenu.addAction(oaAct)

        self.pListView = ListView(self)
        self.pListView.setViewMode(QListView.ListMode)
        self.pListView.setStyleSheet("QListView{icon-size:70px}")

        self.pListView.setGeometry(0, 20, 800, 560)

        self.show()

    def findUser(self):
        global filter
        group = QInputDialog.getText(self, "输入用户昵称", "")
        self.searchedUser = group[0]
        if (len(group[0]) > 0):
            self.pListView.clearData()
            WeiboSearchScrapy(keyword=group[0])

    def findTopic(self):
        dialog = MyDialog(self, info='主题')
        dialog.show()
        if (dialog.exec_() == QDialog.Accepted):
            print(dialog.getData())
            group = dialog.getData()
            topic = group[0]
            filter = 1 if group[1] == True else 0
            WeiboTopicScrapy(keyword=topic, filter=filter)
            QMessageBox.about(self, "提示",
                              "已成功将抓取【{}】主题的任务提交后台,结束会通知您".format(topic))

    def aboutAuthor(self):
        QMessageBox.about(self, "作者介绍",
                          "简介:985计算机本科在读\nQQ:2391527690\n微信公众号:月小水长")

    def openAuthority(self):
        webbrowser.open("https://inspurer.github.io/")

    def search_user(self, msg):
        print(msg)
        if msg == 'EOF':
            QMessageBox.about(self, '提示',
                              '【{}】相关的用户信息加载完毕'.format(self.searchedUser))
            return
        elif msg == 'NetError':
            QMessageBox.warning(self, '警告', '请先检查电脑联网情况')
            return
        data = json.loads(msg)
        self.pListView.addItem(data)
        self.show()

    # 监听窗口大小变化事件
    def resizeEvent(self, *args, **kwargs):
        w, h = self.width(), self.height()
        self.pListView.setGeometry(0, 20, w, h - 40)

    def start_user(self, msg):
        print('wwww', msg)
        res = QMessageBox.question(self, "提示", "只抓取原创微博吗?")
        if res == QMessageBox.Yes:
            WeiboUserScrapy(user_id=int(msg), filter=1)
        else:
            WeiboUserScrapy(user_id=int(msg), filter=0)

    def run_user(self, flag, value):
        print(flag, value)
        if flag == 'start':
            self.totalPageNum = value
            self.progress = QProgressDialog(self)
            self.progress.setWindowTitle("请稍等")
            self.progress.setLabelText("正在准备抓取...")
            '''
            如果任务的预期持续时间小于minimumDuration,则对话框根本不会出现。这样可以防止弹出对话框,快速完成任务。对于预期超过minimumDuration的任务,对话框将在minimumDuration时间之后或任何进度设置后立即弹出。
            如果设置为0,则只要设置任何进度,将始终显示对话框。 默认值为4000毫秒,即4秒。
            '''
            self.progress.setMinimumDuration(1)
            self.progress.setWindowModality(Qt.WindowModal)
            # 去掉取消按钮
            self.progress.setCancelButtonText(None)
            self.progress.setRange(0, self.totalPageNum)
            self.progress.setValue(1)
        if flag == 'run':
            self.progress.setValue(value)
            self.progress.setLabelText("正在抓取第{}/{}页".format(
                value, self.totalPageNum))

            if value == self.totalPageNum:
                self.progress.destroy()
                QMessageBox.about(self, "提示", "抓取结束")

    def topic_finished(self, msg):
        QMessageBox.about(self, "提示", msg)
        ...