On Sat, Mar 29, 2003 at 10:13:31PM -0400, Rob Shortt wrote: > > This is something that I have struggled with also. The problem is that > when you create the InputBox that block of code is not going to wait on > the results / callback. If someone would like to impliment a way to > wait for the callback I would be all for it. :)
> However, if you just think about things a little differently there isn't
> much of a need to actually wait for the callback function to be called.
> Anything that relies on the callback can simply be continued in that
> block of code. Part 1: display the InputBox, Part 2: deal with the results.
OK, here is a patch to mediamenu.py which accomplishes the password
box thingie. It uses an InputBox right now, but if a PasswordBox were
subclassed from InputBox it should be a drop in replacement:
Index: src/mediamenu.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/mediamenu.py,v
retrieving revision 1.41
diff -u -r1.41 mediamenu.py
--- src/mediamenu.py 15 Mar 2003 17:19:44 -0000 1.41
+++ src/mediamenu.py 30 Mar 2003 04:56:20 -0000
@@ -150,6 +150,14 @@
import image.interface
import games.interface
+from osd import SynchronizedObject
+import osd
+osd = osd.get_singleton()
+from item import Item
+
+import gui.InputBox as InputBox
+import gui.AlertBox as AlertBox
+
# XML support
from xml.utils import qp_xml
@@ -429,6 +441,30 @@
return items
+ def pass_cmp_cb(self, word=None):
+ if not word:
+ return
+
+ # read the contents of self.dir/.passwd and compare to word
+ try:
+ pwfile = open(self.dir + '/.password')
+ line = pwfile.readline()
+ except IOError, e:
+ print 'error %d (%s) reading password file for %s' % \
+ (e.errno, e.strerror, self.dir)
+ return
+
+ pwfile.close()
+ password = line.strip()
+ if word == password:
+ self.do_cwd(self.arg, self.menuw)
+ else:
+ pb = AlertBox('Password incorrect')
+ osd.focused_app.add_child(pb)
+ osd.focused_app = pb
+ pb.show()
+ return
+
def cwd(self, arg=None, menuw=None):
"""
make a menu item for each file in the directory
@@ -440,6 +476,20 @@
util.mount(self.dir)
self.media = media
+ if os.path.isfile(self.dir + '/.password'):
+ print 'password protected dir'
+ pb = InputBox('Enter Password', self.pass_cmp_cb)
+ osd.focused_app.add_child(pb)
+ osd.focused_app = pb
+ pb.show()
+ # save these so the InputBox callback can pass them to do_cwd
+ self.arg = arg
+ self.menuw = menuw
+ self.foo = "bar"
+ else:
+ self.do_cwd(arg, menuw)
+
+ def do_cwd(self, arg=None, menuw=None):
try:
files = ([ os.path.join(self.dir, fname)
for fname in os.listdir(self.dir) ])
As a note, it would be nice if the value given to the callback from
InputBox where trimmed of trailing whitespace. Here is a patch that
does this:
Index: src/gui/LetterBoxGroup.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/gui/LetterBoxGroup.py,v
retrieving revision 1.4
diff -u -r1.4 LetterBoxGroup.py
--- src/gui/LetterBoxGroup.py 24 Mar 2003 02:40:50 -0000 1.4
+++ src/gui/LetterBoxGroup.py 30 Mar 2003 04:56:27 -0000
@@ -188,7 +188,7 @@
for box in self.boxes:
word = word + box.get_text()
- return word
+ return word.rstrip()
def _draw(self):
> Yes, I agree. I actually thought about doing that from the beginning.
> I guess I was waiting for someone to use this and give feedback as you
> have done.
Glad to be of help. :-)
> I will certainly make a password dialog based on your feedback. I will
> only have it use numeric characters as well... it is good enough for the
> bank machine so it should be good enough for us.
Certainly.
> I will have some time tomorrow to work on freevo so I will add this to
> my todo list, it shouldn't take me very long.
I wouldn't think so. Even wth me being a newbie at python, I think
even I could handle it. :-)
> I am also going to do
> some work which will result in it being easier to use a GUIObject (fewer
> lines of code).
Cool.
b.
--
Brian J. Murrell
pgp00000.pgp
Description: PGP signature
