From 6fb32687c4511d8ef13df21d1e37c67c23887c9d Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 6 Nov 2014 15:50:12 +0200 Subject: [PATCH] [processing] remove MultipleFileInputPanel as it duplicates MultipleInputPanel homogenize UI in FileSelectionPanel and RenderinStylePanel, remove inused imports --- .../processing/gui/CrsSelectionPanel.py | 1 - .../processing/gui/ExtentSelectionPanel.py | 1 - .../processing/gui/FileSelectionPanel.py | 50 +++++++-------- .../processing/gui/MultipleFileInputPanel.py | 61 ------------------- .../processing/gui/MultipleInputPanel.py | 45 +++++++------- .../plugins/processing/gui/ParametersPanel.py | 3 +- .../processing/gui/RenderingStyleFilePanel.py | 42 ++++++------- 7 files changed, 66 insertions(+), 137 deletions(-) delete mode 100644 python/plugins/processing/gui/MultipleFileInputPanel.py diff --git a/python/plugins/processing/gui/CrsSelectionPanel.py b/python/plugins/processing/gui/CrsSelectionPanel.py index 7472ecf10bc..5e8a07d9250 100644 --- a/python/plugins/processing/gui/CrsSelectionPanel.py +++ b/python/plugins/processing/gui/CrsSelectionPanel.py @@ -26,7 +26,6 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' from PyQt4.QtGui import * -from PyQt4.QtCore import * from qgis.gui import * from qgis.core import * diff --git a/python/plugins/processing/gui/ExtentSelectionPanel.py b/python/plugins/processing/gui/ExtentSelectionPanel.py index 71205073a50..72cfeceab03 100644 --- a/python/plugins/processing/gui/ExtentSelectionPanel.py +++ b/python/plugins/processing/gui/ExtentSelectionPanel.py @@ -25,7 +25,6 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' -from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * diff --git a/python/plugins/processing/gui/FileSelectionPanel.py b/python/plugins/processing/gui/FileSelectionPanel.py index 771f3987155..77d80388dca 100644 --- a/python/plugins/processing/gui/FileSelectionPanel.py +++ b/python/plugins/processing/gui/FileSelectionPanel.py @@ -26,33 +26,29 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' import os -from PyQt4 import QtGui, QtCore + +from PyQt4.QtGui import * + from processing.tools.system import * +from processing.ui.ui_widgetBaseSelector import Ui_Form -class FileSelectionPanel(QtGui.QWidget): - def __init__(self, isFolder, ext = None): - super(FileSelectionPanel, self).__init__(None) +class FileSelectionPanel(QWidget, Ui_Form): + + def __init__(self, isFolder, ext=None): + QWidget.__init__(self) + self.setupUi(self) + self.ext = ext or '*' self.isFolder = isFolder - self.horizontalLayout = QtGui.QHBoxLayout(self) - self.horizontalLayout.setSpacing(2) - self.horizontalLayout.setMargin(0) - self.text = QtGui.QLineEdit() - self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, - QtGui.QSizePolicy.Expanding) - self.horizontalLayout.addWidget(self.text) - self.pushButton = QtGui.QPushButton() - self.pushButton.setText(self.tr('...')) - self.pushButton.clicked.connect(self.showSelectionDialog) - self.horizontalLayout.addWidget(self.pushButton) - self.setLayout(self.horizontalLayout) + + self.btnSelect.clicked.connect(self.showSelectionDialog) def showSelectionDialog(self): # Find the file dialog's working directory - settings = QtCore.QSettings() - text = unicode(self.text.text()) + settings = QSettings() + text = self.leText.text() if os.path.isdir(text): path = text elif os.path.isdir(os.path.dirname(text)): @@ -63,25 +59,25 @@ class FileSelectionPanel(QtGui.QWidget): path = '' if self.isFolder: - folder = QtGui.QFileDialog.getExistingDirectory(self, + folder = QFileDialog.getExistingDirectory(self, self.tr('Select folder'), path) if folder: - self.text.setText(str(folder)) + self.leText.setText(folder) settings.setValue('/Processing/LastInputPath', - os.path.dirname(unicode(folder))) + os.path.dirname(folder)) else: - filenames = QtGui.QFileDialog.getOpenFileNames(self, self.tr('Open file'), - path, '*.' + self.ext) + filenames = QFileDialog.getOpenFileNames(self, + self.tr('Select file'), path, '*.' + self.ext) if filenames: - self.text.setText(u';'.join(filenames)) + self.leText.setText(u';'.join(filenames)) settings.setValue('/Processing/LastInputPath', - os.path.dirname(unicode(filenames[0]))) + os.path.dirname(filenames[0])) def getValue(self): - s = unicode(self.text.text()) + s = self.leText.text() if isWindows(): s = s.replace('\\', '/') return s def setText(self, text): - self.text.setText(text) + self.leText.setText(text) diff --git a/python/plugins/processing/gui/MultipleFileInputPanel.py b/python/plugins/processing/gui/MultipleFileInputPanel.py deleted file mode 100644 index 6b4b6f9651d..00000000000 --- a/python/plugins/processing/gui/MultipleFileInputPanel.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -*************************************************************************** - MultipleFileInputPanel.py - --------------------- - Date : August 2012 - Copyright : (C) 2012 by Victor Olaya - (C) 2013 by CS Systemes d'information (CS SI) - Email : volayaf at gmail dot com - otb at c-s dot fr (CS SI) - Contributors : Victor Olaya - basis from MultipleInputPanel - Alexia Mondot (CS SI) - adapt for a new parameter -*************************************************************************** -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -*************************************************************************** -""" - -__author__ = 'Victor Olaya' -__date__ = 'August 2012' -__copyright__ = '(C) 2012, Victor Olaya' -# This will get replaced with a git SHA1 when you do a git archive -__revision__ = '$Format:%H$' - -from PyQt4 import QtGui -from processing.gui.MultipleFileInputDialog import MultipleFileInputDialog - -class MultipleFileInputPanel(QtGui.QWidget): - - def __init__(self, parent = None): - super(MultipleFileInputPanel, self).__init__(parent) - self.selectedoptions = [] - self.horizontalLayout = QtGui.QHBoxLayout(self) - self.horizontalLayout.setSpacing(2) - self.horizontalLayout.setMargin(0) - self.label = QtGui.QLabel() - self.label.setText(self.tr('0 elements selected')) - self.label.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) - self.horizontalLayout.addWidget(self.label) - self.pushButton = QtGui.QPushButton() - self.pushButton.setText(self.tr('...')) - self.pushButton.clicked.connect(self.showSelectionDialog) - self.horizontalLayout.addWidget(self.pushButton) - self.setLayout(self.horizontalLayout) - - def setSelectedItems(self, selected): - #no checking is performed! - self.selectedoptions = selected - self.label.setText(self.tr('%d elements selected') % len(self.selectedoptions)) - - def showSelectionDialog(self): - dlg = MultipleFileInputDialog(self.selectedoptions) - dlg.exec_() - if dlg.selectedoptions != None: - self.selectedoptions = dlg.selectedoptions - self.label.setText(self.tr('%d elements selected') % len(self.selectedoptions)) diff --git a/python/plugins/processing/gui/MultipleInputPanel.py b/python/plugins/processing/gui/MultipleInputPanel.py index aace2727fac..c8c5bd0de1c 100644 --- a/python/plugins/processing/gui/MultipleInputPanel.py +++ b/python/plugins/processing/gui/MultipleInputPanel.py @@ -25,42 +25,41 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' -from PyQt4 import QtGui +from PyQt4.QtGui import * + from processing.gui.MultipleInputDialog import MultipleInputDialog +from processing.gui.MultipleFileInputDialog import MultipleFileInputDialog +from processing.ui.ui_widgetBaseSelector import Ui_Form -class MultipleInputPanel(QtGui.QWidget): +class MultipleInputPanel(QWidget, Ui_Form): + + def __init__(self, options=None, datatype=None): + QWidget.__init__(self) + self.setupUi(self) + + self.leText.setEnabled(False) + self.leText.setText(self.tr('0 elements selected')) + + self.btnSelect.clicked.connect(self.showSelectionDialog) - def __init__(self, options, datatype=None, parent=None): - super(MultipleInputPanel, self).__init__(parent) self.options = options self.datatype = datatype self.selectedoptions = [] - self.horizontalLayout = QtGui.QHBoxLayout(self) - self.horizontalLayout.setSpacing(2) - self.horizontalLayout.setMargin(0) - self.label = QtGui.QLabel() - self.label.setText('0 elements selected') - self.label.setSizePolicy(QtGui.QSizePolicy.Expanding, - QtGui.QSizePolicy.Expanding) - self.horizontalLayout.addWidget(self.label) - self.pushButton = QtGui.QPushButton() - self.pushButton.setText('...') - self.pushButton.clicked.connect(self.showSelectionDialog) - self.horizontalLayout.addWidget(self.pushButton) - self.setLayout(self.horizontalLayout) def setSelectedItems(self, selected): # No checking is performed! self.selectedoptions = selected - self.label.setText(str(len(self.selectedoptions)) - + ' elements selected') + self.leText.setText( + self.tr('%d elements selected') % len(self.selectedoptions)) def showSelectionDialog(self): - - dlg = MultipleInputDialog(self.options, self.selectedoptions) + if self.datatype is None: + dlg = MultipleInputDialog(self.options, self.selectedoptions) + else: + dlg = MultipleFileInputDialog(self.selectedoptions) dlg.exec_() if dlg.selectedoptions is not None: self.selectedoptions = dlg.selectedoptions - self.label.setText(str(len(self.selectedoptions)) - + ' elements selected') + self.leText.setText( + self.tr('%d elements selected') % len(self.selectedoptions)) diff --git a/python/plugins/processing/gui/ParametersPanel.py b/python/plugins/processing/gui/ParametersPanel.py index b197676b932..7eb2eeceb76 100644 --- a/python/plugins/processing/gui/ParametersPanel.py +++ b/python/plugins/processing/gui/ParametersPanel.py @@ -47,7 +47,6 @@ from processing.gui.NumberInputPanel import NumberInputPanel from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel from processing.gui.FileSelectionPanel import FileSelectionPanel from processing.gui.CrsSelectionPanel import CrsSelectionPanel -from processing.gui.MultipleFileInputPanel import MultipleFileInputPanel from processing.core.parameters import ParameterRaster from processing.core.parameters import ParameterVector from processing.core.parameters import ParameterTable @@ -294,7 +293,7 @@ class ParametersPanel(QWidget): item = FileSelectionPanel(param.isFolder, param.ext) elif isinstance(param, ParameterMultipleInput): if param.datatype == ParameterMultipleInput.TYPE_FILE: - item = MultipleFileInputPanel() + item = MultipleInputPanel(datatype=ParameterMultipleInput.TYPE_FILE) else: if param.datatype == ParameterMultipleInput.TYPE_RASTER: options = dataobjects.getRasterLayers(sorting=False) diff --git a/python/plugins/processing/gui/RenderingStyleFilePanel.py b/python/plugins/processing/gui/RenderingStyleFilePanel.py index eb87a98830f..cedc4f91f65 100644 --- a/python/plugins/processing/gui/RenderingStyleFilePanel.py +++ b/python/plugins/processing/gui/RenderingStyleFilePanel.py @@ -25,37 +25,35 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' -import os.path -from PyQt4 import QtGui, QtCore +from PyQt4.QtGui import * + from processing.core.ProcessingConfig import ProcessingConfig +from processing.tools.system import * + +from processing.ui.ui_widgetBaseSelector import Ui_Form -class RenderingStyleFilePanel(QtGui.QWidget): +class RenderingStyleFilePanel(QWidget, Ui_Form): def __init__(self): - super(RenderingStyleFilePanel, self).__init__(None) - self.horizontalLayout = QtGui.QHBoxLayout(self) - self.horizontalLayout.setSpacing(2) - self.horizontalLayout.setMargin(0) - self.text = QtGui.QLineEdit() - self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, - QtGui.QSizePolicy.Expanding) - self.horizontalLayout.addWidget(self.text) - self.pushButton = QtGui.QPushButton() - self.pushButton.setText('...') - self.pushButton.clicked.connect(self.showSelectionDialog) - self.horizontalLayout.addWidget(self.pushButton) - self.setLayout(self.horizontalLayout) + QWidget.__init__(self) + self.setupUi(self) + + self.btnSelect.clicked.connect(self.showSelectionDialog) + def showSelectionDialog(self): - filename = QtGui.QFileDialog.getOpenFileName(self, - self.tr('Select style file'), '', self.tr('QGIS Layer Style File (*.qml *.QML)')) + filename = QFileDialog.getOpenFileName(self, + self.tr('Select style file'), '', + self.tr('QGIS Layer Style File (*.qml *.QML)')) if filename: - self.text.setText(unicode(filename)) + self.leText.setText(filename) def setText(self, text): - self.text.setText(unicode(text)) + self.leText.setText(text) def getValue(self): - filename = unicode(self.text.text()) - return filename + s = self.leText.text() + if isWindows(): + s = s.replace('\\', '/') + return s