Exemple #1
0
    def on_authorized(self):
        access = self.settings.read_credentials()
        credentials = {"consumer_key": SettingsManager.consumer_key,
                       'consumer_secret': SettingsManager.consumer_secret,
                       'access_key': access['access_key'],
                       'access_secret': access['access_secret']}
        self.client = TwitterClient(credentials)

        self.message_thread = MessageThread(self.client)
        self.message_thread.statuses_updated.connect(self.on_new_statuses_received)
        self.message_thread.start()

        self.tray_icon = TrayIcon()
        self.tray_icon.show()

        self.ui.show()
Exemple #2
0
class MainWindow(QtGui.QWidget):

    posted = pyqtSignal()

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = uic.loadUi("gui/ui/mainwindow.ui")
        self.slots_init()

        self.settings = SettingsManager()
        try:
            self.on_authorized()
        except:
            self.loginwindow = LoginWindow()
            self.loginwindow.authorized.connect(self.on_authorized)
            self.loginwindow.ui.show()



    @pyqtSlot()
    def on_authorized(self):
        access = self.settings.read_credentials()
        credentials = {"consumer_key": SettingsManager.consumer_key,
                       'consumer_secret': SettingsManager.consumer_secret,
                       'access_key': access['access_key'],
                       'access_secret': access['access_secret']}
        self.client = TwitterClient(credentials)

        self.message_thread = MessageThread(self.client)
        self.message_thread.statuses_updated.connect(self.on_new_statuses_received)
        self.message_thread.start()

        self.tray_icon = TrayIcon()
        self.tray_icon.show()

        self.ui.show()

    def slots_init(self):
        self.ui.sendstatus.clicked.connect(self.on_send_status_clicked)

    @pyqtSlot(list)
    def on_new_statuses_received(self, statuses):
        cursor = self.ui.statuslist.textCursor()
        cursor.movePosition(QTextCursor.Start)
        self.ui.statuslist.setTextCursor(cursor)
        for status in statuses:
            self.ui.statuslist.insertHtml(formatStatus(status))
        scroll_bar = self.ui.statuslist.verticalScrollBar()
        scroll_bar.setValue(scroll_bar.minimum())

    @pyqtSlot()
    def status_posted(self):
        self.ui.status.setReadOnly(False)


    @pyqtSlot()
    def on_send_status_clicked(self):
        status = self.ui.status.toPlainText().__str__()
        self.ui.status.clear()
        self.ui.status.setReadOnly(True)
        sender = SenderCommand(self.client, status)
        sender.posted.connect(self.status_posted)
        command_processor = CommandProcessor(sender)
        QThreadPool.globalInstance().start(command_processor)