comparison examples/file_dialog.py @ 32:818393067e54

example script for FileDialog
author Goffi <goffi@goffi.org>
date Tue, 28 Dec 2010 18:31:01 +0100
parents
children 4da76342ae05
comparison
equal deleted inserted replaced
31:42cb54666fc2 32:818393067e54
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 import urwid
5 from urwid_satext.files_management import FileDialog
6 import time
7
8
9 #These palette is optional, but it's easier to use with some colors :)
10
11 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
12 ('default', 'default', 'default'),
13 ('default_focus', 'default,bold', 'default'),
14 ('directory', 'dark cyan, bold', 'default'),
15 ('directory_focus', 'dark cyan, bold', 'dark green'),
16 ('separator', 'brown', 'default'),
17 ]
18
19 def ok_cb(filename):
20 """This callback is called when a file is choosen"""
21
22 #We print the filename in the middle of the screen
23 new_widget = urwid.Filler(urwid.Text(filename,align='center'))
24 loop.widget = new_widget
25 loop.draw_screen()
26 #5 seconds pause
27 time.sleep(5)
28 #see you
29 raise urwid.ExitMainLoop()
30
31 def cancel_cb(control):
32 """This callback is called when user cancelled the dialog"""
33 raise urwid.ExitMainLoop()
34
35 def test_quit(input):
36 """We leave is user press 'esc'"""
37 if input in ('esc'):
38 raise urwid.ExitMainLoop()
39
40 fd = FileDialog(ok_cb, cancel_cb)
41 loop = urwid.MainLoop(fd, const_PALETTE, unhandled_input=test_quit)
42 loop.run()