annotate examples/file_dialog.py @ 151:6689aa54b20c default tip

refactoring from camelCase -> snake_case: This libraries was using camelCase due for historical reasons (related to the use of Twisted in the initial project). This patch fixes it by using PEP8 compliant snake_case
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 15:38:18 +0200
parents 287ff3e1edd1
children
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()
66
287ff3e1edd1 removed trailing spaces
Goffi <goffi@goffi.org>
parents: 42
diff changeset
34
32
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()