def setupUi(self): self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) self.layout.setMargin(0) self.layout.setObjectName(_fromUtf8("verticalLayout_3")) self.fields = QtGui.QVBoxLayout() self.fields.setObjectName(_fromUtf8("fields")) self.layout.addLayout(self.fields) spacerItem = QtGui.QSpacerItem( 0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.layout.addItem(spacerItem)
def __init__(self, parent=None, filter_=None): super(FileSelector, self).__init__(parent) self.filter = filter_ self.setupUi(self) self.connect( self.dialog, SIGNAL(_fromUtf8("clicked()")), self.open_dialog )
def prepare_edit(self, parent, field, value): widget = TextWidget(parent) try: if value is None: value = '' if not isinstance(value, (str, unicode)): value = unicode(value) widget.setText(_fromUtf8(value)) except Exception: widget.setText("Error") return widget
def prepare(self, parent, field, value): widget = QtGui.QLabel(parent) widget.setWordWrap(True) widget.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.TextSelectableByMouse) try: if not isinstance(value, (str, unicode)): value = unicode(value) widget.setText(_fromUtf8(value)) except Exception: widget.setText("Error") return widget
def prepare(self, parent, field, value): widget = super(FieldReferenceWidget, self).prepare( parent, field, value[1]) text = widget.text() uri = "collector://view/fitxa/item/%s/collection/%s" % ( value[0], field.ref_collection) widget.setText("<a href=\"%s\">%s</a>" % (uri, text)) widget.connect( widget, SIGNAL(_fromUtf8("linkActivated(QString)")), lambda s: MainWindow.instance.collector_uri_call(s)) return widget
def set_image(self, value, max_x=450, max_y=450, scale=True): """Changes the current image to the new one, and resizes the widget if the size is different. The allowed values for the *value* param. are: - File path (unicode) - http uri - QImage By default the image is scaled to 450x450px, you can override this behavior setting the *max_x* and *max_y* paramethers. If you don't want to scale the image, set to False the *scale* param. """ if scale: self.max_x = max_x self.max_y = max_y else: self.max_x = None self.max_y = None #FIXME allow parameter: default image default = self.default_src pixmap = None # Check image empty if value is None or value == '': value = default # The image is from network or is local file? if isinstance(value, unicode) and value.startswith('http'): # http uri (defered load) self.nam.get(QNetworkRequest(QUrl(value))) else: # Non url if isinstance(value, QtGui.QImage): # from QImage pixmap = QtGui.QPixmap() pixmap.convertFromImage(value) else: # from file pixmap = QtGui.QPixmap(value) # Check if the resulting pixmap is empty if pixmap.isNull(): # Load the default pixmap pixmap = QtGui.QPixmap(_fromUtf8(default)) # Scale the image if scale: pixmap = pixmap.scaled(max_x, max_y, Qt.KeepAspectRatio) # Set the widget pixmap self.setPixmap(pixmap) # And finally set pretty alignment self.setAlignment(Qt.AlignLeading | Qt.AlignHCenter | Qt.AlignTop) # Store the final value self.src = value
def __init__(self, widgetprovider, parent, field, values): super(MultivalueWidgetEdit, self).__init__(parent) self.widgetprovider = widgetprovider self.setupUi(self) self.widgets = [] self.field = field i = 0 for value in values: i += 1 self.add_value(value) if i == 0: self.add_value() self.connect( self.addValue, SIGNAL(_fromUtf8("clicked()")), self.add_value)
def http_image_complete(self, reply): """This function is called when the image has been loadded from the network""" pixmap = None if reply.error() == QNetworkReply.NoError: img = QtGui.QImage() img.loadFromData(reply.readAll()) pixmap = QtGui.QPixmap(img) else: logging.info("NETWORK failed to obtain image %s:", reply.errorString()) pixmap = QtGui.QPixmap(_fromUtf8(self.default_src)) if self.max_x is not None and self.max_y is not None: scaled = pixmap.scaled(self.max_x, self.max_y, Qt.KeepAspectRatio) del pixmap pixmap = scaled self.setPixmap(pixmap)