From 4876baaa93bb2fc30f1a7df76683ad01d70d1fed Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 1 Jan 2016 01:11:13 +0000 Subject: [PATCH] Simplify replace-plugin dialog code --- source/carla_host.py | 20 ++++++++++---------- source/carla_skin.py | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/source/carla_host.py b/source/carla_host.py index ef2ad276a..a82d41a1e 100644 --- a/source/carla_host.py +++ b/source/carla_host.py @@ -721,8 +721,7 @@ class HostWindow(QMainWindow): # -------------------------------------------------------------------------------------------------------- # Plugins (menu actions) - @pyqtSlot() - def slot_pluginAdd(self, pluginToReplace = -1): + def showAddPluginDialog(self): dialog = PluginDatabaseW(self.fParentOrSelf, self.host) if not dialog.exec_(): @@ -739,17 +738,18 @@ class HostWindow(QMainWindow): uniqueId = dialog.fRetPlugin['uniqueId'] extraPtr = self.getExtraPtr(dialog.fRetPlugin) - if pluginToReplace >= 0: - if not self.host.replace_plugin(pluginToReplace): - CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok) - return + return (btype, ptype, filename, label, uniqueId, extraPtr) + + @pyqtSlot() + def slot_pluginAdd(self): + data = self.showAddPluginDialog() - ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0) + if data is None: + return - if pluginToReplace >= 0: - self.host.replace_plugin(self.host.get_max_plugin_number()) + btype, ptype, filename, label, uniqueId, extraPtr = data - if not ok: + if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0): CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok) @pyqtSlot() diff --git a/source/carla_skin.py b/source/carla_skin.py index c52944701..b2002543b 100755 --- a/source/carla_skin.py +++ b/source/carla_skin.py @@ -763,6 +763,25 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta): self.setName(newName) + def showReplaceDialog(self): + data = gCarla.gui.showAddPluginDialog() + + if data is None: + return + + btype, ptype, filename, label, uniqueId, extraPtr = data + + if not self.host.replace_plugin(self.fPluginId): + CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok) + return + + ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0) + + self.host.replace_plugin(self.host.get_max_plugin_number()) + + if not ok: + CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok) + #------------------------------------------------------------------ def activeChanged(self, onOff): @@ -1083,8 +1102,7 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta): # Replace elif actSel == actReplace: - # FIXME - gCarla.gui.slot_pluginAdd(self.fPluginId) + self.showReplaceDialog() # ------------------------------------------------------------- # Remove