Example #1
0
    def __init__(self, parent=None):
        super(Ui_MainWindow, self).__init__(parent)
        self.is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
        self.tray_icon = QSystemTrayIcon(self)
        self.settings_file = {}
        # will  be used for setting hot keysvisu
        self.firewall_active = False
        self.hold_control = False
        #  will be used to set up hot keys to turn on and off firewall

        self.ip_address_scope = ""

        self.setupUi()

        self.firewall_status()

        self.setupTrayIcon()
        self.set_up_help_window()

        self.hot_keys = self.get_hot_keys()

        self.hot_keys_setup = GlobalHotKeys(self.hot_keys)
        self.hot_keys_setup.start()

        if not self.is_admin:
            self.notAdmin()
Example #2
0
 def __init__(self, selector):
     self.selector = selector
     self.started = False
     self.key_listener = Listener(self.on_key_press)
     self.hotkey_listener = GlobalHotKeys({
         '<ctrl>+d': self.on_ctrl_d_press,
         '<ctrl>+f': self.on_ctrl_f_press
     })
Example #3
0
    def update_global_hot_key(self):

        if self.hot_keys_setup.is_alive():

            self.hot_keys_setup.stop()

            self.hot_keys_setup = GlobalHotKeys(self.get_hot_keys())
            self.hot_keys_setup.start()
Example #4
0
    def _create_bindings(mapping, ctrl):
        """
        Create hotkey bindings from the mapping to the controller actions.

        Args:
            mapping a dictionary with the key as the hotkey combination and the
            value as the controller action.
        """
        mapdict = {
            k: HotKeyHandler.get_function(ctrl, v) for k, v in mapping.items()}
        ghk = GlobalHotKeys(mapdict)
        ghk.start()
Example #5
0
class Director:
    def on_key_press(self, key):
        if key == Key.down:
            self.selector.move_down()
        elif key == Key.up:
            self.selector.move_up()
        elif key == Key.enter:
            self.selector.move_in()
        elif key == Key.esc:
            self.selector.move_out()
        elif key == Key.delete:
            actions.delete_selected_object(self.selector.display)
        elif key == Key.backspace:
            self.key_listener.stop()
            self.hotkey_listener.stop()
            self.selector.display.terminate = True

    def on_ctrl_d_press(self):
        actions.create_new_directory(self.selector.display)

    def on_ctrl_f_press(self):
        actions.create_new_file(self.selector.display)

    def __init__(self, selector):
        self.selector = selector
        self.started = False
        self.key_listener = Listener(self.on_key_press)
        self.hotkey_listener = GlobalHotKeys({
            '<ctrl>+d': self.on_ctrl_d_press,
            '<ctrl>+f': self.on_ctrl_f_press
        })

    def start_directing(self):
        if not self.started:
            self.started = True
            self.key_listener.start()
            self.hotkey_listener.start()
            self.key_listener.join()
Example #6
0
    def test_hotkeys(self):
        q = queue.Queue()

        with GlobalHotKeys({
                '<ctrl>+<shift>+a': lambda: q.put('a'),
                '<ctrl>+<shift>+b': lambda: q.put('b'),
                '<ctrl>+<shift>+c': lambda: q.put('c')}):
            notify('Press <ctrl>+<shift>+a')
            self.assertEqual('a', q.get())

            notify('Press <ctrl>+<shift>+b')
            self.assertEqual('b', q.get())

            notify('Press <ctrl>+<shift>+c')
            self.assertEqual('c', q.get())
Example #7
0
    def hotkeyInit(self):
        cl = Helpers()
        notification.notify(
            title="Assistant ready.",
            message="<i>Press hotkey to activate voice recognition.</i>",
            app_icon=defIcon,
            timeout=3,
        )

        try:
            with GlobalHotKeys({
                    actKey: cl.on_activate_act,
                    escKey: cl.on_activate_esc
            }) as h:
                h.join()
        except TypeError:
            # Tidy up (kill leftover procs, exit)
            cl.kill_proc()
            sys.exit(0)
Example #8
0
    def stop_pressing(self):
        print("stop pressing")
        self.running = False

    def exit(self):
        self.stop_pressing()
        self.program_running = False

    def run(self):
        while self.program_running:
            while self.running:
                time.sleep(self.delay)
                keyboard.press(Key.cmd)
                keyboard.press("\\")
                keyboard.release(Key.cmd)
                keyboard.release("\\")
            time.sleep(0.1)


keyboard = Controller()
press_thread = HotkeyClick(delay)
press_thread.start()

# start: option + shift + ]
# stop: option + shift + [
with GlobalHotKeys({
        '’': press_thread.start_pressing,
        '”': press_thread.stop_pressing
}) as h:
    h.join()
Example #9
0
                sys.exit()

        for i in currency_number_copy.keys():
            # 用过的数量 = 原来的数量 - 剩余的数量
            currency_number_copy[i] -= currency_number[i]
        used_chaos = float(
            currency_number_copy['chaos']) * chaos_chaos + float(
                currency_number_copy['scouring']) * scouring_chaos + float(
                    currency_number_copy['transmutation']
                ) * transmutation_chaos + float(
                    currency_number_copy['alc']) * alc_chaos + float(
                        currency_number_copy['aug']) * aug_chaos + float(
                            currency_number_copy['alt']) * alt_chaos + float(
                                currency_number_copy['reg']) * reg_chaos
        print('此装备使用了' + str(currency_number_copy) + '约使用了' + str(used_chaos) +
              '混沌石')
        # print('剩余' + str(currency_number))
        # 通货基准值重定义
        currency_number_copy = currency_number.copy()


if __name__ == '__main__':
    # 直接绑定快捷键
    with GlobalHotKeys({
            '<alt>+1': get_screenpoint,
            '<alt>+2': get_item_location,
            '<alt>+3': make_gear,
            '<alt>+q': exit_sys
    }) as h:
        h.join()
Example #10
0
        T.insert(END, ''.join(WholeString))
        print(float(str(indexOf) + "." + str(TempIndex2-1)))
        print(''.join(WholeString))
        T.delete(1.0, float(str(indexOf+1) + "." + str(TempIndex2)))
        TheFile.write(''.join(WholeString))
        TheFile.close()


 
def on_release(key):
    global WholeString, COMBINATION
    '''if key in COMBINATION:
        sleep(0.3)
        current.remove(key)
        try:
            T.delete(1.0, END)
        except:
            pass
        T.insert(END, current)'''

listener = Listener(on_press=on_press, on_release=on_release)
listener.start()


def on_activate_o():
    openFile("")

ctrlO = GlobalHotKeys({'<ctrl>+o': on_activate_o})
ctrlO.start()

root.mainloop()
Example #11
0
        def inner(*args, **kargs):

            GlobalHotKeys({hotkey: func})
    main_function(DASHOTKEY3)

def transfer_function4():
    main_function(DASHOTKEY4)

def transfer_function5():
    main_function(DASHOTKEY5)

# Assign Python hotkeys to DAS script hotkeys
HOTKEY1 = "<F1>"
HOTKEY2 = "<F2>"
HOTKEY3 = "<F3>"
HOTKEY4 = "<F4>"
HOTKEY5 = "<F5>"

DASHOTKEY1 = Key.f1
DASHOTKEY2 = Key.f2
DASHOTKEY3 = Key.f3
DASHOTKEY4 = Key.f4
DASHOTKEY5 = Key.f5

with GlobalHotKeys({
        HOTKEY1 : transfer_function1,
        HOTKEY2 : transfer_function2,
        HOTKEY3 : transfer_function3,
        HOTKEY4 : transfer_function4,
        HOTKEY5 : transfer_function5}) as MappedResult:
    MappedResult.join()

# TODO 
# Reduce copipaste in the code somehow
Example #13
0
def hotkey_listen():
    with GlobalHotKeys({'<ctrl>+<alt>+t': on_activate_t}) as hot:
        hot.join()
Example #14
0
def Check_Availability():
    if not path.exists(fileLocation):
        f = open(fileLocation, "w")
        f.close()
        firstList = ['key', 'keydown_time', 'keyup_time', 'fatigue level']
        thread1 = threading.Thread(target=Writer.Write().write_file,
                                   args=(
                                       firstList,
                                       fileLocation,
                                   ))
        thread1.start()


KeyboardListner = Listener(on_press=on_press, on_release=on_release)
HotKeyListner = GlobalHotKeys({
    '<ctrl>+<alt>+h': on_Pause,
    '<ctrl>+<alt>+i': on_Resume
})


def startPopup():
    threading.Thread(target=PopUI.PopUIStarter,
                     args=('PopUIThread', queue)).start()


def starter():
    startPopup()
    KeyboardListner.start()
    HotKeyListner.start()
    KeyboardListner.join()
    HotKeyListner.join()
Example #15
0
class Ui_MainWindow(QMainWindow):
    height = 600
    width = 400
    window_title = "GTA V SOLO KIT"

    def __init__(self, parent=None):
        super(Ui_MainWindow, self).__init__(parent)
        self.is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
        self.tray_icon = QSystemTrayIcon(self)
        self.settings_file = {}
        # will  be used for setting hot keysvisu
        self.firewall_active = False
        self.hold_control = False
        #  will be used to set up hot keys to turn on and off firewall

        self.ip_address_scope = ""

        self.setupUi()

        self.firewall_status()

        self.setupTrayIcon()
        self.set_up_help_window()

        self.hot_keys = self.get_hot_keys()

        self.hot_keys_setup = GlobalHotKeys(self.hot_keys)
        self.hot_keys_setup.start()

        if not self.is_admin:
            self.notAdmin()

    def setupUi(self):
        # second window for scanning lobby ip _ add
        self.second_window = Ui_Dialog(self)
        self.gta_icon = QIcon("gta_icon.png")

        self.resize(self.width, self.height)
        self.setMaximumSize(QtCore.QSize(self.width, self.height))
        self.setWindowIcon(self.gta_icon)

        # main screen
        self.centralwidget = QtWidgets.QWidget(self)
        self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)

        # setting the base frame as the main window
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)

        # setting the grid for the frame
        self.gridLayout_3 = QtWidgets.QGridLayout(self.frame)
        self.gridLayout_3.setContentsMargins(0, 0, 0, 0)

        # a vertical layout to store settings widgets
        self.firewall_settings = QtWidgets.QVBoxLayout()
        # setting a frame for the settings
        self.label = QtWidgets.QLabel(self.frame)
        # adding a label in the vertical box
        self.firewall_settings.addWidget(self.label)

        # create  file path horizontal layout
        self.gta_v_file_path = QtWidgets.QHBoxLayout()
        # directory path, will be used to retrieve the gta path for creating the firewall rule
        self.file_path_directory = QtWidgets.QLineEdit(self.frame)

        self.file_path_directory.setText(
            self.settings_file.get("GTA_FILE_PATH"))

        self.gta_v_file_path.addWidget(self.file_path_directory)

        # will be used to get gta v .exe if user is doesn't have copy paste
        self.file_path = QtWidgets.QPushButton(self.frame)

        self.file_path.clicked.connect(self.get_file_path)

        self.gta_v_file_path.addWidget(self.file_path)

        # adding the the gta v file path layout to firewall setting menu
        self.firewall_settings.addLayout(self.gta_v_file_path)

        # create 2 separate layout one for the layout and other is for holding the buttons
        self.ip_address_layout = QtWidgets.QVBoxLayout()

        # layout for holding the add and remove button
        self.ip_address_options = QtWidgets.QHBoxLayout()
        self.ip_address_options.setSpacing(0)

        self.add_ip_address_button = QtWidgets.QPushButton(self.frame)
        self.add_ip_address_button.clicked.connect(self.add_ip_address)

        self.ip_address_options.addWidget(self.add_ip_address_button)

        self.remove_ip_address_button = QtWidgets.QPushButton(self.frame)
        self.remove_ip_address_button.clicked.connect(self.remove_ip_address)

        self.ip_address_options.addWidget(self.remove_ip_address_button)

        self.ip_address_layout.addLayout(self.ip_address_options)
        self.ip_address_edit_text = QtWidgets.QLineEdit(self.frame)

        self.ip_address_layout.addWidget(self.ip_address_edit_text)
        self.scan_lobby_ip = QtWidgets.QPushButton(self.frame)
        self.scan_lobby_ip.clicked.connect(self.displayLobbyScanWindow)

        self.ip_address_layout.addWidget(self.scan_lobby_ip)

        add_remove_firewall_layout = QtWidgets.QHBoxLayout()

        add_remove_firewall_layout.setSpacing(0)

        self.add_firewall_rule_button = QtWidgets.QPushButton()
        add_remove_firewall_layout.addWidget(self.add_firewall_rule_button)

        self.remove_firewall_rule_button = QtWidgets.QPushButton()
        add_remove_firewall_layout.addWidget(self.remove_firewall_rule_button)

        self.add_firewall_rule_button.clicked.connect(self.add_firewall)
        self.remove_firewall_rule_button.clicked.connect(self.remove_firewall)

        self.firewall_settings.addLayout(add_remove_firewall_layout)

        self.firewall_settings.addLayout(self.ip_address_layout)

        # will be used to display the ip address white listed
        self.tableView = QtWidgets.QTableWidget(self.frame)

        self.firewall_settings.addWidget(self.tableView)

        self.gridLayout_3.addLayout(self.firewall_settings, 0, 0, 1, 1)
        self.gridLayout_2.addWidget(self.frame, 1, 0, 1, 1)

        self.buttons = QtWidgets.QHBoxLayout()
        self.firewall_button = QtWidgets.QPushButton(self.centralwidget)
        self.firewall_button.clicked.connect(self.firewall_mode)
        self.firewall_button.setStyleSheet("background-color:red;")

        self.firewall_button.setMinimumSize(QtCore.QSize(25, 50))
        self.firewall_button.setMaximumSize(QtCore.QSize(218, 50))
        self.buttons.addWidget(self.firewall_button)
        self.resource_monitor_button = QtWidgets.QPushButton(
            self.centralwidget)
        self.resource_monitor_button.clicked.connect(self.suspend_gta)

        self.resource_monitor_button.setMinimumSize(QtCore.QSize(25, 50))
        self.resource_monitor_button.setMaximumSize(QtCore.QSize(217, 50))

        self.buttons.addWidget(self.resource_monitor_button)
        self.gridLayout_2.addLayout(self.buttons, 2, 0, 1, 1)

        self.tableView.setColumnCount(1)

        header = self.tableView.horizontalHeader()
        header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch)

        self.tableView.setHorizontalHeaderLabels(["IP Address"])
        self.create_setting_file()
        # prevent tables from  being edited
        self.tableView.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        menu_bar = self.menuBar()
        setting_menu = menu_bar.addAction("Keyboard Shortcut Settings")
        setting_menu.triggered.connect(self.display_shortcut_window)

        help_window = menu_bar.addAction("Help")
        help_window.triggered.connect(self.displayHelpScreen)
        self.help_dialog = QtWidgets.QDialog(self)

        self.gta_process = GTASuspend(self)
        self.gta_process.seconds.connect(self.seconds_process_down)

        self.shortcut_window = hotkey.HotKey(self)

        self.setCentralWidget(self.centralwidget)
        self.focusWidget()
        self.setTextForButtons()

    def seconds_process_down(self, seconds):

        self.resource_monitor_button.setText(
            f"GTA V Will Resume Process in {seconds}")

        if seconds == 0:
            self.resource_monitor_button.setText("Resource Monitor")

    def notAdmin(self):
        self.firewall_button.setDisabled(True)
        self.add_firewall_rule_button.setDisabled(True)
        self.remove_firewall_rule_button.setDisabled(True)
        self.add_ip_address_button.setDisabled(True)
        self.remove_ip_address_button.setDisabled(True)
        self.file_path_directory.setDisabled(True)
        self.file_path.setDisabled(True)
        self.ip_address_edit_text.setDisabled(True)
        self.tableView.setDisabled(True)

        self.second_window.add_ip_address.setDisabled(True)

        pop_up = QtWidgets.QDialog(self)
        pop_up.setWindowTitle(self.window_title + " - Run as Admin")
        layout = QtWidgets.QVBoxLayout()

        button = QtWidgets.QPushButton(self)
        button.setText("Okay")
        button.clicked.connect(lambda e: pop_up.close())

        pop_up.setFixedSize(300, 70)
        button.setFixedSize(50, 30)

        message = QtWidgets.QLabel(
            "Please run as administrator to use some of the features")

        layout.addWidget(message, alignment=QtCore.Qt.AlignCenter)

        layout.addWidget(button, alignment=QtCore.Qt.AlignCenter)

        pop_up.setLayout(layout)

        pop_up.show()

    def get_hot_keys(self):

        self.hot_keys = json.load(open("settings.json", "r")).get("Hot_Key")

        method_calls = [
            self.turnOnFirewall, self.turnOffFirewall, self.suspend_gta
        ]

        # remove the need to assign function if no key has been assigned

        hot_keys = {
            f"<{key}>": method_calls[index]
            for index, (name, key) in enumerate(self.hot_keys.items())
            if key != "None"
        }

        return hot_keys

    def suspend_gta(self):

        if not self.gta_process.isRunning():
            self.gta_process.start()

    def update_global_hot_key(self):

        if self.hot_keys_setup.is_alive():

            self.hot_keys_setup.stop()

            self.hot_keys_setup = GlobalHotKeys(self.get_hot_keys())
            self.hot_keys_setup.start()

    def display_shortcut_window(self):

        self.shortcut_window.show()

    def set_up_help_window(self):

        self.help_dialog.setWindowTitle(self.window_title + "- HELP")
        layout = QtWidgets.QHBoxLayout()
        instruction = QtWidgets.QLabel(
            "Instruction\n"
            "1. Add Firewall Rule\n"
            "2. Join a public lobby\n"
            "3. Turn on the Firewall (you can use shortcut key in game default key = F11)\n"
            "Give it few seconds(5) and everyone should be kicked out, If not "
            "simply turn off\n and on the firewall \n(using this application) to update GTA "
            "\n\n"
            "Adding your friends"
            "\nFollow the above instructions until you're in a solo lobby\n"
            "1. Turn off firewall\n"
            "2. Get your friends to join your solo lobby\n"
            "3. Add their IP address manually or use the Scan Lobby IP Address feature\n"
            "4. Turn on Firewall\n"
            "\nIf you're using the Scan Lobby IP Address\n"
            "1. Get your friends to join your solo public lobby (firewall off first)\n"
            "2. Click on Scan Lobby IP Address\n"
            "3. Click on Scan Lobby\n"
            "4. Select the IP address and click on Add IP address"
            "5. Turn on Firewall "
            "\n\nIf you have any questions, feel free to contact me on discord @ Hunter#2950"
            "")

        layout.addWidget(instruction)

        self.help_dialog.setFixedHeight(310)
        self.help_dialog.setFixedWidth(420)

        self.help_dialog.setLayout(layout)

    def displayHelpScreen(self):

        # prevent from switching between main window while it is opened
        self.help_dialog.show()

    def displayLobbyScanWindow(self):
        self.second_window.show()

    # used for tray icon to bring window back up
    def showWindow(self):
        self.show()
        # display the window  and brings it to focus when brought back up by tray icon
        self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized
                            | QtCore.Qt.WindowActive)

    def firewall_status(self):

        # will be used to display that a firewall does not exist
        if firewall.firewall_exist():
            self.ip_address_scope = firewall.firewall_scopes_list().split(",")
            self.enable_firewall_settings_buttons()
            self.tableView.setRowCount(len(self.ip_address_scope))
            self.update_table()
            self.update_firewall_button_status()

        else:

            self.disable_firewall_settings_buttons()

    def update_firewall_button_status(self):

        self.firewall_active = firewall.firewall_active()

        if self.firewall_active:
            self.firewall_button.setText("Firewall Mode (ON)")
            self.firewall_button.setStyleSheet("background-color:#00FF00;")
        else:
            self.firewall_button.setText("Firewall Mode (OFF)")
            self.firewall_button.setStyleSheet("background-color:red;")

    # check events from application
    def changeEvent(self, event):
        # check for events tht causes windows state to change
        if event.type() == QtCore.QEvent.WindowStateChange:
            # check if it has been minimised
            if self.windowState() & QtCore.Qt.WindowMinimized:
                # ignore the event
                event.ignore()
                # create new event
                self.hide()
                self.tray_icon.showMessage(
                    "GTA V TOOLKIT", "Application has been minimised to tray",
                    QSystemTrayIcon.NoIcon, 2000)

    def turnOnFirewall(self):
        if firewall.firewall_exist():

            if not self.firewall_active:
                self.firewall_active = True

                self.tray_icon.showMessage(self.windowTitle(), "Firewall On")
                firewall.enable_firewall_rule()
                self.firewall_button.setText("Firewall Mode (ON)")
                self.firewall_button.setStyleSheet("background-color:#00FF00;")

    def turnOffFirewall(self):

        if firewall.firewall_exist():

            if self.firewall_active:
                self.firewall_active = False
                self.tray_icon.showMessage(self.windowTitle(), "Firewall off")
                firewall.disable_firewall_rule()
                self.firewall_button.setText("Firewall Mode (OFF)")
                self.firewall_button.setStyleSheet("background-color:red;")

    def setupTrayIcon(self):
        self.tray_icon.setIcon(self.gta_icon)

        tray_menu = QMenu()
        exit_Application = tray_menu.addAction("Exit")
        exit_Application.triggered.connect(self.close)
        exit_Application.setIcon(QIcon("exit"))

        show_application = tray_menu.addAction("Show")
        show_application.triggered.connect(self.showWindow)
        show_application.setIcon(QIcon("show"))

        self.tray_icon.show()

        self.tray_icon.setContextMenu(tray_menu)

    def setTextForButtons(self):
        self.firewall_button.setText("Firewall Mode (OFF)")
        self.add_firewall_rule_button.setText("Add Firewall Rule")
        self.remove_firewall_rule_button.setText("Remove Firewall Rule")
        self.setWindowTitle(self.window_title)
        self.label.setText("Firewall Settings")
        self.file_path_directory.setPlaceholderText("File Path")
        self.file_path.setText("GTA V Path")
        self.add_ip_address_button.setText("Add IP Address (optional)")
        self.remove_ip_address_button.setText("Remove IP Address")
        self.ip_address_edit_text.setPlaceholderText("IP Address")
        self.scan_lobby_ip.setText("Scan Lobby IP Address")
        self.resource_monitor_button.setText("Resource Monitor")

    def update_table(self):

        self.ip_address_scope = firewall.ip_address_without_scope()

        if not self.ip_address_scope:
            self.tableView.setRowCount(1)
            self.tableView.setItem(
                0, 0,
                QtWidgets.QTableWidgetItem("Private Session - None Allowed"))
        else:
            # remove the "private session not allowed Row"
            self.tableView.removeRow(0)
            self.tableView.setRowCount(len(self.ip_address_scope))

            for index, ip_address in enumerate(self.ip_address_scope):
                self.tableView.setItem(index, 0,
                                       QtWidgets.QTableWidgetItem(ip_address))

    def firewall_mode(self):

        if not self.firewall_active:

            self.firewall_active = True
            self.tray_icon.showMessage(self.windowTitle(), "Firewall On")
            firewall.enable_firewall_rule()
            self.firewall_button.setText("Firewall Mode (ON)")
            self.firewall_button.setStyleSheet("background-color:#00FF00;")

        else:
            self.firewall_active = False
            self.tray_icon.showMessage(self.windowTitle(), "Firewall off")
            self.firewall_button.setText("Firewall Mode (OFF)")
            self.firewall_button.setStyleSheet("background-color:red;")
            firewall.disable_firewall_rule()

    def add_ip_address(self):

        ip_address = self.ip_address_edit_text.text().strip()

        if firewall.valid_ip_address(ip_address):

            whitelist = AddIPThread(ip_address, parent=self)
            whitelist.start()

        else:
            # for debugging
            print("ip address already exist")

    def remove_ip_address(self):
        # ip_address = self.ip_address_edit_text.text()
        selected_ip_address = self.tableView.selectedItems()

        if selected_ip_address:
            # will be displayed if multiple IP address were selected
            if len(selected_ip_address) > 1:
                message_box = QtWidgets.QMessageBox(self)
                message_box.setWindowTitle("Confirm")
                message_box.setText("Are you sure you want to delete?")
                message_box.setIcon(QtWidgets.QMessageBox.Critical)
                message_box.setStandardButtons(QMessageBox.Yes
                                               | QMessageBox.No)
                message_box.buttonClicked.connect(
                    self.messageBoxConfirmationRemoval)
                message_box.exec_()

            elif selected_ip_address[0].text(
            ) != "Private Session - None Allowed":

                firewall.remove_white_list(selected_ip_address[0].text())
                self.update_table()

        else:
            pass

    def messageBoxConfirmationRemoval(self, button):
        if button.text() == "&Yes":
            worker_thread = RemoveIPThread(self)
            worker_thread.selected_ip_address = self.tableView.selectedItems()
            worker_thread.finished.connect(lambda status: self.update_table())

            worker_thread.start()

    def get_file_path(self):

        gta_file_path = self.settings_file.get("GTA_FILE_PATH")

        home_directory = str(
            Path.home()) if not gta_file_path else gta_file_path

        file_dialog = QtWidgets.QFileDialog.getOpenFileName(
            self.frame, "Open file", home_directory, "executable(*.exe)")
        file_path, _ = file_dialog

        file_path_format = os.path.realpath(file_path)

        if file_path and file_path != self.settings_file.get("GTA_FILE_PATH"):
            self.file_path_directory.setText(file_path_format)
            self.settings_file["GTA_FILE_PATH"] = os.path.realpath(
                file_path_format)

            json.dump(self.settings_file, open("settings.json", "w"))

    def add_firewall(self):

        if self.file_path_directory.text():

            added_firewall_rule = firewall.add_firewall_rule(
                self.file_path_directory.text())

            if added_firewall_rule:
                self.enable_firewall_settings_buttons()
                self.update_table()

        else:
            message_box = QtWidgets.QMessageBox(self)
            message_box.setWindowTitle(self.window_title)
            message_box.setText("Your file path cannot be empty")
            message_box.setIcon(QtWidgets.QMessageBox.Critical)
            message_box.setStandardButtons(QMessageBox.Ok)
            message_box.show()

    def remove_firewall(self):

        remove_firewall_rule = firewall.delete_firewall_rule()
        if remove_firewall_rule:
            self.disable_firewall_settings_buttons()
            self.tableView.setRowCount(0)
            self.ip_address_edit_text.setText("")

    def disable_firewall_settings_buttons(self):
        self.add_ip_address_button.setDisabled(True)
        self.remove_ip_address_button.setDisabled(True)
        self.add_firewall_rule_button.setDisabled(False)
        self.remove_firewall_rule_button.setDisabled(True)
        self.ip_address_edit_text.setDisabled(True)
        self.firewall_button.setDisabled(True)

        if self.firewall_active:
            self.firewall_active = False
            self.firewall_button.setText("Firewall Mode (OFF)")
            self.firewall_button.setStyleSheet("background-color:red;")

    def enable_firewall_settings_buttons(self):
        self.ip_address_edit_text.setDisabled(False)
        self.firewall_button.setDisabled(False)

        self.add_firewall_rule_button.setDisabled(True)
        self.remove_firewall_rule_button.setDisabled(False)
        self.add_ip_address_button.setDisabled(False)
        self.remove_ip_address_button.setDisabled(False)
        if not self.firewall_active:
            self.firewall_button.setText("Firewall Mode (OFF)")
            self.firewall_button.setStyleSheet("background-color:red;")

    def create_setting_file(self):

        current_cwd = os.getcwd()

        try:
            self.settings_file = json.load(open("settings.json"))
            gta_v_file_path = self.settings_file.get("GTA_FILE_PATH")
            self.file_path_directory.setText(gta_v_file_path)

        except FileNotFoundError:

            json_settings = {
                "GTA_FILE_PATH": "",
                "IP_Address": {},
                "Hot_Key": {
                    "F_ON": "F11",
                    "F_OFF": "F12",
                    "R_M": "F10"
                }
            }

            self.settings_file = json_settings
            update_setting_file = json.dump(json_settings,
                                            open("settings.json", "w"))