Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added support for custom output rendering styles
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@50 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
- Loading branch information
volayaf
committed
Mar 21, 2012
1 parent
772e8e7
commit 3e95fb5
Showing
8 changed files
with
169 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
from PyQt4 import QtCore, QtGui | ||
from sextante.outputs.OutputRaster import OutputRaster | ||
from sextante.outputs.OutputVector import OutputVector | ||
from sextante.gui.RenderingStyles import RenderingStyles | ||
|
||
class EditRenderingStylesDialog(QtGui.QDialog): | ||
def __init__(self, alg): | ||
QtGui.QDialog.__init__(self) | ||
self.setModal(True) | ||
self.alg = alg | ||
self.setupUi() | ||
|
||
def setupUi(self): | ||
self.valueItems = {} | ||
self.dependentItems = {} | ||
self.resize(650, 450) | ||
self.buttonBox = QtGui.QDialogButtonBox() | ||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) | ||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) | ||
self.buttonBox.setObjectName("buttonBox") | ||
self.tableWidget = QtGui.QTableWidget() | ||
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.NoSelection) | ||
self.tableWidget.setColumnCount(2) | ||
self.tableWidget.setColumnWidth(0,300) | ||
self.tableWidget.setColumnWidth(1,300) | ||
self.tableWidget.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Output")) | ||
self.tableWidget.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Style")) | ||
self.tableWidget.setObjectName("tableWidget") | ||
self.tableWidget.verticalHeader().setVisible(False) | ||
self.tableWidget.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch) | ||
self.setTableContent() | ||
self.setWindowTitle(self.alg.name) | ||
self.verticalLayout = QtGui.QVBoxLayout() | ||
self.verticalLayout.setSpacing(2) | ||
self.verticalLayout.setMargin(0) | ||
self.verticalLayout.setObjectName("vLayout") | ||
self.verticalLayout.addWidget(self.tableWidget) | ||
self.verticalLayout.addWidget(self.buttonBox) | ||
self.setLayout(self.verticalLayout) | ||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed) | ||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed) | ||
QtCore.QMetaObject.connectSlotsByName(self) | ||
|
||
def setTableContent(self): | ||
numOutputs = 0 | ||
for output in self.alg.outputs: | ||
if isinstance(output, (OutputVector, OutputRaster)): | ||
if isinstance(output, OutputVector): | ||
if output.hidden: | ||
continue | ||
numOutputs += 1 | ||
self.tableWidget.setRowCount(numOutputs) | ||
|
||
i = 0 | ||
for output in self.alg.outputs: | ||
if isinstance(output, OutputVector): | ||
if output.hidden: | ||
continue | ||
item = QtGui.QTableWidgetItem(output.description + "<" + output.__module__.split(".")[-1] + ">") | ||
item.setFlags(QtCore.Qt.ItemIsEnabled) | ||
self.tableWidget.setItem(i,0, item) | ||
item = QtGui.QLineEdit() | ||
style = RenderingStyles.getStyle(self.alg.commandLineName(), output.name) | ||
if style: | ||
item.setText(str(style)) | ||
self.valueItems[output.name] = item | ||
self.tableWidget.setCellWidget(i,1, item) | ||
self.tableWidget.setRowHeight(i,22) | ||
i+=1 | ||
|
||
def okPressed(self): | ||
styles = {} | ||
for key in self.valueItems.keys(): | ||
styles[key] = str(self.valueItems[key].text()) | ||
RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles) | ||
self.close() | ||
|
||
def cancelPressed(self): | ||
self.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from sextante.core.SextanteUtils import SextanteUtils | ||
import os.path | ||
|
||
class RenderingStyles(): | ||
|
||
styles = {} | ||
|
||
@staticmethod | ||
def addAlgStylesAndSave(algname, styles): | ||
RenderingStyles.styles[algname] = styles | ||
RenderingStyles.saveSettings() | ||
|
||
|
||
@staticmethod | ||
def configFile(): | ||
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis_styles.conf") | ||
|
||
@staticmethod | ||
def loadStyles(): | ||
if not os.path.isfile(RenderingStyles.configFile()): | ||
return | ||
lines = open(RenderingStyles.configFile()) | ||
line = lines.readline().strip("\n") | ||
while line != "": | ||
tokens = line.split("|") | ||
if tokens[0] in RenderingStyles.styles.keys(): | ||
RenderingStyles.styles[tokens[0]][tokens[1]] = tokens[2] | ||
else: | ||
alg = {} | ||
alg[tokens[1]]=tokens[2] | ||
RenderingStyles.styles[tokens[0]] = alg | ||
line = lines.readline().strip("\n") | ||
lines.close() | ||
|
||
@staticmethod | ||
def saveSettings(): | ||
fout = open(RenderingStyles.configFile(), "w") | ||
for alg in RenderingStyles.styles.keys(): | ||
for out in RenderingStyles.styles[alg].keys(): | ||
fout.write(alg + "|" + out + "|" + RenderingStyles.styles[alg][out] + "\n") | ||
fout.close() | ||
|
||
@staticmethod | ||
def getStyle(algname, outputname): | ||
if algname in RenderingStyles.styles: | ||
if outputname in RenderingStyles.styles[algname]: | ||
return RenderingStyles.styles[algname][outputname] | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters