Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/util/ChooseProject.py
blob: 20469b5d3d294c8f1886aa9fa278b8c2c0d86588 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import os.path
# -*- coding: utf-8 -*-
#   Tixo - A Sugar interpreter for TICO projects
#   Copyright (C) 2012  Rodrigo Perez Fulloni
#   Fundacion Teleton Uruguay - Departamento de Ingenieria
#
#   Based on TICO Project: http://www.proyectotico.com/
#
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "rodripf"
__date__ = "$01/02/2012 10:45:52 AM$"

import os
import pygtk
pygtk.require('2.0')
import gtk
import string

class ChooseProject:
    def limpiarNombres(self, text):
        tmp = string.replace(text, "_", " ")
        return string.replace(tmp, ".jpg", "")

    def __init__(self, dir):
        self.onAbrir = []
        # Create a new window
        self.window = gtk.Dialog("Abrir")

        self.window.set_size_request(400, 500)

        self.window.connect("delete_event", self.deleteEvent)
        self.window.set_position(gtk.WIN_POS_CENTER)

        self.treestore = gtk.TreeStore(str, str)

        #dir = "./"
        car = os.listdir(dir)
        print car
        for e in car:
            if(os.path.isdir(os.path.join(dir, e))):
                self.treestore.append(None, [e,e])


        self.treeview = gtk.TreeView(self.treestore)
        self.tvcolumn = gtk.TreeViewColumn()
        self.treeview.append_column(self.tvcolumn)
        self.cell = gtk.CellRendererText()
        self.tvcolumn.pack_start(self.cell, True)

        # set the cell "text" attribute to column 0 - retrieve text
        # from that column in treestore
        self.tvcolumn.add_attribute(self.cell, 'text', 0)

        # make it searchable
        self.treeview.set_search_column(0)

        # Allow sorting on the column
        self.tvcolumn.set_sort_column_id(0)

        self.window.vbox.add(self.treeview)

        abrir = gtk.Button("Abrir")
        abrir.connect("clicked", self.abrirCB)
        self.window.action_area.pack_start(abrir, True, True, 0)


        cancelar = gtk.Button("Cancelar")
        cancelar.connect("clicked", self.cancelarCB)
        self.window.action_area.pack_start(cancelar, True, True, 0)

    def addOnAbrirListener(self, action):
        self.onAbrir.append(action)

    def show(self):
        self.window.show_all()

    def abrirCB(self, b):
        treeselection = self.treeview.get_selection()
        treeselection.set_mode(gtk.SELECTION_SINGLE)
        (model, iter) = treeselection.get_selected()

        d = self.treestore.get_value(iter, 1)
        
        self.window.destroy()
        for f in self.onAbrir:
            f(d)
            
        return d


    def cancelarCB(self, b):
        self.window.destroy()

    def deleteEvent(self, widget, event, data=None):
        self.window.destroy()
def main():
    gtk.main()

if __name__ == "__main__":
    tvexample = ChooseProject("../proyectos")
    tvexample.show()
    main()