예제 #1
0
 def eventFilter(self, source: QTextEdit, event: QMouseEvent):
     if event.type() == QEvent.MouseButtonDblClick:
         # 格式化组件中的内容
         # 或者尝试解析从浏览器中直接复制过来的 request headers
         formatted_content = ''
         content = source.toPlainText()
         try:
             formatted_content = json.dumps(json.loads(content), ensure_ascii=False, indent=4)
         except Exception:
             try:
                 tmp_config = {}
                 for line in content.split('\n'):
                     line = line.strip()
                     if line == '':
                         continue
                     if line.startswith(':'):
                         continue
                     kv = line.split(':', maxsplit=1)
                     if len(kv) == 1:
                         tmp_config[kv[0].strip()] = ''
                     else:
                         tmp_config[kv[0].strip()] = kv[1].strip()
                 formatted_content = json.dumps(tmp_config, ensure_ascii=False, indent=4)
             except Exception:
                 pass
         if formatted_content != '':
             source.setText(formatted_content)
             self.refresh.emit()
         return True
     return super(HeadersQTextEdit, self).eventFilter(source, event)
예제 #2
0
class Ex(QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        self.textEdit = QTextEdit()
        self.setCentralWidget(self.textEdit)

        self.statusBar()

        openFile = QAction(QIcon('open.svg'), 'Open', self)
        openFile.setShortcut("Ctrl+O")
        openFile.setStatusTip("Open new File")
        openFile.triggered.connect(self.show_dialog)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(openFile)

        self.setGeometry(300, 300, 350, 300)
        self.setWindowTitle('File dialog')

    def show_dialog(self):
        fname, _ = QFileDialog.getOpenFileName(self, "Open file", '/home')
        f = open(fname, 'r')
        with f:
            data = f.read()
            self.textEdit.setText(data)
예제 #3
0
class App(QWidget):
    def __init__(self):

        #init
        super(App, self).__init__()

        #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
        #parameters for the resume generation.
        self.params = {
            "White": 1.0,
            "Black": 1.0,
            "Hispanic": 1.0,
            "Asian": 1.0,
            "GenderRatio": 0.5,
            "TestSection": '',
            "TestMode": 2,
            "WorkPath": "",
            "BeginYear": "",
            "EndYear": "",
            "BeginMonth": "",
            "EndMonth": "",
            "BeginYearEdu": "",
            "EndYearEdu": "",
            "BeginMonthEdu": "",
            "EndMonthEdu": ""
        }
        #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

        #Dictionaries for UI buttons

        self.testModes = {"Before": 1, "After": 2, "Replace": 3}

        self.testSections = {
            "Address": 1,
            "Education": 2,
            "Work History": 3,
            "Skills": 4
        }
        #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
        #Window sizing for application
        self.title = "COEHP Resume Generator"
        self.left = 10
        self.top = 10
        self.width = 100
        self.height = 300

        #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
        #Window is created here
        self.makeUI()

    #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
    #Function creates window and adds widgets

    def makeUI(self):

        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.createLayout()

        windowLayout = QGridLayout()

        windowLayout.addWidget(self.box0, 1, 1, 1, 1)
        windowLayout.addWidget(self.box4, 0, 0, 1, 1)
        windowLayout.addWidget(self.box6, 1, 0, 1, 1)
        windowLayout.addWidget(self.box7, 0, 1, 1, 1)
        windowLayout.addWidget(self.box5, 3, 0, 1, 2)
        windowLayout.addWidget(self.box8, 2, 0, 1, 2)

        windowLayout.setAlignment(QtCore.Qt.AlignTop)

        self.setLayout(windowLayout)
        self.show()

    #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
    #All QGroupBoxes for features are added here.
    def createLayout(self):
        self.box0 = QGroupBox("Timeframe")
        self.box4 = QGroupBox("Test Data")
        self.box6 = QGroupBox("Output Directory")
        self.box5 = QGroupBox("")
        self.box7 = QGroupBox("Demographic Settings")
        self.box8 = QGroupBox("Resume Layout")

        #Demographic Settings

        self.wPercent = QTextEdit("0.25")
        self.bPercent = QTextEdit("0.25")
        self.aPercent = QTextEdit("0.25")
        self.hPercent = QTextEdit("0.25")
        self.gPercent = QTextEdit("0.5")
        self.wLabel = QLabel("White %")
        self.bLabel = QLabel("Black %")
        self.aLabel = QLabel("Asian %")
        self.hLabel = QLabel("Hispanic %")
        self.gLabel = QLabel("       Gender Ratio")

        self.wPercent.setFixedSize(100, 30)
        self.bPercent.setFixedSize(100, 30)
        self.aPercent.setFixedSize(100, 30)
        self.hPercent.setFixedSize(100, 30)
        self.gPercent.setFixedSize(100, 30)

        #Resume Layout Settings

        self.testSectionLabel1 = QLabel("Test Location")
        self.testSectionLabel2 = QLabel("Section")
        self.testSectionLabel3 = QLabel("Location of Content")
        self.sectionSelect = QComboBox()
        self.sectionSelect.addItems(
            ["Address", "Education", "Work History", "Skills"])
        self.sectionSelect.setFixedSize(300, 30)

        self.modeSelect = QComboBox()
        self.modeSelect.addItems(["Before", "After", "Replace"])
        self.modeSelect.setFixedSize(300, 30)

        #Academic Year

        #First Semester
        self.monthBegin = QComboBox()
        self.monthBegin.addItems([
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "November", "December"
        ])
        self.monthBegin.setFixedSize(100, 30)

        self.yearBeginLabel = QLabel("First Semester")
        self.yearBegin = QComboBox()
        self.yearBegin.setFixedSize(100, 30)

        for year in range(1970, 2050):
            self.yearBegin.addItem(str(year))

        #Last Semester
        self.monthEnd = QComboBox()
        self.monthEnd.addItems([
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "November", "December"
        ])
        self.monthEnd.setFixedSize(100, 30)

        self.yearEnd = QComboBox()
        self.yearEndLabel = QLabel("Semester of Graduation")
        for year in range(1970, 2050):
            self.yearEnd.addItem(str(year))
        self.yearEnd.setFixedSize(100, 30)

        #Earliest relevant employment
        self.monthWorkBegin = QComboBox()
        self.monthWorkBegin.addItems([
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "November", "December"
        ])
        self.monthBegin.setFixedSize(100, 30)

        self.yearWorkBeginLabel = QLabel(
            "Earliest Possible Date of Employment")
        self.yearWorkBegin = QComboBox()
        self.yearWorkBegin.setFixedSize(100, 30)

        for year in range(1970, 2050):
            self.yearWorkBegin.addItem(str(year))

        #Latest relevant employment
        self.monthWorkEnd = QComboBox()
        self.monthWorkEnd.addItems([
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "November", "December"
        ])
        self.monthWorkEnd.setFixedSize(100, 30)

        self.yearWorkEnd = QComboBox()
        self.yearWorkEndLabel = QLabel("Latest Possible Date of Employment")
        for year in range(1970, 2050):
            self.yearWorkEnd.addItem(str(year))
        self.yearWorkEnd.setFixedSize(100, 30)

        currentYear = date.today().year
        index = currentYear - 1970
        self.yearEnd.setCurrentIndex(index)
        self.yearBegin.setCurrentIndex(index)
        self.yearWorkBegin.setCurrentIndex(index)
        self.yearWorkEnd.setCurrentIndex(index)

        #Output Directory
        self.dirLabel = QLabel("Output Directory")
        self.currentDir = QTextEdit()
        self.currentDir.setText("Not Selected")
        self.currentDir.layout()
        self.currentDir.setFixedSize(300, 30)
        self.currentDir.setReadOnly(True)
        self.outputName = QTextEdit()

        self.outputLabel = QLabel("Output Folder Name")
        self.outputName.setText("None written")
        self.outputName.setToolTip(
            "Type in the name of the new Folder you would like to make for your Resume batch. \n Otherwise, this will use the current timestamp."
        )
        self.outputName.setFixedSize(300, 30)
        #Select ouput folder button

        self.outputButton = QPushButton('Select Output Directory')
        self.outputButton.setToolTip(
            "Click here to tell the generator where to put this batch of Resumes when it is finished."
        )
        self.outputButton.clicked.connect(
            lambda: self.openDir(self.currentDir))
        self.currentTest = QTextEdit()
        self.currentTest.setText("SportsCollegeList.csv")

        #Output Directory
        self.workLabel = QLabel("Output Directory")
        self.currentWork = QTextEdit()
        self.currentWork.setText("SportsCollegeList.csv")
        self.currentWork.layout()
        self.currentWork.setFixedSize(300, 30)
        self.currentWork.setReadOnly(True)

        #Select work datafolder button
        self.workButton = QPushButton('Select Work Data (.CSV)')
        self.workButton.setToolTip(
            "Click here to select a source file for the employment information in this Resume Batch."
        )
        self.workButton.clicked.connect(lambda: self.openDir(self.currentWork))

        #Select School Data

        self.workLabel = QLabel("Output Directory")
        self.currentSchool = QTextEdit()
        self.currentSchool.setText("Not Selected")
        self.currentSchool.layout()
        self.currentSchool.setFixedSize(300, 30)
        self.currentSchool.setReadOnly(True)

        #Select work datafolder button
        self.schoolButton = QPushButton('Select Work Data (.CSV)')
        self.schoolButton.clicked.connect(
            lambda: self.openDir(self.currentWork))

        #Select test data

        self.testLabel = QLabel("Output Directory")
        self.currentTest = QTextEdit()
        self.currentTest.setText("SportsCollegeList.csv")
        self.currentTest.layout()
        self.currentTest.setFixedSize(300, 30)
        self.currentTest.setReadOnly(True)
        self.testButton = QPushButton('Select Test Data (.CSV)')
        self.testButton.clicked.connect(lambda: self.openDir(self.currentTest))

        #Generate Resumes button
        self.begin = QPushButton('Generate Resumes')
        self.begin.clicked.connect(
            lambda: self.beginTask(self.currentTest.toPlainText()))

        layout = QGridLayout()
        self.box0.setLayout(layout)
        layout.addWidget(self.yearBeginLabel, 0, 0, 1, 2)
        layout.addWidget(self.monthBegin, 1, 0, 1, 1)
        layout.addWidget(self.yearBegin, 1, 1, 1, 1)
        layout.addWidget(self.yearEndLabel, 2, 0, 1, 2)
        layout.addWidget(self.monthEnd, 3, 0, 1, 1)
        layout.addWidget(self.yearEnd, 3, 1, 1, 1)

        layout.addWidget(self.yearWorkBeginLabel, 4, 0, 1, 2)
        layout.addWidget(self.monthWorkBegin, 5, 0, 1, 1)
        layout.addWidget(self.yearWorkBegin, 5, 1, 1, 1)
        layout.addWidget(self.yearWorkEndLabel, 6, 0, 1, 2)
        layout.addWidget(self.monthWorkEnd, 7, 0, 1, 1)
        layout.addWidget(self.yearWorkEnd, 7, 1, 1, 1)

        layout1 = QGridLayout()
        self.box8.setLayout(layout1)
        layout1.addWidget(self.testSectionLabel1, 0, 0, 1, 1)
        layout1.addWidget(self.testSectionLabel3, 1, 0, 1, 1)
        layout1.addWidget(self.sectionSelect, 0, 1, 1, 1)
        layout1.addWidget(self.modeSelect, 1, 1, 1, 1)

        layout2 = QGridLayout()
        self.box7.setLayout(layout2)
        layout2.addWidget(self.wLabel, 0, 0, 1, 1)
        layout2.addWidget(self.bLabel, 1, 0, 1, 1)
        layout2.addWidget(self.hLabel, 0, 2, 1, 1)
        layout2.addWidget(self.aLabel, 2, 0, 1, 1)
        layout2.addWidget(self.wPercent, 0, 1, 1, 1)
        layout2.addWidget(self.bPercent, 1, 1, 1, 1)
        layout2.addWidget(self.hPercent, 0, 3, 1, 1)
        layout2.addWidget(self.aPercent, 2, 1, 1, 1)
        layout2.addWidget(self.gLabel, 3, 1, 1, 1)
        layout2.addWidget(self.gPercent, 3, 2, 1, 2)

        layout = QGridLayout()
        self.box5.setLayout(layout)
        layout.addWidget(self.begin, 0, 0, 1, 2)

        layout3 = QGridLayout()
        layout3.addWidget(self.testButton, 0, 0, 1, 2)
        layout3.addWidget(self.currentTest, 1, 0, 1, 2)
        self.box4.setLayout(layout3)

        layout4 = QGridLayout()

        layout4.addWidget(self.outputButton, 0, 0, 1, 2)
        layout4.addWidget(self.currentDir, 1, 0, 1, 2)
        layout4.addWidget(self.outputLabel, 2, 0, 1, 2)
        layout4.addWidget(self.outputName, 3, 0, 1, 2)
        self.box6.setLayout(layout4)

    #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
    #
    def openDir(self, target):
        fileName = QFileDialog()
        filenames = list()
        if fileName.exec_():
            fileNames = fileName.selectedFiles()
            target.setText(fileNames[0])

    #▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
    #
    def beginTask(self, path):
        self.beginGen(path)

    def beginGen(self, path):

        self.params["White"] = self.wPercent.toPlainText()
        self.params["Black"] = self.bPercent.toPlainText()
        self.params["Hispanic"] = self.hPercent.toPlainText()
        self.params["Asian"] = self.aPercent.toPlainText()
        self.params["GenderRatio"] = self.gPercent.toPlainText()
        self.params["TestMode"] = str(self.modeSelect.currentText())
        self.params["TestSection"] = str(self.sectionSelect.currentText())
        self.params["BeginYear"] = str(self.yearWorkBegin.currentText())
        self.params["EndYear"] = str(self.yearWorkEnd.currentText())
        self.params["BeginMonth"] = str(self.monthWorkBegin.currentText())
        self.params["EndMonth"] = str(self.monthWorkEnd.currentText())
        self.params["workPath"] = "work.csv"
        self.params["BeginYearEdu"] = str(self.yearBegin.currentText())
        self.params["EndYearEdu"] = str(self.yearEnd.currentText())
        self.params["BeginMonthEdu"] = str(self.monthBegin.currentText())
        self.params["EndMonthEdu"] = str(self.monthEnd.currentText())

        print(self.params)
        Printer.begin(self.currentDir.toPlainText(), path,
                      self.outputName.toPlainText(), self.params)
class VideoFinderAddLink(AddLinkWindow):
    running_thread = None
    threadPool = {}

    def __init__(self, parent, receiver_slot, settings, video_dict={}):
        super().__init__(parent, receiver_slot, settings, video_dict)
        self.setWindowTitle(
            QCoreApplication.translate("ytaddlink_src_ui_tr", 'Video Finder'))
        self.size_label.hide()

        # empty lists for no_audio and no_video and video_audio files
        self.no_audio_list = []
        self.no_video_list = []
        self.video_audio_list = []

        self.media_title = ''

        # add support for other languages
        locale = str(self.persepolis_setting.value('settings/locale'))
        QLocale.setDefault(QLocale(locale))
        self.translator = QTranslator()
        if self.translator.load(':/translations/locales/ui_' + locale, 'ts'):
            QCoreApplication.installTranslator(self.translator)

        # extension_label
        self.extension_label = QLabel(self.link_frame)
        self.change_name_horizontalLayout.addWidget(self.extension_label)

        # Fetch Button
        self.url_submit_pushButtontton = QPushButton(self.link_frame)
        self.link_horizontalLayout.addWidget(self.url_submit_pushButtontton)

        # Status Box
        self.status_box_textEdit = QTextEdit(self.link_frame)
        self.status_box_textEdit.setMaximumHeight(150)
        self.link_verticalLayout.addWidget(self.status_box_textEdit)

        # Select format horizontal layout
        select_format_horizontalLayout = QHBoxLayout()

        # Selection Label
        self.select_format_label = QLabel(self.link_frame)
        select_format_horizontalLayout.addWidget(self.select_format_label)

        # Selection combobox
        self.media_comboBox = QComboBox(self.link_frame)
        self.media_comboBox.setMinimumWidth(200)
        select_format_horizontalLayout.addWidget(self.media_comboBox)

        # Duration label
        self.duration_label = QLabel(self.link_frame)
        select_format_horizontalLayout.addWidget(self.duration_label)

        self.format_selection_frame = QFrame(self)
        self.format_selection_frame.setLayout(select_format_horizontalLayout)
        self.link_verticalLayout.addWidget(self.format_selection_frame)

        # advanced_format_selection_checkBox
        self.advanced_format_selection_checkBox = QCheckBox(self)
        self.link_verticalLayout.addWidget(
            self.advanced_format_selection_checkBox)

        # advanced_format_selection_frame
        self.advanced_format_selection_frame = QFrame(self)
        self.link_verticalLayout.addWidget(
            self.advanced_format_selection_frame)

        advanced_format_selection_horizontalLayout = QHBoxLayout(
            self.advanced_format_selection_frame)

        # video_format_selection
        self.video_format_selection_label = QLabel(
            self.advanced_format_selection_frame)
        self.video_format_selection_comboBox = QComboBox(
            self.advanced_format_selection_frame)

        # audio_format_selection
        self.audio_format_selection_label = QLabel(
            self.advanced_format_selection_frame)
        self.audio_format_selection_comboBox = QComboBox(
            self.advanced_format_selection_frame)

        for widget in [
                self.video_format_selection_label,
                self.video_format_selection_comboBox,
                self.audio_format_selection_label,
                self.audio_format_selection_comboBox
        ]:
            advanced_format_selection_horizontalLayout.addWidget(widget)

        # Set Texts
        self.url_submit_pushButtontton.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr",
                                       'Fetch Media List'))
        self.select_format_label.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr",
                                       'Select a format'))

        self.video_format_selection_label.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr", 'Video format:'))
        self.audio_format_selection_label.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr", 'Audio format:'))

        self.advanced_format_selection_checkBox.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr",
                                       'Advanced options'))

        # Add Slot Connections
        self.url_submit_pushButtontton.setEnabled(False)
        self.change_name_lineEdit.setEnabled(False)
        self.ok_pushButton.setEnabled(False)
        self.download_later_pushButton.setEnabled(False)

        self.format_selection_frame.setEnabled(True)
        self.advanced_format_selection_frame.setEnabled(False)
        self.advanced_format_selection_checkBox.toggled.connect(
            self.advancedFormatFrame)

        self.url_submit_pushButtontton.clicked.connect(self.submitClicked)

        self.media_comboBox.activated.connect(
            partial(self.mediaSelectionChanged, 'video_audio'))

        self.video_format_selection_comboBox.activated.connect(
            partial(self.mediaSelectionChanged, 'video'))

        self.audio_format_selection_comboBox.activated.connect(
            partial(self.mediaSelectionChanged, 'audio'))

        self.link_lineEdit.textChanged.disconnect(
            super().linkLineChanged)  # Should be disconnected.
        self.link_lineEdit.textChanged.connect(self.linkLineChangedHere)

        self.setMinimumSize(650, 480)

        self.status_box_textEdit.hide()
        self.format_selection_frame.hide()
        self.advanced_format_selection_frame.hide()
        self.advanced_format_selection_checkBox.hide()

        if 'link' in video_dict.keys() and video_dict['link']:
            self.link_lineEdit.setText(video_dict['link'])
            self.url_submit_pushButtontton.setEnabled(True)
        else:
            # check clipboard
            clipboard = QApplication.clipboard()
            text = clipboard.text()
            if (("tp:/" in text[2:6]) or ("tps:/" in text[2:7])):
                self.link_lineEdit.setText(str(text))

            self.url_submit_pushButtontton.setEnabled(True)

    def advancedFormatFrame(self, button):
        if self.advanced_format_selection_checkBox.isChecked():

            self.advanced_format_selection_frame.setEnabled(True)
            self.format_selection_frame.setEnabled(False)
            self.mediaSelectionChanged(
                'video',
                int(self.video_format_selection_comboBox.currentIndex()))

        else:
            self.advanced_format_selection_frame.setEnabled(False)
            self.format_selection_frame.setEnabled(True)
            self.mediaSelectionChanged('video_audio',
                                       int(self.media_comboBox.currentIndex()))

    def getReadableSize(self, size):
        try:
            return '{:1.2f} MB'.format(int(size) / 1048576)
        except:
            return str(size)

    def getReadableDuration(self, seconds):
        try:
            seconds = int(seconds)
            hours = seconds // 3600
            seconds = seconds % 3600
            minutes = seconds // 60
            seconds = seconds % 60
            return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
        except:
            return str(seconds)

    # Define native slots

    def urlChanged(self, value):
        if ' ' in value or value == '':
            self.url_submit_pushButtontton.setEnabled(False)
            self.url_submit_pushButtontton.setToolTip(
                QCoreApplication.translate("ytaddlink_src_ui_tr",
                                           'Please enter a valid video link'))
        else:
            self.url_submit_pushButtontton.setEnabled(True)
            self.url_submit_pushButtontton.setToolTip('')

    def submitClicked(self, button=None):
        # Clear media list
        self.media_comboBox.clear()
        self.format_selection_frame.hide()
        self.advanced_format_selection_checkBox.hide()
        self.advanced_format_selection_frame.hide()
        self.video_format_selection_comboBox.clear()
        self.audio_format_selection_comboBox.clear()
        self.change_name_lineEdit.clear()
        self.threadPool.clear()
        self.change_name_checkBox.setChecked(False)
        self.video_audio_list.clear()
        self.no_video_list.clear()
        self.no_audio_list.clear()
        self.url_submit_pushButtontton.setEnabled(False)
        self.status_box_textEdit.setText(
            QCoreApplication.translate("ytaddlink_src_ui_tr",
                                       'Fetching Media Info...'))
        self.status_box_textEdit.show()
        self.ok_pushButton.setEnabled(False)
        self.download_later_pushButton.setEnabled(False)

        dictionary_to_send = deepcopy(self.plugin_add_link_dictionary)
        # More options
        more_options = self.collectMoreOptions()
        for k in more_options.keys():
            dictionary_to_send[k] = more_options[k]
        dictionary_to_send['link'] = self.link_lineEdit.text()

        fetcher_thread = MediaListFetcherThread(self.fetchedResult,
                                                dictionary_to_send, self)
        self.parent.threadPool.append(fetcher_thread)
        self.parent.threadPool[len(self.parent.threadPool) - 1].start()

    def fileNameChanged(self, value):
        if value.strip() == '':
            self.ok_pushButton.setEnabled(False)

    def mediaSelectionChanged(self, combobox, index):
        try:
            if combobox == 'video_audio':
                if self.media_comboBox.currentText() == 'Best quality':
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText('.' +
                                                 self.no_audio_list[-1]['ext'])

                else:
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText(
                        '.' + self.video_audio_list[index]['ext'])

                self.change_name_checkBox.setChecked(True)

            elif combobox == 'video':
                if self.video_format_selection_comboBox.currentText(
                ) != 'No video':
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText('.' +
                                                 self.no_audio_list[index -
                                                                    1]['ext'])
                    self.change_name_checkBox.setChecked(True)

                else:

                    if self.audio_format_selection_comboBox.currentText(
                    ) != 'No audio':
                        self.change_name_lineEdit.setText(self.media_title)
                        self.extension_label.setText('.' + self.no_video_list[
                            int(self.audio_format_selection_comboBox.
                                currentIndex()) - 1]['ext'])

                        self.change_name_checkBox.setChecked(True)
                    else:
                        self.change_name_lineEdit.setChecked(False)

            elif combobox == 'audio':
                if self.audio_format_selection_comboBox.currentText(
                ) != 'No audio' and self.video_format_selection_comboBox.currentText(
                ) == 'No video':
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText('.' +
                                                 self.no_video_list[index -
                                                                    1]['ext'])

                    self.change_name_checkBox.setChecked(True)

                elif (self.audio_format_selection_comboBox.currentText()
                      == 'No audio'
                      and self.video_format_selection_comboBox.currentText() !=
                      'No video') or (
                          self.audio_format_selection_comboBox.currentText() !=
                          'No audio' and
                          self.video_format_selection_comboBox.currentText() !=
                          'No video'):
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText('.' + self.no_audio_list[
                        int(self.video_format_selection_comboBox.currentIndex(
                        )) - 1]['ext'])

                    self.change_name_checkBox.setChecked(True)

                elif self.audio_format_selection_comboBox.currentText(
                ) == 'No audio' and self.video_format_selection_comboBox.currentText(
                ) == 'No video':
                    self.change_name_checkBox.setChecked(False)

        except Exception as ex:
            logger.sendToLog(ex, "ERROR")

    def fetchedResult(self, media_dict):

        self.url_submit_pushButtontton.setEnabled(True)
        if 'error' in media_dict.keys():

            self.status_box_textEdit.setText('<font color="#f11">' +
                                             str(media_dict['error']) +
                                             '</font>')
            self.status_box_textEdit.show()
        else:  # Show the media list

            # add no audio and no video options to the comboboxes
            self.video_format_selection_comboBox.addItem('No video')
            self.audio_format_selection_comboBox.addItem('No audio')

            self.media_title = media_dict['title']
            if 'formats' not in media_dict.keys(
            ) and 'entries' in media_dict.keys():
                formats = media_dict['entries']
                formats = formats[0]
                media_dict['formats'] = formats['formats']
            elif 'formats' not in media_dict.keys(
            ) and 'format' in media_dict.keys():
                media_dict['formats'] = [media_dict.copy()]

            try:
                i = 0
                for f in media_dict['formats']:
                    no_audio = False
                    no_video = False
                    text = ''
                    if 'acodec' in f.keys():
                        # only video, no audio
                        if f['acodec'] == 'none':
                            no_audio = True

                        # resolution
                        if 'height' in f.keys():
                            text = text + ' ' + '{}p'.format(f['height'])

                    if 'vcodec' in f.keys():
                        #                         if f['vcodec'] == 'none' and f['acodec'] != 'none':
                        #                             continue

                        # No video, show audio bit rate
                        if f['vcodec'] == 'none':
                            text = text + '{}kbps'.format(f['abr'])
                            no_video = True

                    if 'ext' in f.keys():
                        text = text + ' ' + '.{}'.format(f['ext'])

                    if 'filesize' in f.keys() and f['filesize']:
                        # Youtube api does not supply file size for some formats, so check it.
                        text = text + ' ' + '{}'.format(
                            self.getReadableSize(f['filesize']))

                    else:  # Start spider to find file size
                        input_dict = deepcopy(self.plugin_add_link_dictionary)

                        input_dict['link'] = f['url']
                        more_options = self.collectMoreOptions()

                        for key in more_options.keys():
                            input_dict[key] = more_options[key]

                        size_fetcher = FileSizeFetcherThread(input_dict, i)
                        self.threadPool[str(i)] = {
                            'thread': size_fetcher,
                            'item_id': i
                        }
                        self.parent.threadPool.append(size_fetcher)
                        self.parent.threadPool[len(self.parent.threadPool) -
                                               1].start()
                        self.parent.threadPool[len(self.parent.threadPool) -
                                               1].FOUND.connect(
                                                   self.findFileSize)

                    # Add current format to the related comboboxes
                    if no_audio:
                        self.no_audio_list.append(f)
                        self.video_format_selection_comboBox.addItem(text)

                    elif no_video:
                        self.no_video_list.append(f)
                        self.audio_format_selection_comboBox.addItem(text)

                    else:
                        self.video_audio_list.append(f)
                        self.media_comboBox.addItem(text)

                    i = i + 1

                self.status_box_textEdit.hide()

                if 'duration' in media_dict.keys():
                    self.duration_label.setText(
                        'Duration ' +
                        self.getReadableDuration(media_dict['duration']))

                self.format_selection_frame.show()
                self.advanced_format_selection_checkBox.show()
                self.advanced_format_selection_frame.show()
                self.ok_pushButton.setEnabled(True)
                self.download_later_pushButton.setEnabled(True)

                # if we have no options for separate audio and video, then hide advanced_format_selection...
                if len(self.no_audio_list) == 0 and len(
                        self.no_video_list) == 0:
                    self.advanced_format_selection_checkBox.hide()
                    self.advanced_format_selection_frame.hide()

                # set index of comboboxes on best available quality.
                # we have both audio and video
                if len(self.no_audio_list) != 0 and len(
                        self.no_video_list) != 0:
                    self.media_comboBox.addItem('Best quality')
                    self.media_comboBox.setCurrentIndex(
                        len(self.video_audio_list))
                    self.change_name_lineEdit.setText(self.media_title)
                    self.extension_label.setText('.' +
                                                 self.no_audio_list[-1]['ext'])
                    self.change_name_checkBox.setChecked(True)

                # video and audio are not separate
                elif len(self.video_audio_list) != 0:
                    self.media_comboBox.setCurrentIndex(
                        len(self.video_audio_list) - 1)

                if len(self.no_audio_list) != 0:
                    self.video_format_selection_comboBox.setCurrentIndex(
                        len(self.no_audio_list))

                if len(self.no_video_list) != 0:
                    self.audio_format_selection_comboBox.setCurrentIndex(
                        len(self.no_video_list))

                # if we have only audio or we have only video then hide media_comboBox
                if len(self.video_audio_list) == 0:
                    self.media_comboBox.hide()
                    self.select_format_label.hide()

                    # only video
                    if len(self.no_video_list) != 0 and len(
                            self.no_audio_list) == 0:
                        self.mediaSelectionChanged(
                            'video',
                            int(self.video_format_selection_comboBox.
                                currentIndex()))
                        self.advanced_format_selection_checkBox.setChecked(
                            True)
                        self.advanced_format_selection_checkBox.hide()

                    # only audio
                    elif len(self.no_video_list) == 0 and len(
                            self.no_audio_list) != 0:
                        self.mediaSelectionChanged(
                            'audio',
                            int(self.audio_format_selection_comboBox.
                                currentIndex()))
                        self.advanced_format_selection_checkBox.setChecked(
                            True)
                        self.advanced_format_selection_checkBox.hide()

                    # audio and video
                    else:
                        self.mediaSelectionChanged(
                            'video_audio',
                            int(self.media_comboBox.currentIndex()))

            except Exception as ex:
                logger.sendToLog(ex, "ERROR")

    def findFileSize(self, result):
        try:
            item_id = self.threadPool[str(result['thread_key'])]['item_id']
            if result['file_size'] and result['file_size'] != '0':
                text = self.media_comboBox.itemText(item_id)
                self.media_comboBox.setItemText(
                    item_id, '{} - {}'.format(text, result['file_size']))
        except Exception as ex:
            logger.sendToLog(ex, "ERROR")

    def linkLineChangedHere(self, lineEdit):
        if str(lineEdit) == '':
            self.url_submit_pushButtontton.setEnabled(False)
        else:
            self.url_submit_pushButtontton.setEnabled(True)

    # This method collects additional information like proxy ip, user, password etc.
    def collectMoreOptions(self):
        options = {
            'ip': None,
            'port': None,
            'proxy_user': None,
            'proxy_passwd': None,
            'download_user': None,
            'download_passwd': None
        }
        if self.proxy_checkBox.isChecked():
            options['ip'] = self.ip_lineEdit.text()
            options['port'] = self.port_spinBox.value()
            options['proxy_user'] = self.proxy_user_lineEdit.text()
            options['proxy_passwd'] = self.proxy_pass_lineEdit.text()
        if self.download_checkBox.isChecked():
            options['download_user'] = self.download_user_lineEdit.text()
            options['download_passwd'] = self.download_pass_lineEdit.text()

        # These info (keys) are required for spider to find file size, because spider() does not check if key exists.
        additional_info = [
            'header', 'load_cookies', 'user_agent', 'referer', 'out'
        ]
        for i in additional_info:
            if i not in self.plugin_add_link_dictionary.keys():
                options[i] = None
        return options

    # user submitted information by pressing ok_pushButton, so get information
    # from VideoFinderAddLink window and return them to the mainwindow with callback!
    def okButtonPressed(self, download_later, button=None):

        link_list = []
        # separate audio format and video format is selected.
        if self.advanced_format_selection_checkBox.isChecked():

            if self.video_format_selection_comboBox.currentText(
            ) == 'No video' and self.audio_format_selection_comboBox.currentText(
            ) != 'No audio':

                # only audio link must be added to the link_list
                audio_link = self.no_video_list[
                    self.audio_format_selection_comboBox.currentIndex() -
                    1]['url']
                link_list.append(audio_link)

            elif self.video_format_selection_comboBox.currentText(
            ) != 'No video' and self.audio_format_selection_comboBox.currentText(
            ) == 'No audio':

                # only video link must be added to the link_list
                video_link = self.no_audio_list[
                    self.video_format_selection_comboBox.currentIndex() -
                    1]['url']
                link_list.append(video_link)

            elif self.video_format_selection_comboBox.currentText(
            ) != 'No video' and self.audio_format_selection_comboBox.currentText(
            ) != 'No audio':

                # video and audio links must be added to the link_list
                audio_link = self.no_video_list[
                    self.audio_format_selection_comboBox.currentIndex() -
                    1]['url']
                video_link = self.no_audio_list[
                    self.video_format_selection_comboBox.currentIndex() -
                    1]['url']
                link_list = [video_link, audio_link]

            elif self.video_format_selection_comboBox.currentText(
            ) == 'No video' and self.audio_format_selection_comboBox.currentText(
            ) == 'No audio':

                # no video and audio is selected! REALLY?!. user is DRUNK! close the window! :))
                self.close()
        else:
            if self.media_comboBox.currentText() == 'Best quality':

                # the last item in no_video_list and no_audio_list are the best.
                video_link = self.no_audio_list[-1]['url']
                audio_link = self.no_video_list[-1]['url']

                link_list = [video_link, audio_link]

            else:
                audio_and_video_link = self.video_audio_list[
                    self.media_comboBox.currentIndex()]['url']
                link_list.append(audio_and_video_link)

        # write user's new inputs in persepolis_setting for next time :)
        self.persepolis_setting.setValue('add_link_initialization/ip',
                                         self.ip_lineEdit.text())
        self.persepolis_setting.setValue('add_link_initialization/port',
                                         self.port_spinBox.value())
        self.persepolis_setting.setValue('add_link_initialization/proxy_user',
                                         self.proxy_user_lineEdit.text())
        self.persepolis_setting.setValue(
            'add_link_initialization/download_user',
            self.download_user_lineEdit.text())

        # get proxy information
        if not (self.proxy_checkBox.isChecked()):
            ip = None
            port = None
            proxy_user = None
            proxy_passwd = None
        else:
            ip = self.ip_lineEdit.text()
            if not (ip):
                ip = None
            port = self.port_spinBox.value()
            if not (port):
                port = None
            proxy_user = self.proxy_user_lineEdit.text()
            if not (proxy_user):
                proxy_user = None
            proxy_passwd = self.proxy_pass_lineEdit.text()
            if not (proxy_passwd):
                proxy_passwd = None

        # get download username and password information
        if not (self.download_checkBox.isChecked()):
            download_user = None
            download_passwd = None
        else:
            download_user = self.download_user_lineEdit.text()
            if not (download_user):
                download_user = None
            download_passwd = self.download_pass_lineEdit.text()
            if not (download_passwd):
                download_passwd = None

        # check that if user limits download speed.
        if not (self.limit_checkBox.isChecked()):
            limit = 0
        else:
            if self.limit_comboBox.currentText() == "KiB/s":
                limit = str(self.limit_spinBox.value()) + str("K")
            else:
                limit = str(self.limit_spinBox.value()) + str("M")

        # get start time for download if user set that.
        if not (self.start_checkBox.isChecked()):
            start_time = None
        else:
            start_time = self.start_time_qDataTimeEdit.text()

        # get end time for download if user set that.
        if not (self.end_checkBox.isChecked()):
            end_time = None
        else:
            end_time = self.end_time_qDateTimeEdit.text()

        # set name for file(s)
        if self.change_name_checkBox.isChecked():
            name = str(self.change_name_lineEdit.text())
            if name == '':
                name = 'video_finder_file'
        else:
            name = 'video_finder_file'

        # video finder always finds extension
        # but if it can't find file extension
        # use mp4 for extension.
        if str(self.extension_label.text()) == '':
            extension = '.mp4'
        else:
            extension = str(self.extension_label.text())

        # did user select separate audio and video?
        if len(link_list) == 2:
            video_name = name + extension
            audio_name = name + '.' + \
                str(self.no_video_list[self.audio_format_selection_comboBox.currentIndex() - 1]['ext'])

            name_list = [video_name, audio_name]
        else:
            name_list = [name + extension]

        # get number of connections
        connections = self.connections_spinBox.value()

        # get download_path
        download_path = self.download_folder_lineEdit.text()

        # referer
        if self.referer_lineEdit.text() != '':
            referer = self.referer_lineEdit.text()
        else:
            referer = None

        # header
        if self.header_lineEdit.text() != '':
            header = self.header_lineEdit.text()
        else:
            header = None

        # user_agent
        if self.user_agent_lineEdit.text() != '':
            user_agent = self.user_agent_lineEdit.text()
        else:
            user_agent = None

        # load_cookies
        if self.load_cookies_lineEdit.text() != '':
            load_cookies = self.load_cookies_lineEdit.text()
        else:
            load_cookies = None

        add_link_dictionary_list = []
        if len(link_list) == 1:
            # save information in a dictionary(add_link_dictionary).
            add_link_dictionary = {
                'referer': referer,
                'header': header,
                'user_agent': user_agent,
                'load_cookies': load_cookies,
                'out': name_list[0],
                'start_time': start_time,
                'end_time': end_time,
                'link': link_list[0],
                'ip': ip,
                'port': port,
                'proxy_user': proxy_user,
                'proxy_passwd': proxy_passwd,
                'download_user': download_user,
                'download_passwd': download_passwd,
                'connections': connections,
                'limit_value': limit,
                'download_path': download_path
            }

            add_link_dictionary_list.append(add_link_dictionary)

        else:
            video_add_link_dictionary = {
                'referer': referer,
                'header': header,
                'user_agent': user_agent,
                'load_cookies': load_cookies,
                'out': name_list[0],
                'start_time': start_time,
                'end_time': end_time,
                'link': link_list[0],
                'ip': ip,
                'port': port,
                'proxy_user': proxy_user,
                'proxy_passwd': proxy_passwd,
                'download_user': download_user,
                'download_passwd': download_passwd,
                'connections': connections,
                'limit_value': limit,
                'download_path': download_path
            }

            audio_add_link_dictionary = {
                'referer': referer,
                'header': header,
                'user_agent': user_agent,
                'load_cookies': load_cookies,
                'out': name_list[1],
                'start_time': None,
                'end_time': end_time,
                'link': link_list[1],
                'ip': ip,
                'port': port,
                'proxy_user': proxy_user,
                'proxy_passwd': proxy_passwd,
                'download_user': download_user,
                'download_passwd': download_passwd,
                'connections': connections,
                'limit_value': limit,
                'download_path': download_path
            }

            add_link_dictionary_list = [
                video_add_link_dictionary, audio_add_link_dictionary
            ]

        # get category of download
        category = str(self.add_queue_comboBox.currentText())

        del self.plugin_add_link_dictionary

        # return information to mainwindow
        self.callback(add_link_dictionary_list, download_later, category)

        # close window
        self.close()
예제 #5
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;")
예제 #6
0
class NovoCliente(QWidget):
    status_signal = Signal(str)

    def __init__(self):
        self.db = ClientesDB()
        QWidget.__init__(self)
        font = QFont()
        font.setBold(True)  # Labels em Negrito

        # Labels:
        self.label_title = QLabel("Novo Cliente")
        self.label_title.setFont(font)
        self.label_nome = QLabel("Nome Completo:")
        self.label_nome.setFont(font)
        self.label_endereco = QLabel("Endereço:")
        self.label_endereco.setFont(font)
        self.label_numero = QLabel("Número:")
        self.label_numero.setFont(font)
        self.label_cpf = QLabel("CPF:")
        self.label_cpf.setFont(font)

        # Entries:
        self.entry_nome = QLineEdit()
        self.entry_endereco = QTextEdit()
        self.entry_numero = QLineEdit()
        self.entry_cpf = QLineEdit()

        # Botões;
        self.button_salvar = QPushButton("&Salvar")
        self.button_salvar.clicked.connect(self.salvar_cliente)
        self.button_salvar.setShortcut("Ctrl+S")
        self.button_cancelar = QPushButton("Cancelar")
        self.button_cancelar.clicked.connect(self.limpar)
        self.button_cancelar.setShortcut("ESC")

        # Linha
        self.line = QFrame()
        self.line.setFrameShape(QFrame.HLine)
        self.line.setFrameShadow(QFrame.Sunken)
        self.line.setLineWidth(0)
        self.line.setMidLineWidth(1)

        # Leiaute:
        self.layout = QVBoxLayout()
        self.layout_buttons = QHBoxLayout()
        self.layout.addWidget(self.label_title)
        self.layout.addWidget(self.line)
        self.layout.addWidget(self.label_nome)
        self.layout.addWidget(self.entry_nome)
        self.layout.addWidget(self.label_numero)
        self.layout.addWidget(self.entry_numero)
        self.layout.addWidget(self.label_cpf)
        self.layout.addWidget(self.entry_cpf)
        self.layout.addWidget(self.label_endereco)
        self.layout.addWidget(self.entry_endereco)
        self.layout_buttons.addWidget(self.button_salvar)
        self.layout_buttons.addWidget(self.button_cancelar)
        self.layout.addStretch(2)
        self.layout.addLayout(self.layout_buttons)
        self.setLayout(self.layout)

    @Slot()
    def salvar_cliente(self):
        nome = self.entry_nome.text()
        cpf = self.entry_cpf.text()
        numero = self.entry_numero.text()
        endereco = self.entry_endereco.toPlainText()
        data = {
            'nome': nome,
            'cpf': cpf,
            'numero': numero,
            'endereco': endereco
        }
        try:
            self.db.novo_cliente(data)
            self.status_signal.emit("Salvo")
            self.limpar()
        except ValueError as e:
            popup = QMessageBox(QMessageBox.Critical, "Erro", "Campo Inválido")
            popup.setInformativeText(str(e))
            popup.addButton(QMessageBox.Ok)
            popup.exec()

    @Slot()
    def limpar(self):
        self.entry_nome.setText('')
        self.entry_endereco.setText('')
        self.entry_numero.setText('')
        self.entry_cpf.setText('')