annotate examples/file_dialog.py @ 50:4b3cfb39a362 0.1.1

version change
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2011 19:11:59 +0200
parents 585302e84c1f
children 287ff3e1edd1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
3
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
4 import urwid
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from urwid_satext.files_management import FileDialog
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
6 import time
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
7
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
8
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
9 #These palette is optional, but it's easier to use with some colors :)
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
10
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
11 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
12 ('default', 'default', 'default'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
13 ('default_focus', 'default,bold', 'default'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
14 ('directory', 'dark cyan, bold', 'default'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
15 ('directory_focus', 'dark cyan, bold', 'dark green'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
16 ('separator', 'brown', 'default'),
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
17 ]
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
18
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
19 def ok_cb(filename):
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """This callback is called when a file is choosen"""
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
21
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
22 #We print the filename in the middle of the screen
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
23 new_widget = urwid.Filler(urwid.Text(filename,align='center'))
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
24 loop.widget = new_widget
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
25 loop.draw_screen()
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
26 #5 seconds pause
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
27 time.sleep(5)
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
28 #see you
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
29 raise urwid.ExitMainLoop()
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
30
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def cancel_cb(control):
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
32 """This callback is called when user cancelled the dialog"""
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
33 raise urwid.ExitMainLoop()
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
34
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def test_quit(input):
42
585302e84c1f fixed typo + added comment
Goffi <goffi@goffi.org>
parents: 40
diff changeset
36 """We leave if user press 'esc'"""
40
4da76342ae05 added Menu example
Goffi <goffi@goffi.org>
parents: 32
diff changeset
37 if input in ('esc',):
32
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
38 raise urwid.ExitMainLoop()
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
39
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
40 fd = FileDialog(ok_cb, cancel_cb)
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
41 loop = urwid.MainLoop(fd, const_PALETTE, unhandled_input=test_quit)
818393067e54 example script for FileDialog
Goffi <goffi@goffi.org>
parents:
diff changeset
42 loop.run()