Skip to content

Commit

Permalink
Feature Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomns committed Feb 18, 2018
1 parent f3dd4a1 commit 91ce919
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 347 deletions.
56 changes: 30 additions & 26 deletions data/ui/_.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
* {
font-family: 'Noto Sans';
}

#ParserWindowMenu {
background-color: black;
}

#SpellTarget {
background-color: green;
Expand Down Expand Up @@ -101,45 +94,31 @@
}

#SpellWidget[Warning=false] {
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
border: 1px solid black;
}

#SpellWidget[Warning=true] {
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
border: 1px solid red;
}

#SpellWidgetProgressBarGood {
border: 0px;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
padding: 1px;
border: 0;
padding: 0;
}

#SpellWidgetProgressBarBad {
border: 0px;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
padding: 1px;
border: 0;
padding: 0;
}

#SpellWidgetProgressBarGood::chunk {
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
border: 1px solid #21B6A8;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFF,
stop: 0.5 #21B6A8,
stop: 1.0 #287AA9);
}

#SpellWidgetProgressBarBad::chunk {
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
border: 1px solid #99CC00;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFF,
stop: 0.5 #FF9900,
Expand All @@ -163,6 +142,7 @@

#ParserWindow {
background-color: black;
font-family: 'Noto Sans';
}

#ParserWindowTitle {
Expand All @@ -174,14 +154,30 @@
#ParserButton {
color: white;
background: black;
font-size: 16px;
font-size: 14px;
padding: 0;
}

#ParserButton:Hover {
background: #111133;
}

#ParserWindowMenu {
background-color: transparent;
}

#ParserWindowMenu QSpinBox {
color:white;
font-size: 14px;
font-weight: bold;
padding: 3px;
background-color: #050505;
border: none;
border-radius: 3px;


}

#MapCanvas {
background-color: rgb(0, 0, 0);
border:none;
Expand All @@ -192,3 +188,11 @@
font-size: 12px;
}


#SettingsLabel {
background-color: #DDD;
color: #333;
font-size: 14px;
border-radius: 3px;
padding: 3px;
}
17 changes: 13 additions & 4 deletions helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import re
from datetime import datetime, timedelta

from .settings import SettingsWindow

def parse_line(line: str):

def parse_line(line):
"""
Parses and then returns an everquest log entry's date and text.
"""
Expand All @@ -14,6 +16,12 @@ def parse_line(line: str):
text = line[index:].strip()
return datetime.strptime(sdate, '%a %b %d %H:%M:%S %Y'), text

def strip_timestamp(line):
"""
Strings EQ Timestamp from log entry.
"""
return line[line.find("]")++ 1:].strip()


def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
Expand Down Expand Up @@ -46,6 +54,7 @@ def get_degrees_from_line(x1, y1, x2, y2):


def format_time(time_delta):
"""Returns a string from a timedelta '#d #h #m #s', but only 's' if d, h, m are all 0."""
time_string = ''
days = time_delta.days
hours, remainder = divmod(time_delta.seconds, 3600)
Expand All @@ -61,16 +70,16 @@ def format_time(time_delta):


def text_time_to_seconds(text_time):
""" 'hh:mm:ss' -> seconds """
""" Returns string 'hh:mm:ss' -> seconds """
parts = text_time.split(':')
seconds, minutes, hours = 0, 0, 0
try:
seconds = int(parts[-1])
minutes = int(parts[-2])
hours = int(parts[-3])
except IndexError as e:
except IndexError:
pass
except ValueError as e:
except ValueError:
return

return timedelta(hours=hours, minutes=minutes, seconds=seconds).total_seconds()
18 changes: 12 additions & 6 deletions helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,30 @@ def save():

def verify_settings():
global data
# verify nparse.config.yaml contains what it should
# verify nparse.config.yml contains what it should
try:
# general
_ = int(data['general']['update_interval_msec'])
_ = int(data['general']['parser_opacity'])
assert((_ > 0 and _ <= 100))

# maps
_ = int(data['maps']['grid_line_width'])
_ = int(data['maps']['scale'])
_ = (type(data['maps']['show_poi']) == bool)
_ = (type(data['maps']['toggled']) == bool)
_ = bool(data['maps']['show_poi'])
_ = bool(data['maps']['toggled'])
_ = bool(data['maps']['auto_follow'])
geometry = data['maps'].get('geometry', None)
if geometry:
assert(len([int(x) for x in geometry]) == 4)

# spells
_ = int(data['spells']['level'])
_ = int(data['spells']['seconds_offset'])
_ = (type(data['spells']['toggled']) == bool)
assert(_ > 0 and _ <= 65)
_ = int(data['spells']['casting_window_buffer'])
_ = bool(data['spells']['use_casting_window'])
_ = bool(data['spells']['use_secondary_all'])
_ = bool(data['spells']['delay_self_buffs_on_zone'])
_ = bool(data['spells']['toggled'])
geometry = data['spells'].get('geometry', None)
if geometry:
assert(len([int(x) for x in geometry]) == 4)
Expand Down
91 changes: 34 additions & 57 deletions helpers/logreader.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,40 @@
import threading
import time
import os
import datetime
from glob import glob

from PyQt5.QtCore import QFileSystemWatcher, pyqtSignal

class ThreadedLogReader(threading.Thread):
from helpers import strip_timestamp

def __init__(self, eq_directory, interval = 250):
self._interval = interval
self._eq_directory = eq_directory

self._log_new_lines = []
self._log_file = ""
self._update_log_file()

self._active = True

threading.Thread.__init__(self)


def get_new_lines(self):
new_lines = [line.strip() for line in self._log_new_lines[:]]
for num in range(0, len(new_lines)):
self._log_new_lines.pop(0)
return new_lines

def _update_log_file(self):
log_filter = os.path.join(
self._eq_directory,
"eqlog*.*"
)
files = glob(log_filter)
tlog_file = max(files, key=os.path.getmtime)
if tlog_file != self._log_file:
with open(tlog_file, 'rb') as tlog:
tlog.seek(0, os.SEEK_END)
self._last_read = tlog.tell()
self._file_size = os.stat(tlog_file).st_size
self._log_file = tlog_file

def run(self):
while self._active:
self._update_log_file()
self._check_log()
time.sleep(self._interval/1000.0)

def stop(self):
self._active = False

def _check_log(self):
try:
new_size = os.stat(self._log_file).st_size
if type(self._file_size) == int and self._file_size < new_size:
self._file_size = new_size
with open(self._log_file, 'r') as file:
file.seek(self._last_read, os.SEEK_SET)
self._log_new_lines.extend(file.readlines())
self._last_read = file.tell()
return True
return False
except Exception as e:
print("FileReader().check_log():", e, type(e))
class LogReader(QFileSystemWatcher):

new_line = pyqtSignal(object)

def __init__(self, eq_directory):
super().__init__()

self._eq_directory = eq_directory
self._files = glob(os.path.join(self._eq_directory, 'eqlog*.txt'))
self._watcher = QFileSystemWatcher([self._eq_directory] + self._files)
self._watcher.fileChanged.connect(self._file_changed)

self._stats = {
'log_file':'',
'last_read':0,
}

def _file_changed(self, changed_file):
if changed_file != self._stats['log_file']:
self._stats['log_file'] = changed_file
with open(self._stats['log_file']) as log:
log.seek(0, os.SEEK_END)
self._stats['last_read'] = log.tell()
with open(self._stats['log_file']) as log:
log.seek(self._stats['last_read'], os.SEEK_SET)
lines = log.readlines()
self._stats['last_read'] = log.tell()
for line in lines:
self.new_line.emit((datetime.datetime.now(), strip_timestamp(line))
)

Loading

0 comments on commit 91ce919

Please sign in to comment.