Skip to content
Permalink
Browse files

[processing] use QtDesigner .ui for Multiple selection dialog

  • Loading branch information
alexbruy committed Oct 2, 2013
1 parent 96eae1f commit a763e28ea5ae4e0271e76ba216d738cb23b89bb4
@@ -44,7 +44,6 @@ def __init__(self, alg):

self.alg = alg

self.setModal(True)
self.tblStyles.horizontalHeader().setResizeMode(QHeaderView.Stretch)
self.setWindowTitle(self.alg.name)

@@ -79,13 +78,13 @@ def setTableContent(self):
self.tblStyles.setRowHeight(i, 22)
i += 1

def accepted(self):
def accept(self):
styles = {}
for key in self.valueItems.keys():
styles[key] = str(self.valueItems[key].getValue())
RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles)

QDialog.accept(self)

def rejected(self):
def reject(self):
QDialog.reject(self)
@@ -25,81 +25,58 @@

__revision__ = '$Format:%H$'

from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from processing.ui.ui_DlgMultipleSelection import Ui_DlgMultipleSelection

class MultipleInputDialog(QtGui.QDialog):

def __init__(self, options, selectedoptions):
class MultipleInputDialog(QDialog, Ui_DlgMultipleSelection):

def __init__(self, options, selectedoptions=None):
QDialog.__init__(self)
self.setupUi(self)

self.options = options
self.selectedoptions = selectedoptions
QtGui.QDialog.__init__(self)
self.setModal(True)
self.setupUi()
self.selectedoptions = None

def setupUi(self):
self.resize(381, 320)
self.setWindowTitle('Multiple selection')
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Vertical)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel
| QtGui.QDialogButtonBox.Ok)
self.table = QtGui.QTableWidget()
self.table.setColumnCount(1)
self.table.setColumnWidth(0, 270)
self.table.verticalHeader().setVisible(False)
self.table.horizontalHeader().setVisible(False)
self.table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.selectAllButton = QtGui.QPushButton()
self.selectAllButton.setText('(de)Select all')
# Additional buttons
self.btnSelectAll = QPushButton(self.tr('(de)Select all'))
self.buttonBox.addButton(self.btnSelectAll,
QDialogButtonBox.ActionRole)

self.btnSelectAll.clicked.connect(self.toggleSelection)

self.setTableContent()
self.buttonBox.addButton(self.selectAllButton,
QtGui.QDialogButtonBox.ActionRole)
self.horizontalLayout.addWidget(self.table)
self.horizontalLayout.addWidget(self.buttonBox)
self.setLayout(self.horizontalLayout)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL('accepted()'),
self.okPressed)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL('rejected()'),
self.cancelPressed)
QtCore.QObject.connect(self.selectAllButton, QtCore.SIGNAL('clicked()'
), self.selectAll)
QtCore.QMetaObject.connectSlotsByName(self)

def setTableContent(self):
self.table.setRowCount(len(self.options))
self.tblLayers.setRowCount(len(self.options))
for i in range(len(self.options)):
item = QtGui.QCheckBox()
item = QCheckBox()
item.setText(self.options[i])
if i in self.selectedoptions:
item.setChecked(True)
self.table.setCellWidget(i, 0, item)
self.tblLayers.setCellWidget(i, 0, item)

def okPressed(self):
def accept(self):
self.selectedoptions = []
for i in range(len(self.options)):
widget = self.table.cellWidget(i, 0)
widget = self.tblLayers.cellWidget(i, 0)
if widget.isChecked():
self.selectedoptions.append(i)
self.close()
QDialog.accept(self)

def cancelPressed(self):
def reject(self):
self.selectedoptions = None
self.close()
QDialog.reject(self)

def selectAll(self):
def toggleSelection(self):
checked = False
for i in range(len(self.options)):
widget = self.table.cellWidget(i, 0)
widget = self.tblLayers.cellWidget(i, 0)
if not widget.isChecked():
checked = True
break
for i in range(len(self.options)):
widget = self.table.cellWidget(i, 0)
widget = self.tblLayers.cellWidget(i, 0)
widget.setChecked(checked)
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgMultipleSelection</class>
<widget class="QDialog" name="DlgMultipleSelection">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>Multiple selection</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTableWidget" name="tblLayers">
<property name="columnCount">
<number>1</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgMultipleSelection</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>DlgMultipleSelection</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>
</ui>
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'python/plugins/processing/ui/DlgMultipleSelection.ui'
#
# Created: Wed Oct 2 20:04:27 2013
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_DlgMultipleSelection(object):
def setupUi(self, DlgMultipleSelection):
DlgMultipleSelection.setObjectName(_fromUtf8("DlgMultipleSelection"))
DlgMultipleSelection.resize(380, 320)
self.horizontalLayout = QtGui.QHBoxLayout(DlgMultipleSelection)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.tblLayers = QtGui.QTableWidget(DlgMultipleSelection)
self.tblLayers.setColumnCount(1)
self.tblLayers.setObjectName(_fromUtf8("tblLayers"))
self.tblLayers.setRowCount(0)
self.tblLayers.horizontalHeader().setVisible(False)
self.tblLayers.horizontalHeader().setStretchLastSection(True)
self.tblLayers.verticalHeader().setVisible(False)
self.horizontalLayout.addWidget(self.tblLayers)
self.buttonBox = QtGui.QDialogButtonBox(DlgMultipleSelection)
self.buttonBox.setOrientation(QtCore.Qt.Vertical)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.horizontalLayout.addWidget(self.buttonBox)

self.retranslateUi(DlgMultipleSelection)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), DlgMultipleSelection.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), DlgMultipleSelection.reject)
QtCore.QMetaObject.connectSlotsByName(DlgMultipleSelection)

def retranslateUi(self, DlgMultipleSelection):
DlgMultipleSelection.setWindowTitle(QtGui.QApplication.translate("DlgMultipleSelection", "Multiple selection", None, QtGui.QApplication.UnicodeUTF8))

0 comments on commit a763e28

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