Esempio n. 1
0
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()
        self.thread_pool = QThreadPool()
        self.thread_pool.setMaxThreadCount(1)
        self.active_thread_count = 0

    def init_ui(self):
        self.setWindowTitle('Thread Example 2')
        self.setFixedSize(800, 400)
        self.group_box_1 = QGroupBox(self)
        self.group_box_1.setTitle('GroupBox Test Thread')
        self.group_box_1.resize(350, 275)
        self.button_start = QPushButton('Start', self.group_box_1)
        self.button_stop = QPushButton('Stop', self.group_box_1)
        self.button_start.move(0, 30)
        self.button_stop.move(90, 30)
        self.show()

        self.button_start.clicked.connect(self.on_button_start_click)
        self.button_stop.clicked.connect(self.on_button_stop_click)

    def on_button_start_click(self):
        self.button_start.setEnabled(False)
        self.active_thread_count = 0
        links = [
            'google.com', 'youtube.com', 'instagram.com', 'twitter.com',
            'netflix.com'
        ]
        self.threads = []
        for link in links:
            self.thread = MyThread(link)
            self.thread.signals.finished.connect(self.on_finish)
            self.threads.append(self.thread)

        for thread in self.threads:
            self.thread_pool.start(thread)
            self.active_thread_count += 1

    def on_button_stop_click(self):
        print('Threads stopping...')
        self.button_start.setEnabled(False)
        self.thread_pool.clear()
        self.active_thread_count = self.thread_pool.activeThreadCount()

    def on_finish(self):
        self.active_thread_count -= 1
        if self.active_thread_count == 0:
            print('Finished All Jobs')
            self.button_start.setEnabled(True)
Esempio n. 2
0
janela = QMainWindow()
janela.setGeometry(100, 50, 300, 200)
janela.setWindowTitle("Primeira Janela")

label = QLabel("Checkboxes selecionados", janela)
label.move(50, 120)
label.resize(130, 30)

result = QLabel("", janela)
result.move(50, 140)
result.resize(100, 60)

group_box = QGroupBox("Selecione uma ou mais opções", janela)
group_box.move(50, 20)
group_box.resize(200, 100)

checkbox_1 = QCheckBox("Opção 1", group_box)
checkbox_1.move(10, 20)
checkbox_2 = QCheckBox("Opção 2", group_box)
checkbox_2.move(10, 40)
checkbox_3 = QCheckBox("Opção 3", group_box)
checkbox_3.move(10, 60)


def onClickCheckBox():
    text = ""
    text += "checkbox 1: " + str(checkbox_1.isChecked())
    text += "\ncheckbox 2: " + str(checkbox_2.isChecked())
    text += "\ncheckbox 3: " + str(checkbox_3.isChecked())
    result.setText(text)
    def box_gen(self, x, y, resource=''):
        group_box = QGroupBox(self.window)
        group_box.move(x, y)
        group_box.resize(self.box_width, self.box_height)
        if resource == '':
            return []
        group_box.setTitle('')
        group_box.setStyleSheet('QGroupBox { background-color: \
            rgb(255, 255, 255); border: 3px solid rgb(122, 255, 100); } \
            QGroupBox::title{font: 75 ' + str(100 * self.screen_ratio) + 'pt "宋体"; color: rgb(255, 0, 0)}')

        label_again = QLabel(group_box)
        label_again.setStyleSheet('QLabel {font: 75 ' + str(self.font_size) + 'pt "宋体"; color: rgb(255, 0, 0)}')
        label_again.setText(resource)
        label_again.move(int(self.grid_width * 0.7), 5 * self.screen_ratio)
        label_again.resize(int(self.grid_width * 3.3), self.init_bias - 5)

        product_label00 = QLabel(group_box)
        product_label00.setText('产量')
        product_label00.move(3, self.init_bias)
        product_label00.resize(self.grid_width, self.grid_height)
        product_label00.setStyleSheet('QLabel {font: 75 ' + str(self.font_size) + 'pt "宋体"}')
        product00 = QLineEdit(group_box)
        product00.setText('0')
        product00.move(self.grid_width, self.init_bias)
        product00.resize(self.grid_width, self.grid_height)
        product00.setEnabled(False)
        product00.setStyleSheet('QLineEdit {font: ' + str(self.line_edit_font_size) + 'pt "宋体"}')

        product_label10 = QLabel(group_box)
        product_label10.setText('额外')
        product_label10.move(3, self.grid_height + self.init_bias)
        product_label10.resize(self.grid_width, self.grid_height)
        product_label10.setStyleSheet('QLabel {font: 75 ' + str(self.font_size) + 'pt "宋体"}')
        product10 = QLineEdit(group_box)
        product10.setText('0')
        product10.move(self.grid_width, self.grid_height + self.init_bias)
        product10.resize(self.grid_width, self.grid_height)
        product10.setStyleSheet('QLineEdit {font: ' + str(self.line_edit_font_size) + 'pt "宋体"}')

        product_label01 = QLabel(group_box)
        product_label01.setText('机器')
        product_label01.move(self.grid_width * 2 + self.interval, self.init_bias)
        product_label01.resize(self.grid_width, self.grid_height)
        product_label01.setStyleSheet('QLabel {font: 75 ' + str(self.font_size) + 'pt "宋体"}')
        product01 = QLineEdit(group_box)
        product01.setText('0.0')
        product01.move(self.grid_width * 3 + self.interval, self.init_bias)
        product01.resize(self.grid_width, self.grid_height)
        product01.setStyleSheet('QLineEdit {font: ' + str(self.line_edit_font_size) + 'pt "宋体"}')
        product01.setEnabled(False)

        product_label11 = QLabel(group_box)
        product_label11.setText('已有')
        product_label11.move(self.grid_width * 2 + self.interval, self.grid_height + self.init_bias)
        product_label11.resize(self.grid_width, self.grid_height)
        product_label11.setStyleSheet('QLabel {font: 75 ' + str(self.font_size) + 'pt "宋体"}')
        product11 = QLineEdit(group_box)
        product11.setText('0')
        product11.move(self.grid_width * 3 + self.interval, self.grid_height + self.init_bias)
        product11.resize(self.grid_width, self.grid_height)
        product11.setStyleSheet('QLineEdit {font: ' + str(self.line_edit_font_size) + 'pt "宋体"}')
        if resource in self.supporter:
            product11.setEnabled(True)
        else:
            product11.setEnabled(False)

        return [product00, product01, product10, product11]