#!/usr/bin/env python
#-*- coding: UTF-8 -*-

from PyQt4 import QtCore, QtGui


class LineEditButton(QtGui.QWidget):

    clicked = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        layout = QtGui.QHBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)
        self.button = QtGui.QPushButton(parent=self)
        self.button.setText("...")
        self.button.setFlat(True)
        self.button.setFocusPolicy(QtCore.Qt.NoFocus)
        self.button.clicked.connect(self.clicked)
        self.edit = QtGui.QLineEdit(self)
        layout.addWidget(self.edit)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def __getattr__(self, attr):
        try:
            return getattr(self.edit, attr)
        except AttributeError:
            return getattr(self.button, attr)

    def placeholderText(self):
        return self.edit.placeholderText()

    def setPlaceholderText(self, text):
        self.edit.setPlaceholderText(text)

    def text(self):
        return self.edit.text()

    def setText(self, text):
        self.edit.setText(text)

    def icon(self):
        return self.button.icon()

    def setIcon(self, icon):
        self.button.setText("")
        self.button.setIcon(icon)

    placeholderText = QtCore.pyqtProperty("QString", placeholderText, setPlaceholderText)
    text = QtCore.pyqtProperty("QString", text, setText)
    icon = QtCore.pyqtProperty("QIcon", icon, setIcon)


if __name__ == "__main__":
    import sys

    def test():
        print 'clicked'

    app = QtGui.QApplication(sys.argv)
    w = LineEditButton()
    w.clicked.connect(test)
    w.show()
    sys.exit(app.exec_())
