<filename>controllers/kn8bber/ui/mainWindow.py<gh_stars>0
"""Main Window module for Kn8bber controller."""

from PySide2 import QtWidgets

from controllers.kn8bber.core import controller
from controllers.kn8bber import const


class Kn8bber(QtWidgets.QWidget):
    """Main Window For Kn8bber."""
    def __init__(self):
        super().__init__()
        self._midi_controller = controller.Kn8bberController()
        self._setup_ui()

    def _setup_ui(self):
        """Setups ui for the main window. Just setting the widgets and their callbacks."""
        v_layout = QtWidgets.QVBoxLayout()

        dials_layout = QtWidgets.QGridLayout()

        for idx, cmd in enumerate(const.KOB_CC_LIST):
            grid = QtWidgets.QGridLayout()
            dial = QtWidgets.QDial()
            dial.setWrapping(True)
            dial.setMinimum(0)
            dial.setMaximum(127)
            dial.setSingleStep(1)

            edit_line = QtWidgets.QLineEdit()
            edit_line.setDisabled(True)
            grid.addWidget(dial, 0, 0)
            grid.addWidget(edit_line, 1, 0)

            # Assigning to each dial a value and a command to send through midi.
            dial.valueChanged.connect(lambda value, c=cmd: self._midi_controller.send_value_msg(c, value))

            row = 0 if idx < 4 else 1
            column = idx if idx < 4 else idx - 4
            dials_layout.addLayout(grid, row, column)

        v_layout.addLayout(dials_layout)

        selection_grid = QtWidgets.QGridLayout()

        prev_track_btn = QtWidgets.QPushButton("Previous Track")
        prev_track_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("pTrack")))

        next_track_btn = QtWidgets.QPushButton("Next Track")
        next_track_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("nTrack")))

        prev_device_btn = QtWidgets.QPushButton("Previous Device")
        prev_device_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("pDevice")))

        next_device_btn = QtWidgets.QPushButton("Next Device")
        next_device_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("nDevice")))

        selection_grid.addWidget(prev_track_btn, 0, 0)
        selection_grid.addWidget(next_track_btn, 0, 1)
        selection_grid.addWidget(prev_device_btn, 1, 0)
        selection_grid.addWidget(next_device_btn, 1, 1)

        v_layout.addLayout(selection_grid)
        self.setLayout(v_layout)

<filename>controllers/kn8bber/ui/mainWindow.py<gh_stars>0
"""Main Window module for Kn8bber controller."""

from PySide2 import QtWidgets

from controllers.kn8bber.core import controller
from controllers.kn8bber import const


class Kn8bber(QtWidgets.QWidget):
    """Main Window For Kn8bber."""
    def __init__(self):
        super().__init__()
        self._midi_controller = controller.Kn8bberController()
        self._setup_ui()

    def _setup_ui(self):
        """Setups ui for the main window. Just setting the widgets and their callbacks."""
        v_layout = QtWidgets.QVBoxLayout()

        dials_layout = QtWidgets.QGridLayout()

        for idx, cmd in enumerate(const.KOB_CC_LIST):
            grid = QtWidgets.QGridLayout()
            dial = QtWidgets.QDial()
            dial.setWrapping(True)
            dial.setMinimum(0)
            dial.setMaximum(127)
            dial.setSingleStep(1)

            edit_line = QtWidgets.QLineEdit()
            edit_line.setDisabled(True)
            grid.addWidget(dial, 0, 0)
            grid.addWidget(edit_line, 1, 0)

            # Assigning to each dial a value and a command to send through midi.
            dial.valueChanged.connect(lambda value, c=cmd: self._midi_controller.send_value_msg(c, value))

            row = 0 if idx < 4 else 1
            column = idx if idx < 4 else idx - 4
            dials_layout.addLayout(grid, row, column)

        v_layout.addLayout(dials_layout)

        selection_grid = QtWidgets.QGridLayout()

        prev_track_btn = QtWidgets.QPushButton("Previous Track")
        prev_track_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("pTrack")))

        next_track_btn = QtWidgets.QPushButton("Next Track")
        next_track_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("nTrack")))

        prev_device_btn = QtWidgets.QPushButton("Previous Device")
        prev_device_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("pDevice")))

        next_device_btn = QtWidgets.QPushButton("Next Device")
        next_device_btn.clicked.connect(lambda x: self._midi_controller.send_simple_msg(
            core.navigation_cc.get("nDevice")))

        selection_grid.addWidget(prev_track_btn, 0, 0)
        selection_grid.addWidget(next_track_btn, 0, 1)
        selection_grid.addWidget(prev_device_btn, 1, 0)
        selection_grid.addWidget(next_device_btn, 1, 1)

        v_layout.addLayout(selection_grid)
        self.setLayout(v_layout)

Main Window module for Kn8bber controller. Main Window For Kn8bber. Setups ui for the main window. Just setting the widgets and their callbacks. # Assigning to each dial a value and a command to send through midi.