~ubuntu-branches/ubuntu/hardy/emesene/hardy-proposed

« back to all changes in this revision

Viewing changes to FilterEntry.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2008-02-06 21:57:05 UTC
  • Revision ID: james.westby@ubuntu.com-20080206215705-d1abf07rdwcaju3p
Tags: upstream-1.0~r1013
ImportĀ upstreamĀ versionĀ 1.0~r1013

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
#   This file is part of emesene.
 
4
#
 
5
#    Emesene is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    emesene is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with emesene; if not, write to the Free Software
 
17
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
import gtk
 
20
try: import sexy
 
21
except: hasSexy = False
 
22
else: hasSexy = True
 
23
 
 
24
class FilterEntry(gtk.HBox):
 
25
    
 
26
    def __init__(self, callback):
 
27
        '''the callback is a function that receive
 
28
        the string typed here as only parameter'''
 
29
        
 
30
        gtk.HBox.__init__(self)
 
31
        #self.set_border_width(2)
 
32
        #self.set_spacing(4)
 
33
        self.callback = callback
 
34
        
 
35
        if hasSexy:
 
36
            self.entry = sexy.IconEntry()
 
37
            self.entry.set_icon(sexy.ICON_ENTRY_PRIMARY,gtk.image_new_from_stock(gtk.STOCK_FIND,gtk.ICON_SIZE_BUTTON))
 
38
            self.entry.add_clear_button()
 
39
        else:            
 
40
            self.entry = gtk.Entry()
 
41
            iconInfo = gtk.icon_theme_get_default().lookup_icon(gtk.STOCK_FIND, 22, 0)
 
42
 
 
43
            self.icon = None
 
44
 
 
45
            if iconInfo != None:
 
46
                self.icon = gtk.Image()
 
47
                self.icon.set_from_pixbuf(iconInfo.load_icon())
 
48
                self.pack_start(self.icon, False, False)
 
49
        self.entry.connect('changed', self.entryChanged)
 
50
        self.entry.connect('key_press_event', self.entryKeypressEvent) 
 
51
 
 
52
        self.pack_start(self.entry)
 
53
        self.show_all()
 
54
            
 
55
    def entryChanged(self, *args):
 
56
        self.callback(self.entry.get_text())
 
57
        
 
58
    def entryKeypressEvent(self, widget, event): 
 
59
        keyval = gtk.gdk.keyval_name(event.keyval) 
 
60
        if keyval == 'Escape': 
 
61
            self.entry.props.text = '' 
 
62
            return True 
 
63
        return False 
 
64