Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.idea/
.vscode/
working/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand All @@ -15,6 +16,7 @@ __pycache__/

# Distribution / packaging
.Python
.venv/
env/
venv/
bin/
Expand Down Expand Up @@ -65,3 +67,4 @@ docs/_build/
wiki/
old/
nparse.config.json

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Building
========

Currently only python 3.8.x is supported. Python 3.10.x has known issues that must be resolved.
Install `pyinstaller==4.3` and `pyinstaller-hooks-contrib==2020.7`
Install `pyinstaller==5.3`

Run: `pyinstaller --onefile nparse_py.spec`
Run: `pyinstaller nparse_py.spec`
2 changes: 1 addition & 1 deletion data/maps/map_files/Crystal_1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
P -298.0000, 184.0000, 0.0000, 127, 64, 0, 2, Bank
P -298.0000, 192.0000, -384, 127, 64, 0, 2, Bank
P -758.0000, 265.0000, 0.0000, 127, 64, 0, 2, Broken_Bridge
P 939.1472, 589.2308, -538.4664, 127, 0, 0, 2, Queen
P -692.0000, 176.0000, 0.0000, 127, 64, 0, 2, Waterfall
Expand Down
32 changes: 32 additions & 0 deletions helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import math
import requests
import json

import psutil

from datetime import datetime, timedelta

from .parser import Parser # noqa: F401
from .parser import ParserWindow # noqa: F401


Expand Down Expand Up @@ -100,3 +104,31 @@ def text_time_to_seconds(text_time):
pass

return timedelta(hours=hours, minutes=minutes, seconds=seconds).total_seconds()


def get_eqgame_pid_list() -> list[int]:
"""
get list of process ID's for eqgame.exe, using psutil module

Returns:
object: list of process ID's (in case multiple versions of eqgame.exe are somehow running)
"""

pid_list = list()
for p in psutil.process_iter(['name']):
if p.info['name'] == 'eqgame.exe':
pid_list.append(p.pid)
return pid_list


def starprint(line: str) -> None:
"""
utility function to print with leading and trailing ** indicators

Args:
line: line to be printed

Returns:
None:
"""
print(f'** {line.rstrip():<100} **')
19 changes: 18 additions & 1 deletion helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from glob import glob
import json

# global data
data = {}
_filename = ''
char_name = ''


def load(filename):
Expand Down Expand Up @@ -287,7 +289,22 @@ def verify_settings():
False
)


# deathloopvaccine
data['deathloopvaccine'] = data.get('deathloopvaccine', {})
data['deathloopvaccine']['toggled'] = get_setting(
data['deathloopvaccine'].get('toggled', True),
True
)
data['deathloopvaccine']['deaths'] = get_setting(
data['deathloopvaccine'].get('deaths', 4),
4
)
data['deathloopvaccine']['seconds'] = get_setting(
data['deathloopvaccine'].get('seconds', 120),
120
)


def get_setting(setting, default, func=None):
try:
assert(type(setting) == type(default))
Expand Down
14 changes: 8 additions & 6 deletions helpers/location_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import ssl
import threading
import time

from PyQt5.QtCore import QObject, QRunnable, pyqtSignal, pyqtSlot
Expand All @@ -24,7 +25,8 @@ class LocationSignals(QObject):
config_updated = pyqtSignal()


RUN = True
RUN = threading.Event()
RUN.set()
SIGNALS = LocationSignals()
THREADPOOL = QThreadPool()
_LSC = None
Expand All @@ -50,8 +52,8 @@ def start_location_service(update_func):


def stop_location_service():
global RUN
RUN = False
RUN.clear()
print("Stopping location service.")
lsc = get_location_service_connection()
lsc.enabled = False
lsc.configure_socket()
Expand Down Expand Up @@ -103,7 +105,7 @@ def configure_socket(self):

@pyqtSlot()
def run(self):
while RUN:
while RUN.is_set():
try:
self.configure_socket()
except:
Expand All @@ -113,8 +115,8 @@ def run(self):
try:
self._socket.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
except:
print("Socket connection brokem continuing...")
if RUN:
print("Socket connection broken, continuing...")
if RUN.is_set():
time.sleep(self.reconnect_delay)

@property
Expand Down
4 changes: 2 additions & 2 deletions helpers/logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def _file_changed_safe_wrap(self, changed_file):
def _file_changed(self, changed_file):
if changed_file != self._stats['log_file']:
self._stats['log_file'] = changed_file
char_name = os.path.basename(changed_file).split("_")[1]
config.char_name = os.path.basename(changed_file).split("_")[1]
if not config.data['sharing']['player_name_override']:
config.data['sharing']['player_name'] = char_name
config.data['sharing']['player_name'] = config.char_name
location_service.SIGNALS.config_updated.emit()
with open(self._stats['log_file'], 'rb') as log:
log.seek(0, os.SEEK_END)
Expand Down
63 changes: 46 additions & 17 deletions helpers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,54 @@
QPushButton, QVBoxLayout, QWidget)

from helpers import config
from datetime import datetime


class ParserWindow(QFrame):
class Parser:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about this, but it's growing on me. Maybe there would be other things that don't need a window? IDK, still thinking

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does solve the problem neatly for any non-window parser, now or in the future.


def __init__(self):
super().__init__()
self.name = 'Parser'
self._visible = False

def isVisible(self) -> bool:
return self._visible

def hide(self):
self._visible = False

def show(self):
self._visible = True

# main parsing logic here - derived classed should override this to perform their particular parsing tasks
def parse(self, timestamp: datetime, text: str) -> None:

# default behavior = simply print passed info
# this strftime mask will recreate the EQ log file timestamp format
line = f'[{timestamp.strftime("%a %b %d %H:%M:%S %Y")}] ' + text
print(f'[{self.name}]:{line}')

def toggle(self, _=None) -> None:
if self.isVisible():
self.hide()
config.data[self.name]['toggled'] = False
else:
self.set_flags()
self.show()
config.data[self.name]['toggled'] = True
config.save()

def shutdown(self) -> None:
pass

def set_flags(self) -> None:
pass

def settings_updated(self) -> None:
pass


class ParserWindow(QFrame, Parser):

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -108,16 +153,6 @@ def _toggle_frame(self):
def set_title(self, title):
self._title.setText(title)

def toggle(self, _=None):
if self.isVisible():
self.hide()
config.data[self.name]['toggled'] = False
else:
self.set_flags()
self.show()
config.data[self.name]['toggled'] = True
config.save()

def closeEvent(self, _):
config.data[self.name]['toggled'] = False
config.save()
Expand All @@ -129,9 +164,3 @@ def enterEvent(self, event):
def leaveEvent(self, event):
self._menu.setVisible(False)
QFrame.leaveEvent(self, event)

def shutdown(self):
pass

def settings_updated(self):
pass
26 changes: 19 additions & 7 deletions nparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
from helpers import config, logreader, resource_path, get_version, location_service
from helpers.settings import SettingsWindow

try:
import pyi_splash # noqa

pyi_splash.update_text('Done!')
pyi_splash.close()
except: # noqa
pass

config.load('nparse.config.json')
# validate settings file
config.verify_settings()
Expand All @@ -20,7 +28,7 @@
config.data['general']['qt_scale_factor'] / 100)


CURRENT_VERSION = '0.6.4'
CURRENT_VERSION = '0.6.5'
if config.data['general']['update_check']:
ONLINE_VERSION = get_version()
else:
Expand All @@ -31,6 +39,7 @@ class NomnsParse(QApplication):
"""Application Control."""

def __init__(self, *args):
self.setAttribute(Qt.AA_EnableHighDpiScaling)
super().__init__(*args)

# Updates
Expand Down Expand Up @@ -67,11 +76,13 @@ def _load_parsers(self):
"maps": parsers.Maps(),
"spells": parsers.Spells(),
"discord": parsers.Discord(),
"deathloopvaccine": parsers.DeathLoopVaccine(),
}
self._parsers = [
self._parsers_dict["maps"],
self._parsers_dict["spells"],
self._parsers_dict["discord"],
self._parsers_dict["deathloopvaccine"],
]
for parser in self._parsers:
if parser.name in config.data.keys() and 'geometry' in config.data[parser.name].keys():
Expand Down Expand Up @@ -125,7 +136,6 @@ def _menu(self, event):
menu = QMenu()
menu.setAttribute(Qt.WA_DeleteOnClose)
# check online for new version
new_version_text = ""
if self.new_version_available():
new_version_text = "Update Available {}".format(ONLINE_VERSION)
else:
Expand Down Expand Up @@ -181,13 +191,16 @@ def _menu(self, event):
elif action == quit_action:
if self._toggled:
self._toggle()
else:
location_service.stop_location_service()

# save parser geometry
for parser in self._parsers:
g = parser.geometry()
config.data[parser.name]['geometry'] = [
g.x(), g.y(), g.width(), g.height()
]
if parser.name in config.data.keys() and 'geometry' in config.data[parser.name].keys():
g = parser.geometry()
config.data[parser.name]['geometry'] = [
g.x(), g.y(), g.width(), g.height()
]
config.save()

self._system_tray.setVisible(False)
Expand Down Expand Up @@ -220,7 +233,6 @@ def new_version_available(self):
APP.setStyleSheet(open(resource_path('data/ui/_.css')).read())
APP.setWindowIcon(QIcon(resource_path('data/ui/icon.png')))
APP.setQuitOnLastWindowClosed(False)
APP.setAttribute(Qt.AA_EnableHighDpiScaling)
QFontDatabase.addApplicationFont(
resource_path('data/fonts/NotoSans-Regular.ttf'))
QFontDatabase.addApplicationFont(
Expand Down
Loading