summaryrefslogtreecommitdiff
path: root/portato/gui/windows/search.py
blob: c5315072b0cf66cdcbb1138ac42d21661db57dc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
#
# File: portato/gui/windows/search.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2006-2009 René 'Necoro' Neumann
# This is free software.  You may redistribute copies of it under the terms of
# the GNU General Public License version 2.
# There is NO WARRANTY, to the extent permitted by law.
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>

from __future__ import absolute_import

import gtk
from .basic import AbstractDialog
from ...helper import debug

class SearchWindow (AbstractDialog):
    """A window showing the results of a search process."""
    
    def __init__ (self, parent, list, jump_to):
        """Constructor.

        @param parent: parent-window
        @type parent: gtk.Window
        @param list: list of results to show
        @type list: string[]
        @param jump_to: function to call if "OK"-Button is hit
        @type jump_to: function(string)"""
        
        AbstractDialog.__init__(self, parent)
        
        self.jump_to = jump_to # function to call for jumping
        self.list = list
        self.list.sort()
        
        # combo box
        self.searchList = self.tree.get_widget("searchList")
        self.build_sort_list()
        self.searchList.get_selection().select_path(0)

        # finished --> show
        self.window.show_all()

    def build_sort_list (self):
        """Builds the sort list."""
        
        store = gtk.ListStore(str)
        self.searchList.set_model(store)

        # build categories
        for p in self.list:
            store.append(["%s/<b>%s</b>" % tuple(p.split("/"))])

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn(_("Results"), cell, markup = 0)
        self.searchList.append_column(col)

    def ok (self, *args):
        self.jump()
        self.close()
    
    def jump (self, *args):
        model, iter = self.searchList.get_selection().get_selected()
        self.jump_to(self.list[model.get_path(iter)[0]])

    def cb_key_pressed_combo (self, widget, event):
        """Emulates a ok-button-click."""
        keyname = gtk.gdk.keyval_name(event.keyval)
        if keyname == "Return": # take it as an "OK" if Enter is pressed
            self.jump()
            return True
        else:
            return False
pan>/+129 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108