@ -25,38 +25,41 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
from typing import Iterable , Callable , Tuple
from PyQt5 import QtCore , QtGui , QtWidgets
import engine . api as api
from qtgui . constantsAndConfigs import constantsAndConfigs #Client constantsAndConfigs!
from qtgui . constantsAndConfigs import constantsAndConfigs #Client constantsAndConfigs!
"""
There are two types of submenus in this file . The majority is created in menu . py during start up .
Like Clef , KeySig etc . These don ' t need to ask for any dynamic values.
The other is like SecondaryTempoChangeMenu . In menu . py this is bound with a lambda construct so a
The other is like SecondaryTempoChangeMenu . In menu . py this is bound with a lambda construct so a
new instance gets created each time the action is called by the user . Thats why this function has
self . __call__ in its init .
"""
class Submenu ( QtWidgets . QDialog ) :
class Submenu ( QtWidgets . QDialog ) :
def __init__ ( self , mainWindow , labelString , hasOkCancelButtons = False ) :
super ( ) . __init__ ( mainWindow ) #if you don't set the parent to the main window the whole screen will be the root and the dialog pops up in the middle of it.
super ( ) . __init__ ( mainWindow ) #if you don't set the parent to the main window the whole screen will be the root and the dialog pops up in the middle of it.
#self.setModal(True) #we don't need this when called with self.exec() instead of self.show()
self . layout = QtWidgets . QFormLayout ( )
#self.layout = QtWidgets.QVBoxLayout()
#self.layout = QtWidgets.QVBoxLayout()
self . setLayout ( self . layout )
label = QtWidgets . QLabel ( labelString ) #"Choose a clef" or so.
self . layout . addWidget ( label )
#self.setFocus(); #self.grabKeyboard(); #redundant for a proper modal dialog. Leave here for documentation reasons.
if hasOkCancelButtons :
if hasOkCancelButtons == 1 : #or true
self . buttonBox = QtWidgets . QDialogButtonBox ( QtWidgets . QDialogButtonBox . Ok | QtWidgets . QDialogButtonBox . Cancel )
self . buttonBox . accepted . connect ( self . process )
self . buttonBox . rejected . connect ( self . reject )
self . buttonBox . rejected . connect ( self . reject )
elif hasOkCancelButtons == 2 : #only cancel. #TODO: unpythonic.
self . buttonBox = QtWidgets . QDialogButtonBox ( QtWidgets . QDialogButtonBox . Cancel )
self . buttonBox . rejected . connect ( self . reject )
else :
self . buttonBox = None
def keyPressEvent ( self , event ) :
""" Escape closes the dialog by default.
@ -81,7 +84,7 @@ class Submenu(QtWidgets.QDialog):
def showEvent ( self , event ) :
#TODO: not optimal but better than nothing.
super ( ) . showEvent ( event )
#self.resize(self.layout.geometry().width(), self.layout.geometry().height())
#self.resize(self.layout.geometry().width(), self.layout.geometry().height())
self . resize ( self . childrenRect ( ) . height ( ) , self . childrenRect ( ) . width ( ) )
self . updateGeometry ( )
@ -91,13 +94,13 @@ class Submenu(QtWidgets.QDialog):
def process ( self ) :
""" Careful! Calling this eats python errors without notice. Make sure your objects exists
and your syntax is correct """
raise NotImplementedError ( )
raise NotImplementedError ( )
self . done ( True )
def __call__ ( self ) :
""" This instance can be called like a function """
if self . buttonBox :
self . layout . addWidget ( self . buttonBox )
self . layout . addWidget ( self . buttonBox )
self . setFixedSize ( self . layout . geometry ( ) . size ( ) )
self . exec ( ) #blocks until the dialog gets closed