Skip to content

Commit

Permalink
Added Save and Truncate buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust committed Feb 25, 2024
1 parent 9b941fc commit c3363c8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
57 changes: 53 additions & 4 deletions OSCRUI/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PySide6.QtCore import QSize, QSettings

from OSCR import TREE_HEADER, HEAL_TREE_HEADER
from OSCR.utilities import logline_to_str

from .iofunctions import load_icon_series, get_asset_path, load_icon
from .textedit import format_path
Expand Down Expand Up @@ -84,7 +85,9 @@ def cache_assets(self):
'collapse-left': 'collapse-left.svg',
'expand-right': 'expand-right.svg',
'collapse-right': 'collapse-right.svg',
'refresh': 'refresh-cw.svg'
'refresh': 'refresh-cw.svg',
'save': 'save-cw.svg',
'truncate': 'truncate-cw.svg',
}
self.icons = load_icon_series(icons, self.app_dir)

Expand Down Expand Up @@ -211,12 +214,18 @@ def setup_left_sidebar(self, frame:QFrame):
Parameters:
- :param frame: QFrame -> parent frame of the sidebar
"""
left_layout = QVBoxLayout()
m = self.theme['defaults']['margin']

left_layout = QVBoxLayout()
left_layout.setContentsMargins(m, m, m, m)
left_layout.setSpacing(0)
left_layout.setAlignment(ATOP)

left_button_layout = QHBoxLayout()
left_button_layout.setContentsMargins(m, m, m, m)
left_button_layout.setSpacing(0)
left_button_layout.setAlignment(ATOP)

head = self.create_label('STO Combatlog:', 'label', frame)
left_layout.addWidget(head, alignment=ALEFT)

Expand All @@ -230,14 +239,22 @@ def setup_left_sidebar(self, frame:QFrame):
entry_button_config = {
'default': {'margin-bottom': '@isp'},
'Browse ...': {'callback': lambda: self.browse_log(self.entry), 'align': ALEFT},
'Analyze': {'callback': lambda: self.analyze_log_callback(path=self.entry.text()), 'align': ARIGHT}
'Analyze': {'callback': lambda: self.analyze_log_callback(path=self.entry.text()), 'align': ARIGHT},
}
entry_buttons = self.create_button_series(button_frame, entry_button_config, 'button')
button_frame.setLayout(entry_buttons)
left_layout.addWidget(button_frame)

save_button = self.create_icon_button(self.icons['save'], 'icon_button', frame)
left_button_layout.addWidget(save_button, alignment=ALEFT)

truncate_button = self.create_icon_button(self.icons['truncate'], 'icon_button', frame)
left_button_layout.addWidget(truncate_button, alignment=ALEFT)

refresh_button = self.create_icon_button(self.icons['refresh'], 'icon_button', frame)
left_layout.addWidget(refresh_button, alignment=ARIGHT)
left_button_layout.addWidget(refresh_button, alignment=ARIGHT)

left_layout.addLayout(left_button_layout)

background_frame = self.create_frame(frame, 'light_frame',
{'border-radius': self.theme['listbox']['border-radius']})
Expand All @@ -254,6 +271,8 @@ def setup_left_sidebar(self, frame:QFrame):
left_layout.addWidget(background_frame, stretch=1)

refresh_button.clicked.connect(lambda: self.analyze_log_callback(self.current_combats.currentRow()))
save_button.clicked.connect(lambda: self.save_log(self.entry))
truncate_button.clicked.connect(lambda: self.truncate_log(self.entry))

frame.setLayout(left_layout)

Expand Down Expand Up @@ -548,6 +567,36 @@ def browse_log(self, entry:QLineEdit):
if path != '':
entry.setText(format_path(path))

def save_log(self, entry:QLineEdit):
"""
Callback for save button.
Parameters:
- :param entry: QLineEdit -> path entry line widget
"""
if self.parser1 and self.parser1.active_combat:
current_path = entry.text()
if current_path != '':
path = self.browse_path(os.path.dirname(current_path), 'Logfile (*.log);;Any File (*.*)', save=True)
if path != '':
with open(path, "w") as file:
for line in self.parser1.active_combat.log_data:
file.write(logline_to_str(line))

def truncate_log(self, entry:QLineEdit):
"""
Callback for truncate button.
Parameters:
- :param entry: QLineEdit -> path entry line widget
"""
if self.parser1 and self.parser1.active_combat:
current_path = entry.text()
with open(current_path, "w") as file:
for line in self.parser1.active_combat.log_data:
file.write(logline_to_str(line))
self.analyze_log_callback(path=self.entry.text())

def set_variable(self, var_to_be_set, index, value):
"""
Assigns value at index to variable
Expand Down
12 changes: 7 additions & 5 deletions OSCRUI/iofunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# object methods

def browse_path(self, default_path: str = None, types: str = 'Any File (*.*)') -> str:
def browse_path(self, default_path: str = None, types: str = 'Any File (*.*)', save=False) -> str:
"""
Opens file dialog prompting the user to select a file.
Expand All @@ -23,11 +23,13 @@ def browse_path(self, default_path: str = None, types: str = 'Any File (*.*)') -
default_path = os.path.abspath(default_path)
if not os.path.exists(default_path):
default_path = self.settings.value('base_path')
f = QFileDialog.getOpenFileName(self.window, 'Open Log', default_path, types)[0]
if os.path.exists(f):
return f
if save:
f = QFileDialog.getSaveFileName(self.window, 'Save Log', default_path, types)[0]
else:
return ''
f = QFileDialog.getOpenFileName(self.window, 'Open Log', default_path, types)[0]
if not os.path.exists(f):
return ''
return f

# static functions

Expand Down
1 change: 1 addition & 0 deletions assets/save-cw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/truncate-cw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ nixpkgs.mkShell {
nativeBuildInputs = with nixpkgs; [
nixpkgs.python311
nixpkgs.python311Packages.pyside6
nixpkgs.qt6.full
];
}

0 comments on commit c3363c8

Please sign in to comment.