Skip to content

Commit

Permalink
Version shortcut and some reorganising
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Dec 8, 2023
1 parent e2fda80 commit 4a4b4b9
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 189 deletions.
45 changes: 30 additions & 15 deletions joystick_diagrams/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

from PyQt5 import QtCore, QtGui, QtWidgets

QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

from joystick_diagrams import config
from joystick_diagrams.adaptors.dcs.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen.star_citizen import StarCitizen
from joystick_diagrams.classes import export
from joystick_diagrams.classes.version import version
from joystick_diagrams.devices import device_manager
from joystick_diagrams.ui import ui
from joystick_diagrams.ui import main_UI

QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) # type: ignore
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) # type: ignore

_logger = logging.getLogger(__name__)


class MainWindow(QtWidgets.QMainWindow, ui.Ui_MainWindow): # Refactor pylint: disable=too-many-instance-attributes
class MainWindow(QtWidgets.QMainWindow, main_UI.Ui_MainWindow): # Refactor pylint: disable=too-many-instance-attributes
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setupUi(self)
Expand All @@ -31,6 +31,12 @@ def __init__(self, *args, **kwargs):
self.dcs_profiles_list.clear()
self.jg_profile_list.clear()
self.application_information_textbrowser.clear()
self.donate_button.clicked.connect(self.open_version_window)
self.discord_button.clicked.connect(
lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl("https://discord.gg/G8nRUS2"))
)
self.version_checked = self.version_check()

# DCS UI Setup
self.dcs_selected_directory_label.setText("")
self.dcs_parser_instance = None
Expand All @@ -44,16 +50,6 @@ def __init__(self, *args, **kwargs):
self.export_button.clicked.connect(self.export_profiles)
self.parser_selector.currentChanged.connect(self.change_export_button)
self.change_export_button()
self.donate_button.clicked.connect(
lambda: QtGui.QDesktopServices.openUrl(
QtCore.QUrl(
"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WLLDYGQM5Z39W&source=url"
)
)
)
self.discord_button.clicked.connect(
lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl("https://discord.gg/G8nRUS2"))
)

# JG UI Setup
self.jg_select_profile_button.clicked.connect(self.set_jg_file)
Expand All @@ -63,6 +59,25 @@ def __init__(self, *args, **kwargs):
self.sc_parser_instance = None
self.sc_select_button.clicked.connect(self.set_sc_file)

def version_check(self):
check = version.performn_version_check()

if check:
self.open_version_window()

return check

def open_version_window(self):
msg_box = QtWidgets.QMessageBox()
msg_box.setIcon(QtWidgets.QMessageBox.Information)
msg_box.setText(
"A new version is available at <a href='https://www.joystick-diagrams.com/'>Joystick Diagrams</a> website"
)
msg_box.setWindowTitle("Joystick Diagrams - Update available")
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)

msg_box.exec()

def set_version(self) -> None:
"""
Set version in UI window
Expand Down
Empty file.
21 changes: 15 additions & 6 deletions joystick_diagrams/classes/version/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
Author: https://github.com/Rexeh
"""
from dataclasses import dataclass
import json
import logging
from pathlib import Path
import os
from dataclasses import dataclass
from hashlib import sha256
import json
from pathlib import Path
from typing import Any
import os

import requests

_LOGGER = logging.getLogger(__name__)

VERSION = "1.6"
VERSION = "2.0-ALPHA"
VERSION_SERVER = "https://www.joystick-diagrams.com/"
TEMPLATE_DIR = "./templates"
MANIFEST_DIR = "./"
Expand Down Expand Up @@ -54,7 +55,11 @@ def fetch_local_manifest() -> str | None:


def performn_version_check() -> bool:
"""Checks the local version against the latest release"""
"""Checks the local version against the latest release#
Returns True for Matched Versions
Returns False for Unmatched Versions
"""

remote_manifest = fetch_remote_manifest()
local_manifest = fetch_local_manifest()
Expand Down Expand Up @@ -109,6 +114,10 @@ def generate_template_manifest() -> dict[str, str]:


def compare_versions(running_version: JoystickDiagramVersion, latest_version: JoystickDiagramVersion) -> bool:
"""Compares versions based on object __eq__
Returns TRUE for MATCH
"""
return running_version == latest_version


Expand Down
15 changes: 4 additions & 11 deletions joystick_diagrams/devices/device_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from time import sleep
from typing import Any

from joystick_diagrams.devices import dill

_LOGGER = logging.getLogger(__name__)
_ACTIVE_DEViCES = {}
_ACTIVE_DEViCES: dict[str, str] = {} # GUID : Display Name

# Action mappings for device changes
DEVICE_ACTIONS = {1: "DEVICE_ADDED", 2: "DEVICE_REMOVED"}
Expand All @@ -15,11 +14,11 @@

# Cannot debug?
def _update_device_register(data: dill._DeviceSummary, action):
_LOGGER.info(f"Device was altered, added to device changes")
_LOGGER.info(f"Device {data} was altered, added to device changes")
_device_changes.append([dill.DeviceSummary(data), action])


dill.DILL.set_device_change_callback(_update_device_register) # Figure out this callable
dill.DILL.set_device_change_callback(_update_device_register) # mypy: ignore


# CAN BE DEBUGGED
Expand All @@ -42,10 +41,4 @@ def run():


if __name__ == "__main__":
lst = [1, 2, 3, 4, 5]

while len(lst) != 0:
i = lst.pop(0)
print(f"Popped {i}")

print("finished")
pass
Loading

0 comments on commit 4a4b4b9

Please sign in to comment.