Skip to content

Commit

Permalink
Header presets, custom columns, other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
busimus committed Jan 27, 2018
1 parent b5be4fa commit 299f11d
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 184 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ This will create "log namespaces" which allow you to filter out messages from va

## Planned features
* [ ] Presets for colors
* [ ] Presets for the logger header (with option to add columns for extra data)
* [ ] Modify how rows are arranged in the detail table (like the header dialog)
* [ ] Fix double-search on the last matched result (or indicate that the last result was reached)
* [ ] Ability to save and load logs (as text or as full records)
Expand Down
19 changes: 17 additions & 2 deletions cutelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Exc_Indication(enum.IntEnum):
# There must be a better way to do this, right?
Option = namedtuple('Option', ['name', 'type', 'default'])
OPTION_SPEC = (
# SETTINGS WINDOW:
# Appearance
('dark_theme_default', bool, False),
('logger_table_font', str, DEFAULT_FONT),
Expand All @@ -63,6 +64,10 @@ class Exc_Indication(enum.IntEnum):
('benchmark', bool, False),
('benchmark_interval', float, 0.0005),
('light_theme_is_native', bool, False),

# NON-SETTINGS OPTIONS:
# Header
('default_header_preset', str, "Default"),
)


Expand Down Expand Up @@ -115,6 +120,9 @@ def __setitem__(self, name, value):

def set_option(self, name, value):
self[name] = value
self.qsettings.beginGroup('Configuration')
self.qsettings.setValue(name, value)
self.qsettings.endGroup()

@staticmethod
def get_resource_path(name, directory='ui'):
Expand Down Expand Up @@ -183,13 +191,14 @@ def update_attributes(self, options=None):
self.logger_table_font_size = options.get('logger_table_font_size', self.logger_table_font_size)
self.set_logging_level(options.get('console_logging_level', ROOT_LOG.level))

def save_options(self):
def save_options(self, sync=False):
self.log.debug('Saving options')
self.qsettings.beginGroup('Configuration')
for option in self.option_spec:
self.qsettings.setValue(option.name, self.options[option.name])
self.qsettings.endGroup()
self.sync()
if sync: # syncing is probably not necessary here, so the default is False
self.sync()

def sync(self):
self.log.debug('Syncing QSettings')
Expand Down Expand Up @@ -242,6 +251,12 @@ def load_header_preset(self, name):
s.endGroup()
return result

def delete_header_preset(self, name):
s = self.qsettings
s.beginGroup('Header_Presets')
s.remove(name)
s.endGroup()

def save_geometry(self, geometry):
s = self.qsettings
s.beginGroup('Geometry')
Expand Down
3 changes: 2 additions & 1 deletion cutelog/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def run(self):
'relativeCreated': 4951865.670204163,
'stack_info': None,
'thread': 140062538003776,
'threadName': 'MainThread'}
'threadName': 'MainThread',
'extra_column': 'hey there'}
c = 0
while True:
if self.need_to_stop():
Expand Down
26 changes: 10 additions & 16 deletions cutelog/logger_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def __init__(self, parent, levels, header, max_capacity=0):
super().__init__(parent)
self.parent_widget = parent
self.levels = levels
# maxlen isn't needed here, because of how on_record has to handle max_capacity
self.records = deque(maxlen=max_capacity if max_capacity > 0 else None)
self.records = deque()
self.font = parent.font()
self.date_formatter = logging.Formatter('%(asctime)s') # to format unix timestamp as a date
self.dark_theme = False
Expand All @@ -158,7 +157,7 @@ def data(self, index, role=Qt.DisplayRole):

if role == Qt.DisplayRole:
column = self.table_header[index.column()]
result = getattr(record, column.name)
result = getattr(record, column.name, None)
elif role == Qt.DecorationRole:
if self.headerData(index.column()) == 'Message':
if record.exc_text:
Expand Down Expand Up @@ -308,14 +307,14 @@ def filterAcceptsRow(self, sourceRow, sourceParent):
result = True
if path:
name = record.name
# name is None for record added by method add_conn_closed_record().
# name is None for record added by method add_conn_closed_record().
if name is None:
result = False
elif name == path:
result = True
elif not self.selection_includes_children and name == path:
result = True
elif self.selection_includes_children and name.startswith('{}.'.format(path)):
elif self.selection_includes_children and name.startswith(path + '.'):
result = True
else:
result = False
Expand Down Expand Up @@ -718,21 +717,16 @@ def open_header_menu(self, position):
menu.popup(self.table_header_view.viewport().mapToGlobal(position))

def open_header_dialog(self):
d = HeaderEditDialog(self.main_window, self.table_header.columns)
d = HeaderEditDialog(self.main_window, self.table_header)
d.header_changed.connect(self.header_changed)
d.setWindowTitle('Header editor')
d.open()

def header_changed(self, action, data):
if action == 'rearrange':
self.table_header.replace_columns(data)
elif action == 'load':
loaded = CONFIG.load_columns_preset(data)
self.table_header.replace_columns(loaded)
elif action == 'save':
CONFIG.save_columns_preset(data, self)
elif action == 'save new':
pass
def header_changed(self, preset_name, set_as_default, columns):
self.table_header.preset_name = preset_name
if set_as_default:
CONFIG.set_option('default_header_preset', preset_name)
self.table_header.replace_columns(columns)
self.set_columns_sizes()

def merge_with_records(self, new_records):
Expand Down
Loading

0 comments on commit 299f11d

Please sign in to comment.