예제 #1
0
    def launch(self):
        logger.info('%s Launch', repr(self))

        if not self.launchButton.isEnabled():
            logger.debug('%s Launch Aborted (Launch Button Disabled)', repr(self))
            return

        client_label = self.combobox.currentText()
        if client_label not in self.parent.config.clients.keys():
            dialog = QtWidgets.QMessageBox(parent=self.parent)
            dialog.setWindowTitle('No Client Selected')
            dialog.setText('You must select a client to use.')
            dialog.setModal(True)
            dialog.show()

            logger.debug('%s Launch Aborted (Client Missing)', repr(self))
            return

        exepath = os.path.join(self.parent.config.clients[client_label].path, 'bin', 'exefile.exe')
        if not os.path.exists(exepath):
            dialog = QtWidgets.QMessageBox(parent=self.parent)
            dialog.setWindowTitle('Client Not found')
            dialog.setText('Please ensure that the selected EVE Client is properly configuerd.')
            dialog.setModal(True)
            dialog.show()

            logger.debug('%s Launch Aborted (exefile.exe Missing)', repr(self))
            return

        self.launchButton.setDisabled(self.protected)
        self.launchButton.setFlat(True)
        self.launchButton.setText("Launching....")

        logger.debug('%s Pre-Launch Tests Passed', repr(self))

        self._launch = Launch(self.username, self.password, self.parent.config.clients[client_label])

        self._launch.error.connect(lambda e: self.on_login_error(e))
        self._launch.finished.connect(lambda a=None: self.on_launch_finished(a))

        self._launch.start()

        logger.debug('%s Launch Thread Started', repr(self))

        return
예제 #2
0
class AccountRow(QtCore.QObject):

    def __init__(self, *, label, username, password, protected, clients, parent):
        super(AccountRow, self).__init__()

        self.parent = parent
        self.label = label
        self.username = username
        self.password = password
        self.protected = protected

        logger.debug('%s New', repr(self))

        self.labelButton = QtWidgets.QPushButton(self.label)

        labelIcon = QtGui.QIcon()
        if self.protected:
            labelIcon.addPixmap(
                QtGui.QPixmap(":/icons/icons/lock_open.png"),
                QtGui.QIcon.Normal,
                QtGui.QIcon.On
            )
            labelIcon.addPixmap(
                QtGui.QPixmap(":/icons/icons/lock.png"),
                QtGui.QIcon.Normal,
                QtGui.QIcon.Off
            )
        else:
            labelIcon.addPixmap(
                QtGui.QPixmap(":/icons/icons/tick.png"),
                QtGui.QIcon.Normal,
                QtGui.QIcon.On
            )
            labelIcon.addPixmap(
                QtGui.QPixmap(":/icons/icons/cross.png"),
                QtGui.QIcon.Normal,
                QtGui.QIcon.Off
            )
        self.labelButton.setIcon(labelIcon)
        self.labelButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.labelButton.setCheckable(True)
        self.labelButton.setStyleSheet("text-align: left")

        self.combobox = QtWidgets.QComboBox()
        self.combobox.addItems(clients)

        self.launchButton = QtWidgets.QPushButton("Launch")
        self.launchButton.setDisabled(self.protected)

        self.editButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(':/icons/icons/wrench.png')), '')
        self.removeButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(':/icons/icons/delete.png')), '')

        self.launchButton.clicked.connect(lambda: self.on_launchButton_clicked())
        self.removeButton.clicked.connect(lambda: self.on_remove_clicked())
        self.editButton.clicked.connect(lambda: self.on_edit_clicked())

        self.labelButton.toggled.connect(lambda: self.on_labelButton_toggle())
        self.combobox.currentIndexChanged.connect(lambda: self.on_combobox_change())

        self.launchAction = QtWidgets.QAction('Launch ' + self.label, self.parent)
        self.setLaunchActionIcon()
        self.launchAction.triggered.connect(lambda: self.on_launchButton_clicked())
        #self.launchAction.triggered.connect(lambda: self.labelButton.toggle())

        self.parent.trayIconMenu.addAction(self.launchAction)

        # We should never save the state of the label button for protected accounts
        if self.protected:
            self.labelButton.setChecked(False)
        elif self.label in self.parent.config.states.keys():
            state = self.parent.config.states[self.label]

            self.labelButton.setChecked(state.selected)

            if state.clientLabel is not None:
                try:
                    self.combobox.setCurrentIndex(self.combobox.findText(state.clientLabel))
                except Exception as e:
                    logger.error(e)

    def setLaunchActionIcon(self):
        if self.labelButton.isChecked():
            self.launchAction.setIcon(QtGui.QIcon(":/icons/icons/tick.png"))
        else:
            self.launchAction.setIcon(QtGui.QIcon(":/icons/icons/cross.png"))

    def remove(self):
        logger.debug('%s Remove', repr(self))

        self.parent.trayIconMenu.removeAction(self.launchAction)
        self.launchAction.deleteLater()

        self.parent.accountGridLayout.removeWidget(self.labelButton)
        self.labelButton.deleteLater()

        self.parent.accountGridLayout.removeWidget(self.combobox)
        self.combobox.deleteLater()

        self.parent.accountGridLayout.removeWidget(self.launchButton)
        self.launchButton.deleteLater()

        self.parent.accountGridLayout.removeWidget(self.removeButton)
        self.removeButton.deleteLater()

        self.parent.accountGridLayout.removeWidget(self.editButton)
        self.editButton.deleteLater()

    def redraw(self, *, label, username, password, protected):
        logger.debug('%s Redraw', repr(self))

        self.label = label
        self.username = username
        self.password = password
        self.protected = protected

        self.launchButton.setDisabled(self.protected)
        self.launchButton.setFlat(False)
        self.launchButton.setText("Launch")

        self.labelButton.setText(self.label)

    def redraw_comboBox(self, clients):
        old_choice = self.combobox.currentText()
        self.combobox.clear()
        self.combobox.addItems(clients)
        try:
            self.combobox.setCurrentIndex(self.combobox.findText(old_choice))
        except Exception:
            pass

    def storeState(self):
        logger.debug('%s Store State', repr(self))

        self.parent.config.setState(
            label=self.label,
            selected=self.labelButton.isChecked(),
            clientLabel=self.combobox.currentText()
        )
        self.parent.config.save()

    def launch(self):
        logger.info('%s Launch', repr(self))

        if not self.launchButton.isEnabled():
            logger.debug('%s Launch Aborted (Launch Button Disabled)', repr(self))
            return

        client_label = self.combobox.currentText()
        if client_label not in self.parent.config.clients.keys():
            dialog = QtWidgets.QMessageBox(parent=self.parent)
            dialog.setWindowTitle('No Client Selected')
            dialog.setText('You must select a client to use.')
            dialog.setModal(True)
            dialog.show()

            logger.debug('%s Launch Aborted (Client Missing)', repr(self))
            return

        exepath = os.path.join(self.parent.config.clients[client_label].path, 'bin', 'exefile.exe')
        if not os.path.exists(exepath):
            dialog = QtWidgets.QMessageBox(parent=self.parent)
            dialog.setWindowTitle('Client Not found')
            dialog.setText('Please ensure that the selected EVE Client is properly configuerd.')
            dialog.setModal(True)
            dialog.show()

            logger.debug('%s Launch Aborted (exefile.exe Missing)', repr(self))
            return

        self.launchButton.setDisabled(self.protected)
        self.launchButton.setFlat(True)
        self.launchButton.setText("Launching....")

        logger.debug('%s Pre-Launch Tests Passed', repr(self))

        self._launch = Launch(self.username, self.password, self.parent.config.clients[client_label])

        self._launch.error.connect(lambda e: self.on_login_error(e))
        self._launch.finished.connect(lambda a=None: self.on_launch_finished(a))

        self._launch.start()

        logger.debug('%s Launch Thread Started', repr(self))

        return

    def on_launch_finished(self, a=None):
        logger.debug('%s On Launch Finished (%s)', repr(self), repr(a))

        if a is False:
            self.launchButton.setText('Error')
        else:
            self.launchButton.setDisabled(self.protected)
            if self.protected:
                self.labelButton.setChecked(False)
            self.launchButton.setFlat(False)
            self.launchButton.setText("Launch")

    def on_login_error(self, e):
        logger.debug('%s On Login Error (%s)', repr(self), repr(e))

        dialog = QtWidgets.QMessageBox(parent=self.parent)
        dialog.setWindowTitle('Login Error')
        dialog.setText(str(e))
        dialog.setModal(True)
        dialog.show()
        return

    def on_labelButton_toggle(self):
        logger.debug('%s On Label Button Toggle', repr(self))

        self.setLaunchActionIcon()

        if self.protected:
            self.launchButton.setDisabled(not self.labelButton.isChecked())
        else:
            self.storeState()


    def on_combobox_change(self, *args, **kwargs):
        logger.debug('%s On Combobox Change', repr(self))

        self.storeState()

    def on_launchButton_clicked(self):
        logger.debug('%s On Launch Button Clicked', repr(self))

        self.launch()

    def on_edit_clicked(self):
        logger.debug('%s On Edit Clicked', repr(self))

        dialog = UI_EditAccount(
            parent=self.parent,
            label=self.label,
            username=self.username,
            password=self.password,
            protected=self.protected
        )
        dialog.setModal(True)
        dialog.show()

    def on_remove_clicked(self):
        logger.debug('%s On Remove Clicked', repr(self))

        self.parent.config.removeAccount(self.label)
        self.parent.config.save()

        self.parent.addRemoveAccountRows()

    def __repr__(self):
        return '<AccountRow("{}",protected={})>'.format(self.label, self.protected)