~ubuntu-branches/ubuntu/utopic/pida/utopic

« back to all changes in this revision

Viewing changes to pida/pidagtk/buffertree.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-04-17 16:08:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070417160806-3ttlb6igf94x9i03
Tags: 0.4.4-1
* New upstream release (closes: #419129)
* Add dependency on python-glade2 (closes: #418716)
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*- 
2
 
 
3
 
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
 
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
5
 
 
6
 
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
 
#of this software and associated documentation files (the "Software"), to deal
8
 
#in the Software without restriction, including without limitation the rights
9
 
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 
#copies of the Software, and to permit persons to whom the Software is
11
 
#furnished to do so, subject to the following conditions:
12
 
 
13
 
#The above copyright notice and this permission notice shall be included in
14
 
#all copies or substantial portions of the Software.
15
 
 
16
 
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 
#SOFTWARE.
23
 
 
24
 
import tree
25
 
import gtk
26
 
import toolbar
27
 
import os
28
 
import pida.core.base as base
29
 
class BufferItem(tree.IconTreeItem):
30
 
 
31
 
    def __get_markup(self):
32
 
        return self.value.markup
33
 
    markup = property(__get_markup)
34
 
 
35
 
 
36
 
class BufferTree(tree.Tree):
37
 
    
38
 
    SORT_CONTROLS = True
39
 
    SORT_AVAILABLE = [('Time Opened','creation_time'),
40
 
                      ('File path','filename'),
41
 
                      ('File name','basename'),
42
 
                      ('Mime Type','mimetype'),
43
 
                      ('File Length','length'),
44
 
                      ('Project', 'project_name')]
45
 
 
46
 
    def __init__(self):
47
 
        tree.Tree.__init__(self)
48
 
        self.view.set_expander_column(self.view.get_column(1))
49
 
        self.set_property('markup-format-string', '%(filename)s')
50
 
        self.__bufferdetails = BufferDetails()
51
 
        self.view.set_enable_search(False)
52
 
        def _se(model, column, key, iter):
53
 
            val = model.get_value(iter, 1).value
54
 
            isnt = not val.basename.startswith(key)
55
 
            return isnt
56
 
        self.view.set_search_equal_func(_se)
57
 
        #self.pack_start(self.__bufferdetails, expand=False)
58
 
        
59
 
    def set_bufferlist(self, bufferlist):
60
 
        # naive
61
 
        self.set_items(self.__adapt_bufferlist(bufferlist))
62
 
 
63
 
    def set_currentbuffer(self, filename):
64
 
        self.set_selected(filename)
65
 
 
66
 
    def display_buffer(self, buf):
67
 
        self.__bufferdetails.display_buffer(buf)
68
 
 
69
 
    def __adapt_bufferlist(self, bufferlist):
70
 
        for buf in bufferlist:
71
 
            yield self.__adapt_buffer(bufferlist[buf])
72
 
 
73
 
    def __adapt_buffer(self, buf):
74
 
        return BufferItem(buf.filename, buf, buf.icon)
75
 
 
76
 
    def get_details_box(self):
77
 
        return self.__bufferdetails
78
 
    details_box = property(get_details_box)
79
 
 
80
 
class BufferDetails(gtk.VBox):
81
 
 
82
 
    def __init__(self):
83
 
        gtk.VBox.__init__(self)
84
 
        self.__toolbar = None
85
 
        self.__contextbars = []
86
 
        self.__toolbarholder = gtk.HBox()
87
 
        self.pack_start(self.__toolbarholder, expand=False)
88
 
        self.__title = gtk.Label()
89
 
        self.pack_start(self.__title)
90
 
    
91
 
    def display_buffer(self, buf):
92
 
        self.__currentbuffer = buf
93
 
        if self.__toolbar is not None:
94
 
            self.__toolbarholder.remove(self.__toolbar)
95
 
            for bar in self.__contextbars:
96
 
                self.__toolbarholder.remove(bar)
97
 
        self.__create_toolbar(buf)
98
 
 
99
 
    def __create_toolbar(self, buf):
100
 
        globaldict={'filename':buf.filename}
101
 
        self.__contextbars = []
102
 
        def remove(toolbar):
103
 
            self.__toolbarholder.remove(toolbar)
104
 
        self.__toolbarholder.foreach(remove)
105
 
        for context in buf.contexts:
106
 
            contextbar = buf.boss.command('contexts', 'get-toolbar',
107
 
                                             contextname=context,
108
 
                                             globaldict=globaldict)
109
 
            self.__contextbars.append(contextbar)
110
 
            self.__toolbarholder.pack_start(contextbar, expand=False)
111
 
        self.show_all()
112
 
        self.__title.set_markup(buf.markup)