camelot.camelot.view.controls.search

Package camelot :: Package camelot :: Package view :: Package controls :: Module search |
[hide private]
[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 import art
    31
    32 -class SimpleSearchControl(QtGui.QWidget):
    33    """A control that displays a single text field in which search
    34    keywords can be typed
    35
    36    emits a search and a cancel signal if the user starts or cancels
    37    the search
    38    """
    39
    40 -  def __init__(self):
    41      QtGui.QWidget.__init__(self)
    42      layout = QtGui.QHBoxLayout()
    43      layout.setSpacing(0)
    44      layout.setMargin(0)
    45      # Search button
    46      self.search_button = QtGui.QToolButton()
    47      self.search_button.setIcon(QtGui.QIcon(art.icon16('actions/system-search')))
    48      self.search_button.setIconSize(QtCore.QSize(14, 14))
    49      self.search_button.setAutoRaise(True)
    50      self.connect(self.search_button, QtCore.SIGNAL('clicked()'), self.emit_search)
    51      # Search input
    52      self.search_input = QtGui.QLineEdit()
    53      self.connect(self.search_input, QtCore.SIGNAL('returnPressed()'), self.emit_search)
    54      # Cancel button
    55      self.cancel_button = QtGui.QToolButton()
    56      self.cancel_button.setIcon(QtGui.QIcon(art.icon16('actions/edit-clear')))
    57      self.cancel_button.setIconSize(QtCore.QSize(14, 14))
    58      self.cancel_button.setAutoRaise(True)
    59      self.connect(self.cancel_button, QtCore.SIGNAL('clicked()'), self.emit_cancel)
    60      # Setup layout
    61      layout.addWidget(self.search_button)
    62      layout.addWidget(self.search_input)
    63      layout.addWidget(self.cancel_button)
    64      self.setLayout(layout)
    65
    66 -  def search(self, search_text):
    67      """Start searching for search_text"""
    68      self.search_input.setText(search_text)
    69      self.emit_search()
    70
    71 -  def emit_search(self):
    72      text = str(self.search_input.text())
    73      self.emit(QtCore.SIGNAL('search'), text)
    74
    75 -  def emit_cancel(self):
    76      self.search_input.setText('')
    77      self.emit(QtCore.SIGNAL('cancel'))
    78