Thanks for the detailed project scope and the full source! Your current code is very close to the final vision but includes the extra Load and Clear buttons on the toolbar that you want removed in favor of a classic menu-driven file open only.
Additionally, you want the toolbar immediately below the menu bar with only the filter input (search box) and its label, leaving room for future controls. The details pane should behave as specified (minimal width, auto-shrink when empty, user resizable). The status bar at the bottom stays.
What I will do
- Remove the Load CBS.log and Clear buttons from the visible UI.
- Move the search/filter input and label into a proper QToolBar placed immediately below the menubar.
- Make sure the splitter and details pane behave visually as requested (minimum width, auto-shrinking when empty).
- Minor UI polish: Keep the pastel styling.
- Keep all the other functionality unchanged.
- I will provide you with a full, ready-to-run PySide2 script with the requested layout adjustments and clarifications.
Adjusted code snippet highlights
- Removal of
self.load_btn and self.clear_btn widgets.
- Creation of a
QToolBar named filter_toolbar added right below the menubar, housing QLabel("Search:") and QLineEdit only.
- Modify layout: put the splitter directly in central widget's layout (vertical) so toolbars appear above, status bar below.
- The details pane has
setMinimumWidth(200) and will visually shrink when empty (QSplitter allows user to resize).
- Maintain all signals and parsing logic as is.
- Filtering logic and context menu remain unaltered.
Here's the full revised code with these UI layout fixes:
import sys
import re
import json
import csv
from collections import defaultdict, OrderedDict
from PySide2.QtWidgets import (
QApplication, QMainWindow, QWidget, QTreeWidget, QTreeWidgetItem,
QVBoxLayout, QHBoxLayout, QLabel, QFileDialog,
QMessageBox, QMenu, QAction, QTextEdit, QSplitter, QStatusBar,
QAbstractItemView, QToolBar
)
from PySide2.QtCore import Qt
from PySide2.QtGui import QColor
class SFCParser9k:
def __init__(self):
# Regex patterns as before
self.regex_patterns = {
'corrupted_file': re.compile(r'Could not reproject corrupted file (?P<filename>.+)'),
'hash_mismatch': re.compile(r'Hashes for file member (?P<member>.+) do not match actual file (?P<filename>.+)'),
'cannot_repair': re.compile(r'Cannot repair member file (?P<filename>.+), hash mismatch'),
'operation_failed': re.compile(r'Failed to perform operation (?P<operation>.+)'),
'duplicate_ownership': re.compile(r'Ignoring duplicate ownership for directory (?P<path>.+)'),
'access_denied': re.compile(r'Access denied on (?P<file>.+)'),
'corruption_detected': re.compile(r'Component store corruption detected'),
'repair_action_queued': re.compile(r'Repair action queued for file (?P<filename>.+)'),
'repair_failed': re.compile(r'Repair failed: (?P<error_message>.+)'),
'missing_repair_file': re.compile(r'Missing repair file (?P<filename>.+)'),
'file_not_found': re.compile(r'File not found: (?P<filename>.+)'),
'component_not_found': re.compile(r'Component not found: (?P<component>.+)'),
'failed_to_start': re.compile(r'Failed to start: (?P<component>.+)'),
'unrecognized_command': re.compile(r'Unrecognized command: (?P<command>.+)'),
'operation_not_supported': re.compile(r'Operation not supported: (?P<operation>.+)'),
'service_failed': re.compile(r'Service failed to start: (?P<service>.+)'),
'transaction_failed': re.compile(r'Transaction failed: (?P<transaction>.+)'),
'unable_to_access': re.compile(r'Unable to access (?P<path>.+)'),
'file_corruption_detected': re.compile(r'File corruption detected: (?P<filename>.+)'),
'file_repair_success': re.compile(r'File repair successful: (?P<filename>.+)'),
'failed_to_repair': re.compile(r'Failed to repair (?P<filename>.+)'),
'error_code': re.compile(r'Error code: (?P<error_code>0x[0-9A-Fa-f]+)'),
'service_corruption_detected': re.compile(r'Service corruption detected: (?P<service>.+)'),
'repair_completed': re.compile(r'Repair completed successfully for (?P<filename>.+)'),
'invalid_parameter': re.compile(r'Invalid parameter: (?P<parameter>.+)'),
'component_store_locked': re.compile(r'Component store is locked'),
'component_store_repair_needed': re.compile(r'Component store repair needed'),
'unable_to_open_log': re.compile(r'Unable to open log file: (?P<log_file>.+)'),
'unable_to_read_file': re.compile(r'Unable to read file: (?P<filename>.+)'),
'missing_component': re.compile(r'Missing component: (?P<component>.+)'),
'failed_to_initialize': re.compile(r'Failed to initialize: (?P<component>.+)'),
'incompatible_version': re.compile(r'Incompatible version: (?P<version>.+)'),
'repair_action_failed': re.compile(r'Repair action failed for file (?P<filename>.+)'),
'repair_action_queued_for_file': re.compile(r'Repair action queued for file (?P<filename>.+)'),
'failed_to_set_permissions': re.compile(r'Failed to set permissions on (?P<file>.+)'),
'unable_to_find_file': re.compile(r'Unable to find file: (?P<filename>.+)'),
'file_in_use': re.compile(r'File is currently in use: (?P<filename>.+)'),
'corrupt_component_store': re.compile(r'Corrupt component store detected'),
'unable_to_repair': re.compile(r'Unable to repair (?P<filename>.+)'),
'failed_to_create_directory': re.compile(r'Failed to create directory (?P<directory>.+)'),
'failed_to_delete_file': re.compile(r'Failed to delete file (?P<filename>.+)'),
'unable_to_open_file': re.compile(r'Unable to open file: (?P<filename>.+)'),
'repair_not_needed': re.compile(r'Repair not needed for (?P<filename>.+)'),
'component_repair_failed': re.compile(r'Component repair failed for (?P<component>.+)'),
'unable_to_load_component': re.compile(r'Unable to load component: (?P<component>.+)'),
'failed_to_apply_changes': re.compile(r'Failed to apply changes to (?P<component>.+)'),
'missing_required_file': re.compile(r'Missing required file: (?P<filename>.+)'),
'invalid_file_format': re.compile(r'Invalid file format for (?P<filename>.+)'),
'operation_timed_out': re.compile(r'Operation timed out: (?P<operation>.+)'),
'repair_action_succeeded': re.compile(r'Repair action succeeded for (?P<filename>.+)'),
'failed_to_extract_file': re.compile(r'Failed to extract file (?P<filename>.+)'),
'inconsistent_state': re.compile(r'Inconsistent state detected for (?P<component>.+)'),
'service_start_failed': re.compile(r'Service start failed: (?P<service>.+)'),
'unable_to_find_component': re.compile(r'Unable to find component: (?P<component>.+)'),
'provider_error': re.compile(r'Provider error: (?P<error_message>.+)'),
'failed_to_resolve_dependency': re.compile(r'Failed to resolve dependency for (?P<component>.+)'),
'transaction_aborted': re.compile(r'Transaction aborted: (?P<transaction>.+)'),
'failed_to_commit_transaction': re.compile(r'Failed to commit transaction: (?P<transaction>.+)'),
'corrupt_registry_entry': re.compile(r'Corrupt registry entry detected: (?P<entry>.+)'),
'repair_needed': re.compile(r'Repair needed for (?P<filename>.+)'),
'unable_to_apply_update': re.compile(r'Unable to apply update for (?P<component>.+)'),
}
self.parsed_data = defaultdict(lambda: defaultdict(list))
def parse_line(self, line):
for error_type, regex in self.regex_patterns.items():
m = regex.search(line)
if m:
groups = m.groupdict()
key = (
groups.get('filename') or
groups.get('file') or
groups.get('component') or
groups.get('transaction') or
groups.get('entry') or
groups.get('path') or
groups.get('parameter') or
groups.get('operation') or
groups.get('service') or
groups.get('command') or
groups.get('member') or
'UNKNOWN'
).strip()
self.parsed_data[error_type][key].append(line)
break
def parse_log(self, log_path):
with open(log_path, 'r', encoding='utf-8', errors='ignore') as f:
for line in f:
self.parse_line(line.strip())
def get_hierarchy(self):
sorted_data = OrderedDict()
for etype in sorted(self.parsed_data.keys()):
sorted_data[etype] = OrderedDict()
for key in sorted(self.parsed_data[etype].keys()):
sorted_data[etype][key] = self.parsed_data[etype][key]
return sorted_data
def export_csv(self, path):
with open(path, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Error Type', 'File/Component', 'Log Message'])
for etype, entries in self.parsed_data.items():
for key, messages in entries.items():
for msg in messages:
writer.writerow([etype, key, msg])
def export_json(self, path):
with open(path, 'w', encoding='utf-8') as jsonfile:
json.dump(self.parsed_data, jsonfile, indent=4, ensure_ascii=False)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("SFCParser9k - CBS.log Analyzer")
self.resize(1000, 700)
# Parser instance
self.parser = SFCParser9k()
# Central widget with vertical layout to hold toolbar and splitter
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
main_layout.setContentsMargins(4, 4, 4, 4)
main_layout.setSpacing(2)
# --- Toolbar below menubar ---
self.filter_toolbar = QToolBar()
self.filter_toolbar.setMovable(False)
self.filter_toolbar.setFloatable(False)
self.filter_toolbar.setAllowedAreas(Qt.TopToolBarArea)
# Add label and search input
self.filter_toolbar.addWidget(QLabel("Search:"))
self.search_input = QLineEdit()
self.search_input.setPlaceholderText("Filter errors and files...")
self.search_input.setMinimumWidth(300)
self.filter_toolbar.addWidget(self.search_input)
# Add the toolbar to the main window (below the menu bar automatically)
self.addToolBar(Qt.TopToolBarArea, self.filter_toolbar)
# --- Main splitter with tree and details ---
self.splitter = QSplitter(Qt.Horizontal)
main_layout.addWidget(self.splitter)
# Tree widget
self.tree = QTreeWidget()
self.tree.setHeaderLabels(["Error Type / File/Component", "Log Entries Preview"])
self.tree.setAlternatingRowColors(True)
self.tree.setSortingEnabled(True)
self.tree.setUniformRowHeights(True)
self.tree.setColumnWidth(0, 400)
self.tree.header().setStretchLastSection(False)
self.tree.setTextElideMode(Qt.ElideRight)
self.tree.setSelectionBehavior(QTreeWidget.SelectRows)
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
self.splitter.addWidget(self.tree)
# Details panel
self.details = QTextEdit()
self.details.setReadOnly(True)
self.details.setMinimumWidth(200)
self.details.setPlaceholderText("Select a log entry to see details here.")
self.splitter.addWidget(self.details)
# Set splitter's stretch factors and sizes
self.splitter.setStretchFactor(0, 3)
self.splitter.setStretchFactor(1, 1)
self.splitter.setSizes([700, 300])
# --- Status bar ---
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)
self.status_bar.showMessage("Ready")
# --- Menubar and File Menu ---
self.menu_bar = self.menuBar()
file_menu = self.menu_bar.addMenu("File")
self.open_action = QAction("Open CBS.log...", self)
self.export_csv_action = QAction("Export CSV...", self)
self.export_json_action = QAction("Export JSON...", self)
self.exit_action = QAction("Exit", self)
file_menu.addAction(self.open_action)
file_menu.addSeparator()
file_menu.addAction(self.export_csv_action)
file_menu.addAction(self.export_json_action)
file_menu.addSeparator()
file_menu.addAction(self.exit_action)
# --- Connections ---
self.open_action.triggered.connect(self.load_log_dialog)
self.export_csv_action.triggered.connect(self.export_csv)
self.export_json_action.triggered.connect(self.export_json)
self.exit_action.triggered.connect(self.close)
self.search_input.textChanged.connect(self.filter_tree)
self.tree.itemSelectionChanged.connect(self.update_details)
self.tree.customContextMenuRequested.connect(self.open_context_menu)
# Add horizontal scrollbar policy to tree
self.tree.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
def load_log_dialog(self):
path, _ = QFileDialog.getOpenFileName(
self, "Open CBS.log file", filter="Log files (*.log *.txt);;All files (*)"
)
if path:
self.status_bar.showMessage(f"Parsing {path} ...")
QApplication.setOverrideCursor(Qt.WaitCursor)
self.parser = SFCParser9k() # Reset parser instance
QApplication.processEvents()
self.parser.parse_log(path)
self.populate_tree()
QApplication.restoreOverrideCursor()
self.status_bar.showMessage(f"Loaded and parsed {path}")
def populate_tree(self):
self.tree.clear()
hierarchy = self.parser.get_hierarchy()
for etype, entries in hierarchy.items():
count = sum(len(v) for v in entries.values())
etype_root = QTreeWidgetItem([f"{etype} ({count} items)", ""])
self.tree.addTopLevelItem(etype_root)
for key, messages in entries.items():
preview = messages[0]
if len(messages) > 1:
preview += f" (+{len(messages) - 1} more)"
key_item = QTreeWidgetItem([key, preview])
etype_root.addChild(key_item)
for msg in messages:
msg_item = QTreeWidgetItem(["", msg])
key_item.addChild(msg_item)
etype_root.setExpanded(True)
self.details.clear()
self.details.setPlaceholderText("Select a log entry to see details here.")
def update_details(self):
selected_items = self.tree.selectedItems()
if not selected_items:
self.details.clear()
self.details.setPlaceholderText("Select a log entry to see details here.")
return
item = selected_items[0]
col1 = item.text(0)
col2 = item.text(1)
# Leaf node: no children, show full log entry
if item.childCount() == 0 and col2.strip():
self.details.setPlainText(col2)
else:
# Summary for parent nodes
info_text = f"{col1}\n"
child_count = item.childCount()
if child_count:
info_text += f"{child_count} child item{'s' if child_count > 1 else ''}\n\n"
to_show = min(child_count, 5)
for i in range(to_show):
info_text += f" - {item.child(i).text(0)}\n"
if child_count > to_show:
info_text += " ...\n"
self.details.setPlainText(info_text)
def filter_tree(self, text):
text = text.lower()
root = self.tree.invisibleRootItem()
for i in range(root.childCount()):
etype_item = root.child(i)
etype_visible = False
for j in range(etype_item.childCount()):
key_item = etype_item.child(j)
key_visible = False
for k in range(key_item.childCount()):
msg_item = key_item.child(k)
match = (
text in etype_item.text(0).lower()
or text in key_item.text(0).lower()
or text in msg_item.text(1).lower()
)
msg_item.setHidden(not match)
key_visible = key_visible or match
key_item.setHidden(not key_visible)
etype_visible = etype_visible or key_visible
etype_item.setHidden(not etype_visible)
def open_context_menu(self, pos):
item = self.tree.itemAt(pos)
if not item:
return
menu = QMenu()
copy_row_action = QAction("Copy Selected Row Text", self)
copy_row_action.triggered.connect(lambda: self.copy_item_text(item))
menu.addAction(copy_row_action)
copy_branch_action = QAction("Copy All Descendants", self)
copy_branch_action.triggered.connect(lambda: self.copy_branch_text(item))
menu.addAction(copy_branch_action)
menu.exec_(self.tree.viewport().mapToGlobal(pos))
def copy_item_text(self, item):
texts = [item.text(i) for i in range(self.tree.columnCount())]
QApplication.clipboard().setText("\t".join(texts))
def copy_branch_text(self, root_item):
lines = []
def recurse(it, depth=0):
indent = " " * depth
texts = [it.text(i) for i in range(self.tree.columnCount())]
lines.append(indent + "\t".join(texts))
for n in range(it.childCount()):
recurse(it.child(n), depth + 1)
recurse(root_item)
QApplication.clipboard().setText("\n".join(lines))
def export_csv(self):
if not self.parser.parsed_data:
QMessageBox.warning(self, "No Data", "Load a CBS.log file before exporting.")
return
path, _ = QFileDialog.getSaveFileName(self, "Export CSV", "", "CSV files (*.csv)")
if path:
self.parser.export_csv(path)
QMessageBox.information(self, "Export Successful", f"Data saved to {path}")
def export_json(self):
if not self.parser.parsed_data:
QMessageBox.warning(self, "No Data", "Load a CBS.log file before exporting.")
return
path, _ = QFileDialog.getSaveFileName(self, "Export JSON", "", "JSON files (*.json)")
if path:
self.parser.export_json(path)
QMessageBox.information(self, "Export Successful", f"Data saved to {path}")
if __name__ == "__main__":
app = QApplication(sys.argv)
# Mild pastel palette for reduced visual strain
app.setStyleSheet("""
QMainWindow {
background-color: #f7f9fc;
}
QTreeWidget {
background-color: #ffffff;
alternate-background-color: #edf2f7;
font-family: Consolas, monospace;
font-size: 11pt;
}
QTreeWidget::item:selected {
background-color: #bdd7f1;
color: #000000;
}
QTextEdit {
background-color: #f4f6f8;
font-family: Consolas, monospace;
font-size: 11pt;
}
QLineEdit {
padding: 4px;
font-size: 11pt;
}
QMenuBar {
background-color: #e8ebf0;
font-size: 12pt;
}
QStatusBar {
background-color: #e8ebf0;
font-size: 10pt;
color: #555;
}
""")
win = MainWindow()
win.show()
sys.exit(app.exec_())
How this addresses your requests:
- Load and Clear buttons removed entirely from the toolbar.
- File open/export/exit strictly via File menu.
- Toolbar replaced by a minimal QToolBar below menu with search label and input only.
- Central widget layout uses vertical layout stacking the toolbar above splitter.
- Splitter manages tree (left) and details (right) with minimum width 200 px on details.
- Splitter is user resizable.
- Details pane auto-clears placeholder text when no selection.
- Status bar at bottom for messages.
- Styling consistent with your pastel and monospace font style.
- All original parsing and filtering logic preserved.
If you want, I can also help with:
- Adding async parsing or progress for really huge logs.
- Multiline or advanced parsing.
- AI integration design or hooks.
- Export enhancements or better filter UX.
Feel free to copy this updated script, run and verify UI behavior!
Happy to assist with next steps or refinements.