예제 #1
0
class DDOSDialog(QDialog):
    ddos_checked = Signal()

    def __init__(self):
        super().__init__()
        self.label = QLabel('reCAPTCHA를 해결하고 확인 버튼을 누르세요.\n'
                            '404 페이지가 로드되면 정상입니다. 완료 버튼을 눌러 종료하세요.')
        self.label.setStyleSheet('font: 10pt \'맑은 고딕\'')
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        QWebEngineProfile.defaultProfile().setHttpAcceptLanguage('ko')
        self.browser = QWebEngineView()
        self.browser.setStyleSheet('border: 1px solid gray;')
        # self.browser.loadStarted.connect(self.test)
        # self.browser.loadFinished.connect(self.test2)
        self.btn_zoom_in = NPButton('+', 9, self)
        self.btn_zoom_in.setMinimumWidth(30)
        self.btn_zoom_in.setMaximumWidth(50)
        self.btn_zoom_in.clicked.connect(self.zoom_in)
        self.btn_zoom_out = NPButton('-', 9, self)
        self.btn_zoom_out.setMinimumWidth(30)
        self.btn_zoom_out.setMaximumWidth(50)
        self.btn_zoom_out.clicked.connect(self.zoom_out)
        self.btn = NPButton('완료', 10, self)
        self.btn.setMaximumWidth(200)
        self.btn.clicked.connect(self.accept)
        # self.btn.clicked.connect(self.test2)
        self.abc = False
        box_h = QHBoxLayout()
        box_h.addWidget(self.btn_zoom_in)
        box_h.addWidget(self.btn_zoom_out)
        box_h.addStretch(4)
        box_h.addWidget(self.btn)
        box_h.setStretchFactor(self.btn_zoom_in, 1)
        box_h.setStretchFactor(self.btn_zoom_out, 1)
        box_h.setStretchFactor(self.btn, 4)
        box_v = QVBoxLayout()
        box_v.addWidget(self.label)
        box_v.addWidget(self.browser)
        box_v.addLayout(box_h)
        box_v.setContentsMargins(8, 10, 8, 8)
        self.setLayout(box_v)
        # self.setWindowModality(Qt.ApplicationModal)
        self.setWindowTitle('reCAPTCHA')
        self.setWindowIcon(QIcon('icon.png'))
        self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
        self.browser.setFocus()
        self.resize(480, 700)

    def zoom_in(self):
        self.zoom(True)

    def zoom_out(self):
        self.zoom(False)

    def zoom(self, b):
        if b:
            self.browser.setZoomFactor(self.browser.zoomFactor() + 0.25)
        else:
            self.browser.setZoomFactor(self.browser.zoomFactor() - 0.25)

    @Slot()
    def show_ddos(self):
        self.browser.load(QUrl(f'{core.SITE_URL}/404'))
        ok = self.exec_()
        if ok == QDialog.Accepted:
            self.ddos_checked.emit()
예제 #2
0
class AssistantWidget(QtWidgets.QWidget):

    msg_signal = Signal(str)
    hidden = False
    last_position = QPoint(0, 0)
    current_answer = 0
    answers = []

    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(
            self, parent, Qt.FramelessWindowHint | Qt.WindowSystemMenuHint
            | Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        self.runner = KeyloggerRunner()
        self.runner.start_running(self.msg_signal)
        self.msg_signal.connect(self.get_events)
        self.webview = QWebEngineView()
        self.webview.setAttribute(Qt.WA_StyledBackground)
        self.webview.setStyleSheet("border: 1px solid black;")
        self.webview.setContentsMargins(1, 1, 1, 1)
        self.search_image = QtGui.QPixmap('dialog-search2.png')
        self.search_label = QtWidgets.QLabel()
        self.search_legend = QtWidgets.QLabel(text="¿Qué quieres saber?",
                                              parent=self.search_label)
        self.search_label.setPixmap(self.search_image)
        self.text_input = QtWidgets.QLineEdit(self.search_label)
        self.search_label.window().setStyleSheet("QLineEdit { border: none }")
        self.search_label.move(0, 0)
        self.search_legend.move(34, 120)
        self.text_input.move(34, 145)
        self.clear_button = QtWidgets.QPushButton("x")
        self.progress = QtWidgets.QLabel()
        movie = QtGui.QMovie("progress.gif")
        self.progress.setMovie(movie)
        movie.start()
        self.previous_button = QtWidgets.QPushButton()
        self.previous_button.setIcon(QtGui.QIcon('left.png'))
        self.next_button = QtWidgets.QPushButton()
        self.next_button.setIcon(QtGui.QIcon('right.png'))
        self.logo = QtGui.QPixmap('stacko.png')
        self.logo_label = QtWidgets.QLabel()
        self.logo_label.setPixmap(self.logo)
        self.build_layout()
        self.clear_button.clicked.connect(self.clear_search)
        self.text_input.returnPressed.connect(self.find_answers)
        self.previous_button.clicked.connect(self.show_previous_answer)
        self.next_button.clicked.connect(self.show_next_answer)
        self.api = StackOverflowApi()
        self.answers_runner = BackgroundRunner()
        self.answers_runner.msg_signal.connect(self.answers_loaded)

    def build_layout(self):
        self.parent_layout = QtWidgets.QHBoxLayout()
        self.parent_layout.addLayout(self.build_left_side())
        self.parent_layout.addLayout(self.build_right_side())
        self.setLayout(self.parent_layout)

    def build_left_side(self):
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.logo_label)
        return layout

    def build_right_side(self):
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.search_label)
        layout.addWidget(self.progress)
        self.progress.setVisible(False)
        buttons_layout = QtWidgets.QHBoxLayout()
        layout.addLayout(buttons_layout)
        buttons_layout.addWidget(self.clear_button)
        self.clear_button.setVisible(False)
        buttons_layout.addWidget(self.previous_button)
        self.previous_button.setVisible(False)
        buttons_layout.addWidget(self.next_button)
        self.next_button.setVisible(False)
        self.webview.setVisible(False)
        layout.addWidget(self.webview)
        return layout

    @Slot(str)
    def get_events(self, event):
        callback = getattr(self, f'event_{event}_callback',
                           self.unknown_event_callback)
        callback(event=event)

    @Slot(str)
    def answers_loaded(self, answers_json):
        answers = json.loads(answers_json)
        self.answers = answers
        print(self.answers)
        self.current_answer = 0
        self.previous_button.setVisible(True)
        self.previous_button.setEnabled(False)
        self.next_button.setVisible(True)
        if len(self.answers) > 1:
            self.next_button.setEnabled(True)
        self.clear_button.setVisible(True)
        self.search_label.setVisible(False)
        self.progress.setVisible(False)
        self.webview.setWindowOpacity(80)
        self.webview.setVisible(True)
        self.webview.setHtml(self.answers[self.current_answer]['content'])

    def event_invoke_callback(self, **kwargs):
        if self.hidden:
            self.show()
            self.move(self.last_position.x(), self.last_position.y())
            self.hidden = False
        else:
            self.last_position = self.pos()
            self.hide()
            self.hidden = True

    def event_quit_callback(self, **kwargs):
        QCoreApplication.quit()

    def unknown_event_callback(self, event):
        print(f'Unknown event {event}')

    def clear_search(self):
        self.current_answer = 0
        self.answers = []
        self.previous_button.setVisible(False)
        self.next_button.setVisible(False)
        self.clear_button.setVisible(False)
        self.text_input.clear()
        self.search_label.setVisible(True)
        self.search_label.move(0, 0)
        self.search_legend.move(34, 120)
        self.text_input.move(34, 145)
        self.text_input.setVisible(True)
        self.webview.setVisible(False)

    def find_answers(self):
        self.search_label.setVisible(False)
        self.progress.setVisible(True)
        self.answers_runner.stop_jobs()
        self.answers_runner.start_jobs(self.api.get_answers,
                                       args=(self.text_input.text(), ))

    def mousePressEvent(self, event):
        self.last_position = event.pos()
        super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            diff = event.pos() - self.last_position
            newpos = self.pos() + diff
            self.move(newpos)

    def show_previous_answer(self):
        if len(self.answers) > 0 and 0 <= self.current_answer - 1 < len(
                self.answers):
            self.current_answer = self.current_answer - 1
            self.webview.setHtml(self.answers[self.current_answer]['content'])
            if self.current_answer == 0:
                self.previous_button.setEnabled(False)
            if not self.next_button.isEnabled():
                self.next_button.setEnabled(True)

    def show_next_answer(self):
        if len(self.answers) > 0 and 0 <= self.current_answer + 1 < len(
                self.answers):
            self.current_answer = self.current_answer + 1
            self.webview.setHtml(self.answers[self.current_answer]['content'])
            if self.current_answer == len(self.answers) - 1:
                self.next_button.setEnabled(False)
            if not self.previous_button.isEnabled():
                self.previous_button.setEnabled(True)