Browse Source

add multiplication buttons to tick widget

master
Nils 2 years ago
parent
commit
537dc8fa1c
  1. 36
      qtgui/designer/tickWidget.py
  2. 64
      qtgui/designer/tickWidget.ui
  3. 50
      qtgui/submenus.py
  4. 2
      qtgui/trackEditor.py

36
qtgui/designer/tickWidget.py

@ -2,16 +2,19 @@
# Form implementation generated from reading ui file 'tickWidget.ui'
#
# Created by: PyQt5 UI code generator 5.7
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_tickWidget(object):
def setupUi(self, tickWidget):
tickWidget.setObjectName("tickWidget")
tickWidget.resize(453, 229)
tickWidget.resize(453, 328)
self.D1 = QtWidgets.QPushButton(tickWidget)
self.D1.setGeometry(QtCore.QRect(10, 40, 80, 22))
self.D1.setObjectName("D1")
@ -43,7 +46,7 @@ class Ui_tickWidget(object):
self.D128.setGeometry(QtCore.QRect(370, 80, 80, 22))
self.D128.setObjectName("D128")
self.ticks = QtWidgets.QSpinBox(tickWidget)
self.ticks.setGeometry(QtCore.QRect(160, 190, 161, 23))
self.ticks.setGeometry(QtCore.QRect(160, 280, 161, 23))
self.ticks.setReadOnly(True)
self.ticks.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
self.ticks.setPrefix("")
@ -51,21 +54,33 @@ class Ui_tickWidget(object):
self.ticks.setMaximum(999999999)
self.ticks.setObjectName("ticks")
self.ok = QtWidgets.QPushButton(tickWidget)
self.ok.setGeometry(QtCore.QRect(60, 190, 80, 22))
self.ok.setGeometry(QtCore.QRect(60, 280, 80, 22))
self.ok.setObjectName("ok")
self.cancel = QtWidgets.QPushButton(tickWidget)
self.cancel.setGeometry(QtCore.QRect(340, 190, 80, 22))
self.cancel.setGeometry(QtCore.QRect(340, 280, 80, 22))
self.cancel.setObjectName("cancel")
self.durationLabel = QtWidgets.QLabel(tickWidget)
self.durationLabel.setGeometry(QtCore.QRect(30, 150, 401, 31))
self.durationLabel.setGeometry(QtCore.QRect(30, 240, 401, 31))
self.durationLabel.setAlignment(QtCore.Qt.AlignCenter)
self.durationLabel.setObjectName("durationLabel")
self.reset = QtWidgets.QPushButton(tickWidget)
self.reset.setGeometry(QtCore.QRect(190, 120, 80, 22))
self.reset.setGeometry(QtCore.QRect(190, 210, 80, 22))
self.reset.setObjectName("reset")
self.label = QtWidgets.QLabel(tickWidget)
self.label.setGeometry(QtCore.QRect(120, 10, 241, 20))
self.label.setObjectName("label")
self.x2 = QtWidgets.QPushButton(tickWidget)
self.x2.setGeometry(QtCore.QRect(50, 140, 80, 23))
self.x2.setObjectName("x2")
self.x3 = QtWidgets.QPushButton(tickWidget)
self.x3.setGeometry(QtCore.QRect(140, 140, 80, 23))
self.x3.setObjectName("x3")
self.x5 = QtWidgets.QPushButton(tickWidget)
self.x5.setGeometry(QtCore.QRect(230, 140, 80, 23))
self.x5.setObjectName("x5")
self.x7 = QtWidgets.QPushButton(tickWidget)
self.x7.setGeometry(QtCore.QRect(320, 140, 80, 23))
self.x7.setObjectName("x7")
self.retranslateUi(tickWidget)
QtCore.QMetaObject.connectSlotsByName(tickWidget)
@ -96,4 +111,7 @@ class Ui_tickWidget(object):
self.durationLabel.setText(_translate("tickWidget", "Simplest Duration"))
self.reset.setText(_translate("tickWidget", "Reset"))
self.label.setText(_translate("tickWidget", "Use buttons to add to total tick duration"))
self.x2.setText(_translate("tickWidget", "x2"))
self.x3.setText(_translate("tickWidget", "x3"))
self.x5.setText(_translate("tickWidget", "x5"))
self.x7.setText(_translate("tickWidget", "x7"))

64
qtgui/designer/tickWidget.ui

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>453</width>
<height>229</height>
<height>328</height>
</rect>
</property>
<property name="windowTitle">
@ -162,7 +162,7 @@
<property name="geometry">
<rect>
<x>160</x>
<y>190</y>
<y>280</y>
<width>161</width>
<height>23</height>
</rect>
@ -190,7 +190,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>190</y>
<y>280</y>
<width>80</width>
<height>22</height>
</rect>
@ -206,7 +206,7 @@
<property name="geometry">
<rect>
<x>340</x>
<y>190</y>
<y>280</y>
<width>80</width>
<height>22</height>
</rect>
@ -222,7 +222,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>150</y>
<y>240</y>
<width>401</width>
<height>31</height>
</rect>
@ -238,7 +238,7 @@
<property name="geometry">
<rect>
<x>190</x>
<y>120</y>
<y>210</y>
<width>80</width>
<height>22</height>
</rect>
@ -260,6 +260,58 @@
<string>Use buttons to add to total tick duration</string>
</property>
</widget>
<widget class="QPushButton" name="x2">
<property name="geometry">
<rect>
<x>50</x>
<y>140</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>x2</string>
</property>
</widget>
<widget class="QPushButton" name="x3">
<property name="geometry">
<rect>
<x>140</x>
<y>140</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>x3</string>
</property>
</widget>
<widget class="QPushButton" name="x5">
<property name="geometry">
<rect>
<x>230</x>
<y>140</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>x5</string>
</property>
</widget>
<widget class="QPushButton" name="x7">
<property name="geometry">
<rect>
<x>320</x>
<y>140</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>x7</string>
</property>
</widget>
</widget>
<resources/>
<connections/>

50
qtgui/submenus.py

@ -49,8 +49,9 @@ def wrapCallDeactivateMidIn(self):
Submenu.__call__ = wrapCallDeactivateMidIn
class CombinedTickWidget(QtWidgets.QFrame):
def __init__(self):
super().__init__()
def __init__(self, mainWindow):
super().__init__(mainWindow)
self.mainWindow = mainWindow
self.setFrameShape(QtWidgets.QFrame.Box)
self.setFrameShadow(QtWidgets.QFrame.Sunken)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self)
@ -96,17 +97,28 @@ class CombinedTickWidget(QtWidgets.QFrame):
return self.upbeatSpinBox.value()
def callClickWidgetForUpbeat(self):
dialog = TickWidget(self, initValue = self.upbeatSpinBox.value())
dialog = TickWidget(self.mainWindow, initValue = self.upbeatSpinBox.value())
self.upbeatSpinBox.setValue(int(dialog.ui.ticks.value()))
class TickWidget(QtWidgets.QDialog):
def __init__(self, mainWindow, initValue = 0):
super().__init__(mainWindow)
def __init__(self, parentWindow, initValue = 0):
super().__init__()
#Set up the user interface from Designer.
self.ui = Ui_tickWidget()
self.ui.setupUi(self)
#This without init(parentWindow) will result in a nicely positioned window, that is not accesible :(
"""
self.setParent(parentWindow)
self.setAutoFillBackground(True)
self.setModal(False)
self.raise_()
self.activateWindow()
"""
#self.ui.ticks.setValue(initValue)
self.ui.ticks.setValue(0) #TODO: easier to drawLabel this way. change back to given value when drawLabel is autogenerated and does not work by keeping track anymore.
@ -116,7 +128,8 @@ class TickWidget(QtWidgets.QDialog):
self.ui.durationLabel.setText("")
self.clickedSoFar = [] #keep track
self.clickedSoFar = [] #keep track. This is purely cosmetical to remember the click history.
self.multipliers = [] #keep track. This is purely cosmetical to remember the click history.
self.ui.D1.clicked.connect(lambda: self.addDuration(api.D1))
self.ui.D2.clicked.connect(lambda: self.addDuration(api.D2))
@ -130,6 +143,12 @@ class TickWidget(QtWidgets.QDialog):
self.ui.DB.clicked.connect(lambda: self.addDuration(api.DB))
self.ui.DL.clicked.connect(lambda: self.addDuration(api.DL))
self.ui.x2.clicked.connect(lambda: self.multiply(2))
self.ui.x3.clicked.connect(lambda: self.multiply(3))
self.ui.x5.clicked.connect(lambda: self.multiply(5))
self.ui.x7.clicked.connect(lambda: self.multiply(7))
self.ui.ticks.valueChanged.connect(self.drawLabel)
self.exec() #blocks until the dialog gets closed
@ -139,14 +158,23 @@ class TickWidget(QtWidgets.QDialog):
def reset(self):
self.ui.ticks.setValue(0)
self.clickedSoFar = []
self.multipliers = []
self.ui.durationLabel.setText("")
def addDuration(self, duration):
def addDuration(self, duration:int):
self.clickedSoFar.append(duration)
nowTicks = self.ui.ticks.value()
self.ui.ticks.setValue(nowTicks + duration)
def multiply(self, times:int):
self.multipliers.append("x" + str(times))
nowTicks = self.ui.ticks.value()
self.ui.ticks.setValue(nowTicks * times)
def drawLabel(self):
"""This is purely cosmetical"""
#TODO: with nice partitions of real note icons.
#Error handling. A too complex or wrong duration (off by one, not equal to a partition etc.) blocks the "OK" button. No, just gives a warning.
#backendDurationInstance = api.items.Duration.createByGuessing(self.ui.ticks.value())
@ -159,7 +187,7 @@ class TickWidget(QtWidgets.QDialog):
part = str(times) + "x" + symbol
text.append(part)
self.ui.durationLabel.setText(" + ".join(text))
self.ui.durationLabel.setText("( " + " + ".join(text) + " ) " + " ".join(self.multipliers))
class SecondaryClefMenu(Submenu):
@ -345,7 +373,7 @@ class BlockPropertiesEdit(Submenu):
self.layout.addRow(translate("submenus", "name"), self.name)
#self.minimumInTicks = QtWidgets.QSpinBox()
self.minimumInTicks = CombinedTickWidget()
self.minimumInTicks = CombinedTickWidget(mainWindow)
self.minimumInTicks.setValue(self.staticExportItem["minimumInTicks"])
self.layout.addRow(translate("submenus", "minimum in ticks"), self.minimumInTicks)
@ -372,7 +400,7 @@ class TempoBlockPropertiesEdit(Submenu):
self.name.selectAll()
self.layout.addRow(translate("submenus", "name"), self.name)
self.duration = CombinedTickWidget()
self.duration = CombinedTickWidget(mainWindow)
self.duration.setValue(self.staticExportItem["duration"])
self.layout.addRow(translate("submenus", "duration in ticks"), self.duration)
@ -514,7 +542,7 @@ class GridRhytmEdit(Submenu):
self.mainWindow = mainWindow
self.layout.insertRow(0, QtWidgets.QLabel(translate("submenus", "Edit Grid")))
self.duration = CombinedTickWidget()
self.duration = CombinedTickWidget(mainWindow)
self.duration.setValue(constantsAndConfigs.gridRhythm)
self.layout.addRow(translate("submenus", "duration in ticks"), self.duration)

2
qtgui/trackEditor.py

@ -325,7 +325,7 @@ class TrackEditor(QtWidgets.QWidget):
allUpbeats.setLayout(allUpbeatsLayout)
self.layout.addWidget(allUpbeats)
self.allUpbeatsCombinedTickWidget = CombinedTickWidget()
self.allUpbeatsCombinedTickWidget = CombinedTickWidget(mainWindow)
allUpbeatsPushButton = QtWidgets.QPushButton(translate("trackEditorPythonFile", "set all upbeats"))
allUpbeatsPushButton.clicked.connect(self.setAllUpbeats) #gets the value itself

Loading…
Cancel
Save