2 @copyright: (C) 2008, Thomas Leonard
3 @see: U{http://roscidus.com}
6 from zeroinstall
.support
import tasks
# tmp
14 gtk_theme
= gtk
.icon_theme_get_default()
15 icon_text_plain
= gtk_theme
.load_icon('text-x-generic', icon_size
, 0)
16 icon_dir
= gtk_theme
.load_icon('folder', icon_size
, 0)
18 class DirUpdated(tasks
.Blocker
):
21 class ShellController
:
22 def __init__(self
, file):
27 def build_contents(self
):
29 e
= self
.file.enumerate_children('standard::*', 0)
36 self
.contents
= contents
39 self
.updated
.trigger()
40 self
.updated
= DirUpdated("Updates for " + self
.file.get_uri())
42 def item_activated(self
, name
):
44 self
.file = old_dir
.get_child(name
)
48 parent
= self
.file.get_parent()
53 def gtk_tree_model(contents
):
54 tm
= gtk
.ListStore(str, gtk
.gdk
.Pixbuf
)
55 tm
.set_sort_column_id(0, gtk
.SORT_ASCENDING
)
57 name
= info
.get_name()
58 if not name
.startswith('.'):
60 if info
.get_file_type() == gio
.FILE_TYPE_DIRECTORY
:
63 icon
= icon_text_plain
64 tm
[new
] = [info
.get_name(), icon
]
68 def __init__(self
, shell
):
71 builder
= gtk
.Builder()
72 builder
.add_from_file(os
.path
.join(os
.path
.dirname(__file__
), "ui.xml"))
73 self
.window
= builder
.get_object('directory')
75 cd_parent
= builder
.get_object('cd-parent')
76 cd_parent
.connect('activate', lambda a
: self
.shell
.cd_parent())
78 # Must show window before adding icons, or we randomly get:
79 # The error was 'BadAlloc (insufficient resources for operation)'
82 self
.window_destroyed
= tasks
.Blocker('Window destroyed')
83 self
.window
.connect('destroy', lambda w
: self
.window_destroyed
.trigger())
85 self
.window
.connect('key-press-event', self
.key_press_event
)
87 self
.iv
= builder
.get_object('iconview')
88 self
.iv
.set_text_column(0)
89 self
.iv
.set_pixbuf_column(1)
90 self
.iv
.set_selection_mode(gtk
.SELECTION_MULTIPLE
)
92 self
.iv
.connect('item-activated', self
.item_activated
)
94 self
.window
.show_all()
97 def key_press_event(self
, window
, kev
):
98 if kev
.keyval
== gtk
.keysyms
.BackSpace
:
99 self
.shell
.cd_parent()
104 tree_model
= gtk_tree_model(self
.shell
.contents
)
105 self
.iv
.set_model(tree_model
)
106 self
.window
.set_title(self
.shell
.file.get_uri())
107 yield [self
.shell
.updated
, self
.window_destroyed
]
108 if self
.window_destroyed
.happened
:
111 def item_activated(self
, iv
, path
):
113 name
= tm
[tm
.get_iter(path
)][0]
114 self
.shell
.item_activated(name
)