|
|
@@ -19,7 +19,7 @@ |
|
|
|
# ------------------------------------------------------------------------------------------------------------ |
|
|
|
# Imports (Global) |
|
|
|
|
|
|
|
from PyQt5.QtGui import QKeySequence |
|
|
|
from PyQt5.QtGui import QKeySequence, QMouseEvent |
|
|
|
from PyQt5.QtWidgets import QHBoxLayout |
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------ |
|
|
@@ -81,12 +81,12 @@ class CarlaMiniW(ExternalUI, HostWindow): |
|
|
|
def __init__(self, host, isPatchbay, parent=None): |
|
|
|
ExternalUI.__init__(self) |
|
|
|
HostWindow.__init__(self, host, isPatchbay, parent) |
|
|
|
self.host = host |
|
|
|
|
|
|
|
if False: |
|
|
|
# kdevelop likes this :) |
|
|
|
host = PluginHost() |
|
|
|
self.host = host |
|
|
|
|
|
|
|
self.host = host |
|
|
|
|
|
|
|
host.setExternalUI(self) |
|
|
|
|
|
|
@@ -387,6 +387,157 @@ class CarlaMiniW(ExternalUI, HostWindow): |
|
|
|
else: |
|
|
|
print("unknown message: \"" + msg + "\"") |
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------ |
|
|
|
# Embed Widget |
|
|
|
|
|
|
|
class QEmbedWidget(QWidget): |
|
|
|
def __init__(self, winId): |
|
|
|
QWidget.__init__(self) |
|
|
|
self.setAttribute(Qt.WA_LayoutUsesWidgetRect) |
|
|
|
self.move(0, 0) |
|
|
|
|
|
|
|
self.fPos = (0, 0) |
|
|
|
self.fWinId = 0 |
|
|
|
|
|
|
|
def finalSetup(self, gui, winId): |
|
|
|
self.fWinId = int(self.winId()) |
|
|
|
gui.ui.centralwidget.installEventFilter(self) |
|
|
|
gui.ui.menubar.installEventFilter(self) |
|
|
|
gCarla.utils.x11_reparent_window(self.fWinId, winId) |
|
|
|
self.show() |
|
|
|
|
|
|
|
def fixPosition(self): |
|
|
|
pos = gCarla.utils.x11_get_window_pos(self.fWinId) |
|
|
|
if self.fPos == pos: |
|
|
|
return |
|
|
|
self.fPos = pos |
|
|
|
self.move(pos[0], pos[1]) |
|
|
|
gCarla.utils.x11_move_window(self.fWinId, pos[2], pos[3]) |
|
|
|
|
|
|
|
def eventFilter(self, obj, ev): |
|
|
|
if isinstance(ev, QMouseEvent): |
|
|
|
self.fixPosition() |
|
|
|
return False |
|
|
|
|
|
|
|
def enterEvent(self, ev): |
|
|
|
self.fixPosition() |
|
|
|
QWidget.enterEvent(self, ev) |
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------ |
|
|
|
# Embed plugin UI |
|
|
|
|
|
|
|
class CarlaEmbedW(QEmbedWidget): |
|
|
|
def __init__(self, host, winId, isPatchbay): |
|
|
|
QEmbedWidget.__init__(self, winId) |
|
|
|
|
|
|
|
if False: |
|
|
|
host = CarlaHostPlugin() |
|
|
|
|
|
|
|
self.host = host |
|
|
|
self.fWinId = winId |
|
|
|
self.setFixedSize(1024, 712) |
|
|
|
|
|
|
|
self.fLayout = QVBoxLayout(self) |
|
|
|
self.fLayout.setContentsMargins(0, 0, 0, 0) |
|
|
|
self.fLayout.setSpacing(0) |
|
|
|
self.setLayout(self.fLayout) |
|
|
|
|
|
|
|
self.gui = CarlaMiniW(host, isPatchbay, self) |
|
|
|
self.gui.hide() |
|
|
|
|
|
|
|
self.gui.ui.act_file_quit.setEnabled(False) |
|
|
|
self.gui.ui.act_file_quit.setVisible(False) |
|
|
|
|
|
|
|
self.fShortcutActions = [] |
|
|
|
self.addShortcutActions(self.gui.ui.menu_File.actions()) |
|
|
|
self.addShortcutActions(self.gui.ui.menu_Plugin.actions()) |
|
|
|
self.addShortcutActions(self.gui.ui.menu_PluginMacros.actions()) |
|
|
|
self.addShortcutActions(self.gui.ui.menu_Settings.actions()) |
|
|
|
self.addShortcutActions(self.gui.ui.menu_Help.actions()) |
|
|
|
|
|
|
|
if self.host.processMode == ENGINE_PROCESS_MODE_PATCHBAY: |
|
|
|
self.addShortcutActions(self.gui.ui.menu_Canvas.actions()) |
|
|
|
self.addShortcutActions(self.gui.ui.menu_Canvas_Zoom.actions()) |
|
|
|
|
|
|
|
self.addWidget(self.gui.ui.menubar) |
|
|
|
self.addLine() |
|
|
|
self.addWidget(self.gui.ui.toolBar) |
|
|
|
|
|
|
|
if self.host.processMode == ENGINE_PROCESS_MODE_PATCHBAY: |
|
|
|
self.addLine() |
|
|
|
|
|
|
|
self.addWidget(self.gui.centralWidget()) |
|
|
|
self.finalSetup(self.gui, winId) |
|
|
|
|
|
|
|
def addShortcutActions(self, actions): |
|
|
|
for action in actions: |
|
|
|
if not action.shortcut().isEmpty(): |
|
|
|
self.fShortcutActions.append(action) |
|
|
|
|
|
|
|
def addWidget(self, widget): |
|
|
|
widget.setParent(self) |
|
|
|
self.fLayout.addWidget(widget) |
|
|
|
|
|
|
|
def addLine(self): |
|
|
|
line = QFrame(self) |
|
|
|
line.setFrameShadow(QFrame.Sunken) |
|
|
|
line.setFrameShape(QFrame.HLine) |
|
|
|
line.setLineWidth(0) |
|
|
|
line.setMidLineWidth(1) |
|
|
|
self.fLayout.addWidget(line) |
|
|
|
|
|
|
|
def keyPressEvent(self, event): |
|
|
|
modifiers = event.modifiers() |
|
|
|
modifiersStr = "" |
|
|
|
|
|
|
|
if modifiers & Qt.ShiftModifier: |
|
|
|
modifiersStr += "Shift+" |
|
|
|
if modifiers & Qt.ControlModifier: |
|
|
|
modifiersStr += "Ctrl+" |
|
|
|
if modifiers & Qt.AltModifier: |
|
|
|
modifiersStr += "Alt+" |
|
|
|
if modifiers & Qt.MetaModifier: |
|
|
|
modifiersStr += "Meta+" |
|
|
|
|
|
|
|
keyStr = QKeySequence(event.key()).toString() |
|
|
|
keySeq = QKeySequence(modifiersStr + keyStr) |
|
|
|
|
|
|
|
for action in self.fShortcutActions: |
|
|
|
if not action.isEnabled(): |
|
|
|
continue |
|
|
|
if keySeq.matches(action.shortcut()) != QKeySequence.ExactMatch: |
|
|
|
continue |
|
|
|
event.accept() |
|
|
|
action.trigger() |
|
|
|
return |
|
|
|
|
|
|
|
QEmbedWidget.keyPressEvent(self, event) |
|
|
|
|
|
|
|
def showEvent(self, event): |
|
|
|
QEmbedWidget.showEvent(self, event) |
|
|
|
|
|
|
|
# set our gui as parent for all plugins UIs |
|
|
|
if self.host.manageUIs: |
|
|
|
winIdStr = "%x" % self.fWinId |
|
|
|
self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr) |
|
|
|
|
|
|
|
def hideEvent(self, event): |
|
|
|
# disable parent |
|
|
|
self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0") |
|
|
|
|
|
|
|
QEmbedWidget.hideEvent(self, event) |
|
|
|
|
|
|
|
def closeEvent(self, event): |
|
|
|
self.gui.close() |
|
|
|
self.gui.closeExternalUI() |
|
|
|
QEmbedWidget.closeEvent(self, event) |
|
|
|
|
|
|
|
# there might be other qt windows open which will block carla-plugin from quitting |
|
|
|
app.quit() |
|
|
|
|
|
|
|
def setLoadRDFsNeeded(self): |
|
|
|
self.gui.setLoadRDFsNeeded() |
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------ |
|
|
|
# Main |
|
|
|
|
|
|
@@ -415,7 +566,17 @@ if __name__ == '__main__': |
|
|
|
# ------------------------------------------------------------- |
|
|
|
# Create GUI |
|
|
|
|
|
|
|
gui = CarlaMiniW(host, isPatchbay) |
|
|
|
try: |
|
|
|
winId = int(os.getenv("CARLA_PLUGIN_EMBED_WINID")) |
|
|
|
except: |
|
|
|
winId = 0 |
|
|
|
|
|
|
|
gCarla.utils.setenv("CARLA_PLUGIN_EMBED_WINID", "0") |
|
|
|
|
|
|
|
if LINUX and winId != 0: |
|
|
|
gui = CarlaEmbedW(host, winId, isPatchbay) |
|
|
|
else: |
|
|
|
gui = CarlaMiniW(host, isPatchbay) |
|
|
|
|
|
|
|
# ------------------------------------------------------------- |
|
|
|
# App-Loop |
|
|
|