Music production session manager https://www.laborejo.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.7 KiB

5 years ago
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2020, Nils Hilbricht, Germany ( https://www.hilbricht.net )
This file is part of the Laborejo Software Suite ( https://www.laborejo.org ).
This application is free software: you can redistribute it and/or modify
5 years ago
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging; logger = logging.getLogger(__name__); logger.info("import")
#Standard Library
import datetime
#Third Party
from PyQt5 import QtCore, QtGui, QtWidgets
#Engine
from engine.config import METADATA #includes METADATA only. No other environmental setup is executed.
import engine.api as api
class SessionButton(QtWidgets.QPushButton):
def __init__(self, sessionDict):
self.sessionDict = sessionDict
super().__init__(sessionDict["nsmSessionName"])
self.clicked.connect(self.openSession)
#self.setFlat(True)
font = self.font()
font.setPixelSize(font.pixelSize() * 1.2 )
self.setFont(font)
5 years ago
#width = self.fontMetrics().boundingRect(sessionDict["nsmSessionName"]).width()+10
#width = self.fontMetrics().boundingRect(longestSessionName).width()+10
#width = parent.geometry().width()
5 years ago
#self.setFixedSize(width, 40)
self.setFixedHeight(40)
5 years ago
def openSession(self):
name = self.sessionDict["nsmSessionName"]
api.sessionOpen(name)
5 years ago
class QuickSessionController(object):
"""Controls the widget, but does not subclass"""
def __init__(self, mainWindow):
self.mainWindow = mainWindow
self.layout = mainWindow.ui.quickSessionChooser.layout()
#self.layout.setAlignment(QtCore.Qt.AlignHCenter)
5 years ago
newSessionButton = mainWindow.ui.quickNewSession
font = newSessionButton.font()
font.setPixelSize(font.pixelSize() * 1.4)
5 years ago
newSessionButton.setFont(font)
5 years ago
newSessionButton.setFixedHeight(40)
newSessionButton.setFocus(True) #Enter on program start creates a new session.
newSessionButton.clicked.connect(self._newTimestampSession)
5 years ago
api.callbacks.sessionsChanged.append(self._reactCallback_sessionsChanged)
#self.layout.geometry().width() #very small
#self.mainWindow.ui.quickSessionChooser.geometry().width() #too small
#self.mainWindow.ui.scrollArea.geometry().width()
#mainWindow.geometry().width()
5 years ago
logger.info("Quick Session Chooser ready")
def _clear(self):
"""Clear everything but the spacer item"""
for child in self.mainWindow.ui.quickSessionChooser.children():
if type(child) is SessionButton:
5 years ago
self.layout.removeWidget(child)
child.setParent(None)
del child
5 years ago
def _reactCallback_sessionsChanged(self, sessionDicts:list):
"""Main callback for new, added, removed, moved sessions etc."""
logger.info("Rebuilding session buttons")
5 years ago
self._clear() #except the space
spacer = self.layout.takeAt(0)
#longestSessionName = ""
#for sessionDict in sessionDicts:
# if len(sessionDict["nsmSessionName"]) > len(longestSessionName):
# longestSessionName = sessionDict["nsmSessionName"]
5 years ago
for sessionDict in sorted(sessionDicts, key=lambda d: d["nsmSessionName"]):
self.layout.addWidget(SessionButton(sessionDict))
5 years ago
#Finally add vertical spacer
#spacerItem = QtWidgets.QSpacerItem(1, 1, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) #int w, int h, QSizePolicy::Policy hPolicy = QSizePolicy::Minimum, QSizePolicy::Policy vPolicy = QSizePolicy::Minimum
self.layout.addItem(spacer)
5 years ago
def _newTimestampSession(self):
5 years ago
nsmExecutables = api.getNsmExecutables() #type set, cached, very fast.
con = METADATA["preferredClients"]["data"]
5 years ago
data = METADATA["preferredClients"]["connections"]
startclients = []
5 years ago
if con in nsmExecutables:
startclients.append(con)
5 years ago
if data in nsmExecutables:
startclients.append(data)
5 years ago
#now = datetime.datetime.now().replace(second=0, microsecond=0).isoformat()[:-3]
now = datetime.datetime.now().replace(microsecond=0).isoformat()
name = now
api.sessionNew(name, startclients)