[pyar] Ubicar widget en un MDI

Fernando Gonzalez fagonzalez en steel.com.ar
Lun Sep 3 09:59:15 ART 2012


El 03/09/2012 09:40, Roberto Alsina escribió:
> On 09/03/2012 09:23 AM, Fernando Gonzalez wrote:
>>
>> este código lo levante de las páginas de trolltech, andan todas las
>> funciones, de hecho el formulario no puede achicarse por debajo de los
>> valores fijados en el código, pero no se posiciona donde quiero. La
>> pregunta es si alguien conoce alguna variante para posicionar el widget
>> cuando se presenta en la pantalla. Desde ya muchas gracias
>
> Es muy difícil poder saber qué es lo que pasa con un fragmento de código
> que no podemos usar :-)
>
> En general, lo que deberías hacer es simplemente moverlo, PERO eso no
> alcanza si estás usando, por ejemplo, un layout manager, o si hacés
> reparenting del widget.
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
>
>
te paso el código completo, (ja no es tan grande), primero te paso el 
código que genera el pyuic4

> # -*- coding: utf-8 -*-
>
> # Form implementation generated from reading ui file 'frmCliente.ui'
> #
> # Created: Thu Jul 26 16:18:02 2012
> #      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_frmCliente(object):
>     def setupUi(self, frmCliente):
>         frmCliente.setObjectName(_fromUtf8("frmCliente"))
>         frmCliente.resize(465, 231)
>         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
>                                        QtGui.QSizePolicy.Fixed)
>         sizePolicy.setHorizontalStretch(0)
>         sizePolicy.setVerticalStretch(0)
>         sizePolicy.setHeightForWidth(frmCliente.sizePolicy().
>                                      hasHeightForWidth())
>         frmCliente.setSizePolicy(sizePolicy)
>         palette = QtGui.QPalette()
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.WindowText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(170, 170, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 191))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 159))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 84))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 170, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.BrightText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.ButtonText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.AlternateBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.ToolTipBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Active,
>                          QtGui.QPalette.ToolTipText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.WindowText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 191))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 159))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.Midlight, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 84))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.BrightText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.ButtonText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.AlternateBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.ToolTipBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Inactive,
>                          QtGui.QPalette.ToolTipText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.WindowText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 191))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 159))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.Midlight, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 63))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 84))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush)
>         brush = QtGui.QBrush(QtGui.QColor(113, 113, 113))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.BrightText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.ButtonText, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.AlternateBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.ToolTipBase, brush)
>         brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
>         brush.setStyle(QtCore.Qt.SolidPattern)
>         palette.setBrush(QtGui.QPalette.Disabled,
>                          QtGui.QPalette.ToolTipText, brush)
>         frmCliente.setPalette(palette)
>         self.layoutWidget = QtGui.QWidget(frmCliente)
>         self.layoutWidget.setGeometry(QtCore.QRect(10, 10, 455, 178))
>         self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
>         self.gridLayout = QtGui.QGridLayout(self.layoutWidget)
>         self.gridLayout.setMargin(0)
>         self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
>         self.label = QtGui.QLabel(self.layoutWidget)
>         self.label.setStatusTip(_fromUtf8(""))
>         self.label.setObjectName(_fromUtf8("label"))
>         self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
>         self.label_2 = QtGui.QLabel(self.layoutWidget)
>         self.label_2.setStatusTip(_fromUtf8(""))
>         self.label_2.setObjectName(_fromUtf8("label_2"))
>         self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
>         self.txtNombre = QtGui.QLineEdit(self.layoutWidget)
>         self.txtNombre.setStatusTip(_fromUtf8(""))
>         self.txtNombre.setObjectName(_fromUtf8("txtNombre"))
>         self.gridLayout.addWidget(self.txtNombre, 1, 1, 1, 4)
>         self.label_3 = QtGui.QLabel(self.layoutWidget)
>         self.label_3.setStatusTip(_fromUtf8(""))
>         self.label_3.setObjectName(_fromUtf8("label_3"))
>         self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
>         self.txtDireccion = QtGui.QLineEdit(self.layoutWidget)
>         self.txtDireccion.setStatusTip(_fromUtf8(""))
>         self.txtDireccion.setObjectName(_fromUtf8("txtDireccion"))
>         self.gridLayout.addWidget(self.txtDireccion, 2, 1, 1, 4)
>         self.label_4 = QtGui.QLabel(self.layoutWidget)
>         self.label_4.setStatusTip(_fromUtf8(""))
>         self.label_4.setObjectName(_fromUtf8("label_4"))
>         self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
>         self.label_5 = QtGui.QLabel(self.layoutWidget)
>         self.label_5.setStatusTip(_fromUtf8(""))
>         self.label_5.setObjectName(_fromUtf8("label_5"))
>         self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1)
>         self.txtLocalidad = QtGui.QLineEdit(self.layoutWidget)
>         self.txtLocalidad.setStatusTip(_fromUtf8(""))
>         self.txtLocalidad.setObjectName(_fromUtf8("txtLocalidad"))
>         self.gridLayout.addWidget(self.txtLocalidad, 4, 1, 1, 3)
>         spacerItem = QtGui.QSpacerItem(148, 20, QtGui.QSizePolicy.Expanding,
>                                        QtGui.QSizePolicy.Minimum)
>         self.gridLayout.addItem(spacerItem, 4, 4, 1, 1)
>         self.label_6 = QtGui.QLabel(self.layoutWidget)
>         self.label_6.setStatusTip(_fromUtf8(""))
>         self.label_6.setObjectName(_fromUtf8("label_6"))
>         self.gridLayout.addWidget(self.label_6, 5, 0, 1, 1)
>         self.cmbIVA = QtGui.QComboBox(self.layoutWidget)
>         self.cmbIVA.setStatusTip(_fromUtf8(""))
>         self.cmbIVA.setObjectName(_fromUtf8("cmbIVA"))
>         self.cmbIVA.addItem(_fromUtf8(""))
>         self.cmbIVA.setItemText(0, _fromUtf8("Consumidor Final"))
>         self.cmbIVA.addItem(_fromUtf8(""))
>         self.cmbIVA.setItemText(1, _fromUtf8("Exento"))
>         self.cmbIVA.addItem(_fromUtf8(""))
>         self.cmbIVA.setItemText(2, _fromUtf8("Monotributo"))
>         self.cmbIVA.addItem(_fromUtf8(""))
>         self.cmbIVA.setItemText(3, _fromUtf8("Resp. Inscripto"))
>         self.gridLayout.addWidget(self.cmbIVA, 5, 1, 1, 2)
>         spacerItem1 = QtGui.QSpacerItem(228, 20, QtGui.QSizePolicy.Expanding,
>                                         QtGui.QSizePolicy.Minimum)
>         self.gridLayout.addItem(spacerItem1, 5, 3, 1, 2)
>         self.label_7 = QtGui.QLabel(self.layoutWidget)
>         self.label_7.setStatusTip(_fromUtf8(""))
>         self.label_7.setObjectName(_fromUtf8("label_7"))
>         self.gridLayout.addWidget(self.label_7, 6, 0, 1, 1)
>         self.txtNCUIT = QtGui.QLineEdit(self.layoutWidget)
>         self.txtNCUIT.setStatusTip(_fromUtf8(""))
>         self.txtNCUIT.setObjectName(_fromUtf8("txtNCUIT"))
>         self.gridLayout.addWidget(self.txtNCUIT, 6, 1, 1, 2)
>         spacerItem2 = QtGui.QSpacerItem(228, 20, QtGui.QSizePolicy.Expanding,
>                                         QtGui.QSizePolicy.Minimum)
>         self.gridLayout.addItem(spacerItem2, 6, 3, 1, 2)
>         self.txtTelefono = QtGui.QLineEdit(self.layoutWidget)
>         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
>                                        QtGui.QSizePolicy.Fixed)
>         sizePolicy.setHorizontalStretch(0)
>         sizePolicy.setVerticalStretch(0)
>         sizePolicy.setHeightForWidth(self.txtTelefono.
>                                      sizePolicy().hasHeightForWidth())
>         self.txtTelefono.setSizePolicy(sizePolicy)
>         self.txtTelefono.setStatusTip(_fromUtf8(""))
>         self.txtTelefono.setObjectName(_fromUtf8("txtTelefono"))
>         self.gridLayout.addWidget(self.txtTelefono, 3, 1, 1, 3)
>         self.txtNCuenta = QtGui.QLineEdit(self.layoutWidget)
>         self.txtNCuenta.setStatusTip(_fromUtf8(""))
>         self.txtNCuenta.setObjectName(_fromUtf8("txtNCuenta"))
>         self.gridLayout.addWidget(self.txtNCuenta, 0, 1, 1, 2)
>         spacerItem3 = QtGui.QSpacerItem(258, 20, QtGui.QSizePolicy.Expanding,
>                                         QtGui.QSizePolicy.Minimum)
>         self.gridLayout.addItem(spacerItem3, 0, 3, 1, 2)
>         self.layoutWidget1 = QtGui.QWidget(frmCliente)
>         self.layoutWidget1.setGeometry(QtCore.QRect(10, 200, 451, 25))
>         self.layoutWidget1.setObjectName(_fromUtf8("layoutWidget1"))
>         self.horizontalLayout = QtGui.QHBoxLayout(self.layoutWidget1)
>         self.horizontalLayout.setMargin(0)
>         self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
>         self.cmdNuevo = QtGui.QPushButton(self.layoutWidget1)
>         self.cmdNuevo.setObjectName(_fromUtf8("cmdNuevo"))
>         self.horizontalLayout.addWidget(self.cmdNuevo)
>         self.cmdBusca = QtGui.QPushButton(self.layoutWidget1)
>         self.cmdBusca.setObjectName(_fromUtf8("cmdBusca"))
>         self.horizontalLayout.addWidget(self.cmdBusca)
>         self.cmdGraba = QtGui.QPushButton(self.layoutWidget1)
>         self.cmdGraba.setObjectName(_fromUtf8("cmdGraba"))
>         self.horizontalLayout.addWidget(self.cmdGraba)
>         self.cmdBorra = QtGui.QPushButton(self.layoutWidget1)
>         self.cmdBorra.setObjectName(_fromUtf8("cmdBorra"))
>         self.horizontalLayout.addWidget(self.cmdBorra)
>         self.label.setBuddy(self.txtNCuenta)
>         self.label_2.setBuddy(self.txtNombre)
>         self.label_3.setBuddy(self.txtDireccion)
>         self.label_4.setBuddy(self.txtTelefono)
>         self.label_5.setBuddy(self.txtLocalidad)
>         self.label_6.setBuddy(self.cmbIVA)
>         self.label_7.setBuddy(self.txtNCUIT)
>
>         self.retranslateUi(frmCliente)
>         QtCore.QMetaObject.connectSlotsByName(frmCliente)
>         frmCliente.setTabOrder(self.txtNCuenta, self.txtNombre)
>         frmCliente.setTabOrder(self.txtNombre, self.txtDireccion)
>         frmCliente.setTabOrder(self.txtDireccion, self.txtTelefono)
>         frmCliente.setTabOrder(self.txtTelefono, self.txtLocalidad)
>         frmCliente.setTabOrder(self.txtLocalidad, self.cmbIVA)
>         frmCliente.setTabOrder(self.cmbIVA, self.txtNCUIT)
>         frmCliente.setTabOrder(self.txtNCUIT, self.cmdNuevo)
>         frmCliente.setTabOrder(self.cmdNuevo, self.cmdBusca)
>         frmCliente.setTabOrder(self.cmdBusca, self.cmdGraba)
>         frmCliente.setTabOrder(self.cmdGraba, self.cmdBorra)
>
>     def retranslateUi(self, frmCliente):
>         frmCliente.setWindowTitle(QtGui.QApplication.translate("frmCliente",
>                    "Dialog", None, QtGui.QApplication.UnicodeUTF8))
>         self.label.setText(QtGui.QApplication.translate("frmCliente",
>                    "Nº &Cuenta", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_2.setText(QtGui.QApplication.translate("frmCliente",
>                    "&Nombre", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_3.setText(QtGui.QApplication.translate("frmCliente",
>                    "&Dirección", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_4.setText(QtGui.QApplication.translate("frmCliente",
>                    "&Teléfono", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_5.setText(QtGui.QApplication.translate("frmCliente",
>                    "&Localidad", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_6.setText(QtGui.QApplication.translate("frmCliente",
>                    "Cond. &IVA", None, QtGui.QApplication.UnicodeUTF8))
>         self.label_7.setText(QtGui.QApplication.translate("frmCliente",
>                    "Nº C&UIT", None, QtGui.QApplication.UnicodeUTF8))
>         self.cmdNuevo.setText(QtGui.QApplication.translate("frmCliente",
>                    "&Nuevo", None, QtGui.QApplication.UnicodeUTF8))
>         self.cmdBusca.setText(QtGui.QApplication.translate("frmCliente",
>                    "Busca", None, QtGui.QApplication.UnicodeUTF8))
>         self.cmdGraba.setText(QtGui.QApplication.translate("frmCliente",
>                    "Graba", None, QtGui.QApplication.UnicodeUTF8))
>         self.cmdBorra.setText(QtGui.QApplication.translate("frmCliente",
>                    "Borra", None, QtGui.QApplication.UnicodeUTF8))

y a continuación la clase que lo despliega en el MDI:

> from PyQt4 import QtGui, QtCore
> import frmArticulo
> import ctrlBuscarArt
> import MySQLdb
> from easygui import *
> from general import *
>
>
> try:
>     _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
>     _fromUtf8 = lambda s: s
>
> """
> codigo sql para crear la tabla articulos
>
> DROP TABLE IF EXISTS `Sistema`.`tblArticulos`;
> CREATE TABLE  `Sistema`.`tblArticulos` (
>   `Articulos_Id` int(10) unsigned NOT NULL,
>   `Articulos_Descrip` varchar(100) NOT NULL,
>   `Articulos_Rubro` int(10) unsigned NOT NULL,
>   `Articulos_PrecioVenta` float NOT NULL DEFAULT '0',
>   `Articulos_PrecioCompra` float NOT NULL DEFAULT '0'
>   COMMENT 'precio de la ultima compra',
>   PRIMARY KEY (`Articulos_Id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
>
> """
>
>
> class fichaArticulo(QtGui.QWidget, frmArticulo.Ui_Form):
>
>     Modo = "A"
>     X = 0
>     Y = 0
>     wL = 0
>     mydb = MySQLdb.connection(host="190.5.0.142", user="root",
>                               passwd="raroca", db="Sistema")
>
>     def __init__(self, parent=None):
>         super(fichaArticulo, self).__init__(parent)
>         self.setupUi(self)
>
>         self.cmdNuevo.clicked.connect(self.Nuevo)
>         self.connect(self.cmdGraba, QtCore.SIGNAL("clicked()"), self.Graba)
>         self.connect(self.cmdBorra, QtCore.SIGNAL("clicked()"), self.Borra)
>         self.connect(self.cmdBusca, QtCore.SIGNAL("clicked()"), self.Busca)
>         self.connect(self.txtID, QtCore.SIGNAL("returnPressed()"),
>                      self.BuscaNCuenta)
>         self.setWindowTitle("Carpeta de articulos - ALTAS*BAJAS*EDICION")
>         self.cBCli = ctrlBuscarArt.ctrlBArticulos()
>         self.cmdNuevo.setAutoDefault(False)
>         self.cmdGraba.setAutoDefault(False)
>         self.cmdBorra.setAutoDefault(False)
>         self.cmdBusca.setAutoDefault(False)
>         self.cBCli.connect(self.cBCli,
>                            QtCore.SIGNAL("datovalido"),
>                            self.datoValido)
>         self.cBCli.connect(self.cBCli,
>                            QtCore.SIGNAL("cancela"),
>                            self.cierrabusqueda)
>         self.cmdGraba.setEnabled(False)
>         self.cmdBorra.setEnabled(False)
>         #abro la base de datos
>
>         self.PosicionaForm()
>
>     def BuscaNCuenta(self):
>         NC = str(self.txtNCuenta.text())
>         if (NC != ""):
>             #print str(NC)
>             self.datoValido(NC)
>         else:
>             msgbox("Debe ingresar un numero de cuenta")
>
>     def cierrabusqueda(self):
>         self.cBCli.hide()
>
>     def Nuevo(self):
>         self.Limpia()
>         self.cmdBorra.setEnabled(False)
>         self.cmdBusca.setEnabled(False)
>         self.cmdGraba.setEnabled(True)
>         self.BuscaNuevoNCuenta()
>         self.Modo = "A"
>
>     def Graba(self):
>         if (self.Modo == "A"):
>             if (self.ValidoDatosFormulario()):
>                 if (boolbox
>                    ('Seguro graba este registro en la base de datos')):
>                     self.InsertaNuevo()
>                     self.Limpia()
>             else:
>                 msgbox('No estan todos los datos requeridos')
>         elif (self.Modo == "E"):
>             self.ActualizaRegistro()
>             self.Limpia()
>
>     def PosicionaForm(self):
>         StrSQL = "SELECT * FROM tblSetupGUI "
>         StrSQL = StrSQL + "WHERE SetupGUI_ventan = 'frmCliente'"
>         self.mydb.query(StrSQL)
>         r = self.mydb.store_result()
>         cli = r.fetch_row(1)
>         self.X = int(cli[0][2])
>         self.Y = int(cli[0][3])
>         #self.setGeometry(X, Y, 554, 271)
>         self.setMinimumWidth(554)
>         self.setMinimumHeight(271)
>         self.move(self.X, self.Y)
>         print str(self.X) + '   ' + str(self.Y)
>
>     def Borra(self):
>         resp = boolbox("Seguro borra este registro?")
>         if (resp == 1):
>             ID = int(self.txtNCuenta.text())
>             StrSQL = "DELETE FROM tblArticulos WHERE Articulos_Id = %d" % (ID)
>             self.mydb.query(StrSQL)
>             self.Limpia()
>
>     def Busca(self):
>         self.cBCli.show()
>         self.cBCli.Busca(self.txtDescrip.text())
>         self.Modo = "E"
>
>     def datoValido(self, Id):
>         self.cBCli.hide()
>         #busco el cliente en la base de datos
>         self.mydb.query("SELECT * FROM tblArticulos WHERE Articulos_Id = "
>                         + str(Id))
>         r = self.mydb.store_result()
>         cli = r.fetch_row(1)
>         #lo muestro
>         self.txtID.setText(str(cli[0][0]))
>         self.txtDescrip.setText(str(cli[0][1]))
>         self.cmbRubro.setCurrentIndex(int(cli[0][2]))
>         self.txtPV.setText(str(cli[0][3]))
>         self.txtPC.setText(str(cli[0][4]))
>         self.txtID.setReadOnly(True)
>         self.cmdGraba.setEnabled(True)
>         self.cmdBorra.setEnabled(True)
>
>     def Limpia(self):
>         #borro el contenido de todos los textbox
>         self.txtID.setText("")
>         self.txtDescrip.setText("")
>         self.txtPC.setText("")
>         self.txtPV.setText("")
>         #acomodo los botones
>         self.cmdNuevo.setEnabled(True)
>         self.cmdBusca.setEnabled(True)
>         self.cmdGraba.setEnabled(False)
>         self.cmdBorra.setEnabled(False)
>
>     def BuscaNuevoNCuenta(self):
>         try:
>             #busco el ultimo registro actual
>             self.mydb.query("SELECT Articulos_Id FROM tblArticulos ORDER BY" +
>                         " Articulos_id DESC LIMIT 1")
>             r = self.mydb.store_result()
>             cli = r.fetch_row(1)
>             nc = int(cli[0][0])
>             #le sumo uno
>             nc += 1
>         except:
>             #no hay clientes, agrego el cliente n 1
>             nc = 1
>         #lo ofresco como siguiente numero de cliente
>         self.txtID.setText(str(nc))
>         self.txtDescrip.setFocus()
>
>     def ValidoDatosFormulario(self):
>         return ((self.txtDescrip.text() != "") and
>                 (self.txtPV.text() != ""))
>
>     def InsertaNuevo(self):
>         CatFiscal = 0
>         StrSQL = "INSERT INTO tblArticulos (Articulos_Id , Articulos_Descrip, "
>         StrSQL = StrSQL + "Articulos_PrecioVenta, Articulos_PrecioCompra, "
>         StrSQL = StrSQL + "Articulos_Rubro) "
>         StrSQL = StrSQL + "VALUES ('%s', '%s', '%s', '%s', '%s')"
>         StrSQL = StrSQL % (self.txtID.text(), self.txtDescrip.text(),
>                            self.txtPV.text(), self.txtPC.text(),
>                            CatFiscal)
>         self.mydb.query(StrSQL)
>
>     def ActualizaRegistro(self):
>         NCuenta = int(self.txtID.text())
>         CF = int(self.cmbRubro.currentIndex())
>         StrSQL = "UPDATE tblArticulos SET Articulos_Descrip = '%s', "
>         StrSQL = StrSQL + "Articulos_PrecioVenta = '%s', "
>         StrSQL = StrSQL + "Articulos_PrecioCompra = '%s', "
>         StrSQL = StrSQL + "Articulos_Rubro = '%d' WHERE "
>         StrSQL = StrSQL + "Articulos_Id = %d "
>         #print str(CF) + "  " + str(NCuenta)
>         StrSQL = StrSQL % (self.txtDescrip.text(),
>                           self.txtPV.text(), self.txtPV.text(),
>                           CF, NCuenta)
>         self.mydb.query(StrSQL)

No creo estar haciendo el reparenting, pero hay cosas que todavía se 
escapan a mi comprensión.

Desde ya muchas gracias.

Un abrazo

Fer




More information about the pyar mailing list