# HG changeset patch # User Goffi # Date 1293557461 -3600 # Node ID 818393067e547aca7ee55f0d7c7525a599d6c5a5 # Parent 42cb54666fc235f72d378cf43209c94d0e2ebc64 example script for FileDialog diff -r 42cb54666fc2 -r 818393067e54 examples/file_dialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/file_dialog.py Tue Dec 28 18:31:01 2010 +0100 @@ -0,0 +1,42 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import urwid +from urwid_satext.files_management import FileDialog +import time + + +#These palette is optional, but it's easier to use with some colors :) + +const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'), + ('default', 'default', 'default'), + ('default_focus', 'default,bold', 'default'), + ('directory', 'dark cyan, bold', 'default'), + ('directory_focus', 'dark cyan, bold', 'dark green'), + ('separator', 'brown', 'default'), + ] + +def ok_cb(filename): + """This callback is called when a file is choosen""" + + #We print the filename in the middle of the screen + new_widget = urwid.Filler(urwid.Text(filename,align='center')) + loop.widget = new_widget + loop.draw_screen() + #5 seconds pause + time.sleep(5) + #see you + raise urwid.ExitMainLoop() + +def cancel_cb(control): + """This callback is called when user cancelled the dialog""" + raise urwid.ExitMainLoop() + +def test_quit(input): + """We leave is user press 'esc'""" + if input in ('esc'): + raise urwid.ExitMainLoop() + +fd = FileDialog(ok_cb, cancel_cb) +loop = urwid.MainLoop(fd, const_PALETTE, unhandled_input=test_quit) +loop.run() diff -r 42cb54666fc2 -r 818393067e54 urwid_satext/files_management.py --- a/urwid_satext/files_management.py Tue Dec 28 15:42:37 2010 +0100 +++ b/urwid_satext/files_management.py Tue Dec 28 18:31:01 2010 +0100 @@ -25,6 +25,7 @@ from xml.dom import minidom from logging import debug, info, error from time import time +_ = unicode #FIXME: temporary workaround, the time to manage well i18n class PathEdit(sat_widgets.AdvancedEdit): """AdvancedEdit with manage file paths"""