Esempio n. 1
0
    def addNewMessage(self):
        name = self.ui.txt_name.text()
        text = self.ui.txt_message.text()
        now = datetime.now().strftime('%H')

        if name != "" and text != "":
            for message in self.messages:
                if name == message[1]:
                    if int(now) - int(message[3][11:12]) <= 0:
                        self.msgBox("Your message should be for 1 hour ago or more")
                        break
            else:
                response = Database.insert(name, text)
                if response:
                    self.length += 1
                    label = QLabel()
                    label.setText(name + ": " + text)
                    self.ui.gl_messages.addWidget(label, self.length, 1, alignment=Qt.Alignment())
                    
                    btn = QPushButton()
                    btn.setText('×')
                    btn.setStyleSheet('max-width: 18px; min-height: 18px; background-color: red; color: white; border: 0px; border-radius: 5px;')
                    self.ui.gl_messages.addWidget(btn, self.length, 0, alignment=Qt.Alignment())
                    btn.clicked.connect(partial(self.deleteMessage, self.messages[-1][0], btn, label))
                
                    self.ui.txt_name.setText("")
                    self.ui.txt_message.setText("")

                    self.msgBox("Your message sent successfully!")
                else:
                    self.msgBox("Database error!")                
        else:
            self.msgBox("Error: feilds are empty!")
Esempio n. 2
0
    def initUI(self):
        self.setWindowTitle("QTableWidget 例子")
        self.resize(430, 300);
        conLayout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        conLayout.addWidget(tableWidget)

        tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])

        newItem = QTableWidgetItem("张三")
        tableWidget.setItem(0, 0, newItem)

        comBox = QComboBox()
        comBox.addItem("男")
        comBox.addItem("女")
        comBox.setStyleSheet("QComboBox{margin:3px};")
        tableWidget.setCellWidget(0, 1, comBox)

        searchBtn = QPushButton("修改")
        searchBtn.setDown(True)
        searchBtn.setStyleSheet("QPushButton{margin:3px};")
        tableWidget.setCellWidget(0, 2, searchBtn)

        self.setLayout(conLayout)
Esempio n. 3
0
    def __init__(self, parent, init_label, mainfunction, quitfunction):
        super().__init__(parent)
        self.button = QPushButton(init_label)
        self.button.clicked.connect(mainfunction)
        self.button.setAutoDefault(True)
        quitbutton = QPushButton('終わる')
        quitbutton.setStyleSheet('background-color: #c00; color: white;')
        quitbutton.clicked.connect(quitfunction)

        layout = QHBoxLayout()
        layout.addWidget(self.button)
        layout.addWidget(quitbutton)
        self.setLayout(layout)
Esempio n. 4
0
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(400, 120)
        Dialog.setMinimumSize(QSize(400, 120))
        Dialog.setMaximumSize(QSize(400, 120))
        self.verticalLayout = QVBoxLayout(Dialog)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(9, 9, 9, 9)
        self.bg_diag = QFrame(Dialog)
        self.bg_diag.setObjectName(u"bg_diag")
        self.bg_diag.setStyleSheet(u"background-color: rgb(29, 0, 86);\n"
                                   "border-radius: 10px;")
        self.bg_diag.setFrameShape(QFrame.NoFrame)
        self.bg_diag.setFrameShadow(QFrame.Raised)
        self.tittle_bar = QFrame(self.bg_diag)
        self.tittle_bar.setObjectName(u"tittle_bar")
        self.tittle_bar.setGeometry(QRect(10, 10, 361, 31))
        self.tittle_bar.setFrameShape(QFrame.StyledPanel)
        self.tittle_bar.setFrameShadow(QFrame.Raised)
        self.lbl_falhaLogar = QLabel(self.tittle_bar)
        self.lbl_falhaLogar.setObjectName(u"lbl_falhaLogar")
        self.lbl_falhaLogar.setGeometry(QRect(64, -9, 241, 41))
        self.lbl_falhaLogar.setStyleSheet(u"color: rgb(255, 255, 255);\n"
                                          "font: 18pt \"Segoe UI\";")
        self.pushButton = QPushButton(self.bg_diag)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(161, 60, 61, 31))
        self.pushButton.setStyleSheet(u"background-color: rgb(53, 159, 159);\n"
                                      "color: rgb(255, 255, 255);\n"
                                      "font: 18pt \"Segoe UI\";\n"
                                      "")

        self.verticalLayout.addWidget(self.bg_diag)

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)

    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(
            QCoreApplication.translate("Dialog", u"Dialog", None))
        self.lbl_falhaLogar.setText(
            QCoreApplication.translate("Dialog",
                                       u"Falha ao logar usu\u00e1rio", None))
        self.pushButton.setText(
            QCoreApplication.translate("Dialog", u"Ok", None))
Esempio n. 5
0
    def readMessages(self):
        messages = Database.select()
        for i, message in enumerate(messages):
            label = QLabel()
            label.setText(message[1] + ": " + message[2])
            self.ui.gl_messages.addWidget(label,i, 1, alignment=Qt.Alignment())
            
            btn = QPushButton()
            btn.setText('×')
            btn.setStyleSheet('max-width: 18px; min-height: 18px; background-color: red; color: white; border: 0px; border-radius: 5px;')

            self.ui.gl_messages.addWidget(btn, i, 0, alignment=Qt.Alignment())
            btn.clicked.connect(partial(self.deleteMessage, message[0], btn, label))
        return messages
Esempio n. 6
0
class SecondWidget2(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        self.back = QPushButton(self)
        self.back.setStyleSheet(
            '''
            QPushButton{image:url(./img/back_img.png); border:0px;}
            QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;}
            ''')
        self.back.setGeometry(0, 0, 50, 50) 
        self.back.clicked.connect(self.change_stack1)

        label1 = QLabel(' 중요한 이미지는 변환하지마세요 BASE64는 보안으로 매우 약합니다 간단한 텍스트 용도으로 사용하기 때문에 이미지 \n 변환은 권장하지 않습니다', self)
        label1.move(125, 180)

        self.files = QPushButton("파일 선택", self)	
        self.files.setGeometry(50, 100, 850, 50) 
        self.files.clicked.connect(self.pushButtonClicked)

        self.files_encoding = QPushButton("OK", self)	
        self.files_encoding.setGeometry(800, 450, 100, 30) 
        self.files_encoding.clicked.connect(self.base64_files_encoding)

    def pushButtonClicked(self):
        # self.FileOpen = QFileDialog.getOpenFileName(self, '열기', './')
        '''
        특정 확장자 검색
        https://doc.qt.io/qt-5/qfiledialog.html 참조
        '''
        # self.FileOpen = QFileDialog.getOpenFileName(self, '열기', '','Images (*.png *.jpg *.bmp);; All File(*)')
        self.FileOpen = QFileDialog.getOpenFileName(self, '열기', '','Images (*.png *.jpg *.bmp)')
        # self.files.setText(self.FileOpen[0])
        print(self.FileOpen[0])
    
    def base64_files_encoding(self):
        
        with open(self.FileOpen[0], 'rb') as imagefile:
            byteform = base64.b64encode(imagefile.read())

        f = open('C:/Users/'+user_name+'/Desktop/base64encoding.bin', 'wb')
        f.write(byteform)
        f.close()

        guidance = QMessageBox.information(self, 'base64', '바탕화면에 base64encoding.bin 파일이 생성했습니다', QMessageBox.Ok)
        print('완료')


    def change_stack1(self):
        self.parent().stack.setCurrentIndex(1)
Esempio n. 7
0
class SecondWidget4(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        layout = QtWidgets.QVBoxLayout(self)
        label1 = QLabel('입력', self)
        label1.setAlignment(Qt.AlignVCenter)
        label1.move(200, 30)

        label2 = QLabel('결과', self)
        label2.setAlignment(Qt.AlignVCenter)
        label2.move(710, 30)

        self.text_dox1 = QTextEdit(self)
        self.text_dox1.resize(350, 350)
        self.text_dox1.move(50, 60)

        self.text_dox2 = QTextBrowser(self)
        self.text_dox2.append('')
        self.text_dox2.setGeometry(550, 60, 350, 350) 

        self.dk_base64 = QPushButton("OK", self)	
        self.dk_base64.setGeometry(50, 420, 850, 45) 
        self.dk_base64.clicked.connect(self.base64_conversion)


        self.back = QPushButton(self)
        self.back.setStyleSheet(
            '''
            QPushButton{image:url(./img/back_img.png); border:0px;}
            QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;}
            ''')
        self.back.setGeometry(0, 0, 50, 50) 
        self.back.clicked.connect(self.change_stack1)

    
    def change_stack1(self):
        self.parent().stack.setCurrentIndex(4)

    def base64_conversion(self):
        # print(self.text_dox1.toPlainText())
        sitename_bytes = base64.b64decode(self.text_dox1.toPlainText())
        sitename = sitename_bytes.decode('utf-8')
        print(sitename)

        # 내용 초기화
        self.text_dox2.clear()
        self.text_dox2.repaint()

        self.text_dox2.append(str(sitename))
Esempio n. 8
0
class SecondWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        self.butt1 = QPushButton(self)
        self.butt1.setStyleSheet('image:url(./img/text_img.png);border:0px;')	
        self.butt1.setGeometry(50, 50, 400, 400) 
        self.butt1.clicked.connect(self.change_stack1)

        self.butt2 = QPushButton(self)	
        self.butt2.setStyleSheet('image:url(./img/image_img.png);border:0px;')	
        self.butt2.setGeometry(500, 50, 400, 400) 
        self.butt2.clicked.connect(self.change_stack2)

        self.back = QPushButton(self)	
        self.back.setStyleSheet(
            '''
            QPushButton{image:url(./img/back_img.png); border:0px;}
            QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;}
            ''')
        self.back.setGeometry(0, 0, 50, 50) 
        self.back.clicked.connect(self.change_stack3)

    #2 텍스트 인코딩 페이지 
    def change_stack1(self):
        self.parent().stack.setCurrentIndex(2)

    # 3 이미지 인코딩 페이지
    def change_stack2(self):
        self.parent().stack.setCurrentIndex(3)


    # 뒤로 가기 
    def change_stack3(self):
        self.parent().stack.setCurrentIndex(0)
Esempio n. 9
0
class SecondWidget5(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        self.files = QPushButton("파일 선택", self)	
        self.files.setGeometry(50, 100, 850, 50) 
        self.files.clicked.connect(self.pushButtonClicked)

        self.files_encoding = QPushButton("OK", self)	
        self.files_encoding.setGeometry(800, 450, 100, 30) 
        self.files_encoding.clicked.connect(self.base64_files_encoding)

        self.back = QPushButton(self)
        self.back.setStyleSheet(
            '''
            QPushButton{image:url(./img/back_img.png); border:0px;}
            QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;}
            ''')
        self.back.setGeometry(0, 0, 50, 50) 
        self.back.clicked.connect(self.change_stack1)

    def change_stack1(self):
        self.parent().stack.setCurrentIndex(4)

    def pushButtonClicked(self):
        # self.FileOpen = QFileDialog.getOpenFileName(self, '열기', './')

        self.FileOpen = QFileDialog.getOpenFileName(self, '열기', '','Images (*.bin)')
        # self.files.setText(self.FileOpen[0])
        print(self.FileOpen[0])
    
    def base64_files_encoding(self):
        print(self.FileOpen[0])
        file = open(self.FileOpen[0], 'r')
        decoding = file.read()

        im = Image.open(BytesIO(base64.b64decode(decoding)))
        im.save('C:/Users/'+user_name+'/Desktop/b64decode_images.png', 'PNG')
        guidance = QMessageBox.information(self, 'base64', '바탕화면에 b64decode_images.png 이 생성했습니다', QMessageBox.Ok)
        print("완료")
Esempio n. 10
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        btnRun1 = QPushButton(self)	
        btnRun1.setStyleSheet('image:url(./img/1_img_kr.png);border:0px;')
        btnRun1.setGeometry(50, 50, 400, 400) 
        btnRun1.clicked.connect(self.change_stack1)

        btnRun2 = QPushButton(self)	
        btnRun2.setStyleSheet('image:url(./img/2_img_kr.png);border:0px;')
        btnRun2.setGeometry(500, 50, 400, 400) 
        btnRun2.clicked.connect(self.change_stack2)
     
        exit_button = QPushButton(self)	
        exit_button.setStyleSheet('image:url(./img/PNG_exit_2.png);border:0px;')
        exit_button.setGeometry(900, 0, 50, 50) 
        exit_button.clicked.connect(QCoreApplication.instance().quit)
Esempio n. 11
0
class MineSweeper(QMainWindow):
	def __init__(self):
		super().__init__()

		self.undiscovered_color: str = "#000000"
		self.discovered_color: str = "#d9d9d9"
		self.win_timer_color: str = "#e30e0e"
		self.lose_timer_color: str = "#0cc431"


		self.curr_time = QTime(00,00,00)
		self.timer = QTimer()
		self.timer.timeout.connect(self.time)
		self.timer_already_started = False

		self.solved: bool = False
		
		self.player_ended: bool = False

		self.theme: str = "dark"

		self.list_of_mines: list = []

		self.difficulty_slider_default_value: int = 2
		self.number_of_mines: int = mines_number(NUMBER_OF_LABELS, self.difficulty_slider_default_value)


		self.create_GUI()

	def create_GUI(self) -> None:
		self.setWindowTitle("MineSweeper 1.1")

		self.win_massage = QMessageBox(self)
		self.win_massage.setText("Gratuluji, dokázal jsi nalézt všechny miny")

		self.setMouseTracking(True)

		centralWidget = QWidget(self)
		centralWidget.setStyleSheet("background: white")
		self.setCentralWidget(centralWidget)
		self.setFixedSize(X_WINDOW_SIZE + 20, Y_WINDOW_SIZE)

		layout = QGridLayout(centralWidget)
		layout.setSpacing(0)
		layout.setContentsMargins(0, 0, 0, 0)
		centralWidget.setLayout(layout)

		self.list_of_labels: list = []

		self.list_of_mines = generate_mines(self.number_of_mines, X_SIZE, Y_SIZE)

		# RESET BUTTON
		self.reset_button = QPushButton(centralWidget)
		self.reset_button.setText("RESET")
		self.reset_button.clicked.connect(self.reset)
		self.reset_button.setStyleSheet("margin: 3px")
		self.reset_button.setMinimumSize(0, 50)

		# TIMER LABEL
		self.timer_label = QLabel(centralWidget)
		self.timer_label.setText(f"{self.curr_time.minute():0>2}:{self.curr_time.second():0>2}")
		self.timer_label.setAlignment(Qt.AlignHCenter)
		self.timer_label.setStyleSheet("font: 34px")

		# DIFFICULTY SLIDER
		self.difficulty_slider = QSlider(centralWidget)
		self.difficulty_slider.setOrientation(Qt.Horizontal)
		self.difficulty_slider.setFixedHeight(30)
		self.difficulty_slider.setRange(1, 10)
		self.difficulty_slider.setTickInterval(1)
		self.difficulty_slider.setValue(self.difficulty_slider_default_value)
		self.difficulty_slider.valueChanged.connect(self.difficulty_label_set)
		self.difficulty_slider.sliderReleased.connect(self.new_mines_set)

		# DIFFICULTY LABEL
		self.difficulty_label = QLabel(centralWidget)
		self.difficulty_label.setText(str(self.difficulty_slider_default_value))
		self.difficulty_label.setAlignment(Qt.AlignCenter)
		self.difficulty_label.setStyleSheet("font: 20px")
		
		

		for i in range(Y_SIZE):
			row = []
			for j in range(X_SIZE):
				if (i, j) in self.list_of_mines:
					mine = True
				else:
					mine = False

				label = Chunk(j, i, mine)
				label.setFixedSize(FIELD_SQUARE_SIZE, FIELD_SQUARE_SIZE)
				label.setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey")
				layout.addWidget(label, i, j)
				row.append(label)
			self.list_of_labels.append(row)


		self.color_theme_combobox = QComboBox(centralWidget)
		self.color_theme_combobox.addItem("Dark theme", "dark")
		self.color_theme_combobox.addItem("Light theme", "light")
		self.color_theme_combobox.addItem("Color theme", "colorful")
		self.color_theme_combobox.currentIndexChanged.connect(self.theme_change)
		self.color_theme_combobox.setMinimumHeight(FIELD_SQUARE_SIZE * 2)
		if self.theme == "dark":
			self.color_theme_combobox.setCurrentIndex(0)
		elif self.theme == "light":
			self.color_theme_combobox.setCurrentIndex(1)
		else:
			self.color_theme_combobox.setCurrentIndex(2)
		layout.addWidget(self.color_theme_combobox, Y_SIZE - 2, X_SIZE, 2, 1)

		layout.addWidget(self.timer_label, 0, X_SIZE, 3, 1)
		layout.addWidget(self.reset_button, 2, X_SIZE, 3, 1)
		layout.addWidget(self.difficulty_slider, Y_SIZE, 1, 1, X_SIZE - 2)
		layout.addWidget(self.difficulty_label, Y_SIZE, X_SIZE, 1, 1)

		self.mines_number_surroundings_calculate()

	def theme_change(self) -> None:
		if self.color_theme_combobox.currentData() == "light":
			self.undiscovered_color = LIGHT_THEME["undiscovered_color"]
			self.discovered_color = LIGHT_THEME["discovered_color"]
			self.win_timer_color = LIGHT_THEME["win_timer_color"]
			self.lose_timer_color = LIGHT_THEME["lose_timer_color"]
			self.theme = "light"
	
		if self.color_theme_combobox.currentData() == "dark":	
			self.undiscovered_color = DARK_THEME["undiscovered_color"]
			self.discovered_color = DARK_THEME["discovered_color"]
			self.win_timer_color = DARK_THEME["win_timer_color"]
			self.lose_timer_color = DARK_THEME["lose_timer_color"]
			self.theme = "dark"

		if self.color_theme_combobox.currentData() == "colorful":	
			self.undiscovered_color = COLOR_THEME["undiscovered_color"]
			self.discovered_color = COLOR_THEME["discovered_color"]
			self.win_timer_color = COLOR_THEME["win_timer_color"]
			self.lose_timer_color = COLOR_THEME["lose_timer_color"]
			self.theme = "colorful"

		for y in range(Y_SIZE):
			for x in range(X_SIZE):	 
				if self.list_of_labels[y][x].marked:
					pass

				elif not self.list_of_labels[y][x].discovered:
					self.list_of_labels[y][x].setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey")

				elif self.list_of_labels[y][x].discovered:
					self.list_of_labels[y][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
		
	def difficulty_label_set(self):
		self.difficulty_label.setText(str(self.difficulty_slider.value()))

	def mousePressEvent(self, QMouseEvent) -> None:
		if not self.player_ended:

			y = QMouseEvent.pos().x()
			x = QMouseEvent.pos().y()

			if not (x > X_GRID_SIZE or y > Y_GRID_SIZE):

				x = closest_smaller_number(x, Y_POSSIBLE_VALUES)
				y = closest_smaller_number(y, X_POSSIBLE_VALUES)

				x = int(x // FIELD_SQUARE_SIZE)
				y = int(y // FIELD_SQUARE_SIZE)

				if QMouseEvent.button() == Qt.LeftButton:
					if self.list_of_labels[x][y].mine:				
						self.stop_timer()
						if not self.player_ended:
							self.list_of_labels[x][y].discovered = True
							self.list_of_labels[x][y].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
							self.list_of_labels[x][y].setPixmap(QPixmap("C:/Data/python/miny/pracovní verze/pictures/bomb_small.png"))
							self.win_massage.about(self, "PROHRA", "Tentokrát se to bohužel nepovedlo, snad to vyjde příště.")
					
						self.player_ended = True
					else:
						if not self.timer_already_started:
							self.start_timer()

						self.timer_already_started = True
						self.list_of_labels[x][y].discovered = True
						self.list_of_labels[x][y].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")

						self.reveal_area(y, x)

					self.solved_check()

				else:
					if not self.list_of_labels[x][y].discovered:
						if self.list_of_labels[x][y].marked:
							self.list_of_labels[x][y].setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey")
							self.list_of_labels[x][y].marked = False

						else:
							self.list_of_labels[x][y].setStyleSheet("background: orange; border: 1px solid grey")
							self.list_of_labels[x][y].marked = True

	def mines_number_surroundings_calculate(self) -> None:
		for x in range(X_SIZE):
			for y in range(Y_SIZE):
				self.list_of_labels[x][y].mines_number_surroundings = 0
				for i in range(x - 1, x + 2):
					for j in range(y - 1, y + 2):
						try:
							if self.list_of_labels[i][j].mine and i >= 0 and j >= 0:
								if not (i == x and j == y):
									self.list_of_labels[x][y].mines_number_surroundings += 1
						except IndexError:
							pass

	def new_mines_set(self):
		self.number_of_mines = mines_number(NUMBER_OF_LABELS, self.difficulty_slider.value())
		self.list_of_mines = generate_mines(self.number_of_mines, X_SIZE, Y_SIZE)
		for y in range(Y_SIZE):
			for x in range(X_SIZE):
				if (y, x) in self.list_of_mines:
					self.list_of_labels[y][x].mine = True
				else:
					self.list_of_labels[y][x].mine = False

		self.mines_number_surroundings_calculate()
		self.label_set()

	def label_set(self) -> None:
		for y in range(Y_SIZE):
			for x in range(X_SIZE):
				if self.list_of_labels[y][x].discovered:
					if self.list_of_labels[y][x].mines_number_surroundings == 0:
						pass
					else:
						self.list_of_labels[y][x].setText(str(self.list_of_labels[y][x].mines_number_surroundings))

	def reveal_area(self, x: int, y: int) -> None:
		if self.list_of_labels[y][x].mines_number_surroundings == 0:		
			try:
				extract = self.list_of_labels[y - 1][x]

				if not extract.mine and Y_SIZE > y - 1 >= 0 and not extract.discovered:
					self.list_of_labels[y - 1][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
					self.list_of_labels[y - 1][x].discovered = True
					if extract.mines_number_surroundings == 0:
						self.reveal_area(x, y - 1)

			except IndexError:
				pass

			try:
				extract = self.list_of_labels[y + 1][x]

				if not extract.mine and Y_SIZE > y + 1 >= 0 and not extract.discovered:
					self.list_of_labels[y + 1][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
					self.list_of_labels[y + 1][x].discovered = True
					if extract.mines_number_surroundings == 0:
						self.reveal_area(x, y + 1)

			except IndexError:
				pass

			try:
				extract = self.list_of_labels[y][x + 1]

				if not extract.mine and X_SIZE > x + 1 >= 0 and not extract.discovered:
					self.list_of_labels[y][x + 1].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
					self.list_of_labels[y][x + 1].discovered = True
					if extract.mines_number_surroundings == 0:
						self.reveal_area(x + 1, y)

			except IndexError:
				pass

			try:
				extract = self.list_of_labels[y][x - 1]

				if not extract.mine and X_SIZE - 1 > x  - 1 >= 0 and not extract.discovered:
					self.list_of_labels[y][x - 1].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey")
					self.list_of_labels[y][x - 1].discovered = True
					if extract.mines_number_surroundings == 0:
						self.reveal_area(x - 1, y)

			except IndexError:
				pass

		self.label_set()

	def solved_check(self) -> None:
		for element in self.list_of_labels:
			for part in element:
				if not part.mine and not part.discovered:
					return

		self.solved = True
		self.stop_timer()

		if not self.player_ended:
			self.player_ended = True
			self.win_massage.about(self, "VÝHRA", f"Gratuluji, zvládl/a jsi vyřešit tento problém. Zvládl/a jsi to za {self.curr_time.minute():0>2}:{self.curr_time.second():0>2}")

	# TIMER FUNCIONS
	def start_timer(self) -> None:
		self.difficulty_slider.setDisabled(True)
		self.timer.start(1000)
		
	def stop_timer(self) -> None:
		self.timer.stop()
		if not self.solved:
			self.timer_label.setStyleSheet(f"font: 34px; color: {self.win_timer_color}")
		else:
			self.timer_label.setStyleSheet(f"font: 34px; color: {self.lose_timer_color}")

	def time(self) -> None:
		self.curr_time = self.curr_time.addSecs(1)
		self.timer_label.setText(f"{self.curr_time.minute():0>2}:{self.curr_time.second():0>2}")

	#RESET
	def reset(self) -> None:
		self.timer = QTimer()
		self.curr_time = QTime(00,00,00)
		self.timer.timeout.connect(self.time)
		self.solved = False
		self.timer_already_started = False
		self.player_ended = False
		self.difficulty_slider.setDisabled(False)
		self.difficulty_slider_default_value = self.difficulty_slider.value()
		self.create_GUI()
Esempio n. 12
0
class UIBuilder(object):
    """Constructs the UI for a main application window"""
    def setup(self, main_window: QMainWindow) -> None:
        """
        Initialize the UI.

        :param main_window: An instance of the `QMainWindow` class.
        :type main_window: :class:`QMainWindow`
        """
        main_window.setObjectName("main_window")
        main_window.setWindowTitle("TeaseAI")
        main_window.resize(1137, 751)
        main_window.setSizePolicy(*EXP_EXP)
        main_window.setTabShape(QTabWidget.Rounded)

        self.menubar = QMenuBar(main_window)
        self.menubar.setObjectName("menubar")
        self.menubar.setGeometry(0, 0, 1137, 23)
        self.file_menu = QMenu("File", self.menubar)
        self.file_menu.setObjectName("file_men")
        self.server_menu = QMenu("Server", self.menubar)
        self.server_menu.setObjectName("server_men")
        self.options_menu = QMenu("Options", self.menubar)
        self.options_menu.setObjectName("options_men")
        self.media_menu = QMenu("Media", self.menubar)
        self.media_menu.setObjectName("media_men")
        main_window.setMenuBar(self.menubar)

        self.exit = QAction("Exit", main_window)
        self.exit.setObjectName("exit")
        self.start_server = QAction("Start Server", main_window)
        self.start_server.setObjectName("start_server")
        self.connect_server = QAction("Connect to Server", main_window)
        self.connect_server.setObjectName("connect_server")
        self.kill_server = QAction("Kill Server", main_window)
        self.kill_server.setObjectName("kill_server")
        self.options = QAction("Options", main_window)
        self.options.setObjectName("options")
        self.start_webcam = QAction("Start Webcam", main_window)
        self.start_webcam.setObjectName("start_webcam")
        self.start_webcam.setCheckable(False)
        self.centralwidget = QWidget(main_window)
        self.centralwidget.setObjectName("centralwidget")
        self.centralwidget.setContentsMargins(QMargins(0, 0, 0, 0))
        self.centralwidget.setSizePolicy(*EXP_EXP)
        self.grid_layout = QGridLayout(self.centralwidget)

        self.media = QFrame(self.centralwidget)
        self.media.setObjectName("media")
        self.media.setSizePolicy(*EXP_EXP)
        self.media.setMinimumSize(200, 200)
        self.media.setStyleSheet("background: #000;")
        self.grid_layout.addWidget(self.media, 0, 0, 5, 1)

        self.users_label = QLabel(" Online users:", self.centralwidget)
        self.users_label.setObjectName("users_label")
        self.users_label.setMinimumSize(300, 15)
        self.users_label.setMaximumSize(300, 15)
        self.grid_layout.addWidget(self.users_label, 0, 1, 1, 2)

        self.online = QPlainTextEdit("", self.centralwidget)
        self.online.setObjectName("online")
        self.online.setSizePolicy(*FIX_FIX)
        self.online.setMinimumSize(300, 50)
        self.online.setMaximumSize(300, 50)
        self.online.setStyleSheet("margin-left: 3px;" + SUNKEN)
        self.online.setLineWidth(2)
        self.online.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.online.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.online.setSizeAdjustPolicy(QAbstractScrollArea.AdjustIgnored)
        self.online.setReadOnly(True)
        self.grid_layout.addWidget(self.online, 1, 1, 1, 2)

        self.chat = QPlainTextEdit("", self.centralwidget)
        self.chat.setObjectName("chat")
        self.chat.setSizePolicy(*FIX_EXP)
        self.chat.setMinimumSize(300, 0)
        self.chat.setMaximumSize(300, INFINITE)
        self.chat.setStyleSheet("margin-bottom: 3px; margin-top: 8px;" +
                                SUNKEN)
        self.chat.setLineWidth(2)
        self.chat.setReadOnly(True)
        self.chat.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.grid_layout.addWidget(self.chat, 2, 1, 1, 2)

        self.input = QLineEdit(self.centralwidget)
        self.input.setObjectName("input")
        self.input.setSizePolicy(*FIX_FIX)
        self.input.setMinimumSize(224, 30)
        self.input.setMaximumSize(224, 30)
        self.input.setStyleSheet(SUNKEN)
        self.input.setEchoMode(QLineEdit.Normal)
        self.input.setClearButtonEnabled(True)
        self.grid_layout.addWidget(self.input, 3, 1, 1, 1)

        self.submit = QPushButton("Submit", self.centralwidget)
        self.submit.setObjectName("submit")
        self.submit.setSizePolicy(*FIX_FIX)
        self.submit.setMinimumSize(70, 30)
        self.submit.setMaximumSize(70, 30)
        self.grid_layout.addWidget(self.submit, 3, 2, 1, 1)

        self.tabs = QTabWidget(self.centralwidget)
        self.tabs.setObjectName("tabs")
        self.tabs.setSizePolicy(*FIX_FIX)
        self.tabs.setMinimumSize(300, 150)
        self.tabs.setMaximumSize(300, 150)
        self.tab = QWidget()
        self.tab.setObjectName("tab")
        self.tabs.addTab(self.tab, "Actions")
        self.tab2 = QWidget()
        self.tab2.setObjectName("tab2")
        self.tabs.addTab(self.tab2, "My Media")
        self.tab3 = QWidget()
        self.tab3.setObjectName("tab3")
        self.tab3.setSizePolicy(*FIX_FIX)
        self.grid_layout2 = QGridLayout(self.tab3)
        self.grid_layout2.setHorizontalSpacing(0)
        self.grid_layout2.setVerticalSpacing(3)
        self.grid_layout2.setContentsMargins(3, -1, 3, -1)
        self.server_folder = QLineEdit(self.tab3)
        self.server_folder.setObjectName("server_folder")

        self.grid_layout2.addWidget(self.server_folder, 0, 0, 1, 3)
        self.srv_browse = QPushButton("BROWSE", self.tab3)
        self.srv_browse.setObjectName("srv_browse")
        self.srv_browse.setStyleSheet("background: transparent;\n"
                                      "	color: #4d4940;\n"
                                      "    font-size: 8pt;\n"
                                      "	font-weight: 450;\n"
                                      "    padding: 6px;\n")

        self.grid_layout2.addWidget(self.srv_browse, 0, 3, 1, 1)

        self.back_button = QPushButton("", self.tab3)
        self.back_button.setObjectName("back_button")
        self.back_button.setSizePolicy(*FIX_FIX)
        self.back_button.setMaximumSize(SEVENTY_FIVE)
        self.back_button.setCursor(QCursor(Qt.PointingHandCursor))
        self.back_button.setStyleSheet("border: 0;\n"
                                       "background: transparent;")
        icon = QIcon()
        icon.addFile(":/newPrefix/back_button.png", SIXTY_FOUR, QIcon.Normal,
                     QIcon.Off)
        self.back_button.setIcon(icon)
        self.back_button.setIconSize(SIXTY_FOUR)

        self.grid_layout2.addWidget(self.back_button, 1, 0, 1, 1)

        self.play_button = QPushButton("", self.tab3)
        self.play_button.setObjectName("play_button")
        self.play_button.setSizePolicy(*FIX_FIX)
        self.play_button.setMaximumSize(SEVENTY_FIVE)
        self.play_button.setCursor(QCursor(Qt.PointingHandCursor))
        self.play_button.setStyleSheet("border: 0;\n"
                                       "background: transparent;")
        icon1 = QIcon()
        icon1.addFile(":/newPrefix/play_button.png", SIXTY_FOUR, QIcon.Normal,
                      QIcon.Off)
        self.play_button.setIcon(icon1)
        self.play_button.setIconSize(SIXTY_FOUR)

        self.grid_layout2.addWidget(self.play_button, 1, 1, 1, 1)

        self.stop_button = QPushButton("", self.tab3)
        self.stop_button.setObjectName("stop_button")
        self.stop_button.setSizePolicy(*FIX_FIX)
        self.stop_button.setMaximumSize(SEVENTY_FIVE)
        self.stop_button.setCursor(QCursor(Qt.PointingHandCursor))
        self.stop_button.setStyleSheet("border: 0;\n"
                                       "background: transparent;")
        icon2 = QIcon()
        icon2.addFile(":/newPrefix/stop_button.png", SIXTY_FOUR, QIcon.Normal,
                      QIcon.Off)
        self.stop_button.setIcon(icon2)
        self.stop_button.setIconSize(SIXTY_FOUR)

        self.grid_layout2.addWidget(self.stop_button, 1, 2, 1, 1)

        self.fast_forward = QPushButton("", self.tab3)
        self.fast_forward.setObjectName("fast_forward")
        self.fast_forward.setSizePolicy(*FIX_FIX)
        self.fast_forward.setMaximumSize(SEVENTY_FIVE)
        self.fast_forward.setCursor(QCursor(Qt.PointingHandCursor))
        self.fast_forward.setStyleSheet("border: 0;\n"
                                        "background: transparent;")
        icon3 = QIcon()
        icon3.addFile(":/newPrefix/fast_forward.png", SIXTY_FOUR, QIcon.Normal,
                      QIcon.Off)
        self.fast_forward.setIcon(icon3)
        self.fast_forward.setIconSize(SIXTY_FOUR)

        self.grid_layout2.addWidget(self.fast_forward, 1, 3, 1, 1)

        self.tabs.addTab(self.tab3, "Server Media")
        self.grid_layout.addWidget(self.tabs, 4, 1, 1, 2)
        main_window.setCentralWidget(self.centralwidget)

        self.statusbar = QStatusBar(main_window)
        self.statusbar.setObjectName("statusbar")
        self.statusbar.setEnabled(True)
        self.statusbar.setStyleSheet("margin-bottom: 5px;")
        self.statusbar.setSizePolicy(*EXP_FIX)
        self.statusbar.setMinimumSize(INFINITE, 30)
        self.statusbar.setMaximumSize(INFINITE, 30)
        self.statusbar.setSizeGripEnabled(False)
        main_window.setStatusBar(self.statusbar)

        self.menubar.addAction(self.file_menu.menuAction())
        self.menubar.addAction(self.server_menu.menuAction())
        self.menubar.addAction(self.options_menu.menuAction())
        self.menubar.addAction(self.media_menu.menuAction())
        self.file_menu.addAction(self.exit)
        self.server_menu.addAction(self.start_server)
        self.server_menu.addAction(self.connect_server)
        self.server_menu.addAction(self.kill_server)
        self.options_menu.addAction(self.options)
        self.media_menu.addAction(self.start_webcam)
        self.exit.triggered.connect(main_window.close)
        self.tabs.setCurrentIndex(0)
        QMetaObject.connectSlotsByName(main_window)
        self.exit.setStatusTip("Exit the program.")
        self.start_server.setStatusTip("Initialize a local server instance.")
        self.connect_server.setStatusTip("Connect to a remote server.")
        self.kill_server.setStatusTip("Shut down a running local server.")
        self.options.setStatusTip("Open the options menu.")
        self.start_webcam.setStatusTip("Start webcam feed.")
        self.tooltip = QLabel("", self.statusbar)
        tooltip_policy = QSizePolicy(*EXP_FIX)
        tooltip_policy.setHorizontalStretch(100)
        self.tooltip.setSizePolicy(tooltip_policy)
        self.tooltip.setMinimumSize(INFINITE, 26)
        self.tooltip.setMaximumSize(INFINITE, 26)
        self.server_status = QLabel("Server status:", self.statusbar)
        self.server_status.setSizePolicy(*FIX_FIX)
        self.server_status.setMinimumSize(300, 26)
        self.server_status.setMaximumSize(300, 26)
        self.client_status = QLabel("Client status:", self.statusbar)
        self.client_status.setSizePolicy(*FIX_FIX)
        self.client_status.setMinimumSize(302, 26)
        self.client_status.setMaximumSize(302, 26)
        self.statusbar.addPermanentWidget(self.tooltip)
        self.statusbar.addPermanentWidget(self.server_status)
        self.statusbar.addPermanentWidget(self.client_status)
        self.tooltip.setStyleSheet(SUNKEN + "margin-left: 4px;\
            margin-right: 0px;")
        self.client_status.setStyleSheet(SUNKEN + "margin-right: 7px;")
        self.server_status.setStyleSheet(SUNKEN + "margin-right: 2px;\
            margin-left: 2px;")
        self.statusbar.messageChanged.connect(main_window.status_tip)
Esempio n. 13
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(400, 300)
        MainWindow.setWindowTitle(u"\u0421\u0442\u0435\u0433\u0430\u043d\u043e\u0433\u0440\u0430\u0444\u0438\u044f")
        MainWindow.setStyleSheet(u
                                "QMainWindow {\n"
                                "background-color: #f8f9fa;\n"
                                "}\n"
                                "QPushButton:hover {\n"
                                "color: rgb(70, 126, 163);\n"
                                "font: bold 11pt;\n"
                                "}\n"
                                "QPushButton {\n"
                                "color: white;\n"
                                "border:1px solid rgb(82, 108, 125);\n"
                                "border-radius: 6px;\n"
                                "background-color: rgb(82, 108, 125)\n";
                                "}")

        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.verticalLayout = QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.load_button = QPushButton(self.centralwidget)
        self.load_button.setObjectName(u"load_button")
        font = QFont()
        font.setPointSize(9)
        self.load_button.setFont(font)
        self.load_button.setStyleSheet(u"")
        self.load_button.setText(u"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435")

        self.horizontalLayout.addWidget(self.load_button)

        self.save_button = QPushButton(self.centralwidget)
        self.save_button.setObjectName(u"save_button")
        self.save_button.setFont(font)
        self.save_button.setStyleSheet(u"")
        self.save_button.setText(u"\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435")

        self.horizontalLayout.addWidget(self.save_button)


        self.verticalLayout.addLayout(self.horizontalLayout)

        self.message_frame = QTextEdit(self.centralwidget)
        self.message_frame.setObjectName(u"message_frame")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(1)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.message_frame.sizePolicy().hasHeightForWidth())
        self.message_frame.setSizePolicy(sizePolicy)
        font.setPointSize(10)
        self.message_frame.setFont(font)
        font.setPointSize(9)        
        self.message_frame.setStyleSheet(u"")
        self.message_frame.setFrameShape(QFrame.StyledPanel)
        self.message_frame.setMarkdown(u"")
        self.message_frame.setHtml(u"")
        self.message_frame.setPlaceholderText(u"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435")

        self.verticalLayout.addWidget(self.message_frame)

        self.output_label = QLabel(self.centralwidget)
        self.output_label.setObjectName(u"output_label")
        sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy1.setHorizontalStretch(1)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(self.output_label.sizePolicy().hasHeightForWidth())
        self.output_label.setSizePolicy(sizePolicy1)
        font1 = QFont()
        self.output_label.setFont(font1)
        self.output_label.setText(u"")
        self.output_label.setScaledContents(False)
        self.output_label.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop)
        self.output_label.setWordWrap(True)

        self.verticalLayout.addWidget(self.output_label)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.decode_button = QPushButton(self.centralwidget)
        self.decode_button.setObjectName(u"decode_button")
        palette = QPalette()
        brush = QBrush(QColor(255, 255, 255, 255))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Active, QPalette.WindowText, brush)
        brush1 = QBrush(QColor(13, 110, 253, 255))
        brush1.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Active, QPalette.Button, brush1)
        palette.setBrush(QPalette.Active, QPalette.Text, brush)
        palette.setBrush(QPalette.Active, QPalette.ButtonText, brush)
        palette.setBrush(QPalette.Active, QPalette.Base, brush1)
        palette.setBrush(QPalette.Active, QPalette.Window, brush1)
        palette.setBrush(QPalette.Active, QPalette.PlaceholderText, brush)
        palette.setBrush(QPalette.Inactive, QPalette.WindowText, brush)
        palette.setBrush(QPalette.Inactive, QPalette.Button, brush1)
        palette.setBrush(QPalette.Inactive, QPalette.Text, brush)
        palette.setBrush(QPalette.Inactive, QPalette.ButtonText, brush)
        palette.setBrush(QPalette.Inactive, QPalette.Base, brush1)
        palette.setBrush(QPalette.Inactive, QPalette.Window, brush1)
        palette.setBrush(QPalette.Inactive, QPalette.PlaceholderText, brush)
        palette.setBrush(QPalette.Disabled, QPalette.WindowText, brush)
        palette.setBrush(QPalette.Disabled, QPalette.Button, brush1)
        palette.setBrush(QPalette.Disabled, QPalette.Text, brush)
        palette.setBrush(QPalette.Disabled, QPalette.ButtonText, brush)
        palette.setBrush(QPalette.Disabled, QPalette.Base, brush1)
        palette.setBrush(QPalette.Disabled, QPalette.Window, brush1)
        palette.setBrush(QPalette.Disabled, QPalette.PlaceholderText, brush)
        self.decode_button.setPalette(palette)
        self.decode_button.setFont(font)
        self.decode_button.setStyleSheet(u"")
        self.decode_button.setText(u"\u0414\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442")

        self.horizontalLayout_2.addWidget(self.decode_button)

        self.encode_button = QPushButton(self.centralwidget)
        self.encode_button.setObjectName(u"encode_button")
        self.encode_button.setFont(font)
        self.encode_button.setStyleSheet(u"")
        self.encode_button.setText(u"\u0417\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442")

        self.horizontalLayout_2.addWidget(self.encode_button)


        self.verticalLayout.addLayout(self.horizontalLayout_2)

        MainWindow.setCentralWidget(self.centralwidget)
        QWidget.setTabOrder(self.load_button, self.save_button)
        QWidget.setTabOrder(self.save_button, self.encode_button)
        QWidget.setTabOrder(self.encode_button, self.decode_button)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        pass
Esempio n. 14
0
class MyWidget(QtWidgets.QWidget):
    def __init__(self, game):
        super().__init__()

        self.game = game
        self.level = QLabel(f'Уровень: {self.game.cur_level}')
        self.river = QLabel(
            f'Процент загрязнения реки: {self.game.river.mud_level}%')
        self.level.setFont(QFont('Times', 28))
        self.river.setFont(QFont('Times', 24))

        self.money = []
        self.pictures = []
        for i, fact in enumerate(game.factories):
            label = QLabel()
            img = QPixmap('pictures/factory1.png')

            self.money.append(QLabel(str(fact.money)))
            if i == self.game.cur_factory:
                self.money[i].setFont(QFont('Times', 24, QFont.Bold))
                img = img.scaled(280, 280, QtCore.Qt.KeepAspectRatio)
            else:
                self.money[i].setFont(QFont('Times', 14))
                img = img.scaled(200, 200, QtCore.Qt.KeepAspectRatio)

            label.setPixmap(img)
            self.pictures.append(label)

        self.button_work = QPushButton('Работать')
        self.button_work_and_clean = QPushButton('Работать и очистить реку')
        self.button_do_nothing = QPushButton('Простаивать')

        self.main_layout = QtWidgets.QVBoxLayout(self)
        self.main_layout.addWidget(self.level)
        self.main_layout.addWidget(self.river)

        self.factories_layout = QtWidgets.QHBoxLayout()
        for picture in self.pictures:
            self.factories_layout.addWidget(picture)
            picture.setAlignment(QtCore.Qt.AlignCenter)

        self.money_layout = QtWidgets.QHBoxLayout()
        for money in self.money:
            self.money_layout.addWidget(money)
            money.setAlignment(QtCore.Qt.AlignCenter)

        self.main_layout.addLayout(self.factories_layout)
        self.main_layout.addLayout(self.money_layout)
        self.main_layout.addWidget(self.button_work)
        self.main_layout.addWidget(self.button_work_and_clean)
        self.main_layout.addWidget(self.button_do_nothing)

        self.button_work_and_clean.clicked.connect(self.work_and_clean)
        self.button_work.clicked.connect(self.work)
        self.button_do_nothing.clicked.connect(self.do_nothing)

        with open('style.css') as f:
            style = f.read()
            self.level.setStyleSheet(style)
            self.button_work.setStyleSheet(style)
            self.button_work_and_clean.setStyleSheet(style)
            self.button_do_nothing.setStyleSheet(style)

    def work_and_clean(self):
        self.game.work_and_clean_factory()
        self.update()

    def work(self):
        self.game.work_factory()
        self.update()

    def do_nothing(self):
        self.game.do_nothing_factory()
        self.update()

    def update(self):
        for i, fact in enumerate(self.game.factories):
            img = QPixmap('pictures/factory1.png')
            self.money[i].setText(str(fact.money))
            if i == self.game.cur_factory:
                self.money[i].setFont(QFont('Times', 24, QFont.Bold))
                img = img.scaled(280, 280, QtCore.Qt.KeepAspectRatio)
            else:
                self.money[i].setFont(QFont('Times', 14))
                img = img.scaled(200, 200, QtCore.Qt.KeepAspectRatio)

            self.pictures[i].setPixmap(img)

        self.level.setText(f'Уровень: {self.game.cur_level}')
        self.river.setText(
            f'Процент загрязнения реки: {self.game.river.mud_level}%')
Esempio n. 15
0
def _style_button(button: QtWidgets.QPushButton) -> None:
    button.setStyleSheet(
        "QPushButton:pressed {background-color: rgb(164, 168, 188)}"
        "QPushButton {background-color: rgb(114, 118, 138);"
        "border: 1px solid black; padding: 4px}"
        "QPushButton:disabled { background-color: rgb(50, 54, 76) }")
Esempio n. 16
0
class SecondWidget1(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        layout = QtWidgets.QVBoxLayout(self)
        label1 = QLabel('입력', self)
        label1.setAlignment(Qt.AlignVCenter)
        label1.move(200, 30)

        label2 = QLabel('결과', self)
        label2.setAlignment(Qt.AlignVCenter)
        label2.move(710, 30)

        self.text_box1 = QTextEdit(self)
        self.text_box1.resize(350, 350)
        self.text_box1.move(50, 60)

        self.text_box2 = QTextBrowser(self)
        self.text_box2.append('')
        self.text_box2.setGeometry(550, 60, 350, 350) 

        self.ok_base64 = QPushButton("OK", self)	
        self.ok_base64.setGeometry(50, 420, 850, 45) 
        self.ok_base64.clicked.connect(self.base64_conversion)

        self.back = QPushButton(self)
        self.back.setStyleSheet(
            '''
            QPushButton{image:url(./img/back_img.png); border:0px;}
            QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;}
            ''') 
        self.back.setGeometry(0, 0, 50, 50) 
        self.back.clicked.connect(self.change_stack1)

    def base64_conversion(self):
        '''
        QTextEdit 사용 경우 .toPlainText() 사용 바람
        https://doc.qt.io/qt-5/qplaintextedit.html#plainText-prop 참조
        '''
        # print(self.text_box1.toPlainText())

        # Base64 변환 과정
        inpututf = self.text_box1.toPlainText().encode('utf-8') # ascii 사용시 오류발생 utf-8으로 사용하세요
        finalvalue = base64.b64encode(inpututf)
        print(finalvalue)

        '''
        내용 수정또는 추가시 내용 초기화
        https://study-code.gitbook.io/python-basic/qtpy/pyqt-widget/application-make/widget-2#undefined-1 참조
        '''
        self.text_box2.clear()
        self.text_box2.repaint()

        '''
        "b"와 따옴표없이 출력 .decode("utf-8")
        https://stackoverflow.com/a/45151048 참조
        '''
        self.text_box2.append(str(finalvalue.decode("utf-8")))

        
    def change_stack(self):
        self.parent().stack.setCurrentIndex(0)

    def change_stack1(self):
        self.parent().stack.setCurrentIndex(1)
Esempio n. 17
0
class Homepage(QWidget):
    def __init__(self):
        super().__init__()

        # Declare Widgets
        self.homepage_label = QLabel('Home')
        self.search_label = QLabel('Find an Image!')
        self.srch_box = QLineEdit()  # input field for search
        self.srch_btn = QPushButton("Search")

        # Create U.I. Layout
        mbox = QVBoxLayout()  # Main layout

        vbox = QVBoxLayout()  # Layout for search feature
        vbox.addWidget(self.homepage_label)
        vbox.addWidget(self.search_label)
        vbox.addWidget(self.srch_box)
        vbox.addWidget(self.srch_btn)

        gbox1 = QGroupBox()  # Set group for search feature layout
        gbox1.setLayout(vbox)
        mbox.addWidget(gbox1)

        # Home Images
        images = []
        images = self.getHomepageImages()

        # Create layout for images
        vbox2 = QHBoxLayout()  # horizontal layout

        i = 0
        for img in images:  # iterate through images list
            self.label = QLabel()

            pixmap1 = QPixmap(img)  # set image
            pixmap1 = pixmap1.scaled(300, 300, Qt.KeepAspectRatio)

            self.label.setPixmap(pixmap1)

            temp_vbox = QVBoxLayout()
            temp_vbox.addWidget(self.label)

            gbox2 = QGroupBox()  # group box for current image
            gbox2.setLayout(temp_vbox)
            gbox2.setStyleSheet("background-color: grey")

            vbox2.addWidget(gbox2)
            i += 1

        gbox3 = QGroupBox()  # main group box for images
        gbox3.setLayout(vbox2)
        mbox.addWidget(gbox3)
        self.setLayout(mbox)

        # Styling
        self.setStyleSheet("""
            color: orange;
            font-family: Comfortaa;
            """)
        self.srch_btn.setStyleSheet(":hover { background-color:cyan }")
        gbox1.setStyleSheet("""
            font-size: 18px
            """)

        # Listeners
        self.srch_btn.clicked.connect(self.find_images)

    # Function to find multiple images by keyword(s)
    @Slot()
    def find_images(self):
        print("Finding Match...")

        payload = {  # pass parameters
            'client_id': api_key,
            'query': self.srch_box.text(),
            'page': 1,
            'per_page': 5
        }
        endpoint = 'https://api.unsplash.com/search/photos'  # define endpoint
        try:
            request = requests.get(endpoint, params=payload)
            data = request.json()
            pprint(data)
        except:
            print('please try again')

        if data:  # iterate through retrieved json object
            i = 0
            imgs = []
            for image in data['results']:
                im = Image.open(
                    requests.get(image['urls']['full'],
                                 stream=True).raw)  # get image from json
                imgs.append(image)
                with open("./results/result" + str(i), "wb") as myfile:
                    pickle.dump(image, myfile)
                name = "./results/result" + str(i) + ".jpg"
                i += 1
            window.createNewTab(imgs)
        else:
            print('no data')

    def getHomepageImages(self):
        home_images = []
        print("Finding Match...")

        payload = {'client_id': api_key, 'count': 3}
        endpoint = 'https://api.unsplash.com/photos/random'  # use this endpoint for random images
        try:
            request = requests.get(endpoint, params=payload)
            data = request.json()
            pprint(data)
        except:
            print('please try again')

        i = 1
        if data:
            for image in data:
                im = Image.open(
                    requests.get(image['urls']['thumb'], stream=True).raw)

                loc = image['links']['html']
                print(loc)

                im_name = "image" + str(i) + ".jpg"
                im_path = "home_images/" + im_name
                im.save(im_path)
                home_images.append(im_path)
                i += 1
            return home_images
        else:
            print('no data')
Esempio n. 18
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(450, 520)
        MainWindow.setMinimumSize(QSize(450, 520))
        MainWindow.setMaximumSize(QSize(450, 520))
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.bg_frame_2 = QVBoxLayout(self.centralwidget)
        self.bg_frame_2.setSpacing(0)
        self.bg_frame_2.setObjectName(u"bg_frame_2")
        self.bg_frame_2.setContentsMargins(10, 10, 10, 10)
        self.bg_frame = QFrame(self.centralwidget)
        self.bg_frame.setObjectName(u"bg_frame")
        self.bg_frame.setStyleSheet(u"background-color: rgb(29, 0, 86);\n"
                                    "border-radius: 10px;")
        self.bg_frame.setFrameShape(QFrame.NoFrame)
        self.bg_frame.setFrameShadow(QFrame.Raised)
        self.tittle_bar = QFrame(self.bg_frame)
        self.tittle_bar.setObjectName(u"tittle_bar")
        self.tittle_bar.setGeometry(QRect(10, 10, 411, 31))
        self.tittle_bar.setFrameShape(QFrame.StyledPanel)
        self.tittle_bar.setFrameShadow(QFrame.Raised)
        self.label = QLabel(self.tittle_bar)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(10, 0, 61, 31))
        self.label.setStyleSheet(u"color: rgb(255, 255, 255);\n"
                                 "font: 18pt \"Segoe UI\";")
        self.button_close = QPushButton(self.tittle_bar)
        self.button_close.setObjectName(u"button_close")
        self.button_close.setGeometry(QRect(380, 0, 21, 24))
        self.button_close.setStyleSheet(u"background-color: rgb(152, 0, 0);\n"
                                        "font: 14pt \"Segoe UI\";")
        self.button_minimize = QPushButton(self.tittle_bar)
        self.button_minimize.setObjectName(u"button_minimize")
        self.button_minimize.setGeometry(QRect(350, 0, 21, 24))
        self.button_minimize.setStyleSheet(
            u"background-color: rgb(53, 159, 159);\n"
            "font: 14pt \"Segoe UI\";")
        self.user_login = QLineEdit(self.bg_frame)
        self.user_login.setObjectName(u"user_login")
        self.user_login.setGeometry(QRect(60, 160, 301, 51))
        self.user_login.setStyleSheet(u"background-color: rgb(53, 159, 159);\n"
                                      "")
        self.pass_login = QLineEdit(self.bg_frame)
        self.pass_login.setObjectName(u"pass_login")
        self.pass_login.setGeometry(QRect(60, 281, 301, 51))
        self.pass_login.setStyleSheet(u"background-color: rgb(53, 159, 159);\n"
                                      "")
        self.user_lbl = QLabel(self.bg_frame)
        self.user_lbl.setObjectName(u"user_lbl")
        self.user_lbl.setGeometry(QRect(170, 110, 81, 41))
        self.user_lbl.setStyleSheet(u"color: rgb(255, 255, 255);\n"
                                    "font: 18pt \"Segoe UI\";")
        self.senha_lbl = QLabel(self.bg_frame)
        self.senha_lbl.setObjectName(u"senha_lbl")
        self.senha_lbl.setGeometry(QRect(179, 230, 71, 41))
        self.senha_lbl.setStyleSheet(u"color: rgb(255, 255, 255);\n"
                                     "font: 18pt \"Segoe UI\";")
        self.btn_login = QPushButton(self.bg_frame)
        self.btn_login.setObjectName(u"btn_login")
        self.btn_login.setGeometry(QRect(160, 360, 101, 41))
        self.btn_login.setStyleSheet(u"background-color: rgb(53, 159, 159);\n"
                                     "color: rgb(255, 255, 255);\n"
                                     "font: 18pt \"Segoe UI\";\n"
                                     "")

        self.bg_frame_2.addWidget(self.bg_frame)

        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)

    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(
            QCoreApplication.translate("MainWindow", u"Login", None))
        self.label.setText(
            QCoreApplication.translate("MainWindow", u"Login", None))
        self.button_close.setText(
            QCoreApplication.translate("MainWindow", u"x", None))
        self.button_minimize.setText(
            QCoreApplication.translate("MainWindow", u"-", None))
        self.user_lbl.setText(
            QCoreApplication.translate("MainWindow", u"Usu\u00e1rio", None))
        self.senha_lbl.setText(
            QCoreApplication.translate("MainWindow", u"Senha", None))
        self.btn_login.setText(
            QCoreApplication.translate("MainWindow", u"Logar", None))
Esempio n. 19
0
class CsgoBindGenerator(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("CS:GO Bind Generator")
        self.setFixedSize(1700, 500)

        self.centralWidget = QWidget(self)
        self.setCentralWidget(self.centralWidget)
        self.layout = QGridLayout(self.centralWidget)
        self.centralWidget.setLayout(self.layout)

        self.create_GUI()

    def create_GUI(self) -> None:
        self.commands_display = QTextEdit(self)
        font = self.commands_display.font()
        font.setPointSize(10)
        self.commands_display.setFont(font)

        self.commands_display.setReadOnly(True)
        place_holder: str = "1. Choose Action | 2. Pick a Key to be Bound | 3. Select a Gun/Equipment"
        self.commands_display.setPlaceholderText(place_holder)

        self.f1 = QPushButton(self.centralWidget)
        self.f2 = QPushButton(self.centralWidget)
        self.f3 = QPushButton(self.centralWidget)
        self.f4 = QPushButton(self.centralWidget)
        self.f5 = QPushButton(self.centralWidget)
        self.f6 = QPushButton(self.centralWidget)
        self.f7 = QPushButton(self.centralWidget)
        self.f8 = QPushButton(self.centralWidget)
        self.f9 = QPushButton(self.centralWidget)
        self.f10 = QPushButton(self.centralWidget)
        self.f11 = QPushButton(self.centralWidget)
        self.f12 = QPushButton(self.centralWidget)

        self.acute = QPushButton(self.centralWidget)
        self.one = QPushButton(self.centralWidget)
        self.two = QPushButton(self.centralWidget)
        self.three = QPushButton(self.centralWidget)
        self.four = QPushButton(self.centralWidget)
        self.five = QPushButton(self.centralWidget)
        self.six = QPushButton(self.centralWidget)
        self.seven = QPushButton(self.centralWidget)
        self.eight = QPushButton(self.centralWidget)
        self.nine = QPushButton(self.centralWidget)
        self.zero = QPushButton(self.centralWidget)
        self.minus = QPushButton(self.centralWidget)
        self.equal = QPushButton(self.centralWidget)
        self.backspace = QPushButton(self.centralWidget)

        self.tab = QPushButton(self.centralWidget)
        self.q = QPushButton(self.centralWidget)
        self.w = QPushButton(self.centralWidget)
        self.e = QPushButton(self.centralWidget)
        self.r = QPushButton(self.centralWidget)
        self.t = QPushButton(self.centralWidget)
        self.y = QPushButton(self.centralWidget)
        self.u = QPushButton(self.centralWidget)
        self.i = QPushButton(self.centralWidget)
        self.o = QPushButton(self.centralWidget)
        self.p = QPushButton(self.centralWidget)
        self.open_bracket = QPushButton(self.centralWidget)
        self.closed_bracket = QPushButton(self.centralWidget)
        self.backslash = QPushButton(self.centralWidget)

        self.capslock = QPushButton(self.centralWidget)
        self.a = QPushButton(self.centralWidget)
        self.s = QPushButton(self.centralWidget)
        self.d = QPushButton(self.centralWidget)
        self.f = QPushButton(self.centralWidget)
        self.g = QPushButton(self.centralWidget)
        self.h = QPushButton(self.centralWidget)
        self.j = QPushButton(self.centralWidget)
        self.k = QPushButton(self.centralWidget)
        self.l = QPushButton(self.centralWidget)
        self.semicolon = QPushButton(self.centralWidget)
        self.apostrophe = QPushButton(self.centralWidget)
        self.enter = QPushButton(self.centralWidget)

        self.left_shift = QPushButton(self.centralWidget)
        self.z = QPushButton(self.centralWidget)
        self.x = QPushButton(self.centralWidget)
        self.c = QPushButton(self.centralWidget)
        self.v = QPushButton(self.centralWidget)
        self.b = QPushButton(self.centralWidget)
        self.n = QPushButton(self.centralWidget)
        self.m = QPushButton(self.centralWidget)
        self.comma = QPushButton(self.centralWidget)
        self.dot = QPushButton(self.centralWidget)
        self.slash = QPushButton(self.centralWidget)
        self.right_shift = QPushButton(self.centralWidget)

        self.left_ctrl = QPushButton(self.centralWidget)
        self.right_alt = QPushButton(self.centralWidget)
        self.space = QPushButton(self.centralWidget)
        self.left_alt = QPushButton(self.centralWidget)
        self.right_ctrl = QPushButton(self.centralWidget)

        self.insert = QPushButton(self.centralWidget)
        self.home = QPushButton(self.centralWidget)
        self.pgup = QPushButton(self.centralWidget)
        self.delete = QPushButton(self.centralWidget)
        self.end = QPushButton(self.centralWidget)
        self.pgdn = QPushButton(self.centralWidget)
        self.uparrow = QPushButton(self.centralWidget)
        self.leftarrow = QPushButton(self.centralWidget)
        self.downarrow = QPushButton(self.centralWidget)
        self.rightarrow = QPushButton(self.centralWidget)

        self.numlock = QPushButton(self.centralWidget)
        self.kp_slash = QPushButton(self.centralWidget)
        self.kp_multiply = QPushButton(self.centralWidget)
        self.kp_minus = QPushButton(self.centralWidget)
        self.kp_home = QPushButton(self.centralWidget)
        self.kp_uparrow = QPushButton(self.centralWidget)
        self.kp_pgup = QPushButton(self.centralWidget)
        self.kp_plus = QPushButton(self.centralWidget)
        self.kp_plus.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.kp_leftarrow = QPushButton(self.centralWidget)
        self.kp_five = QPushButton(self.centralWidget)
        self.kp_rightarrow = QPushButton(self.centralWidget)
        self.kp_end = QPushButton(self.centralWidget)
        self.kp_downarrow = QPushButton(self.centralWidget)
        self.kp_pgdn = QPushButton(self.centralWidget)
        self.kp_enter = QPushButton(self.centralWidget)
        self.kp_enter.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.kp_insert = QPushButton(self.centralWidget)
        self.kp_delete = QPushButton(self.centralWidget)

        self.buy = QPushButton(self.centralWidget)
        self.buy.setStyleSheet("QPushButton" "{" "font-size: 17px;" "}")
        self.buy.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.hand_switch = QPushButton(self.centralWidget)
        self.clear_decals = QPushButton(self.centralWidget)
        self.bind_grenade = QPushButton(self.centralWidget)
        self.voice_mute = QPushButton(self.centralWidget)
        self.bomb_drop = QPushButton(self.centralWidget)
        self.copy = QPushButton(self.centralWidget)
        self.reset = QPushButton(self.centralWidget)

        self.ak47 = QPushButton(self.centralWidget)
        self.ak47.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.m4s = QPushButton(self.centralWidget)
        self.m4s.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.aug = QPushButton(self.centralWidget)
        self.sg = QPushButton(self.centralWidget)
        self.awp = QPushButton(self.centralWidget)
        self.ssg = QPushButton(self.centralWidget)
        self.famas = QPushButton(self.centralWidget)
        self.galil = QPushButton(self.centralWidget)

        self.mac10 = QPushButton(self.centralWidget)
        self.mp9 = QPushButton(self.centralWidget)
        self.mp7 = QPushButton(self.centralWidget)
        self.ump = QPushButton(self.centralWidget)
        self.bizon = QPushButton(self.centralWidget)
        self.p90 = QPushButton(self.centralWidget)
        self.mp5 = QPushButton(self.centralWidget)

        self.xm = QPushButton(self.centralWidget)
        self.sawedoff = QPushButton(self.centralWidget)
        self.mag7 = QPushButton(self.centralWidget)

        self.p250 = QPushButton(self.centralWidget)
        self.cz75 = QPushButton(self.centralWidget)
        self.tec9 = QPushButton(self.centralWidget)
        self.fiveseven = QPushButton(self.centralWidget)
        self.deagle = QPushButton(self.centralWidget)
        self.revolver = QPushButton(self.centralWidget)

        self.nade = QPushButton(self.centralWidget)
        self.flash = QPushButton(self.centralWidget)
        self.double_flash = QPushButton(self.centralWidget)
        self.smoke = QPushButton(self.centralWidget)
        self.molotov = QPushButton(self.centralWidget)
        self.inc_grenade = QPushButton(self.centralWidget)

        self.vest = QPushButton(self.centralWidget)
        self.vest.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.vest_helmet = QPushButton(self.centralWidget)
        self.vest_helmet.setSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Expanding)
        self.defuse_kit = QPushButton(self.centralWidget)

        self.mouse3 = QPushButton(self.centralWidget)
        self.mouse3.setStyleSheet("margin-top: 25px;" "margin-bottom: 10px;")
        self.mouse4 = QPushButton(self.centralWidget)
        self.mouse4.setStyleSheet("margin-top: 25px;" "margin-bottom: 10px;")
        self.mouse5 = QPushButton(self.centralWidget)
        self.mouse5.setStyleSheet("margin-top: 25px;" "margin-bottom: 10px;")

        self.f1.setText("F1")
        self.f2.setText("F2")
        self.f3.setText("F3")
        self.f4.setText("F4")
        self.f5.setText("F5")
        self.f6.setText("F6")
        self.f7.setText("F7")
        self.f8.setText("F8")
        self.f9.setText("F9")
        self.f10.setText("F10")
        self.f11.setText("F11")
        self.f12.setText("F12")
        self.acute.setText("`")
        self.one.setText("1")
        self.two.setText("2")
        self.three.setText("3")
        self.four.setText("4")
        self.five.setText("5")
        self.six.setText("6")
        self.seven.setText("7")
        self.eight.setText("8")
        self.nine.setText("9")
        self.zero.setText("0")
        self.minus.setText("-")
        self.equal.setText("=")
        self.backspace.setText("Backspace")
        self.tab.setText("TAB")
        self.q.setText("Q")
        self.w.setText("W")
        self.e.setText("E")
        self.r.setText("R")
        self.t.setText("T")
        self.y.setText("Y")
        self.u.setText("U")
        self.i.setText("I")
        self.o.setText("O")
        self.p.setText("P")
        self.open_bracket.setText("[")
        self.closed_bracket.setText("]")
        self.backslash.setText("\\")
        self.capslock.setText("Caps Lock")
        self.a.setText("A")
        self.s.setText("S")
        self.d.setText("D")
        self.f.setText("F")
        self.g.setText("G")
        self.h.setText("H")
        self.j.setText("J")
        self.k.setText("K")
        self.l.setText("L")
        self.semicolon.setText(";")
        self.apostrophe.setText("'")
        self.enter.setText("Enter")
        self.left_shift.setText("Shift")
        self.z.setText("Z")
        self.x.setText("X")
        self.c.setText("C")
        self.v.setText("V")
        self.b.setText("B")
        self.n.setText("N")
        self.m.setText("M")
        self.comma.setText(",")
        self.dot.setText(".")
        self.slash.setText("/")
        self.right_shift.setText("Shift")
        self.left_ctrl.setText("Ctrl")
        self.left_alt.setText("Alt")
        self.space.setText("Space")
        self.right_alt.setText("Alt")
        self.right_ctrl.setText("Ctrl")
        self.insert.setText("Insert")
        self.home.setText("Home")
        self.pgup.setText("PgUp")
        self.delete.setText("Del")
        self.end.setText("End")
        self.pgdn.setText("PgDn")
        self.uparrow.setText("↑")
        self.leftarrow.setText("←")
        self.downarrow.setText("↓")
        self.rightarrow.setText("→")
        self.numlock.setText("Num Lock")
        self.kp_slash.setText("/")
        self.kp_multiply.setText("*")
        self.kp_minus.setText("-")
        self.kp_home.setText("7")
        self.kp_uparrow.setText("8")
        self.kp_pgup.setText("9")
        self.kp_plus.setText("+")
        self.kp_leftarrow.setText("4")
        self.kp_five.setText("5")
        self.kp_rightarrow.setText("6")
        self.kp_end.setText("1")
        self.kp_downarrow.setText("2")
        self.kp_pgdn.setText("3")
        self.kp_enter.setText("Enter")
        self.kp_insert.setText("0")
        self.kp_delete.setText(".")

        self.buy.setText("BUY")
        self.bind_grenade.setText("Bind Grenades")
        self.voice_mute.setText("Mute Voice Chat")
        self.bomb_drop.setText("Bomb Drop")
        self.reset.setText("RESET")
        self.clear_decals.setText("Clear Decals")
        self.hand_switch.setText("Switch Hands")
        self.copy.setText("Copy to Clipboard")
        self.mouse3.setText("Mouse 3")
        self.mouse4.setText("Mouse 4")
        self.mouse5.setText("Mouse 5")

        self.ak47.setText("AK-47")
        self.m4s.setText("M4A4/1-S")
        self.aug.setText("AUG")
        self.sg.setText("SG 553")
        self.awp.setText("AWP")
        self.galil.setText("Galil AR")
        self.famas.setText("FAMAS")
        self.ssg.setText("SSG 08")

        self.mac10.setText("MAC-10")
        self.mp9.setText("MP9")
        self.mp7.setText("MP7")
        self.bizon.setText("PP-Bizon")
        self.p90.setText("P90")
        self.ump.setText("UMP-45")
        self.mp5.setText("MP5-SD")

        self.mag7.setText("MAG-7")
        self.sawedoff.setText("Sawed-Off")
        self.xm.setText("XM1014")

        self.p250.setText("P250")
        self.cz75.setText("CZ75-Auto")
        self.fiveseven.setText("Five-SeveN")
        self.tec9.setText("Tec-9")
        self.deagle.setText("Desert Eagle")
        self.revolver.setText("R8 Revolver")

        self.vest.setText("Kevlar Vest")
        self.vest_helmet.setText(f"Kevlar\n +\nHelmet")
        self.defuse_kit.setText("Defuse Kit")

        self.flash.setText("Flash")
        self.double_flash.setText("2x Flash")
        self.nade.setText("Grenade")
        self.smoke.setText("Smoke")
        self.inc_grenade.setText("INC-Grenade")
        self.molotov.setText("Molotov")

        self.layout.addWidget(self.commands_display, 0, 5, 5, 7)

        self.layout.addWidget(self.bind_grenade, 0, 0, 1, 2)
        self.layout.addWidget(self.bomb_drop, 1, 0, 1, 2)
        self.layout.addWidget(self.voice_mute, 2, 0, 1, 2)
        self.layout.addWidget(self.hand_switch, 3, 0, 1, 2)
        self.layout.addWidget(self.clear_decals, 4, 0, 1, 2)

        self.layout.addWidget(self.buy, 0, 3, 2, 2)
        self.layout.addWidget(self.reset, 3, 3, 1, 2)
        self.layout.addWidget(self.copy, 4, 3, 1, 2)

        self.layout.addWidget(self.ak47, 0, 12, 2, 1)
        self.layout.addWidget(self.m4s, 0, 13, 2, 1)
        self.layout.addWidget(self.vest, 2, 12, 2, 1)
        self.layout.addWidget(self.vest_helmet, 2, 13, 2, 1)
        self.layout.addWidget(self.defuse_kit, 4, 12)
        self.layout.addWidget(self.double_flash, 4, 13)

        self.layout.addWidget(self.flash, 0, 14)
        self.layout.addWidget(self.smoke, 1, 14)
        self.layout.addWidget(self.nade, 2, 14)
        self.layout.addWidget(self.inc_grenade, 3, 14)
        self.layout.addWidget(self.molotov, 4, 14)

        self.layout.addWidget(self.awp, 0, 15)
        self.layout.addWidget(self.deagle, 1, 15)

        self.layout.addWidget(self.aug, 0, 16)
        self.layout.addWidget(self.sg, 1, 16)
        self.layout.addWidget(self.famas, 3, 16)
        self.layout.addWidget(self.galil, 2, 16)
        self.layout.addWidget(self.ssg, 4, 16)

        self.layout.addWidget(self.fiveseven, 0, 17)
        self.layout.addWidget(self.tec9, 1, 17)
        self.layout.addWidget(self.cz75, 3, 17)
        self.layout.addWidget(self.p250, 2, 17)
        self.layout.addWidget(self.revolver, 4, 17)

        self.layout.addWidget(self.mac10, 0, 18)
        self.layout.addWidget(self.mp9, 1, 18)
        self.layout.addWidget(self.mp7, 2, 18)
        self.layout.addWidget(self.ump, 3, 18)
        self.layout.addWidget(self.p90, 4, 18)

        self.layout.addWidget(self.mp5, 0, 19)
        self.layout.addWidget(self.bizon, 1, 19)
        self.layout.addWidget(self.mag7, 2, 19)
        self.layout.addWidget(self.sawedoff, 3, 19)
        self.layout.addWidget(self.xm, 4, 19)

        self.layout.addWidget(self.mouse3, 5, 7)
        self.layout.addWidget(self.mouse4, 5, 8)
        self.layout.addWidget(self.mouse5, 5, 9)

        self.layout.addWidget(self.f1, 6, 0)
        self.layout.addWidget(self.f2, 6, 1)
        self.layout.addWidget(self.f3, 6, 2)
        self.layout.addWidget(self.f4, 6, 3)
        self.layout.addWidget(self.f5, 6, 4)
        self.layout.addWidget(self.f6, 6, 5)
        self.layout.addWidget(self.f7, 6, 6)
        self.layout.addWidget(self.f8, 6, 7)
        self.layout.addWidget(self.f9, 6, 8)
        self.layout.addWidget(self.f10, 6, 9)
        self.layout.addWidget(self.f11, 6, 10)
        self.layout.addWidget(self.f12, 6, 11)

        self.layout.addWidget(self.acute, 7, 0)
        self.layout.addWidget(self.one, 7, 1)
        self.layout.addWidget(self.two, 7, 2)
        self.layout.addWidget(self.three, 7, 3)
        self.layout.addWidget(self.four, 7, 4)
        self.layout.addWidget(self.five, 7, 5)
        self.layout.addWidget(self.six, 7, 6)
        self.layout.addWidget(self.seven, 7, 7)
        self.layout.addWidget(self.eight, 7, 8)
        self.layout.addWidget(self.nine, 7, 9)
        self.layout.addWidget(self.zero, 7, 10)
        self.layout.addWidget(self.minus, 7, 11)
        self.layout.addWidget(self.equal, 7, 12)
        self.layout.addWidget(self.backspace, 7, 13)
        self.layout.addWidget(self.insert, 7, 14)
        self.layout.addWidget(self.home, 7, 15)
        self.layout.addWidget(self.pgup, 7, 16)
        self.layout.addWidget(self.numlock, 7, 17)
        self.layout.addWidget(self.kp_slash, 7, 18)
        self.layout.addWidget(self.kp_multiply, 7, 19)
        self.layout.addWidget(self.kp_minus, 7, 20)

        self.layout.addWidget(self.tab, 8, 0)
        self.layout.addWidget(self.q, 8, 1)
        self.layout.addWidget(self.w, 8, 2)
        self.layout.addWidget(self.e, 8, 3)
        self.layout.addWidget(self.r, 8, 4)
        self.layout.addWidget(self.t, 8, 5)
        self.layout.addWidget(self.y, 8, 6)
        self.layout.addWidget(self.u, 8, 7)
        self.layout.addWidget(self.i, 8, 8)
        self.layout.addWidget(self.o, 8, 9)
        self.layout.addWidget(self.p, 8, 10)
        self.layout.addWidget(self.open_bracket, 8, 11)
        self.layout.addWidget(self.closed_bracket, 8, 12)
        self.layout.addWidget(self.backslash, 8, 13)
        self.layout.addWidget(self.delete, 8, 14)
        self.layout.addWidget(self.end, 8, 15)
        self.layout.addWidget(self.pgdn, 8, 16)
        self.layout.addWidget(self.kp_home, 8, 17)
        self.layout.addWidget(self.kp_uparrow, 8, 18)
        self.layout.addWidget(self.kp_pgup, 8, 19)
        self.layout.addWidget(self.kp_plus, 8, 20, 2, 1)

        self.layout.addWidget(self.capslock, 9, 0)
        self.layout.addWidget(self.a, 9, 1)
        self.layout.addWidget(self.s, 9, 2)
        self.layout.addWidget(self.d, 9, 3)
        self.layout.addWidget(self.f, 9, 4)
        self.layout.addWidget(self.g, 9, 5)
        self.layout.addWidget(self.h, 9, 6)
        self.layout.addWidget(self.j, 9, 7)
        self.layout.addWidget(self.k, 9, 8)
        self.layout.addWidget(self.l, 9, 9)
        self.layout.addWidget(self.semicolon, 9, 10)
        self.layout.addWidget(self.apostrophe, 9, 11)
        self.layout.addWidget(self.enter, 9, 12, 1, 2)
        self.layout.addWidget(self.kp_leftarrow, 9, 17)
        self.layout.addWidget(self.kp_five, 9, 18)
        self.layout.addWidget(self.kp_rightarrow, 9, 19)

        self.layout.addWidget(self.left_shift, 10, 0, 1, 2)
        self.layout.addWidget(self.z, 10, 2)
        self.layout.addWidget(self.x, 10, 3)
        self.layout.addWidget(self.c, 10, 4)
        self.layout.addWidget(self.v, 10, 5)
        self.layout.addWidget(self.b, 10, 6)
        self.layout.addWidget(self.n, 10, 7)
        self.layout.addWidget(self.m, 10, 8)
        self.layout.addWidget(self.comma, 10, 9)
        self.layout.addWidget(self.dot, 10, 10)
        self.layout.addWidget(self.slash, 10, 11)
        self.layout.addWidget(self.right_shift, 10, 12, 1, 2)
        self.layout.addWidget(self.uparrow, 10, 15)
        self.layout.addWidget(self.kp_end, 10, 17)
        self.layout.addWidget(self.kp_downarrow, 10, 18)
        self.layout.addWidget(self.kp_pgdn, 10, 19)
        self.layout.addWidget(self.kp_enter, 10, 20, 2, 1)

        self.layout.addWidget(self.left_ctrl, 11, 0)
        self.layout.addWidget(self.left_alt, 11, 2)
        self.layout.addWidget(self.space, 11, 3, 1, 7)
        self.layout.addWidget(self.right_alt, 11, 10)
        self.layout.addWidget(self.right_ctrl, 11, 13)
        self.layout.addWidget(self.leftarrow, 11, 14)
        self.layout.addWidget(self.downarrow, 11, 15)
        self.layout.addWidget(self.rightarrow, 11, 16)
        self.layout.addWidget(self.kp_insert, 11, 17, 1, 2)
        self.layout.addWidget(self.kp_delete, 11, 19)

        self.f1.clicked.connect(lambda: self.key_clicked('"f1"'))
        self.f2.clicked.connect(lambda: self.key_clicked('"f2"'))
        self.f3.clicked.connect(lambda: self.key_clicked('"f3"'))
        self.f4.clicked.connect(lambda: self.key_clicked('"f4"'))
        self.f5.clicked.connect(lambda: self.key_clicked('"f5"'))
        self.f6.clicked.connect(lambda: self.key_clicked('"f6"'))
        self.f7.clicked.connect(lambda: self.key_clicked('"f7"'))
        self.f8.clicked.connect(lambda: self.key_clicked('"f8"'))
        self.f9.clicked.connect(lambda: self.key_clicked('"f9"'))
        self.f10.clicked.connect(lambda: self.key_clicked('"f10"'))
        self.f11.clicked.connect(lambda: self.key_clicked('"f11"'))
        self.f12.clicked.connect(lambda: self.key_clicked('"f12"'))

        self.acute.clicked.connect(lambda: self.key_clicked('"`"'))
        self.one.clicked.connect(lambda: self.key_clicked('"1"'))
        self.two.clicked.connect(lambda: self.key_clicked('"2"'))
        self.three.clicked.connect(lambda: self.key_clicked('"3"'))
        self.four.clicked.connect(lambda: self.key_clicked('"4"'))
        self.five.clicked.connect(lambda: self.key_clicked('"5"'))
        self.six.clicked.connect(lambda: self.key_clicked('"6"'))
        self.seven.clicked.connect(lambda: self.key_clicked('"7"'))
        self.eight.clicked.connect(lambda: self.key_clicked('"8"'))
        self.nine.clicked.connect(lambda: self.key_clicked('"9"'))
        self.zero.clicked.connect(lambda: self.key_clicked('"0"'))
        self.minus.clicked.connect(lambda: self.key_clicked('"-"'))
        self.equal.clicked.connect(lambda: self.key_clicked('"="'))
        self.backspace.clicked.connect(lambda: self.key_clicked('"backspace"'))
        self.insert.clicked.connect(lambda: self.key_clicked('"ins"'))
        self.home.clicked.connect(lambda: self.key_clicked('"home"'))
        self.pgup.clicked.connect(lambda: self.key_clicked('"pgup"'))
        self.numlock.clicked.connect(lambda: self.key_clicked('"numlock"'))
        self.kp_slash.clicked.connect(lambda: self.key_clicked('"kp_slash"'))
        self.kp_multiply.clicked.connect(
            lambda: self.key_clicked('"kp_multiply"'))
        self.kp_minus.clicked.connect(lambda: self.key_clicked('"kp_minus"'))

        self.tab.clicked.connect(lambda: self.key_clicked('"tab"'))
        self.q.clicked.connect(lambda: self.key_clicked('"q"'))
        self.w.clicked.connect(lambda: self.key_clicked('"w"'))
        self.e.clicked.connect(lambda: self.key_clicked('"e"'))
        self.r.clicked.connect(lambda: self.key_clicked('"r"'))
        self.t.clicked.connect(lambda: self.key_clicked('"t"'))
        self.y.clicked.connect(lambda: self.key_clicked('"y"'))
        self.u.clicked.connect(lambda: self.key_clicked('"u"'))
        self.i.clicked.connect(lambda: self.key_clicked('"i"'))
        self.o.clicked.connect(lambda: self.key_clicked('"o"'))
        self.p.clicked.connect(lambda: self.key_clicked('"p"'))
        self.open_bracket.clicked.connect(lambda: self.key_clicked('"["'))
        self.closed_bracket.clicked.connect(lambda: self.key_clicked('"]"'))
        self.backspace.clicked.connect(lambda: self.key_clicked('"\\"'))
        self.delete.clicked.connect(lambda: self.key_clicked('"del"'))
        self.end.clicked.connect(lambda: self.key_clicked('"End"'))
        self.pgdn.clicked.connect(lambda: self.key_clicked('"pgdn"'))
        self.kp_home.clicked.connect(lambda: self.key_clicked('"kp_home"'))
        self.kp_uparrow.clicked.connect(
            lambda: self.key_clicked('"kp_uparrow"'))
        self.kp_pgup.clicked.connect(lambda: self.key_clicked('"kp_pgup"'))
        self.kp_plus.clicked.connect(lambda: self.key_clicked('"kp_plus"'))

        self.capslock.clicked.connect(lambda: self.key_clicked('"capslock"'))
        self.a.clicked.connect(lambda: self.key_clicked('"a"'))
        self.s.clicked.connect(lambda: self.key_clicked('"s"'))
        self.d.clicked.connect(lambda: self.key_clicked('"d"'))
        self.f.clicked.connect(lambda: self.key_clicked('"f"'))
        self.g.clicked.connect(lambda: self.key_clicked('"g"'))
        self.h.clicked.connect(lambda: self.key_clicked('"h"'))
        self.j.clicked.connect(lambda: self.key_clicked('"j"'))
        self.k.clicked.connect(lambda: self.key_clicked('"k"'))
        self.l.clicked.connect(lambda: self.key_clicked('"l"'))
        self.semicolon.clicked.connect(lambda: self.key_clicked('"semicolon"'))
        self.apostrophe.clicked.connect(lambda: self.key_clicked('"' '"'))
        self.enter.clicked.connect(lambda: self.key_clicked('"enter"'))
        self.kp_leftarrow.clicked.connect(
            lambda: self.key_clicked('"kp_leftarrow"'))
        self.kp_five.clicked.connect(lambda: self.key_clicked('"kp_5"'))
        self.kp_rightarrow.clicked.connect(
            lambda: self.key_clicked('"kp_rightarrow"'))

        self.left_shift.clicked.connect(lambda: self.key_clicked('"shift"'))
        self.z.clicked.connect(lambda: self.key_clicked('"z"'))
        self.x.clicked.connect(lambda: self.key_clicked('"x"'))
        self.c.clicked.connect(lambda: self.key_clicked('"c"'))
        self.v.clicked.connect(lambda: self.key_clicked('"v"'))
        self.b.clicked.connect(lambda: self.key_clicked('"b"'))
        self.n.clicked.connect(lambda: self.key_clicked('"n"'))
        self.m.clicked.connect(lambda: self.key_clicked('"m"'))
        self.comma.clicked.connect(lambda: self.key_clicked('","'))
        self.dot.clicked.connect(lambda: self.key_clicked('"."'))
        self.slash.clicked.connect(lambda: self.key_clicked('"/"'))
        self.right_shift.clicked.connect(lambda: self.key_clicked('"shift"'))
        self.uparrow.clicked.connect(lambda: self.key_clicked('"uparrow"'))
        self.kp_end.clicked.connect(lambda: self.key_clicked('"kp_end"'))
        self.kp_downarrow.clicked.connect(
            lambda: self.key_clicked('"kp_downarrow"'))
        self.kp_pgdn.clicked.connect(lambda: self.key_clicked('"kp_pgdn"'))
        self.kp_enter.clicked.connect(lambda: self.key_clicked('"kp_enter"'))

        self.left_ctrl.clicked.connect(lambda: self.key_clicked('"ctrl"'))
        self.left_alt.clicked.connect(lambda: self.key_clicked('"alt"'))
        self.space.clicked.connect(lambda: self.key_clicked('"space"'))
        self.right_alt.clicked.connect(lambda: self.key_clicked('"alt"'))
        self.right_ctrl.clicked.connect(lambda: self.key_clicked('"ctrl"'))
        self.leftarrow.clicked.connect(lambda: self.key_clicked('"leftarrow"'))
        self.downarrow.clicked.connect(lambda: self.key_clicked('"downarrow"'))
        self.rightarrow.clicked.connect(
            lambda: self.key_clicked('"rightarrow"'))
        self.kp_insert.clicked.connect(lambda: self.key_clicked('"kp_ins"'))
        self.kp_delete.clicked.connect(lambda: self.key_clicked('"kp_del"'))

        self.mouse3.clicked.connect(lambda: self.key_clicked('"mouse3"'))
        self.mouse4.clicked.connect(lambda: self.key_clicked('"mouse4"'))
        self.mouse5.clicked.connect(lambda: self.key_clicked('"mouse5"'))

        self.buy.clicked.connect(self.buy_clicked)
        self.reset.clicked.connect(self.reset_clicked)
        self.bomb_drop.clicked.connect(self.bomb_drop_clicked)
        self.clear_decals.clicked.connect(self.clear_decals_clicked)
        self.bind_grenade.clicked.connect(self.bind_grenade_clicked)
        self.voice_mute.clicked.connect(self.voice_mute_clicked)
        self.hand_switch.clicked.connect(self.hand_switch_clicked)
        self.copy.clicked.connect(self.copy_clicked)

        self.ak47.clicked.connect(
            lambda: self.gear_clicked('"buy ak47; buy m4a1";'))
        self.m4s.clicked.connect(
            lambda: self.gear_clicked('"buy m4a1; buy ak47";'))
        self.vest.clicked.connect(lambda: self.gear_clicked('"buy vest";'))
        self.vest_helmet.clicked.connect(
            lambda: self.gear_clicked('"buy vesthelm";'))
        self.defuse_kit.clicked.connect(
            lambda: self.gear_clicked('"buy defuser";'))
        self.double_flash.clicked.connect(
            lambda: self.gear_clicked('"buy flashbang; buy flashbang";'))

        self.flash.clicked.connect(
            lambda: self.gear_clicked('"buy flashbang";'))
        self.smoke.clicked.connect(
            lambda: self.gear_clicked('"buy smokegrenade";'))
        self.nade.clicked.connect(
            lambda: self.gear_clicked('"buy hegrenade";'))
        self.inc_grenade.clicked.connect(
            lambda: self.gear_clicked('"buy incgrenade; buy molotov";'))
        self.molotov.clicked.connect(
            lambda: self.gear_clicked('"buy molotov; buy incgrenade";'))

        self.awp.clicked.connect(lambda: self.gear_clicked('"buy awp";'))
        self.deagle.clicked.connect(
            lambda: self.gear_clicked('"buy deagle; buy revolver";'))

        self.aug.clicked.connect(
            lambda: self.gear_clicked('"buy aug; buy sg556";'))
        self.sg.clicked.connect(
            lambda: self.gear_clicked('"buy sg556; buy aug";'))
        self.galil.clicked.connect(
            lambda: self.gear_clicked('"buy galilar; buy famas";'))
        self.famas.clicked.connect(
            lambda: self.gear_clicked('"buy famas; buy galilar";'))
        self.ssg.clicked.connect(lambda: self.gear_clicked('"buy ssg08";'))

        self.fiveseven.clicked.connect(
            lambda: self.gear_clicked('"buy fiveseven; buy tec9";'))
        self.tec9.clicked.connect(
            lambda: self.gear_clicked('"buy tec9; buy fiveseven";'))
        self.p250.clicked.connect(lambda: self.gear_clicked('"buy p250";'))
        self.cz75.clicked.connect(
            lambda: self.gear_clicked('"buy fiveseven; buy tec9";'))
        self.revolver.clicked.connect(
            lambda: self.gear_clicked('"buy revolver; buy deagle";'))

        self.mac10.clicked.connect(
            lambda: self.gear_clicked('"buy mac10; buy mp9";'))
        self.mp9.clicked.connect(
            lambda: self.gear_clicked('"buy mp9; buy mac10";'))
        self.mp7.clicked.connect(lambda: self.gear_clicked('"buy mp7";'))
        self.ump.clicked.connect(lambda: self.gear_clicked('"buy ump";'))
        self.p90.clicked.connect(lambda: self.gear_clicked('"buy p90";'))

        self.mp5.clicked.connect(lambda: self.gear_clicked('"buy mp7";'))
        self.bizon.clicked.connect(lambda: self.gear_clicked('"buy bizon";'))
        self.mag7.clicked.connect(
            lambda: self.gear_clicked('"buy mag7; buy sawedoff";'))
        self.sawedoff.clicked.connect(
            lambda: self.gear_clicked('"buy sawedoff; buy mag7";'))
        self.xm.clicked.connect(lambda: self.gear_clicked('"buy xm1014"`'))

        #------------------------------------------------------------------------------------------
        #------------------------------------------------------------------------------------------
        #------------------------------------------------------------------------------------------

        self.command: str = ""
        self.bind: Union[NoneType, bool] = None
        self.action: Union[NoneType, str] = None
        self.grenade_keys: tuple = (self.flash, self.smoke, self.nade,
                                    self.inc_grenade, self.molotov)
        #self.bound_keys: list = () #TODO bound keys

#------------------------------------------------------------------------------------------

    def buy_clicked(self) -> None:
        self.action = "buy"

    def key_clicked(self, key_value: str) -> None:
        if self.action and not self.bind:
            if self.action == "buy":
                self.command += f"bind { key_value } "
                self.bind = True

            elif self.action == "bind_grenade":
                self.command += f"bind { key_value} "
                self.bind = True
                for key in self.grenade_keys:
                    key.setStyleSheet("background-color: #3f3f3f;")

            elif self.action == "bomb_drop":
                self.command += f'bind { key_value } "use weapon_knife; use weapon_c4; drop; slot1";\n'
                self.commands_display.setText(self.command)
                self.action = None

            elif self.action == "voice_mute":
                self.command += f"bindtoggle { key_value } voice_enable;\n"
                self.commands_display.setText(self.command)
                self.action = None

            elif self.action == "hand_switch":
                self.command += f'bind { key_value } "toggle cl_righthand 0 1";\n'
                self.commands_display.setText(self.command)
                self.action = None

            elif self.action == "clear_decals":
                self.command += f"bind { key_value } r_cleardecals;\n"
                self.commands_display.setText(self.command)
                self.action = None
        else:
            pass

    def gear_clicked(self, key_value: str) -> None:
        if self.action and self.bind:
            if self.action == "buy":
                self.command += f"{ key_value }\n"
                self.commands_display.setText(self.command)
                self.action = None
                self.bind = None

            elif self.action == "bind_grenade":
                new_key_value = key_value.replace("buy ", "use weapon_")
                self.command += f"{ new_key_value }\n"
                self.commands_display.setText(self.command)
                self.action = None
                self.bind = None
                for key in self.grenade_keys:
                    key.setStyleSheet("background-color: #2F2F2F;")
        else:
            pass

#------------------------------------------------------------------------------------------

    def bind_grenade_clicked(self) -> None:
        self.action = "bind_grenade"

    def bomb_drop_clicked(self) -> None:
        self.action = "bomb_drop"

    def voice_mute_clicked(self) -> None:
        self.action = "voice_mute"

    def hand_switch_clicked(self) -> None:
        self.action = "hand_switch"

    def clear_decals_clicked(self) -> None:
        self.action = "clear_decals"

    def copy_clicked(self) -> None:
        QApplication.clipboard().setText(self.command.replace("\n", " "))

    def reset_clicked(self) -> None:
        self.commands_display.setText("")
        self.command = ""
        self.action = None
        self.bind = None
        self.action = None
        for key in self.grenade_keys:
            key.setStyleSheet("background-color: #2F2F2F;")
Esempio n. 20
0
class Homepage(QWidget):
    def __init__(self):
        super().__init__()

        # Declare Widgets
        self.homepage_label = QLabel('Home')
        self.search_label = QLabel('Find an Image!')
        self.srch_box = QLineEdit()  # input field for search
        self.srch_btn = QPushButton("Search")

        # Create U.I. Layout
        mbox = QVBoxLayout()

        vbox = QVBoxLayout()
        vbox.addWidget(self.homepage_label)
        vbox.addWidget(self.search_label)
        vbox.addWidget(self.srch_box)
        vbox.addWidget(self.srch_btn)

        gbox1 = QGroupBox()
        gbox1.setLayout(vbox)
        mbox.addWidget(gbox1)

        # Homes Images Layout
        images = []
        images = self.getHomepageImages()

        # Create layout for images
        vbox2 = QHBoxLayout()

        i = 0
        for img in images:
            self.label = QLabel()
            # pic = Image.open(requests.get(img['urls']['thumb'], stream=True).raw)

            pixmap1 = QPixmap(img)

            pixmap1 = pixmap1.scaled(300, 300, Qt.KeepAspectRatio)

            self.label.setPixmap(pixmap1)

            temp_vbox = QVBoxLayout()
            temp_vbox.addWidget(self.label)

            gbox2 = QGroupBox()
            gbox2.setLayout(temp_vbox)
            gbox2.setStyleSheet("background-color: grey")

            vbox2.addWidget(gbox2)
            i += 1

        gbox3 = QGroupBox()
        gbox3.setLayout(vbox2)
        mbox.addWidget(gbox3)
        self.setLayout(mbox)

        # Styling
        self.setStyleSheet("""
            color: orange;
            font-family: Comfortaa;
            """)
        self.srch_btn.setStyleSheet(":hover { background-color:cyan }")
        gbox1.setStyleSheet("""
            font-size: 18px
            """)

        # Listeners
        self.srch_btn.clicked.connect(self.find_images)

    # Function to find multiple images by keyword(s)
    @Slot()
    def find_images(self):
        print("Finding Match...")

        payload = {
            'client_id': api_key,
            'query': self.srch_box.text(),
            'page': 1,
            'per_page': 1
        }
        endpoint = 'https://api.unsplash.com/search/photos'
        try:
            request = requests.get(endpoint, params=payload)
            data = request.json()
            pprint(data)
        except:
            print('please try again')

        if data:
            for image in data['results']:
                im = Image.open(
                    requests.get(image['urls']['thumb'], stream=True).raw)
                im.show()
        else:
            print('no data')

    def getHomepageImages(self):
        home_images = []
        print("Finding Match...")

        payload = {'client_id': api_key, 'count': 3}
        endpoint = 'https://api.unsplash.com/photos/random'
        try:
            request = requests.get(endpoint, params=payload)
            data = request.json()
            pprint(data)
        except:
            print('please try again')

        i = 1
        if data:
            for image in data:
                im = Image.open(
                    requests.get(image['urls']['thumb'], stream=True).raw)

                loc = image['links']['html']
                print(loc)

                im_name = "image" + str(i) + ".jpg"
                im_path = "home_images/" + im_name
                im.save(im_path)
                home_images.append(im_path)
                i += 1
            return home_images
        else:
            print('no data')
class SongSimilarityListItem(OrderableListItem):
    """The original song"""
    _song: Song
    """All similar songs"""
    _similar_songs_list: List[Song]
    """The similarity scores for each song pair"""
    _similarity_scores: dict[tuple[Song, Song], int]
    """The button opening the similarity details"""
    _button: QPushButton

    def __init__(self, similar_songs_list, similarity_scores):
        """Init gui
        :type similar_songs_list: List[Song]
        :param similar_songs_list: A group of songs that are similar
        :type similarity_scores: dict[tuple[Song, Song], int]
        :param similarity_scores: The similarity scores for each song pair"""
        super().__init__()
        # Add similar songs
        self._similar_songs_list = similar_songs_list
        self._similarity_scores = similarity_scores
        # Build gui
        self._button = QPushButton(
            self._similar_songs_list[0].get_name() + '(' +
            str(len(self._similar_songs_list)) + ')', self)
        self._button.clicked.connect(self._show_details_dialog)
        self._set_button_color()
        self._layout.addWidget(self._button)
        self._layout.addWidget(self._button)
        # Subscribe to song changes
        for song in self._similar_songs_list:
            song.subscribe(Song.UPDATED, self._song_updated)

    def _set_button_color(self):
        """Set this items button color"""
        # Check if all songs were marked
        all_songs_marked: bool = True
        for song in self._similar_songs_list:
            if not song.is_marked_for_keeping(
            ) and not song.is_marked_for_deleting():
                all_songs_marked = False
                break
        # Adjust the button color
        if all_songs_marked:
            self._button.setStyleSheet('background-color: green')
        else:
            self._button.setStyleSheet('background-color: gray')

    def _song_updated(self, song):
        """A song was updated"""
        self._set_button_color()
        self._trigger_subscriptions(OrderableListItem.UPDATED, item=self)

    def delete(self, song=None):
        """Delete this item
        :type song: Song
        :param song: This parameter is passed, when the delete call is coming directly from a song
        """
        super().delete()

    def _show_details_dialog(self):
        """Show the similarity details"""
        song_similarity_gui: SongSimilarityWindow = SongSimilarityWindow(
            self._similar_songs_list, self._similarity_scores)
        song_similarity_gui.show()
        song_similarity_gui.activateWindow()

    def get_order_string(self):
        """Get the song title this item is ordered by
        :returns str: The song title this item is ordered by"""
        return self._similar_songs_list[0].get_name().lower()