Browse Source

Add ProjectRegistry to hold opened projects.

looper
Ben Niemann 6 years ago
parent
commit
ed8f0aac93
  1. 36
      noisicaa/ui/editor_app.py
  2. 14
      noisicaa/ui/editor_project.py
  3. 18
      noisicaa/ui/editor_project_test.py
  4. 8
      noisicaa/ui/editor_window.py
  5. 51
      noisicaa/ui/project_registry.py
  6. 4
      noisicaa/ui/ui_process.py

36
noisicaa/ui/editor_app.py

@ -20,9 +20,11 @@ from noisicaa import devices
from ..exceptions import RestartAppException, RestartAppCleanException
from ..constants import EXIT_EXCEPTION, EXIT_RESTART, EXIT_RESTART_CLEAN
from .editor_window import EditorWindow
from .editor_project import EditorProject
from ..instr.library import InstrumentLibrary
from . import project_registry
logger = logging.getLogger('ui.editor_app')
@ -72,14 +74,13 @@ class BaseEditorApp(QApplication):
self.setQuitOnLastWindowClosed(False)
self._projects = []
self.default_style = None
self.project_registry = None
self.sequencer = None
self.midi_hub = None
def setup(self):
async def setup(self):
self.default_style = self.style().objectName()
style_name = self.settings.value('appearance/qtStyle', '')
@ -87,6 +88,9 @@ class BaseEditorApp(QApplication):
style = QStyleFactory.create(style_name)
self.setStyle(style)
self.project_registry = project_registry.ProjectRegistry(
self.process.event_loop, self.process.manager)
self.sequencer = self.createSequencer()
self.midi_hub = self.createMidiHub()
@ -105,7 +109,7 @@ class BaseEditorApp(QApplication):
self.show_edit_areas_action.setChecked(
int(self.settings.value('dev/show_edit_areas', '0')))
def cleanup(self):
async def cleanup(self):
logger.info("Cleaning up.")
if self.midi_hub is not None:
self.midi_hub.stop()
@ -142,7 +146,7 @@ class BaseEditorApp(QApplication):
and self.show_edit_areas_action.isChecked())
def addProject(self, project):
self._projects.append(project)
#self._projects.append(project)
self.win.addProjectView(project)
self.settings.setValue(
@ -151,7 +155,7 @@ class BaseEditorApp(QApplication):
def removeProject(self, project):
self.win.removeProjectView(project)
self._projects.remove(project)
#self._projects.remove(project)
self.settings.setValue(
'opened_projects',
@ -185,12 +189,12 @@ class EditorApp(BaseEditorApp):
self._old_excepthook = None
self.win = None
def setup(self):
async def setup(self):
logger.info("Installing custom excepthook.")
self._old_excepthook = sys.excepthook
sys.excepthook = ExceptHook(self)
super().setup()
await super().setup()
logger.info("Creating InstrumentLibrary.")
self.instrument_library = None #InstrumentLibrary()
@ -204,16 +208,14 @@ class EditorApp(BaseEditorApp):
for path in self.paths:
if path.startswith('+'):
path = path[1:]
project = EditorProject(self)
project.create(path)
self.addProject(project)
await self.project_registry.create_project(path)
else:
self.win.openProject(path)
await self.project_registry.open_project(path)
else:
reopen_projects = self.settings.value('opened_projects', [])
for path in reopen_projects:
self.win.openProject(path)
for path in reopen_projects or []:
await self.project_registry.open_project(path)
self.aboutToQuit.connect(self.shutDown)
@ -225,12 +227,12 @@ class EditorApp(BaseEditorApp):
self.settings.sync()
self.dumpSettings()
def cleanup(self):
async def cleanup(self):
if self.win is not None:
self.win.closeAll()
self.win = None
super().cleanup()
await super().cleanup()
logger.info("Remove custom excepthook.")
sys.excepthook = self._old_excepthook

14
noisicaa/ui/editor_project.py

@ -1,14 +0,0 @@
#!/usr/bin/python3
import logging
from noisicaa import music
logger = logging.getLogger(__name__)
class EditorProject(music.Project):
def __init__(self, app):
super().__init__()
self._app = app

18
noisicaa/ui/editor_project_test.py

@ -1,18 +0,0 @@
#!/usr/bin/python3
import unittest
from . import editor_project
class FakeApp(object):
pass
class EditorProjectTest(unittest.TestCase):
def testCreate(self):
p = editor_project.EditorProject(FakeApp())
p.close()
if __name__ == '__main__':
unittest.main()

8
noisicaa/ui/editor_window.py

@ -42,7 +42,6 @@ from ..ui_state import UpdateUIState
from .command_shell import CommandShell
from .settings import SettingsDialog
from .project_view import ProjectView
from .editor_project import EditorProject
from .instrument_library import InstrumentLibraryDialog
from .flowlayout import FlowLayout
from ..constants import DATA_DIR
@ -474,12 +473,7 @@ class EditorWindow(QMainWindow):
async def openProjectAsync(self, path):
try:
project_process_address = await self._app.process.manager.call(
'CREATE_PROJECT_PROCESS', path)
project_client = music.ProjectClient(self._app.process.event_loop)
await project_client.setup()
await project_client.connect(project_process_address)
await project_client.open(path)
await self._app.project_registry.open_project(path)
except:
import sys
sys.excepthook(*sys.exc_info())

51
noisicaa/ui/project_registry.py

@ -0,0 +1,51 @@
#!/usr/bin/python3
import logging
from noisicaa import music
logger = logging.getLogger(__name__)
class Project(object):
def __init__(self, path, event_loop, process_manager):
self.path = path
self.event_loop = event_loop
self.process_manager = process_manager
self.process_address = None
self.client = None
async def create_process(self):
self.process_address = await self.process_manager.call(
'CREATE_PROJECT_PROCESS', self.path)
self.client = music.ProjectClient(self.event_loop)
await self.client.setup()
await self.client.connect(self.process_address)
async def open(self):
await self.create_process()
await self.client.open(self.path)
async def create(self):
await self.create_process()
await self.client.create(self.path)
class ProjectRegistry(object):
def __init__(self, event_loop, process_manager):
self.event_loop = event_loop
self.process_manager = process_manager
self.projects = {}
async def open_project(self, path):
project = Project(path, self.event_loop, self.process_manager)
await project.open()
self.projects[path] = project
return project
async def create_project(self, path):
project = Project(path, self.event_loop, self.process_manager)
await project.create()
self.projects[path] = project
return project

4
noisicaa/ui/ui_process.py

@ -38,10 +38,10 @@ class UIProcessMixin(object):
self._shutting_down = asyncio.Event()
await super().setup()
self.app.setup()
await self.app.setup()
async def cleanup(self):
self.app.cleanup()
await self.app.cleanup()
await super().cleanup()
async def run(self):

Loading…
Cancel
Save