Skip to content

Commit c635578

Browse files
committedApr 26, 2013
[sextante] Improvements in commander
1 parent 4065d57 commit c635578

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed
 

‎python/plugins/sextante/SextantePlugin.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ def __init__(self, iface):
5454
Sextante.setInterface(iface)
5555
Sextante.setPlugin(self)
5656

57-
def initGui(self):
57+
def initGui(self):
58+
self.commander = None
5859
self.toolbox = SextanteToolbox(self.iface)
5960
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
6061
self.toolbox.hide()
6162
Sextante.addAlgListListener(self.toolbox)
62-
63+
6364
self.menu = QMenu(self.iface.mainWindow())
6465
self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))
6566

@@ -100,7 +101,7 @@ def initGui(self):
100101
self.iface.mainWindow())
101102
self.commanderAction.triggered.connect(self.openCommander)
102103
self.menu.addAction(self.commanderAction)
103-
self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")
104+
self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")
104105

105106
def unload(self):
106107
self.toolbox.setVisible(False)
@@ -112,10 +113,13 @@ def unload(self):
112113

113114
self.iface.unregisterMainWindowAction(self.commanderAction)
114115

115-
def openCommander(self):
116-
dlg = CommanderWindow(self.iface.mainWindow(), self.iface.mapCanvas())
117-
dlg.show()
118-
dlg.exec_()
116+
def openCommander(self):
117+
if self.commander is None:
118+
self.commander = CommanderWindow(self.iface.mainWindow(), self.iface.mapCanvas())
119+
Sextante.addAlgListListener(self.commander)
120+
self.commander.prepareGui()
121+
self.commander.show()
122+
#dlg.exec_()
119123

120124

121125
def openToolbox(self):

‎python/plugins/sextante/commander/CommanderWindow.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class CommanderWindow(QtGui.QDialog):
4242
def __init__(self, parent, canvas):
4343
self.canvas = canvas
4444
QtGui.QDialog.__init__(self, parent, Qt.FramelessWindowHint)
45-
self.setModal(True)
46-
self.commands = imp.load_source("commands", self.commandsFile())
45+
#self.setModal(True)
46+
self.commands = imp.load_source("commands", self.commandsFile())
4747
self.initGui()
4848

4949
def commandsFolder(self):
@@ -65,29 +65,14 @@ def commandsFile(self):
6565
out.close()
6666
return f
6767

68+
def algsListHasChanged(self):
69+
self.fillCombo()
6870

6971
def initGui(self):
70-
self.combo= ExtendedComboBox()
71-
#add algorithm
72-
for providerName in Sextante.algs.keys():
73-
provider = Sextante.algs[providerName]
74-
algs = provider.values()
75-
for alg in algs:
76-
self.combo.addItem("SEXTANTE algorithm: " + alg.name)
77-
#add functions
78-
for command in dir(self.commands):
79-
if isinstance(self.commands.__dict__.get(command), types.FunctionType):
80-
self.combo.addItem("Command: " + command);
81-
#add menu entries
82-
menuActions = []
83-
actions = Sextante.getInterface().mainWindow().menuBar().actions()
84-
for action in actions:
85-
menuActions.extend(self.getActions(action))
86-
for action in menuActions:
87-
self.combo.addItem("Menu action: " + unicode(action.text()))
72+
self.combo= ExtendedComboBox()
73+
self.fillCombo()
8874

8975
self.combo.setEditable(True)
90-
self.combo.setEditText("")
9176
self.label = QtGui.QLabel("Enter command:")
9277
self.errorLabel = QtGui.QLabel("Enter command:")
9378
self.vlayout = QtGui.QVBoxLayout()
@@ -104,6 +89,31 @@ def initGui(self):
10489
self.vlayout.addSpacerItem(QtGui.QSpacerItem(0, OFFSET, QSizePolicy.Maximum, QSizePolicy.Expanding));
10590
self.setLayout(self.vlayout)
10691
self.combo.lineEdit().returnPressed.connect(self.run)
92+
self.prepareGui()
93+
94+
def fillCombo(self):
95+
self.combo.clear()
96+
#add algorithms
97+
for providerName in Sextante.algs.keys():
98+
provider = Sextante.algs[providerName]
99+
algs = provider.values()
100+
for alg in algs:
101+
self.combo.addItem("SEXTANTE algorithm: " + alg.name)
102+
#add functions
103+
for command in dir(self.commands):
104+
if isinstance(self.commands.__dict__.get(command), types.FunctionType):
105+
self.combo.addItem("Command: " + command);
106+
#add menu entries
107+
menuActions = []
108+
actions = Sextante.getInterface().mainWindow().menuBar().actions()
109+
for action in actions:
110+
menuActions.extend(self.getActions(action))
111+
for action in menuActions:
112+
self.combo.addItem("Menu action: " + unicode(action.text()))
113+
114+
115+
def prepareGui(self):
116+
self.combo.setEditText("")
107117
self.combo.setMaximumSize(QtCore.QSize(self.canvas.rect().width() - 2 * OFFSET, ITEMHEIGHT))
108118
self.combo.view().setStyleSheet("min-height: 150px")
109119
self.combo.setFocus(Qt.OtherFocusReason)

‎python/plugins/sextante/gui/HistoryDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* *
1717
***************************************************************************
1818
"""
19-
from sextante.gui import TestTools
2019

2120
__author__ = 'Victor Olaya'
2221
__date__ = 'August 2012'
@@ -26,6 +25,7 @@
2625

2726
from PyQt4.QtCore import *
2827
from PyQt4.QtGui import *
28+
from sextante.gui import TestTools
2929
from sextante.core.SextanteLog import SextanteLog
3030
from sextante.ui.ui_DlgHistory import Ui_DlgHistory
3131

0 commit comments

Comments
 (0)
Please sign in to comment.