Package Camelot :: Package camelot :: Package view :: Package controls :: Module search |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.search

      1  #  ============================================================================
      2  #
      3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.
      4  #  www.conceptive.be / project-camelot@conceptive.be
      5  #
      6  #  This file is part of the Camelot Library.
      7  #
      8  #  This file may be used under the terms of the GNU General Public
      9  #  License version 2.0 as published by the Free Software Foundation
     10  #  and appearing in the file LICENSE.GPL included in the packaging of
     11  #  this file.  Please review the following information to ensure GNU
     12  #  General Public Licensing requirements will be met:
     13  #  http://www.trolltech.com/products/qt/opensource.html
     14  #
     15  #  If you are unsure which license is appropriate for your use, please
     16  #  review the following information:
     17  #  http://www.trolltech.com/products/qt/licensing.html or contact
     18  #  project-camelot@conceptive.be.
     19  #
     20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
     21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     22  #
     23  #  For use of this library in commercial applications, please contact
     24  #  project-camelot@conceptive.be
     25  #
     26  #  ============================================================================
     27
     28  from PyQt4 import QtCore, QtGui
     29
     30  from camelot.view.art import Icon
     31  from camelot.core.utils import ugettext as _
     32
     33 -class SimpleSearchControl(QtGui.QWidget):
     34      """A control that displays a single text field in which search keywords can
     35    be typed
     36
     37    emits a search and a cancel signal if the user starts or cancels the search
     38    """
     39
     40      expand_search_options_signal = QtCore.SIGNAL('expand_search_options()')
     41
     42 -    def __init__(self, parent):
     43          QtGui.QWidget.__init__(self, parent)
     44          layout = QtGui.QHBoxLayout()
     45          layout.setSpacing(0)
     46          layout.setMargin(3)
     47
     48          # Search button
     49          self.search_button = QtGui.QToolButton()
     50          icon = Icon('tango/16x16/actions/system-search.png').getQIcon()
     51          self.search_button.setIcon(icon)
     52          self.search_button.setIconSize(QtCore.QSize(14, 14))
     53          self.search_button.setAutoRaise(True)
     54          self.search_button.setToolTip(_('Expand or collapse search options'))
     55          self.connect(self.search_button,
     56                       QtCore.SIGNAL('clicked()'),
     57                       self.expand_search_options_signal)
     58
     59          # Search input
     60          from camelot.view.controls.decorated_line_edit import DecoratedLineEdit
     61          self.search_input = DecoratedLineEdit(self)
     62          self.search_input.set_background_text(_('Search...'))
     63          self.search_input.setToolTip(_('type words to search for'))
     64          #self.search_input.setStyleSheet('QLineEdit{ border-radius: 0.25em;}')
     65          self.connect(self.search_input,
     66                       QtCore.SIGNAL('returnPressed()'),
     67                       self.emit_search)
     68          self.connect(self.search_input,
     69                       QtCore.SIGNAL('textEdited(const QString&)'),
     70                       self.emit_search)
     71          self.setFocusProxy( self.search_input )
     72
     73          # Cancel button
     74          self.cancel_button = QtGui.QToolButton()
     75          icon = Icon('tango/16x16/actions/edit-clear.png').getQIcon()
     76          self.cancel_button.setIcon(icon)
     77          self.cancel_button.setIconSize(QtCore.QSize(14, 14))
     78          self.cancel_button.setAutoRaise(True)
     79          self.connect(self.cancel_button,
     80                       QtCore.SIGNAL('clicked()'),
     81                       self.emit_cancel)
     82
     83          # Setup layout
     84          layout.addWidget(self.search_button)
     85          layout.addWidget(self.search_input)
     86          layout.addWidget(self.cancel_button)
     87          self.setLayout(layout)
     88
     89 -    def search(self, search_text):
     90          """Start searching for search_text"""
     91          self.search_input.setText(search_text)
     92          self.emit_search()
     93
     94 -    def emit_expand_search_options(self):
     95          self.emit(self.expand_search_options_signal)
     96
     97 -    def emit_search(self):
     98          text = unicode(self.search_input.user_input())
     99          self.emit(QtCore.SIGNAL('search'), text)
    100
    101 -    def emit_cancel(self):
    102          self.search_input.setText('')
    103          self.emit(QtCore.SIGNAL('cancel'))
    104