Example #1
0
    def onClicked_AccountGroup(self, account):
        def getUserInfo(account):
            try:
                if account.plugin.service == 'all_accounts':
                    user_info = {
                        'screen_name': '所有账户',
                        'followers_count': 'x',
                        'friends_count': 'x',
                        'statuses_count': 'x'
                    }
                    avatar = constant.ALL_ACCOUNTS_AVATAR
                else:
                    user_info = account.getUserInfo(account.plugin.uid)
                    avatar = account.avatar_manager.get(
                        user_info['avatar_large'])
                return (avatar, user_info)
            except Exception as e:
                return (None, {
                    'error': str(e),
                    'service': account.plugin.service
                })

        def updateUI(avatar, user_info):
            if 'error' in user_info:
                QMessageBox.critical(None, user_info['service'],
                                     user_info['error'])
            else:
                self.updateUserInfo(avatar, user_info)
                self.button_to_widget[self.button_group.getCurrent()].refresh()

        account_manager.setCurrentAccount(account.plugin.service,
                                          account.plugin.username)
        easy_thread.start(getUserInfo, args=(account, ), callback=updateUI)
Example #2
0
 def onClicked_AccountGroup(self, account):
     def getUserInfo(account):
         try:
             if account.plugin.service == 'all_accounts':
                 user_info = {
                     'screen_name': '所有账户',
                     'followers_count': 'x',
                     'friends_count': 'x',
                     'statuses_count': 'x'
                 }
                 avatar = constant.ALL_ACCOUNTS_AVATAR
             else:
                 user_info = account.getUserInfo(account.plugin.uid)
                 avatar = account.avatar_manager.get(user_info['avatar_large'])
             return (avatar, user_info)
         except Exception as e:
             return (None, {'error': str(e), 'service': account.plugin.service})
         
     def updateUI(avatar, user_info):
         if 'error' in user_info:
             QMessageBox.critical(None, user_info['service'], user_info['error'])
         else:
             self.updateUserInfo(avatar, user_info)
             self.button_to_widget[self.button_group.getCurrent()].refresh()
     
     account_manager.setCurrentAccount(account.plugin.service, account.plugin.username)
     easy_thread.start(getUserInfo,
         args=(account, ),
         callback=updateUI
     )
Example #3
0
    def refresh(self):
        if self.retrievingData:
            return
        else:
            self.refreshing = True
        
        account_list = account_manager.getCurrentAccount()
        
        for account in account_list:
            account.last_tweet_id = 0
            account.last_tweet_time = 0
            
        self.retrievingData_image.show()
        self.insertWidget(0, self.retrievingData_image)
        
        self.retrievingData = True
        easy_thread.start(self.retrieveData, args=(account_list, 1, 20), callback=self.updateUI)
        log.info('Starting thread')
        self.currentPage = 2
        
        self.emit(SIGNAL('refreshFinished'))
        
#    def refresh(self):
#        '''
#        For debug purpose
#        '''
#        self.removeAllWidgets()
#        
#        import random
#        account_list = account_manager.getCurrentAccount()
#        length = len(account_list)
#        rtn = [(account, []) for account in account_list]
#        for tweet in json.load(open('doc/json'))['statuses']:
#            rtn[random.randrange(0, length)][1].append(tweet)
#        self.updateUI(rtn)
Example #4
0
 def addAccount(self, service):
     '''
     @param service: string. Service name
     '''
     global_proxy = json.loads(config_manager.getParameter('Proxy'))
     if len(global_proxy.keys()) != 0:
         proxy_string = global_proxy['http']
         (host_name, port) = proxy_string.rsplit(':', 1)
         #host_name = host_name.split('://')[-1]
         
         proxy = QNetworkProxy()
         proxy.setType(QNetworkProxy.HttpProxy)
         proxy.setHostName(host_name)
         proxy.setPort(int(port))
         QNetworkProxy.setApplicationProxy(proxy)
         
     # Visit authorize url and get redirected url.
     plugin_class = plugin.plugins[service].Plugin
     url, data = plugin_class.getAuthorize()
     callback = plugin_class.getCallbackUrl()
     web = WebView(url, callback)
     web.exec()
     
     # Visit access token url.
     redirected_url = web.getRedirectedUrl()
     log.debug(redirected_url)
     # User gives up adding account
     if redirected_url == '':
         self.btn_add.setText('添加')
         self.btn_add.setEnabled(True)
         return None
     
     easy_thread.start(self.retrieveData, args=(service, redirected_url, data, plugin_class, global_proxy),
         callback=self.updateUI
     )
Example #5
0
 def showEvent(self, event):
     if self.first_show:
         self.button_to_widget[self.home].initialRefresh()
         self.button_to_widget[self.comment].initialRefresh()
         self.button_to_widget[self.at].initialRefresh()
         easy_thread.start(self.checkUnreads)
         self.connect(self, SIGNAL_UPDATE_UNREADS, self.updateUnreads)
         self.first_show = False
Example #6
0
 def showEvent(self, event):
     if self.first_show:
         self.button_to_widget[self.home].initialRefresh()
         self.button_to_widget[self.comment].initialRefresh()
         self.button_to_widget[self.at].initialRefresh()
         easy_thread.start(self.checkUnreads)
         self.connect(self, SIGNAL_UPDATE_UNREADS, self.updateUnreads)
         self.first_show = False
Example #7
0
    def refresh(self):
        self.insertWidget(0, self.retrievingData_image)

        log.info('Starting thread')
        easy_thread.start(self.retrieveData,
                          (account_manager.getCurrentAccount(), ),
                          callback=self.updateUI)
        pass
Example #8
0
 def __init__(self, account, tweet, avatar, thumbnail, parent=None):
     '''
     @param account: misc.Account object
     @param tweet: dict of tweet. See doc/插件接口设计.pdf: 单条微博
     @param avatar: QMovie showing that the avatar is still loading from Internet
     @param thumbnail: QMovie showing that the thumbnail is still loading from Internet
     @return: None
     '''
     super(TweetWidget, self).__init__(parent)
     
     self.account = account
     self.tweet = tweet
     self.avatar = avatar
     self.thumbnail = thumbnail
     self.pic_url = ''
     self.time_format = '%Y-%m-%d %H:%M:%S'
     
     self.setupUI()
     self.renderUI()
     self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding))
     #self.setStyleSheet('border-style:solid;border-width:5px')
     
     self.connect(self.label_tweet, SIGNAL('linkActivated (const QString&)'), self.onLinkActivated)
     if self.label_retweet:
         self.connect(self.label_retweet, SIGNAL('linkActivated (const QString&)'), self.onLinkActivated)
     if self.label_thumbnail:
         self.connect(self.label_thumbnail, SIGNAL_THUMBNAIL_CLICKED, self.onClicked_Thumbnail)
         
     # Repost button
     self.connect(self.btn_tweet_repost, SIGNAL_RESPONSE_CLICKED, self.onClicked_Repost)
     # Comment button
     self.connect(self.btn_tweet_comment, SIGNAL_RESPONSE_CLICKED, self.onClicked_Comment)
     # Click time to show tweet in seperated window
     self.connect(self.btn_tweet_time, SIGNAL_RESPONSE_CLICKED, self.onClicked_TweetTime)
     
     # Start downloading avatar
     avatar_url = tweet['user']['avatar_large']
     easy_thread.start(self.getResource,
         args=(avatar_url, constant.BROKEN_AVATAR, self.account.avatar_manager, self.label_avatar,
             QSize(constant.AVATER_IN_TWEET_SIZE, constant.AVATER_IN_TWEET_SIZE)
         ),
         callback=self.updateUI
     )
     
     # Start downloading thumbnail if exists
     try:
         if 'thumbnail_pic' in tweet:
             url = tweet['thumbnail_pic']
         elif ('retweeted_status' in tweet) and ('thumbnail_pic' in tweet['retweeted_status']):
             url = tweet['retweeted_status']['thumbnail_pic']
         easy_thread.start(self.getResource,
             args=(url, constant.BROKEN_IMAGE, self.account.picture_manager, self.label_thumbnail, None),
             callback=self.updateUI
         )
     except UnboundLocalError:
         # No picture
         pass
Example #9
0
 def appendNew(self):
     if self.retrievingData:
         return
     
     account_list = account_manager.getCurrentAccount()
     
     self.retrievingData_image.show()
     self.insertWidget(-1, self.retrievingData_image)
     
     self.retrievingData = True
     easy_thread.start(self.retrieveData, args=(account_list, self.currentPage, 20), callback=self.updateUI)
     log.info('Starting thread')
     self.currentPage += 1
Example #10
0
    def appendNew(self):
        if self.retrievingData:
            return

        account_list = account_manager.getCurrentAccount()

        self.retrievingData_image.show()
        self.insertWidget(-1, self.retrievingData_image)

        self.retrievingData = True
        easy_thread.start(self.retrieveData,
                          args=(account_list, self.currentPage, 20),
                          callback=self.updateUI)
        log.info('Starting thread')
        self.currentPage += 1
Example #11
0
    def onClicked_BtnSend(self):
        text = self.editor.toPlainText()
        if text:
            log.debug(text)

            accounts = self.getSelectedAccounts()
            if len(accounts) > 0:
                self.btn_send.setText('发送中...')
                self.btn_send.setEnabled(False)

                easy_thread.start(self.sendTweet,
                                  args=(accounts, text, self.pic_file),
                                  callback=self.updateUI)
            else:
                QMessageBox.critical(self, '错误', '请至少选择一个账户!')
        else:
            QMessageBox.critical(self, '错误', '微博不能为空!')
Example #12
0
    def onClicked_Btn(self):
        text = self.edit.toPlainText()
        self.button.setEnabled(False)
        self.edit.setEnabled(False)

        log.debug('checkBox: %s' % self.checkBox.isChecked())
        if self.widget_type == ResponseWidget.COMMENT:
            easy_thread.start(self.procSendComment,
                              args=(text, self.checkBox.isChecked()),
                              callback=self.updateUI)
        elif self.widget_type == ResponseWidget.REPOST:
            if 'retweeted_status' in self.tweet:
                text = ''.join((text, '//@', self.tweet['user']['screen_name'],
                                ': ', self.tweet['text']))
            easy_thread.start(self.procSendRetweet,
                              args=(text, self.checkBox.isChecked()),
                              callback=self.updateUI)
Example #13
0
 def onClicked_Btn(self):
     text = self.edit.toPlainText()
     self.button.setEnabled(False)
     self.edit.setEnabled(False)
     
     log.debug('checkBox: %s' % self.checkBox.isChecked())
     if self.widget_type == ResponseWidget.COMMENT:
         easy_thread.start(self.procSendComment,
             args=(text, self.checkBox.isChecked()),
             callback=self.updateUI
         )
     elif self.widget_type == ResponseWidget.REPOST:
         if 'retweeted_status' in self.tweet:
             text = ''.join((text, '//@', self.tweet['user']['screen_name'], ': ', self.tweet['text']))
         easy_thread.start(self.procSendRetweet,
             args=(text, self.checkBox.isChecked()),
             callback=self.updateUI
         )
Example #14
0
    def refresh(self):
        if self.retrievingData:
            return
        else:
            self.refreshing = True

        account_list = account_manager.getCurrentAccount()

        for account in account_list:
            account.last_tweet_id = 0
            account.last_tweet_time = 0

        self.retrievingData_image.show()
        self.insertWidget(0, self.retrievingData_image)

        self.retrievingData = True
        easy_thread.start(self.retrieveData,
                          args=(account_list, 1, 20),
                          callback=self.updateUI)
        log.info('Starting thread')
        self.currentPage = 2

        self.emit(SIGNAL('refreshFinished'))


#    def refresh(self):
#        '''
#        For debug purpose
#        '''
#        self.removeAllWidgets()
#
#        import random
#        account_list = account_manager.getCurrentAccount()
#        length = len(account_list)
#        rtn = [(account, []) for account in account_list]
#        for tweet in json.load(open('doc/json'))['statuses']:
#            rtn[random.randrange(0, length)][1].append(tweet)
#        self.updateUI(rtn)
Example #15
0
 def refresh(self):
     self.insertWidget(0, self.retrievingData_image)
     
     log.debug('Starting thread')
     easy_thread.start(self.retrieveData, (account_manager.getCurrentAccount(), ), callback=self.updateUI)
     pass
Example #16
0
    def __init__(self, account, tweet, avatar, thumbnail, parent=None):
        '''
        @param account: misc.Account object
        @param tweet: dict of tweet. See doc/插件接口设计.pdf: 单条微博
        @param avatar: QMovie showing that the avatar is still loading from Internet
        @param thumbnail: QMovie showing that the thumbnail is still loading from Internet
        @return: None
        '''
        super(TweetWidget, self).__init__(parent)

        self.account = account
        self.tweet = tweet
        self.avatar = avatar
        self.thumbnail = thumbnail
        self.pic_url = ''
        self.time_format = '%Y-%m-%d %H:%M:%S'

        self.setupUI()
        self.renderUI()
        self.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding))
        #self.setStyleSheet('border-style:solid;border-width:5px')

        self.connect(self.label_tweet,
                     SIGNAL('linkActivated (const QString&)'),
                     self.onLinkActivated)
        if self.label_retweet:
            self.connect(self.label_retweet,
                         SIGNAL('linkActivated (const QString&)'),
                         self.onLinkActivated)
        if self.label_thumbnail:
            self.connect(self.label_thumbnail, SIGNAL_THUMBNAIL_CLICKED,
                         self.onClicked_Thumbnail)

        # Repost button
        self.connect(self.btn_tweet_repost, SIGNAL_RESPONSE_CLICKED,
                     self.onClicked_Repost)
        # Comment button
        self.connect(self.btn_tweet_comment, SIGNAL_RESPONSE_CLICKED,
                     self.onClicked_Comment)
        # Click time to show tweet in seperated window
        self.connect(self.btn_tweet_time, SIGNAL_RESPONSE_CLICKED,
                     self.onClicked_TweetTime)

        # Start downloading avatar
        avatar_url = tweet['user']['avatar_large']
        easy_thread.start(self.getResource,
                          args=(avatar_url, constant.BROKEN_AVATAR,
                                self.account.avatar_manager, self.label_avatar,
                                QSize(constant.AVATER_IN_TWEET_SIZE,
                                      constant.AVATER_IN_TWEET_SIZE)),
                          callback=self.updateUI)

        # Start downloading thumbnail if exists
        try:
            if 'thumbnail_pic' in tweet:
                url = tweet['thumbnail_pic']
            elif ('retweeted_status'
                  in tweet) and ('thumbnail_pic' in tweet['retweeted_status']):
                url = tweet['retweeted_status']['thumbnail_pic']
            easy_thread.start(self.getResource,
                              args=(url, constant.BROKEN_IMAGE,
                                    self.account.picture_manager,
                                    self.label_thumbnail, None),
                              callback=self.updateUI)
        except UnboundLocalError:
            # No picture
            pass