Skip to content

Commit

Permalink
Merge 5f80b81 into 8ba7209
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Mar 4, 2020
2 parents 8ba7209 + 5f80b81 commit cd62ae3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 71 deletions.
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -236,7 +236,7 @@ The command line interface accepts other arguments too:
.. code-block::
usage: neurotic [-h] [-V] [--debug] [--no-lazy] [--thick-traces]
[--show-datetime] [--ui-scale {tiny,small,large,huge}]
[--show-datetime] [--ui-scale {tiny,small,medium,large,huge}]
[--theme {light,dark,original,printer-friendly}]
[--launch-example-notebook]
[file] [dataset]
Expand All @@ -262,9 +262,9 @@ The command line interface accepts other arguments too:
--show-datetime display the real-world date and time, which may be
inaccurate depending on file type and acquisition
software (default: do not display)
--ui-scale {tiny,small,large,huge}
--ui-scale {tiny,small,medium,large,huge}
the scale of user interface elements, such as text
(default: small)
(default: medium)
--theme {light,dark,original,printer-friendly}
a color theme for the GUI (default: light)
--launch-example-notebook
Expand Down
31 changes: 10 additions & 21 deletions neurotic/gui/config.py
Expand Up @@ -99,26 +99,13 @@ def __init__(self, metadata, blk, lazy = False):
'label_fill_color': '#DDDDDDDD', # transparent light gray
}

self.ui_scales = {}
self.ui_scales['tiny'] = {
'app_font_size': 6,
'channel_label_size': 6,
'scatter_size': 3,
}
self.ui_scales['small'] = {
'app_font_size': 8,
'channel_label_size': 8,
'scatter_size': 5,
}
self.ui_scales['large'] = {
'app_font_size': 12,
'channel_label_size': 14,
'scatter_size': 10,
}
self.ui_scales['huge'] = {
'app_font_size': 14,
'channel_label_size': 16,
'scatter_size': 15,
self.default_font_size = ephyviewer.QT.QFont().pointSize()
self.ui_scales = {
'tiny': {'app_font_size': self.default_font_size-4, 'channel_label_size': self.default_font_size-4, 'scatter_size': 4},
'small': {'app_font_size': self.default_font_size-2, 'channel_label_size': self.default_font_size-2, 'scatter_size': 6},
'medium': {'app_font_size': self.default_font_size, 'channel_label_size': self.default_font_size, 'scatter_size': 8},
'large': {'app_font_size': self.default_font_size+2, 'channel_label_size': self.default_font_size+2, 'scatter_size': 10},
'huge': {'app_font_size': self.default_font_size+4, 'channel_label_size': self.default_font_size+4, 'scatter_size': 12},
}

# hide and disable viewers for which inputs are missing
Expand Down Expand Up @@ -314,7 +301,9 @@ def create_ephyviewer_window(self, theme='light', ui_scale='small', support_incr
win.setAttribute(ephyviewer.QT.WA_DeleteOnClose, True)

# set the font size for most text
win.setStyleSheet(f"font: {self.ui_scales[ui_scale]['app_font_size']}pt")
font = win.font()
font.setPointSize(self.ui_scales[ui_scale]['app_font_size'])
win.setFont(font)

########################################################################
# COLORS
Expand Down
24 changes: 20 additions & 4 deletions neurotic/gui/standalone.py
Expand Up @@ -82,11 +82,12 @@ def __init__(self, file=None, initial_selection=None, lazy=True, theme='light',
# lazy loading using Neo RawIO
self.lazy = lazy

# available themes are 'light', 'dark', and 'original'
# available themes are 'light', 'dark', 'original', and 'printer-friendly'
self.theme = theme

# available sizes are 'tiny', 'small', 'large', and 'huge'
# available sizes are 'tiny', 'small', 'medium', 'large', and 'huge'
self.ui_scale = ui_scale
self.default_font_size = QT.QFont().pointSize()

# support_increased_line_width=True eliminates the extremely poor
# performance associated with TraceViewer's line_width > 1.0, but it
Expand Down Expand Up @@ -221,13 +222,14 @@ def create_menus(self):

ui_scale_group = QT.QActionGroup(appearance_menu)
ui_scale_actions = {}
for size in ['tiny', 'small', 'large', 'huge']:
for size in ['tiny', 'small', 'medium', 'large', 'huge']:
ui_scale_actions[size] = appearance_menu.addAction(f'&{size.capitalize()} scale')
ui_scale_actions[size].setCheckable(True)
ui_scale_actions[size].triggered.connect(lambda checked, size=size: self.set_ui_scale(size))
ui_scale_group.addAction(ui_scale_actions[size])
if self.ui_scale in ui_scale_actions:
ui_scale_actions[self.ui_scale].setChecked(True)
self.set_ui_scale(self.ui_scale)
else:
raise ValueError('ui scale "{}" is unrecognized'.format(self.ui_scale))

Expand Down Expand Up @@ -568,6 +570,17 @@ def toggle_show_datetime(self, checked):
def set_ui_scale(self, size):
self.ui_scale = size

font_size = {
'tiny': self.default_font_size-4,
'small': self.default_font_size-2,
'medium': self.default_font_size,
'large': self.default_font_size+2,
'huge': self.default_font_size+4,
}
font = self.font()
font.setPointSize(font_size[size])
self.setFont(font)

def set_theme(self, theme):
self.theme = theme

Expand Down Expand Up @@ -615,7 +628,10 @@ def __init__(self, mainwindow):
self.mainwindow = mainwindow

self.setSelectionMode(QT.QListWidget.SingleSelection)
self.setStyleSheet('font: 9pt Courier;')

font = self.font()
font.setFamily('Courier')
self.setFont(font)

self.currentRowChanged.connect(self._on_select)
self.itemDoubleClicked.connect(self.mainwindow.start_launch)
Expand Down
8 changes: 4 additions & 4 deletions neurotic/scripts.py
Expand Up @@ -61,10 +61,10 @@ def parse_args(argv):
'may be inaccurate depending on file type and ' \
'acquisition software (default: do not display)')
parser.add_argument('--ui-scale', dest='ui_scale',
choices=['tiny', 'small', 'large', 'huge'],
default='small', help='the scale of user interface ' \
'elements, such as text ' \
'(default: small)')
choices=['tiny', 'small', 'medium', 'large', 'huge'],
default='medium', help='the scale of user interface ' \
'elements, such as text ' \
'(default: medium)')
parser.add_argument('--theme', choices=['light', 'dark', 'original',
'printer-friendly'],
default='light', help='a color theme for the GUI ' \
Expand Down
50 changes: 11 additions & 39 deletions neurotic/tests/test_cli.py
Expand Up @@ -75,7 +75,7 @@ def test_cli_defaults(self):
'thick traces enabled without --thick-traces')
self.assertFalse(win.show_datetime,
'datetime enabled without --show-datetime')
self.assertEqual(win.ui_scale, 'small',
self.assertEqual(win.ui_scale, 'medium',
'ui_scale changed without --ui-scale')
self.assertEqual(win.theme, 'light', 'theme changed without --theme')
self.assertEqual(win.metadata_selector.file, self.default_file,
Expand Down Expand Up @@ -123,49 +123,21 @@ def test_ui_scale(self):
"""Test that --ui-scale changes the ui_scale"""
app = mkQApp()

argv = ['neurotic', '--ui-scale', 'tiny']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.ui_scale, 'tiny', 'unexpected scale')

argv = ['neurotic', '--ui-scale', 'small']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.ui_scale, 'small', 'unexpected scale')

argv = ['neurotic', '--ui-scale', 'large']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.ui_scale, 'large', 'unexpected scale')

argv = ['neurotic', '--ui-scale', 'huge']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.ui_scale, 'huge', 'unexpected scale')
for size in ['tiny', 'small', 'medium', 'large', 'huge']:
argv = ['neurotic', '--ui-scale', size]
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.ui_scale, size, 'unexpected scale')

def test_theme(self):
"""Test that --theme changes the theme"""
app = mkQApp()

argv = ['neurotic', '--theme', 'light']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.theme, 'light', 'unexpected theme')

argv = ['neurotic', '--theme', 'dark']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.theme, 'dark', 'unexpected theme')

argv = ['neurotic', '--theme', 'original']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.theme, 'original', 'unexpected theme')

argv = ['neurotic', '--theme', 'printer-friendly']
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.theme, 'printer-friendly', 'unexpected theme')
for theme in ['light', 'dark', 'original', 'printer-friendly']:
argv = ['neurotic', '--theme', theme]
args = neurotic.parse_args(argv)
win = neurotic.win_from_args(args)
self.assertEqual(win.theme, theme, 'unexpected theme')

def test_file(self):
"""Test that metadata file can be set"""
Expand Down

0 comments on commit cd62ae3

Please sign in to comment.