Le 2014-02-28 18:37, Aaron Richiger a écrit :
> Hello Jerome!

Hi.
 
> Welcome in the PySide world... 

Thank you !

> Would it be possible, to send us the code 
> (source files). It's always great to run the code, a UI or a error 
> message often says more than many words...

I deliberately stripped the relevant parts in my former message, as the
rest might be confusing. Here are the files I'm running. This is just a
test, so don't be surprised to see stupid or hardcoded stuff.

-- 
Jérôme
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'dialogBuilding.ui'
#
# Created: Fri Feb 28 18:01:48 2014
#      by: pyside-uic 0.2.13 running on PySide 1.1.1
#
# WARNING! All changes made in this file will be lost!

from PySide import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 300)
        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.formLayoutWidget = QtGui.QWidget(Dialog)
        self.formLayoutWidget.setGeometry(QtCore.QRect(10, 20, 381, 191))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtGui.QFormLayout(self.formLayoutWidget)
        self.formLayout.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formLayout.setObjectName("formLayout")
        self.nameLabel = QtGui.QLabel(self.formLayoutWidget)
        self.nameLabel.setObjectName("nameLabel")
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.nameLabel)
        self.nameLineEdit = QtGui.QLineEdit(self.formLayoutWidget)
        self.nameLineEdit.setObjectName("nameLineEdit")
        self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.nameLineEdit)
        self.surfaceLabel = QtGui.QLabel(self.formLayoutWidget)
        self.surfaceLabel.setObjectName("surfaceLabel")
        self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.surfaceLabel)
        self.floorsLabel = QtGui.QLabel(self.formLayoutWidget)
        self.floorsLabel.setObjectName("floorsLabel")
        self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.floorsLabel)
        self.occupDLabellabel_4 = QtGui.QLabel(self.formLayoutWidget)
        self.occupDLabellabel_4.setObjectName("occupDLabellabel_4")
        self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.occupDLabellabel_4)
        self.occupWLabel = QtGui.QLabel(self.formLayoutWidget)
        self.occupWLabel.setObjectName("occupWLabel")
        self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.occupWLabel)
        self.sufraceSpinBox = QtGui.QSpinBox(self.formLayoutWidget)
        self.sufraceSpinBox.setObjectName("sufraceSpinBox")
        self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.sufraceSpinBox)
        self.spinBox_2 = QtGui.QSpinBox(self.formLayoutWidget)
        self.spinBox_2.setObjectName("spinBox_2")
        self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.spinBox_2)
        self.spinBox_3 = QtGui.QSpinBox(self.formLayoutWidget)
        self.spinBox_3.setObjectName("spinBox_3")
        self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.spinBox_3)
        self.spinBox_4 = QtGui.QSpinBox(self.formLayoutWidget)
        self.spinBox_4.setObjectName("spinBox_4")
        self.formLayout.setWidget(4, QtGui.QFormLayout.FieldRole, self.spinBox_4)

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

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.nameLabel.setText(QtGui.QApplication.translate("Dialog", "Name", None, QtGui.QApplication.UnicodeUTF8))
        self.surfaceLabel.setText(QtGui.QApplication.translate("Dialog", "Surface area", None, QtGui.QApplication.UnicodeUTF8))
        self.floorsLabel.setText(QtGui.QApplication.translate("Dialog", "Floors", None, QtGui.QApplication.UnicodeUTF8))
        self.occupDLabellabel_4.setText(QtGui.QApplication.translate("Dialog", "Occupancy d/w", None, QtGui.QApplication.UnicodeUTF8))
        self.occupWLabel.setText(QtGui.QApplication.translate("Dialog", "Occupancy w/y", None, QtGui.QApplication.UnicodeUTF8))

Attachment: dialogBuilding.ui
Description: XML document

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created: Fri Feb 28 18:01:48 2014
#      by: pyside-uic 0.2.13 running on PySide 1.1.1
#
# WARNING! All changes made in this file will be lost!

from PySide import QtCore, QtGui

class Ui_mainwindow(object):
    def setupUi(self, mainwindow):
        mainwindow.setObjectName("mainwindow")
        mainwindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(mainwindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayoutWidget_2 = QtGui.QWidget(self.centralwidget)
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 30, 761, 191))
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
        self.verticalLayout_3 = QtGui.QVBoxLayout(self.verticalLayoutWidget_2)
        self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.nameLineEdit = QtGui.QLineEdit(self.verticalLayoutWidget_2)
        self.nameLineEdit.setObjectName("nameLineEdit")
        self.horizontalLayout_2.addWidget(self.nameLineEdit)
        self.editNamePushButton = QtGui.QPushButton(self.verticalLayoutWidget_2)
        self.editNamePushButton.setObjectName("editNamePushButton")
        self.horizontalLayout_2.addWidget(self.editNamePushButton)
        self.verticalLayout_3.addLayout(self.horizontalLayout_2)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.buildingsTableView = QtGui.QTableView(self.verticalLayoutWidget_2)
        self.buildingsTableView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
        self.buildingsTableView.setObjectName("buildingsTableView")
        self.buildingsTableView.verticalHeader().setVisible(False)
        self.horizontalLayout.addWidget(self.buildingsTableView)
        self.verticalLayout_2 = QtGui.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.addPushButton = QtGui.QPushButton(self.verticalLayoutWidget_2)
        self.addPushButton.setObjectName("addPushButton")
        self.verticalLayout_2.addWidget(self.addPushButton)
        self.editPushButton = QtGui.QPushButton(self.verticalLayoutWidget_2)
        self.editPushButton.setObjectName("editPushButton")
        self.verticalLayout_2.addWidget(self.editPushButton)
        self.removePushButton = QtGui.QPushButton(self.verticalLayoutWidget_2)
        self.removePushButton.setObjectName("removePushButton")
        self.verticalLayout_2.addWidget(self.removePushButton)
        self.horizontalLayout.addLayout(self.verticalLayout_2)
        self.verticalLayout_3.addLayout(self.horizontalLayout)
        mainwindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(mainwindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25))
        self.menubar.setObjectName("menubar")
        mainwindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(mainwindow)
        self.statusbar.setObjectName("statusbar")
        mainwindow.setStatusBar(self.statusbar)

        self.retranslateUi(mainwindow)
        QtCore.QMetaObject.connectSlotsByName(mainwindow)

    def retranslateUi(self, mainwindow):
        mainwindow.setWindowTitle(QtGui.QApplication.translate("mainwindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.editNamePushButton.setText(QtGui.QApplication.translate("mainwindow", "Edit name", None, QtGui.QApplication.UnicodeUTF8))
        self.addPushButton.setText(QtGui.QApplication.translate("mainwindow", "Add", None, QtGui.QApplication.UnicodeUTF8))
        self.editPushButton.setText(QtGui.QApplication.translate("mainwindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
        self.removePushButton.setText(QtGui.QApplication.translate("mainwindow", "Remove", None, QtGui.QApplication.UnicodeUTF8))

Attachment: mainwindow.ui
Description: XML document

from PySide import QtCore, QtGui
import dialogBuilding

class building(QtCore.QObject):
    
    def __init__(self, name, surf, nb_floors, occ_w, occ_y):
        #super(building, self).__init__(None)
        QtCore.QObject.__init__(self)
        self.name = name
        self.surf = surf
        self.nb_floors = nb_floors
        self.occ_w = occ_w
        self.occ_y = occ_y


class buildingDialog(QtGui.QDialog):

    def __init__(self, parent=None):
        super(buildingDialog, self).__init__(parent)
        self.ui = dialogBuilding.Ui_Dialog()
        self.ui.setupUi(self)

        # http://stackoverflow.com/questions/17433044/cant-seem-to-call-a-custom-dialog-from-the-mainwindow-pyside
        # http://www.blog.pythonlibrary.org/2013/04/16/pyside-standard-dialogs-and-message-boxes/


import sys

from PySide import QtCore, QtGui

# Generate and import UIs
from subprocess import call
call(["pyside-uic", "mainwindow.ui", "-omainwindow.py"])
call(["pyside-uic", "dialogBuilding.ui", "-odialogBuilding.py"])
import mainwindow

#import generator as gen
import building as bui

class buildingSurvey(QtGui.QMainWindow):
    
    def __init__(self, parent=None):
        super(buildingSurvey, self).__init__(parent)
        self.ui = mainwindow.Ui_mainwindow()
        self.ui.setupUi(self)

        # Name
        self.name = "Dummy name"
        self.ui.nameLineEdit.setText(self.name)

        # Buildings model
        self.buildingsModel = QtGui.QStandardItemModel()
        self.buildingsModel.setHorizontalHeaderLabels(['Name', 'Surf', 'Floors', 'Occ W', 'Occ Y'])
        self.ui.buildingsTableView.setModel(self.buildingsModel)
        #self.ui.buildingsTableView.horizontalHeader().setStretchLastSection(True)
        #self.ui.buildingsTableView.resizeColumnsToContents()

        # Test : hide a column
        # self.ui.buildingsTableView.setColumnHidden(0, True)
 
        # Buildings list
        self.buildings = []
        self.add_building('Bat 1', '1069', '3', '5', '48')
        self.add_building('Bat 2', '500', '2', '5', '48')

        # Signals / slots connections
        self.ui.removePushButton.clicked.connect(self.removePushButtonClicked)
        self.ui.addPushButton.clicked.connect(self.addPushButtonClicked)
     
    def add_building(self, name, surf, nb_floors, occ_w, occ_y):

        self.buildings.append(bui.building(name, surf, nb_floors, occ_w, occ_y))
        self.buildingsModel.appendRow([QtGui.QStandardItem(i) for i in [name, surf, nb_floors, occ_w, occ_y]])
        #self.ui.buildingsTableView.resizeColumnsToContents()

    def rem_building(self, index):

        self.buildingsModel.removeRow(index)
        del(self.buildings[index])
   
    def removePushButtonClicked(self):

        selected = self.ui.buildingsTableView.selectedIndexes()
        if selected != []:
            self.rem_building(selected[0].row())


    def addPushButtonClicked(self):

        dialog = bui.buildingDialog(self)
        print(dialog.exec_())


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    mySW = buildingSurvey()
    mySW.show()
    sys.exit(app.exec_())

_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to