Skip to content
Permalink
Browse files

[processing] add toolbar to modeler dialog

  • Loading branch information
alexbruy committed Sep 22, 2013
1 parent cb6f8cc commit f890449d6285776cc07abc55378991e8da94b244
@@ -53,32 +53,21 @@ def __init__(self, alg=None):
self.hasChanged = False
self.setupUi(self)

self.setWindowFlags(self.windowFlags() | Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint)
#self.setWindowFlags(self.windowFlags() | Qt.WindowSystemMenuHint |
# Qt.WindowMinMaxButtonsHint)
self.tabWidget.setCurrentIndex(0)
self.scene = ModelerScene(self)
self.scene.setSceneRect(QRectF(0, 0, 4000, 4000))
self.view.setScene(self.scene)
self.view.ensureVisible(0, 0, 10, 10)

# additional buttons
self.editHelpButton = QPushButton(self.tr("Edit model help"))
self.buttonBox.addButton(self.editHelpButton, QDialogButtonBox.ActionRole)
self.runButton = QPushButton(self.tr("Run"))
self.runButton.setToolTip(self.tr("Execute current model"))
self.buttonBox.addButton(self.runButton, QDialogButtonBox.ActionRole)
self.openButton = QPushButton(self.tr("Open"))
self.openButton.setToolTip(self.tr("Open existing model"))
self.buttonBox.addButton(self.openButton, QDialogButtonBox.ActionRole)
self.saveButton = QPushButton(self.tr("Save"))
self.saveButton.setToolTip(self.tr("Save current model"))
self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole)
self.saveAsButton = QPushButton(self.tr("Save as..."))
self.saveAsButton.setToolTip(self.tr("Save current model as"))
self.buttonBox.addButton(self.saveAsButton, QDialogButtonBox.ActionRole)
self.exportAsImageButton = QPushButton(self.tr("Export as image..."))
self.exportAsImageButton.setToolTip(self.tr("Export current model to image"))
self.buttonBox.addButton(self.exportAsImageButton, QDialogButtonBox.ActionRole)
# set icons
self.btnOpen.setIcon(QgsApplication.getThemeIcon("/mActionFileOpen.svg"))
self.btnSave.setIcon(QgsApplication.getThemeIcon("/mActionFileSave.svg"))
self.btnSaveAs.setIcon(QgsApplication.getThemeIcon("/mActionFileSaveAs.svg"))
self.btnExportImage.setIcon(QgsApplication.getThemeIcon("/mActionSaveMapAsImage.png"))
self.btnEditHelp.setIcon(QIcon(":/processing/images/edithelp.png"))
self.btnRun.setIcon(QIcon(":/processing/images/runalgorithm.png"))

# fill trees with inputs and algorithms
self.fillInputsTree()
@@ -97,12 +86,12 @@ def __init__(self, alg=None):
self.searchBox.textChanged.connect(self.fillAlgorithmTree)
self.algorithmTree.doubleClicked.connect(self.addAlgorithm)

self.openButton.clicked.connect(self.openModel)
self.saveButton.clicked.connect(self.save)
self.saveAsButton.clicked.connect(self.saveAs)
self.exportAsImageButton.clicked.connect(self.exportAsImage)
self.runButton.clicked.connect(self.runModel)
self.editHelpButton.clicked.connect(self.editHelp)
self.btnOpen.clicked.connect(self.openModel)
self.btnSave.clicked.connect(self.save)
self.btnSaveAs.clicked.connect(self.saveAs)
self.btnExportImage.clicked.connect(self.exportAsImage)
self.btnEditHelp.clicked.connect(self.editHelp)
self.btnRun.clicked.connect(self.runModel)

if alg is not None:
self.alg = alg
@@ -117,19 +106,21 @@ def __init__(self, alg=None):
self.help = None
self.update = False #indicates whether to update or not the toolbox after closing this dialog

def closeEvent(self, evt):
def closeEvent(self, evt):
if self.hasChanged:
ret = QMessageBox.question(self, 'Message',
"The are unchanged changes in model. Close modeler without saving?",
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
ret = QMessageBox.question(self,
self.tr("Message"),
self.tr("The are unchanged changes in model. Close modeler without saving?"),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
)

if ret == QMessageBox.Yes:
evt.accept()
else:
evt.ignore()
evt.ignore()
else:
evt.accept()
evt.accept()

def editHelp(self):
dlg = HelpEditionDialog(self.alg)
dlg.exec_()
@@ -212,7 +203,10 @@ def saveModel(self, saveAs):
if self.alg.descriptionFile != None and not saveAs:
filename = self.alg.descriptionFile
else:
filename = unicode(QFileDialog.getSaveFileName(self, self.tr("Save Model"), ModelerUtils.modelsFolder(), self.tr("Processing models (*.model)")))
filename = unicode(QFileDialog.getSaveFileName(self,
self.tr("Save Model"),
ModelerUtils.modelsFolder(),
self.tr("Processing models (*.model)")))
if filename:
if not filename.endswith(".model"):
filename += ".model"
@@ -224,14 +218,14 @@ def saveModel(self, saveAs):
except:
if saveAs:
QMessageBox.warning(self,
self.tr("I/O error"),
self.tr("Unable to save edits. Reason:\n %1").arg(unicode(sys.exc_info()[1]))
)
self.tr("I/O error"),
self.tr("Unable to save edits. Reason:\n %s") % (unicode(sys.exc_info()[1]))
)
else:
QMessageBox.warning(self,
self.tr("Can't save model"),
self.tr("This model can't be saved in its original location\n(probably you do not have permission to do it).\nPlease, use the 'Save as...' option.")
)
self.tr("Can't save model"),
self.tr("This model can't be saved in its original location\n(probably you do not have permission to do it).\nPlease, use the 'Save as...' option.")
)
return
fout.write(text)
fout.close()
@@ -246,11 +240,14 @@ def saveModel(self, saveAs):
self.tr("Model saved"),
self.tr("Model was correctly saved.")
)

self.hasChanged = False

def openModel(self):
filename = unicode(QFileDialog.getOpenFileName(self, self.tr("Open Model"), ModelerUtils.modelsFolder(), self.tr("Processing models (*.model)")))
filename = unicode(QFileDialog.getOpenFileName(self,
self.tr("Open Model"),
ModelerUtils.modelsFolder(),
self.tr("Processing models (*.model)")))
if filename:
try:
alg = ModelerAlgorithm()
@@ -267,7 +264,7 @@ def openModel(self):
except WrongModelException, e:
QMessageBox.critical(self,
self.tr("Could not open model"),
self.tr("The selected model could not be loaded.\nWrong line: %1").arg(e.msg)
self.tr("The selected model could not be loaded.\nWrong line: %s") % e.msg
)

def repaintModel(self):
@@ -418,7 +415,6 @@ def fillAlgorithmTreeUsingCategories(self):
if text != "":
groupItem.setExpanded(True)


def fillAlgorithmTreeUsingProviders(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
@@ -20,6 +20,110 @@
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>-1</number>
</property>
<property name="margin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="btnOpen">
<property name="toolTip">
<string>Open model</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSave">
<property name="toolTip">
<string>Save</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSaveAs">
<property name="toolTip">
<string>Save as...</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnExportImage">
<property name="toolTip">
<string>Export as image</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnEditHelp">
<property name="toolTip">
<string>Edit model help</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRun">
<property name="toolTip">
<string>Run model</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
@@ -32,6 +136,9 @@
<height>0</height>
</size>
</property>
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>1</number>
</property>
@@ -125,16 +232,6 @@
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@@ -145,38 +242,5 @@
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgModeler</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DlgModeler</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

0 comments on commit f890449

Please sign in to comment.
You can’t perform that action at this time.