Skip to content

Commit

Permalink
[sextante] Improvements in commander
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Apr 26, 2013
1 parent 4065d57 commit c635578
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
18 changes: 11 additions & 7 deletions python/plugins/sextante/SextantePlugin.py
Expand Up @@ -54,12 +54,13 @@ def __init__(self, iface):
Sextante.setInterface(iface)
Sextante.setPlugin(self)

def initGui(self):
def initGui(self):
self.commander = None
self.toolbox = SextanteToolbox(self.iface)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
Sextante.addAlgListListener(self.toolbox)

self.menu = QMenu(self.iface.mainWindow())
self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

Expand Down Expand Up @@ -100,7 +101,7 @@ def initGui(self):
self.iface.mainWindow())
self.commanderAction.triggered.connect(self.openCommander)
self.menu.addAction(self.commanderAction)
self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")
self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")

def unload(self):
self.toolbox.setVisible(False)
Expand All @@ -112,10 +113,13 @@ def unload(self):

self.iface.unregisterMainWindowAction(self.commanderAction)

def openCommander(self):
dlg = CommanderWindow(self.iface.mainWindow(), self.iface.mapCanvas())
dlg.show()
dlg.exec_()
def openCommander(self):
if self.commander is None:
self.commander = CommanderWindow(self.iface.mainWindow(), self.iface.mapCanvas())
Sextante.addAlgListListener(self.commander)
self.commander.prepareGui()
self.commander.show()
#dlg.exec_()


def openToolbox(self):
Expand Down
52 changes: 31 additions & 21 deletions python/plugins/sextante/commander/CommanderWindow.py
Expand Up @@ -42,8 +42,8 @@ class CommanderWindow(QtGui.QDialog):
def __init__(self, parent, canvas):
self.canvas = canvas
QtGui.QDialog.__init__(self, parent, Qt.FramelessWindowHint)
self.setModal(True)
self.commands = imp.load_source("commands", self.commandsFile())
#self.setModal(True)
self.commands = imp.load_source("commands", self.commandsFile())
self.initGui()

def commandsFolder(self):
Expand All @@ -65,29 +65,14 @@ def commandsFile(self):
out.close()
return f

def algsListHasChanged(self):
self.fillCombo()

def initGui(self):
self.combo= ExtendedComboBox()
#add algorithm
for providerName in Sextante.algs.keys():
provider = Sextante.algs[providerName]
algs = provider.values()
for alg in algs:
self.combo.addItem("SEXTANTE algorithm: " + alg.name)
#add functions
for command in dir(self.commands):
if isinstance(self.commands.__dict__.get(command), types.FunctionType):
self.combo.addItem("Command: " + command);
#add menu entries
menuActions = []
actions = Sextante.getInterface().mainWindow().menuBar().actions()
for action in actions:
menuActions.extend(self.getActions(action))
for action in menuActions:
self.combo.addItem("Menu action: " + unicode(action.text()))
self.combo= ExtendedComboBox()
self.fillCombo()

self.combo.setEditable(True)
self.combo.setEditText("")
self.label = QtGui.QLabel("Enter command:")
self.errorLabel = QtGui.QLabel("Enter command:")
self.vlayout = QtGui.QVBoxLayout()
Expand All @@ -104,6 +89,31 @@ def initGui(self):
self.vlayout.addSpacerItem(QtGui.QSpacerItem(0, OFFSET, QSizePolicy.Maximum, QSizePolicy.Expanding));
self.setLayout(self.vlayout)
self.combo.lineEdit().returnPressed.connect(self.run)
self.prepareGui()

def fillCombo(self):
self.combo.clear()
#add algorithms
for providerName in Sextante.algs.keys():
provider = Sextante.algs[providerName]
algs = provider.values()
for alg in algs:
self.combo.addItem("SEXTANTE algorithm: " + alg.name)
#add functions
for command in dir(self.commands):
if isinstance(self.commands.__dict__.get(command), types.FunctionType):
self.combo.addItem("Command: " + command);
#add menu entries
menuActions = []
actions = Sextante.getInterface().mainWindow().menuBar().actions()
for action in actions:
menuActions.extend(self.getActions(action))
for action in menuActions:
self.combo.addItem("Menu action: " + unicode(action.text()))


def prepareGui(self):
self.combo.setEditText("")
self.combo.setMaximumSize(QtCore.QSize(self.canvas.rect().width() - 2 * OFFSET, ITEMHEIGHT))
self.combo.view().setStyleSheet("min-height: 150px")
self.combo.setFocus(Qt.OtherFocusReason)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/HistoryDialog.py
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************
"""
from sextante.gui import TestTools

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -26,6 +25,7 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.gui import TestTools
from sextante.core.SextanteLog import SextanteLog
from sextante.ui.ui_DlgHistory import Ui_DlgHistory

Expand Down

0 comments on commit c635578

Please sign in to comment.