Refactor Common-/ProjectMixin.

Now delegates all methods/properties to a context object. It's easier to inject a TestContext
object, than using a TestMixin (which needed those separate *Impl classes).
looper
Ben Niemann 5 years ago
parent 6f07c55c2a
commit 407d3f3638
  1. 15
      noisicaa/ui/editor_app.py
  2. 21
      noisicaa/ui/editor_window.py
  3. 8
      noisicaa/ui/instrument_library.py
  4. 8
      noisicaa/ui/instrument_library_test.py
  5. 4
      noisicaa/ui/pipeline_graph_monitor.py
  6. 44
      noisicaa/ui/pipeline_graph_view.py
  7. 4
      noisicaa/ui/pipeline_perf_monitor.py
  8. 2
      noisicaa/ui/project_properties_dock.py
  9. 34
      noisicaa/ui/project_view.py
  10. 59
      noisicaa/ui/project_view_test.py
  11. 18
      noisicaa/ui/settings.py
  12. 4
      noisicaa/ui/stat_monitor.py
  13. 4
      noisicaa/ui/track_items/base_track_item.py
  14. 20
      noisicaa/ui/track_items/beat_track_item.py
  15. 16
      noisicaa/ui/track_items/control_track_item.py
  16. 10
      noisicaa/ui/track_items/sample_track_item.py
  17. 58
      noisicaa/ui/track_items/score_track_item.py
  18. 14
      noisicaa/ui/track_properties_dock.py
  19. 8
      noisicaa/ui/tracks_dock.py
  20. 16
      noisicaa/ui/tracks_dock_test.py
  21. 96
      noisicaa/ui/ui_base.py
  22. 17
      noisicaa/ui/uitest_utils.py

@ -41,6 +41,7 @@ from . import project_registry
from . import pipeline_perf_monitor
from . import pipeline_graph_monitor
from . import stat_monitor
from . import ui_base
logger = logging.getLogger('ui.editor_app')
@ -119,6 +120,8 @@ class InstrumentDBClient(instrument_db.InstrumentDBClientMixin, InstrumentDBClie
class BaseEditorApp(object):
def __init__(self, *, process, runtime_settings, settings=None):
self.__context = ui_base.CommonContext(app=self)
self.process = process
self.runtime_settings = runtime_settings
@ -140,6 +143,10 @@ class BaseEditorApp(object):
self.__clipboard = None
@property
def context_args(self):
return {'context': self.__context}
async def setup(self):
await self.createNodeDB()
await self.createInstrumentDB()
@ -308,16 +315,16 @@ class EditorApp(BaseEditorApp, QtWidgets.QApplication):
self.setStyle(style)
logger.info("Creating PipelinePerfMonitor.")
self.pipeline_perf_monitor = pipeline_perf_monitor.PipelinePerfMonitor(self)
self.pipeline_perf_monitor = pipeline_perf_monitor.PipelinePerfMonitor(**self.context_args)
# logger.info("Creating PipelineGraphMonitor.")
# self.pipeline_graph_monitor = pipeline_graph_monitor.PipelineGraphMonitor(self)
# self.pipeline_graph_monitor = pipeline_graph_monitor.PipelineGraphMonitor(**self.context_args)
logger.info("Creating StatMonitor.")
self.stat_monitor = stat_monitor.StatMonitor(self)
self.stat_monitor = stat_monitor.StatMonitor(**self.context_args)
logger.info("Creating EditorWindow.")
self.win = EditorWindow(self)
self.win = EditorWindow(**self.context_args)
await self.win.setup()
self.win.show()

@ -49,15 +49,15 @@ logger = logging.getLogger(__name__)
class CommandShellDockWidget(DockWidget):
def __init__(self, app, parent):
def __init__(self, *, parent, **kwargs):
super().__init__(
app=app,
parent=parent,
identifier='command_shell',
title="Command Shell",
allowed_areas=Qt.AllDockWidgetAreas,
initial_area=Qt.BottomDockWidgetArea,
initial_visible=False)
initial_visible=False,
**kwargs)
command_shell = CommandShell(parent=self)
self.setWidget(command_shell)
@ -71,14 +71,14 @@ class EditorWindow(ui_base.CommonMixin, QtWidgets.QMainWindow):
playbackLoopChanged = QtCore.pyqtSignal(bool)
projectListChanged = QtCore.pyqtSignal()
def __init__(self, app):
super().__init__(app=app)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._docks = []
self._settings_dialog = SettingsDialog(self.app, self)
self._settings_dialog = SettingsDialog(parent=self, **self.context_args)
self._instrument_library_dialog = instrument_library.InstrumentLibraryDialog(
**self.context, parent=self)
**self.context_args, parent=self)
self._current_project_view = None
@ -411,7 +411,7 @@ class EditorWindow(ui_base.CommonMixin, QtWidgets.QMainWindow):
self.setStatusBar(self.statusbar)
def createDockWidgets(self):
self._docks.append(CommandShellDockWidget(self.app, self))
self._docks.append(CommandShellDockWidget(parent=self, **self.context_args))
def storeState(self):
logger.info("Saving current EditorWindow geometry.")
@ -485,10 +485,11 @@ class EditorWindow(ui_base.CommonMixin, QtWidgets.QMainWindow):
self.currentProjectChanged.emit(None)
async def addProjectView(self, project_connection):
view = ProjectView(
context = ui_base.ProjectContext(
selection_set=selection_set.SelectionSet(),
project_connection=project_connection,
**self.context)
app=self.app)
view = ProjectView(context=context)
await view.setup()
idx = self._project_tabs.addTab(view, project_connection.name)

@ -132,7 +132,7 @@ class Instrument(Item):
return self.description.display_name
class LibraryModelImpl(QtCore.QAbstractItemModel):
class LibraryModel(ui_base.CommonMixin, QtCore.QAbstractItemModel):
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -313,10 +313,6 @@ class LibraryModelImpl(QtCore.QAbstractItemModel):
return None
class LibraryModel(ui_base.CommonMixin, LibraryModelImpl):
pass
class FilterModel(QtCore.QSortFilterProxyModel):
def __init__(self, source, **kwargs):
super().__init__(**kwargs)
@ -425,7 +421,7 @@ class InstrumentLibraryDialog(ui_base.CommonMixin, QtWidgets.QDialog):
self.instruments_search.addAction(action, QtWidgets.QLineEdit.TrailingPosition)
self.instruments_search.textChanged.connect(self.onInstrumentSearchChanged)
self.__model = LibraryModel(**self.context)
self.__model = LibraryModel(**self.context_args)
self.__model_filter = FilterModel(self.__model)
self.__view = LibraryView(self)
self.__view.setModel(self.__model_filter)

@ -32,10 +32,6 @@ from . import uitest_utils
from . import instrument_library
class TestLibraryModel(uitest_utils.TestMixin, instrument_library.LibraryModelImpl):
pass
class TracksModelTest(uitest_utils.UITest):
async def setUp(self):
await super().setUp()
@ -48,7 +44,7 @@ class TracksModelTest(uitest_utils.UITest):
properties={})
async def test_addInstrument(self):
model = TestLibraryModel(**self.context)
model = instrument_library.LibraryModel(**self.context_args)
try:
root_index = QtCore.QModelIndex()
self.assertEqual(model.rowCount(root_index), 0)
@ -71,7 +67,7 @@ class TracksModelTest(uitest_utils.UITest):
model.close()
async def test_addInstrument_long_path(self):
model = TestLibraryModel(**self.context)
model = instrument_library.LibraryModel(**self.context_args)
try:
model.addInstrument(self.__mkinstr('/some/path/test1.wav'))
self.assertEqual(

@ -38,7 +38,7 @@ from . import ui_base
logger = logging.getLogger(__name__)
class AudioProcClientImpl(object):
class AudioProcClient(audioproc.AudioProcClientMixin):
def __init__(self, monitor):
super().__init__()
self.event_loop = monitor.event_loop
@ -51,8 +51,6 @@ class AudioProcClientImpl(object):
async def cleanup(self):
await self.server.cleanup()
class AudioProcClient(
audioproc.AudioProcClientMixin, AudioProcClientImpl):
def handle_pipeline_mutation(self, mutation):
self.monitor.onPipelineMutation(mutation)

@ -624,7 +624,7 @@ class NodePropertyDialog(
drywet=float(value))
class NodeItemImpl(QtWidgets.QGraphicsRectItem):
class NodeItem(ui_base.ProjectMixin, QtWidgets.QGraphicsRectItem):
def __init__(self, node, view, **kwargs):
super().__init__(**kwargs)
self._node = node
@ -696,7 +696,7 @@ class NodeItemImpl(QtWidgets.QGraphicsRectItem):
self._properties_dialog = NodePropertyDialog(
node_item=self,
parent=self.window,
**self.context)
**self.context_args)
@property
def node(self):
@ -838,11 +838,8 @@ class NodeItemImpl(QtWidgets.QGraphicsRectItem):
self._properties_dialog.move(pos)
self._properties_dialog.activateWindow()
class NodeItem(ui_base.ProjectMixin, NodeItemImpl):
pass
class ConnectionItemImpl(QtWidgets.QGraphicsPathItem):
class ConnectionItem(ui_base.ProjectMixin, QtWidgets.QGraphicsPathItem):
def __init__(self, connection=None, view=None, **kwargs):
super().__init__(**kwargs)
@ -886,9 +883,6 @@ class ConnectionItemImpl(QtWidgets.QGraphicsPathItem):
else:
self.setGraphicsEffect(None)
class ConnectionItem(ui_base.ProjectMixin, ConnectionItemImpl):
pass
class DragConnection(QtWidgets.QGraphicsPathItem):
def __init__(self, port):
@ -926,7 +920,7 @@ class DragConnection(QtWidgets.QGraphicsPathItem):
self.setPath(path)
class PipelineGraphSceneImpl(QtWidgets.QGraphicsScene):
class PipelineGraphScene(ui_base.ProjectMixin, QtWidgets.QGraphicsScene):
def __init__(self, view=None, **kwargs):
super().__init__(**kwargs)
self.view = view
@ -943,17 +937,14 @@ class PipelineGraphSceneImpl(QtWidgets.QGraphicsScene):
return
super().helpEvent(evt)
class PipelineGraphScene(ui_base.ProjectMixin, PipelineGraphSceneImpl):
pass
class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
class PipelineGraphGraphicsView(ui_base.ProjectMixin, QtWidgets.QGraphicsView):
nodeSelected = QtCore.pyqtSignal(object)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._scene = PipelineGraphScene(view=self, **self.context)
self._scene = PipelineGraphScene(view=self, **self.context_args)
self.setScene(self._scene)
self._drag_connection = None
@ -965,7 +956,7 @@ class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
self._nodes = []
self._node_map = {}
for node in self.project.pipeline_graph_nodes:
item = NodeItem(node=node, view=self, **self.context)
item = NodeItem(node=node, view=self, **self.context_args)
self._scene.addItem(item)
self._nodes.append(item)
self._node_map[node.id] = item
@ -976,7 +967,7 @@ class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
self._connections = []
for connection in self.project.pipeline_graph_connections:
item = ConnectionItem(
connection=connection, view=self, **self.context)
connection=connection, view=self, **self.context_args)
self._scene.addItem(item)
self._connections.append(item)
self._node_map[connection.source_node.id].connections.add(item)
@ -994,7 +985,7 @@ class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
def onPipelineGraphNodesChange(self, action, *args):
if action == 'insert':
idx, node = args
item = NodeItem(node=node, view=self, **self.context)
item = NodeItem(node=node, view=self, **self.context_args)
self._scene.addItem(item)
self._nodes.insert(idx, item)
self._node_map[node.id] = item
@ -1017,7 +1008,7 @@ class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
if action == 'insert':
idx, connection = args
item = ConnectionItem(
connection=connection, view=self, **self.context)
connection=connection, view=self, **self.context_args)
self._scene.addItem(item)
self._connections.insert(idx, item)
self._node_map[connection.source_node.id].connections.add(item)
@ -1183,10 +1174,6 @@ class PipelineGraphGraphicsViewImpl(QtWidgets.QGraphicsView):
evt.acceptProposedAction()
class PipelineGraphGraphicsView(
ui_base.ProjectMixin, PipelineGraphGraphicsViewImpl):
pass
class NodesList(ui_base.CommonMixin, QtWidgets.QListWidget):
def __init__(self, **kwargs):
@ -1221,7 +1208,7 @@ class NodeListDock(dock_widget.DockWidget):
initial_visible=True,
**kwargs)
self._node_list = NodesList(parent=self, **self.context)
self._node_list = NodesList(parent=self, **self.context_args)
self._node_filter = QtWidgets.QLineEdit(self)
self._node_filter.addAction(
@ -1254,13 +1241,13 @@ class NodeListDock(dock_widget.DockWidget):
item.setHidden(True)
class PipelineGraphViewImpl(QtWidgets.QWidget):
class PipelineGraphView(ui_base.ProjectMixin, QtWidgets.QWidget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._graph_view = PipelineGraphGraphicsView(**self.context)
self._graph_view = PipelineGraphGraphicsView(**self.context_args)
self._node_list_dock = NodeListDock(parent=self.window, **self.common_context)
self._node_list_dock = NodeListDock(parent=self.window, **self.context_args)
self._node_list_dock.hide()
layout = QtWidgets.QHBoxLayout()
@ -1273,6 +1260,3 @@ class PipelineGraphViewImpl(QtWidgets.QWidget):
def hideEvent(self, evt):
self._node_list_dock.hide()
class PipelineGraphView(ui_base.ProjectMixin, PipelineGraphViewImpl):
pass

@ -34,8 +34,8 @@ from . import ui_base
class PipelinePerfMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
visibilityChanged = QtCore.pyqtSignal(bool)
def __init__(self, app):
super().__init__(app=app)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.history = []
self.realtime = True

@ -77,4 +77,4 @@ class ProjectPropertiesDockWidget(ui_base.ProjectMixin, dock_widget.DockWidget):
initial_visible=True,
**kwargs)
self.setWidget(ProjectProperties(**self.context))
self.setWidget(ProjectProperties(**self.context_args))

@ -343,10 +343,10 @@ class Editor(TrackViewMixin, ui_base.ProjectMixin, AsyncSetupBase, QtWidgets.QWi
def createTrack(self, track):
track_item_cls = self.track_cls_map[type(track).__name__]
track_item = track_item_cls(
**self.context,
track=track,
player_state=self.__player_state,
editor=self)
editor=self,
**self.context_args)
track_item.rectChanged.connect(
lambda rect: self.update(rect.translated(-self.offset())))
track_item.sizeChanged.connect(
@ -399,7 +399,7 @@ class Editor(TrackViewMixin, ui_base.ProjectMixin, AsyncSetupBase, QtWidgets.QWi
self.__current_tool_box = None
if cls is not None:
self.__current_tool_box = cls(**self.context)
self.__current_tool_box = cls(**self.context_args)
self.__onCurrentToolChanged(self.__current_tool_box.currentTool())
self.__current_tool_box.currentToolChanged.connect(self.__onCurrentToolChanged)
@ -1076,7 +1076,7 @@ class TrackList(TrackViewMixin, ui_base.ProjectMixin, AsyncSetupBase, QtWidgets.
self.__content_height = 400
def createTrack(self, track):
track_item = TrackListItem(track=track, **self.context)
track_item = TrackListItem(track=track, **self.context_args)
track_item.rectChanged.connect(lambda _: self.update())
return track_item
@ -1150,7 +1150,7 @@ class Frame(QtWidgets.QFrame):
self.__layout.addWidget(widget, 1)
class ProjectViewImpl(QtWidgets.QMainWindow):
class ProjectView(ui_base.ProjectMixin, QtWidgets.QMainWindow):
currentToolBoxChanged = QtCore.pyqtSignal(tools.ToolBox)
playbackStateChanged = QtCore.pyqtSignal(str)
playbackLoopChanged = QtCore.pyqtSignal(bool)
@ -1167,7 +1167,7 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
self.player_audioproc_address = None
self.__time_mapper = time_mapper.TimeMapper(self.project)
self.__player_state = PlayerState(time_mapper=self.__time_mapper, **self.context)
self.__player_state = PlayerState(time_mapper=self.__time_mapper, **self.context_args)
self.__player_state.stateChanged.connect(self.playbackStateChanged)
self.__player_state.loopChanged.connect(self.playbackLoopChanged)
@ -1176,7 +1176,7 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
editor_frame = Frame(parent=editor_tab)
self.__editor = Editor(
player_state=self.__player_state,
parent=editor_frame, **self.context)
parent=editor_frame, **self.context_args)
editor_frame.setWidget(self.__editor)
self.__editor.currentToolBoxChanged.connect(self.currentToolBoxChanged)
@ -1184,11 +1184,11 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
time_line_frame = Frame(parent=editor_tab)
self.__time_line = TimeLine(
project_view=self, player_state=self.__player_state,
parent=time_line_frame, **self.context)
parent=time_line_frame, **self.context_args)
time_line_frame.setWidget(self.__time_line)
track_list_frame = Frame(parent=editor_tab)
track_list = TrackList(parent=track_list_frame, **self.context)
track_list = TrackList(parent=track_list_frame, **self.context_args)
track_list_frame.setWidget(track_list)
self.__time_line.setScaleX(self.__editor.scaleX())
@ -1232,7 +1232,7 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
mixer_tab = QtWidgets.QWidget()
graph_tab = pipeline_graph_view.PipelineGraphView(**self.context)
graph_tab = pipeline_graph_view.PipelineGraphView(**self.context_args)
project_tab = QtWidgets.QTabWidget(self)
project_tab.setTabPosition(QtWidgets.QTabWidget.West)
@ -1249,19 +1249,20 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
self._docks = []
self._tools_dock = tool_dock.ToolsDockWidget(parent=self, **self.context)
self._tools_dock = tool_dock.ToolsDockWidget(parent=self, **self.context_args)
self._docks.append(self._tools_dock)
self.currentToolBoxChanged.connect(self._tools_dock.setCurrentToolBox)
self._tools_dock.setCurrentToolBox(self.currentToolBox())
self._project_properties_dock = project_properties_dock.ProjectPropertiesDockWidget(
parent=self, **self.context)
parent=self, **self.context_args)
self._docks.append(self._project_properties_dock)
self._tracks_dock = tracks_dock.TracksDockWidget(parent=self, **self.context)
self._tracks_dock = tracks_dock.TracksDockWidget(parent=self, **self.context_args)
self._docks.append(self._tracks_dock)
self._track_properties_dock = track_properties_dock.TrackPropertiesDockWidget(parent=self, **self.context)
self._track_properties_dock = track_properties_dock.TrackPropertiesDockWidget(
parent=self, **self.context_args)
self._docks.append(self._track_properties_dock)
self._tracks_dock.currentTrackChanged.connect(self._track_properties_dock.setTrack)
@ -1488,8 +1489,3 @@ class ProjectViewImpl(QtWidgets.QMainWindow):
self.project.id, 'SetNumMeasures',
num_measures=dialog.intValue()))
dialog.show()
class ProjectView(ui_base.ProjectMixin, ProjectViewImpl):
pass

@ -35,12 +35,9 @@ from . import track_items
class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
pass
# class InitTest(uitest_utils.UITest):
# async def test_init(self):
# view = ProjectView(**self.context)
# view = ProjectView(**self.context_args)
# await view.setup()
# self.assertIsNone(view.currentSheetView())
#
@ -51,7 +48,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# self.project.sheets.append(model.Sheet('sheet2'))
# self.project.sheets[1].property_track = model.SheetPropertyTrack('prop2')
# self.project.sheets[1].master_group = model.TrackGroup('master')
# view = ProjectView(**self.context)
# view = ProjectView(**self.context_args)
# await view.setup()
# self.assertIsInstance(view.currentSheetView(), SheetView)
# self.assertEqual(view.currentSheetView().sheet.id, 'sheet1')
@ -66,7 +63,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# pass
# # async def test_add_sheet(self):
# # view = ProjectView(**self.context)
# # view = ProjectView(**self.context_args)
# # await view.setup()
# # self.assertEqual(len(list(view.sheetViews)), 0)
@ -80,7 +77,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# # sheet.property_track = model.SheetPropertyTrack('prop1')
# # self.project.sheets.append(sheet)
# # view = ProjectView(**self.context)
# # view = ProjectView(**self.context_args)
# # await view.setup()
# # self.assertEqual(len(list(view.sheetViews)), 1)
@ -92,7 +89,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# # sheet.property_track = model.SheetPropertyTrack('prop1')
# # self.project.sheets.append(sheet)
# # view = ProjectView(**self.context)
# # view = ProjectView(**self.context_args)
# # await view.setup()
# # self.assertEqual(len(list(view.sheetViews)), 1)
@ -108,7 +105,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# sheet.master_group = model.TrackGroup('master')
# self.project.sheets.append(sheet)
# view = ProjectView(**self.context)
# view = ProjectView(**self.context_args)
# await view.setup()
# view.onAddSheet()
# self.assertEqual(
@ -127,7 +124,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# sheet.master_group = model.TrackGroup('master')
# self.project.sheets.append(sheet)
# view = ProjectView(**self.context)
# view = ProjectView(**self.context_args)
# await view.setup()
# view.onDeleteSheet()
# self.assertEqual(
@ -164,36 +161,6 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# # self.assertEqual(view.currentTool(), Tool.NOTE_HALF)
# class ScoreMeasureItem(
# uitest_utils.TestMixin, score_track_item.ScoreMeasureItemImpl):
# pass
# class ScoreTrackItem(
# uitest_utils.TestMixin, score_track_item.ScoreTrackItemImpl):
# measure_item_cls = ScoreMeasureItem
# class SheetPropertyMeasureItem(
# uitest_utils.TestMixin,
# sheet_property_track_item.SheetPropertyMeasureItemImpl):
# pass
# class SheetPropertyTrackItem(
# uitest_utils.TestMixin,
# sheet_property_track_item.SheetPropertyTrackItemImpl):
# measure_item_cls = SheetPropertyMeasureItem
# class SheetView(uitest_utils.TestMixin, sheet_view.SheetViewImpl):
# track_cls_map = {
# 'SheetPropertyTrack': SheetPropertyTrackItem,
# 'ScoreTrack': ScoreTrackItem,
# }
# async def setup(self):
# pass
# async def cleanup(self):
# pass
# class SheetViewTest(uitest_utils.UITest):
# async def setUp(self):
@ -210,7 +177,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# async def test_init(self):
# track = model.ScoreTrack('track1')
# self.sheet.master_group.tracks.append(track)
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# self.assertEqual(
# [ti.track.id for ti in view.trackItems],
@ -219,7 +186,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# class SheetViewModelChangesTest(SheetViewTest):
# async def test_tracks(self):
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# track = model.ScoreTrack('track1')
@ -244,7 +211,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# async def test_track_visibility(self):
# track = model.ScoreTrack('track1')
# self.sheet.master_group.tracks.append(track)
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# view.updateSheet = mock.MagicMock()
# self.assertEqual(view.updateSheet.call_count, 0)
@ -254,7 +221,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# class SheetViewCommandsTest(SheetViewTest):
# async def test_onAddTrack(self):
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# view.onAddTrack('score')
# self.assertEqual(
@ -264,7 +231,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# class SheetViewEventsTest(SheetViewTest):
# async def test_keyEvent(self):
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# # Number keys select notes, if the current tool is a note.
@ -343,7 +310,7 @@ class ProjectView(uitest_utils.TestMixin, project_view.ProjectViewImpl):
# class SheetViewToolTest(SheetViewTest):
# # This one just aims for coverage. TODO: also verify effects.
# async def test_setCurrentTool(self):
# view = SheetView(**self.context, sheet=self.sheet)
# view = SheetView(**self.context_args, sheet=self.sheet)
# await view.setup()
# for tool in tool_dock.Tool:

@ -34,8 +34,8 @@ from ..constants import DATA_DIR
from . import ui_base
class SettingsDialog(ui_base.CommonMixin, QtWidgets.QDialog):
def __init__(self, app, parent):
super().__init__(app=app, parent=parent)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setWindowTitle("noisicaä - Settings")
self.resize(600, 300)
@ -43,7 +43,7 @@ class SettingsDialog(ui_base.CommonMixin, QtWidgets.QDialog):
self.tabs = QtWidgets.QTabWidget(self)
for cls in (AppearancePage, AudioPage):
page = cls(self.app)
page = cls(**self.context_args)
self.tabs.addTab(page, page.getIcon(), page.title)
close = QtWidgets.QPushButton("Close")
@ -78,8 +78,8 @@ class SettingsDialog(ui_base.CommonMixin, QtWidgets.QDialog):
class Page(ui_base.CommonMixin, QtWidgets.QWidget):
def __init__(self, app):
super().__init__(app=app)
def __init__(self, **kwargs):
super().__init__(**kwargs)
layout = QtWidgets.QVBoxLayout()
@ -90,11 +90,11 @@ class Page(ui_base.CommonMixin, QtWidgets.QWidget):
class AppearancePage(Page):
def __init__(self, app):
def __init__(self, **kwargs):
self.title = "Appearance"
self._qt_styles = sorted(QtWidgets.QStyleFactory.keys())
super().__init__(app)
super().__init__(**kwargs)
def getIcon(self):
path = os.path.join(DATA_DIR, 'icons', 'settings_appearance.png')
@ -145,10 +145,10 @@ class QBlockSizeSpinBox(QtWidgets.QSpinBox):
class AudioPage(Page):
def __init__(self, app):
def __init__(self, **kwargs):
self.title = "Audio"
self._backends = ['portaudio', 'null']
super().__init__(app)
super().__init__(**kwargs)
def getIcon(self):
path = os.path.join(DATA_DIR, 'icons', 'settings_audio.png')

@ -150,8 +150,8 @@ class QTextEdit(QtWidgets.QTextEdit):
class StatMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
visibilityChanged = QtCore.pyqtSignal(bool)
def __init__(self, app):
super().__init__(app=app)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__update_timer = QtCore.QTimer(self)
self.__update_timer.setInterval(1000)

@ -742,7 +742,7 @@ class MeasuredTrackEditorItem(BaseTrackEditorItem):
for idx, mref in enumerate(self.track.measure_list):
self.addMeasure(idx, mref)
appendix_item = Appendix(track_item=self, **self.context)
appendix_item = Appendix(track_item=self, **self.context_args)
appendix_item.rectChanged.connect(self.rectChanged)
self.__measure_items.append(appendix_item)
@ -780,7 +780,7 @@ class MeasuredTrackEditorItem(BaseTrackEditorItem):
def addMeasure(self, idx, mref):
measure_item = self.measure_item_cls( # pylint: disable=not-callable
track_item=self, measure_reference=mref, **self.context)
track_item=self, measure_reference=mref, **self.context_args)
measure_item.rectChanged.connect(self.rectChanged)
self.__measure_items.insert(idx, measure_item)
self.updateMeasures()

@ -50,7 +50,7 @@ class EditBeatsTool(base_track_item.MeasuredToolBase):
super().mouseMoveEvent(target, evt)
def mousePressEvent(self, target, evt):
assert isinstance(target, BeatMeasureEditorItemImpl), type(target).__name__
assert isinstance(target, BeatMeasureEditorItem), type(target).__name__
if (evt.button() == Qt.LeftButton and evt.modifiers() == Qt.NoModifier):
click_timepos = target.xToTimepos(evt.pos().x())
@ -71,7 +71,7 @@ class EditBeatsTool(base_track_item.MeasuredToolBase):
return super().mousePressEvent(target, evt)
def wheelEvent(self, target, evt):
assert isinstance(target, BeatMeasureEditorItemImpl), type(target).__name__
assert isinstance(target, BeatMeasureEditorItem), type(target).__name__
if evt.modifiers() in (Qt.NoModifier, Qt.ShiftModifier):
if evt.modifiers() == Qt.ShiftModifier:
@ -96,11 +96,11 @@ class BeatToolBox(tools.ToolBox):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.addTool(base_track_item.ArrangeMeasuresTool(**self.context))
self.addTool(EditBeatsTool(**self.context))
self.addTool(base_track_item.ArrangeMeasuresTool(**self.context_args))
self.addTool(EditBeatsTool(**self.context_args))
class BeatMeasureEditorItemImpl(base_track_item.MeasureEditorItem):
class BeatMeasureEditorItem(ui_base.ProjectMixin, base_track_item.MeasureEditorItem):
FOREGROUND = 'fg'
BACKGROUND = 'bg'
GHOST = 'ghost'
@ -219,11 +219,7 @@ class BeatMeasureEditorItemImpl(base_track_item.MeasureEditorItem):
super().leaveEvent(evt)
class BeatMeasureEditorItem(ui_base.ProjectMixin, BeatMeasureEditorItemImpl):
pass
class BeatTrackEditorItemImpl(base_track_item.MeasuredTrackEditorItem):
class BeatTrackEditorItem(ui_base.ProjectMixin, base_track_item.MeasuredTrackEditorItem):
measure_item_cls = BeatMeasureEditorItem
toolBoxClass = BeatToolBox
@ -253,7 +249,3 @@ class BeatTrackEditorItemImpl(base_track_item.MeasuredTrackEditorItem):
# 'track:%s' % self.track.id,
# audioproc.NoteOffEvent(-1, self.__play_last_pitch)))
self.__play_last_pitch = None
class BeatTrackEditorItem(ui_base.ProjectMixin, BeatTrackEditorItemImpl):
pass

@ -51,7 +51,7 @@ class EditControlPointsTool(tools.ToolBase):
return 'edit-control-points'
def mousePressEvent(self, target, evt):
assert isinstance(target, ControlTrackEditorItemImpl), type(target).__name__
assert isinstance(target, ControlTrackEditorItem), type(target).__name__
target.updateHighlightedPoint()
@ -100,7 +100,7 @@ class EditControlPointsTool(tools.ToolBase):
super().mousePressEvent(target, evt)
def mouseMoveEvent(self, target, evt):
assert isinstance(target, ControlTrackEditorItemImpl), type(target).__name__
assert isinstance(target, ControlTrackEditorItem), type(target).__name__
if self.__moving_point is not None:
new_pos = evt.pos() - self.__moving_point_offset
@ -141,7 +141,7 @@ class EditControlPointsTool(tools.ToolBase):
super().mouseMoveEvent(target, evt)
def mouseReleaseEvent(self, target, evt):
assert isinstance(target, ControlTrackEditorItemImpl), type(target).__name__
assert isinstance(target, ControlTrackEditorItem), type(target).__name__
if evt.button() == Qt.LeftButton and self.__moving_point is not None:
pos = self.__moving_point.pos()
@ -170,7 +170,7 @@ class EditControlPointsTool(tools.ToolBase):
super().mouseReleaseEvent(target, evt)
def mouseDoubleClickEvent(self, target, evt):
assert isinstance(target, ControlTrackEditorItemImpl), type(target).__name__
assert isinstance(target, ControlTrackEditorItem), type(target).__name__
if (evt.button() == Qt.LeftButton
and evt.modifiers() == Qt.NoModifier):
@ -206,7 +206,7 @@ class ControlTrackToolBox(tools.ToolBox):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.addTool(EditControlPointsTool(**self.context))
self.addTool(EditControlPointsTool(**self.context_args))
class ControlPoint(object):
@ -264,7 +264,7 @@ class ControlPoint(object):
self.__pos = pos
class ControlTrackEditorItemImpl(base_track_item.BaseTrackEditorItem):
class ControlTrackEditorItem(ui_base.ProjectMixin, base_track_item.BaseTrackEditorItem):
toolBoxClass = ControlTrackToolBox
def __init__(self, **kwargs):
@ -462,7 +462,3 @@ class ControlTrackEditorItemImpl(base_track_item.BaseTrackEditorItem):
painter.drawLine(x + 3, y - 3, x + 3, y + 3)
painter.drawLine(x + 3, y + 3, x - 3, y + 3)
painter.drawLine(x - 3, y + 3, x - 3, y - 3)
class ControlTrackEditorItem(ui_base.ProjectMixin, ControlTrackEditorItemImpl):
pass

@ -51,7 +51,7 @@ class EditSamplesTool(tools.ToolBase):
return 'edit-samples'
def mousePressEvent(self, target, evt):
assert isinstance(target, SampleTrackEditorItemImpl), type(target).__name__
assert isinstance(target, SampleTrackEditorItem), type(target).__name__
if (evt.button() == Qt.LeftButton
and evt.modifiers() == Qt.NoModifier
@ -123,7 +123,7 @@ class SampleTrackToolBox(tools.ToolBox):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.addTool(EditSamplesTool(**self.context))
self.addTool(EditSamplesTool(**self.context_args))
class SampleItem(object):
@ -274,7 +274,7 @@ class SampleItem(object):
painter.drawLine(x, ycenter - h // 2, x, ycenter + h // 2)
class SampleTrackEditorItemImpl(base_track_item.BaseTrackEditorItem):
class SampleTrackEditorItem(ui_base.ProjectMixin, base_track_item.BaseTrackEditorItem):
toolBoxClass = SampleTrackToolBox
def __init__(self, **kwargs):
@ -521,7 +521,3 @@ class SampleTrackEditorItemImpl(base_track_item.BaseTrackEditorItem):
if self.__playback_timepos is not None:
pos = self.timeposToX(self.__playback_timepos)
painter.fillRect(pos, 0, 2, self.height(), QtGui.QColor(0, 0, 160))
class SampleTrackEditorItem(ui_base.ProjectMixin, SampleTrackEditorItemImpl):
pass

@ -64,7 +64,7 @@ class ScoreToolBase(base_track_item.MeasuredToolBase):
target.setGhost(None)
def mouseMoveEvent(self, target, evt):
assert isinstance(target, ScoreMeasureEditorItemImpl), type(target).__name__
assert isinstance(target, ScoreMeasureEditorItem), type(target).__name__
self._updateGhost(target, evt.pos())
@ -303,27 +303,27 @@ class ScoreToolBox(tools.ToolBox):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.addTool(base_track_item.ArrangeMeasuresTool(**self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_WHOLE, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_HALF, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_QUARTER, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_8TH, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_16TH, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_32TH, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_WHOLE, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_HALF, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_QUARTER, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_8TH, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_16TH, **self.context))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_32TH, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_NATURAL, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_SHARP, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_FLAT, **self.context))
#self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_DOUBLE_SHARP, **self.context))
#self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_DOUBLE_FLAT, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_DOT, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_TRIPLET, **self.context))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_QUINTUPLET, **self.context))
self.addTool(base_track_item.ArrangeMeasuresTool(**self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_WHOLE, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_HALF, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_QUARTER, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_8TH, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_16TH, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.NOTE_32TH, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_WHOLE, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_HALF, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_QUARTER, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_8TH, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_16TH, **self.context_args))
self.addTool(InsertNoteTool(type=tools.ToolType.REST_32TH, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_NATURAL, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_SHARP, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_FLAT, **self.context_args))
#self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_DOUBLE_SHARP, **self.context_args))
#self.addTool(ModifyNoteTool(type=tools.ToolType.ACCIDENTAL_DOUBLE_FLAT, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_DOT, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_TRIPLET, **self.context_args))
self.addTool(ModifyNoteTool(type=tools.ToolType.DURATION_QUINTUPLET, **self.context_args))
def keyPressEvent(self, target, evt):
if (not evt.isAutoRepeat()
@ -496,7 +496,7 @@ class ScoreToolBox(tools.ToolBox):
# super().keyPressEvent(evt)
class ScoreMeasureEditorItemImpl(base_track_item.MeasureEditorItem):
class ScoreMeasureEditorItem(ui_base.ProjectMixin, base_track_item.MeasureEditorItem):
FOREGROUND = 'fg'
BACKGROUND = 'bg'
GHOST = 'ghost'
@ -959,11 +959,7 @@ class ScoreMeasureEditorItemImpl(base_track_item.MeasureEditorItem):
super().mouseMoveEvent(evt)
class ScoreMeasureEditorItem(ui_base.ProjectMixin, ScoreMeasureEditorItemImpl):
pass
class ScoreTrackEditorItemImpl(base_track_item.MeasuredTrackEditorItem):
class ScoreTrackEditorItem(ui_base.ProjectMixin, base_track_item.MeasuredTrackEditorItem):
measure_item_cls = ScoreMeasureEditorItem
toolBoxClass = ScoreToolBox
@ -982,7 +978,7 @@ class ScoreTrackEditorItemImpl(base_track_item.MeasuredTrackEditorItem):
affected_measure_items.extend(self.selection_set)
else:
mitem = self.measureItemAt(pos)
if isinstance(mitem, ScoreMeasureEditorItemImpl):
if isinstance(mitem, ScoreMeasureEditorItem):
affected_measure_items.append(mitem)
enable_measure_actions = bool(affected_measure_items)
@ -1130,7 +1126,3 @@ class ScoreTrackEditorItemImpl(base_track_item.MeasuredTrackEditorItem):
0, self.__play_last_pitch.midi_note))))
self.__play_last_pitch = None
class ScoreTrackEditorItem(ui_base.ProjectMixin, ScoreTrackEditorItemImpl):
pass

@ -205,7 +205,7 @@ class ScoreTrackProperties(TrackProperties):
async def onSelectInstrumentAsync(self):
dialog = instrument_library.InstrumentLibraryDialog(
**self.common_context, selectButton=True, parent=self)
**self.context_args, selectButton=True, parent=self)
dialog.setWindowTitle(
"Select instrument for track '%s'" % self._track.name)
dialog.setModal(True)
@ -286,7 +286,7 @@ class BeatTrackProperties(TrackProperties):
async def onSelectInstrumentAsync(self):
dialog = instrument_library.InstrumentLibraryDialog(
**self.common_context, selectButton=True, parent=self)
**self.context_args, selectButton=True, parent=self)
dialog.setWindowTitle(
"Select instrument for track '%s'" % self._track.name)
dialog.setModal(True)
@ -348,23 +348,23 @@ class TrackPropertiesDockWidget(ui_base.ProjectMixin, DockWidget):
elif isinstance(self._track, model.TrackGroup):
self.setWidget(TrackGroupProperties(
track=self._track, **self.context))
track=self._track, **self.context_args))
elif isinstance(self._track, model.ScoreTrack):
self.setWidget(ScoreTrackProperties(
track=self._track, **self.context))
track=self._track, **self.context_args))
elif isinstance(self._track, model.BeatTrack):
self.setWidget(BeatTrackProperties(
track=self._track, **self.context))
track=self._track, **self.context_args))
elif isinstance(self._track, model.ControlTrack):
self.setWidget(ControlTrackProperties(
track=self._track, **self.context))
track=self._track, **self.context_args))
elif isinstance(self._track, model.SampleTrack):
self.setWidget(SampleTrackProperties(
track=self._track, **self.context))
track=self._track, **self.context_args))
else:
raise ValueError(type(self._track))

@ -50,7 +50,7 @@ class TracksModelItem(object):
yield from child.walk()
class TracksModelImpl(QtCore.QAbstractItemModel):
class TracksModel(ui_base.ProjectMixin, QtCore.QAbstractItemModel):
VisibleRole = Qt.UserRole
MuteRole = Qt.UserRole + 1
@ -279,10 +279,6 @@ class TracksModelImpl(QtCore.QAbstractItemModel):
self.project.id, 'RemoveTrack', track_id=track.id)
class TracksModel(ui_base.ProjectMixin, TracksModelImpl):
pass
class TrackItemDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, parent = None):
super().__init__(parent)
@ -476,7 +472,7 @@ class TracksDockWidget(ui_base.ProjectMixin, DockWidget):
self._tracks_list = TrackList(self)
self._tracks_list.currentIndexChanged.connect(self.onCurrentChanged)
self._model = TracksModel(**self.context)
self._model = TracksModel(**self.context_args)
self._tracks_list.setModel(self._model)
buttons_layout = QtWidgets.QHBoxLayout(spacing=1)

@ -31,10 +31,6 @@ from . import model
from . import tracks_dock
class TestTracksModel(uitest_utils.TestMixin, tracks_dock.TracksModelImpl):
pass
class TracksModelTest(uitest_utils.UITest):
async def setUp(self):
await super().setUp()
@ -43,7 +39,7 @@ class TracksModelTest(uitest_utils.UITest):
self.project.master_group.name = 'master'
async def test_start_empty(self):
tracks_model = TestTracksModel(**self.context)
tracks_model = tracks_dock.TracksModel(**self.context_args)
try:
root_index = QtCore.QModelIndex()
self.assertEqual(tracks_model.rowCount(root_index), 1)
@ -124,7 +120,7 @@ class TracksModelTest(uitest_utils.UITest):
track3.name = 'track3'
grp1.tracks.append(track3)
tracks_model = TestTracksModel(**self.context)
tracks_model = tracks_dock.TracksModel(**self.context_args)
try:
root_index = QtCore.QModelIndex()
self.assertEqual(tracks_model.rowCount(root_index), 1)
@ -182,7 +178,7 @@ class TracksModelTest(uitest_utils.UITest):
track3.name = 'track3'
grp1.tracks.append(track3)
tracks_model = TestTracksModel(**self.context)
tracks_model = tracks_dock.TracksModel(**self.context_args)
try:
master_index = tracks_model.index(0)