Source code for wonambi.widgets.creation
"""Functions used when creating a new window.
"""
from logging import getLogger
from functools import partial
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QAction,
QDockWidget,
QMessageBox,
)
from .settings import Settings # has to be first
from .utils import ICON # has to be second
from .labels import Labels
from .channels import Channels
from .info import Info, ExportDatasetDialog
from .overview import Overview
from .notes import Notes, MergeDialog, ExportEventsDialog
from .detect_dialogs import SpindleDialog, SWDialog
from .analysis import AnalysisDialog
from .spectrum import Spectrum
from .traces import Traces
from .video import Video
lg = getLogger(__name__)
[docs]def create_widgets(MAIN):
"""Create all the widgets and dockwidgets. It also creates actions to
toggle views of dockwidgets in dockwidgets.
"""
""" ------ CREATE WIDGETS ------ """
MAIN.labels = Labels(MAIN)
MAIN.channels = Channels(MAIN)
MAIN.notes = Notes(MAIN)
MAIN.merge_dialog = MergeDialog(MAIN)
MAIN.export_events_dialog = ExportEventsDialog(MAIN)
MAIN.export_dataset_dialog = ExportDatasetDialog(MAIN)
MAIN.spindle_dialog = SpindleDialog(MAIN)
MAIN.slow_wave_dialog = SWDialog(MAIN)
MAIN.analysis_dialog = AnalysisDialog(MAIN)
#MAIN.plot_dialog = PlotDialog(MAIN)
MAIN.overview = Overview(MAIN)
MAIN.spectrum = Spectrum(MAIN)
MAIN.traces = Traces(MAIN)
MAIN.video = Video(MAIN)
MAIN.settings = Settings(MAIN) # depends on all widgets apart from Info
MAIN.info = Info(MAIN) # this has to be the last, it depends on settings
MAIN.setCentralWidget(MAIN.traces)
""" ------ LIST DOCKWIDGETS ------ """
new_docks = [{'name': 'Information',
'widget': MAIN.info,
'main_area': Qt.LeftDockWidgetArea,
'extra_area': Qt.RightDockWidgetArea,
},
{'name': 'Labels',
'widget': MAIN.labels,
'main_area': Qt.RightDockWidgetArea,
'extra_area': Qt.LeftDockWidgetArea,
},
{'name': 'Channels',
'widget': MAIN.channels,
'main_area': Qt.RightDockWidgetArea,
'extra_area': Qt.LeftDockWidgetArea,
},
{'name': 'Spectrum',
'widget': MAIN.spectrum,
'main_area': Qt.RightDockWidgetArea,
'extra_area': Qt.LeftDockWidgetArea,
},
{'name': 'Annotations',
'widget': MAIN.notes,
'main_area': Qt.LeftDockWidgetArea,
'extra_area': Qt.RightDockWidgetArea,
},
{'name': 'Video',
'widget': MAIN.video,
'main_area': Qt.LeftDockWidgetArea,
'extra_area': Qt.RightDockWidgetArea,
},
{'name': 'Overview',
'widget': MAIN.overview,
'main_area': Qt.BottomDockWidgetArea,
'extra_area': Qt.TopDockWidgetArea,
},
]
""" ------ CREATE DOCKWIDGETS ------ """
idx_docks = {}
actions = MAIN.action
actions['dockwidgets'] = []
for dock in new_docks:
dockwidget = QDockWidget(dock['name'], MAIN)
dockwidget.setWidget(dock['widget'])
dockwidget.setAllowedAreas(dock['main_area'] | dock['extra_area'])
dockwidget.setObjectName(dock['name']) # savestate
idx_docks[dock['name']] = dockwidget
MAIN.addDockWidget(dock['main_area'], dockwidget)
dockwidget_action = dockwidget.toggleViewAction()
dockwidget_action.setIcon(QIcon(ICON['widget']))
actions['dockwidgets'].append(dockwidget_action)
""" ------ ORGANIZE DOCKWIDGETS ------ """
MAIN.tabifyDockWidget(idx_docks['Information'],
idx_docks['Video'])
MAIN.tabifyDockWidget(idx_docks['Channels'],
idx_docks['Labels'])
idx_docks['Information'].raise_()
[docs]def create_actions(MAIN):
"""Create all the possible actions."""
actions = MAIN.action # actions was already taken
""" ------ OPEN SETTINGS ------ """
actions['open_settings'] = QAction(QIcon(ICON['settings']), 'Settings',
MAIN)
actions['open_settings'].triggered.connect(MAIN.show_settings)
""" ------ CLOSE WINDOW ------ """
actions['close_wndw'] = QAction(QIcon(ICON['quit']), 'Quit', MAIN)
actions['close_wndw'].triggered.connect(MAIN.close)
""" ------ ABOUT ------ """
actions['about'] = QAction('About WONAMBI', MAIN)
actions['about'].triggered.connect(MAIN.about)
actions['aboutqt'] = QAction('About Qt', MAIN)
actions['aboutqt'].triggered.connect(lambda: QMessageBox.aboutQt(MAIN))
[docs]def create_toolbar(MAIN):
"""Create the various toolbars."""
actions = MAIN.action
toolbar = MAIN.addToolBar('File Management')
toolbar.setObjectName('File Management') # for savestate
toolbar.addAction(MAIN.info.action['open_dataset'])
toolbar.addSeparator()
toolbar.addAction(MAIN.channels.action['load_channels'])
toolbar.addAction(MAIN.channels.action['save_channels'])
toolbar.addSeparator()
toolbar.addAction(MAIN.notes.action['new_annot'])
toolbar.addAction(MAIN.notes.action['load_annot'])
""" ------ SCROLL ------ """
actions = MAIN.traces.action
toolbar = MAIN.addToolBar('Scroll')
toolbar.setObjectName('Scroll') # for savestate
toolbar.addAction(actions['step_prev'])
toolbar.addAction(actions['step_next'])
toolbar.addAction(actions['page_prev'])
toolbar.addAction(actions['page_next'])
toolbar.addSeparator()
toolbar.addAction(actions['X_more'])
toolbar.addAction(actions['X_less'])
toolbar.addSeparator()
toolbar.addAction(actions['Y_less'])
toolbar.addAction(actions['Y_more'])
toolbar.addAction(actions['Y_wider'])
toolbar.addAction(actions['Y_tighter'])
""" ------ ANNOTATIONS ------ """
actions = MAIN.notes.action
toolbar = MAIN.addToolBar('Annotations')
toolbar.setObjectName('Annotations')
toolbar.addAction(actions['new_bookmark'])
toolbar.addSeparator()
toolbar.addAction(actions['new_event'])
toolbar.addWidget(MAIN.notes.idx_eventtype)
toolbar.addSeparator()
toolbar.addWidget(MAIN.notes.idx_stage)
toolbar.addWidget(MAIN.notes.idx_quality)