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
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;")
class MainWidget(QWidget): def __init__(self, parent: QWidget, model: Model) -> None: super().__init__(parent) logger.add(self.log) settings = QSettings() self.mainlayout = QVBoxLayout() self.mainlayout.setContentsMargins(5, 5, 5, 5) self.setLayout(self.mainlayout) # summary summarylayout = FlowLayout() summarylayout.setContentsMargins(0, 0, 0, 0) self.summary = QWidget() self.summary.setLayout(summarylayout) self.mainlayout.addWidget(self.summary) self.summary.setVisible( settings.value('showSummary', 'True') == 'True') detailslayout = QHBoxLayout() detailslayout.setContentsMargins(1, 0, 0, 0) detailslayout.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) detailslayout.setSpacing(15) details = QWidget() details.setLayout(detailslayout) summarylayout.addWidget(details) self.modstotal = QLabel() detailslayout.addWidget(self.modstotal) self.modsenabled = QLabel() detailslayout.addWidget(self.modsenabled) self.overridden = QLabel() detailslayout.addWidget(self.overridden) self.conflicts = QLabel() detailslayout.addWidget(self.conflicts) buttonslayout = QHBoxLayout() buttonslayout.setContentsMargins(0, 0, 0, 0) buttonslayout.setAlignment(Qt.AlignRight | Qt.AlignVCenter) buttons = QWidget() buttons.setLayout(buttonslayout) summarylayout.addWidget(buttons) self.startscriptmerger = QPushButton('Start Script Merger') self.startscriptmerger.setContentsMargins(0, 0, 0, 0) self.startscriptmerger.setMinimumWidth(140) self.startscriptmerger.setIcon( QIcon(str(getRuntimePath('resources/icons/script.ico')))) self.startscriptmerger.clicked.connect(lambda: [ openExecutable(Path(str(settings.value('scriptMergerPath'))), True) ]) self.startscriptmerger.setEnabled( verifyScriptMergerPath( Path(str(settings.value('scriptMergerPath')))) is not None) buttonslayout.addWidget(self.startscriptmerger) self.startgame = QPushButton('Start Game') self.startgame.setContentsMargins(0, 0, 0, 0) self.startgame.setMinimumWidth(100) self.startgame.setIcon( QIcon(str(getRuntimePath('resources/icons/w3b.ico')))) buttonslayout.addWidget(self.startgame) # splitter self.splitter = QSplitter(Qt.Vertical) self.stack = QStackedWidget() self.splitter.addWidget(self.stack) # mod list widget self.modlistwidget = QWidget() self.modlistlayout = QVBoxLayout() self.modlistlayout.setContentsMargins(0, 0, 0, 0) self.modlistwidget.setLayout(self.modlistlayout) self.stack.addWidget(self.modlistwidget) # search bar self.searchbar = QLineEdit() self.searchbar.setPlaceholderText('Search...') self.modlistlayout.addWidget(self.searchbar) # mod list self.modlist = ModList(self, model) self.modlistlayout.addWidget(self.modlist) self.searchbar.textChanged.connect(lambda e: self.modlist.setFilter(e)) # welcome message welcomelayout = QVBoxLayout() welcomelayout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) welcomewidget = QWidget() welcomewidget.setLayout(welcomelayout) welcomewidget.dragEnterEvent = self.modlist.dragEnterEvent # type: ignore welcomewidget.dragMoveEvent = self.modlist.dragMoveEvent # type: ignore welcomewidget.dragLeaveEvent = self.modlist.dragLeaveEvent # type: ignore welcomewidget.dropEvent = self.modlist.dropEvent # type: ignore welcomewidget.setAcceptDrops(True) icon = QIcon(str(getRuntimePath('resources/icons/open-folder.ico'))) iconpixmap = icon.pixmap(32, 32) icon = QLabel() icon.setPixmap(iconpixmap) icon.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) icon.setContentsMargins(4, 4, 4, 4) welcomelayout.addWidget(icon) welcome = QLabel('''<p><font> No mod installed yet. Drag a mod into this area to get started! </font></p>''') welcome.setAttribute(Qt.WA_TransparentForMouseEvents) welcome.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) welcomelayout.addWidget(welcome) self.stack.addWidget(welcomewidget) # output log self.output = QTextEdit(self) self.output.setTextInteractionFlags(Qt.NoTextInteraction) self.output.setReadOnly(True) self.output.setContextMenuPolicy(Qt.NoContextMenu) self.output.setPlaceholderText('Program output...') self.splitter.addWidget(self.output) # TODO: enhancement: show indicator if scripts have to be merged self.splitter.setStretchFactor(0, 1) self.splitter.setStretchFactor(1, 0) self.mainlayout.addWidget(self.splitter) # TODO: incomplete: make start game button functional if len(model): self.stack.setCurrentIndex(0) self.splitter.setSizes([self.splitter.size().height(), 50]) else: self.stack.setCurrentIndex(1) self.splitter.setSizes([self.splitter.size().height(), 0]) model.updateCallbacks.append(self.modelUpdateEvent) asyncio.create_task(model.loadInstalled()) def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() == Qt.Key_Escape: self.modlist.setFocus() self.searchbar.setText('') elif event.matches(QKeySequence.Find): self.searchbar.setFocus() elif event.matches(QKeySequence.Paste): self.pasteEvent() # TODO: enhancement: add start game / start script merger shortcuts else: super().keyPressEvent(event) def pasteEvent(self) -> None: clipboard = QApplication.clipboard().text().splitlines() if len(clipboard) == 1 and isValidNexusModsUrl(clipboard[0]): self.parentWidget().showDownloadModDialog() else: urls = [ url for url in QApplication.clipboard().text().splitlines() if len(str(url.strip())) ] if all( isValidModDownloadUrl(url) or isValidFileUrl(url) for url in urls): asyncio.create_task(self.modlist.checkInstallFromURLs(urls)) def modelUpdateEvent(self, model: Model) -> None: total = len(model) enabled = len([mod for mod in model if model[mod].enabled]) overridden = sum( len(file) for file in model.conflicts.bundled.values()) conflicts = sum(len(file) for file in model.conflicts.scripts.values()) self.modstotal.setText( f'<font color="#73b500" size="4">{total}</font> \ <font color="#888" text-align="center">Installed Mod{"" if total == 1 else "s"}</font>' ) self.modsenabled.setText( f'<font color="#73b500" size="4">{enabled}</font> \ <font color="#888">Enabled Mod{"" if enabled == 1 else "s"}</font>' ) self.overridden.setText( f'<font color="{"#b08968" if overridden > 0 else "#84C318"}" size="4">{overridden}</font> \ <font color="#888">Overridden File{"" if overridden == 1 else "s"}</font> ' ) self.conflicts.setText( f'<font color="{"#E55934" if conflicts > 0 else "#aad576"}" size="4">{conflicts}</font> \ <font color="#888">Unresolved Conflict{"" if conflicts == 1 else "s"}</font> ' ) if len(model) > 0: if self.stack.currentIndex() != 0: self.stack.setCurrentIndex(0) self.repaint() else: if self.stack.currentIndex() != 1: self.stack.setCurrentIndex(1) self.repaint() def unhideOutput(self) -> None: if self.splitter.sizes()[1] < 10: self.splitter.setSizes([self.splitter.size().height(), 50]) def unhideModList(self) -> None: if self.splitter.sizes()[0] < 10: self.splitter.setSizes([50, self.splitter.size().height()]) def log(self, message: Any) -> None: # format log messages to user readable output settings = QSettings() record = message.record message = record['message'] extra = record['extra'] level = record['level'].name.lower() name = str(extra['name'] ) if 'name' in extra and extra['name'] is not None else '' path = str(extra['path'] ) if 'path' in extra and extra['path'] is not None else '' dots = bool( extra['dots'] ) if 'dots' in extra and extra['dots'] is not None else False newline = bool( extra['newline'] ) if 'newline' in extra and extra['newline'] is not None else False output = bool( extra['output'] ) if 'output' in extra and extra['output'] is not None else bool( message) modlist = bool( extra['modlist'] ) if 'modlist' in extra and extra['modlist'] is not None else False if level in ['debug' ] and settings.value('debugOutput', 'False') != 'True': if newline: self.output.append(f'') return n = '<br>' if newline else '' d = '...' if dots else '' if len(name) and len(path): path = f' ({path})' if output: message = html.escape(message, quote=True) if level in ['success', 'error', 'warning']: message = f'<strong>{message}</strong>' if level in ['success']: message = f'<font color="#04c45e">{message}</font>' if level in ['error', 'critical']: message = f'<font color="#ee3b3b">{message}</font>' if level in ['warning']: message = f'<font color="#ff6500">{message}</font>' if level in ['debug', 'trace']: message = f'<font color="#aaa">{message}</font>' path = f'<font color="#aaa">{path}</font>' if path else '' d = f'<font color="#aaa">{d}</font>' if d else '' time = record['time'].astimezone( tz=None).strftime('%Y-%m-%d %H:%M:%S') message = f'<font color="#aaa">{time}</font> {message}' self.output.append( f'{n}{message.strip()}{" " if name or path else ""}{name}{path}{d}' ) else: self.output.append(f'') self.output.verticalScrollBar().setValue( self.output.verticalScrollBar().maximum()) self.output.repaint() if modlist: self.unhideModList() if settings.value('unhideOutput', 'True') == 'True' and output: self.unhideOutput()
class MainWindow(QMainWindow): def __init__(self, window_width=None, window_height=None): super(MainWindow, self).__init__() if window_width != None and window_height != None: self.window_width = window_width self.window_height = window_height self.resize(window_width, window_height) self.stack_of_widget = QStackedWidget() self.central_widget = QWidget() self.main_layout = QVBoxLayout() self.username = "" # ui widgets self.message_visable_field = QTextEdit() self.message_input_field = QTextEdit() self.send_message = QPushButton("Send my message!") self.login_screen = LoginScreen() self.login_screen.auth_button.clicked.connect(self.login_button_click) # show all widgets self.build_ui() def build_ui(self): self.message_visable_field.setFont(QFont("Roboto", 12)) self.message_visable_field.setReadOnly(True) self.message_input_field.setFont(QFont("Roboto", 11)) self.message_input_field.setPlaceholderText( "Input your message here...") self.message_input_field.setMinimumHeight(50) self.message_input_field.setMaximumHeight(50) self.send_message.setFont(QFont("Roboto", 11)) self.send_message.clicked.connect(self.send_message_button_clicked) self.main_layout.addWidget(self.message_visable_field) self.main_layout.addWidget(self.message_input_field) self.main_layout.addWidget(self.send_message) self.central_widget.setLayout(self.main_layout) self.stack_of_widget.addWidget(self.login_screen) self.setMaximumSize(self.minimumSize()) self.stack_of_widget.addWidget(self.central_widget) self.setCentralWidget(self.stack_of_widget) def send_message_button_clicked(self): """ send a client message to the server, and append to the list message. """ message = self.message_input_field.toPlainText() if message != '': # send message to the server r_type = RequestInfo(type_request="MessageRequest", request_ts=f"{datetime.now()}") r_data = MessageRequest(from_=self.username, to="all", message=message) request = Request(request=[r_type], data=[r_data]) client_worker.send(request.json()) self.message_visable_field.append('You: ' + message) self.message_input_field.clear() def login_button_click(self): self.username = self.login_screen.login_field.text() r_type = RequestInfo(type_request="AuthRequest", request_ts=f"{datetime.now()}") r_data = AuthRequest( login=f"{self.username}", password=f"{self.login_screen.password_field.text()}") request = Request(request=[r_type], data=[r_data]) client_worker.send(request.json()) @Slot(str) def recieved_message_handler(self, message): msg = json.loads(message) print(msg) response = Request(**msg) if response.request[0].type_request == "AuthResponse": data = AuthResponse(**response.data[0]) if data.access is True: self.show_main_screen() elif response.request[0].type_request == "MessageRequest": data = MessageRequest(**response.data[0]) if data.to == "all": self.message_visable_field.append( f"[{data.from_}]: {data.message}") def show_main_screen(self): self.stack_of_widget.setCurrentWidget(self.central_widget) self.setMinimumSize(self.window_width, self.window_height) self.resize(self.minimumSize()) def closeEvent(self, event): client_worker.close() network_thread.exit() network_thread.wait(500) if network_thread.isRunning() is True: network_thread.terminate()