Esempio n. 1
0
    def __init__(self, chatScreen, bot):
        self.nickname = ""
        self.password = ""
        self.refreshToken = ""
        self.refreshTimer = 0

        self.chatScreen = chatScreen
        if not SettingManager.checkLoginFilesAreCompleted(
        ) or GeneralLoginDialog.reFreshTokenAndGetLogin() is None:
            generalDialog = GeneralLoginDialog(self)
            generalDialog.exec()
            if not SettingManager.checkLoginFilesAreCompleted():
                self.chatScreen.chatUI.centralWidget.mainWindow.close()
        [self.nickname, self.password, self.refreshToken
         ] = SettingManager.getSettingFileContent(SettingManager.LOGIN_FILE)
        self.receiveSocket = socket.socket()
        self.sendSocket = socket.socket()
        self.receiveSocketRunning = False
        self.systemMessageProcessor = SystemMessageProcessor(
            self.chatScreen, bot.messageQueue)
        self.systemMessageThread = self.systemMessageProcessor.systemMessageThread
        self.isHoldingMessage = False
        self.heldMessage = ''
        self.channelMessagePattern = re.compile('.*PRIVMSG (#[^ ]*) :')
        bot.connectIRC(self)
    def __init__(self, clientIRC):
        super(GeneralLoginDialog, self).__init__()
        self.loginChanged = False
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.clientIRC = clientIRC
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setWindowTitle('Login')
        position = self.clientIRC.chatScreen.chatUI.centralWidget.mainWindow.getPopUpPosition(
            400, 100)
        self.setGeometry(position.x(), position.y(), 400, 100)
        self.nickname = ""
        self.oauthToken = ""
        self.expire_in = 0
        self.refreshToken = ""
        self.hasLogin = SettingManager.checkLoginFilesAreCompleted()
        if self.hasLogin:
            [self.nickname, self.oauthToken,
             self.refreshToken] = SettingManager.getSettingFileContent(
                 SettingManager.LOGIN_FILE)
        layout = QVBoxLayout()
        self.label = QLabel()
        changeAccountButton = QPushButton()
        changeAccountButton.setText('Change account')
        changeAccountButton.clicked.connect(self.changeAccount)
        self.connectButton = QPushButton()
        self.connectButton.setText('Connect')
        self.connectButton.clicked.connect(self.connect)

        buttonLayout = QHBoxLayout()
        removeLoginButton = QPushButton()
        removeLoginButton.setText("Remove login")
        removeLoginButton.clicked.connect(self.removeLogin)
        buttonLayout.addWidget(changeAccountButton)
        buttonLayout.addWidget(removeLoginButton)

        self.defaultChannelLineEdit = QLineEdit()
        if self.hasLogin:
            self.defaultChannelLineEdit.setText(
                SettingManager.getSettingFileContent(
                    SettingManager.DEFAULT_CHANNEL_FILE)[0])
        else:
            self.defaultChannelLineEdit.setText("")
        self.defaultChannelLineEdit.returnPressed.connect(self.connect)
        self.defaultChannelLineEdit.textChanged[str].connect(
            self.enableConnectButton)

        layout.addWidget(self.label, 1)
        layout.addLayout(buttonLayout)
        layout.addWidget(
            QLabel(
                "Default list of channels to connect to, separated by comma"))
        layout.addWidget(self.defaultChannelLineEdit)
        layout.addWidget(self.connectButton, 1)

        self.setLayout(layout)
        self.updateUsername()
def test_setUpBasicSettingFiles(tmpdir):
    SettingManager.SETTING_DIRECTORY = tmpdir
    SettingManager.MAIN_SETTING_FILE = tmpdir + "\\MainSetting"
    SettingManager.NOTIFICATION_SETTING_FILE = tmpdir + "\\NotificationSetting"
    SettingManager.CHAT_CSS_FILE = tmpdir + "\\ChatCSS"
    SettingManager.setUpBasicSettingFiles()
    assert SettingManager.CHAT_CSS_FILE.read(
    ) == "QTextBrowser { background-color: black; color: white; }", "set up basic setting files failed: chat css file"
    assert SettingManager.NOTIFICATION_SETTING_FILE.read(
    ) == "Consolas\n10\n#ffff7f\n#000000\n\n", "set up basic setting files failed: notification setting file"
    assert SettingManager.MAIN_SETTING_FILE.read(
    ) == "Consolas\n10\n10\n\n", "set up basic setting files failed: main setting file"
 def requestAccepted(self, token):
     self.loginChanged = True
     self.hasLogin = True
     response = requests.post(self.oauthTokenURL.replace("REPLACE", token))
     oauthToken = response.json()['access_token']
     refreshToken = response.json()['refresh_token']
     response = requests.get(
         self.VALIDATE_URL,
         headers={"Authorization": "OAuth " + oauthToken})
     self.nickname = response.json()['login']
     SettingManager.saveSetting(
         SettingManager.LOGIN_FILE,
         [self.nickname, "oauth:" + oauthToken, refreshToken])
     self.updateUsername()
Esempio n. 5
0
    def __init__(self, settingDialog):
        super(MainWidget, self).__init__(settingDialog)
        self.settingDialog = settingDialog
        layout = QVBoxLayout()

        settings = SettingManager.getSettingFileContent(
            SettingManager.MAIN_SETTING_FILE)
        chatFontGroupBox = QGroupBox(self)
        chatFontGroupBox.setTitle("Chat Font")
        chatFontLayout = QGridLayout()
        chatFontLayout.addWidget(QLabel("Font Name:"), 0, 0)
        self.chatFont = QLineEdit()
        self.chatFont.setText(settings[0])
        self.chatFont.setEnabled(False)
        chatFontLayout.setContentsMargins(5, 5, 5, 5)
        chatFontLayout.addWidget(self.chatFont, 0, 1)
        selectFontButton = QPushButton("Select Font")
        selectFontButton.clicked.connect(self.chooseFont)
        chatFontLayout.addWidget(selectFontButton, 1, 2)
        chatFontLayout.addWidget(QLabel("Font Size:"), 1, 0)
        self.chatFontSize = QLineEdit()
        self.chatFontSize.setText(settings[1])
        self.chatFontSize.setEnabled(False)
        chatFontLayout.addWidget(self.chatFontSize, 1, 1)
        chatFontLayout.addWidget(QLabel("Line Spacing:"), 2, 0)
        self.chatLineSpacing = QLineEdit()
        self.chatLineSpacing.setText(settings[2])
        self.chatLineSpacing.setEnabled(False)
        chatFontLayout.addWidget(self.chatLineSpacing, 2, 1)
        chatFontGroupBox.setLayout(chatFontLayout)
        layout.addWidget(chatFontGroupBox)

        self.setLayout(layout)
Esempio n. 6
0
 def updateSetting(self):
     settings = SettingManager.getSettingFileContent(
         SettingManager.NOTIFICATION_SETTING_FILE)
     self.font = QFont(settings[0], int(settings[1]), -1, False)
     self.chatScreen.chatUI.centralWidget.mainWindow.setStyleSheet(
         "QLabel#NotificationLabel { background-color : " + settings[2] +
         "; color : " + settings[3] + "; }")
     self.qSound = QSound(settings[4])
 def closeEvent(self, event):
     if SettingManager.checkLoginFilesAreCompleted():
         if self.loginChanged:
             self.connect()
         else:
             self.close()
     else:
         self.clientIRC.chatScreen.chatUI.centralWidget.mainWindow.close()
 def reFreshTokenAndGetLogin():
     response = GeneralLoginDialog.refreshAccessToken()
     if response:
         GeneralLoginDialog.writeLoginFile(response[0], response[1],
                                           response[2])
     else:
         return None
     return SettingManager.getSettingFileContent(SettingManager.LOGIN_FILE)
Esempio n. 9
0
 def __init__(self):
     if not os.path.exists(CacheManager.DIRECTORY):
         os.mkdir(CacheManager.DIRECTORY)
     if not SettingManager.checkBasicSettingFilesCompletion():
         SettingManager.setUpBasicSettingFiles()
     super().__init__()
     self.setAttribute(Qt.WA_DeleteOnClose)
     self.setWindowTitle('Twitch chat')
     self.left = 500
     self.top = 40
     self.width = 500
     self.height = 900
     self.setGeometry(self.left, self.top, self.width, self.height)
     self.centralWidget = CentralWidget(self)
     self.setCentralWidget(self.centralWidget)
     menu = MenuBar(self)
     self.setMenuBar(menu)
     self.show()
Esempio n. 10
0
 def reconnect(self):
     old_nickName = self.nickname
     [self.nickname, self.password, self.refreshToken
      ] = SettingManager.getSettingFileContent(SettingManager.LOGIN_FILE)
     if old_nickName != self.nickname:
         while self.chatScreen.count() > 0:
             self.chatScreen.closeTab(False)
         self.reLogin()
     self.chatScreen.joinDefaultChannel()
 def __init__(self, parent):
     super(ChatScreen, self).__init__(parent)
     self.showMessage = True
     self.chatUI = parent
     settings = SettingManager.getSettingFileContent(
         SettingManager.MAIN_SETTING_FILE)
     self.font = QFont(settings[0], int(settings[1]), -1, False)
     self.jsonDecoder = JSONDecoder()
     self.tabs = {}
     self.clientIRC = ClientIRC(self)
     self.clientIRC.start()
     self.notificationManager = NotificationManager(self)
     self.setAutoFillBackground(True)
     self.joinDefaultChannel()
     QShortcut(QKeySequence('Ctrl+Tab'), self, self.nextTab)
     QShortcut(QKeySequence('Ctrl+W'), self, self.closeTabOrExit)
     self.newWhisperSignal.connect(self.newWhisper)
Esempio n. 12
0
 def __init__(self, chatTab, channelName, jsonDecoder):
     super(ChannelChat, self).__init__(chatTab)
     self.chatTab = chatTab
     self.messageProcessor = MessageProcessor(jsonDecoder, self.chatTab.clientIRC.chatScreen.font.pointSizeF() / 12 * 16, self.chatTab.clientIRC.chatScreen.bot.messageQueue, self.newNotificationSignal)
     self.chatThread = ChatThread(self, channelName)
     self.channelName = channelName
     self.chatThread.start()
     self.setReadOnly(True)
     self.anchorClicked.connect(self.checkClick)
     self.setAcceptRichText(True)
     self.setOpenLinks(False)
     self.scrollToBottom = True
     self.lastSent = ''
     self.verticalScrollBar().rangeChanged.connect(self.scrollBar)
     self.verticalScrollBar().sliderReleased.connect(self.shouldKeepScrolling)
     self.verticalScrollBar().valueChanged.connect(self.shouldKeepScrolling)
     self.setFont(self.chatTab.clientIRC.chatScreen.font)
     self.document().setDefaultStyleSheet("background-color: yellow")
     self.setStyleSheet(SettingManager.getHTMLSettingContent(SettingManager.CHAT_CSS_FILE))
 def refreshAccessToken():
     [username, _, refreshToken
      ] = SettingManager.getSettingFileContent(SettingManager.LOGIN_FILE)
     return GeneralLoginDialog.refreshAccessTokenWithName(
         username, refreshToken)
def test_checkIfFileIsCompleted(tmpdir):
    p = tmpdir.join("login")
    p.write("content\ncontent\n")
    file = open(p, "r")
    assert SettingManager.checkIfFileIsCompleted(file, 0) == True
    file.close()
 def loadAndUpdateLogin(self):
     [self.nickname, self.oauthToken, self.refreshToken
      ] = SettingManager.getSettingFileContent(SettingManager.LOGIN_FILE)
     self.hasLogin = True
     self.updateUsername()
 def connect(self):
     SettingManager.saveSetting(
         SettingManager.DEFAULT_CHANNEL_FILE,
         [self.defaultChannelLineEdit.text().lower()])
     self.accept()
 def removeLogin(self):
     SettingManager.clearSettingFile(SettingManager.LOGIN_FILE)
     self.hasLogin = False
     self.updateUsername()
 def writeLoginFile(nickname, oauthToken, refreshToken):
     content = []
     content.append(nickname)
     content.append("oauth:" + oauthToken)
     content.append(refreshToken)
     SettingManager.saveSetting(SettingManager.LOGIN_FILE, content)
def test_getUsername(tmpdir):
    p = tmpdir.join("login")
    p.write("content")
    SettingManager.LOGIN_FILE = tmpdir + "\\login"
    assert SettingManager.getUsername(
    ) == "content", "get username test failed"
Esempio n. 20
0
 def saveSetting(self):
     settings = []
     settings.append(self.chatFont.text())
     settings.append(self.chatFontSize.text())
     settings.append(self.chatLineSpacing.text())
     SettingManager.saveSetting(SettingManager.MAIN_SETTING_FILE, settings)
 def parseListFromDefaultChannelFile(self):
     return SettingManager.getSettingFileContent(
         SettingManager.DEFAULT_CHANNEL_FILE)[0].replace(" ", "").split(",")